add a parameter for the tdb-flags to the client function
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 4 Jun 2008 00:46:20 +0000 (10:46 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 4 Jun 2008 00:46:20 +0000 (10:46 +1000)
ctdb_attach()   so that we can pass TDB_NOSYNC when we attach to
a persistent database and want fast unsafe writes instead of
slow but safe tdb_transaction writes.

enhance the ctdb_persistent test suite to test both safe and unsafe writes

12 files changed:
client/ctdb_client.c
include/ctdb.h
server/ctdb_recoverd.c
tests/ctdb_bench.c
tests/ctdb_fetch.c
tests/ctdb_persistent.c
tests/ctdb_randrec.c
tests/ctdb_store.c
tests/ctdb_traverse.c
tests/persistent.sh
tools/ctdb.c
tools/ctdb_vacuum.c

index 921392c84485bd6d067a5ddbd6103685289041c8..04befd05cb63f031a4be1485f2a096802c48fe9e 100644 (file)
@@ -1640,7 +1640,7 @@ static int ctdb_fetch_func(struct ctdb_call_info *call)
 /*
   attach to a specific database - client call
 */
-struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent)
+struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags)
 {
        struct ctdb_db_context *ctdb_db;
        TDB_DATA data;
@@ -1663,7 +1663,7 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name,
        data.dsize = strlen(name)+1;
 
        /* tell ctdb daemon to attach */
-       ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0
+       ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, tdb_flags
                           persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH,
                           0, data, ctdb_db, &data, &res, NULL, NULL);
        if (ret != 0 || res != 0 || data.dsize != sizeof(uint32_t)) {
index 95d3f2f3929f8910b2e7868ae806db17bc2d0e4d..ecbe9576d61cb8b69a80df3b7d319654436a0452 100644 (file)
@@ -185,7 +185,7 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
 /*
   attach to a ctdb database
 */
-struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent);
+struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags);
 
 /*
   find an attached ctdb_db handle given a name
index 9a338197372e8c0d3b24f955347a0536f4ec68ce..30b121ce16b935f334d1659c6b8e2824d2cf7e9a 100644 (file)
@@ -866,7 +866,7 @@ static void vacuum_fetch_handler(struct ctdb_context *ctdb, uint64_t srvid,
        }
 
        /* attach to it */
-       ctdb_db = ctdb_attach(ctdb, name, persistent);
+       ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                talloc_free(tmp_ctx);
index c14ef2b3cd5c09b201340bc086ec7f33573aafe0..2d6b3ab298b7484ae7587814c0c9e05584fd6b3e 100644 (file)
@@ -201,7 +201,7 @@ int main(int argc, const char *argv[])
                                 &cluster_ready);
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false);
+       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index 56eb244a704538c83d6212f32958aa5914cf88ae..2cc51d51bce9162eaf063377bcca524a8889a152 100644 (file)
@@ -219,7 +219,7 @@ int main(int argc, const char *argv[])
                                 &cluster_ready);
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false);
+       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index b98e662cc72697135d064a2237cd025d06d32b70..7bd4ab876983a22f8191929cb5cd9970539c3cd0 100644 (file)
@@ -167,11 +167,12 @@ int main(int argc, const char *argv[])
 {
        struct ctdb_context *ctdb;
        struct ctdb_db_context *ctdb_db;
-
+       int unsafe_writes = 0;
        struct poptOption popt_options[] = {
                POPT_AUTOHELP
                POPT_CTDB_CMDLINE
                { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
+               { "unsafe-writes", 'u', POPT_ARG_NONE, &unsafe_writes, 0, "do not use tdb transactions when writing", NULL },
                POPT_TABLEEND
        };
        int opt;
@@ -201,9 +202,18 @@ int main(int argc, const char *argv[])
        ev = event_context_init(NULL);
 
        ctdb = ctdb_cmdline_client(ev);
+       if (ctdb == NULL) {
+               printf("Could not attach to daemon\n");
+               return 1;
+       }
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true);
+       if (unsafe_writes == 1) {
+               ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true, TDB_NOSYNC);
+       } else {
+               ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true, 0);
+       }
+
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index 287b57c34ad4f0939b85e2e122fc609321130c80..4b9b2bc93efe593dd73d15fa32558f0d47f41c52 100644 (file)
@@ -143,7 +143,7 @@ int main(int argc, const char *argv[])
        ctdb = ctdb_cmdline_client(ev);
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false);
+       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index 70ce7fb59d732dc2fa4fc785c1c6d4890e8093f7..ce4195c65ff456c30a505b133ce945a102213949 100644 (file)
@@ -139,7 +139,7 @@ int main(int argc, const char *argv[])
        ctdb = ctdb_cmdline_client(ev);
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false);
+       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index 136dfbc20232fa4658cf55f180064852086a23ea..f5ca7159c40c4749086738a9544045cb1e0ab22e 100644 (file)
@@ -92,7 +92,7 @@ int main(int argc, const char *argv[])
        ctdb = ctdb_cmdline_client(ev);
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, dbname, false);
+       ctdb_db = ctdb_attach(ctdb, dbname, false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index d952786cd6f86c115f0855c800e997ef363a3470..327f8bcce9a4f5596494605b879806de2462874f 100755 (executable)
@@ -5,7 +5,8 @@ if [ $# -gt 0 ]; then
     NUMNODES=$1
 fi
 
-echo "Starting $NUMNODES daemons"
+
+echo "Starting $NUMNODES daemons for SAFE persistent writes"
 tests/start_daemons.sh $NUMNODES || exit 1
 
 killall -9 -q ctdb_persistent
@@ -17,5 +18,24 @@ wait
 
 echo "Shutting down"
 bin/ctdb shutdown -n all --socket=sock.1
+killall -9 ctdbd
+
+
+
+echo "Starting $NUMNODES daemons for UNSAFE persistent writes"
+tests/start_daemons.sh $NUMNODES || exit 1
+
+killall -9 -q ctdb_persistent
+
+for i in `seq 1 $NUMNODES`; do
+  $VALGRIND bin/ctdb_persistent --unsafe-writes --timelimit 30 --socket sock.$i $* &
+done
+wait
+
+echo "Shutting down"
+bin/ctdb shutdown -n all --socket=sock.1
+killall -9 ctdbd
+
+
 
 exit 0
index c8cfe80e5b1aaa72545ffab984a874baddfe89d9..6df78130d6e24c815f68c5897209e60735a67ae5 100644 (file)
@@ -1278,7 +1278,7 @@ static int control_catdb(struct ctdb_context *ctdb, int argc, const char **argv)
        }
 
        db_name = argv[0];
-       ctdb_db = ctdb_attach(ctdb, db_name, false);
+       ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
 
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
@@ -1633,7 +1633,7 @@ static int control_attach(struct ctdb_context *ctdb, int argc, const char **argv
        }
        db_name = argv[0];
 
-       ctdb_db = ctdb_attach(ctdb, db_name, false);
+       ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
                return -1;
index 1423582f0adfd44bcf187376eb74b48b16acd3ec..60a0b0a3ee7b410e054e63b79de9aebe70f58755 100644 (file)
@@ -260,7 +260,7 @@ static int ctdb_vacuum_db(struct ctdb_context *ctdb, uint32_t db_id, struct ctdb
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, name, persistent);
+       ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                talloc_free(vdata);
@@ -579,7 +579,7 @@ static int ctdb_repack_db(struct ctdb_context *ctdb, uint32_t db_id,
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, name, persistent);
+       ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                return -1;