diff options
author | Luke Chen <luke.chen@mongodb.com> | 2019-09-09 14:45:50 +1000 |
---|---|---|
committer | Luke Chen <luke.chen@mongodb.com> | 2019-09-09 14:48:15 +1000 |
commit | d1c52b7aafac44e16dd62ce94663eab1aa16f921 (patch) | |
tree | 2aea018150b745b0fc7ef3dc626c4ef4164d2704 /src/third_party/wiredtiger/test/csuite/wt2403_lsm_workload/main.c | |
parent | b326fd656716e95418e563ff12368a3015994b5e (diff) | |
download | mongo-d1c52b7aafac44e16dd62ce94663eab1aa16f921.tar.gz |
Import wiredtiger: c600bde20363629405082a3ea985b70dfb00850e from branch mongodb-4.2
ref: 280c572c80..c600bde203
for: 4.2.1
WT-4535 Enhance wt command line utility to use read-only mode
WT-4658 Apply Clang Format
WT-4810 Adding WT_ERR_ASSERT and WT_RET_ASSERT macros
WT-4831 Add option to python tests to not fail if stdout is not empty
WT-4884 Test for recovery correctness with modify operations
WT-4935 Add a perf test to find out the wiredtiger_calc_modify overhead
WT-4966 Fix valgrind detected memory leak from test/csuite/import/smoke.sh
WT-5043 Add debugging to aid in test/format hang
WT-5046 Prepared transactions aren't properly cleared from global table with WT_CONN_LOG_DEBUG_MODE enabled
WT-5062 Adjust the record size to consume less size
WT-5063 Return proper error message for cursor modify operation for not supported cursor types
WT-5074 Fix "make check" on exotic architectures
WT-5076 Cut WiredTiger 3.2.1 release
WT-5080 New wtperf workload modify_distribute option
WT-5085 Fix spacing in wtperf output
WT-5087 Add time tracking at start of reconciliation
WT-5088 Refine clearing and setting of debug timer
WT-5100 Update test format to disable readonly mode in utility
Diffstat (limited to 'src/third_party/wiredtiger/test/csuite/wt2403_lsm_workload/main.c')
-rw-r--r-- | src/third_party/wiredtiger/test/csuite/wt2403_lsm_workload/main.c | 344 |
1 files changed, 162 insertions, 182 deletions
diff --git a/src/third_party/wiredtiger/test/csuite/wt2403_lsm_workload/main.c b/src/third_party/wiredtiger/test/csuite/wt2403_lsm_workload/main.c index b8a99b68db2..870304f8252 100644 --- a/src/third_party/wiredtiger/test/csuite/wt2403_lsm_workload/main.c +++ b/src/third_party/wiredtiger/test/csuite/wt2403_lsm_workload/main.c @@ -29,213 +29,193 @@ #include "test_util.h" static const char name[] = "lsm:test"; -#define NUM_DOCS 100000 -#define NUM_QUERIES (NUM_DOCS/100) +#define NUM_DOCS 100000 +#define NUM_QUERIES (NUM_DOCS / 100) static void rand_str(uint64_t i, char *str) { - uint64_t x, y; + uint64_t x, y; - y = strlen(str); - for (x = y; x > y - 8; x--) { - str[x - 1] = (char)(i % 10) + 48; - i = i / 10; - } + y = strlen(str); + for (x = y; x > y - 8; x--) { + str[x - 1] = (char)(i % 10) + 48; + i = i / 10; + } } static void check_str(uint64_t i, char *str, bool mod) { - char str2[] = "0000000000000000"; + char str2[] = "0000000000000000"; - rand_str(i, str2); - if (mod) - str2[0] = 'A'; - testutil_checkfmt(strcmp(str, str2), - "strcmp failed, got %s, expected %s", str, str2); + rand_str(i, str2); + if (mod) + str2[0] = 'A'; + testutil_checkfmt(strcmp(str, str2), "strcmp failed, got %s, expected %s", str, str2); } static void query_docs(WT_CURSOR *cursor, bool mod) { - WT_ITEM key, value; - int i; - - for (i = 0; i < NUM_QUERIES; i++) { - testutil_check(cursor->next(cursor)); - testutil_check(cursor->get_key(cursor, &key)); - testutil_check(cursor->get_value(cursor, &value)); - check_str((uint64_t)key.data, (char *)value.data, mod); - } - printf("%d documents read\n", NUM_QUERIES); + WT_ITEM key, value; + int i; + + for (i = 0; i < NUM_QUERIES; i++) { + testutil_check(cursor->next(cursor)); + testutil_check(cursor->get_key(cursor, &key)); + testutil_check(cursor->get_value(cursor, &value)); + check_str((uint64_t)key.data, (char *)value.data, mod); + } + printf("%d documents read\n", NUM_QUERIES); } static void * compact_thread(void *args) { - WT_SESSION *session; + WT_SESSION *session; - session = (WT_SESSION *)args; - testutil_check(session->compact(session, name, NULL)); - return (NULL); + session = (WT_SESSION *)args; + testutil_check(session->compact(session, name, NULL)); + return (NULL); } int main(int argc, char *argv[]) { - TEST_OPTS *opts, _opts; - WT_CURSOR *rcursor, *wcursor; - WT_ITEM key, value; - WT_SESSION *session, *session2; - pthread_t thread; - uint64_t i; - - char str[] = "0000000000000000"; - - /* - * Create a clean test directory for this run of the test program if the - * environment variable isn't already set (as is done by make check). - */ - opts = &_opts; - memset(opts, 0, sizeof(*opts)); - testutil_check(testutil_parse_opts(argc, argv, opts)); - testutil_make_work_dir(opts->home); - testutil_check(wiredtiger_open(opts->home, - NULL, "create,cache_size=200M", &opts->conn)); - - testutil_check( - opts->conn->open_session(opts->conn, NULL, NULL, &session)); - testutil_check( - opts->conn->open_session(opts->conn, NULL, NULL, &session2)); - - testutil_check(session->create(session, name, - "key_format=Q,value_format=S")); - - /* Populate the table with some data. */ - testutil_check(session->open_cursor( - session, name, NULL, "overwrite", &wcursor)); - for (i = 0; i < NUM_DOCS; i++) { - wcursor->set_key(wcursor, i); - rand_str(i, str); - wcursor->set_value(wcursor, str); - testutil_check(wcursor->insert(wcursor)); - } - testutil_check(wcursor->close(wcursor)); - printf("%d documents inserted\n", NUM_DOCS); - - /* Perform some random reads */ - testutil_check(session->open_cursor( - session, name, NULL, "next_random=true", &rcursor)); - query_docs(rcursor, false); - testutil_check(rcursor->close(rcursor)); - - /* Setup Transaction to pin the current values */ - testutil_check( - session2->begin_transaction(session2, "isolation=snapshot")); - testutil_check(session2->open_cursor( - session2, name, NULL, "next_random=true", &rcursor)); - - /* Perform updates in a txn to confirm that we see only the original. */ - testutil_check(session->open_cursor( - session, name, NULL, "overwrite", &wcursor)); - for (i = 0; i < NUM_DOCS; i++) { - rand_str(i, str); - str[0] = 'A'; - wcursor->set_key(wcursor, i); - wcursor->set_value(wcursor, str); - testutil_check(wcursor->update(wcursor)); - } - testutil_check(wcursor->close(wcursor)); - printf("%d documents set to update\n", NUM_DOCS); - - /* Random reads, which should see the original values */ - query_docs(rcursor, false); - testutil_check(rcursor->close(rcursor)); - - /* Finish the txn */ - testutil_check(session2->rollback_transaction(session2, NULL)); - - /* Random reads, which should see the updated values */ - testutil_check(session2->open_cursor( - session2, name, NULL, "next_random=true", &rcursor)); - query_docs(rcursor, true); - testutil_check(rcursor->close(rcursor)); - - /* Setup a pre-delete txn */ - testutil_check( - session2->begin_transaction(session2, "isolation=snapshot")); - testutil_check(session2->open_cursor( - session2, name, NULL, "next_random=true", &rcursor)); - - /* Delete all but one document */ - testutil_check(session->open_cursor( - session, name, NULL, "overwrite", &wcursor)); - for (i = 0; i < NUM_DOCS - 1; i++) { - wcursor->set_key(wcursor, i); - testutil_check(wcursor->remove(wcursor)); - } - testutil_check(wcursor->close(wcursor)); - printf("%d documents deleted\n", NUM_DOCS - 1); - - /* Random reads, which should not see the deletes */ - query_docs(rcursor, true); - testutil_check(rcursor->close(rcursor)); - - /* Rollback the txn so we can see the deletes */ - testutil_check(session2->rollback_transaction(session2, NULL)); - - /* Find the one remaining document 3 times */ - testutil_check(session2->open_cursor( - session2, name, NULL, "next_random=true", &rcursor)); - for (i = 0; i < 3; i++) { - testutil_check(rcursor->next(rcursor)); - testutil_check(rcursor->get_key(rcursor, &key)); - testutil_check(rcursor->get_value(rcursor, &value)); - /* There should only be one value available to us */ - testutil_assertfmt((uint64_t)key.data == NUM_DOCS - 1, - "expected %d and got %" PRIu64, - NUM_DOCS - 1, (uint64_t)key.data); - check_str((uint64_t)key.data, (char *)value.data, true); - } - printf("Found the deleted doc 3 times\n"); - testutil_check(rcursor->close(rcursor)); - - /* Repopulate the table for compact. */ - testutil_check(session->open_cursor( - session, name, NULL, "overwrite", &wcursor)); - for (i = 0; i < NUM_DOCS - 1; i++) { - wcursor->set_key(wcursor, i); - rand_str(i, str); - str[0] = 'A'; - wcursor->set_value(wcursor, str); - testutil_check(wcursor->insert(wcursor)); - } - testutil_check(wcursor->close(wcursor)); - - /* Run random cursor queries while compact is running */ - testutil_check(session2->open_cursor( - session2, name, NULL, "next_random=true", &rcursor)); - testutil_check(pthread_create(&thread, NULL, compact_thread, session)); - query_docs(rcursor, true); - testutil_check(rcursor->close(rcursor)); - testutil_check(pthread_join(thread, NULL)); - - /* Delete everything. Check for infinite loops */ - testutil_check(session->open_cursor( - session, name, NULL, "overwrite", &wcursor)); - for (i = 0; i < NUM_DOCS; i++) { - wcursor->set_key(wcursor, i); - testutil_check(wcursor->remove(wcursor)); - } - testutil_check(wcursor->close(wcursor)); - - testutil_check(session2->open_cursor( - session2, name, NULL, "next_random=true", &rcursor)); - for (i = 0; i < 3; i++) - testutil_assert(rcursor->next(rcursor) == WT_NOTFOUND); - printf("Successfully got WT_NOTFOUND\n"); - - testutil_cleanup(opts); - return (EXIT_SUCCESS); + TEST_OPTS *opts, _opts; + WT_CURSOR *rcursor, *wcursor; + WT_ITEM key, value; + WT_SESSION *session, *session2; + pthread_t thread; + uint64_t i; + + char str[] = "0000000000000000"; + + /* + * Create a clean test directory for this run of the test program if the environment variable + * isn't already set (as is done by make check). + */ + opts = &_opts; + memset(opts, 0, sizeof(*opts)); + testutil_check(testutil_parse_opts(argc, argv, opts)); + testutil_make_work_dir(opts->home); + testutil_check(wiredtiger_open(opts->home, NULL, "create,cache_size=200M", &opts->conn)); + + testutil_check(opts->conn->open_session(opts->conn, NULL, NULL, &session)); + testutil_check(opts->conn->open_session(opts->conn, NULL, NULL, &session2)); + + testutil_check(session->create(session, name, "key_format=Q,value_format=S")); + + /* Populate the table with some data. */ + testutil_check(session->open_cursor(session, name, NULL, "overwrite", &wcursor)); + for (i = 0; i < NUM_DOCS; i++) { + wcursor->set_key(wcursor, i); + rand_str(i, str); + wcursor->set_value(wcursor, str); + testutil_check(wcursor->insert(wcursor)); + } + testutil_check(wcursor->close(wcursor)); + printf("%d documents inserted\n", NUM_DOCS); + + /* Perform some random reads */ + testutil_check(session->open_cursor(session, name, NULL, "next_random=true", &rcursor)); + query_docs(rcursor, false); + testutil_check(rcursor->close(rcursor)); + + /* Setup Transaction to pin the current values */ + testutil_check(session2->begin_transaction(session2, "isolation=snapshot")); + testutil_check(session2->open_cursor(session2, name, NULL, "next_random=true", &rcursor)); + + /* Perform updates in a txn to confirm that we see only the original. */ + testutil_check(session->open_cursor(session, name, NULL, "overwrite", &wcursor)); + for (i = 0; i < NUM_DOCS; i++) { + rand_str(i, str); + str[0] = 'A'; + wcursor->set_key(wcursor, i); + wcursor->set_value(wcursor, str); + testutil_check(wcursor->update(wcursor)); + } + testutil_check(wcursor->close(wcursor)); + printf("%d documents set to update\n", NUM_DOCS); + + /* Random reads, which should see the original values */ + query_docs(rcursor, false); + testutil_check(rcursor->close(rcursor)); + + /* Finish the txn */ + testutil_check(session2->rollback_transaction(session2, NULL)); + + /* Random reads, which should see the updated values */ + testutil_check(session2->open_cursor(session2, name, NULL, "next_random=true", &rcursor)); + query_docs(rcursor, true); + testutil_check(rcursor->close(rcursor)); + + /* Setup a pre-delete txn */ + testutil_check(session2->begin_transaction(session2, "isolation=snapshot")); + testutil_check(session2->open_cursor(session2, name, NULL, "next_random=true", &rcursor)); + + /* Delete all but one document */ + testutil_check(session->open_cursor(session, name, NULL, "overwrite", &wcursor)); + for (i = 0; i < NUM_DOCS - 1; i++) { + wcursor->set_key(wcursor, i); + testutil_check(wcursor->remove(wcursor)); + } + testutil_check(wcursor->close(wcursor)); + printf("%d documents deleted\n", NUM_DOCS - 1); + + /* Random reads, which should not see the deletes */ + query_docs(rcursor, true); + testutil_check(rcursor->close(rcursor)); + + /* Rollback the txn so we can see the deletes */ + testutil_check(session2->rollback_transaction(session2, NULL)); + + /* Find the one remaining document 3 times */ + testutil_check(session2->open_cursor(session2, name, NULL, "next_random=true", &rcursor)); + for (i = 0; i < 3; i++) { + testutil_check(rcursor->next(rcursor)); + testutil_check(rcursor->get_key(rcursor, &key)); + testutil_check(rcursor->get_value(rcursor, &value)); + /* There should only be one value available to us */ + testutil_assertfmt((uint64_t)key.data == NUM_DOCS - 1, "expected %d and got %" PRIu64, + NUM_DOCS - 1, (uint64_t)key.data); + check_str((uint64_t)key.data, (char *)value.data, true); + } + printf("Found the deleted doc 3 times\n"); + testutil_check(rcursor->close(rcursor)); + + /* Repopulate the table for compact. */ + testutil_check(session->open_cursor(session, name, NULL, "overwrite", &wcursor)); + for (i = 0; i < NUM_DOCS - 1; i++) { + wcursor->set_key(wcursor, i); + rand_str(i, str); + str[0] = 'A'; + wcursor->set_value(wcursor, str); + testutil_check(wcursor->insert(wcursor)); + } + testutil_check(wcursor->close(wcursor)); + + /* Run random cursor queries while compact is running */ + testutil_check(session2->open_cursor(session2, name, NULL, "next_random=true", &rcursor)); + testutil_check(pthread_create(&thread, NULL, compact_thread, session)); + query_docs(rcursor, true); + testutil_check(rcursor->close(rcursor)); + testutil_check(pthread_join(thread, NULL)); + + /* Delete everything. Check for infinite loops */ + testutil_check(session->open_cursor(session, name, NULL, "overwrite", &wcursor)); + for (i = 0; i < NUM_DOCS; i++) { + wcursor->set_key(wcursor, i); + testutil_check(wcursor->remove(wcursor)); + } + testutil_check(wcursor->close(wcursor)); + + testutil_check(session2->open_cursor(session2, name, NULL, "next_random=true", &rcursor)); + for (i = 0; i < 3; i++) + testutil_assert(rcursor->next(rcursor) == WT_NOTFOUND); + printf("Successfully got WT_NOTFOUND\n"); + + testutil_cleanup(opts); + return (EXIT_SUCCESS); } |