/*- * Public Domain 2014-present MongoDB, Inc. * Public Domain 2008-2014 WiredTiger, Inc. * * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ /* * This test creates two threads that continuously open and close cursors on the same collection. * One thread opens bulk cursors while the other opens standard ones. The intent is to create a * race between the two threads and end up with a standard cursor opened on a table while a bulk * cursor is already using it, which is illegal. */ #include "src/common/constants.h" #include "src/common/thread_manager.h" #include "src/storage/connection_manager.h" extern "C" { #include "wiredtiger.h" #include "test_util.h" } using namespace test_harness; void create_cursor(WT_SESSION *session, const std::string &uri, bool bulk); bool do_create = false; void create_cursor(WT_SESSION *session, const std::string &uri, bool bulk) { while (do_create) { WT_CURSOR *cursor; int ret = session->open_cursor(session, uri.c_str(), nullptr, bulk ? "bulk" : nullptr, &cursor); if (ret == 0) testutil_check(cursor->close(cursor)); } } int main(int argc, char *argv[]) { const std::string progname(testutil_set_progname(argv)); const std::string home_dir(std::string(DEFAULT_DIR) + '_' + progname); connection_manager::instance().create(CONNECTION_CREATE, home_dir); WT_CONNECTION *conn = connection_manager::instance().get_connection(); /* Open different sessions. */ WT_SESSION *session1, *session2; testutil_check(conn->open_session(conn, nullptr, nullptr, &session1)); testutil_check(conn->open_session(conn, nullptr, nullptr, &session2)); /* Create a collection. */ const std::string collection_name = "table:my_collection"; testutil_check( session1->create(session1, collection_name.c_str(), DEFAULT_FRAMEWORK_SCHEMA.c_str())); thread_manager t; do_create = true; /* Opens bulk cursors. */ t.add_thread(create_cursor, session1, collection_name, true); /* Opens standard cursors. */ t.add_thread(create_cursor, session2, collection_name, false); int test_duration_s = 10; std::this_thread::sleep_for(std::chrono::seconds(test_duration_s)); /* Stop the threads. */ do_create = false; t.join(); return (0); }