From bd9cbc9a6a8d192895298133c2d3f65c00545617 Mon Sep 17 00:00:00 2001 From: Lingzhi Deng Date: Mon, 10 May 2021 17:52:03 +0000 Subject: SERVER-56783: Ignore NamespaceNotFound for createIndex in tenant oplog applier (cherry picked from commit 8f87828a42fbe05df15265eda5a0835772169f16) --- src/mongo/db/repl/tenant_oplog_applier.cpp | 33 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/mongo/db/repl/tenant_oplog_applier.cpp b/src/mongo/db/repl/tenant_oplog_applier.cpp index 44db0b4f06b..a5330eb1aa2 100644 --- a/src/mongo/db/repl/tenant_oplog_applier.cpp +++ b/src/mongo/db/repl/tenant_oplog_applier.cpp @@ -921,24 +921,27 @@ Status TenantOplogApplier::_applyOplogEntryOrGroupedInserts( if (op.getCommandType() == OplogEntry::CommandType::kCreateIndexes) { auto uuid = op.getUuid(); uassert(5652700, "Missing UUID from createIndex oplog entry", uuid); - AutoGetCollectionForRead autoColl(opCtx, {op.getNss().db().toString(), *uuid}); - if (!autoColl.getCollection()) { + try { + AutoGetCollectionForRead autoColl(opCtx, {op.getNss().db().toString(), *uuid}); + uassert(ErrorCodes::NamespaceNotFound, "Collection does not exist", autoColl); + // During tenant migration oplog application, we only need to apply createIndex on empty + // collections. Otherwise, the index is guaranteed to be dropped after. This is because + // we block index builds on the donor for the duration of the tenant migration. + if (!Helpers::findOne( + opCtx, autoColl.getCollection(), BSONObj(), false /* requireIndex */) + .isNull()) { + LOGV2_DEBUG(5652701, + 2, + "Tenant migration ignoring createIndex for non-empty collection", + "op"_attr = redact(op.toBSONForLogging()), + "tenant"_attr = _tenantId, + "migrationUuid"_attr = _migrationUuid); + return Status::OK(); + } + } catch (const ExceptionFor&) { // If the collection doesn't exist, it is safe to ignore. return Status::OK(); } - // During tenant migration oplog application, we only need to apply createIndex on empty - // collections. Otherwise, the index is guaranteed to be dropped after. This is because we - // block index builds on the donor for the duration of the tenant migration. - if (!Helpers::findOne(opCtx, autoColl.getCollection(), BSONObj(), false /* requireIndex */) - .isNull()) { - LOGV2_DEBUG(5652701, - 2, - "Tenant migration ignoring createIndex for non-empty collection", - "op"_attr = redact(op.toBSONForLogging()), - "tenant"_attr = _tenantId, - "migrationUuid"_attr = _migrationUuid); - return Status::OK(); - } } // We don't count tenant application in the ops applied stats. auto incrementOpsAppliedStats = [] {}; -- cgit v1.2.1