Skip to content

Commit 3cb9e79

Browse files
benetyevergreen
authored andcommitted
SERVER-39002 clean up index builds on the secondary using the timestamp from the abortIndexBuild oplog entry
1 parent 5d9ecdd commit 3cb9e79

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/mongo/db/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ env.Library(
792792
'$BUILD_DIR/mongo/db/catalog/collection_catalog',
793793
'$BUILD_DIR/mongo/db/concurrency/lock_manager',
794794
'$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
795+
'$BUILD_DIR/mongo/db/repl/timestamp_block',
795796
'$BUILD_DIR/mongo/db/s/sharding_api_d',
796797
'$BUILD_DIR/mongo/idl/server_parameter',
797798
'$BUILD_DIR/mongo/util/fail_point',

src/mongo/db/index_builds_coordinator.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "mongo/db/operation_context.h"
4949
#include "mongo/db/repl/member_state.h"
5050
#include "mongo/db/repl/replication_coordinator.h"
51+
#include "mongo/db/repl/timestamp_block.h"
5152
#include "mongo/db/s/collection_sharding_state.h"
5253
#include "mongo/db/s/database_sharding_state.h"
5354
#include "mongo/db/server_options.h"
@@ -952,8 +953,22 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
952953
}
953954
} else {
954955
// We started this index build during oplog application as a secondary node.
956+
Timestamp abortIndexBuildTimestamp;
957+
if (status == ErrorCodes::IndexBuildAborted) {
958+
// We are on a secondary. We should be able to obtain the timestamp for cleaning
959+
// up the index build from the oplog entry unless the index build did not fail
960+
// due to processing an abortIndexBuild oplog entry. For example, a unique index
961+
// key violation would result in the index build failing on the secondary.
962+
stdx::unique_lock<Latch> lk(replState->mutex);
963+
invariant(replState->aborted, replState->buildUUID.toString());
964+
abortIndexBuildTimestamp = replState->abortTimestamp;
965+
}
966+
955967
unlockRSTLForIndexCleanup(opCtx);
956968
Lock::CollectionLock collLock(opCtx, nss, MODE_X);
969+
970+
// TimestampBlock is a no-op if the abort timestamp is unset.
971+
TimestampBlock tsBlock(opCtx, abortIndexBuildTimestamp);
957972
_indexBuildsManager.tearDownIndexBuild(
958973
opCtx, collection, replState->buildUUID, MultiIndexBlock::kNoopOnCleanUpFn);
959974
}

src/mongo/db/repl/oplog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ Status abortIndexBuild(OperationContext* opCtx,
225225
opCtx,
226226
indexBuildUUID,
227227
str::stream() << "abortIndexBuild oplog entry encountered: " << cause);
228+
IndexBuildsCoordinator::get(opCtx)->joinIndexBuild(opCtx, indexBuildUUID);
228229
return Status::OK();
229230
}
230231

0 commit comments

Comments
 (0)