r10406: added --nosync option to all ldb tools, so that you can control if
authorAndrew Tridgell <tridge@samba.org>
Thu, 22 Sep 2005 04:16:46 +0000 (04:16 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:38:41 +0000 (13:38 -0500)
transactions are synchronous or not on the command line.

add LDB_FLG_NOSYNC flag to ldb_connect() so we can make our temporary
ldb databases non-synchronous

source/lib/ldb/include/ldb.h
source/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
source/lib/ldb/ldb_tdb/ldb_tdb.c
source/lib/ldb/tools/cmdline.c
source/lib/ldb/tools/cmdline.h
source/lib/ldb/tools/ldbtest.c

index 008327eb0550849476b57eb4c5adad2e8197d86e..f7abd920ebcd3e0ad553a15349bc87be0f6913f2 100644 (file)
@@ -158,6 +158,7 @@ struct ldb_debug_ops {
 };
 
 #define LDB_FLG_RDONLY 1
+#define LDB_FLG_NOSYNC 2
 
 #ifndef PRINTF_ATTRIBUTE
 #define PRINTF_ATTRIBUTE(a,b)
index 8742b5396246176e871cb22b5d4c9848557e96bb..ac706291ef911b714fb95496505f54ba5e2fac52 100644 (file)
@@ -1522,7 +1522,7 @@ static int lsqlite3_end_trans(struct ldb_module *module, int status)
  */
 
 static int initialize(struct lsqlite3_private *lsqlite3,
-                       struct ldb_context *ldb, const char *url)
+                     struct ldb_context *ldb, const char *url, int flags)
 {
        TALLOC_CTX *local_ctx;
         long long queryInt;
@@ -1648,14 +1648,16 @@ static int initialize(struct lsqlite3_private *lsqlite3,
                goto failed;
        }
         
-       /* DANGEROUS */
-       ret = sqlite3_exec(lsqlite3->sqlite, "PRAGMA synchronous = OFF;", NULL, NULL, &errmsg);
-       if (ret != SQLITE_OK) {
-               if (errmsg) {
-                       printf("lsqlite3 initializaion error: %s\n", errmsg);
-                       free(errmsg);
+       if (flags & LDB_FLG_NOSYNC) {
+               /* DANGEROUS */
+               ret = sqlite3_exec(lsqlite3->sqlite, "PRAGMA synchronous = OFF;", NULL, NULL, &errmsg);
+               if (ret != SQLITE_OK) {
+                       if (errmsg) {
+                               printf("lsqlite3 initializaion error: %s\n", errmsg);
+                               free(errmsg);
+                       }
+                       goto failed;
                }
-               goto failed;
        }
         
        /* */
@@ -1836,7 +1838,7 @@ int lsqlite3_connect(struct ldb_context *ldb,
        lsqlite3->options = NULL;
        lsqlite3->trans_count = 0;
         
-       ret = initialize(lsqlite3, ldb, url);
+       ret = initialize(lsqlite3, ldb, url, flags);
        if (ret != SQLITE_OK) {
                goto failed;
        }
index c056bd2e2d8605215d67984525e8cde4e0d630e1..a2faaa805f4eb8348f1a61d3db804d989bf08591 100644 (file)
@@ -895,11 +895,10 @@ int ltdb_connect(struct ldb_context *ldb, const char *url,
 
        tdb_flags = TDB_DEFAULT;
 
-#if 0
-       /* set this to run tdb without disk sync, but still with
-          transactions */
-       tdb_flags |= TDB_NOSYNC;
-#endif
+       /* check for the 'nosync' option */
+       if (flags & LDB_FLG_NOSYNC) {
+               tdb_flags |= TDB_NOSYNC;
+       }
 
        if (flags & LDB_FLG_RDONLY) {
                open_flags = O_RDONLY;
index fb0292b7d9ea8c6b9be43916e280b386ee65b0ce..7cdecc334f8948e551255d90231dcf7aa1898d0b 100644 (file)
@@ -55,6 +55,7 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
                { "num-searches", 0, POPT_ARG_INT, &options.num_searches, 0, "number of test searches", NULL },
                { "num-records", 0, POPT_ARG_INT, &options.num_records, 0, "number of test records", NULL },
                { "all", 'a',    POPT_ARG_NONE, &options.all_records, 0, "dn=*", NULL },
+               { "nosync", 0,   POPT_ARG_NONE, &options.nosync, 0, "non-synchronous transactions", NULL },
                { "sorted", 'S', POPT_ARG_NONE, &options.sorted, 0, "sort attributes", NULL },
                { "sasl-mechanism", 0, POPT_ARG_STRING, &options.sasl_mechanism, 0, "choose SASL mechanism", "MECHANISM" },
                { "input", 'I', POPT_ARG_STRING, &options.input, 0, "Input File", "Input" },
@@ -159,7 +160,11 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
        }
 
        if (strcmp(ret->url, "NONE") != 0) {
-               if (ldb_connect(ldb, ret->url, 0, ret->options) != 0) {
+               int flags = 0;
+               if (options.nosync) {
+                       flags |= LDB_FLG_NOSYNC;
+               }
+               if (ldb_connect(ldb, ret->url, flags, ret->options) != 0) {
                        fprintf(stderr, "Failed to connect to %s - %s\n", 
                                ret->url, ldb_errstring(ldb));
                        goto failed;
index daf9c06f429ddbd683a59fdb967e345fe15d327c..9aaf37a9781b2b78d2c63633b7b15008eb6612be 100644 (file)
@@ -34,6 +34,7 @@ struct ldb_cmdline {
        int verbose;
        int recursive;
        int all_records;
+       int nosync;
        const char **options;
        int argc;
        const char **argv;
index eeedd49e84ec36f60f93778e6bb7e3c16efcd85d..08ce99d20ff75b3652e12f17df7712cb4e422db5 100644 (file)
@@ -299,6 +299,11 @@ static void start_test_index(struct ldb_context **ldb)
        struct ldb_dn *indexlist;
        struct ldb_dn *basedn;
        int ret;
+       int flags = 0;
+
+       if (options->nosync) {
+               flags |= LDB_FLG_NOSYNC;
+       }
 
        printf("Starting index test\n");
 
@@ -337,7 +342,7 @@ static void start_test_index(struct ldb_context **ldb)
 
        (*ldb) = ldb_init(options);
        
-       ret = ldb_connect(*ldb, options->url, 0, NULL);
+       ret = ldb_connect(*ldb, options->url, flags, NULL);
        if (ret != 0) {
                printf("failed to connect to %s\n", options->url);
                exit(1);