add_stat(tdb, alloc_coalesce_tried, 1);
end = off + sizeof(struct tdb_used_record) + data_len;
- while (end < tdb->map_size) {
+ while (end < tdb->file->map_size) {
const struct tdb_free_record *r;
tdb_off_t nb_off;
unsigned ftable, bucket;
}
if (frec_magic(r) != TDB_FREE_MAGIC) {
- tdb_access_release(tdb, r);
ecode = tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
"lock_and_alloc:"
" %llu non-free 0x%llx",
(long long)off,
(long long)r->magic_and_prev);
+ tdb_access_release(tdb, r);
goto unlock_err;
}
best = *r;
}
- if (frec_len(&best) < size * multiplier && best_off) {
+ if (frec_len(&best) <= size * multiplier && best_off) {
tdb_access_release(tdb, r);
break;
}
/* Need to hold a hash lock to expand DB: transactions rely on it. */
if (!(tdb->flags & TDB_NOLOCK)
- && !tdb->allrecord_lock.count && !tdb_has_hash_locks(tdb)) {
+ && !tdb->file->allrecord_lock.count && !tdb_has_hash_locks(tdb)) {
return tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
"tdb_expand: must hold lock during expand");
}
/* always make room for at least 100 more records, and at
least 25% more space. */
- if (size * TDB_EXTENSION_FACTOR > tdb->map_size / 4)
+ if (size * TDB_EXTENSION_FACTOR > tdb->file->map_size / 4)
wanted = size * TDB_EXTENSION_FACTOR;
else
- wanted = tdb->map_size / 4;
+ wanted = tdb->file->map_size / 4;
wanted = adjust_size(0, wanted);
/* Only one person can expand file at a time. */
}
/* Someone else may have expanded the file, so retry. */
- old_size = tdb->map_size;
- tdb->methods->oob(tdb, tdb->map_size + 1, true);
- if (tdb->map_size != old_size) {
+ old_size = tdb->file->map_size;
+ tdb->methods->oob(tdb, tdb->file->map_size + 1, true);
+ if (tdb->file->map_size != old_size) {
tdb_unlock_expand(tdb, F_WRLCK);
return TDB_SUCCESS;
}