mirror of
https://github.com/samba-team/samba.git
synced 2025-02-19 21:57:57 +03:00
r16071: tdb has nested transactions
change the code to exploit that in ldb I still have to reintroduce transactions when you call ldb_request directly, I have some plans I hop to be able to develop in the next weekend (This used to be commit 35111206021d667dfd217b5fd8d82f5c2714cc9e)
This commit is contained in:
parent
2ed444de43
commit
2452d41b22
@ -171,13 +171,11 @@ void ldb_reset_err_string(struct ldb_context *ldb)
|
|||||||
/*
|
/*
|
||||||
start a transaction
|
start a transaction
|
||||||
*/
|
*/
|
||||||
int ldb_transaction_start(struct ldb_context *ldb)
|
static int ldb_transaction_start_internal(struct ldb_context *ldb)
|
||||||
{
|
{
|
||||||
struct ldb_module *module;
|
struct ldb_module *module;
|
||||||
int status;
|
int status;
|
||||||
FIRST_OP(ldb, start_transaction);
|
FIRST_OP(ldb, start_transaction);
|
||||||
|
|
||||||
ldb->transaction_active++;
|
|
||||||
|
|
||||||
ldb_reset_err_string(ldb);
|
ldb_reset_err_string(ldb);
|
||||||
|
|
||||||
@ -195,18 +193,12 @@ int ldb_transaction_start(struct ldb_context *ldb)
|
|||||||
/*
|
/*
|
||||||
commit a transaction
|
commit a transaction
|
||||||
*/
|
*/
|
||||||
int ldb_transaction_commit(struct ldb_context *ldb)
|
static int ldb_transaction_commit_internal(struct ldb_context *ldb)
|
||||||
{
|
{
|
||||||
struct ldb_module *module;
|
struct ldb_module *module;
|
||||||
int status;
|
int status;
|
||||||
FIRST_OP(ldb, end_transaction);
|
FIRST_OP(ldb, end_transaction);
|
||||||
|
|
||||||
if (ldb->transaction_active > 0) {
|
|
||||||
ldb->transaction_active--;
|
|
||||||
} else {
|
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
ldb_reset_err_string(ldb);
|
ldb_reset_err_string(ldb);
|
||||||
|
|
||||||
status = module->ops->end_transaction(module);
|
status = module->ops->end_transaction(module);
|
||||||
@ -223,18 +215,12 @@ int ldb_transaction_commit(struct ldb_context *ldb)
|
|||||||
/*
|
/*
|
||||||
cancel a transaction
|
cancel a transaction
|
||||||
*/
|
*/
|
||||||
int ldb_transaction_cancel(struct ldb_context *ldb)
|
static int ldb_transaction_cancel_internal(struct ldb_context *ldb)
|
||||||
{
|
{
|
||||||
struct ldb_module *module;
|
struct ldb_module *module;
|
||||||
int status;
|
int status;
|
||||||
FIRST_OP(ldb, del_transaction);
|
FIRST_OP(ldb, del_transaction);
|
||||||
|
|
||||||
if (ldb->transaction_active > 0) {
|
|
||||||
ldb->transaction_active--;
|
|
||||||
} else {
|
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = module->ops->del_transaction(module);
|
status = module->ops->del_transaction(module);
|
||||||
if (status != LDB_SUCCESS) {
|
if (status != LDB_SUCCESS) {
|
||||||
if (ldb->err_string == NULL) {
|
if (ldb->err_string == NULL) {
|
||||||
@ -246,6 +232,89 @@ int ldb_transaction_cancel(struct ldb_context *ldb)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ldb_transaction_start(struct ldb_context *ldb)
|
||||||
|
{
|
||||||
|
/* disable autotransactions */
|
||||||
|
ldb->transaction_active++;
|
||||||
|
|
||||||
|
return ldb_transaction_start_internal(ldb);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ldb_transaction_commit(struct ldb_context *ldb)
|
||||||
|
{
|
||||||
|
/* renable autotransactions (when we reach 0) */
|
||||||
|
if (ldb->transaction_active > 0)
|
||||||
|
ldb->transaction_active--;
|
||||||
|
|
||||||
|
return ldb_transaction_commit_internal(ldb);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ldb_transaction_cancel(struct ldb_context *ldb)
|
||||||
|
{
|
||||||
|
/* renable autotransactions (when we reach 0) */
|
||||||
|
if (ldb->transaction_active > 0)
|
||||||
|
ldb->transaction_active--;
|
||||||
|
|
||||||
|
return ldb_transaction_cancel_internal(ldb);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ldb_autotransaction_start(struct ldb_context *ldb)
|
||||||
|
{
|
||||||
|
/* explicit transaction active, ignore autotransaction request */
|
||||||
|
if (ldb->transaction_active)
|
||||||
|
return LDB_SUCCESS;
|
||||||
|
|
||||||
|
return ldb_transaction_start_internal(ldb);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ldb_autotransaction_commit(struct ldb_context *ldb)
|
||||||
|
{
|
||||||
|
/* explicit transaction active, ignore autotransaction request */
|
||||||
|
if (ldb->transaction_active)
|
||||||
|
return LDB_SUCCESS;
|
||||||
|
|
||||||
|
return ldb_transaction_commit_internal(ldb);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ldb_autotransaction_cancel(struct ldb_context *ldb)
|
||||||
|
{
|
||||||
|
/* explicit transaction active, ignore autotransaction request */
|
||||||
|
if (ldb->transaction_active)
|
||||||
|
return LDB_SUCCESS;
|
||||||
|
|
||||||
|
return ldb_transaction_cancel_internal(ldb);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* autostarts a transacion if none active */
|
||||||
|
static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_request *req)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ldb_autotransaction_start(ldb);
|
||||||
|
if (ret != LDB_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ldb_request(ldb, req);
|
||||||
|
if (ret == LDB_SUCCESS) {
|
||||||
|
ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == LDB_SUCCESS) {
|
||||||
|
return ldb_autotransaction_commit(ldb);
|
||||||
|
}
|
||||||
|
ldb_autotransaction_cancel(ldb);
|
||||||
|
|
||||||
|
if (ldb->err_string == NULL) {
|
||||||
|
/* no error string was setup by the backend */
|
||||||
|
ldb_set_errstring(ldb,
|
||||||
|
talloc_asprintf(ldb, "%s (%d)",
|
||||||
|
ldb_strerror(ret), ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int ldb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type)
|
int ldb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type)
|
||||||
{
|
{
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
@ -461,42 +530,6 @@ int ldb_search(struct ldb_context *ldb,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* autostarts a transacion if none active */
|
|
||||||
static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_request *req)
|
|
||||||
{
|
|
||||||
int ret, close_transaction;
|
|
||||||
|
|
||||||
close_transaction = 0;
|
|
||||||
if (!ldb->transaction_active) {
|
|
||||||
ret = ldb_transaction_start(ldb);
|
|
||||||
if (ret != LDB_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
close_transaction = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = ldb_request(ldb, req);
|
|
||||||
if (ret == LDB_SUCCESS) {
|
|
||||||
ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (close_transaction) {
|
|
||||||
if (ret == LDB_SUCCESS) {
|
|
||||||
return ldb_transaction_commit(ldb);
|
|
||||||
}
|
|
||||||
ldb_transaction_cancel(ldb);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ldb->err_string == NULL) {
|
|
||||||
/* no error string was setup by the backend */
|
|
||||||
ldb_set_errstring(ldb,
|
|
||||||
talloc_asprintf(ldb, "%s (%d)",
|
|
||||||
ldb_strerror(ret), ret));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
add a record to the database. Will fail if a record with the given class and key
|
add a record to the database. Will fail if a record with the given class and key
|
||||||
|
Loading…
x
Reference in New Issue
Block a user