diff options
Diffstat (limited to 'src/third_party/wiredtiger/bench/wtperf/wtperf_truncate.c')
-rw-r--r-- | src/third_party/wiredtiger/bench/wtperf/wtperf_truncate.c | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/src/third_party/wiredtiger/bench/wtperf/wtperf_truncate.c b/src/third_party/wiredtiger/bench/wtperf/wtperf_truncate.c index 581d1987947..11b09c60d5d 100644 --- a/src/third_party/wiredtiger/bench/wtperf/wtperf_truncate.c +++ b/src/third_party/wiredtiger/bench/wtperf/wtperf_truncate.c @@ -1,5 +1,5 @@ /*- - * Public Domain 2014-2015 MongoDB, Inc. + * Public Domain 2014-2016 MongoDB, Inc. * Public Domain 2008-2014 WiredTiger, Inc. * * This is free and unencumbered software released into the public domain. @@ -41,7 +41,7 @@ setup_truncate(CONFIG *cfg, CONFIG_THREAD *thread, WT_SESSION *session) { TRUNCATE_QUEUE_ENTRY *truncate_item; WORKLOAD *workload; WT_CURSOR *cursor; - char *key, *truncate_key; + char *key; int ret; uint64_t end_point, final_stone_gap, i, start_point; @@ -54,6 +54,12 @@ setup_truncate(CONFIG *cfg, CONFIG_THREAD *thread, WT_SESSION *session) { session, cfg->uris[0], NULL, NULL, &cursor)) != 0) goto err; + /* + * If we find the workload getting behind we multiply the number of + * records to be truncated. + */ + trunc_cfg->catchup_multiplier = 1; + /* How many entries between each stone. */ trunc_cfg->stone_gap = (workload->truncate_count * workload->truncate_pct) / 100; @@ -96,23 +102,14 @@ setup_truncate(CONFIG *cfg, CONFIG_THREAD *thread, WT_SESSION *session) { if (trunc_cfg->stone_gap != 0) { trunc_cfg->expected_total = (end_point - start_point); for (i = 1; i <= trunc_cfg->needed_stones; i++) { - truncate_key = calloc(cfg->key_sz, 1); - if (truncate_key == NULL) { - ret = enomem(cfg); - goto err; - } - truncate_item = calloc(sizeof(TRUNCATE_QUEUE_ENTRY), 1); - if (truncate_item == NULL) { - free(truncate_key); - ret = enomem(cfg); - goto err; - } + truncate_item = + dcalloc(sizeof(TRUNCATE_QUEUE_ENTRY), 1); + truncate_item->key = dcalloc(cfg->key_sz, 1); generate_key( - cfg, truncate_key, trunc_cfg->stone_gap * i); - truncate_item->key = truncate_key; + cfg, truncate_item->key, trunc_cfg->stone_gap * i); truncate_item->diff = (trunc_cfg->stone_gap * i) - trunc_cfg->last_key; - TAILQ_INSERT_TAIL( &cfg->stone_head, truncate_item, q); + TAILQ_INSERT_TAIL(&cfg->stone_head, truncate_item, q); trunc_cfg->last_key = trunc_cfg->stone_gap * i; trunc_cfg->num_stones++; } @@ -131,8 +128,8 @@ run_truncate(CONFIG *cfg, CONFIG_THREAD *thread, TRUNCATE_CONFIG *trunc_cfg; TRUNCATE_QUEUE_ENTRY *truncate_item; - char *truncate_key; int ret, t_ret; + uint64_t used_stone_gap; ret = 0; trunc_cfg = &thread->trunc_cfg; @@ -145,27 +142,36 @@ run_truncate(CONFIG *cfg, CONFIG_THREAD *thread, trunc_cfg->last_total_inserts = trunc_cfg->total_inserts; /* We are done if there isn't enough data to trigger a new milestone. */ - if (trunc_cfg->expected_total <= trunc_cfg->needed_stones) + if (trunc_cfg->expected_total <= thread->workload->truncate_count) return (0); + /* + * If we are falling behind and using more than one stone per lap we + * should widen the stone gap for this lap to try and catch up quicker. + */ + if (trunc_cfg->expected_total > + thread->workload->truncate_count + trunc_cfg->stone_gap) { + /* + * Increase the multiplier until we create stones that are + * almost large enough to truncate the whole expected table size + * in one operation. + */ + trunc_cfg->catchup_multiplier = + WT_MIN(trunc_cfg->catchup_multiplier + 1, + trunc_cfg->needed_stones - 1); + } else { + /* Back off if we start seeing an improvement */ + trunc_cfg->catchup_multiplier = + WT_MAX(trunc_cfg->catchup_multiplier - 1, 1); + } + used_stone_gap = trunc_cfg->stone_gap * trunc_cfg->catchup_multiplier; + while (trunc_cfg->num_stones < trunc_cfg->needed_stones) { - trunc_cfg->last_key += trunc_cfg->stone_gap; - truncate_key = calloc(cfg->key_sz, 1); - if (truncate_key == NULL) { - lprintf(cfg, ENOMEM, 0, - "truncate: couldn't allocate key array"); - return (ENOMEM); - } - truncate_item = calloc(sizeof(TRUNCATE_QUEUE_ENTRY), 1); - if (truncate_item == NULL) { - free(truncate_key); - lprintf(cfg, ENOMEM, 0, - "truncate: couldn't allocate item"); - return (ENOMEM); - } - generate_key(cfg, truncate_key, trunc_cfg->last_key); - truncate_item->key = truncate_key; - truncate_item->diff = trunc_cfg->stone_gap; + trunc_cfg->last_key += used_stone_gap; + truncate_item = dcalloc(sizeof(TRUNCATE_QUEUE_ENTRY), 1); + truncate_item->key = dcalloc(cfg->key_sz, 1); + generate_key(cfg, truncate_item->key, trunc_cfg->last_key); + truncate_item->diff = used_stone_gap; TAILQ_INSERT_TAIL(&cfg->stone_head, truncate_item, q); trunc_cfg->num_stones++; } @@ -189,7 +195,6 @@ run_truncate(CONFIG *cfg, CONFIG_THREAD *thread, goto err; } - *truncatedp = 1; trunc_cfg->expected_total -= truncate_item->diff; |