summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2017-11-13 10:35:55 -0500
committerGeert Bosch <geert@mongodb.com>2017-11-13 19:51:21 -0500
commit002a4c7ad4b9b7f53adadc3ebae487ea369a67b6 (patch)
tree5eb9caeb74b219db5dde0a0651ec9a6eba49c922
parent351b4b12e45c7307d1bde5075d91b189423342c6 (diff)
downloadmongo-002a4c7ad4b9b7f53adadc3ebae487ea369a67b6.tar.gz
SERVER-31933 Add prepareSnapshot method to avoid doing this implicitly in _getNextOptimes mutex
-rw-r--r--src/mongo/db/repl/oplog.cpp2
-rw-r--r--src/mongo/db/storage/recovery_unit.h8
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp5
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h1
5 files changed, 17 insertions, 1 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index dcc54adf696..a2535fdb44e 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -158,6 +158,8 @@ void _getNextOpTimes(OperationContext* opCtx,
term = replCoord->getTerm();
}
+ // Allow the storage engine to start the transaction outside the critical section.
+ opCtx->recoveryUnit()->prepareSnapshot();
stdx::lock_guard<stdx::mutex> lk(newOpMutex);
auto ts = LogicalClock::get(opCtx)->reserveTicks(count).asTimestamp();
diff --git a/src/mongo/db/storage/recovery_unit.h b/src/mongo/db/storage/recovery_unit.h
index fe9ed473163..5ac712b4887 100644
--- a/src/mongo/db/storage/recovery_unit.h
+++ b/src/mongo/db/storage/recovery_unit.h
@@ -85,6 +85,14 @@ public:
virtual void abandonSnapshot() = 0;
/**
+ * Informs the RecoveryUnit that a snapshot will be needed soon, if one was not already
+ * established. This specifically allows the storage engine to preallocate any required
+ * transaction resources while minimizing the critical section between generating a new
+ * timestamp and setting it using setTimestamp.
+ */
+ virtual void prepareSnapshot() {}
+
+ /**
* Informs this RecoveryUnit that all future reads through it should be from a snapshot
* marked as Majority Committed. Snapshots should still be separately acquired and newer
* committed snapshots should be used if available whenever implementations would normally
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index 232ecdcdbb7..336b7d9d486 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -1675,7 +1675,7 @@ void WiredTigerRecordStore::cappedTruncateAfter(OperationContext* opCtx,
Status WiredTigerRecordStore::oplogDiskLocRegister(OperationContext* opCtx,
const Timestamp& opTime) {
- // This starts a new transaction and gives it a timestamp.
+ // This labels the current transaction with a timestamp.
// This is required for oplog visibility to work correctly, as WiredTiger uses the transaction
// list to determine where there are holes in the oplog.
return opCtx->recoveryUnit()->setTimestamp(SnapshotName(opTime));
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
index 8be67c449a5..54db183fe36 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -178,6 +178,11 @@ void WiredTigerRecoveryUnit::abandonSnapshot() {
_areWriteUnitOfWorksBanned = false;
}
+void WiredTigerRecoveryUnit::prepareSnapshot() {
+ // Begin a new transaction, if one is not already started.
+ getSession();
+}
+
void* WiredTigerRecoveryUnit::writingPtr(void* data, size_t len) {
// This API should not be used for anything other than the MMAP V1 storage engine
MONGO_UNREACHABLE;
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
index 397d17a142b..a1040952dc3 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
@@ -70,6 +70,7 @@ public:
void registerChange(Change* change) override;
void abandonSnapshot() override;
+ void prepareSnapshot() override;
Status setReadFromMajorityCommittedSnapshot() override;
bool isReadingFromMajorityCommittedSnapshot() const override {