static int ldb_kv_end_trans(struct ldb_module *module)
{
	int ret;
	void *data = ldb_module_get_private(module);
	struct ldb_kv_private *ldb_kv =
	    talloc_get_type(data, struct ldb_kv_private);

	/*
	 * If in batch mode and there has been an operation failure
	 * rollback the transaction rather than committing it to avoid
	 * any possible corruption
	 */
	if (ldb_kv->batch_mode && ldb_kv->operation_failed) {
		ret = ldb_kv_del_trans( module);
		if (ret != LDB_SUCCESS) {
			ldb_debug_set(ldb_module_get_ctx(module),
				      LDB_DEBUG_FATAL,
				      "An operation failed during a batch mode "
				      "transaction. The transaction could not"
				      "be rolled back, ldb_kv_del_trans "
				      "returned (%s, %s)",
				      ldb_kv->kv_ops->errorstr(ldb_kv),
				      ldb_strerror(ret));
		} else {
			ldb_debug_set(ldb_module_get_ctx(module),
				      LDB_DEBUG_FATAL,
				      "An operation failed during a batch mode "
				      "transaction, the transaction was "
				      "rolled back");
		}
		return LDB_ERR_OPERATIONS_ERROR;
	}

	if (!ldb_kv->prepared_commit) {
		ret = ldb_kv_prepare_commit(module);
		if (ret != LDB_SUCCESS) {
			return ret;
		}
	}

	ldb_kv->prepared_commit = false;

	if (ldb_kv->kv_ops->finish_write(ldb_kv) != 0) {
		ret = ldb_kv->kv_ops->error(ldb_kv);
		ldb_asprintf_errstring(
		    ldb_module_get_ctx(module),
		    "Failure during tdb_transaction_commit(): %s -> %s",
		    ldb_kv->kv_ops->errorstr(ldb_kv),
		    ldb_strerror(ret));
		return ret;
	}

	return LDB_SUCCESS;
}
static int ldb_kv_end_trans(struct ldb_module *module)
{
	int ret;
	void *data = ldb_module_get_private(module);
	struct ldb_kv_private *ldb_kv =
	    talloc_get_type(data, struct ldb_kv_private);

	 
	if (ldb_kv->batch_mode && ldb_kv->operation_failed) {
		ret = ldb_kv_del_trans( module);
		if (ret != LDB_SUCCESS) {
			ldb_debug_set(ldb_module_get_ctx(module),
				      LDB_DEBUG_FATAL,
				      "An operation failed during a batch mode "
				      "transaction. The transaction could not"
				      "be rolled back, ldb_kv_del_trans "
				      "returned (%s, %s)",
				      ldb_kv->kv_ops->errorstr(ldb_kv),
				      ldb_strerror(ret));
		} else {
			ldb_debug_set(ldb_module_get_ctx(module),
				      LDB_DEBUG_FATAL,
				      "An operation failed during a batch mode "
				      "transaction, the transaction was "
				      "rolled back");
		}
		return LDB_ERR_OPERATIONS_ERROR;
	}

	if (!ldb_kv->prepared_commit) {
		ret = ldb_kv_prepare_commit(module);
		if (ret != LDB_SUCCESS) {
			return ret;
		}
	}

	ldb_kv->prepared_commit = false;

	if (ldb_kv->kv_ops->finish_write(ldb_kv) != 0) {
		ret = ldb_kv->kv_ops->error(ldb_kv);
		ldb_asprintf_errstring(
		    ldb_module_get_ctx(module),
		    "Failure during tdb_transaction_commit(): %s -> %s",
		    ldb_kv->kv_ops->errorstr(ldb_kv),
		    ldb_strerror(ret));
		return ret;
	}

	return LDB_SUCCESS;
}