summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/commands/getmore_cmd.cpp2
-rw-r--r--src/mongo/db/db_raii.cpp2
-rw-r--r--src/mongo/db/query/find.cpp2
-rw-r--r--src/mongo/db/read_concern_mongod.cpp11
-rw-r--r--src/mongo/db/repl/storage_interface_impl_test.cpp2
-rw-r--r--src/mongo/db/rs_local_client.cpp4
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp2
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h2
-rw-r--r--src/mongo/db/storage/kv/kv_engine_timestamps_test.cpp16
-rw-r--r--src/mongo/db/storage/recovery_unit.h15
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp18
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h3
12 files changed, 32 insertions, 47 deletions
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp
index 02deebccc27..b47bcbd57d8 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -151,7 +151,7 @@ void applyCursorReadConcern(OperationContext* opCtx, repl::ReadConcernArgs rcArg
opCtx->recoveryUnit()->abandonSnapshot();
opCtx->recoveryUnit()->setTimestampReadSource(
RecoveryUnit::ReadSource::kMajorityCommitted);
- uassertStatusOK(opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot());
+ uassertStatusOK(opCtx->recoveryUnit()->majorityCommittedSnapshotAvailable());
break;
}
case repl::ReadConcernArgs::MajorityReadMechanism::kSpeculative: {
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp
index df1494408e1..cc6f62ddcb4 100644
--- a/src/mongo/db/db_raii.cpp
+++ b/src/mongo/db/db_raii.cpp
@@ -244,7 +244,7 @@ AutoGetCollectionForReadBase<AutoGetCollectionType>::AutoGetCollectionForReadBas
if (readSource == RecoveryUnit::ReadSource::kMajorityCommitted) {
replCoord->waitUntilSnapshotCommitted(opCtx, *minSnapshot);
- uassertStatusOK(opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot());
+ uassertStatusOK(opCtx->recoveryUnit()->majorityCommittedSnapshotAvailable());
}
{
diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp
index 9403b21e1e3..19499903222 100644
--- a/src/mongo/db/query/find.cpp
+++ b/src/mongo/db/query/find.cpp
@@ -364,7 +364,7 @@ Message getMore(OperationContext* opCtx,
cursorPin->getReadConcernArgs().getLevel() ==
repl::ReadConcernLevel::kMajorityReadConcern) {
opCtx->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kMajorityCommitted);
- uassertStatusOK(opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot());
+ uassertStatusOK(opCtx->recoveryUnit()->majorityCommittedSnapshotAvailable());
}
uassert(40548,
diff --git a/src/mongo/db/read_concern_mongod.cpp b/src/mongo/db/read_concern_mongod.cpp
index 0ee34f808b1..077b486ef44 100644
--- a/src/mongo/db/read_concern_mongod.cpp
+++ b/src/mongo/db/read_concern_mongod.cpp
@@ -421,13 +421,13 @@ Status waitForReadConcernImpl(OperationContext* opCtx,
"readConcernArgs"_attr = readConcernArgs);
ru->setTimestampReadSource(RecoveryUnit::ReadSource::kMajorityCommitted);
- Status status = ru->obtainMajorityCommittedSnapshot();
+ Status status = ru->majorityCommittedSnapshotAvailable();
// Wait until a snapshot is available.
while (status == ErrorCodes::ReadConcernMajorityNotAvailableYet) {
LOGV2_DEBUG(20992, debugLevel, "Snapshot not available yet.");
replCoord->waitUntilSnapshotCommitted(opCtx, Timestamp());
- status = ru->obtainMajorityCommittedSnapshot();
+ status = ru->majorityCommittedSnapshotAvailable();
}
if (!status.isOK()) {
@@ -436,11 +436,8 @@ Status waitForReadConcernImpl(OperationContext* opCtx,
LOGV2_DEBUG(20993,
debugLevel,
- "Using 'committed' snapshot: {CurOp_get_opCtx_opDescription} with readTs: "
- "{opCtx_recoveryUnit_getPointInTimeReadTimestamp}",
- "CurOp_get_opCtx_opDescription"_attr = CurOp::get(opCtx)->opDescription(),
- "opCtx_recoveryUnit_getPointInTimeReadTimestamp"_attr =
- ru->getPointInTimeReadTimestamp());
+ "Using 'committed' snapshot",
+ "operation_description"_attr = CurOp::get(opCtx)->opDescription());
}
return Status::OK();
}
diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp
index e78f89427ab..8e626e10f25 100644
--- a/src/mongo/db/repl/storage_interface_impl_test.cpp
+++ b/src/mongo/db/repl/storage_interface_impl_test.cpp
@@ -384,7 +384,7 @@ TEST_F(StorageInterfaceImplTest, GetRollbackIDReturnsBadStatusIfRollbackIDIsNotI
TEST_F(StorageInterfaceImplTest, SnapshotSupported) {
auto opCtx = getOperationContext();
- Status status = opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot();
+ Status status = opCtx->recoveryUnit()->majorityCommittedSnapshotAvailable();
ASSERT(status.isOK());
}
diff --git a/src/mongo/db/rs_local_client.cpp b/src/mongo/db/rs_local_client.cpp
index 253efa13eca..41d5ed47cc7 100644
--- a/src/mongo/db/rs_local_client.cpp
+++ b/src/mongo/db/rs_local_client.cpp
@@ -103,7 +103,7 @@ StatusWith<Shard::QueryResponse> RSLocalClient::queryOnce(
if (readConcernLevel == repl::ReadConcernLevel::kMajorityReadConcern) {
// Set up operation context with majority read snapshot so correct optime can be retrieved.
opCtx->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kMajorityCommitted);
- Status status = opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot();
+ Status status = opCtx->recoveryUnit()->majorityCommittedSnapshotAvailable();
// Wait for any writes performed by this ShardLocal instance to be committed and visible.
Status readConcernStatus = replCoord->waitUntilOpTimeForRead(
@@ -114,7 +114,7 @@ StatusWith<Shard::QueryResponse> RSLocalClient::queryOnce(
// Inform the storage engine to read from the committed snapshot for the rest of this
// operation.
- status = opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot();
+ status = opCtx->recoveryUnit()->majorityCommittedSnapshotAvailable();
if (!status.isOK()) {
return status;
}
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp
index 44d73995482..a74ccb08d2f 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp
@@ -98,7 +98,7 @@ bool RecoveryUnit::waitUntilDurable(OperationContext* opCtx) {
return true; // This is an in-memory storage engine.
}
-Status RecoveryUnit::obtainMajorityCommittedSnapshot() {
+Status RecoveryUnit::majorityCommittedSnapshotAvailable() const {
return Status::OK();
}
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h
index 9258c232f67..52f8dc5fe68 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h
@@ -51,7 +51,7 @@ public:
virtual void setOrderedCommit(bool orderedCommit) override;
- Status obtainMajorityCommittedSnapshot() final;
+ Status majorityCommittedSnapshotAvailable() const final;
void prepareUnitOfWork() override;
diff --git a/src/mongo/db/storage/kv/kv_engine_timestamps_test.cpp b/src/mongo/db/storage/kv/kv_engine_timestamps_test.cpp
index 817038d795b..96c7d1ab9b4 100644
--- a/src/mongo/db/storage/kv/kv_engine_timestamps_test.cpp
+++ b/src/mongo/db/storage/kv/kv_engine_timestamps_test.cpp
@@ -152,7 +152,7 @@ public:
int itCountCommitted() {
auto op = makeOperation();
op->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kMajorityCommitted);
- ASSERT_OK(op->recoveryUnit()->obtainMajorityCommittedSnapshot());
+ ASSERT_OK(op->recoveryUnit()->majorityCommittedSnapshotAvailable());
return itCountOn(op);
}
@@ -174,7 +174,7 @@ public:
auto op = makeOperation();
Lock::GlobalLock globalLock(op, MODE_IS);
op->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kMajorityCommitted);
- ASSERT_OK(op->recoveryUnit()->obtainMajorityCommittedSnapshot());
+ ASSERT_OK(op->recoveryUnit()->majorityCommittedSnapshotAvailable());
return readRecordOn(op, id);
}
@@ -241,21 +241,21 @@ TEST_F(SnapshotManagerTests, FailsWithNoCommittedSnapshot) {
op->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kMajorityCommitted);
// Before first snapshot is created.
- ASSERT_EQ(ru->obtainMajorityCommittedSnapshot(),
+ ASSERT_EQ(ru->majorityCommittedSnapshotAvailable(),
ErrorCodes::ReadConcernMajorityNotAvailableYet);
// There is a snapshot but it isn't committed.
auto snap = fetchAndIncrementTimestamp();
- ASSERT_EQ(ru->obtainMajorityCommittedSnapshot(),
+ ASSERT_EQ(ru->majorityCommittedSnapshotAvailable(),
ErrorCodes::ReadConcernMajorityNotAvailableYet);
// Now there is a committed snapshot.
snapshotManager->setCommittedSnapshot(snap);
- ASSERT_OK(ru->obtainMajorityCommittedSnapshot());
+ ASSERT_OK(ru->majorityCommittedSnapshotAvailable());
// Not anymore!
snapshotManager->clearCommittedSnapshot();
- ASSERT_EQ(ru->obtainMajorityCommittedSnapshot(),
+ ASSERT_EQ(ru->majorityCommittedSnapshotAvailable(),
ErrorCodes::ReadConcernMajorityNotAvailableYet);
}
@@ -273,7 +273,7 @@ TEST_F(SnapshotManagerTests, FailsAfterDropAllSnapshotsWhileYielded) {
// Start an operation using a committed snapshot.
auto snap = fetchAndIncrementTimestamp();
snapshotManager->setCommittedSnapshot(snap);
- ASSERT_OK(op->recoveryUnit()->obtainMajorityCommittedSnapshot());
+ ASSERT_OK(op->recoveryUnit()->majorityCommittedSnapshotAvailable());
ASSERT_EQ(itCountOn(op), 0); // acquires a snapshot.
// Everything still works until we abandon our snapshot.
@@ -328,7 +328,7 @@ TEST_F(SnapshotManagerTests, BasicFunctionality) {
auto longOp = makeOperation();
Lock::GlobalLock globalLock(longOp, MODE_IS);
longOp->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kMajorityCommitted);
- ASSERT_OK(longOp->recoveryUnit()->obtainMajorityCommittedSnapshot());
+ ASSERT_OK(longOp->recoveryUnit()->majorityCommittedSnapshotAvailable());
ASSERT_EQ(itCountOn(longOp), 3);
// If this fails, the snapshot contains writes that were rolled back.
diff --git a/src/mongo/db/storage/recovery_unit.h b/src/mongo/db/storage/recovery_unit.h
index e0fc02f4742..964d5b4fe29 100644
--- a/src/mongo/db/storage/recovery_unit.h
+++ b/src/mongo/db/storage/recovery_unit.h
@@ -240,11 +240,8 @@ public:
}
/**
- * Obtains a majority committed snapshot. Snapshots should still be separately acquired and
- * newer committed snapshots should be used if available whenever implementations would normally
- * change snapshots.
- *
- * If no snapshot has yet been marked as Majority Committed, returns a status with error code
+ * Returns whether or not a majority commmitted snapshot is available. If no snapshot has yet
+ * been marked as Majority Committed, returns a status with error code
* ReadConcernMajorityNotAvailableYet. After this returns successfully, at any point where
* implementations attempt to acquire committed snapshot, if there are none available due to a
* call to SnapshotManager::clearCommittedSnapshot(), a AssertionException with the same code
@@ -253,7 +250,7 @@ public:
* StorageEngines that don't support a SnapshotManager should use the default
* implementation.
*/
- virtual Status obtainMajorityCommittedSnapshot() {
+ virtual Status majorityCommittedSnapshotAvailable() const {
return {ErrorCodes::CommandNotSupported,
"Current storage engine does not support majority readConcerns"};
}
@@ -265,10 +262,10 @@ public:
* - when using ReadSource::kNoOverlap, the timestamp chosen by the storage engine.
* - when using ReadSource::kAllDurableSnapshot, the timestamp chosen using the storage
* engine's all_durable timestamp.
- * applied timestamp. Can return boost::none if no timestamp has been established.
+ * - when using ReadSource::kLastAppplied, the last applied timestamp. Can return boost::none
+ * if no timestamp has been established.
* - when using ReadSource::kMajorityCommitted, the majority committed timestamp chosen by the
- * storage engine after a transaction has been opened or after a call to
- * obtainMajorityCommittedSnapshot().
+ * storage engine after a transaction has been opened.
*
* This may passively start a storage engine transaction to establish a read timestamp.
*/
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
index 3e531b37175..ebc262d3cd8 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -496,14 +496,13 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) {
_mustBeTimestamped = false;
}
-Status WiredTigerRecoveryUnit::obtainMajorityCommittedSnapshot() {
+Status WiredTigerRecoveryUnit::majorityCommittedSnapshotAvailable() const {
invariant(_timestampReadSource == ReadSource::kMajorityCommitted);
auto snapshotName = _sessionCache->snapshotManager().getMinSnapshotForNextCommittedRead();
if (!snapshotName) {
return {ErrorCodes::ReadConcernMajorityNotAvailableYet,
"Read concern majority reads are currently not possible."};
}
- _majorityCommittedSnapshot = *snapshotName;
return Status::OK();
}
@@ -516,11 +515,6 @@ boost::optional<Timestamp> WiredTigerRecoveryUnit::getPointInTimeReadTimestamp()
switch (_timestampReadSource) {
case ReadSource::kNoTimestamp:
return boost::none;
- case ReadSource::kMajorityCommitted:
- // This ReadSource depends on a previous call to obtainMajorityCommittedSnapshot() and
- // does not require an open transaction to return a valid timestamp.
- invariant(!_majorityCommittedSnapshot.isNull());
- return _majorityCommittedSnapshot;
case ReadSource::kProvided:
// The read timestamp is set by the user and does not require a transaction to be open.
invariant(!_readAtTimestamp.isNull());
@@ -531,6 +525,7 @@ boost::optional<Timestamp> WiredTigerRecoveryUnit::getPointInTimeReadTimestamp()
case ReadSource::kNoOverlap:
case ReadSource::kLastApplied:
case ReadSource::kAllDurableSnapshot:
+ case ReadSource::kMajorityCommitted:
break;
}
@@ -548,12 +543,12 @@ boost::optional<Timestamp> WiredTigerRecoveryUnit::getPointInTimeReadTimestamp()
}
return boost::none;
case ReadSource::kAllDurableSnapshot:
+ case ReadSource::kMajorityCommitted:
invariant(!_readAtTimestamp.isNull());
return _readAtTimestamp;
// The follow ReadSources returned values in the first switch block.
case ReadSource::kNoTimestamp:
- case ReadSource::kMajorityCommitted:
case ReadSource::kProvided:
MONGO_UNREACHABLE;
}
@@ -583,11 +578,8 @@ void WiredTigerRecoveryUnit::_txnOpen() {
break;
}
case ReadSource::kMajorityCommitted: {
- // We reset _majorityCommittedSnapshot to the actual read timestamp used when the
- // transaction was started.
- _majorityCommittedSnapshot =
- _sessionCache->snapshotManager().beginTransactionOnCommittedSnapshot(
- session, _prepareConflictBehavior, _roundUpPreparedTimestamps);
+ _readAtTimestamp = _sessionCache->snapshotManager().beginTransactionOnCommittedSnapshot(
+ session, _prepareConflictBehavior, _roundUpPreparedTimestamps);
break;
}
case ReadSource::kLastApplied: {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
index 0916d60fda4..05dbbce7bc7 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
@@ -115,7 +115,7 @@ public:
void preallocateSnapshot() override;
void preallocateSnapshotForOplogRead() override;
- Status obtainMajorityCommittedSnapshot() override;
+ Status majorityCommittedSnapshotAvailable() const override;
boost::optional<Timestamp> getPointInTimeReadTimestamp() override;
@@ -297,7 +297,6 @@ private:
Timestamp _durableTimestamp;
Timestamp _prepareTimestamp;
boost::optional<Timestamp> _lastTimestampSet;
- Timestamp _majorityCommittedSnapshot;
Timestamp _readAtTimestamp;
Timestamp _catalogConflictTimestamp;
std::unique_ptr<Timer> _timer;