|
48 | 48 | #include "mongo/db/operation_context.h" |
49 | 49 | #include "mongo/db/repl/member_state.h" |
50 | 50 | #include "mongo/db/repl/replication_coordinator.h" |
| 51 | +#include "mongo/db/repl/timestamp_block.h" |
51 | 52 | #include "mongo/db/s/collection_sharding_state.h" |
52 | 53 | #include "mongo/db/s/database_sharding_state.h" |
53 | 54 | #include "mongo/db/server_options.h" |
@@ -952,8 +953,22 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx, |
952 | 953 | } |
953 | 954 | } else { |
954 | 955 | // 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 | + |
955 | 967 | unlockRSTLForIndexCleanup(opCtx); |
956 | 968 | 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); |
957 | 972 | _indexBuildsManager.tearDownIndexBuild( |
958 | 973 | opCtx, collection, replState->buildUUID, MultiIndexBlock::kNoopOnCleanUpFn); |
959 | 974 | } |
|
0 commit comments