diff options
Diffstat (limited to 'src/third_party/wiredtiger/test/csuite/wt7989_compact_checkpoint/main.c')
-rw-r--r-- | src/third_party/wiredtiger/test/csuite/wt7989_compact_checkpoint/main.c | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/src/third_party/wiredtiger/test/csuite/wt7989_compact_checkpoint/main.c b/src/third_party/wiredtiger/test/csuite/wt7989_compact_checkpoint/main.c index 6e388b54535..a93d83b0985 100644 --- a/src/third_party/wiredtiger/test/csuite/wt7989_compact_checkpoint/main.c +++ b/src/third_party/wiredtiger/test/csuite/wt7989_compact_checkpoint/main.c @@ -37,6 +37,7 @@ */ #define NUM_RECORDS 1000000 +#define CHECKPOINT_NUM 3 /* Constants and variables declaration. */ /* @@ -78,11 +79,13 @@ main(int argc, char *argv[]) /* * First run test with WT_TIMING_STRESS_CHECKPOINT_SLOW. */ + printf("Running stress test...\n"); run_test(true, opts->home, opts->uri); /* * Now run test where compact and checkpoint threads are synchronized using condition variable. */ + printf("Running normal test...\n"); testutil_assert(sizeof(home_cv) > strlen(opts->home) + 3); sprintf(home_cv, "%s.CV", opts->home); run_test(false, home_cv, opts->uri); @@ -110,8 +113,8 @@ run_test(bool stress_test, const char *home, const char *uri) if (stress_test) { /* - * Set WT_TIMING_STRESS_CHECKPOINT_SLOW flag. It adds 10 seconds sleep before each - * checkpoint. + * Set WT_TIMING_STRESS_CHECKPOINT_SLOW flag for stress test. It adds 10 seconds sleep + * before each checkpoint. */ set_timing_stress_checkpoint(conn); } @@ -161,17 +164,17 @@ run_test(bool stress_test, const char *home, const char *uri) } testutil_check(session->close(session, NULL)); + session = NULL; + + testutil_check(conn->close(conn, NULL)); + conn = NULL; /* Check if there's at least 10% compaction. */ printf(" - Compressed file size MB: %f\n - Original file size MB: %f\n", file_sz_after / (1024.0 * 1024), file_sz_before / (1024.0 * 1024)); - /* - * FIXME-WT-8055 At the moment the assert below is commented out to prevent evergreen from going - * red. Please enable the assert as soon as the underlying defect is fixed and compact does its - * job well. - */ - /*testutil_assert(file_sz_before * 0.9 > file_sz_after);*/ + /* Make sure the compact operation has reduced the file size by at least 20%. */ + testutil_assert((file_sz_before / 100) * 80 > file_sz_after); } static void * @@ -198,7 +201,9 @@ thread_func_compact(void *arg) /* Perform compact operation. */ testutil_check(session->compact(session, td->uri, NULL)); + testutil_check(session->close(session, NULL)); + session = NULL; return (NULL); } @@ -219,13 +224,18 @@ static void * thread_func_checkpoint(void *arg) { struct thread_data *td; + WT_RAND_STATE rnd; WT_SESSION *session; + uint64_t sleep_sec; + int i; bool signalled; td = (struct thread_data *)arg; testutil_check(td->conn->open_session(td->conn, NULL, NULL, &session)); + __wt_random_init_seed((WT_SESSION_IMPL *)session, &rnd); + if (td->cond != NULL) { printf("Waiting for the signal...\n"); /* @@ -238,8 +248,22 @@ thread_func_checkpoint(void *arg) printf("Signal received!\n"); } - testutil_check(session->checkpoint(session, NULL)); + /* + * Run several checkpoints. First one without any delay. Others will have a random delay before + * start. + */ + for (i = 0; i < CHECKPOINT_NUM; i++) { + testutil_check(session->checkpoint(session, NULL)); + + if (i < CHECKPOINT_NUM - 1) { + sleep_sec = (uint64_t)__wt_random(&rnd) % 15 + 1; + printf("Sleep %" PRIu64 " sec before next checkpoint.\n", sleep_sec); + __wt_sleep(sleep_sec, 0); + } + } + testutil_check(session->close(session, NULL)); + session = NULL; return (NULL); } @@ -248,27 +272,28 @@ static void populate(WT_SESSION *session, const char *uri) { WT_CURSOR *cursor; - time_t t; + WT_RAND_STATE rnd; uint64_t val; int i, str_len; - srand((u_int)time(&t)); + __wt_random_init_seed((WT_SESSION_IMPL *)session, &rnd); str_len = sizeof(data_str) / sizeof(data_str[0]); for (i = 0; i < str_len - 1; i++) - data_str[i] = 'a' + rand() % 26; + data_str[i] = 'a' + __wt_random(&rnd) % 26; data_str[str_len - 1] = '\0'; testutil_check(session->open_cursor(session, uri, NULL, NULL, &cursor)); for (i = 0; i < NUM_RECORDS; i++) { cursor->set_key(cursor, i); - val = (uint64_t)rand(); + val = (uint64_t)__wt_random(&rnd); cursor->set_value(cursor, val, val, val, data_str); testutil_check(cursor->insert(cursor)); } testutil_check(cursor->close(cursor)); + cursor = NULL; } static void @@ -286,6 +311,7 @@ remove_records(WT_SESSION *session, const char *uri) } testutil_check(cursor->close(cursor)); + cursor = NULL; } static uint64_t @@ -293,8 +319,7 @@ get_file_size(WT_SESSION *session, const char *uri) { WT_CURSOR *cur_stat; uint64_t val; - char *descr, *str_val; - char stat_uri[128]; + char *descr, *str_val, stat_uri[128]; sprintf(stat_uri, "statistics:%s", uri); testutil_check(session->open_cursor(session, stat_uri, NULL, "statistics=(all)", &cur_stat)); @@ -302,6 +327,7 @@ get_file_size(WT_SESSION *session, const char *uri) testutil_check(cur_stat->search(cur_stat)); testutil_check(cur_stat->get_value(cur_stat, &descr, &str_val, &val)); testutil_check(cur_stat->close(cur_stat)); + cur_stat = NULL; return (val); } |