client: add timeout argument to ctdb_attach
authorDavid Disseldorp <ddiss@suse.de>
Mon, 8 Aug 2011 14:35:56 +0000 (16:35 +0200)
committerDavid Disseldorp <ddiss@suse.de>
Tue, 6 Sep 2011 11:57:04 +0000 (13:57 +0200)
Rather than using a fixed 2 second CTDB_CONTROL_GETDBPATH timeout.

13 files changed:
client/ctdb_client.c
include/ctdb_client.h
server/ctdb_recoverd.c
tests/src/ctdb_bench.c
tests/src/ctdb_fetch.c
tests/src/ctdb_fetch_one.c
tests/src/ctdb_persistent.c
tests/src/ctdb_randrec.c
tests/src/ctdb_store.c
tests/src/ctdb_transaction.c
tests/src/ctdb_traverse.c
tools/ctdb.c
tools/ctdb_vacuum.c

index 55c32735d91c0282b1fec0f9df5b6088f44c273e..bd0e800b0e8d0e5df904b632e45aef7f61797f5f 100644 (file)
@@ -1696,7 +1696,11 @@ 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, uint32_t tdb_flags)
+struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
+                                   struct timeval timeout,
+                                   const char *name,
+                                   bool persistent,
+                                   uint32_t tdb_flags)
 {
        struct ctdb_db_context *ctdb_db;
        TDB_DATA data;
@@ -1731,7 +1735,7 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name,
        ctdb_db->db_id = *(uint32_t *)data.dptr;
        talloc_free(data.dptr);
 
-       ret = ctdb_ctrl_getdbpath(ctdb, timeval_current_ofs(2, 0), CTDB_CURRENT_NODE, ctdb_db->db_id, ctdb_db, &ctdb_db->db_path);
+       ret = ctdb_ctrl_getdbpath(ctdb, timeout, CTDB_CURRENT_NODE, ctdb_db->db_id, ctdb_db, &ctdb_db->db_path);
        if (ret != 0) {
                DEBUG(DEBUG_ERR,("Failed to get dbpath for database '%s'\n", name));
                talloc_free(ctdb_db);
index baa720dea4779f5a9991ab72fdb0a73a8ba1e12e..95b907378a5930826e7ba12a28fca2b7a5cc69e8 100644 (file)
@@ -105,7 +105,12 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog,
 /*
   attach to a ctdb database
 */
-struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags);
+struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
+                                   struct timeval timeout,
+                                   const char *name,
+                                   bool persistent,
+                                   uint32_t tdb_flags);
+
 
 /*
   find an attached ctdb_db handle given a name
index 2db9109532d60a06c76da735de740125bf9a1ec9..0fcfd3370d7605f9201bc452fed3b21043894946 100644 (file)
@@ -841,7 +841,7 @@ static void vacuum_fetch_handler(struct ctdb_context *ctdb, uint64_t srvid,
        }
 
        /* attach to it */
-       ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, CONTROL_TIMEOUT(), name, persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                talloc_free(tmp_ctx);
index cdd176ac84d128025e86f352b1f7913b349ca434..8e0e0d79561649a70ff956f9c7c47e61a72e0bf7 100644 (file)
@@ -225,7 +225,8 @@ int main(int argc, const char *argv[])
        ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+       ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb",
