/* startup a client only ctdb context */ struct ctdb_context *ctdb_cmdline_client(struct tevent_context *ev, struct timeval req_timeout) { struct ctdb_context *ctdb; char *socket_name; int ret; /* initialise ctdb */ ctdb = ctdb_init(ev); if (ctdb == NULL) { fprintf(stderr, "Failed to init ctdb\n"); exit(1); } /* tell ctdb the socket address */ socket_name = getenv("CTDB_SOCKET"); if (socket_name != NULL) { ret = ctdb_set_socketname(ctdb, socket_name); if (ret == -1) { printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } if (ctdb_cmdline.socketname != NULL) { ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname); if (ret == -1) { fprintf(stderr, "ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } /* Set the debug level */ if (!parse_debug(ctdb_cmdline.debuglevel, &DEBUGLEVEL)) { DEBUGLEVEL = DEBUG_ERR; } ret = ctdb_socket_connect(ctdb); if (ret != 0) { fprintf(stderr, __location__ " Failed to connect to daemon\n"); talloc_free(ctdb); return NULL; } /* get our pnn */ ctdb->pnn = ctdb_ctrl_getpnn(ctdb, req_timeout, CTDB_CURRENT_NODE); if (ctdb->pnn == (uint32_t)-1) { DEBUG(DEBUG_CRIT,(__location__ " Failed to get ctdb pnn\n")); talloc_free(ctdb); return NULL; } return ctdb; }
/* main program */ int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; struct ctdb_db_context *ctdb_db; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_CTDB_CMDLINE { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" }, { "base-rec", 'b', POPT_ARG_INT, &base_rec, 0, "base_rec", "integer" }, { "delete-pct", 'p', POPT_ARG_INT, &delete_pct, 0, "delete_pct", "integer" }, POPT_TABLEEND }; int opt; const char **extra_argv; int extra_argc = 0; poptContext pc; struct event_context *ev; 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 = event_context_init(NULL); ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0)); if (ctdb == NULL) { printf("failed to connect to daemon\n"); exit(1); } /* attach to a specific database */ 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); } store_records(ctdb, ev); return 0; }
/* startup daemon side of ctdb according to command line options */ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev) { struct ctdb_context *ctdb; int ret; /* initialise ctdb */ ctdb = ctdb_init(ev); if (ctdb == NULL) { printf("Failed to init ctdb\n"); exit(1); } if (ctdb_cmdline.torture) { ctdb_set_flags(ctdb, CTDB_FLAG_TORTURE); } /* command line specified a socket name */ if (ctdb_cmdline.socketname != NULL) { setenv("CTDB_SOCKET", ctdb_cmdline.socketname, 1); ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname); if (ret == -1) { printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } /* Set the debug level */ if (isalpha(ctdb_cmdline.debuglevel[0]) || ctdb_cmdline.debuglevel[0] == '-') { LogLevel = get_debug_by_desc(ctdb_cmdline.debuglevel); } else { LogLevel = strtol(ctdb_cmdline.debuglevel, NULL, 0); } /* set up the tree to store server ids */ ctdb->server_ids = trbt_create(ctdb, 0); return ctdb; }
/* startup daemon side of ctdb according to command line options */ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev) { struct ctdb_context *ctdb; int ret; /* initialise ctdb */ ctdb = ctdb_init(ev); if (ctdb == NULL) { printf("Failed to init ctdb\n"); exit(1); } if (ctdb_cmdline.torture) { ctdb_set_flags(ctdb, CTDB_FLAG_TORTURE); } /* command line specified a socket name */ if (ctdb_cmdline.socketname != NULL) { setenv("CTDB_SOCKET", ctdb_cmdline.socketname, 1); ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname); if (ret == -1) { printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } /* Set the debug level */ if (!parse_debug(ctdb_cmdline.debuglevel, &DEBUGLEVEL)) { DEBUGLEVEL = DEBUG_ERR; } /* set up the tree to store server ids */ ctdb->server_ids = trbt_create(ctdb, 0); return ctdb; }
static int pmda_ctdb_daemon_connect(void) { const char *socket_name; int ret; struct sockaddr_un addr; ev = tevent_context_init(NULL); if (ev == NULL) { fprintf(stderr, "Failed to init event ctx\n"); return -1; } ctdb = ctdb_init(ev); if (ctdb == NULL) { fprintf(stderr, "Failed to init ctdb\n"); goto err_ev; } socket_name = getenv("CTDB_SOCKET"); if (socket_name == NULL) { socket_name = CTDB_SOCKET; } ret = ctdb_set_socketname(ctdb, socket_name); if (ret == -1) { fprintf(stderr, "ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); goto err_ctdb; } /* * ctdb_socket_connect() sets a default queue callback handler that * calls exit() if ctdbd is unavailable on recv, use our own wrapper to * work around this */ memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path)); ctdb->daemon.sd = socket(AF_UNIX, SOCK_STREAM, 0); if (ctdb->daemon.sd == -1) { fprintf(stderr, "Failed to open client socket\n"); goto err_ctdb; } set_nonblocking(ctdb->daemon.sd); set_close_on_exec(ctdb->daemon.sd); if (connect(ctdb->daemon.sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { fprintf(stderr, "Failed to connect to ctdb daemon via %s\n", ctdb->daemon.name); goto err_sd; } ctdb->daemon.queue = ctdb_queue_setup(ctdb, ctdb, ctdb->daemon.sd, CTDB_DS_ALIGNMENT, pmda_ctdb_q_read_cb, ctdb, "to-ctdbd"); if (ctdb->daemon.queue == NULL) { fprintf(stderr, "Failed to setup queue\n"); goto err_sd; } ctdb->pnn = ctdb_ctrl_getpnn(ctdb, timeval_current_ofs(3, 0), CTDB_CURRENT_NODE); if (ctdb->pnn == (uint32_t)-1) { fprintf(stderr, "Failed to get ctdb pnn\n"); goto err_sd; } return 0; err_sd: close(ctdb->daemon.sd); err_ctdb: talloc_free(ctdb); err_ev: talloc_free(ev); ctdb = NULL; return -1; }
/* main program */ int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; struct ctdb_db_context *ctdb_db; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_CTDB_CMDLINE { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" }, { "base-rec", 'b', POPT_ARG_INT, &base_rec, 0, "base_rec", "integer" }, POPT_TABLEEND }; int opt; const char **extra_argv; int extra_argc = 0; poptContext pc; struct event_context *ev; 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); } } /* talloc_enable_leak_report_full(); */ /* 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 = event_context_init(NULL); ctdb = ctdb_cmdline_client(ev); /* attach to a specific database */ ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0); if (!ctdb_db) { printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); exit(1); } 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; event_loop_once(ev); } store_records(ctdb, ev); return 0; }
/* main program */ int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; int interactive = 0; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_CTDB_CMDLINE { "interactive", 'i', POPT_ARG_NONE, &interactive, 0, "don't fork", NULL }, { "public-addresses", 0, POPT_ARG_STRING, &options.public_address_list, 0, "public address list file", "filename" }, { "public-interface", 0, POPT_ARG_STRING, &options.public_interface, 0, "public interface", "interface"}, { "event-script-dir", 0, POPT_ARG_STRING, &options.event_script_dir, 0, "event script directory", "dirname" }, { "logging", 0, POPT_ARG_STRING, &options.logging, 0, "logging method to be used", NULL }, { "nlist", 0, POPT_ARG_STRING, &options.nlist, 0, "node list file", "filename" }, { "notification-script", 0, POPT_ARG_STRING, &options.notification_script, 0, "notification script", "filename" }, { "listen", 0, POPT_ARG_STRING, &options.myaddress, 0, "address to listen on", "address" }, { "transport", 0, POPT_ARG_STRING, &options.transport, 0, "protocol transport", NULL }, { "dbdir", 0, POPT_ARG_STRING, &options.db_dir, 0, "directory for the tdb files", NULL }, { "dbdir-persistent", 0, POPT_ARG_STRING, &options.db_dir_persistent, 0, "directory for persistent tdb files", NULL }, { "dbdir-state", 0, POPT_ARG_STRING, &options.db_dir_state, 0, "directory for internal state tdb files", NULL }, { "reclock", 0, POPT_ARG_STRING, &options.recovery_lock, 0, "recovery lock", "lock" }, { "pidfile", 0, POPT_ARG_STRING, &ctdbd_pidfile, 0, "location of PID file", "filename" }, { "valgrinding", 0, POPT_ARG_NONE, &options.valgrinding, 0, "disable setscheduler SCHED_FIFO call, use mmap for tdbs", NULL }, { "nosetsched", 0, POPT_ARG_NONE, &options.nosetsched, 0, "disable setscheduler SCHED_FIFO call, use mmap for tdbs", NULL }, { "start-as-disabled", 0, POPT_ARG_NONE, &options.start_as_disabled, 0, "Node starts in disabled state", NULL }, { "start-as-stopped", 0, POPT_ARG_NONE, &options.start_as_stopped, 0, "Node starts in stopped state", NULL }, { "no-lmaster", 0, POPT_ARG_NONE, &options.no_lmaster, 0, "disable lmaster role on this node", NULL }, { "no-recmaster", 0, POPT_ARG_NONE, &options.no_recmaster, 0, "disable recmaster role on this node", NULL }, { "script-log-level", 0, POPT_ARG_INT, &options.script_log_level, 0, "log level of event script output", NULL }, { "nopublicipcheck", 0, POPT_ARG_NONE, &options.no_publicipcheck, 0, "don't check we have/don't have the correct public ip addresses", NULL }, { "max-persistent-check-errors", 0, POPT_ARG_INT, &options.max_persistent_check_errors, 0, "max allowed persistent check errors (default 0)", NULL }, { "sloppy-start", 0, POPT_ARG_NONE, &fast_start, 0, "Do not perform full recovery on start", NULL }, POPT_TABLEEND }; int opt, ret; const char **extra_argv; int extra_argc = 0; poptContext pc; struct tevent_context *ev; 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++; } talloc_enable_null_tracking(); fault_setup(); ev = tevent_context_init(NULL); if (ev == NULL) { DEBUG(DEBUG_ALERT,("tevent_context_init() failed\n")); exit(1); } tevent_loop_allow_nesting(ev); ctdb = ctdb_cmdline_init(ev); ctdb->start_as_disabled = options.start_as_disabled; ctdb->start_as_stopped = options.start_as_stopped; script_log_level = options.script_log_level; if (!ctdb_logging_init(ctdb, options.logging)) { exit(1); } DEBUG(DEBUG_NOTICE,("CTDB starting on node\n")); gettimeofday(&ctdb->ctdbd_start_time, NULL); gettimeofday(&ctdb->last_recovery_started, NULL); gettimeofday(&ctdb->last_recovery_finished, NULL); ctdb->recovery_mode = CTDB_RECOVERY_NORMAL; ctdb->recovery_master = (uint32_t)-1; ctdb->upcalls = &ctdb_upcalls; if (options.recovery_lock == NULL) { DEBUG(DEBUG_WARNING, ("Recovery lock not set\n")); } ctdb->recovery_lock = options.recovery_lock; TALLOC_FREE(ctdb->idr); ret = reqid_init(ctdb, 0, &ctdb->idr);; if (ret != 0) { DEBUG(DEBUG_ALERT, ("reqid_init failed (%s)\n", strerror(ret))); exit(1); } ctdb_tunables_set_defaults(ctdb); ret = ctdb_set_transport(ctdb, options.transport); if (ret == -1) { DEBUG(DEBUG_ALERT,("ctdb_set_transport failed - %s\n", ctdb_errstr(ctdb))); exit(1); } /* tell ctdb what address to listen on */ if (options.myaddress) { ret = ctdb_set_address(ctdb, options.myaddress); if (ret == -1) { DEBUG(DEBUG_ALERT,("ctdb_set_address failed - %s\n", ctdb_errstr(ctdb))); exit(1); } } /* set ctdbd capabilities */ ctdb->capabilities = CTDB_CAP_DEFAULT; if (options.no_lmaster != 0) { ctdb->capabilities &= ~CTDB_CAP_LMASTER; } if (options.no_recmaster != 0) { ctdb->capabilities &= ~CTDB_CAP_RECMASTER; } /* Initialise this node's PNN to the unknown value. This will * be set to the correct value by either ctdb_add_node() as * part of loading the nodes file or by * ctdb_tcp_listen_automatic() when the transport is * initialised. At some point we should de-optimise this and * pull it out into ctdb_start_daemon() so it is done clearly * and only in one place. */ ctdb->pnn = -1; /* Default value for CTDB_BASE - don't override */ setenv("CTDB_BASE", CTDB_ETCDIR, 0); /* tell ctdb what nodes are available */ if (options.nlist != NULL) { ctdb->nodes_file = options.nlist; } else { ctdb->nodes_file = talloc_asprintf(ctdb, "%s/nodes", getenv("CTDB_BASE")); if (ctdb->nodes_file == NULL) { DEBUG(DEBUG_ALERT,(__location__ " Out of memory\n")); exit(1); } } ctdb_load_nodes_file(ctdb); ctdb->db_directory = options.db_dir; mkdir_p_or_die(ctdb->db_directory, 0700); ctdb->db_directory_persistent = options.db_dir_persistent; mkdir_p_or_die(ctdb->db_directory_persistent, 0700); ctdb->db_directory_state = options.db_dir_state; mkdir_p_or_die(ctdb->db_directory_state, 0700); if (options.public_interface) { ctdb->default_public_interface = talloc_strdup(ctdb, options.public_interface); CTDB_NO_MEMORY(ctdb, ctdb->default_public_interface); } if (options.event_script_dir != NULL) { ctdb->event_script_dir = options.event_script_dir; } else { ctdb->event_script_dir = talloc_asprintf(ctdb, "%s/events.d", getenv("CTDB_BASE")); if (ctdb->event_script_dir == NULL) { DEBUG(DEBUG_ALERT,(__location__ " Out of memory\n")); exit(1); } } if (options.notification_script != NULL) { ret = ctdb_set_notification_script(ctdb, options.notification_script); if (ret == -1) { DEBUG(DEBUG_ALERT,("Unable to setup notification script\n")); exit(1); } } ctdb->valgrinding = (options.valgrinding == 1); ctdb->do_setsched = (options.nosetsched != 1); if (ctdb->valgrinding) { ctdb->do_setsched = false; } ctdb->public_addresses_file = options.public_address_list; ctdb->do_checkpublicip = (options.no_publicipcheck == 0); if (options.max_persistent_check_errors < 0) { ctdb->max_persistent_check_errors = 0xFFFFFFFFFFFFFFFFLL; } else { ctdb->max_persistent_check_errors = (uint64_t)options.max_persistent_check_errors; } /* start the protocol running (as a child) */ return ctdb_start_daemon(ctdb, interactive?false:true); }
/* main program */ int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_CTDB_CMDLINE POPT_TABLEEND }; int opt; const char **extra_argv; int extra_argc = 0; poptContext pc; struct event_context *ev; struct ctdb_vnn_map *vnnmap=NULL; 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 = event_context_init(NULL); ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(5, 0)); if (ctdb == NULL) { exit(1); } /* attach to a specific database */ ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(5, 0), "test.tdb", false, 0); if (!ctdb_db) { printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); exit(1); } 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; event_loop_once(ev); } if (ctdb_ctrl_getvnnmap(ctdb, timeval_zero(), CTDB_CURRENT_NODE, ctdb, &vnnmap) != 0) { printf("Unable to get vnnmap from local node\n"); exit(1); } printf("Current Generation %d\n", (int)vnnmap->generation); fetch_lock_once(ctdb, ev, vnnmap->generation); return 0; }
/* 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; }
/* main program */ int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; struct ctdb_db_context *ctdb_db; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_CTDB_CMDLINE POPT_TABLEEND }; int opt; const char **extra_argv; int extra_argc = 0; int i, ret; poptContext pc; struct event_context *ev; struct ctdb_call call; 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 = event_context_init(NULL); /* initialise ctdb */ ctdb = ctdb_cmdline_init(ev); if (ctdb == NULL) { printf("Failed to init ctdb\n"); exit(1); } /* attach to a specific database */ ctdb_db = ctdb_attach(ctdb, "test.tdb", TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0666); if (!ctdb_db) { printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)); exit(1); } /* setup a ctdb call function */ ret = ctdb_set_call(ctdb_db, sort_func, FUNC_SORT); ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH); /* start the protocol running */ ret = ctdb_start(ctdb); ctdb_connect_wait(ctdb); ZERO_STRUCT(call); call.key.dptr = discard_const("test"); call.key.dsize = strlen("test")+1; /* add some random data */ for (i=0;i<10;i++) { int v = random() % 1000; call.call_id = FUNC_SORT; call.call_data.dptr = (uint8_t *)&v; call.call_data.dsize = sizeof(v); ret = ctdb_call(ctdb_db, &call); if (ret == -1) { printf("ctdb_call FUNC_SORT failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } /* fetch the record */ call.call_id = FUNC_FETCH; call.call_data.dptr = NULL; call.call_data.dsize = 0; ret = ctdb_call(ctdb_db, &call); if (ret == -1) { printf("ctdb_call FUNC_FETCH failed - %s\n", ctdb_errstr(ctdb)); exit(1); } for (i=0;i<call.reply_data.dsize/sizeof(int);i++) { printf("%3d\n", ((int *)call.reply_data.dptr)[i]); } talloc_free(call.reply_data.dptr); /* go into a wait loop to allow other nodes to complete */ ctdb_shutdown(ctdb); return 0; }
/* main program */ int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; struct ctdb_db_context *ctdb_db; int unsafe_writes = 0; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_CTDB_CMDLINE { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" }, { "delay", 'D', POPT_ARG_INT, &delay, 0, "delay (in seconds) between operations", "integer" }, { "verbose", 'v', POPT_ARG_NONE, &verbose, 0, "switch on verbose mode", NULL }, { "unsafe-writes", 'u', POPT_ARG_NONE, &unsafe_writes, 0, "do not use tdb transactions when writing", NULL }, POPT_TABLEEND }; int opt; const char **extra_argv; int extra_argc = 0; poptContext pc; struct event_context *ev; printf("SUCCESS (transaction test disabled while transactions are being rewritten)\n"); exit(0); if (verbose) { setbuf(stdout, (char *)NULL); /* don't buffer */ } else { setlinebuf(stdout); } 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 = event_context_init(NULL); ctdb = ctdb_cmdline_client(ev); if (ctdb == NULL) { DEBUG(DEBUG_ERR, ("Could not attach to daemon\n")); return 1; } /* attach to a specific database */ if (unsafe_writes == 1) { ctdb_db = ctdb_attach(ctdb, "transaction.tdb", true, TDB_NOSYNC); } else { ctdb_db = ctdb_attach(ctdb, "transaction.tdb", true, 0); } if (!ctdb_db) { DEBUG(DEBUG_ERR, ("ctdb_attach failed - %s\n", ctdb_errstr(ctdb))); exit(1); } DEBUG(DEBUG_ERR, ("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; event_loop_once(ev); } pnn = ctdb_get_pnn(ctdb); printf("Starting test on node %u. running for %u seconds. sleep delay: %u seconds.\n", pnn, timelimit, delay); if (!verbose && (pnn == 0)) { event_add_timed(ev, ctdb, timeval_current_ofs(1, 0), each_second, ctdb); } test_store_records(ctdb, ev); if (verbose || (pnn == 0)) { if (success != true) { printf("The test FAILED\n"); return 1; } else { printf("SUCCESS!\n"); } } return 0; }