remove the old ctdb_attach() function and move all callers over to the new ctdb_attac...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 17 May 2010 04:26:19 +0000 (14:26 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 17 May 2010 04:26:19 +0000 (14:26 +1000)
15 files changed:
client/ctdb_client.c
include/ctdb.h
include/ctdb_protocol.h
libctdb/libctdb.c
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 1552c414cc40d0801e970bbe0100c4a94184617c..56d8b5a729e746b77bbdcc4726d621bf8bce593f 100644 (file)
@@ -1022,100 +1022,6 @@ int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode)
        return 0;
 }
 
-/*
-  this is the dummy null procedure that all databases support
-*/
-static int ctdb_null_func(struct ctdb_call_info *call)
-{
-       return 0;
-}
-
-/*
-  this is a plain fetch procedure that all databases support
-*/
-static int ctdb_fetch_func(struct ctdb_call_info *call)
-{
-       call->reply_data = &call->record_data;
-       return 0;
-}
-
-
-
-/*
-  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_db;
-       int ret;
-       uint32_t db_id;
-       ctdb_handle *handle;
-
-       ctdb_db = ctdb_db_handle(ctdb, name);
-       if (ctdb_db) {
-               return ctdb_db;
-       }
-
-       ctdb_db = talloc_zero(ctdb, struct ctdb_db_context);
-       CTDB_NO_MEMORY_NULL(ctdb, ctdb_db);
-
-       ctdb_db->ctdb = ctdb;
-       ctdb_db->db_name = talloc_strdup(ctdb_db, name);
-       CTDB_NO_MEMORY_NULL(ctdb, ctdb_db->db_name);
-
-       /* tell ctdb daemon to attach */
-       handle = ctdb_createdb_send(ctdb, CTDB_CURRENT_NODE,
-                                   name, persistent, tdb_flags,
-                                   NULL, NULL);
-       if (handle == NULL) {
-               DEBUG(DEBUG_ERR, (__location__ " Failed to send CREATEDB control\n"));
-               talloc_free(ctdb_db);
-               return NULL;
-       }
-
-       ret = ctdb_createdb_recv(ctdb, handle, &db_id);
-       if (ret != 0) {
-               DEBUG(DEBUG_ERR,("Failed to attach to database '%s'\n", name));
-               talloc_free(ctdb_db);
-               return NULL;
-       }
-       
-       ctdb_db->db_id = db_id;
-
-       ret = ctdb_ctrl_getdbpath(ctdb, timeval_current_ofs(2, 0), 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);
-               return NULL;
-       }
-
-       tdb_flags = persistent?TDB_DEFAULT:TDB_NOSYNC;
-       if (ctdb->valgrinding) {
-               tdb_flags |= TDB_NOMMAP;
-       }
-       tdb_flags |= TDB_DISALLOW_NESTING;
-
-       ctdb_db->ltdb = tdb_wrap_open(ctdb, ctdb_db->db_path, 0, tdb_flags, O_RDWR, 0);
-       if (ctdb_db->ltdb == NULL) {
-               ctdb_set_error(ctdb, "Failed to open tdb '%s'\n", ctdb_db->db_path);
-               talloc_free(ctdb_db);
-               return NULL;
-       }
-
-       ctdb_db->persistent = persistent;
-
-       DLIST_ADD(ctdb->db_list, ctdb_db);
-
-       /* add well known functions */
-       ctdb_set_call(ctdb_db, ctdb_null_func, CTDB_NULL_FUNC);
-       ctdb_set_call(ctdb_db, ctdb_fetch_func, CTDB_FETCH_FUNC);
-
-       return ctdb_db;
-}
-
-
-
-
 struct traverse_state {
        bool done;
        uint32_t count;
index 7ccedaaff896c70e610a03f224f1782c5026b7b6..678189e2e61b336257557ec6519f49b829f04e8a 100644 (file)
@@ -75,13 +75,13 @@ struct ctdb_db_context;
 typedef void (*ctdb_attachdb_cb)(int32_t status, struct ctdb_db_context *ctdb_db, void *private_data);
 
 ctdb_handle *
-ctdb_attachdb_send(struct ctdb_context *ctdb, uint32_t destnode,
+ctdb_attachdb_send(struct ctdb_context *ctdb,
                   const char *name, int persistent, uint32_t tdb_flags,
                   ctdb_attachdb_cb callback,
                   void *private_data);
 int ctdb_attachdb_recv(struct ctdb_context *ctdb,
                       ctdb_handle *handle, struct ctdb_db_context **);
-int ctdb_attachdb(struct ctdb_context *ctdb, uint32_t destnode,
+int ctdb_attachdb(struct ctdb_context *ctdb,
                  const char *name, int persistent, uint32_t tdb_flags,
                  struct ctdb_db_context **);
 
index 16f8d1efe773748fe75a06331edada7e86ff3707..694fdae6d17bfa2726e2f91c5f5dc7715da942c2 100644 (file)
@@ -213,11 +213,6 @@ int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip);
 int ctdb_start(struct ctdb_context *ctdb);
 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);
-
 /*
   find an attached ctdb_db handle given a name
  */
index 64b35ba2e07ff3c377b9e27286d918d5617b6531..7e95431d2c57c15111135115e1b102fbfcd3bb8c 100644 (file)
@@ -729,7 +729,6 @@ int ctdb_getdbpath(struct ctdb_context *ctdb, uint32_t destnode,
 
 struct ctdb_attachdb_state {
        enum control_state state;
-       uint32_t destnode;
        struct ctdb_context *ctdb;
        struct ctdb_db_context *ctdb_db;
        struct ctdb_client_control_state *cdb_state;
@@ -836,7 +835,7 @@ ctdb_attachdb_recv1_cb(struct ctdb_client_control_state *state)
 
        adb_state->ctdb_db->db_id = *(uint32_t *)state->outdata.dptr;
 
-       adb_state->gdp_state = ctdb_getdbpath_send(adb_state->ctdb, adb_state->destnode, adb_state->ctdb_db->db_id, NULL, NULL);
+       adb_state->gdp_state = ctdb_getdbpath_send(adb_state->ctdb, CTDB_CURRENT_NODE, adb_state->ctdb_db->db_id, NULL, NULL);
        if (state == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " ctdb_getdbpath_send() failed.\n"));
                adb_state->state = CTDB_CONTROL_ERROR;
@@ -853,7 +852,7 @@ ctdb_attachdb_recv1_cb(struct ctdb_client_control_state *state)
 }
 
 ctdb_handle *
-ctdb_attachdb_send(struct ctdb_context *ctdb, uint32_t destnode,
+ctdb_attachdb_send(struct ctdb_context *ctdb,
                   const char *name, int persistent, uint32_t tdb_flags,
                   ctdb_attachdb_cb callback,
                   void *private_data)
@@ -883,7 +882,6 @@ ctdb_attachdb_send(struct ctdb_context *ctdb, uint32_t destnode,
        state->state      = CTDB_CONTROL_WAIT;
        state->ctdb       = ctdb;       
        state->ctdb_db    = ctdb_db;
-       state->destnode   = destnode;
        state->tdb_flags  = tdb_flags;
        state->persistent = persistent?True:False;
 
@@ -940,10 +938,25 @@ int ctdb_attachdb_recv(struct ctdb_context *ctdb,
        return 0;
 }
 
+int ctdb_attachdb(struct ctdb_context *ctdb,
+                 const char *name, int persistent, uint32_t tdb_flags,
+                 struct ctdb_db_context **ctdb_db)
+{
+       ctdb_handle *handle;
+       int ret;
 
+       handle = ctdb_attachdb_send(ctdb, name, persistent, tdb_flags, NULL, NULL);
+       if (handle == NULL) {
+               DEBUG(DEBUG_ERR, (__location__ " Failed to send attachdb control\n"));
+               return -1;
+       }
 
+       ret = ctdb_attachdb_recv(ctdb, handle, ctdb_db);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR, (__location__ " receive of attachdb reply failed\n"));
+               return -1;
+       }
 
-int ctdb_attachdb(struct ctdb_context *ctdb, uint32_t destnode,
-                 const char *name, int persistent, uint32_t tdb_flags,
-                 struct ctdb_db_context **);
+       return 0;
+}
 
index 017450996316196aea25d26c4a30af23f3a7a51f..db0372c463c6357df1d5667a04d09ca26fe7a301 100644 (file)
@@ -839,8 +839,8 @@ static void vacuum_fetch_handler(struct ctdb_context *ctdb, uint64_t srvid,
        }
 
        /* attach to it */
-       ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
-       if (ctdb_db == NULL) {
+       ret = ctdb_attachdb(ctdb, name, persistent, 0, &ctdb_db);
+       if (ret != 0) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                talloc_free(tmp_ctx);
                return;
index b03868ae9a2bdd0ac426b90b0bd061ff4871dd91..d94a2920363292cdac002fb4fd550f6f09d64a7a 100644 (file)
@@ -220,8 +220,8 @@ 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, 0);
-       if (!ctdb_db) {
+       ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+       if (ret) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
        }
index d53bfb9d42f93e124bade77e6f280f1981b9cbae..2cb6ff0ce3126e9096fd3588079d57cfb2cedf42 100644 (file)
@@ -172,7 +172,7 @@ int main(int argc, const char *argv[])
                { NULL, 'n', POPT_ARG_INT, &num_nodes, 0, "num_nodes", "integer" },
                POPT_TABLEEND
        };
