diff --git a/source4/dsdb/samdb/ldb_modules/partition_metadata.c b/source4/dsdb/samdb/ldb_modules/partition_metadata.c index 1db800ec6af..3c5180b7ab7 100644 --- a/source4/dsdb/samdb/ldb_modules/partition_metadata.c +++ b/source4/dsdb/samdb/ldb_modules/partition_metadata.c @@ -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) { diff --git a/source4/dsdb/samdb/ldb_modules/schema_load.c b/source4/dsdb/samdb/ldb_modules/schema_load.c index 8449543ad16..0672b5c62d0 100644 --- a/source4/dsdb/samdb/ldb_modules/schema_load.c +++ b/source4/dsdb/samdb/ldb_modules/schema_load.c @@ -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);