diff options
author | Andrew Tridgell <tridge@samba.org> | 2009-10-23 22:45:03 +1100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-12-16 08:03:52 +0100 |
commit | a51ad4a3be11887488ad248a4268f3fea67f4fc1 (patch) | |
tree | 337a58b79edaa46ad1af4badd662c705d7e1bef9 | |
parent | 2b10c14e350115661d93c8b22a693187aade2f93 (diff) | |
download | samba-a51ad4a3be11887488ad248a4268f3fea67f4fc1.tar.gz samba-a51ad4a3be11887488ad248a4268f3fea67f4fc1.tar.xz samba-a51ad4a3be11887488ad248a4268f3fea67f4fc1.zip |
tdb: detect tdb store of identical records and skip
This can help with ldb where we rewrite the index records
(cherry picked from samba commit d4c0e8fdf063f88032c32de7ece60d502b322089)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
(This used to be ctdb commit 470750fa2e3cf987f10de48451b1ee13aab03907)
-rw-r--r-- | ctdb/lib/tdb/common/tdb.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ctdb/lib/tdb/common/tdb.c b/ctdb/lib/tdb/common/tdb.c index 0389d3cb96..564c5fed5c 100644 --- a/ctdb/lib/tdb/common/tdb.c +++ b/ctdb/lib/tdb/common/tdb.c @@ -121,6 +121,7 @@ tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t has return rec_ptr; } +static TDB_DATA _tdb_fetch(struct tdb_context *tdb, TDB_DATA key); /* update an entry in place - this only works if the new data size is <= the old data size and the key exists. @@ -135,6 +136,25 @@ static int tdb_update_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) return -1; + /* it could be an exact duplicate of what is there - this is + * surprisingly common (eg. with a ldb re-index). */ + if (rec.key_len == key.dsize && + rec.data_len == dbuf.dsize && + rec.full_hash == hash) { + TDB_DATA data = _tdb_fetch(tdb, key); + if (data.dsize == dbuf.dsize && + memcmp(data.dptr, dbuf.dptr, data.dsize) == 0) { + if (data.dptr) { + free(data.dptr); + } + return 0; + } + if (data.dptr) { + free(data.dptr); + } + } + + /* must be long enough key, data and tailer */ if (rec.rec_len < key.dsize + dbuf.dsize + sizeof(tdb_off_t)) { tdb->ecode = TDB_SUCCESS; /* Not really an error */ |