@@ -331,11 +331,14 @@ bool StorageEngineImpl::_handleInternalIdents(
331331 const std::string& ident,
332332 InternalIdentReconcilePolicy internalIdentReconcilePolicy,
333333 ReconcileResult* reconcileResult,
334- std::set<std::string>* internalIdentsToDrop) {
334+ std::set<std::string>* internalIdentsToDrop,
335+ std::set<std::string>* allInternalIdents) {
335336 if (!_catalog->isInternalIdent (ident)) {
336337 return false ;
337338 }
338339
340+ allInternalIdents->insert (ident);
341+
339342 if (InternalIdentReconcilePolicy::kDrop == internalIdentReconcilePolicy ||
340343 !supportsResumableIndexBuilds ()) {
341344 internalIdentsToDrop->insert (ident);
@@ -378,8 +381,6 @@ bool StorageEngineImpl::_handleInternalIdents(
378381 reconcileResult->indexBuildsToResume .push_back (resumeInfo);
379382
380383 // Once we have parsed the resume info, we can safely drop the internal ident.
381- // TODO SERVER-49846: revisit this logic since this could cause the side tables
382- // associated with the index build to be orphaned if resuming fails.
383384 internalIdentsToDrop->insert (ident);
384385
385386 LOGV2 (4916301 ,
@@ -435,6 +436,7 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
435436 catalogIdents.insert (vec.begin (), vec.end ());
436437 }
437438 std::set<std::string> internalIdentsToDrop;
439+ std::set<std::string> allInternalIdents;
438440
439441 auto dropPendingIdents = _dropPendingIdentReaper.getAllIdentNames ();
440442
@@ -446,8 +448,12 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
446448 continue ;
447449 }
448450
449- if (_handleInternalIdents (
450- opCtx, it, internalIdentReconcilePolicy, &reconcileResult, &internalIdentsToDrop)) {
451+ if (_handleInternalIdents (opCtx,
452+ it,
453+ internalIdentReconcilePolicy,
454+ &reconcileResult,
455+ &internalIdentsToDrop,
456+ &allInternalIdents)) {
451457 continue ;
452458 }
453459
@@ -623,6 +629,11 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
623629 }
624630 }
625631
632+ // If there are no index builds to resume, we should drop all internal idents.
633+ if (reconcileResult.indexBuildsToResume .empty ()) {
634+ internalIdentsToDrop.swap (allInternalIdents);
635+ }
636+
626637 for (auto && temp : internalIdentsToDrop) {
627638 LOGV2 (22257 , " Dropping internal ident" , " ident" _attr = temp);
628639 WriteUnitOfWork wuow (opCtx);
0 commit comments