summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-10-18 21:45:46 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:21:26 -0500
commit4b9eee02c4a0c856f16d9f17929e726fb75e051f (patch)
treec22d0f46f4d6d549feb4873d3274cc837aab08fe /source4/lib/ldb
parentcba142f1ae71b03266210e254c251683846d7fd7 (diff)
downloadsamba-4b9eee02c4a0c856f16d9f17929e726fb75e051f.tar.gz
samba-4b9eee02c4a0c856f16d9f17929e726fb75e051f.tar.bz2
samba-4b9eee02c4a0c856f16d9f17929e726fb75e051f.zip
r19402: - 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 (This used to be commit 1347ad254eb8cd12ce22a5a2a37bec0a0ac8dbf1)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_cache.c8
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c21
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c2
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.h4
4 files changed, 15 insertions, 20 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c
index 84932ac47f..467f1ac34d 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c
@@ -316,6 +316,12 @@ int ltdb_cache_load(struct ldb_module *module)
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 @@ int ltdb_cache_load(struct ldb_module *module)
}
}
+ 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);
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index 85b6a123ca..4b76c437b6 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -248,25 +248,13 @@ int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct l
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_lock_read(struct ldb_module *module)
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);
}
/*
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index fd1c8780ae..3f9db39097 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -1021,7 +1021,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
path = url;
}
- tdb_flags = TDB_DEFAULT;
+ tdb_flags = TDB_DEFAULT | TDB_SEQNUM;
/* check for the 'nosync' option */
if (flags & LDB_FLG_NOSYNC) {
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
index c20c3bd5f9..42f3dc2421 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
@@ -21,6 +21,10 @@ struct ltdb_private {
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;