diff options
author | Amitay Isaacs <amitay@gmail.com> | 2016-04-20 14:49:47 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2016-07-22 06:50:21 +0200 |
commit | 5a510ecbea87b445bcdf3fd8e5baa719e90e0076 (patch) | |
tree | 051e08773732aea1f0da74652059c6126de88aea /ctdb | |
parent | bc157dc3d46dde4cbf7c45de1dc65b37526511ae (diff) | |
download | samba-5a510ecbea87b445bcdf3fd8e5baa719e90e0076.tar.gz |
ctdb-tests: Replace ctdb_fetch_readonly_once with fetch_readonly using new client API
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb')
-rwxr-xr-x | ctdb/tests/simple/75_readonly_records_basic.sh | 10 | ||||
-rw-r--r-- | ctdb/tests/src/ctdb_fetch_readonly_once.c | 129 | ||||
-rw-r--r-- | ctdb/tests/src/fetch_readonly.c | 163 | ||||
-rwxr-xr-x | ctdb/wscript | 4 |
4 files changed, 171 insertions, 135 deletions
diff --git a/ctdb/tests/simple/75_readonly_records_basic.sh b/ctdb/tests/simple/75_readonly_records_basic.sh index e4d57081609..05deaf0c194 100755 --- a/ctdb/tests/simple/75_readonly_records_basic.sh +++ b/ctdb/tests/simple/75_readonly_records_basic.sh @@ -128,7 +128,8 @@ try_command_on_node all $CTDB_TEST_WRAPPER ctdb_update_record ###################################################################### echo "Try some readonly fetches, these should all be upgraded to full fetchlocks..." -try_command_on_node all $CTDB_TEST_WRAPPER "ctdb_fetch_readonly_once </dev/null" +try_command_on_node all $CTDB_TEST_WRAPPER $VALGRIND fetch_readonly \ + -D ${testdb} -k testkey check_no_readonly @@ -155,7 +156,8 @@ echo "Create 1 read-only delegation ..." try_command_on_node 1 $CTDB_TEST_WRAPPER ctdb_update_record # Fetch read-only to node 0 -try_command_on_node 0 $CTDB_TEST_WRAPPER "ctdb_fetch_readonly_once </dev/null" +try_command_on_node 0 $CTDB_TEST_WRAPPER $VALGRIND fetch_readonly \ + -D ${testdb} -k testkey check_readonly 1 0 @@ -177,8 +179,8 @@ others="" for n in $all_nodes ; do if [ "$n" != "$dmaster" ] ; then # Fetch read-only copy to this node - try_command_on_node $n \ - $CTDB_TEST_WRAPPER "ctdb_fetch_readonly_once </dev/null" + try_command_on_node $n $CTDB_TEST_WRAPPER $VALGRIND fetch_readonly \ + -D ${testdb} -k testkey others="${others} ${n}" fi done diff --git a/ctdb/tests/src/ctdb_fetch_readonly_once.c b/ctdb/tests/src/ctdb_fetch_readonly_once.c deleted file mode 100644 index 211927363fc..00000000000 --- a/ctdb/tests/src/ctdb_fetch_readonly_once.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - simple ctdb test tool - This test just fetch_locks a record and releases it once. - - Copyright (C) Ronnie Sahlberg 2009 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ - -#include "replace.h" -#include "system/filesys.h" -#include "system/network.h" - -#include <popt.h> -#include <talloc.h> -#include <tevent.h> -#include <tdb.h> - -#include "lib/util/time.h" - -#include "ctdb_private.h" -#include "ctdb_client.h" - -#include "common/common.h" -#include "common/cmdline.h" - -const char *TESTKEY = "testkey"; - -/* - Just try locking/unlocking a single record once -*/ -static void fetch_readonly_once(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db, TDB_DATA key) -{ - TDB_DATA data; - struct ctdb_record_handle *h; - - printf("Trying to readonly fetch lock the record ...\n"); - - h = ctdb_fetch_readonly_lock(ctdb_db, ctdb, key, &data, 1); - if (h == NULL) { - fprintf(stderr, "Failed to get readonly lock\n"); - exit(1); - } - - talloc_free(h); - printf("Record released.\n"); -} - -/* - main program -*/ -int main(int argc, const char *argv[]) -{ - struct ctdb_context *ctdb; - struct ctdb_db_context *ctdb_db; - struct tevent_context *ev; - - TDB_DATA key; - - struct poptOption popt_options[] = { - POPT_AUTOHELP - { "record", 'r', POPT_ARG_STRING, &TESTKEY, 0, "record", "string" }, - POPT_TABLEEND - }; - int opt; - const char **extra_argv; - int extra_argc = 0; - poptContext pc; - - pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST); - - while ((opt = poptGetNextOpt(pc)) != -1) { - switch (opt) { - default: - fprintf(stderr, "Invalid option %s: %s\n", - poptBadOption(pc, 0), poptStrerror(opt)); - exit(1); - } - } - - /* setup the remaining options for the main program to use */ - extra_argv = poptGetArgs(pc); - if (extra_argv) { - extra_argv++; - while (extra_argv[extra_argc]) extra_argc++; - } - - ev = tevent_context_init(NULL); - - ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0)); - if (ctdb == NULL) { - printf("failed to connect to ctdb daemon.\n"); - exit(1); - } - - key.dptr = discard_const(TESTKEY); - key.dsize = strlen(TESTKEY); - - /* attach to a specific database */ - ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(3, 0), "test.tdb", - false, 0); - if (!ctdb_db) { - fprintf(stderr, "ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); - exit(10); - } - - printf("Waiting for cluster\n"); - while (1) { - uint32_t recmode=1; - ctdb_ctrl_getrecmode(ctdb, ctdb, timeval_zero(), CTDB_CURRENT_NODE, &recmode); - if (recmode == 0) break; - tevent_loop_once(ev); - } - - fetch_readonly_once(ctdb, ctdb_db, key); - - return 0; -} diff --git a/ctdb/tests/src/fetch_readonly.c b/ctdb/tests/src/fetch_readonly.c new file mode 100644 index 00000000000..5d2972a3f09 --- /dev/null +++ b/ctdb/tests/src/fetch_readonly.c @@ -0,0 +1,163 @@ +/* + Fetch a single record using readonly + + Copyright (C) Amitay Isaacs 2016 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "replace.h" +#include "system/network.h" + +#include "lib/util/tevent_unix.h" + +#include "client/client.h" +#include "tests/src/test_options.h" +#include "tests/src/cluster_wait.h" + + +struct fetch_readonly_state { + struct tevent_context *ev; +}; + +static void fetch_readonly_done(struct tevent_req *subreq); + +static struct tevent_req *fetch_readonly_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct ctdb_client_context *client, + struct ctdb_db_context *db, + const char *keystr, + int timelimit) +{ + struct tevent_req *req, *subreq; + struct fetch_readonly_state *state; + TDB_DATA key; + + req = tevent_req_create(mem_ctx, &state, struct fetch_readonly_state); + if (req == NULL) { + return NULL; + } + + state->ev = ev; + + key.dptr = (uint8_t *)discard_const(keystr); + key.dsize = strlen(keystr); + + subreq = ctdb_fetch_lock_send(state, ev, client, db, key, true); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, fetch_readonly_done, req); + + return req; +} + +static void fetch_readonly_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct fetch_readonly_state *state = tevent_req_data( + req, struct fetch_readonly_state); + struct ctdb_record_handle *h; + int ret; + + h = ctdb_fetch_lock_recv(subreq, NULL, state, NULL, &ret); + TALLOC_FREE(subreq); + if (h == NULL) { + tevent_req_error(req, ret); + return; + } + + talloc_free(h); + tevent_req_done(req); +} + +static bool fetch_readonly_recv(struct tevent_req *req, int *perr) +{ + int err; + + if (tevent_req_is_unix_error(req, &err)) { + if (perr != NULL) { + *perr = err; + } + return false; + } + return true; +} + +int main(int argc, const char *argv[]) +{ + const struct test_options *opts; + TALLOC_CTX *mem_ctx; + struct tevent_context *ev; + struct ctdb_client_context *client; + struct ctdb_db_context *ctdb_db; + struct tevent_req *req; + int ret; + bool status; + + status = process_options_database(argc, argv, &opts); + if (! status) { + exit(1); + } + + mem_ctx = talloc_new(NULL); + if (mem_ctx == NULL) { + fprintf(stderr, "Memory allocation error\n"); + exit(1); + } + + ev = tevent_context_init(mem_ctx); + if (ev == NULL) { + fprintf(stderr, "Memory allocation error\n"); + exit(1); + } + + ret = ctdb_client_init(mem_ctx, ev, opts->socket, &client); + if (ret != 0) { + fprintf(stderr, "Failed to initialize client, %s\n", + strerror(ret)); + exit(1); + } + + if (! ctdb_recovery_wait(ev, client)) { + fprintf(stderr, "Memory allocation error\n"); + exit(1); + } + + ret = ctdb_attach(ev, client, tevent_timeval_zero(), opts->dbname, 0, + &ctdb_db); + if (ret != 0) { + fprintf(stderr, "Failed to attach to DB %s\n", opts->dbname); + exit(1); + } + + req = fetch_readonly_send(mem_ctx, ev, client, ctdb_db, + opts->keystr, opts->timelimit); + if (req == NULL) { + fprintf(stderr, "Memory allocation error\n"); + exit(1); + } + + tevent_req_poll(req, ev); + + status = fetch_readonly_recv(req, &ret); + if (! status) { + fprintf(stderr, "fetch readonly loop test failed\n"); + exit(1); + } + + talloc_free(mem_ctx); + return 0; +} diff --git a/ctdb/wscript b/ctdb/wscript index 2d78fb273be..2e0dac2e3a7 100755 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -677,7 +677,6 @@ def build(bld): # Test binaries ctdb_tests = [ 'rb_test', - 'ctdb_fetch_readonly_once', 'ctdb_fetch_readonly_loop', 'ctdb_trackingdb_test', 'ctdb_update_record', @@ -710,7 +709,8 @@ def build(bld): 'g_lock_loop', 'message_ring', 'fetch_ring', - 'fetch_loop' + 'fetch_loop', + 'fetch_readonly' ] for target in ctdb_tests: |