static void test_store_records(struct ctdb_context *ctdb, struct event_context *ev) { TDB_DATA key; struct ctdb_db_context *ctdb_db; int ret; uint32_t *counters; ctdb_db = ctdb_db_handle(ctdb, "transaction.tdb"); key.dptr = discard_const("testkey"); key.dsize = strlen((const char *)key.dptr)+1; start_timer(); while ((timelimit == 0) || (end_timer() < timelimit)) { TALLOC_CTX *tmp_ctx = talloc_new(ctdb); TDB_DATA data; struct ctdb_transaction_handle *h; if (verbose) DEBUG(DEBUG_ERR, ("starting transaction\n")); h = ctdb_transaction_start(ctdb_db, tmp_ctx); if (h == NULL) { DEBUG(DEBUG_ERR, ("Failed to start transaction on node %d\n", ctdb_get_pnn(ctdb))); talloc_free(tmp_ctx); return; } if (verbose) DEBUG(DEBUG_ERR, ("transaction started\n")); do_sleep(delay); if (verbose) DEBUG(DEBUG_ERR, ("calling transaction_fetch\n")); ret = ctdb_transaction_fetch(h, tmp_ctx, key, &data); if (ret != 0) { DEBUG(DEBUG_ERR,("Failed to fetch record\n")); exit(1); } if (verbose) DEBUG(DEBUG_ERR, ("fetched data ok\n")); do_sleep(delay); if (data.dsize < sizeof(uint32_t) * (pnn+1)) { unsigned char *ptr = data.dptr; data.dptr = talloc_zero_size(tmp_ctx, sizeof(uint32_t) * (pnn+1)); memcpy(data.dptr, ptr, data.dsize); talloc_free(ptr); data.dsize = sizeof(uint32_t) * (pnn+1); } if (data.dptr == NULL) { DEBUG(DEBUG_ERR, ("Failed to realloc array\n")); talloc_free(tmp_ctx); return; } counters = (uint32_t *)data.dptr; /* bump our counter */ counters[pnn]++; if (verbose) DEBUG(DEBUG_ERR, ("calling transaction_store\n")); ret = ctdb_transaction_store(h, key, data); if (ret != 0) { DEBUG(DEBUG_ERR,("Failed to store record\n")); exit(1); } if (verbose) DEBUG(DEBUG_ERR, ("stored data ok\n")); do_sleep(delay); if (verbose) DEBUG(DEBUG_ERR, ("calling transaction_commit\n")); ret = ctdb_transaction_commit(h); if (ret != 0) { DEBUG(DEBUG_ERR,("Failed to commit transaction\n")); check_counters(ctdb, data); exit(1); } if (verbose) DEBUG(DEBUG_ERR, ("transaction committed\n")); /* store the counters and verify that they are sane */ if (verbose || (pnn == 0)) { check_counters(ctdb, data); } do_sleep(delay); talloc_free(tmp_ctx); } }
static void test_store_records(struct db_context *db, struct tevent_context *ev) { TDB_DATA key; uint32_t *counters; TALLOC_CTX *tmp_ctx = talloc_stackframe(); struct timeval start; key = string_term_tdb_data("testkey"); start = timeval_current(); while ((timelimit == 0) || (timeval_elapsed(&start) < timelimit)) { struct db_record *rec; TDB_DATA data; TDB_DATA value; int ret; NTSTATUS status; if (!no_trans) { if (verbose) DEBUG(1, ("starting transaction\n")); ret = dbwrap_transaction_start(db); if (ret != 0) { DEBUG(0, ("Failed to start transaction on node " "%d\n", pnn)); goto fail; } if (verbose) DEBUG(1, ("transaction started\n")); do_sleep(torture_delay); } if (verbose) DEBUG(1, ("calling fetch_lock\n")); rec = dbwrap_fetch_locked(db, tmp_ctx, key); if (rec == NULL) { DEBUG(0, ("Failed to fetch record\n")); goto fail; } if (verbose) DEBUG(1, ("fetched record ok\n")); do_sleep(torture_delay); value = dbwrap_record_get_value(rec); data.dsize = MAX(value.dsize, sizeof(uint32_t) * (pnn+1)); data.dptr = (unsigned char *)talloc_zero_size(tmp_ctx, data.dsize); if (data.dptr == NULL) { DEBUG(0, ("Failed to allocate data\n")); goto fail; } memcpy(data.dptr, value.dptr, value.dsize); counters = (uint32_t *)data.dptr; /* bump our counter */ counters[pnn]++; if (verbose) DEBUG(1, ("storing data\n")); status = dbwrap_record_store(rec, data, TDB_REPLACE); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Failed to store record\n")); if (!no_trans) { ret = dbwrap_transaction_cancel(db); if (ret != 0) { DEBUG(0, ("Error cancelling transaction.\n")); } } goto fail; } talloc_free(rec); if (verbose) DEBUG(1, ("stored data ok\n")); do_sleep(torture_delay); if (!no_trans) { if (verbose) DEBUG(1, ("calling transaction_commit\n")); ret = dbwrap_transaction_commit(db); if (ret != 0) { DEBUG(0, ("Failed to commit transaction\n")); goto fail; } if (verbose) DEBUG(1, ("transaction committed\n")); } /* store the counters and verify that they are sane */ if (verbose || (pnn == 0)) { if (!check_counters(db, data)) { goto fail; } } talloc_free(data.dptr); do_sleep(torture_delay); } goto done; fail: success = false; done: talloc_free(tmp_ctx); return; }
/* * Parent: wait for kids to get ready, start them, wait for them to * finish, read and accumulate results. */ void parent( int children, int load, char * mix_file, char * iodist_file) { char string[80]; /* for interactive startup */ int result; int invalid_run; /* holds INVALID RUN status */ int runtime_val; /* store Runtime value to be printed later */ int Saveerrno; char *nameptr; #if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS)) struct sigaction sig_act, old_sig_act; #endif /* * Setup a SIGCHLD handler in case one of our beloved children dies * before its time. */ #if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS)) /* use XOPEN signal handling */ sig_act.sa_handler = sfs_reaper; (void)sigemptyset(&sig_act.sa_mask); sig_act.sa_flags = 0; if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) { perror("sigaction failed: SIGCHLD"); exit(66); } #else (void) signal(SIGCHLD, sfs_reaper); #endif /* Change my name for error logging */ if ((nameptr = strrchr(sfs_Myname, '/')) != NULL) sfs_Myname = ++nameptr; /* * store the Runtime value; to be printed in results */ if (Prime_client) runtime_val = Runtime - MULTICLIENT_OFFSET; else runtime_val = Runtime; /* print logfile header information */ (void) fprintf(stdout,"\n"); (void) fprintf(stdout, "************************************************************************"); (void) fprintf(stdout,"\n"); (void) fflush(stdout); /* print sfs information */ if (Prime_client) { (void) fprintf(stderr, "\nSFS NFS Version %d Benchmark Client Logfile, %s\n", nfs_version, lad_timestamp()); (void) fprintf(stderr, "\tClient hostname = %s\n", lad_hostname); (void) fprintf(stderr, "\tPrime Client hostname = %s\n", Prime_client); } (void) fprintf(stderr, "\nSPEC SFS Benchmark Version %s, Creation - %s\n", SFS_VERSION_NUM, SFS_VERSION_DATE); (void) fprintf(stderr, "NFS Protocol Version %d\n", nfs_version); /* mount test directories */ (void) fprintf(stderr, "%s Mounting %d remote test directories.\n", lad_timestamp(), children); synchronize_children(children); (void) fprintf(stderr, "%s Completed.", lad_timestamp()); /* * if multi-client execution then tell Prime-Client I'm done mounting * test directories. */ if (Prime_client) { (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Sending DONE-MOUNT message to Prime Client(%s).\n", lad_timestamp(), Prime_client); if ((result = (int) signal_Prime_Client("CLIENT_SIGNAL", "")) == (int) RPC_SUCCESS) { (void) fprintf(stderr, "%s Completed.",lad_timestamp()); (void) fflush(stderr); } else { (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s: error %d sending DONE-MOUNT message to Prime Client\n", sfs_Myname, result); /* cleanup and exit */ #if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS)) sig_act.sa_handler = SIG_DFL; (void)sigemptyset(&sig_act.sa_mask); sig_act.sa_flags = 0; if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) { perror("sigaction failed: SIGCHLD"); exit(67); } #else (void) signal(SIGCHLD, SIG_DFL); #endif (void) generic_kill(0, SIGINT); exit(68); } (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Waiting on DO-INIT message from Prime Client(%s).\n", lad_timestamp(), Prime_client); (void) fflush(stderr); /* * wait for DO-INIT message from Prime Client * sfs_syncd (rpc server) sends a SIGUSR1 signal; * user can also terminate experiment anytime they wish * with SIGINT or SIGTERM signal */ (void) pause(); (void) fprintf(stderr, "%s Received.",lad_timestamp()); (void) fflush(stderr); } /* send DONE-MOUNT and got DO-INIT message */ /* initialize test directories */ (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Initializing test directories.\n", lad_timestamp()); /* send SIGUSR1 to child processes */ (void) generic_kill(0, SIGUSR1); synchronize_children(children); (void) fprintf(stderr, "%s Completed.", lad_timestamp()); (void) fflush(stderr); /* * if multi-client execution then tell Prime-Client I'm done initializing * and wait for synchronized do warmupmessage. */ if (Prime_client) { (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Sending DONE-INIT message to Prime Client(%s).\n", lad_timestamp(), Prime_client); if ((result = (int) signal_Prime_Client("CLIENT_SIGNAL","")) == (int) RPC_SUCCESS) { (void) fprintf(stderr, "%s Completed.",lad_timestamp()); (void) fflush(stderr); } else { (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s: error %d sending DONE-INIT message to Prime Client\n", sfs_Myname, result); /* cleanup and exit */ #if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS)) sig_act.sa_handler = SIG_DFL; (void)sigemptyset(&sig_act.sa_mask); sig_act.sa_flags = 0; if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) { perror("sigaction failed: SIGCHLD"); exit(69); } #else (void) signal(SIGCHLD, SIG_DFL); #endif (void) generic_kill(0, SIGINT); exit(70); } (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Waiting on DO-WARMUP message from Prime Client(%s).\n", lad_timestamp(), Prime_client); (void) fflush(stderr); /* * wait for DO-WARMUP message from Prime Client * sfs_syncd (rpc server) sends a SIGUSR1 signal; * user can also terminate experiment anytime they wish * with SIGINT or SIGTERM signal */ (void) pause(); (void) fprintf(stderr, "%s Received.",lad_timestamp()); (void) fflush(stderr); } /* send DONE-INIT and got DO-WARMUP message */ if (Populate_only) { (void) fprintf(stderr, "\nPopulating directories and exiting.\n"); #if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS)) sig_act.sa_handler = SIG_DFL; (void)sigemptyset(&sig_act.sa_mask); sig_act.sa_flags = 0; if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) { perror("sigaction failed: SIGCHLD"); exit(71); } #else (void) signal(SIGCHLD, SIG_DFL); #endif (void) generic_kill(0, SIGUSR1); while (wait((int *) 0) != -1) { /* nop */ } return; } /* do warm-up */ if (Warmuptime) { (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Performing %d seconds pretest warmup.\n", lad_timestamp(), Warmuptime); (void) generic_kill(0, SIGUSR1); (void) sleep(Warmuptime); (void) fprintf(stderr, "%s Completed.", lad_timestamp()); (void) fflush(stderr); } if (Interactive) { (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "Hit <return> when ready to start test ..."); (void) fgets(string,10,stdin); } /* * if multi-client execution then tell Prime-Client I'm done warm-up * and wait for synchronized Start message. */ if (Prime_client) { (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Sending READY message to Prime Client(%s).\n", lad_timestamp(), Prime_client); if ((result = (int) signal_Prime_Client("CLIENT_SIGNAL","")) == (int) RPC_SUCCESS) { (void) fprintf(stderr, "%s Completed.",lad_timestamp()); (void) fflush(stderr); } else { (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s: error %d sending READY message to Prime Client\n", sfs_Myname, result); /* cleanup and exit */ #if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS)) sig_act.sa_handler = SIG_DFL; (void)sigemptyset(&sig_act.sa_mask); sig_act.sa_flags = 0; if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) { perror("sigaction failed: SIGCHLD"); exit(72); } #else (void) signal(SIGCHLD, SIG_DFL); #endif (void) generic_kill(0, SIGINT); exit(73); } (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Waiting on START message from Prime Client(%s).\n", lad_timestamp(), Prime_client); (void) fflush(stderr); /* * wait for START message from Prime Client * sfs_syncd (rpc server) sends a SIGUSR1 signal; * user can also terminate experiment anytime they wish * with SIGINT or SIGTERM signal */ (void) pause(); (void) fprintf(stderr, "%s Received.",lad_timestamp()); (void) fflush(stderr); } /* send READY and got START message */ (void) fprintf(stderr, "\n"); if (Timed_run) { if (Prime_client) { (void) fprintf(stderr, "%s Starting %d seconds test run.\n", lad_timestamp(), Runtime - MULTICLIENT_OFFSET); } else { (void) fprintf(stderr, "%s Starting %d seconds test run.\n", lad_timestamp(), Runtime); } } else { (void) fprintf(stderr, "%s Starting %d call test run.\n", lad_timestamp(), Ops[TOTAL].target_calls); } (void) fflush(stderr); /* signal child processes to go */ (void) generic_kill(0, SIGUSR1); if (Timed_run) (void) sleep(Runtime); #if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS)) sig_act.sa_handler = SIG_DFL; (void)sigemptyset(&sig_act.sa_mask); sig_act.sa_flags = 0; if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) { perror("sigaction failed: SIGCHLD"); exit(74); } #else (void) signal(SIGCHLD, SIG_DFL); #endif if (Timed_run) { /* * The parent and the prime are both sleeping for Runtime. * If the parent wakes up first, he'll tell the children to stop. * If the prime wakes up first, he'll send an SIGALRM (via syncd) * to the parent. That alarm may arrive while the parent is still * asleep, which is ok, or after he has starting running. Since * the parent SIGARLM catcher does nothing, there is no harm done * by the extra signal in this case. * * Perhaps, if running multi we should just wait (pause()) for * the STOP signal, like we waited for the start signal. It would * be more obvious. The only drawback is the OTW rpc delay in * receiving the stop signal from the prime. */ (void) generic_kill(0, SIGUSR2); /* tell children to finish */ } /* Wait for all the children to finish/die */ while (wait((int *) 0) != -1) { /* nop */ } (void) fprintf(stderr, "%s Completed.", lad_timestamp()); (void) fflush(stdout); (void) fflush(stderr); /* Initialize and sum up counters */ collect_counters(children); if ((invalid_run = check_counters()) == 0) invalid_run = check_parameters(iodist_file, mix_file, runtime_val); /* print test results */ print_results(children, load, mix_file, invalid_run, runtime_val, iodist_file); /* * if multi-client execution then tell Prime client that * I'm done with 'real' work and wait for move-data message * and send data across */ if (Prime_client) { (void) fprintf(stderr, "%s Sending DONE-TEST message to Prime Client(%s).\n", lad_timestamp(), Prime_client); if ((result = (int) signal_Prime_Client("CLIENT_SIGNAL","")) == (int) RPC_SUCCESS) { (void) fprintf(stderr, "%s Completed.", lad_timestamp()); (void) fflush(stderr); } else { Saveerrno = errno; (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s: error %d sending DONE-TEST message to Prime Client\n", sfs_Myname, result); errno = Saveerrno; perror("signal_Prime_Client"); /* cleanup and exit */ (void) generic_kill(0, SIGINT); exit(75); } /* * wait for MOVE-DATA message from Prime Client before * sending send results. */ (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Waiting on MOVE-DATA message from Prime Client(%s).\n", lad_timestamp(), Prime_client); (void) fflush(stderr); (void) pause(); (void) fprintf(stderr, "%s Received.", lad_timestamp()); (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s Sending results to Prime Client(%s)\n", lad_timestamp(), Prime_client); (void) fflush(stderr); if ((result = (int) signal_Prime_Client("CLIENT_DATA", Client_results)) == (int) RPC_SUCCESS) { (void) fprintf(stderr, "%s Completed.\n", lad_timestamp()); (void) fflush(stderr); } else { Saveerrno = errno; (void) fprintf(stderr, "\n"); (void) fprintf(stderr, "%s: error %d sending client's result to Prime Client\n", sfs_Myname, result); errno = Saveerrno; perror("signal_Prime_Client"); /* cleanup and exit */ (void) generic_kill(0, SIGINT); exit(76); } } /* sent done, got move-data and sent data */ (void) fprintf(stdout,"\n"); (void) fprintf(stdout, "************************************************************************"); (void) fprintf(stdout,"\n"); } /* parent */