schema: Make the fetch of the schema version fast
authorAndrew Bartlett <abartlet@samba.org>
Mon, 4 Jul 2016 02:05:46 +0000 (14:05 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 6 Jul 2016 13:35:17 +0000 (15:35 +0200)
Use the tdb_seqnum() to avoid needing locks to check if the schema has not changed

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
source4/dsdb/samdb/ldb_modules/partition_metadata.c
source4/dsdb/samdb/ldb_modules/schema_load.c

index 1db800ec6af1d8677004877f123024480fb94f84..3c5180b7ab7a8a35328e1611b4b08d02f96ecb5a 100644 (file)
@@ -242,7 +242,7 @@ static int partition_metadata_open(struct ldb_module *module, bool create)
 
        data->metadata->db = tdb_wrap_open(
                data->metadata, filename, 10,
-               lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT), open_flags, 0660);
+               lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT|TDB_SEQNUM), open_flags, 0660);
        if (data->metadata->db == NULL) {
                talloc_free(tmp_ctx);
                if (create) {
index 8449543ad166b2a5e603d6e1d3537880fe40e3f0..0672b5c62d0c9723a833d91966b750036a3984e6 100644 (file)
@@ -37,6 +37,8 @@
 struct schema_load_private_data {
        bool in_transaction;
        struct tdb_wrap *metadata;
+       uint64_t schema_seq_num_cache;
+       int tdb_seqnum;
 };
 
 static int dsdb_schema_from_db(struct ldb_module *module,
@@ -94,7 +96,7 @@ static int schema_metadata_open(struct ldb_module *module)
                                       struct loadparm_context);
 
        data->metadata = tdb_wrap_open(data, filename, 10,
-                                      lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
+                                      lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT|TDB_SEQNUM),
                                       open_flags, 0660);
        if (data->metadata == NULL) {
                talloc_free(tmp_ctx);
@@ -114,12 +116,19 @@ static int schema_metadata_get_uint64(struct ldb_module *module,
        TDB_DATA tdb_key, tdb_data;
        char *value_str;
        TALLOC_CTX *tmp_ctx;
+       int tdb_seqnum;
 
        if (!data || !data->metadata) {
                *value = default_value;
                return LDB_SUCCESS;
        }
 
+       tdb_seqnum = tdb_get_seqnum(data->metadata->tdb);
+       if (tdb_seqnum == data->tdb_seqnum) {
+               *value = data->schema_seq_num_cache;
+               return LDB_SUCCESS;
+       }
+
        tmp_ctx = talloc_new(NULL);
        if (tmp_ctx == NULL) {
                return ldb_module_oom(module);
@@ -150,7 +159,15 @@ static int schema_metadata_get_uint64(struct ldb_module *module,
                return ldb_module_oom(module);
        }
 
-       *value = strtoull(value_str, NULL, 10);
+       /*
+        * Now store it in the cache.  We don't mind that tdb_seqnum
+        * may be stale now, that just means the cache won't be used
+        * next time
+        */
+       data->tdb_seqnum = tdb_seqnum;
+       data->schema_seq_num_cache = strtoull(value_str, NULL, 10);
+
+       *value = data->schema_seq_num_cache;
 
        SAFE_FREE(tdb_data.dptr);
        talloc_free(tmp_ctx);