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-19 20:45:43 -0400 |
commit | f1dcaea4a97903fa7c785f31c55f484d275a5aed (patch) | |
tree | 22b6ebe2d59eea16492d3005db4e187893d84f98 /src | |
parent | 97f820a0d28e1cb3230c0a4560c2d9694c462a80 (diff) | |
download | mongo-f1dcaea4a97903fa7c785f31c55f484d275a5aed.tar.gz |
SERVER-41779: reconstructPreparedTransactions should use readSource kNoTimestamp
Diffstat (limited to 'src')
-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 efd30fb762d..ea15f87137d 100644 --- a/src/mongo/db/catalog_raii.cpp +++ b/src/mongo/db/catalog_raii.cpp @@ -198,7 +198,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) { @@ -206,7 +208,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 36043e60564..82fb2675497 100644 --- a/src/mongo/db/catalog_raii.h +++ b/src/mongo/db/catalog_raii.h @@ -227,7 +227,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 2038989393e..eda14fecb4d 100644 --- a/src/mongo/db/repl/initial_syncer.cpp +++ b/src/mongo/db/repl/initial_syncer.cpp @@ -104,6 +104,9 @@ MONGO_FAIL_POINT_DEFINE(initialSyncHangAfterDataCloning); // Failpoint which skips clearing _initialSyncState after a successful initial sync attempt. MONGO_FAIL_POINT_DEFINE(skipClearInitialSyncState); +// 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; @@ -1398,6 +1401,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 f97ebb90f04..0dae9ddaa05 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -1219,10 +1219,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. @@ -1231,6 +1227,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 8f376b44d18..37a03a58bf0 100644 --- a/src/mongo/db/repl/transaction_oplog_application.cpp +++ b/src/mongo/db/repl/transaction_oplog_application.cpp @@ -410,8 +410,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() { |