diff options
author | Louis Williams <louis.williams@mongodb.com> | 2018-09-20 14:22:27 -0400 |
---|---|---|
committer | Louis Williams <louis.williams@mongodb.com> | 2018-09-24 16:30:44 -0400 |
commit | 6d6ed710c9c3fa701e38e82a59e5b21014e5a944 (patch) | |
tree | b5df7b2b56806db948d0b17c5fdcd3a79c48809d | |
parent | 74dea95986ff33ab9d0d757b7a38b608a67d6f21 (diff) | |
download | mongo-6d6ed710c9c3fa701e38e82a59e5b21014e5a944.tar.gz |
SERVER-37121 Retry timestamping secondary background index builds
(cherry picked from commit 1b7b5200e158345d8818b00b039fccdccbed7aa2)
-rw-r--r-- | src/mongo/db/index_builder.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp index e70494335ff..c00702e476b 100644 --- a/src/mongo/db/index_builder.cpp +++ b/src/mongo/db/index_builder.cpp @@ -243,10 +243,26 @@ Status IndexBuilder::_build(OperationContext* opCtx, writeConflictRetry(opCtx, "Commit index build", ns.ns(), [opCtx, &indexer, &ns] { WriteUnitOfWork wunit(opCtx); indexer.commit(); + if (requiresGhostCommitTimestamp(opCtx, ns)) { - fassert(50701, - opCtx->recoveryUnit()->setTimestamp( - LogicalClock::get(opCtx)->getClusterTime().asTimestamp())); + + auto tryTimestamp = [opCtx] { + auto status = opCtx->recoveryUnit()->setTimestamp( + LogicalClock::get(opCtx)->getClusterTime().asTimestamp()); + if (status.code() == ErrorCodes::BadValue) { + LOG(1) << "Temporarily could not timestamp the index build commit: " + << status.reason(); + return false; + } + fassert(50701, status); + return true; + }; + + // Timestamping the index build may fail in rare cases if retrieving the cluster time + // races with the stable timestamp advancing. It should be retried immediately. + while (!tryTimestamp()) { + opCtx->checkForInterrupt(); + } } wunit.commit(); }); |