summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2021-01-11 14:18:31 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-14 23:21:19 +0000
commitf1e474787956e78972a07e846a8e64cf36af3328 (patch)
tree0d5b52ecf564253396fd12381a2b1874e4e05d9d
parenteb949a18023881d941e5367ff0ac6ccf4ae46b79 (diff)
downloadmongo-f1e474787956e78972a07e846a8e64cf36af3328.tar.gz
SERVER-46876 Compaction interrupts on EBUSY
(cherry picked from commit 0ce2fa7273aa7f4c7170c1bba3944efe46b4f043)
-rw-r--r--jstests/noPassthrough/compact_stops_on_ebusy.js29
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp10
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp10
3 files changed, 49 insertions, 0 deletions
diff --git a/jstests/noPassthrough/compact_stops_on_ebusy.js b/jstests/noPassthrough/compact_stops_on_ebusy.js
new file mode 100644
index 00000000000..b4a2e60cbd2
--- /dev/null
+++ b/jstests/noPassthrough/compact_stops_on_ebusy.js
@@ -0,0 +1,29 @@
+/**
+ * Checks that the compact command exits cleanly on EBUSY.
+ *
+ * @tags: [requires_wiredtiger, requires_persistence]
+ */
+(function() {
+ "use strict";
+
+ const conn = MongoRunner.runMongod({});
+ const db = conn.getDB("test");
+ const coll = db.getCollection(jsTest.name());
+
+ for (let i = 0; i < 10; i++) {
+ assert.commandWorked(coll.insert({x: i}));
+ }
+
+ const failPoints = ["WTCompactRecordStoreEBUSY", "WTCompactIndexEBUSY"];
+ let failPoint;
+ for (failPoint in failPoints) {
+ assert.commandWorked(
+ db.adminCommand({configureFailPoint: failPoints[failPoint], mode: "alwaysOn"}));
+ assert.commandFailedWithCode(db.runCommand({compact: jsTest.name()}),
+ ErrorCodes.Interrupted);
+ assert.commandWorked(
+ db.adminCommand({configureFailPoint: failPoints[failPoint], mode: "off"}));
+ }
+
+ MongoRunner.stopMongod(conn);
+}());
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
index fb993d906f3..435d2363223 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
@@ -77,6 +77,7 @@
namespace mongo {
namespace {
+MONGO_FAIL_POINT_DEFINE(WTCompactIndexEBUSY);
MONGO_FAIL_POINT_DEFINE(WTEmulateOutOfOrderNextIndexKey);
using std::string;
@@ -556,6 +557,15 @@ Status WiredTigerIndex::compact(OperationContext* opCtx) {
WT_SESSION* s = WiredTigerRecoveryUnit::get(opCtx)->getSession()->getSession();
opCtx->recoveryUnit()->abandonSnapshot();
int ret = s->compact(s, uri().c_str(), "timeout=0");
+ if (MONGO_unlikely(WTCompactIndexEBUSY.shouldFail())) {
+ ret = EBUSY;
+ }
+
+ if (ret == EBUSY) {
+ return Status(ErrorCodes::Interrupted,
+ str::stream() << "Compaction interrupted on " << uri().c_str()
+ << " due to cache eviction pressure");
+ }
invariantWTOK(ret);
}
return Status::OK();
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index 92d195b29bc..c77b440b6ec 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -90,6 +90,7 @@ void checkOplogFormatVersion(OperationContext* opCtx, const std::string& uri) {
}
} // namespace
+MONGO_FAIL_POINT_DEFINE(WTCompactRecordStoreEBUSY);
MONGO_FAIL_POINT_DEFINE(WTWriteConflictException);
MONGO_FAIL_POINT_DEFINE(WTWriteConflictExceptionForReads);
@@ -1516,6 +1517,15 @@ Status WiredTigerRecordStore::compact(OperationContext* opCtx,
WT_SESSION* s = WiredTigerRecoveryUnit::get(opCtx)->getSession()->getSession();
opCtx->recoveryUnit()->abandonSnapshot();
int ret = s->compact(s, getURI().c_str(), "timeout=0");
+ if (MONGO_unlikely(WTCompactRecordStoreEBUSY.shouldFail())) {
+ ret = EBUSY;
+ }
+
+ if (ret == EBUSY) {
+ return Status(ErrorCodes::Interrupted,
+ str::stream() << "Compaction interrupted on " << getURI().c_str()
+ << " due to cache eviction pressure");
+ }
invariantWTOK(ret);
}
return Status::OK();