svn commit: samba r19402 - in branches/SAMBA_4_0/source/lib/ldb/ldb_tdb: .

tridge at samba.org tridge at samba.org
Wed Oct 18 21:45:47 GMT 2006


Author: tridge
Date: 2006-10-18 21:45:46 +0000 (Wed, 18 Oct 2006)
New Revision: 19402

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19402

Log:

- use the new tdb_lockall_read() to make ldb_search() more efficient,
  by avoiding chain locks on each tdb_fetch() within the search

- use the tdb_get_seqnum() call to avoid re-reading the @BASEINFO
  record when it hasn't changed.

These speed up the LOCAL-DBSPEED test for ldb from 7k ops/sec to a bit
over 11k ops/sec

Modified:
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_search.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.h


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c	2006-10-18 21:41:59 UTC (rev 19401)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c	2006-10-18 21:45:46 UTC (rev 19402)
@@ -316,6 +316,12 @@
 	uint64_t seq;
 	struct ldb_message *baseinfo;
 
+	/* a very fast check to avoid extra database reads */
+	if (ltdb->cache != NULL && 
+	    tdb_get_seqnum(ltdb->tdb) == ltdb->tdb_seqnum) {
+		return 0;
+	}
+
 	if (ltdb->cache == NULL) {
 		ltdb->cache = talloc_zero(ltdb, struct ltdb_cache);
 		if (ltdb->cache == NULL) goto failed;
@@ -349,6 +355,8 @@
 		}
 	}
 
+	ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb);
+
 	/* if the current internal sequence number is the same as the one
 	   in the database then assume the rest of the cache is OK */
 	seq = ldb_msg_find_attr_as_uint64(baseinfo, LTDB_SEQUENCE_NUMBER, 0);

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_search.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_search.c	2006-10-18 21:41:59 UTC (rev 19401)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_search.c	2006-10-18 21:45:46 UTC (rev 19402)
@@ -248,25 +248,13 @@
 	return 1;
 }
 
-/* the lock key for search locking. Note that this is not a DN, its
-   just an arbitrary key to give to tdb. Also note that as we and
-   using transactions for all write operations and transactions take
-   care of their own locks, we don't need to do any locking anywhere
-   other than in ldb_search() */
-#define LDBLOCK	"INT_LDBLOCK"
-
 /*
   lock the database for read - use by ltdb_search
 */
 static int ltdb_lock_read(struct ldb_module *module)
 {
 	struct ltdb_private *ltdb = module->private_data;
-	TDB_DATA key;
-
-	key.dptr = discard_const(LDBLOCK);
-	key.dsize = strlen(LDBLOCK);
-
-	return tdb_chainlock_read(ltdb->tdb, key);
+	return tdb_lockall_read(ltdb->tdb);
 }
 
 /*
@@ -275,12 +263,7 @@
 static int ltdb_unlock_read(struct ldb_module *module)
 {
 	struct ltdb_private *ltdb = module->private_data;
-	TDB_DATA key;
-
-	key.dptr = discard_const(LDBLOCK);
-	key.dsize = strlen(LDBLOCK);
-
-	return tdb_chainunlock_read(ltdb->tdb, key);
+	return tdb_unlockall_read(ltdb->tdb);
 }
 
 /*

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c	2006-10-18 21:41:59 UTC (rev 19401)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c	2006-10-18 21:45:46 UTC (rev 19402)
@@ -1021,7 +1021,7 @@
 		path = url;
 	}
 
-	tdb_flags = TDB_DEFAULT;
+	tdb_flags = TDB_DEFAULT | TDB_SEQNUM;
 
 	/* check for the 'nosync' option */
 	if (flags & LDB_FLG_NOSYNC) {

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.h	2006-10-18 21:41:59 UTC (rev 19401)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.h	2006-10-18 21:45:46 UTC (rev 19402)
@@ -21,6 +21,10 @@
 	   handling. It has plenty of digits of precision */
 	unsigned long long sequence_number;
 
+	/* the low level tdb seqnum - used to avoid loading BASEINFO when
+	   possible */
+	int tdb_seqnum;
+
 	struct ltdb_cache {
 		struct ldb_message *indexlist;
 		struct ldb_message *attributes;



More information about the samba-cvs mailing list