-       int opt;
+       int ret, opt;
        const char **extra_argv;
        int extra_argc = 0;
        poptContext pc;
@@ -214,8 +214,8 @@ int main(int argc, const char *argv[])
                                 &cluster_ready);
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
-       if (!ctdb_db) {
+       ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+       if (ret) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
        }
index 70b617d275ef474846c55d891566f58db477a4c7..b6b5a82c58891f0e5c358224ee05542c479efb22 100644 (file)
@@ -89,7 +89,7 @@ int main(int argc, const char *argv[])
                { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
                POPT_TABLEEND
        };
-       int opt;
+       int ret, opt;
        const char **extra_argv;
        int extra_argc = 0;
        poptContext pc;
@@ -118,8 +118,8 @@ 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, 0);
-       if (!ctdb_db) {
+       ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+       if (ret) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
        }
index 4ae782b35677ad665b38c1693740fbd60b5012fd..87a629e5a4355a34d27d9b82e5057741dcc10cfd 100644 (file)
@@ -193,7 +193,7 @@ int main(int argc, const char *argv[])
                { "unsafe-writes", 'u', POPT_ARG_NONE, &unsafe_writes, 0, "do not use tdb transactions when writing", NULL },
                POPT_TABLEEND
        };
-       int opt;
+       int ret, opt;
        const char **extra_argv;
        int extra_argc = 0;
        poptContext pc;