+                             false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index b97e2ef0230a2e969f6cfc1e15100238a0b0b323..f0311c8948e0e590046e13a9b6bac0c2eb2c11ff 100644 (file)
@@ -218,7 +218,8 @@ int main(int argc, const char *argv[])
                                 &cluster_ready);
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+       ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb",
+                             false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index f8fa466699073b43de3b658a5e4e9d3c9fd93a33..042e605f9684e41dc07f691606d432d636fb3b08 100644 (file)
@@ -122,7 +122,8 @@ int main(int argc, const char *argv[])
        }
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+       ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb",
+                             false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index bf975c61025161c1abc25718edfaaaa4949dfcc7..98c100f4ed14104dfacb2c137eee8498db913685 100644 (file)
@@ -228,9 +228,11 @@ int main(int argc, const char *argv[])
 
        /* attach to a specific database */
        if (unsafe_writes == 1) {
-               ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true, TDB_NOSYNC);
+               ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0),
+                                     "persistent.tdb", true, TDB_NOSYNC);
        } else {
-               ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true, 0);
+               ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0),
+                                     "persistent.tdb", true, 0);
        }
 
        if (!ctdb_db) {
index 128ffc877f6268be6d5cec4e7fa1d91d37d8fc5f..dbaa4ba0fc864fa31ed2f34500aefdf03d65bd2d 100644 (file)
@@ -189,7 +189,8 @@ int main(int argc, const char *argv[])
        }
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+       ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb",
+                             false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index ea1486c0a0cccff66f8891a744af62a9b4efb8c7..c657f7850e4dbe7abac9a763d5c18fe3836353eb 100644 (file)
@@ -144,7 +144,7 @@ int main(int argc, const char *argv[])
        }
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
+       ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), "test.tdb", false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index 1eba5c860321b56b0cf1a90aee1516a68bef7456..65088747176ce5b05fab93206e70c319884bea07 100644 (file)
@@ -260,9 +260,11 @@ int main(int argc, const char *argv[])
 
        /* attach to a specific database */
        if (unsafe_writes == 1) {
-               ctdb_db = ctdb_attach(ctdb, "transaction.tdb", true, TDB_NOSYNC);
+               ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0),
+                                     "transaction.tdb", true, TDB_NOSYNC);
        } else {
-               ctdb_db = ctdb_attach(ctdb, "transaction.tdb", true, 0);
+               ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0),
+                                     "transaction.tdb", true, 0);
        }
 
        if (!ctdb_db) {
index 4d523f27ea9afd810910e33f80d7dd468c2a9571..218e7f777ded426e531365a8b9e2123633f44fb8 100644 (file)
@@ -92,7 +92,7 @@ int main(int argc, const char *argv[])
        ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, dbname, false, 0);
+       ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(2, 0), dbname, false, 0);
        if (!ctdb_db) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
index e9c8b91492c765ea2aafef97bcd165f9f7194d0a..e30302b2180808caa7e428449205687af064c767 100644 (file)
@@ -2983,7 +2983,7 @@ static int control_catdb(struct ctdb_context *ctdb, int argc, const char **argv)
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
 
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
@@ -3029,7 +3029,7 @@ static int control_readkey(struct ctdb_context *ctdb, int argc, const char **arg
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
 
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
@@ -3078,7 +3078,7 @@ static int control_writekey(struct ctdb_context *ctdb, int argc, const char **ar
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
 
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
@@ -3142,7 +3142,7 @@ static int control_pfetch(struct ctdb_context *ctdb, int argc, const char **argv
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
 
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
@@ -3305,8 +3305,7 @@ static int control_pstore(struct ctdb_context *ctdb, int argc, const char **argv
 
        db_name = argv[0];
 
-       ctdb_db = ctdb_attach(ctdb, db_name, true, 0);
-
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, true, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
                talloc_free(tmp_ctx);
@@ -3950,7 +3949,7 @@ static int control_attach(struct ctdb_context *ctdb, int argc, const char **argv
                persistent = true;
        }
 
-       ctdb_db = ctdb_attach(ctdb, db_name, persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
                return -1;
@@ -4158,7 +4157,7 @@ static int control_backupdb(struct ctdb_context *ctdb, int argc, const char **ar
                                     allow_unhealthy));
        }
 
-       ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), argv[0], dbmap->dbs[i].persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", argv[0]));
                talloc_free(tmp_ctx);
@@ -4305,7 +4304,7 @@ static int control_restoredb(struct ctdb_context *ctdb, int argc, const char **a
                dbname, tbuf);
 
 
-       ctdb_db = ctdb_attach(ctdb, dbname, dbhdr.persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), dbname, dbhdr.persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", dbname));
                talloc_free(tmp_ctx);
@@ -4557,7 +4556,7 @@ static int control_wipedb(struct ctdb_context *ctdb, int argc,
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), argv[0], dbmap->dbs[i].persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR, ("Unable to attach to database '%s'\n",
                                  argv[0]));
index bd75a69e2564763b69e3f5ffbb467d8570e7df50..e5ed9515fda3e05090f73efb38b7745a88953fba 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, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), name, persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                talloc_free(vdata);
@@ -581,7 +581,7 @@ static int ctdb_repack_db(struct ctdb_context *ctdb, uint32_t db_id,
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), name, persistent, 0);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                return -1;