summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtienne Petrel <etienne.petrel@mongodb.com>2022-09-27 17:07:58 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-27 18:10:25 +0000
commitee585b3f3d01a1676211fb56aa47c2ec2c79dc73 (patch)
tree5d21d4e17e8f5f2d37f0c2356bfc0c918a5f49b9
parentb929ccd58eef0e2100c4ff287122fe43846562f5 (diff)
downloadmongo-ee585b3f3d01a1676211fb56aa47c2ec2c79dc73.tar.gz
Import wiredtiger: 4ddc2cc6d395b8412ca4f0d6937f487feaead947 from branch mongodb-master
ref: 441b9a3769..4ddc2cc6d3 for: 6.2.0-rc0 WT-9636 Use general event handler for compact interruption. (#8293)
-rw-r--r--src/third_party/wiredtiger/import.data2
-rw-r--r--src/third_party/wiredtiger/src/btree/bt_compact.c7
-rw-r--r--src/third_party/wiredtiger/src/include/wiredtiger.in1
-rw-r--r--src/third_party/wiredtiger/test/csuite/wt8057_compact_stress/main.c58
4 files changed, 62 insertions, 6 deletions
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data
index 02b9d0f7a4b..3fd00db763a 100644
--- a/src/third_party/wiredtiger/import.data
+++ b/src/third_party/wiredtiger/import.data
@@ -2,5 +2,5 @@
"vendor": "wiredtiger",
"github": "wiredtiger/wiredtiger.git",
"branch": "mongodb-master",
- "commit": "441b9a3769271ac32088dce23e1b9a4c10c31790"
+ "commit": "4ddc2cc6d395b8412ca4f0d6937f487feaead947"
}
diff --git a/src/third_party/wiredtiger/src/btree/bt_compact.c b/src/third_party/wiredtiger/src/btree/bt_compact.c
index 0b7072a168e..5a5b4a5c7a8 100644
--- a/src/third_party/wiredtiger/src/btree/bt_compact.c
+++ b/src/third_party/wiredtiger/src/btree/bt_compact.c
@@ -340,6 +340,13 @@ __wt_compact(WT_SESSION_IMPL *session)
if (++i > 100) {
bm->compact_progress(bm, session, &msg_count);
WT_ERR(__wt_session_compact_check_timeout(session));
+ if (session->event_handler->handle_general != NULL) {
+ ret = session->event_handler->handle_general(session->event_handler,
+ &(S2C(session))->iface, &session->iface, WT_EVENT_COMPACT_CHECK);
+ /* If the user's handler returned non-zero we return WT_ERROR to the caller. */
+ if (ret != 0)
+ WT_ERR_MSG(session, WT_ERROR, "compact interrupted by application");
+ }
if (__wt_cache_stuck(session))
WT_ERR(EBUSY);
diff --git a/src/third_party/wiredtiger/src/include/wiredtiger.in b/src/third_party/wiredtiger/src/include/wiredtiger.in
index c7727afcb14..c99331ea64e 100644
--- a/src/third_party/wiredtiger/src/include/wiredtiger.in
+++ b/src/third_party/wiredtiger/src/include/wiredtiger.in
@@ -3292,6 +3292,7 @@ const char *wiredtiger_strerror(int error) WT_ATTRIBUTE_LIBRARY_VISIBLE;
/*! WT_EVENT_HANDLER::special event types */
typedef enum {
+ WT_EVENT_COMPACT_CHECK, /*!< Compact check iteration. */
WT_EVENT_CONN_CLOSE, /*!< Connection closing. */
WT_EVENT_CONN_READY /*!< Connection is ready. */
} WT_EVENT_TYPE;
diff --git a/src/third_party/wiredtiger/test/csuite/wt8057_compact_stress/main.c b/src/third_party/wiredtiger/test/csuite/wt8057_compact_stress/main.c
index 91e3529cc33..73fc9fe18a7 100644
--- a/src/third_party/wiredtiger/test/csuite/wt8057_compact_stress/main.c
+++ b/src/third_party/wiredtiger/test/csuite/wt8057_compact_stress/main.c
@@ -40,6 +40,9 @@
#define NUM_RECORDS 100000
#define TIMEOUT 40
+static bool compact_error;
+static uint64_t compact_event;
+
/* Constants and variables declaration. */
/*
* You may want to add "verbose=[compact,compact_progress]" to the connection config string to get
@@ -73,11 +76,37 @@ subtest_error_handler(
return (0);
}
+/*
+ * handle_general --
+ * General event handler.
+ */
+static int
+handle_general(
+ WT_EVENT_HANDLER *handler, WT_CONNECTION *conn, WT_SESSION *session, WT_EVENT_TYPE type)
+{
+ (void)(handler);
+ (void)(conn);
+ (void)(session);
+ if (type != WT_EVENT_COMPACT_CHECK)
+ return (0);
+
+ /*
+ * The compact_event variable is cumulative. Return with an interrupt periodically but not too
+ * often. We don't want to change the nature of the test too much.
+ */
+ if (++compact_event % 8 == 0) {
+ printf(" *** Compact check interrupting compact with error\n");
+ compact_error = true;
+ return (-1);
+ }
+ return (0);
+}
+
static WT_EVENT_HANDLER event_handler = {
subtest_error_handler, NULL, /* Message handler */
NULL, /* Progress handler */
NULL, /* Close handler */
- NULL /* Special handler */
+ handle_general /* General handler */
};
static void sig_handler(int) WT_GCC_FUNC_DECL_ATTRIBUTE((noreturn));
@@ -166,7 +195,7 @@ run_test(bool column_store, bool preserve)
workload_compact(home, column_store ? table_config_col : table_config_row);
/*
- * We do not expect test to reach here. The child process should have been killed by the
+ * We do not expect the test to reach here. The child process should have been killed by the
* parent process.
*/
printf("Child finished processing...\n");
@@ -220,6 +249,7 @@ workload_compact(const char *home, const char *table_config)
WT_CONNECTION *conn;
WT_RAND_STATE rnd;
WT_SESSION *session;
+ int ret;
bool first_ckpt;
char ckpt_file[2048];
@@ -242,9 +272,10 @@ workload_compact(const char *home, const char *table_config)
populate(session, 0, NUM_RECORDS);
/*
- * Although we are repeating the steps 40 times, we expect parent process will kill us way
- * before than that.
+ * Although we are repeating the steps 40 times, we expect the parent process will kill us long
+ * before that number of iterations.
*/
+ compact_event = 0;
for (i = 0; i < 40; i++) {
printf("Running Loop: %" PRIu32 "\n", i + 1);
@@ -268,9 +299,26 @@ workload_compact(const char *home, const char *table_config)
remove_records(session, uri1, key_range_start, key_range_start + NUM_RECORDS / 3);
remove_records(session, uri2, key_range_start, key_range_start + NUM_RECORDS / 3);
+ compact_error = false;
/* Only perform compaction on the first table. */
- testutil_check(session->compact(session, uri1, NULL));
+ ret = session->compact(session, uri1, NULL);
+ /*
+ * If the handler function returned an error to WiredTiger, make sure an error was returned
+ * back to the caller.
+ */
+ if (compact_error)
+ testutil_assert(ret != 0);
+ else
+ testutil_assert(ret == 0);
+ /*
+ * We expect that sometime in the first several iterations at least one of those compact
+ * calls would have called the callback function. It is hard to predict on any given
+ * iteration so check the total once, after a while.
+ */
+ if (i == 5)
+ testutil_assert(compact_event != 0);
+ printf(" - Cumulative compact event callbacks: %" PRIu64 "\n", compact_event);
log_db_size(session, uri1);
/* If we made progress with compact, verify that compact stats support that. */