diff options
author | Geert Bosch <geert@mongodb.com> | 2017-11-13 10:35:55 -0500 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2017-11-13 19:51:21 -0500 |
commit | 002a4c7ad4b9b7f53adadc3ebae487ea369a67b6 (patch) | |
tree | 5eb9caeb74b219db5dde0a0651ec9a6eba49c922 /src/mongo/db/storage | |
parent | 351b4b12e45c7307d1bde5075d91b189423342c6 (diff) | |
download | mongo-002a4c7ad4b9b7f53adadc3ebae487ea369a67b6.tar.gz |
SERVER-31933 Add prepareSnapshot method to avoid doing this implicitly in _getNextOptimes mutex
Diffstat (limited to 'src/mongo/db/storage')
4 files changed, 15 insertions, 1 deletions
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 { |