summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSusan LoVerso <sue@wiredtiger.com>2014-02-03 10:44:13 -0500
committerSusan LoVerso <sue@wiredtiger.com>2014-02-03 10:44:13 -0500
commitc332c6e14d0fa8bb560713dfda7aa06f0173be86 (patch)
tree51bf148761495432bd7b9e5b898bc01a824739c9
parent885a6c9b42f1ac2e73246f9bcb17de5dcfcdaba5 (diff)
downloadmongo-c332c6e14d0fa8bb560713dfda7aa06f0173be86.tar.gz
Refactor populate code to eliminate duplicate code.
-rw-r--r--bench/wtperf/wtperf.c121
1 files changed, 43 insertions, 78 deletions
diff --git a/bench/wtperf/wtperf.c b/bench/wtperf/wtperf.c
index b4b9e08c9da..f8ee4fcb952 100644
--- a/bench/wtperf/wtperf.c
+++ b/bench/wtperf/wtperf.c
@@ -533,100 +533,65 @@ populate_thread(void *arg)
}
/* Populate the database. */
- if (cfg->populate_ops_per_txn == 0)
- for (;;) {
- op = get_next_incr();
- if (op > cfg->icount)
- break;
+ for (intxn = 0, opcount = 0;;) {
+ op = get_next_incr();
+ if (op > cfg->icount)
+ break;
- sprintf(key_buf, "%0*" PRIu64, cfg->key_sz, op);
- measure_latency = cfg->sample_interval != 0 && (
- trk->ops % cfg->sample_rate == 0);
- if (measure_latency &&
- (ret = __wt_epoch(NULL, &start)) != 0) {
- lprintf(cfg, ret, 0, "Get time call failed");
- goto err;
- }
- cursor->set_key(cursor, key_buf);
- if (cfg->random_value)
- randomize_value(cfg, value_buf);
- cursor->set_value(cursor, value_buf);
- if ((ret = cursor->insert(cursor)) != 0) {
- lprintf(cfg, ret, 0, "Failed inserting");
+ if (cfg->populate_ops_per_txn != 0 && !intxn) {
+ if ((ret = session->begin_transaction(
+ session, cfg->transaction_config)) != 0) {
+ lprintf(cfg, ret, 0,
+ "Failed starting transaction.");
goto err;
}
- /* Gather statistics */
- if (measure_latency) {
- if ((ret = __wt_epoch(NULL, &stop)) != 0) {
- lprintf(cfg, ret, 0,
- "Get time call failed");
- goto err;
- }
- ++trk->latency_ops;
- usecs = ns_to_us(WT_TIMEDIFF(stop, start));
- track_operation(trk, usecs);
- }
- ++thread->insert.ops; /* Same as trk->ops */
+ intxn = 1;
}
- else {
- for (intxn = 0, opcount = 0;;) {
- op = get_next_incr();
- if (op > cfg->icount)
- break;
-
- if (!intxn) {
- if ((ret = session->begin_transaction(
- session, cfg->transaction_config)) != 0) {
- lprintf(cfg, ret, 0,
- "Failed starting transaction.");
- goto err;
- }
- intxn = 1;
- }
- sprintf(key_buf, "%0*" PRIu64, cfg->key_sz, op);
- measure_latency = cfg->sample_interval != 0 && (
- trk->ops % cfg->sample_rate == 0);
- if (measure_latency &&
- (ret = __wt_epoch(NULL, &start)) != 0) {
- lprintf(cfg, ret, 0, "Get time call failed");
- goto err;
- }
- cursor->set_key(cursor, key_buf);
- if (cfg->random_value)
- randomize_value(cfg, value_buf);
- cursor->set_value(cursor, value_buf);
- if ((ret = cursor->insert(cursor)) != 0) {
- lprintf(cfg, ret, 0, "Failed inserting");
+ sprintf(key_buf, "%0*" PRIu64, cfg->key_sz, op);
+ measure_latency = cfg->sample_interval != 0 && (
+ trk->ops % cfg->sample_rate == 0);
+ if (measure_latency &&
+ (ret = __wt_epoch(NULL, &start)) != 0) {
+ lprintf(cfg, ret, 0, "Get time call failed");
+ goto err;
+ }
+ cursor->set_key(cursor, key_buf);
+ if (cfg->random_value)
+ randomize_value(cfg, value_buf);
+ cursor->set_value(cursor, value_buf);
+ if ((ret = cursor->insert(cursor)) != 0) {
+ lprintf(cfg, ret, 0, "Failed inserting");
+ goto err;
+ }
+ /* Gather statistics */
+ if (measure_latency) {
+ if ((ret = __wt_epoch(NULL, &stop)) != 0) {
+ lprintf(cfg, ret, 0,
+ "Get time call failed");
goto err;
}
- /* Gather statistics */
- if (measure_latency) {
- if ((ret = __wt_epoch(NULL, &stop)) != 0) {
- lprintf(cfg, ret, 0,
- "Get time call failed");
- goto err;
- }
- ++trk->latency_ops;
- usecs = ns_to_us(WT_TIMEDIFF(stop, start));
- track_operation(trk, usecs);
- }
- ++thread->insert.ops; /* Same as trk->ops */
+ ++trk->latency_ops;
+ usecs = ns_to_us(WT_TIMEDIFF(stop, start));
+ track_operation(trk, usecs);
+ }
+ ++thread->insert.ops; /* Same as trk->ops */
+ if (cfg->populate_ops_per_txn != 0) {
if (++opcount < cfg->populate_ops_per_txn)
continue;
opcount = 0;
- if ((ret =
- session->commit_transaction(session, NULL)) != 0)
+ if ((ret = session->commit_transaction(
+ session, NULL)) != 0)
lprintf(cfg, ret, 0,
"Fail committing, transaction was aborted");
intxn = 0;
}
- if (intxn &&
- (ret = session->commit_transaction(session, NULL)) != 0)
- lprintf(cfg, ret, 0,
- "Fail committing, transaction was aborted");
}
+ if (intxn &&
+ (ret = session->commit_transaction(session, NULL)) != 0)
+ lprintf(cfg, ret, 0,
+ "Fail committing, transaction was aborted");
if ((ret = session->close(session, NULL)) != 0) {
lprintf(cfg, ret, 0, "Error closing session in populate");