2 Trivial Database 2: hash handling
3 Copyright (C) Rusty Russell 2010
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include <ccan/hash/hash.h>
22 static uint64_t jenkins_hash(const void *key, size_t length, uint64_t seed,
26 /* hash64_stable assumes lower bits are more important; they are a
27 * slightly better hash. We use the upper bits first, so swap them. */
28 ret = hash64_stable((const unsigned char *)key, length, seed);
29 return (ret >> 32) | (ret << 32);
32 void tdb_hash_init(struct tdb_context *tdb)
34 tdb->khash = jenkins_hash;
35 tdb->hash_priv = NULL;
38 uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len)
40 return tdb->khash(ptr, len, tdb->hash_seed, tdb->hash_priv);
43 uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off)
45 const struct tdb_used_record *r;
49 r = tdb_access_read(tdb, off, sizeof(*r), true);
54 klen = rec_key_length(r);
55 tdb_access_release(tdb, r);
57 key = tdb_access_read(tdb, off + sizeof(*r), klen, false);
61 hash = tdb_hash(tdb, key, klen);
62 tdb_access_release(tdb, key);
66 /* Get bits from a value. */
67 static uint32_t bits_from(uint64_t val, unsigned start, unsigned num)
70 return (val >> start) & ((1U << num) - 1);
73 /* We take bits from the top: that way we can lock whole sections of the hash
74 * by using lock ranges. */
75 static uint32_t use_bits(struct hash_info *h, unsigned num)
78 return bits_from(h->h, 64 - h->hash_used, num);
81 static bool key_matches(struct tdb_context *tdb,
82 const struct tdb_used_record *rec,
84 const struct tdb_data *key)
89 if (rec_key_length(rec) != key->dsize) {
90 add_stat(tdb, compare_wrong_keylen, 1);
94 rkey = tdb_access_read(tdb, off + sizeof(*rec), key->dsize, false);
97 if (memcmp(rkey, key->dptr, key->dsize) == 0)
100 add_stat(tdb, compare_wrong_keycmp, 1);
101 tdb_access_release(tdb, rkey);
105 /* Does entry match? */
106 static bool match(struct tdb_context *tdb,
108 const struct tdb_data *key,
110 struct tdb_used_record *rec)
114 add_stat(tdb, compares, 1);
115 /* Desired bucket must match. */
116 if (h->home_bucket != (val & TDB_OFF_HASH_GROUP_MASK)) {
117 add_stat(tdb, compare_wrong_bucket, 1);
121 /* Top bits of offset == next bits of hash. */
122 if (bits_from(val, TDB_OFF_HASH_EXTRA_BIT, TDB_OFF_UPPER_STEAL_EXTRA)
123 != bits_from(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
124 TDB_OFF_UPPER_STEAL_EXTRA)) {
125 add_stat(tdb, compare_wrong_offsetbits, 1);
129 off = val & TDB_OFF_MASK;
130 if (tdb_read_convert(tdb, off, rec, sizeof(*rec)) == -1)
133 if ((h->h & ((1 << 11)-1)) != rec_hash(rec)) {
134 add_stat(tdb, compare_wrong_rechash, 1);
138 return key_matches(tdb, rec, off, key);
141 static tdb_off_t hbucket_off(tdb_off_t group_start, unsigned bucket)
144 + (bucket % (1 << TDB_HASH_GROUP_BITS)) * sizeof(tdb_off_t);
147 bool is_subhash(tdb_off_t val)
149 return (val >> TDB_OFF_UPPER_STEAL_SUBHASH_BIT) & 1;
152 /* FIXME: Guess the depth, don't over-lock! */
153 static tdb_off_t hlock_range(tdb_off_t group, tdb_off_t *size)
155 *size = 1ULL << (64 - (TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS));
156 return group << (64 - (TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS));
159 static tdb_off_t COLD find_in_chain(struct tdb_context *tdb,
163 struct tdb_used_record *rec,
164 struct traverse_info *tinfo)
168 /* In case nothing is free, we set these to zero. */
169 h->home_bucket = h->found_bucket = 0;
171 for (off = chain; off; off = next) {
174 h->group_start = off;
175 if (tdb_read_convert(tdb, off, h->group, sizeof(h->group)))
178 for (i = 0; i < (1 << TDB_HASH_GROUP_BITS); i++) {
181 /* Remember this empty bucket. */
182 h->home_bucket = h->found_bucket = i;
186 /* We can insert extra bits via add_to_hash
187 * empty bucket logic. */
188 recoff = h->group[i] & TDB_OFF_MASK;
189 if (tdb_read_convert(tdb, recoff, rec, sizeof(*rec)))
192 if (key_matches(tdb, rec, recoff, &key)) {
193 h->home_bucket = h->found_bucket = i;
196 tinfo->levels[tinfo->num_levels]
198 tinfo->levels[tinfo->num_levels]
200 = 1 << TDB_HASH_GROUP_BITS;
201 tinfo->levels[tinfo->num_levels].entry
208 next = tdb_read_off(tdb, off
209 + offsetof(struct tdb_chain, next));
210 if (next == TDB_OFF_ERR)
213 next += sizeof(struct tdb_used_record);
218 /* This is the core routine which searches the hashtable for an entry.
219 * On error, no locks are held and TDB_OFF_ERR is returned.
220 * Otherwise, hinfo is filled in (and the optional tinfo).
221 * If not found, the return value is 0.
222 * If found, the return value is the offset, and *rec is the record. */
223 tdb_off_t find_and_lock(struct tdb_context *tdb,
227 struct tdb_used_record *rec,
228 struct traverse_info *tinfo)
232 enum TDB_ERROR ecode;
234 h->h = tdb_hash(tdb, key.dptr, key.dsize);
236 group = use_bits(h, TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS);
237 h->home_bucket = use_bits(h, TDB_HASH_GROUP_BITS);
239 h->hlock_start = hlock_range(group, &h->hlock_range);
240 ecode = tdb_lock_hashes(tdb, h->hlock_start, h->hlock_range, ltype,
242 if (ecode != TDB_SUCCESS) {
247 hashtable = offsetof(struct tdb_header, hashtable);
249 tinfo->toplevel_group = group;
250 tinfo->num_levels = 1;
251 tinfo->levels[0].entry = 0;
252 tinfo->levels[0].hashtable = hashtable
253 + (group << TDB_HASH_GROUP_BITS) * sizeof(tdb_off_t);
254 tinfo->levels[0].total_buckets = 1 << TDB_HASH_GROUP_BITS;
257 while (h->hash_used <= 64) {
258 /* Read in the hash group. */
259 h->group_start = hashtable
260 + group * (sizeof(tdb_off_t) << TDB_HASH_GROUP_BITS);
262 if (tdb_read_convert(tdb, h->group_start, &h->group,
263 sizeof(h->group)) == -1)
266 /* Pointer to another hash table? Go down... */
267 if (is_subhash(h->group[h->home_bucket])) {
268 hashtable = (h->group[h->home_bucket] & TDB_OFF_MASK)
269 + sizeof(struct tdb_used_record);
271 /* When we come back, use *next* bucket */
272 tinfo->levels[tinfo->num_levels-1].entry
273 += h->home_bucket + 1;
275 group = use_bits(h, TDB_SUBLEVEL_HASH_BITS
276 - TDB_HASH_GROUP_BITS);
277 h->home_bucket = use_bits(h, TDB_HASH_GROUP_BITS);
279 tinfo->levels[tinfo->num_levels].hashtable
281 tinfo->levels[tinfo->num_levels].total_buckets
282 = 1 << TDB_SUBLEVEL_HASH_BITS;
283 tinfo->levels[tinfo->num_levels].entry
284 = group << TDB_HASH_GROUP_BITS;
290 /* It's in this group: search (until 0 or all searched) */
291 for (i = 0, h->found_bucket = h->home_bucket;
292 i < (1 << TDB_HASH_GROUP_BITS);
293 i++, h->found_bucket = ((h->found_bucket+1)
294 % (1 << TDB_HASH_GROUP_BITS))) {
295 if (is_subhash(h->group[h->found_bucket]))
298 if (!h->group[h->found_bucket])
301 if (match(tdb, h, &key, h->group[h->found_bucket],
304 tinfo->levels[tinfo->num_levels-1].entry
307 return h->group[h->found_bucket] & TDB_OFF_MASK;
310 /* Didn't find it: h indicates where it would go. */
314 return find_in_chain(tdb, key, hashtable, h, rec, tinfo);
317 tdb_unlock_hashes(tdb, h->hlock_start, h->hlock_range, ltype);
321 /* I wrote a simple test, expanding a hash to 2GB, for the following
323 * 1) Expanding all the buckets at once,
324 * 2) Expanding the bucket we wanted to place the new entry into.
325 * 3) Expanding the most-populated bucket,
327 * I measured the worst/average/best density during this process.
332 * So we figure out the busiest bucket for the moment.
334 static unsigned fullest_bucket(struct tdb_context *tdb,
335 const tdb_off_t *group,
338 unsigned counts[1 << TDB_HASH_GROUP_BITS] = { 0 };
339 unsigned int i, best_bucket;
341 /* Count the new entry. */
342 counts[new_bucket]++;
343 best_bucket = new_bucket;
345 for (i = 0; i < (1 << TDB_HASH_GROUP_BITS); i++) {
346 unsigned this_bucket;
348 if (is_subhash(group[i]))
350 this_bucket = group[i] & TDB_OFF_HASH_GROUP_MASK;
351 if (++counts[this_bucket] > counts[best_bucket])
352 best_bucket = this_bucket;
358 static bool put_into_group(tdb_off_t *group,
359 unsigned bucket, tdb_off_t encoded)
363 for (i = 0; i < (1 << TDB_HASH_GROUP_BITS); i++) {
364 unsigned b = (bucket + i) % (1 << TDB_HASH_GROUP_BITS);
374 static void force_into_group(tdb_off_t *group,
375 unsigned bucket, tdb_off_t encoded)
377 if (!put_into_group(group, bucket, encoded))
381 static tdb_off_t encode_offset(tdb_off_t new_off, struct hash_info *h)
383 return h->home_bucket
385 | ((uint64_t)bits_from(h->h,
386 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
387 TDB_OFF_UPPER_STEAL_EXTRA)
388 << TDB_OFF_HASH_EXTRA_BIT);
391 /* Simply overwrite the hash entry we found before. */
392 int replace_in_hash(struct tdb_context *tdb,
396 return tdb_write_off(tdb, hbucket_off(h->group_start, h->found_bucket),
397 encode_offset(new_off, h));
400 /* We slot in anywhere that's empty in the chain. */
401 static int COLD add_to_chain(struct tdb_context *tdb,
405 size_t entry = tdb_find_zero_off(tdb, subhash, 1<<TDB_HASH_GROUP_BITS);
407 if (entry == 1 << TDB_HASH_GROUP_BITS) {
410 next = tdb_read_off(tdb, subhash
411 + offsetof(struct tdb_chain, next));
412 if (next == TDB_OFF_ERR)
416 next = alloc(tdb, 0, sizeof(struct tdb_chain), 0,
417 TDB_CHAIN_MAGIC, false);
418 if (next == TDB_OFF_ERR)
420 if (zero_out(tdb, next+sizeof(struct tdb_used_record),
421 sizeof(struct tdb_chain)))
423 if (tdb_write_off(tdb, subhash
424 + offsetof(struct tdb_chain, next),
428 return add_to_chain(tdb, next, new_off);
431 return tdb_write_off(tdb, subhash + entry * sizeof(tdb_off_t),
435 /* Add into a newly created subhash. */
436 static int add_to_subhash(struct tdb_context *tdb, tdb_off_t subhash,
437 unsigned hash_used, tdb_off_t val)
439 tdb_off_t off = (val & TDB_OFF_MASK), *group;
443 h.hash_used = hash_used;
445 if (hash_used + TDB_SUBLEVEL_HASH_BITS > 64)
446 return add_to_chain(tdb, subhash, off);
448 h.h = hash_record(tdb, off);
449 gnum = use_bits(&h, TDB_SUBLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS);
450 h.group_start = subhash
451 + gnum * (sizeof(tdb_off_t) << TDB_HASH_GROUP_BITS);
452 h.home_bucket = use_bits(&h, TDB_HASH_GROUP_BITS);
454 group = tdb_access_write(tdb, h.group_start,
455 sizeof(*group) << TDB_HASH_GROUP_BITS, true);
458 force_into_group(group, h.home_bucket, encode_offset(off, &h));
459 return tdb_access_commit(tdb, group);
462 static int expand_group(struct tdb_context *tdb, struct hash_info *h)
464 unsigned bucket, num_vals, i, magic;
467 tdb_off_t vals[1 << TDB_HASH_GROUP_BITS];
469 /* Attach new empty subhash under fullest bucket. */
470 bucket = fullest_bucket(tdb, h->group, h->home_bucket);
472 if (h->hash_used == 64) {
473 add_stat(tdb, alloc_chain, 1);
474 subsize = sizeof(struct tdb_chain);
475 magic = TDB_CHAIN_MAGIC;
477 add_stat(tdb, alloc_subhash, 1);
478 subsize = (sizeof(tdb_off_t) << TDB_SUBLEVEL_HASH_BITS);
479 magic = TDB_HTABLE_MAGIC;
482 subhash = alloc(tdb, 0, subsize, 0, magic, false);
483 if (subhash == TDB_OFF_ERR)
486 if (zero_out(tdb, subhash + sizeof(struct tdb_used_record), subsize))
489 /* Remove any which are destined for bucket or are in wrong place. */
491 for (i = 0; i < (1 << TDB_HASH_GROUP_BITS); i++) {
492 unsigned home_bucket = h->group[i] & TDB_OFF_HASH_GROUP_MASK;
493 if (!h->group[i] || is_subhash(h->group[i]))
495 if (home_bucket == bucket || home_bucket != i) {
496 vals[num_vals++] = h->group[i];
500 /* FIXME: This assert is valid, but we do this during unit test :( */
501 /* assert(num_vals); */
503 /* Overwrite expanded bucket with subhash pointer. */
504 h->group[bucket] = subhash | (1ULL << TDB_OFF_UPPER_STEAL_SUBHASH_BIT);
506 /* Point to actual contents of record. */
507 subhash += sizeof(struct tdb_used_record);
509 /* Put values back. */
510 for (i = 0; i < num_vals; i++) {
511 unsigned this_bucket = vals[i] & TDB_OFF_HASH_GROUP_MASK;
513 if (this_bucket == bucket) {
514 if (add_to_subhash(tdb, subhash, h->hash_used, vals[i]))
517 /* There should be room to put this back. */
518 force_into_group(h->group, this_bucket, vals[i]);
524 int delete_from_hash(struct tdb_context *tdb, struct hash_info *h)
526 unsigned int i, num_movers = 0;
527 tdb_off_t movers[1 << TDB_HASH_GROUP_BITS];
529 h->group[h->found_bucket] = 0;
530 for (i = 1; i < (1 << TDB_HASH_GROUP_BITS); i++) {
531 unsigned this_bucket;
533 this_bucket = (h->found_bucket+i) % (1 << TDB_HASH_GROUP_BITS);
534 /* Empty bucket? We're done. */
535 if (!h->group[this_bucket])
538 /* Ignore subhashes. */
539 if (is_subhash(h->group[this_bucket]))
542 /* If this one is not happy where it is, we'll move it. */
543 if ((h->group[this_bucket] & TDB_OFF_HASH_GROUP_MASK)
545 movers[num_movers++] = h->group[this_bucket];
546 h->group[this_bucket] = 0;
550 /* Put back the ones we erased. */
551 for (i = 0; i < num_movers; i++) {
552 force_into_group(h->group, movers[i] & TDB_OFF_HASH_GROUP_MASK,
556 /* Now we write back the hash group */
557 return tdb_write_convert(tdb, h->group_start,
558 h->group, sizeof(h->group));
561 int add_to_hash(struct tdb_context *tdb, struct hash_info *h, tdb_off_t new_off)
563 /* We hit an empty bucket during search? That's where it goes. */
564 if (!h->group[h->found_bucket]) {
565 h->group[h->found_bucket] = encode_offset(new_off, h);
566 /* Write back the modified group. */
567 return tdb_write_convert(tdb, h->group_start,
568 h->group, sizeof(h->group));
571 if (h->hash_used > 64)
572 return add_to_chain(tdb, h->group_start, new_off);
574 /* We're full. Expand. */
575 if (expand_group(tdb, h) == -1)
578 if (is_subhash(h->group[h->home_bucket])) {
579 /* We were expanded! */
583 /* Write back the modified group. */
584 if (tdb_write_convert(tdb, h->group_start, h->group,
588 /* Move hashinfo down a level. */
589 hashtable = (h->group[h->home_bucket] & TDB_OFF_MASK)
590 + sizeof(struct tdb_used_record);
591 gnum = use_bits(h,TDB_SUBLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS);
592 h->home_bucket = use_bits(h, TDB_HASH_GROUP_BITS);
593 h->group_start = hashtable
594 + gnum * (sizeof(tdb_off_t) << TDB_HASH_GROUP_BITS);
595 if (tdb_read_convert(tdb, h->group_start, &h->group,
596 sizeof(h->group)) == -1)
600 /* Expanding the group must have made room if it didn't choose this
602 if (put_into_group(h->group, h->home_bucket, encode_offset(new_off, h)))
603 return tdb_write_convert(tdb, h->group_start,
604 h->group, sizeof(h->group));
606 /* This can happen if all hashes in group (and us) dropped into same
607 * group in subhash. */
608 return add_to_hash(tdb, h, new_off);
611 /* Traverse support: returns offset of record, or 0 or TDB_OFF_ERR. */
612 static tdb_off_t iterate_hash(struct tdb_context *tdb,
613 struct traverse_info *tinfo)
617 struct traverse_level *tlevel;
619 tlevel = &tinfo->levels[tinfo->num_levels-1];
622 for (i = tdb_find_nonzero_off(tdb, tlevel->hashtable,
623 tlevel->entry, tlevel->total_buckets);
624 i != tlevel->total_buckets;
625 i = tdb_find_nonzero_off(tdb, tlevel->hashtable,
626 i+1, tlevel->total_buckets)) {
627 val = tdb_read_off(tdb, tlevel->hashtable+sizeof(tdb_off_t)*i);
628 if (unlikely(val == TDB_OFF_ERR))
631 off = val & TDB_OFF_MASK;
633 /* This makes the delete-all-in-traverse case work
634 * (and simplifies our logic a little). */
635 if (off == tinfo->prev)
640 if (!is_subhash(val)) {
646 /* When we come back, we want the next one */
650 tlevel->hashtable = off + sizeof(struct tdb_used_record);
652 /* Next level is a chain? */
653 if (unlikely(tinfo->num_levels == TDB_MAX_LEVELS + 1))
654 tlevel->total_buckets = (1 << TDB_HASH_GROUP_BITS);
656 tlevel->total_buckets = (1 << TDB_SUBLEVEL_HASH_BITS);
661 if (tinfo->num_levels == 1)
664 /* Handle chained entries. */
665 if (unlikely(tinfo->num_levels == TDB_MAX_LEVELS + 1)) {
666 tlevel->hashtable = tdb_read_off(tdb, tlevel->hashtable
667 + offsetof(struct tdb_chain,
669 if (tlevel->hashtable == TDB_OFF_ERR)
671 if (tlevel->hashtable) {
672 tlevel->hashtable += sizeof(struct tdb_used_record);
678 /* Go back up and keep searching. */
684 /* Return 1 if we find something, 0 if not, -1 on error. */
685 int next_in_hash(struct tdb_context *tdb,
686 struct traverse_info *tinfo,
687 TDB_DATA *kbuf, size_t *dlen)
689 const unsigned group_bits = TDB_TOPLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS;
690 tdb_off_t hl_start, hl_range, off;
691 enum TDB_ERROR ecode;
693 while (tinfo->toplevel_group < (1 << group_bits)) {
694 hl_start = (tdb_off_t)tinfo->toplevel_group
695 << (64 - group_bits);
696 hl_range = 1ULL << group_bits;
697 ecode = tdb_lock_hashes(tdb, hl_start, hl_range, F_RDLCK,
699 if (ecode != TDB_SUCCESS) {
704 off = iterate_hash(tdb, tinfo);
706 struct tdb_used_record rec;
708 if (tdb_read_convert(tdb, off, &rec, sizeof(rec))) {
709 tdb_unlock_hashes(tdb,
710 hl_start, hl_range, F_RDLCK);
713 if (rec_magic(&rec) != TDB_USED_MAGIC) {
714 tdb_logerr(tdb, TDB_ERR_CORRUPT,
717 " corrupt record at %llu",
722 kbuf->dsize = rec_key_length(&rec);
724 /* They want data as well? */
726 *dlen = rec_data_length(&rec);
727 kbuf->dptr = tdb_alloc_read(tdb,
732 kbuf->dptr = tdb_alloc_read(tdb,
736 tdb_unlock_hashes(tdb, hl_start, hl_range, F_RDLCK);
737 return kbuf->dptr ? 1 : -1;
740 tdb_unlock_hashes(tdb, hl_start, hl_range, F_RDLCK);
742 tinfo->toplevel_group++;
743 tinfo->levels[0].hashtable
744 += (sizeof(tdb_off_t) << TDB_HASH_GROUP_BITS);
745 tinfo->levels[0].entry = 0;
750 /* Return 1 if we find something, 0 if not, -1 on error. */
751 int first_in_hash(struct tdb_context *tdb,
752 struct traverse_info *tinfo,
753 TDB_DATA *kbuf, size_t *dlen)
756 tinfo->toplevel_group = 0;
757 tinfo->num_levels = 1;
758 tinfo->levels[0].hashtable = offsetof(struct tdb_header, hashtable);
759 tinfo->levels[0].entry = 0;
760 tinfo->levels[0].total_buckets = (1 << TDB_HASH_GROUP_BITS);
762 return next_in_hash(tdb, tinfo, kbuf, dlen);
765 /* Even if the entry isn't in this hash bucket, you'd have to lock this
766 * bucket to find it. */
767 static int chainlock(struct tdb_context *tdb, const TDB_DATA *key,
768 int ltype, enum tdb_lock_flags waitflag,
771 enum TDB_ERROR ecode;
772 uint64_t h = tdb_hash(tdb, key->dptr, key->dsize);
773 tdb_off_t lockstart, locksize;
774 unsigned int group, gbits;
776 gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
777 group = bits_from(h, 64 - gbits, gbits);
779 lockstart = hlock_range(group, &locksize);
781 ecode = tdb_lock_hashes(tdb, lockstart, locksize, ltype, waitflag);
782 tdb_trace_1rec(tdb, func, *key);
783 if (ecode != TDB_SUCCESS) {
790 /* lock/unlock one hash chain. This is meant to be used to reduce
791 contention - it cannot guarantee how many records will be locked */
792 int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key)
794 return chainlock(tdb, &key, F_WRLCK, TDB_LOCK_WAIT, "tdb_chainlock");
797 int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
799 uint64_t h = tdb_hash(tdb, key.dptr, key.dsize);
800 tdb_off_t lockstart, locksize;
801 unsigned int group, gbits;
802 enum TDB_ERROR ecode;
804 gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
805 group = bits_from(h, 64 - gbits, gbits);
807 lockstart = hlock_range(group, &locksize);
809 tdb_trace_1rec(tdb, "tdb_chainunlock", key);
810 ecode = tdb_unlock_hashes(tdb, lockstart, locksize, F_WRLCK);
811 if (ecode != TDB_SUCCESS) {