/* main program */ int main(int argc, const char *argv[]) { TALLOC_CTX *mem_ctx; struct tevent_context *ev_ctx; struct messaging_context *msg_ctx; struct db_context *db; int unsafe_writes = 0; struct poptOption popt_options[] = { POPT_AUTOHELP POPT_COMMON_SAMBA { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "INTEGER" }, { "delay", 'D', POPT_ARG_INT, &torture_delay, 0, "delay (in seconds) between operations", "INTEGER" }, { "verbose", 'v', POPT_ARG_NONE, &verbose, 0, "switch on verbose mode", NULL }, { "db-name", 'N', POPT_ARG_STRING, &db_name, 0, "name of the test db", "NAME" }, { "no-trans", 'n', POPT_ARG_NONE, &no_trans, 0, "use fetch_lock/record store instead of transactions", 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; int tdb_flags; int ret = 1; mem_ctx = talloc_stackframe(); if (verbose) { setbuf(stdout, (char *)NULL); /* don't buffer */ } else { setlinebuf(stdout); } load_case_tables(); setup_logging(argv[0], DEBUG_STDERR); lp_set_cmdline("log level", "0"); 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)); goto done; } } /* 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++; } lp_load_global(get_dyn_CONFIGFILE()); ev_ctx = samba_tevent_context_init(mem_ctx); if (ev_ctx == NULL) { d_fprintf(stderr, "ERROR: could not init event context\n"); goto done; } msg_ctx = messaging_init(mem_ctx, ev_ctx); if (msg_ctx == NULL) { d_fprintf(stderr, "ERROR: could not init messaging context\n"); goto done; } if (unsafe_writes == 1) { tdb_flags = TDB_NOSYNC; } else { tdb_flags = TDB_DEFAULT; } if (no_trans) { tdb_flags |= TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH; } db = db_open(mem_ctx, db_name, 0, tdb_flags, O_RDWR | O_CREAT, 0644, DBWRAP_LOCK_ORDER_1); if (db == NULL) { d_fprintf(stderr, "failed to open db '%s': %s\n", db_name, strerror(errno)); goto done; } if (get_my_vnn() == NONCLUSTER_VNN) { set_my_vnn(0); } pnn = get_my_vnn(); printf("Starting test on node %u. running for %u seconds. " "sleep delay: %u seconds.\n", pnn, timelimit, torture_delay); if (!verbose && (pnn == 0)) { tevent_add_timer(ev_ctx, db, timeval_current_ofs(1, 0), each_second, db); } test_store_records(db, ev_ctx); if (verbose || (pnn == 0)) { if (success != true) { printf("The test FAILED\n"); ret = 2; } else { printf("SUCCESS!\n"); ret = 0; } } done: talloc_free(mem_ctx); return ret; }
/* 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; }