[PATCH 2/3] client: add timeout argument to ctdb_attach
David Disseldorp
ddiss at suse.de
Wed Aug 24 05:05:12 MDT 2011
Rather than using a fixed 2 second CTDB_CONTROL_GETDBPATH timeout.
---
client/ctdb_client.c | 8 ++++++--
include/ctdb.h | 6 +++++-
server/ctdb_recoverd.c | 2 +-
tests/src/ctdb_bench.c | 3 ++-
tests/src/ctdb_fetch.c | 3 ++-
tests/src/ctdb_fetch_one.c | 3 ++-
tests/src/ctdb_persistent.c | 6 ++++--
tests/src/ctdb_randrec.c | 3 ++-
tests/src/ctdb_store.c | 2 +-
tests/src/ctdb_transaction.c | 6 ++++--
tests/src/ctdb_traverse.c | 2 +-
tools/ctdb.c | 10 +++++-----
tools/ctdb_vacuum.c | 4 ++--
13 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index 2d3c176..7633e62 100644
--- a/client/ctdb_client.c
+++ b/client/ctdb_client.c
@@ -1671,7 +1671,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;
@@ -1706,7 +1710,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);
diff --git a/include/ctdb.h b/include/ctdb.h
index de44503..1c94c4c 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -214,7 +214,11 @@ 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
diff --git a/server/ctdb_recoverd.c b/server/ctdb_recoverd.c
index 93af64e..e502aed 100644
--- a/server/ctdb_recoverd.c
+++ b/server/ctdb_recoverd.c
@@ -844,7 +844,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);
diff --git a/tests/src/ctdb_bench.c b/tests/src/ctdb_bench.c
index c56aec1..0b93429 100644
--- a/tests/src/ctdb_bench.c
+++ b/tests/src/ctdb_bench.c
@@ -220,7 +220,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);
diff --git a/tests/src/ctdb_fetch.c b/tests/src/ctdb_fetch.c
index d0e78f1..c3bd008 100644
--- a/tests/src/ctdb_fetch.c
+++ b/tests/src/ctdb_fetch.c
@@ -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);
diff --git a/tests/src/ctdb_fetch_one.c b/tests/src/ctdb_fetch_one.c
index 5fd9de9..4bb1d9f 100644
--- a/tests/src/ctdb_fetch_one.c
+++ b/tests/src/ctdb_fetch_one.c
@@ -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);
diff --git a/tests/src/ctdb_persistent.c b/tests/src/ctdb_persistent.c
index 85cd457..a2c4813 100644
--- a/tests/src/ctdb_persistent.c
+++ b/tests/src/ctdb_persistent.c
@@ -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) {
diff --git a/tests/src/ctdb_randrec.c b/tests/src/ctdb_randrec.c
index 8600bb3..11ab59d 100644
--- a/tests/src/ctdb_randrec.c
+++ b/tests/src/ctdb_randrec.c
@@ -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);
diff --git a/tests/src/ctdb_store.c b/tests/src/ctdb_store.c
index e9d7aa0..a1ad16f 100644
--- a/tests/src/ctdb_store.c
+++ b/tests/src/ctdb_store.c
@@ -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);
diff --git a/tests/src/ctdb_transaction.c b/tests/src/ctdb_transaction.c
index 2c60b95..dc2b20d 100644
--- a/tests/src/ctdb_transaction.c
+++ b/tests/src/ctdb_transaction.c
@@ -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) {
diff --git a/tests/src/ctdb_traverse.c b/tests/src/ctdb_traverse.c
index 4616d01..3baa6e5 100644
--- a/tests/src/ctdb_traverse.c
+++ b/tests/src/ctdb_traverse.c
@@ -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);
diff --git a/tools/ctdb.c b/tools/ctdb.c
index 25a6165..42478d4 100644
--- a/tools/ctdb.c
+++ b/tools/ctdb.c
@@ -2701,7 +2701,7 @@ static int control_catdb(struct ctdb_context *ctdb, int argc, const char **argv)
return -1;
}
- ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, false, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
@@ -3306,7 +3306,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, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), db_name, false, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
return -1;
@@ -3514,7 +3514,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);
@@ -3652,7 +3652,7 @@ static int control_restoredb(struct ctdb_context *ctdb, int argc, const char **a
dbhdr.name, tbuf);
- ctdb_db = ctdb_attach(ctdb, dbhdr.name, dbhdr.persistent, 0);
+ ctdb_db = ctdb_attach(ctdb, TIMELIMIT(), dbhdr.name, dbhdr.persistent, 0);
if (ctdb_db == NULL) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", dbhdr.name));
talloc_free(tmp_ctx);
@@ -3904,7 +3904,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]));
diff --git a/tools/ctdb_vacuum.c b/tools/ctdb_vacuum.c
index bd45287..e645cd3 100644
--- a/tools/ctdb_vacuum.c
+++ b/tools/ctdb_vacuum.c
@@ -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;
--
1.7.1
More information about the samba-technical
mailing list