summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>2000-04-05 07:02:12 +0000
committerLuke Leighton <lkcl@samba.org>2000-04-05 07:02:12 +0000
commit3a07583e147d60266d2804b40898a29c1e6318fe (patch)
tree4c7dfd171664a38f0b3a596b7a3319669597532b
parentedca5a4600580eda6c180efefcb77cc99cf98f3d (diff)
downloadsamba-3a07583e147d60266d2804b40898a29c1e6318fe.tar.gz
optimisation of TDB_MODIFY: use tdb_update() to tell us if the attempted
in-place replacement of the record didn't exist (and so failed), and if it didn't exist, we don't need to check again (don't need to make _another_ call to tdb_exists(), just fail).
-rw-r--r--source/tdb/tdb.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/source/tdb/tdb.c b/source/tdb/tdb.c
index 7d99773e6f8..5db783eedd9 100644
--- a/source/tdb/tdb.c
+++ b/source/tdb/tdb.c
@@ -632,6 +632,9 @@ int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
return -1;
}
+ /* initialise error code to ok, first */
+ tdb->ecode = 0;
+
/* find which hash bucket it is in */
hash = tdb_hash(&key);
@@ -639,7 +642,10 @@ int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
rec_ptr = tdb_find(tdb, key, hash, &rec);
if (!rec_ptr)
+ {
+ tdb->ecode = TDB_ERR_NOEXIST;
goto out;
+ }
/* must be long enough */
if (rec.rec_len < key.dsize + dbuf.dsize)
@@ -1033,17 +1039,25 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
return -1;
}
- /* check for it _not_ existing, on modify. */
- if (flag == TDB_MODIFY && !tdb_exists(tdb, key)) {
- tdb->ecode = TDB_ERR_NOEXIST;
- return -1;
- }
-
/* first try in-place update, on modify or replace. */
if (flag != TDB_INSERT && tdb_update(tdb, key, dbuf) == 0) {
return 0;
}
+ /* check for it _not_ existing, from error code of the update. */
+ if (flag == TDB_MODIFY && tdb->ecode == TDB_ERR_NOEXIST) {
+ return -1;
+ }
+
+ /* reset the error code potentially set by the tdb_update() */
+ tdb->ecode = 0;
+
+ /*
+ * now we're into insert / modify / replace of a record
+ * which we know could not be optimised by an in-place
+ * store (for various reasons).
+ */
+
rec_ptr = tdb_allocate(tdb, key.dsize + dbuf.dsize);
if (rec_ptr == 0) {
return -1;