Lines Matching full:hash
139 #define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off_t))
162 #define BUCKET(hash) ((hash) % tdb->header.hash_size)
169 plus a separate data list for each hash value */
175 u32 full_hash; /* the full 32 bit hash of the key */
194 u32 hash_size; /* number of hash entries */
210 u32 hash;
284 static tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash, int locktype,
743 /* lock/unlock one hash chain. This is meant to be used to reduce
750 /* lock/unlock one hash chain, non-blocking. This is meant to be used
943 do an unlocked scan of the hash table heads to find the next non-zero head. The value
1266 - keep a mirrored copy of the tdb hash chain heads to allow for the
1267 fast hash heads scan on traverse, updating the mirrored copy in
1304 /* we keep a mirrored copy of the tdb hash heads here so
1407 /* if the write is to a hash head, then update the transaction
1408 hash heads */
1520 accelerated hash chain head search, using the cached hash heads
1636 TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to get hash locks\n"));
1641 /* setup a copy of the hash table heads so the hash scan in
1651 TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_start: failed to read hash heads\n"));
1667 transaction linked list due to hash table updates */
1670 TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_start: failed to prime hash table\n"));
2023 TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to upgrade hash locks\n"));
2651 for (; tlock->hash < tdb->header.hash_size; tlock->hash++) {
2652 if (!tlock->off && tlock->hash != 0) {
2654 the hash chain is empty, which is particularly
2657 time in tdb_brlock(), locking empty hash chains.
2660 if the hash chain is empty before starting to look
2662 hash chain. If it isn't empty then we can't believe
2668 first hash chain is critical. We must guarantee
2681 tdb->methods->next_hash_chain(tdb, &tlock->hash);
2682 if (tlock->hash == tdb->header.hash_size) {
2687 if (tdb_lock(tdb, tlock->hash, tlock->lock_rw) == -1)
2692 if (tdb_ofs_read(tdb, TDB_HASH_TOP(tlock->hash),
2734 tdb_unlock(tdb, tlock->hash, tlock->lock_rw);
2742 if (tdb_unlock(tdb, tlock->hash, tlock->lock_rw) != 0)
2776 if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0)
2787 if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0) {
2872 tdb->travlocks.off = tdb->travlocks.hash = 0;
2882 /* Unlock the hash chain of the record we just read. */
2883 if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0)
2898 if (tdb_lock(tdb,tdb->travlocks.hash,tdb->travlocks.lock_rw))
2909 if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0) {
2924 tdb->travlocks.hash = BUCKET(rec.full_hash);
2930 oldhash = tdb->travlocks.hash;
2939 if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0)
2950 static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash,
2962 printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%d "
2964 hash, offset, rec.next, rec.rec_len, rec.key_len, rec.data_len,
2994 printf("hash=%d\n", i);
3108 static tdb_off_t tdb_find(struct tdb_context *tdb, TDB_DATA key, u32 hash,
3113 /* read in the hash top */
3114 if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
3122 if (!TDB_DEAD(r) && hash==r->full_hash
3135 tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash, int locktype,
3140 if (tdb_lock(tdb, BUCKET(hash), locktype) == -1)
3142 if (!(rec_ptr = tdb_find(tdb, key, hash, rec)))
3143 tdb_unlock(tdb, BUCKET(hash), locktype);
3152 static int tdb_update_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash, TDB_DATA dbuf)
3158 if (!(rec_ptr = tdb_find(tdb, key, hash, &rec)))
3191 u32 hash;
3193 /* find which hash bucket it is in */
3194 hash = tdb->hash_fn(&key);
3195 if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec)))
3229 u32 hash;
3231 /* find which hash bucket it is in */
3232 hash = tdb->hash_fn(&key);
3234 if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) {
3252 static int tdb_exists_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash)
3256 if (tdb_find_lock_hash(tdb, key, hash, F_RDLCK, &rec) == 0)
3264 u32 hash = tdb->hash_fn(&key);
3265 return tdb_exists_hash(tdb, key, hash);
3284 /* find previous record in hash chain */
3303 static int tdb_count_dead(struct tdb_context *tdb, u32 hash)
3309 /* read in the hash top */
3310 if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
3326 * Purge all DEAD records from a hash chain
3328 static int tdb_purge_dead(struct tdb_context *tdb, u32 hash)
3338 /* read in the hash top */
3339 if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
3364 static int tdb_delete_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash)
3373 * Allow for some dead records per hash chain, mainly for
3377 if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
3380 if (tdb_count_dead(tdb, hash) >= tdb->max_dead_records) {
3385 tdb_purge_dead(tdb, hash);
3388 if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) {
3389 tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
3400 if (!(rec_ptr = tdb_find_lock_hash(tdb, key, hash, F_WRLCK,
3418 u32 hash = tdb->hash_fn(&key);
3419 return tdb_delete_hash(tdb, key, hash);
3425 static tdb_off_t tdb_find_dead(struct tdb_context *tdb, u32 hash,
3430 /* read in the hash top */
3431 if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
3459 u32 hash;
3469 /* find which hash bucket it is in */
3470 hash = tdb->hash_fn(&key);
3471 if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
3476 if (tdb_exists_hash(tdb, key, hash)) {
3482 if (tdb_update_hash(tdb, key, hash, dbuf) == 0) {
3499 tdb_delete_hash(tdb, key, hash);
3515 * Allow for some dead records per hash chain, look if we can
3521 tdb, hash, &rec,
3527 rec.full_hash = hash;
3542 * the hash chain under the freelist lock.
3550 && (tdb_purge_dead(tdb, hash) == -1)) {
3564 /* Read hash top into next ptr */
3565 if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec.next) == -1)
3570 rec.full_hash = hash;
3573 /* write out and point the top of the hash chain at it */
3576 || tdb_ofs_write(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) {
3589 tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
3597 u32 hash;
3601 /* find which hash bucket it is in */
3602 hash = tdb->hash_fn(&key);
3603 if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
3630 tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
3713 /* This is based on the hash algorithm from gdbm */
3716 u32 value; /* Used to compute the hash value. */
3727 /* initialise a new database with a specified hash size */
3790 database file. A flags value of O_WRONLY is invalid. The hash size
4004 * Set the maximum number of dead records per hash chain