mirror of
https://github.com/samba-team/samba.git
synced 2025-01-26 10:04:02 +03:00
schema: Make the fetch of the schema version fast
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>
This commit is contained in:
parent
3175d5f4bf
commit
bad502fd86
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user