summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/oplog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/oplog.cpp')
-rw-r--r--src/mongo/db/repl/oplog.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index dce50640e27..c5aefc7b346 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -164,6 +164,16 @@ void applyImportCollectionDefault(OperationContext* opCtx,
"isDryRun"_attr = isDryRun);
}
+StringData getInvalidatingReason(const OplogApplication::Mode mode, const bool isDataConsistent) {
+ if (mode == OplogApplication::Mode::kInitialSync) {
+ return "initial sync"_sd;
+ } else if (!isDataConsistent) {
+ return "minvalid suggests inconsistent snapshot"_sd;
+ }
+
+ return ""_sd;
+}
+
} // namespace
ApplyImportCollectionFn applyImportCollection = applyImportCollectionDefault;
@@ -248,6 +258,7 @@ void writeToImageCollection(OperationContext* opCtx,
const Timestamp timestamp,
repl::RetryImageEnum imageKind,
const BSONObj& dataImage,
+ const StringData& invalidatedReason,
bool* upsertConfigImage) {
AutoGetCollection autoColl(opCtx, NamespaceString::kConfigImagesNamespace, LockMode::MODE_IX);
repl::ImageEntry imageEntry;
@@ -258,7 +269,7 @@ void writeToImageCollection(OperationContext* opCtx,
imageEntry.setImage(dataImage);
if (dataImage.isEmpty()) {
imageEntry.setInvalidated(true);
- imageEntry.setInvalidatedReason("initial sync"_sd);
+ imageEntry.setInvalidatedReason(invalidatedReason);
}
UpdateRequest request;
@@ -1084,6 +1095,7 @@ Status applyOperation_inlock(OperationContext* opCtx,
const OplogEntryOrGroupedInserts& opOrGroupedInserts,
bool alwaysUpsert,
OplogApplication::Mode mode,
+ const bool isDataConsistent,
IncrementOpsAppliedStatsFn incrementOpsAppliedStats) {
// Get the single oplog entry to be applied or the first oplog entry of grouped inserts.
auto op = opOrGroupedInserts.getOp();
@@ -1432,7 +1444,7 @@ Status applyOperation_inlock(OperationContext* opCtx,
request.setUpdateModification(std::move(updateMod));
request.setUpsert(upsert);
request.setFromOplogApplication(true);
- if (mode != OplogApplication::Mode::kInitialSync) {
+ if (mode != OplogApplication::Mode::kInitialSync && isDataConsistent) {
if (op.getNeedsRetryImage() == repl::RetryImageEnum::kPreImage) {
request.setReturnDocs(UpdateRequest::ReturnDocOption::RETURN_OLD);
} else if (op.getNeedsRetryImage() == repl::RetryImageEnum::kPostImage) {
@@ -1560,6 +1572,7 @@ Status applyOperation_inlock(OperationContext* opCtx,
// initial sync, the value passed in here is conveniently
// the empty BSONObj.
ur.requestedDocImage,
+ getInvalidatingReason(mode, isDataConsistent),
&upsertConfigImage);
}
@@ -1611,7 +1624,8 @@ Status applyOperation_inlock(OperationContext* opCtx,
request.setNsString(requestNss);
request.setQuery(deleteCriteria);
if (mode != OplogApplication::Mode::kInitialSync &&
- op.getNeedsRetryImage() == repl::RetryImageEnum::kPreImage) {
+ op.getNeedsRetryImage() == repl::RetryImageEnum::kPreImage &&
+ isDataConsistent) {
// When in initial sync, we'll pass an empty image into
// `writeToImageCollection`.
request.setReturnDeleted(true);
@@ -1624,17 +1638,13 @@ Status applyOperation_inlock(OperationContext* opCtx,
// isn't strictly necessary for correctness -- the `config.transactions` table
// is responsible for whether to retry. The motivation here is to simply reduce
// the number of states related documents in the two collections can be in.
- BSONObj imageDoc;
- if (result.nDeleted > 0 && mode != OplogApplication::Mode::kInitialSync) {
- imageDoc = result.requestedPreImage.get();
- }
-
writeToImageCollection(opCtx,
op.getSessionId().get(),
op.getTxnNumber().get(),
op.getTimestamp(),
repl::RetryImageEnum::kPreImage,
- imageDoc,
+ result.requestedPreImage.value_or(BSONObj()),
+ getInvalidatingReason(mode, isDataConsistent),
&upsertConfigImage);
}