@@ -229,12 +229,12 @@ 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);
+         ret = ctdb_attachdb(ctdb, "persistent.tdb", true, TDB_NOSYNC, &ctdb_db);
        } else {
-               ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true, 0);
+         ret = ctdb_attachdb(ctdb, "persistent.tdb", true, 0, &ctdb_db);
        }
 
-       if (!ctdb_db) {
+       if (ret) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
        }
index a11cfba75099ebac14b7f410eda5bcbfe9645c06..6fb02f9285c3093ee75f9d5a021e3ad0819080f7 100644 (file)
@@ -115,7 +115,7 @@ int main(int argc, const char *argv[])
                { "delete-pct", 'p', POPT_ARG_INT, &delete_pct, 0, "delete_pct", "integer" },
                POPT_TABLEEND
        };
-       int opt;
+       int ret, opt;
        const char **extra_argv;
        int extra_argc = 0;
        poptContext pc;
@@ -144,8 +144,8 @@ 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, 0);
-       if (!ctdb_db) {
+       ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+       if (ret) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
        }
index ffeb89082dc639300dc7c0f9b8f730ac95ec0f45..f50548b9062b300b5aea395d8f2d518751fc7dcd 100644 (file)
@@ -109,7 +109,7 @@ int main(int argc, const char *argv[])
                { "base-rec", 'b', POPT_ARG_INT, &base_rec, 0, "base_rec", "integer" },
                POPT_TABLEEND
        };
-       int opt;
+       int ret, opt;
        const char **extra_argv;
        int extra_argc = 0;
        poptContext pc;
@@ -140,8 +140,8 @@ 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, 0);
-       if (!ctdb_db) {
+       ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+       if (ret) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
        }
index b35e7d401d09cc0bba5cc87224fbc3dca83edcdb..64de72b18558abb740099f8fe1045fa2bfca9af8 100644 (file)
@@ -218,7 +218,7 @@ int main(int argc, const char *argv[])
                { "unsafe-writes", 'u', POPT_ARG_NONE, &unsafe_writes, 0, "do not use tdb transactions when writing", NULL },
                POPT_TABLEEND
        };
-       int opt;
+       int ret, opt;
        const char **extra_argv;
        int extra_argc = 0;
        poptContext pc;
@@ -261,12 +261,12 @@ 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);
+         ret = ctdb_attachdb(ctdb, "transaction.tdb", true, TDB_NOSYNC, &ctdb_db);
        } else {
-               ctdb_db = ctdb_attach(ctdb, "transaction.tdb", true, 0);
+         ret = ctdb_attachdb(ctdb, "transaction.tdb", true, 0, &ctdb_db);
        }
 
