1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00
samba-mirror/lib/tdb/common
Volker Lendecke 500a729a55 tdb: Make record deletion circular-chain safe
Before this patch we had 3 loops walking a hash chain to delete
records:

tdb_do_delete() to find the predecessor of the record that was to be
deleted. tdb_count_dead(), the name says it all and tdb_purge_dead()
to give back all dead records from a chain to the freelist.

This patch introduces tdb_trim_dead that walks a hash chain just
once. While it does so it counts the number of dead records, and all
records beyond tdb->max_dead_records are moved to the freelist.

Normal record deletion now works by always marking a record as dead in
step 1 and then calling tdb_trim_dead. This is made safe against
circular chains by doing the slow chain walk only in the case when we
did not delete a dead record during our walk.

It changes our dynamics a bit:

When deleting a record with non-zero max_dead_records, now we always
leave that number of records around when deleting, doing a blocking
lock on the freelist when we found too many dead records.

Previously when exceeding max_dead_records we wiped all dead records
to start accumulating them from scratch, assuming we could lock the
freelist in a nonblocking fashion.

The net effect for an uncontended freelist is the same: In
tdb_allocate() we still completely hand over all dead records to the
freelist when we could lock it, it just happens later than without
this patch.

This means for a lightly loaded system we will potentially leave more
dead records around in databases like locking.tdb. However, on a
heavily loaded system we become more predictable: If the freelist is
so heavily contended that across many deletes we can't get hold of it,
previously we accumulated more dead records than max_dead_records
would allow. This is a really lowlevel tradeoff that is likely hard to
measure, but to me becoming more deterministic without sacrificing too
much parallelism (we keep more dead records around) is worth trying.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Oct 30 02:48:38 CET 2018 on sn-devel-144
2018-10-30 02:48:38 +01:00
..
check.c Harden tdb_check_used_record against overflow 2018-03-22 02:15:14 +01:00
dump.c tdb: Align an integer type 2018-10-29 23:36:24 +01:00
error.c tdb: Fix blank line endings 2012-12-21 11:54:53 +01:00
freelist.c tdb: Make record deletion circular-chain safe 2018-10-30 02:48:38 +01:00
freelistcheck.c tdb: Use tdb_null in freelistcheck 2013-02-19 15:46:45 +01:00
hash.c lib:tdb: Add FALL_THROUGH statements in hash.c 2018-03-01 04:37:41 +01:00
io.c tdb: Harden tdb_rec_read 2018-03-22 02:15:14 +01:00
lock.c tdb: Fix a typo 2018-10-29 23:36:24 +01:00
mutex.c tdb: runtime check for robust mutexes may hang in threaded programs 2017-04-27 14:52:16 +02:00
open.c tdb: Use explicit initialization 2018-10-25 17:58:23 +02:00
rescue.c tdb: Remove "header" from tdb_context 2013-02-05 13:18:28 +01:00
summary.c tdb: Make get_hash_length circular-safe 2018-10-08 22:17:10 +02:00
tdb_private.h tdb: Make record deletion circular-chain safe 2018-10-30 02:48:38 +01:00
tdb.c tdb: Make record deletion circular-chain safe 2018-10-30 02:48:38 +01:00
transaction.c tdb: Fix a "increases alignment" warning 2018-03-22 07:21:44 +01:00
traverse.c tdb: Don't delete dead records in traverse 2018-10-29 23:36:24 +01:00