/* 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; }
/* 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; 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; }