-       if (!ctdb_db) {
+       if (ret) {
                DEBUG(DEBUG_ERR, ("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)));
                exit(1);
        }
index 5377bf59edf1312e1b79378945e208a04f29aca1..b534384cb98b62b704957810560b8472e59359e8 100644 (file)
@@ -62,7 +62,7 @@ int main(int argc, const char *argv[])
                { "database", 0, POPT_ARG_STRING, &dbname, 0, "database to traverse", "name" },
                POPT_TABLEEND
        };
-       int opt;
+       int ret, opt;
        const char **extra_argv;
        int extra_argc = 0;
        poptContext pc;
@@ -93,8 +93,8 @@ int main(int argc, const char *argv[])
        ctdb = ctdb_cmdline_client(ev);
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attach(ctdb, dbname, false, 0);
-       if (!ctdb_db) {
+       ret = ctdb_attachdb(ctdb, dbname, false, 0, &ctdb_db);
+       if (ret) {
                printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
        }
index 83350ceff6d27ee44019137f5d07224020160ff2..fa89f8a8d97acb63195d326340c6f9ece9e2215e 100644 (file)
@@ -2710,9 +2710,9 @@ static int control_catdb(struct ctdb_context *ctdb, int argc, const char **argv)
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
+       ret = ctdb_attachdb(ctdb, db_name, false, 0, &ctdb_db);
 
-       if (ctdb_db == NULL) {
+       if (ret != 0) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
                return -1;
        }
@@ -3309,14 +3309,15 @@ static int control_attach(struct ctdb_context *ctdb, int argc, const char **argv
 {
        const char *db_name;
        struct ctdb_db_context *ctdb_db;
+       int ret;
 
        if (argc < 1) {
                usage();
        }
        db_name = argv[0];
 
-       ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
-       if (ctdb_db == NULL) {
+       ret = ctdb_attachdb(ctdb, db_name, false, 0, &ctdb_db);
+       if (ret != 0) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
                return -1;
        }
@@ -3523,8 +3524,8 @@ 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);
-       if (ctdb_db == NULL) {
+       ret = ctdb_attachdb(ctdb, argv[0], dbmap->dbs[i].persistent, 0, &ctdb_db);
+       if (ret != 0) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", argv[0]));
                talloc_free(tmp_ctx);
                return -1;
@@ -3661,8 +3662,8 @@ 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);
-       if (ctdb_db == NULL) {
+       ret = ctdb_attachdb(ctdb, dbhdr.name, dbhdr.persistent, 0, &ctdb_db);
+       if (ret != 0) {
                DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", dbhdr.name));
                talloc_free(tmp_ctx);
                return -1;
@@ -3913,8 +3914,8 @@ static int control_wipedb(struct ctdb_context *ctdb, int argc,
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].persistent, 0);
-       if (ctdb_db == NULL) {
+       ret = ctdb_attachdb(ctdb, argv[0], dbmap->dbs[i].persistent, 0, &ctdb_db);
+       if (ret != 0) {
                DEBUG(DEBUG_ERR, ("Unable to attach to database '%s'\n",
                                  argv[0]));
                talloc_free(tmp_ctx);
index 04124c04cc88f81d44e5e42985d86cf00bb997dd..7397673e011cffb25f34852015bca21c389d8e76 100644 (file)
@@ -238,7 +238,7 @@ static int ctdb_vacuum_db(struct ctdb_context *ctdb, uint32_t db_id, struct ctdb
        struct ctdb_db_context *ctdb_db;
        const char *name;
        struct vacuum_data *vdata;
-       int i;
+       int ret, i;
 
        vdata = talloc_zero(ctdb, struct vacuum_data);
        if (vdata == NULL) {
@@ -260,8 +260,8 @@ 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);
-       if (ctdb_db == NULL) {
+       ret = ctdb_attachdb(ctdb, name, persistent, 0, &ctdb_db);
+       if (ret != 0) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                talloc_free(vdata);
                return -1;
@@ -323,7 +323,6 @@ static int ctdb_vacuum_db(struct ctdb_context *ctdb, uint32_t db_id, struct ctdb
        if (vdata->delete_count > 0) {
                struct delete_records_list *recs;
                TDB_DATA indata, outdata;
-               int ret;
                int32_t res;
                uint32_t count;
 
@@ -574,15 +573,15 @@ static int ctdb_repack_db(struct ctdb_context *ctdb, uint32_t db_id,
 {
        struct ctdb_db_context *ctdb_db;
        const char *name;
-       int size;
+       int ret, size;
 
        if (ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, db_id, ctdb, &name) != 0) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to get name of db 0x%x\n", db_id));
                return -1;
        }
 
-       ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
-       if (ctdb_db == NULL) {
+       ret = ctdb_attachdb(ctdb, name, persistent, 0, &ctdb_db);
+       if (ret != 0) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                return -1;
        }