mirror of
https://github.com/samba-team/samba.git
synced 2025-02-26 21:57:41 +03:00
lib ldb key value backends: Add nested txn support
Add limited nested transaction support to the back ends to make the key value operations atomic (for those back ends that support nested transactions). Note: that only the lmdb backend currently supports nested transactions. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
d73bbf0b73
commit
d7dc4fde40
@ -51,6 +51,9 @@ struct kv_db_ops {
|
||||
bool (*has_changed)(struct ldb_kv_private *ldb_kv);
|
||||
bool (*transaction_active)(struct ldb_kv_private *ldb_kv);
|
||||
size_t (*get_size)(struct ldb_kv_private *ldb_kv);
|
||||
int (*begin_nested_write)(struct ldb_kv_private *);
|
||||
int (*finish_nested_write)(struct ldb_kv_private *);
|
||||
int (*abort_nested_write)(struct ldb_kv_private *);
|
||||
};
|
||||
|
||||
/* this private structure is used by the key value backends in the
|
||||
|
@ -739,6 +739,36 @@ static size_t lmdb_get_size(struct ldb_kv_private *ldb_kv)
|
||||
return stats.ms_entries;
|
||||
}
|
||||
|
||||
/*
|
||||
* Start a sub transaction
|
||||
* As lmdb supports nested transactions we can start a new transaction
|
||||
*/
|
||||
static int lmdb_nested_transaction_start(struct ldb_kv_private *ldb_kv)
|
||||
{
|
||||
int ret = lmdb_transaction_start(ldb_kv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Commit a sub transaction
|
||||
* As lmdb supports nested transactions we can commit the nested transaction
|
||||
*/
|
||||
static int lmdb_nested_transaction_commit(struct ldb_kv_private *ldb_kv)
|
||||
{
|
||||
int ret = lmdb_transaction_commit(ldb_kv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Cancel a sub transaction
|
||||
* As lmdb supports nested transactions we can cancel the nested transaction
|
||||
*/
|
||||
static int lmdb_nested_transaction_cancel(struct ldb_kv_private *ldb_kv)
|
||||
{
|
||||
int ret = lmdb_transaction_cancel(ldb_kv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct kv_db_ops lmdb_key_value_ops = {
|
||||
.options = LDB_KV_OPTION_STABLE_READ_LOCK,
|
||||
|
||||
@ -760,6 +790,9 @@ static struct kv_db_ops lmdb_key_value_ops = {
|
||||
.has_changed = lmdb_changed,
|
||||
.transaction_active = lmdb_transaction_active,
|
||||
.get_size = lmdb_get_size,
|
||||
.begin_nested_write = lmdb_nested_transaction_start,
|
||||
.finish_nested_write = lmdb_nested_transaction_commit,
|
||||
.abort_nested_write = lmdb_nested_transaction_cancel,
|
||||
};
|
||||
|
||||
static const char *lmdb_get_path(const char *url)
|
||||
|
@ -437,6 +437,36 @@ static size_t ltdb_get_size(struct ldb_kv_private *ldb_kv)
|
||||
return size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Start a sub transaction
|
||||
* As TDB does not currently support nested transactions, we do nothing and
|
||||
* return LDB_SUCCESS
|
||||
*/
|
||||
static int ltdb_nested_transaction_start(struct ldb_kv_private *ldb_kv)
|
||||
{
|
||||
return LDB_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Commit a sub transaction
|
||||
* As TDB does not currently support nested transactions, we do nothing and
|
||||
* return LDB_SUCCESS
|
||||
*/
|
||||
static int ltdb_nested_transaction_commit(struct ldb_kv_private *ldb_kv)
|
||||
{
|
||||
return LDB_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Cancel a sub transaction
|
||||
* As TDB does not currently support nested transactions, we do nothing and
|
||||
* return LDB_SUCCESS
|
||||
*/
|
||||
static int ltdb_nested_transaction_cancel(struct ldb_kv_private *ldb_kv)
|
||||
{
|
||||
return LDB_SUCCESS;
|
||||
}
|
||||
|
||||
static const struct kv_db_ops key_value_ops = {
|
||||
/* No support for any additional features */
|
||||
.options = 0,
|
||||
@ -459,6 +489,9 @@ static const struct kv_db_ops key_value_ops = {
|
||||
.has_changed = ltdb_changed,
|
||||
.transaction_active = ltdb_transaction_active,
|
||||
.get_size = ltdb_get_size,
|
||||
.begin_nested_write = ltdb_nested_transaction_start,
|
||||
.finish_nested_write = ltdb_nested_transaction_commit,
|
||||
.abort_nested_write = ltdb_nested_transaction_cancel,
|
||||
};
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user