Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
cbfcfe53
Commit
cbfcfe53
authored
Aug 30, 2010
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tdb2: fixes and test for hash enlargement.
parent
2088fa3c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
12 deletions
+56
-12
ccan/tdb2/tdb.c
ccan/tdb2/tdb.c
+10
-4
ccan/tdb2/test/run-enlarge_hash.c
ccan/tdb2/test/run-enlarge_hash.c
+46
-8
No files found.
ccan/tdb2/tdb.c
View file @
cbfcfe53
...
...
@@ -599,12 +599,18 @@ static void enlarge_hash(struct tdb_context *tdb)
"find_bucket_and_lock: zero hash bucket!
\n
"
);
goto
unlock
;
}
h
=
hash_record
(
tdb
,
off
);
/* Find next empty hash slot. */
for
(
h
=
hash_record
(
tdb
,
off
);
tdb_read_off
(
tdb
,
newoff
+
(
h
&
((
num
*
2
)
-
1
))
*
sizeof
(
tdb_off_t
))
!=
0
;
h
++
);
/* FIXME: Encode extra hash bits! */
if
(
tdb_write_off
(
tdb
,
newoff
+
(
h
&
((
num
*
2
)
-
1
))
*
sizeof
(
uint64_t
),
off
)
==
-
1
)
if
(
tdb_write_off
(
tdb
,
newoff
+
(
h
&
((
num
*
2
)
-
1
))
*
sizeof
(
tdb_off_t
),
off
)
==
-
1
)
goto
unlock
;
i
++
;
}
/* Free up old hash. */
...
...
ccan/tdb2/test/run-enlarge_hash.c
View file @
cbfcfe53
...
...
@@ -6,24 +6,62 @@
#include <ccan/tap/tap.h>
#include "logging.h"
/* We rig the hash so adjacent-numbered records always clash. */
static
uint64_t
clash
(
const
void
*
key
,
size_t
len
,
uint64_t
seed
,
void
*
priv
)
{
return
*
(
unsigned
int
*
)
key
/
2
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
unsigned
int
i
;
struct
tdb_context
*
tdb
;
unsigned
int
v
;
struct
tdb_data
key
=
{
(
unsigned
char
*
)
&
v
,
sizeof
(
v
)
};
struct
tdb_data
data
=
{
(
unsigned
char
*
)
&
v
,
sizeof
(
v
)
};
union
tdb_attribute
hattr
=
{
.
hash
=
{
.
base
=
{
TDB_ATTRIBUTE_HASH
},
.
hash_fn
=
clash
}
};
int
flags
[]
=
{
TDB_INTERNAL
,
TDB_DEFAULT
,
TDB_INTERNAL
|
TDB_CONVERT
,
TDB_CONVERT
};
plan_tests
(
sizeof
(
flags
)
/
sizeof
(
flags
[
0
])
*
2
+
1
);
hattr
.
base
.
next
=
&
tap_log_attr
;
plan_tests
(
sizeof
(
flags
)
/
sizeof
(
flags
[
0
])
*
11
+
1
);
for
(
i
=
0
;
i
<
sizeof
(
flags
)
/
sizeof
(
flags
[
0
]);
i
++
)
{
tdb
=
tdb_open
(
"run-enlarge-hash.tdb"
,
flags
[
i
],
O_RDWR
|
O_CREAT
|
O_TRUNC
,
0600
,
&
tap_log_
attr
);
O_RDWR
|
O_CREAT
|
O_TRUNC
,
0600
,
&
h
attr
);
ok1
(
tdb
);
if
(
tdb
)
{
enlarge_hash
(
tdb
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
tdb_close
(
tdb
);
}
/* FIXME: Test enlarging with hash clash. */
if
(
!
tdb
)
continue
;
/* Put a single entry in. */
v
=
0
;
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
enlarge_hash
(
tdb
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
/* Put a non-clashing entry in. */
v
=
2
;
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
enlarge_hash
(
tdb
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
/* Now, make a clash. */
v
=
1
;
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
enlarge_hash
(
tdb
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
/* Clash at end. */
v
=
((
1
<<
tdb
->
header
.
v
.
hash_bits
)
-
1
)
*
2
;
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
v
++
;
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
enlarge_hash
(
tdb
);
ok1
(
tdb_check
(
tdb
,
NULL
,
NULL
)
==
0
);
tdb_close
(
tdb
);
}
ok1
(
tap_log_messages
==
0
);
return
exit_status
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment