diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2020-12-09 09:38:22 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-14 14:18:35 +0000 |
commit | 0c4247a3401c21b59f7f6553b169aecbf824091f (patch) | |
tree | ce719612a57b8393b8352471a52292c57858c537 /src/mongo/db/storage/snapshot_helper.h | |
parent | 17db86d32461a9f48680d27ec286a66f2f3203af (diff) | |
download | mongo-0c4247a3401c21b59f7f6553b169aecbf824091f.tar.gz |
SERVER-53299 Fix so AutoGetCollectionForReadLockFree only read replication state once when setting up read source.
Diffstat (limited to 'src/mongo/db/storage/snapshot_helper.h')
-rw-r--r-- | src/mongo/db/storage/snapshot_helper.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/mongo/db/storage/snapshot_helper.h b/src/mongo/db/storage/snapshot_helper.h index c24dfd16d8c..cc62cbec889 100644 --- a/src/mongo/db/storage/snapshot_helper.h +++ b/src/mongo/db/storage/snapshot_helper.h @@ -33,13 +33,20 @@ namespace mongo { namespace SnapshotHelper { -// Returns a ReadSource if we should change our current ReadSource. Returns boost::none otherwise. -boost::optional<RecoveryUnit::ReadSource> getNewReadSource(OperationContext* opCtx, - const NamespaceString& nss); +struct ReadSourceChange { + boost::optional<RecoveryUnit::ReadSource> newReadSource; + bool shouldReadAtLastApplied; +}; -bool shouldReadAtLastApplied(OperationContext* opCtx, - const NamespaceString& nss, - std::string* reason = nullptr); +/** + * Returns a ReadSourceChange containing data necessary to decide if we need to change read source. + * + * For Lock-Free Reads, the decisions made within this function based on replication state may + * become invalid after it returns and multiple calls may yield different answers. Higher level code + * must validate the relevance of the outcome based on replication state before and after calling + * this function. + */ +ReadSourceChange shouldChangeReadSource(OperationContext* opCtx, const NamespaceString& nss); bool collectionChangesConflictWithRead(boost::optional<Timestamp> collectionMin, boost::optional<Timestamp> readTimestamp); |