3
This test just fetch_locks a record and releases it once.
5
Copyright (C) Ronnie Sahlberg 2009
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 3 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, see <http://www.gnu.org/licenses/>.
22
#include "system/filesys.h"
27
const char *TESTKEY = "testkey";
29
static void rorl_cb(struct ctdb_db *ctdb_db,
30
struct ctdb_lock *lock, TDB_DATA outdata, void *private)
32
int *finished = private;
34
printf("Record fetchlocked.\n");
35
printf("Press enter to release the record ...\n");
42
Just try locking/unlocking a single record once
44
static void fetch_readonly_once(struct ctdb_connection *ctdb, struct ctdb_db *ctdb_db, TDB_DATA key)
48
printf("Trying to fetch lock the record ...\n");
51
if (!ctdb_readonlyrecordlock_async(ctdb_db, key,
52
rorl_cb, &finished)) {
53
printf("Failed to send READONLYRECORDLOCK\n");
60
pfd.fd = ctdb_get_fd(ctdb);
61
pfd.events = ctdb_which_events(ctdb);
62
if (poll(&pfd, 1, -1) < 0) {
63
fprintf(stderr, "Poll failed");
66
if (ctdb_service(ctdb, pfd.revents) < 0) {
67
fprintf(stderr, "Failed to service");
72
printf("Record released.\n");
78
int main(int argc, const char *argv[])
80
struct ctdb_connection *ctdb;
81
struct ctdb_db *ctdb_db;
85
struct poptOption popt_options[] = {
87
{ "record", 'r', POPT_ARG_STRING, &TESTKEY, 0, "record", "string" },
91
const char **extra_argv;
95
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
97
while ((opt = poptGetNextOpt(pc)) != -1) {
100
fprintf(stderr, "Invalid option %s: %s\n",
101
poptBadOption(pc, 0), poptStrerror(opt));
106
/* setup the remaining options for the main program to use */
107
extra_argv = poptGetArgs(pc);
110
while (extra_argv[extra_argc]) extra_argc++;
113
ctdb = ctdb_connect("/tmp/ctdb.socket",
114
ctdb_log_file, stderr);
117
fprintf(stderr, "Connecting to /tmp/ctdb.socket");
121
key.dptr = discard_const(TESTKEY);
122
key.dsize = strlen(TESTKEY);
124
/* attach to a specific database */
125
ctdb_db = ctdb_attachdb(ctdb, "test.tdb", false, 0);
127
fprintf(stderr, "ctdb_attachdb failed\n");
131
printf("Waiting for cluster\n");
134
ctdb_getrecmode(ctdb, CTDB_CURRENT_NODE, &recmode);
135
if (recmode == 0) break;
139
fetch_readonly_once(ctdb, ctdb_db, key);