added support for a prepare_commit() op in ldb modules
authorAndrew Tridgell <tridge@samba.org>
Tue, 31 Mar 2009 04:07:54 +0000 (15:07 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 31 Mar 2009 04:07:54 +0000 (15:07 +1100)
This op will be used by the partition module to give us good
transaction semantics across the 4 partitions that sam.ldb uses.

source4/lib/ldb/external/libtdb.m4
source4/lib/ldb/include/ldb_module.h
source4/lib/ldb/ldb.mk
source4/lib/ldb/ldb_tdb/ldb_tdb.c
source4/lib/ldb/ldb_tdb/ldb_tdb.h
source4/min_versions.m4

index 8c2cab702fdf128dd72f6f41acb655dd5ee8b512..cdfc5ea2fbb0eac799ea10ce3cf65ac8f8751f67 100644 (file)
@@ -4,4 +4,4 @@ AC_SUBST(TDB_LIBS)
 
 AC_CHECK_HEADER(tdb.h,
    [AC_CHECK_LIB(tdb, tdb_open, [TDB_LIBS="-ltdb"]) ],
-   [PKG_CHECK_MODULES(TDB, tdb >= 1.1.0)])
+   [PKG_CHECK_MODULES(TDB, tdb >= 1.1.4)])
index 4e1019184d32471156dfb65ea5a0c0067723f506..e07fd43e27199ec89db2485190f4b3213ecda751 100644 (file)
@@ -52,6 +52,7 @@ struct ldb_module_ops {
        int (*request)(struct ldb_module *, struct ldb_request *); /* match any other operation */
        int (*extended)(struct ldb_module *, struct ldb_request *); /* extended operations */
        int (*start_transaction)(struct ldb_module *);
+       int (*prepare_commit)(struct ldb_module *);
        int (*end_transaction)(struct ldb_module *);
        int (*del_transaction)(struct ldb_module *);
        int (*sequence_number)(struct ldb_module *, struct ldb_request *);
index ff8c1f3baf16263665a62f1dd8ac1d8e0837a0b7..0589baf5d4aa44ef210ee3898b96efd23c7b1122 100644 (file)
@@ -66,7 +66,7 @@ build-python:: ldb.$(SHLIBEXT)
 
 pyldb.o: $(ldbdir)/pyldb.c
        $(CC) $(PICFLAG) -c $(ldbdir)/pyldb.c $(CFLAGS) `$(PYTHON_CONFIG) --cflags`
-       
+
 ldb.$(SHLIBEXT): pyldb.o
        $(SHLD) $(SHLD_FLAGS) -o ldb.$(SHLIBEXT) pyldb.o $(LIB_FLAGS) `$(PYTHON_CONFIG) --ldflags`
 
index 9df62be93631baad29a71c60aea97ad2d75a2761..0f84b67afaa673c9dcd42400e32da0ddefeebbd1 100644 (file)
@@ -857,18 +857,46 @@ static int ltdb_start_trans(struct ldb_module *module)
        return LDB_SUCCESS;
 }
 
-static int ltdb_end_trans(struct ldb_module *module)
+static int ltdb_prepare_commit(struct ldb_module *module)
 {
        void *data = ldb_module_get_private(module);
        struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
 
-       ltdb->in_transaction--;
+       if (ltdb->in_transaction != 1) {
+               return LDB_SUCCESS;
+       }
 
        if (ltdb_index_transaction_commit(module) != 0) {
                tdb_transaction_cancel(ltdb->tdb);
+               ltdb->in_transaction--;
+               return ltdb_err_map(tdb_error(ltdb->tdb));
+       }
+
+       if (tdb_transaction_prepare_commit(ltdb->tdb) != 0) {
+               ltdb->in_transaction--;
                return ltdb_err_map(tdb_error(ltdb->tdb));
        }
 
+       ltdb->prepared_commit = true;
+
+       return LDB_SUCCESS;
+}
+
+static int ltdb_end_trans(struct ldb_module *module)
+{
+       void *data = ldb_module_get_private(module);
+       struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
+
+       if (!ltdb->prepared_commit) {
+               int ret = ltdb_prepare_commit(module);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
+               }
+       }
+
+       ltdb->in_transaction--;
+       ltdb->prepared_commit = false;
+
        if (tdb_transaction_commit(ltdb->tdb) != 0) {
                return ltdb_err_map(tdb_error(ltdb->tdb));
        }
@@ -1209,6 +1237,7 @@ static const struct ldb_module_ops ltdb_ops = {
        .extended          = ltdb_handle_request,
        .start_transaction = ltdb_start_trans,
        .end_transaction   = ltdb_end_trans,
+       .prepare_commit    = ltdb_prepare_commit,
        .del_transaction   = ltdb_del_trans,
 };
 
index 5a1c8fee2d7482948754bcc5e264c914e8da2d79..370cd0729b589c17ce105339cb0a1a989747826a 100644 (file)
@@ -30,6 +30,7 @@ struct ltdb_private {
 
        bool check_base;
        struct ltdb_idxptr *idxptr;
+       bool prepared_commit;
 };
 
 /*
index 1dd3501b992f09d1ac7538776b800b636689a0ec..c7892a2108cc1aa732ce53c465a9e81fdb0dbdbf 100644 (file)
@@ -1,6 +1,6 @@
 # Minimum and exact required versions for various libraries 
 # if we use the ones installed in the system.
-define(TDB_MIN_VERSION,1.1.3)
+define(TDB_MIN_VERSION,1.1.4)
 define(TALLOC_MIN_VERSION,1.3.0)
 define(LDB_REQUIRED_VERSION,0.9.3)
 define(TEVENT_REQUIRED_VERSION,0.9.5)