ldb_tdb: Remove tdb_get_seqnum and use a generic 'has_changed'
authorGarming Sam <garming@catalyst.net.nz>
Tue, 10 Jan 2017 10:23:22 +0000 (23:23 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 5 Mar 2018 19:50:15 +0000 (20:50 +0100)
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/ldb_tdb/ldb_cache.c
lib/ldb/ldb_tdb/ldb_tdb.c
lib/ldb/ldb_tdb/ldb_tdb.h

index 600b73f767effc884c2069d6c59f2d69b5b42818..4790bcd7e531fa9980f8bfd3da74a73ed500144b 100644 (file)
@@ -391,8 +391,7 @@ int ltdb_cache_load(struct ldb_module *module)
        ldb = ldb_module_get_ctx(module);
 
        /* a very fast check to avoid extra database reads */
-       if (ltdb->cache != NULL && 
-           tdb_get_seqnum(ltdb->tdb) == ltdb->tdb_seqnum) {
+       if (ltdb->cache != NULL && !ltdb->kv_ops->has_changed(ltdb)) {
                return 0;
        }
 
@@ -432,7 +431,8 @@ int ltdb_cache_load(struct ldb_module *module)
                }
        }
 
-       ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb);
+       /* Ignore the result, and update the sequence number */
+       ltdb->kv_ops->has_changed(ltdb);
 
        /* if the current internal sequence number is the same as the one
           in the database then assume the rest of the cache is OK */
@@ -594,7 +594,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module)
 
        /* updating the tdb_seqnum here avoids us reloading the cache
           records due to our own modification */
-       ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb);
+       ltdb->kv_ops->has_changed(ltdb);
 
        return ret;
 }
index 7e95437e79e924b7fb35169733c04531fb8b7563..d7fe491796577fb3998ead24f274c1e154a05e52 100644 (file)
@@ -1714,6 +1714,15 @@ static const char * ltdb_tdb_name(struct ltdb_private *ltdb)
        return tdb_name(ltdb->tdb);
 }
 
+static bool ltdb_tdb_changed(struct ltdb_private *ltdb)
+{
+       bool ret = (tdb_get_seqnum(ltdb->tdb) != ltdb->tdb_seqnum);
+
+       ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb);
+
+       return ret;
+}
+
 static const struct kv_db_ops key_value_ops = {
        .store = ltdb_tdb_store,
        .delete = ltdb_tdb_delete,
@@ -1725,6 +1734,7 @@ static const struct kv_db_ops key_value_ops = {
        .abort_write = ltdb_tdb_transaction_cancel,
        .error = ltdb_error,
        .name = ltdb_tdb_name,
+       .has_changed = ltdb_tdb_changed,
 };
 
 static void ltdb_callback(struct tevent_context *ev,
index 4d4805b98efb1818d1a457963211ca4fbf9114f2..ba827f92a885e9eaa7b7ba56a9b6697b6d481833 100644 (file)
@@ -16,6 +16,7 @@ struct kv_db_ops {
        int (*finish_write)(struct ltdb_private *);
        int (*error)(struct ltdb_private *ltdb);
        const char * (*name)(struct ltdb_private *ltdb);
+       bool (*has_changed)(struct ltdb_private *ltdb);
 };
 
 /* this private structure is used by the ltdb backend in the