summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2020-02-21 18:02:40 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-22 04:23:39 +0000
commit864fbf14ed92ce263c4481b960285fce6f407fb6 (patch)
tree96b285b81f853b87986bb48fa6497cfa0cf3e81f
parentc4b918f7335495a8d5fc7f70ed14a9d674a4f289 (diff)
downloadmongo-864fbf14ed92ce263c4481b960285fce6f407fb6.tar.gz
SERVER-46229 avoid using side transaction to set multikey flag if the index was created in the same multi-document transaction
-rw-r--r--src/mongo/db/catalog/index_catalog_entry_impl.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.cpp b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
index 2a9593d7ca8..ac57473dd05 100644
--- a/src/mongo/db/catalog/index_catalog_entry_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
@@ -278,8 +278,16 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
// multikey flag write and the parent transaction. We can do this write separately and commit it
// before the parent transaction commits.
auto txnParticipant = TransactionParticipant::get(opCtx);
- if (opCtx->inMultiDocumentTransaction()) {
+ while (opCtx->inMultiDocumentTransaction()) {
TransactionParticipant::SideTransactionBlock sideTxn(opCtx);
+
+ // If the index is not visible within the side transaction, the index may have been created,
+ // but not committed, in the parent transaction. Therefore, we abandon the side transaction
+ // and set the multikey flag in the parent transaction.
+ if (!_catalogIsPresent(opCtx)) {
+ break;
+ }
+
writeConflictRetry(opCtx, "set index multikey", ns().ns(), [&] {
WriteUnitOfWork wuow(opCtx);
@@ -314,11 +322,13 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
});
wuow.commit();
});
- } else {
- indexMetadataHasChanged = DurableCatalog::get(opCtx)->setIndexIsMultikey(
- opCtx, _descriptor->getCollection()->getCatalogId(), _descriptor->indexName(), paths);
+
+ return;
}
+ indexMetadataHasChanged = DurableCatalog::get(opCtx)->setIndexIsMultikey(
+ opCtx, _descriptor->getCollection()->getCatalogId(), _descriptor->indexName(), paths);
+
opCtx->recoveryUnit()->onCommit(
[onMultikeyCommitFn, indexMetadataHasChanged](boost::optional<Timestamp>) {
onMultikeyCommitFn(indexMetadataHasChanged);