Skip to content

Commit

Permalink
ldb_tdb: Remove tdb_get_seqnum and use a generic 'has_changed'
Browse files Browse the repository at this point in the history
Signed-off-by: Garming Sam <[email protected]>
Reviewed-by: Andrew Bartlett <[email protected]>
  • Loading branch information
GSam authored and abartlet committed Mar 5, 2018
1 parent e21a476 commit c66a005
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/ldb/ldb_tdb/ldb_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/ldb/ldb_tdb/ldb_tdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/ldb/ldb_tdb/ldb_tdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c66a005

Please sign in to comment.