use transactions in ldbadd, ldbmodify and ldbedit
authorAndrew Tridgell <tridge@samba.org>
Tue, 16 Dec 2008 03:39:42 +0000 (14:39 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 16 Dec 2008 03:39:42 +0000 (14:39 +1100)
The command line tools ldbadd, ldbmodify and ldbedit should operate
within a transaction to make them more efficient. The ldbadd tool in
particular is much faster when adding a large number of records if all
the adds happen within a transaction. Previously there was a
transaction per record.

source4/lib/ldb/tools/ldbadd.c
source4/lib/ldb/tools/ldbedit.c
source4/lib/ldb/tools/ldbmodify.c

index 15376e7342c18ba4a715ecaff97f5442dcd780c2..3749aec629db0f529e812eb67065e2660f079ee3 100644 (file)
@@ -92,6 +92,11 @@ int main(int argc, const char **argv)
 
        options = ldb_cmdline_process(ldb, argc, argv, usage);
 
+       if (ldb_transaction_start(ldb) != 0) {
+               printf("Failed to start transaction\n");
+               exit(1);
+       }
+
        if (options->argc == 0) {
                ret = process_file(ldb, stdin, &count);
        } else {
@@ -108,6 +113,11 @@ int main(int argc, const char **argv)
                }
        }
 
+       if (count != 0 && ldb_transaction_commit(ldb) != 0) {
+               printf("Failed to commit transaction\n");
+               exit(1);
+       }
+
        talloc_free(ldb);
 
        printf("Added %d records with %d failures\n", count, failures);
index b2a040cd09c94c8c25c6ed1574a2149c7d2467a4..b18aea1b10ca3e02db4a9ff1bcfbf4bb92375d5e 100644 (file)
@@ -112,6 +112,11 @@ static int merge_edits(struct ldb_context *ldb,
        int ret = 0;
        int adds=0, modifies=0, deletes=0;
 
+       if (ldb_transaction_start(ldb) != 0) {
+               fprintf(stderr, "Failed to start transaction\n");
+               return -1;
+       }
+
        /* do the adds and modifies */
        for (i=0;i<count2;i++) {
                msg = msg_find(ldb, msgs1, count1, msgs2[i]->dn);
@@ -150,6 +155,11 @@ static int merge_edits(struct ldb_context *ldb,
                }
        }
 
+       if (ldb_transaction_commit(ldb) != 0) {
+               fprintf(stderr, "Failed to commit transaction\n");
+               return -1;
+       }
+
        printf("# %d adds  %d modifies  %d deletes\n", adds, modifies, deletes);
 
        return ret;
index 6e355a10cf5e11af091d5544eb23e5a789c0f25d..8b6309e016af2ee5b85869e7c7a0f5e519d2f6b3 100644 (file)
@@ -91,6 +91,11 @@ int main(int argc, const char **argv)
 
        ldb = ldb_init(NULL, NULL);
 
+       if (ldb_transaction_start(ldb) != 0) {
+               printf("Failed to start transaction\n");
+               exit(1);
+       }
+
        options = ldb_cmdline_process(ldb, argc, argv, usage);
 
        if (options->argc == 0) {
@@ -108,6 +113,11 @@ int main(int argc, const char **argv)
                }
        }
 
+       if (count != 0 && ldb_transaction_commit(ldb) != 0) {
+               printf("Failed to commit transaction\n");
+               exit(1);
+       }
+
        talloc_free(ldb);
 
        printf("Modified %d records with %d failures\n", count, failures);