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;
}
}
}
- 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 */
/* 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;
}
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,
.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,
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