diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2019-06-16 16:55:53 -0400 |
---|---|---|
committer | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2019-06-21 10:28:24 -0400 |
commit | a24ee3ffddee6c04d80aaf8b9ac7dc20d13a807a (patch) | |
tree | c96a7bc96737ad06e860479e70474e12db265c49 /src/mongo | |
parent | 469b1c11c70b5ac4a287b6eb13c0e0aac4748864 (diff) | |
download | mongo-a24ee3ffddee6c04d80aaf8b9ac7dc20d13a807a.tar.gz |
SERVER-41779: reconstructPreparedTransactions should use readSource kNoTimestamp
(cherry picked from commit f1dcaea4a97903fa7c785f31c55f484d275a5aed)
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/catalog_raii.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/catalog_raii.h | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/repl/transaction_oplog_application.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp | 5 |
6 files changed, 29 insertions, 10 deletions
diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp index d3e4c1f5e60..3b2b4ed417a 100644 --- a/src/mongo/db/catalog_raii.cpp +++ b/src/mongo/db/catalog_raii.cpp @@ -199,7 +199,9 @@ ConcealCollectionCatalogChangesBlock::~ConcealCollectionCatalogChangesBlock() { CollectionCatalog::get(_opCtx).onOpenCatalog(_opCtx); } -ReadSourceScope::ReadSourceScope(OperationContext* opCtx) +ReadSourceScope::ReadSourceScope(OperationContext* opCtx, + RecoveryUnit::ReadSource readSource, + boost::optional<Timestamp> provided) : _opCtx(opCtx), _originalReadSource(opCtx->recoveryUnit()->getTimestampReadSource()) { if (_originalReadSource == RecoveryUnit::ReadSource::kProvided) { @@ -207,7 +209,7 @@ ReadSourceScope::ReadSourceScope(OperationContext* opCtx) } _opCtx->recoveryUnit()->abandonSnapshot(); - _opCtx->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kUnset); + _opCtx->recoveryUnit()->setTimestampReadSource(readSource, provided); } ReadSourceScope::~ReadSourceScope() { diff --git a/src/mongo/db/catalog_raii.h b/src/mongo/db/catalog_raii.h index 8522f33c92b..5461d4af7e9 100644 --- a/src/mongo/db/catalog_raii.h +++ b/src/mongo/db/catalog_raii.h @@ -228,7 +228,9 @@ private: */ class ReadSourceScope { public: - ReadSourceScope(OperationContext* opCtx); + ReadSourceScope(OperationContext* opCtx, + RecoveryUnit::ReadSource readSource = RecoveryUnit::ReadSource::kUnset, + boost::optional<Timestamp> provided = boost::none); ~ReadSourceScope(); private: diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp index bf5f20021f9..8cd4a86de6b 100644 --- a/src/mongo/db/repl/initial_syncer.cpp +++ b/src/mongo/db/repl/initial_syncer.cpp @@ -101,6 +101,9 @@ MONGO_FAIL_POINT_DEFINE(rsSyncApplyStop); // Failpoint which causes the initial sync function to hang afte cloning all databases. MONGO_FAIL_POINT_DEFINE(initialSyncHangAfterDataCloning); +// Failpoint which causes the initial sync function to fail and hang before starting a new attempt. +MONGO_FAIL_POINT_DEFINE(failAndHangInitialSync); + namespace { using namespace executor; using CallbackArgs = executor::TaskExecutor::CallbackArgs; @@ -1384,6 +1387,12 @@ void InitialSyncer::_finishInitialSyncAttempt(const StatusWith<OpTimeAndWallTime _stats.initialSyncAttemptInfos.emplace_back( InitialSyncer::InitialSyncAttemptInfo{runTime, result.getStatus(), _syncSource}); + if (MONGO_FAIL_POINT(failAndHangInitialSync)) { + log() << "failAndHangInitialSync fail point enabled."; + MONGO_FAIL_POINT_PAUSE_WHILE_SET(failAndHangInitialSync); + result = Status(ErrorCodes::InternalError, "failAndHangInitialSync fail point enabled"); + } + if (result.isOK()) { // Scope guard will invoke _finishCallback(). return; diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 74112da3178..1ae959a1cda 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -1220,10 +1220,6 @@ void ReplicationCoordinatorImpl::_setMyLastAppliedOpTimeAndWallTime( _opTimeWaiterList.signalIf_inlock( [opTime](Waiter* waiter) { return waiter->opTime <= opTime; }); - if (opTime.isNull()) { - return; - } - // Update the local snapshot before updating the stable timestamp on the storage engine. New // transactions reading from the local snapshot should start before the oldest timestamp is // advanced to avoid races. @@ -1232,6 +1228,10 @@ void ReplicationCoordinatorImpl::_setMyLastAppliedOpTimeAndWallTime( // Notify the oplog waiters after updating the local snapshot. signalOplogWaiters(); + if (opTime.isNull()) { + return; + } + // Add the new applied optime to the list of stable optime candidates and then set the last // stable optime. Stable optimes are used to determine the last optime that it is safe to revert // the database to, in the event of a rollback via the 'recover to timestamp' method. If we are diff --git a/src/mongo/db/repl/transaction_oplog_application.cpp b/src/mongo/db/repl/transaction_oplog_application.cpp index dae9faa2f7d..20c01c432e7 100644 --- a/src/mongo/db/repl/transaction_oplog_application.cpp +++ b/src/mongo/db/repl/transaction_oplog_application.cpp @@ -397,8 +397,11 @@ void reconstructPreparedTransactions(OperationContext* opCtx, repl::OplogApplica log() << "Hit skipReconstructPreparedTransactions failpoint"; return; } - // Read the transactions table with its own snapshot and read timestamp. - ReadSourceScope readSourceScope(opCtx); + // Read the transactions table and the oplog collection without a timestamp. + // The below DBDirectClient read uses AutoGetCollectionForRead which could implicitly change the + // read source to kLastApplied. So we need to explicitly set the read source to kNoTimestamp to + // force reads in this scope to be untimestamped. + ReadSourceScope readSourceScope(opCtx, RecoveryUnit::ReadSource::kNoTimestamp); DBDirectClient client(opCtx); const auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp index 32299a71648..7216bc1727b 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp @@ -50,7 +50,10 @@ void WiredTigerSnapshotManager::setCommittedSnapshot(const Timestamp& timestamp) void WiredTigerSnapshotManager::setLocalSnapshot(const Timestamp& timestamp) { stdx::lock_guard<stdx::mutex> lock(_localSnapshotMutex); - _localSnapshot = timestamp; + if (timestamp.isNull()) + _localSnapshot = boost::none; + else + _localSnapshot = timestamp; } boost::optional<Timestamp> WiredTigerSnapshotManager::getLocalSnapshot() { |