summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorWilliam Schultz <william.schultz@mongodb.com>2019-08-12 16:24:04 -0400
committerWilliam Schultz <william.schultz@mongodb.com>2019-08-12 16:24:04 -0400
commit20ba91db04c0b7b3d10fe2527b6938b1a14fcaa6 (patch)
tree22f677d19f2ed7865bc6f1feaa6538831f11a27a /src/mongo/db
parentff468c0b65af2cc978aa549d0ec7ed56553abf5a (diff)
downloadmongo-20ba91db04c0b7b3d10fe2527b6938b1a14fcaa6.tar.gz
SERVER-41766 Remove obsolete code for tracking multikey writes inside multi-document transactions
Now that we update the multikey flag within a transaction in a side transaction, the in-memory state about the multikey write will be naturally visible to subsequent writes inside the transaction, so we don't need to keep around any extra structures to enforce this anymore.
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/catalog/index_catalog.h2
-rw-r--r--src/mongo/db/catalog/index_catalog_entry.h2
-rw-r--r--src/mongo/db/catalog/index_catalog_entry_impl.cpp61
-rw-r--r--src/mongo/db/catalog/index_catalog_entry_impl.h2
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp6
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.h2
-rw-r--r--src/mongo/db/catalog/index_catalog_noop.h2
-rw-r--r--src/mongo/db/catalog/record_store_validate_adaptor.cpp6
-rw-r--r--src/mongo/db/exec/count_scan.h2
-rw-r--r--src/mongo/db/exec/distinct_scan.h2
-rw-r--r--src/mongo/db/exec/index_scan.h2
-rw-r--r--src/mongo/db/exec/stagedebug_cmd.cpp2
-rw-r--r--src/mongo/db/exec/text.cpp2
-rw-r--r--src/mongo/db/index/index_descriptor.cpp4
-rw-r--r--src/mongo/db/index/index_descriptor.h2
-rw-r--r--src/mongo/db/query/get_executor.cpp4
-rw-r--r--src/mongo/db/query/internal_plans.cpp2
-rw-r--r--src/mongo/db/repl/storage_interface_impl_test.cpp2
-rw-r--r--src/mongo/db/transaction_participant.cpp1
-rw-r--r--src/mongo/db/transaction_participant.h23
20 files changed, 27 insertions, 104 deletions
diff --git a/src/mongo/db/catalog/index_catalog.h b/src/mongo/db/catalog/index_catalog.h
index 6ca4e8aef7a..87f408ceb9b 100644
--- a/src/mongo/db/catalog/index_catalog.h
+++ b/src/mongo/db/catalog/index_catalog.h
@@ -381,7 +381,7 @@ public:
/**
* Returns true if the index 'idx' is multikey, and returns false otherwise.
*/
- virtual bool isMultikey(OperationContext* const opCtx, const IndexDescriptor* const idx) = 0;
+ virtual bool isMultikey(const IndexDescriptor* const idx) = 0;
/**
* Returns the path components that cause the index 'idx' to be multikey if the index supports
diff --git a/src/mongo/db/catalog/index_catalog_entry.h b/src/mongo/db/catalog/index_catalog_entry.h
index 6a5d1212ece..07246e14f03 100644
--- a/src/mongo/db/catalog/index_catalog_entry.h
+++ b/src/mongo/db/catalog/index_catalog_entry.h
@@ -95,7 +95,7 @@ public:
/**
* Returns true if this index is multikey and false otherwise.
*/
- virtual bool isMultikey(OperationContext* opCtx) const = 0;
+ virtual bool isMultikey() const = 0;
/**
* Returns the path components that cause this index to be multikey if this index supports
diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.cpp b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
index f6e19d9942a..6c2418d1b63 100644
--- a/src/mongo/db/catalog/index_catalog_entry_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
@@ -141,53 +141,13 @@ bool IndexCatalogEntryImpl::isReady(OperationContext* opCtx) const {
return _isReady;
}
-bool IndexCatalogEntryImpl::isMultikey(OperationContext* opCtx) const {
- auto ret = _isMultikey.load();
- if (ret) {
- return true;
- }
-
- // Multikey updates are only persisted, to disk and in memory, when the transaction
- // commits. In the case of multi-statement transactions, a client attempting to read their own
- // transactions writes can return wrong results if their writes include multikey changes.
- //
- // To accomplish this, the write-path will persist multikey changes on the `Session` object
- // and the read-path will query this state before determining there is no interesting multikey
- // state. Note, it's always legal, though potentially wasteful, to return `true`.
- auto txnParticipant = TransactionParticipant::get(opCtx);
- if (!txnParticipant || !txnParticipant.transactionIsOpen()) {
- return false;
- }
-
- invariant(txnParticipant);
-
- for (const MultikeyPathInfo& path : txnParticipant.getUncommittedMultikeyPathInfos()) {
- if (path.nss == ns() && path.indexName == _descriptor->indexName()) {
- return true;
- }
- }
-
- return false;
+bool IndexCatalogEntryImpl::isMultikey() const {
+ return _isMultikey.load();
}
MultikeyPaths IndexCatalogEntryImpl::getMultikeyPaths(OperationContext* opCtx) const {
stdx::lock_guard<stdx::mutex> lk(_indexMultikeyPathsMutex);
-
- auto txnParticipant = TransactionParticipant::get(opCtx);
- if (!txnParticipant || !txnParticipant.transactionIsOpen()) {
- return _indexMultikeyPaths;
- }
-
- invariant(txnParticipant);
-
- MultikeyPaths ret = _indexMultikeyPaths;
- for (const MultikeyPathInfo& path : txnParticipant.getUncommittedMultikeyPathInfos()) {
- if (path.nss == ns() && path.indexName == _descriptor->indexName()) {
- MultikeyPathTracker::mergeMultikeyPaths(&ret, path.multikeyPaths);
- }
- }
-
- return ret;
+ return _indexMultikeyPaths;
}
// ---
@@ -204,7 +164,7 @@ void IndexCatalogEntryImpl::setIsReady(bool newIsReady) {
void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
const MultikeyPaths& multikeyPaths) {
- if (!_indexTracksPathLevelMultikeyInfo && isMultikey(opCtx)) {
+ if (!_indexTracksPathLevelMultikeyInfo && isMultikey()) {
// If the index is already set as multikey and we don't have any path-level information to
// update, then there's nothing more for us to do.
return;
@@ -339,19 +299,6 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
[onMultikeyCommitFn, indexMetadataHasChanged](boost::optional<Timestamp>) {
onMultikeyCommitFn(indexMetadataHasChanged);
});
-
- // Within a multi-document transaction, reads should be able to see the effect of previous
- // writes done within that transaction. If a previous write in a transaction has set the index
- // to be multikey, then a subsequent read MUST know that fact in order to return correct
- // results. This is true in general for multikey writes. Since we don't update the in-memory
- // multikey flag until after the transaction commits, we track extra information here to let
- // subsequent readers within the same transaction know if this index was set as multikey by a
- // previous write in the transaction.
- if (opCtx->inMultiDocumentTransaction()) {
- invariant(txnParticipant);
- txnParticipant.addUncommittedMultikeyPathInfo(
- MultikeyPathInfo{ns(), _descriptor->indexName(), std::move(paths)});
- }
}
// ----
diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.h b/src/mongo/db/catalog/index_catalog_entry_impl.h
index 4e011e98b33..e11322d63e3 100644
--- a/src/mongo/db/catalog/index_catalog_entry_impl.h
+++ b/src/mongo/db/catalog/index_catalog_entry_impl.h
@@ -118,7 +118,7 @@ public:
/**
* Returns true if this index is multikey, and returns false otherwise.
*/
- bool isMultikey(OperationContext* opCtx) const final;
+ bool isMultikey() const final;
/**
* Returns the path components that cause this index to be multikey if this index supports
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index b3abf64ad83..d20de36536f 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -949,10 +949,10 @@ void IndexCatalogImpl::deleteIndexFromDisk(OperationContext* opCtx, const string
}
}
-bool IndexCatalogImpl::isMultikey(OperationContext* opCtx, const IndexDescriptor* idx) {
+bool IndexCatalogImpl::isMultikey(const IndexDescriptor* const idx) {
IndexCatalogEntry* entry = _readyIndexes.find(idx);
invariant(entry);
- return entry->isMultikey(opCtx);
+ return entry->isMultikey();
}
MultikeyPaths IndexCatalogImpl::getMultikeyPaths(OperationContext* opCtx,
@@ -1109,7 +1109,7 @@ const IndexDescriptor* IndexCatalogImpl::findShardKeyPrefixedIndex(OperationCont
if (!shardKey.isPrefixOf(desc->keyPattern(), SimpleBSONElementComparator::kInstance))
continue;
- if (!desc->isMultikey(opCtx) && hasSimpleCollation)
+ if (!desc->isMultikey() && hasSimpleCollation)
return desc;
if (!requireSingleKey && hasSimpleCollation)
diff --git a/src/mongo/db/catalog/index_catalog_impl.h b/src/mongo/db/catalog/index_catalog_impl.h
index ddffb2802fd..0d2bf6ecf05 100644
--- a/src/mongo/db/catalog/index_catalog_impl.h
+++ b/src/mongo/db/catalog/index_catalog_impl.h
@@ -225,7 +225,7 @@ public:
/**
* Returns true if the index 'idx' is multikey, and returns false otherwise.
*/
- bool isMultikey(OperationContext* opCtx, const IndexDescriptor* idx) override;
+ bool isMultikey(const IndexDescriptor* const idx) override;
/**
* Returns the path components that cause the index 'idx' to be multikey if the index supports
diff --git a/src/mongo/db/catalog/index_catalog_noop.h b/src/mongo/db/catalog/index_catalog_noop.h
index 5358a13bdf5..ec5a264b450 100644
--- a/src/mongo/db/catalog/index_catalog_noop.h
+++ b/src/mongo/db/catalog/index_catalog_noop.h
@@ -178,7 +178,7 @@ public:
return {};
}
- bool isMultikey(OperationContext* const opCtx, const IndexDescriptor* const idx) {
+ bool isMultikey(const IndexDescriptor* const idx) {
return false;
}
diff --git a/src/mongo/db/catalog/record_store_validate_adaptor.cpp b/src/mongo/db/catalog/record_store_validate_adaptor.cpp
index 674576f9057..7bfc00e8460 100644
--- a/src/mongo/db/catalog/record_store_validate_adaptor.cpp
+++ b/src/mongo/db/catalog/record_store_validate_adaptor.cpp
@@ -103,7 +103,7 @@ Status RecordStoreValidateAdaptor::validate(const RecordId& recordId,
&multikeyPaths,
recordId);
- if (!descriptor->isMultikey(_opCtx) &&
+ if (!descriptor->isMultikey() &&
iam->shouldMarkIndexAsMultikey(
{documentKeySet.begin(), documentKeySet.end()},
{multikeyMetadataKeys.begin(), multikeyMetadataKeys.end()},
@@ -290,8 +290,8 @@ void RecordStoreValidateAdaptor::validateIndexKeyCount(const IndexDescriptor* id
// collection. This check is only valid for indexes that are not multikey (indexed arrays
// produce an index key per array entry) and not $** indexes which can produce index keys for
// multiple paths within a single document.
- if (results.valid && !idx->isMultikey(_opCtx) &&
- idx->getIndexType() != IndexType::INDEX_WILDCARD && numTotalKeys > numRecs) {
+ if (results.valid && !idx->isMultikey() && idx->getIndexType() != IndexType::INDEX_WILDCARD &&
+ numTotalKeys > numRecs) {
std::string err = str::stream()
<< "index " << idx->indexName() << " is not multi-key, but has more entries ("
<< numTotalKeys << ") than documents in the index (" << numRecs << ")";
diff --git a/src/mongo/db/exec/count_scan.h b/src/mongo/db/exec/count_scan.h
index 83e98c03db1..5ebe00b0a7a 100644
--- a/src/mongo/db/exec/count_scan.h
+++ b/src/mongo/db/exec/count_scan.h
@@ -59,7 +59,7 @@ struct CountScanParams {
descriptor->indexName(),
descriptor->keyPattern(),
descriptor->getMultikeyPaths(opCtx),
- descriptor->isMultikey(opCtx)) {}
+ descriptor->isMultikey()) {}
const IndexDescriptor* indexDescriptor;
std::string name;
diff --git a/src/mongo/db/exec/distinct_scan.h b/src/mongo/db/exec/distinct_scan.h
index 7ce8cadaa6d..4596d92d378 100644
--- a/src/mongo/db/exec/distinct_scan.h
+++ b/src/mongo/db/exec/distinct_scan.h
@@ -61,7 +61,7 @@ struct DistinctParams {
descriptor->indexName(),
descriptor->keyPattern(),
descriptor->getMultikeyPaths(opCtx),
- descriptor->isMultikey(opCtx)) {}
+ descriptor->isMultikey()) {}
const IndexDescriptor* indexDescriptor;
std::string name;
diff --git a/src/mongo/db/exec/index_scan.h b/src/mongo/db/exec/index_scan.h
index cd1ca230d53..5ee7d807282 100644
--- a/src/mongo/db/exec/index_scan.h
+++ b/src/mongo/db/exec/index_scan.h
@@ -60,7 +60,7 @@ struct IndexScanParams {
descriptor->indexName(),
descriptor->keyPattern(),
descriptor->getMultikeyPaths(opCtx),
- descriptor->isMultikey(opCtx)) {}
+ descriptor->isMultikey()) {}
const IndexDescriptor* indexDescriptor;
diff --git a/src/mongo/db/exec/stagedebug_cmd.cpp b/src/mongo/db/exec/stagedebug_cmd.cpp
index ecca17e1287..3baee889ab1 100644
--- a/src/mongo/db/exec/stagedebug_cmd.cpp
+++ b/src/mongo/db/exec/stagedebug_cmd.cpp
@@ -292,7 +292,7 @@ public:
params.bounds.boundInclusion = IndexBounds::makeBoundInclusionFromBoundBools(
nodeArgs["startKeyInclusive"].Bool(), nodeArgs["endKeyInclusive"].Bool());
params.direction = nodeArgs["direction"].numberInt();
- params.shouldDedup = desc->isMultikey(opCtx);
+ params.shouldDedup = desc->isMultikey();
return new IndexScan(opCtx, params, workingSet, matcher);
} else if ("andHash" == nodeName) {
diff --git a/src/mongo/db/exec/text.cpp b/src/mongo/db/exec/text.cpp
index 571433c149c..93054164ebb 100644
--- a/src/mongo/db/exec/text.cpp
+++ b/src/mongo/db/exec/text.cpp
@@ -110,7 +110,7 @@ unique_ptr<PlanStage> TextStage::buildTextTree(OperationContext* opCtx,
ixparams.bounds.boundInclusion = BoundInclusion::kIncludeBothStartAndEndKeys;
ixparams.bounds.isSimpleRange = true;
ixparams.direction = -1;
- ixparams.shouldDedup = _params.index->isMultikey(opCtx);
+ ixparams.shouldDedup = _params.index->isMultikey();
indexScanList.push_back(std::make_unique<IndexScan>(opCtx, ixparams, ws, nullptr));
}
diff --git a/src/mongo/db/index/index_descriptor.cpp b/src/mongo/db/index/index_descriptor.cpp
index 8ebf493ba00..77478c7e6a6 100644
--- a/src/mongo/db/index/index_descriptor.cpp
+++ b/src/mongo/db/index/index_descriptor.cpp
@@ -158,8 +158,8 @@ IndexVersion IndexDescriptor::getDefaultIndexVersion() {
return IndexVersion::kV2;
}
-bool IndexDescriptor::isMultikey(OperationContext* opCtx) const {
- return _collection->getIndexCatalog()->isMultikey(opCtx, this);
+bool IndexDescriptor::isMultikey() const {
+ return _collection->getIndexCatalog()->isMultikey(this);
}
MultikeyPaths IndexDescriptor::getMultikeyPaths(OperationContext* opCtx) const {
diff --git a/src/mongo/db/index/index_descriptor.h b/src/mongo/db/index/index_descriptor.h
index 7e955258ab7..496ba0a2e58 100644
--- a/src/mongo/db/index/index_descriptor.h
+++ b/src/mongo/db/index/index_descriptor.h
@@ -193,7 +193,7 @@ public:
}
// Is this index multikey?
- bool isMultikey(OperationContext* opCtx) const;
+ bool isMultikey() const;
MultikeyPaths getMultikeyPaths(OperationContext* opCtx) const;
diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp
index 9c33a86a6bd..d36775885ce 100644
--- a/src/mongo/db/query/get_executor.cpp
+++ b/src/mongo/db/query/get_executor.cpp
@@ -160,7 +160,7 @@ IndexEntry indexEntryFromIndexCatalogEntry(OperationContext* opCtx,
auto accessMethod = ice.accessMethod();
invariant(accessMethod);
- const bool isMultikey = desc->isMultikey(opCtx);
+ const bool isMultikey = desc->isMultikey();
const ProjectionExecAgg* projExec = nullptr;
std::set<FieldRef> multikeyPathSet;
@@ -1349,7 +1349,7 @@ QueryPlannerParams fillOutPlannerParamsForDistinct(OperationContext* opCtx,
if (desc->keyPattern().hasField(parsedDistinct.getKey())) {
if (!mayUnwindArrays &&
isAnyComponentOfPathMultikey(desc->keyPattern(),
- desc->isMultikey(opCtx),
+ desc->isMultikey(),
desc->getMultikeyPaths(opCtx),
parsedDistinct.getKey())) {
// If the caller requested "strict" distinct that does not "pre-unwind" arrays,
diff --git a/src/mongo/db/query/internal_plans.cpp b/src/mongo/db/query/internal_plans.cpp
index 594c23ada38..4e65301e867 100644
--- a/src/mongo/db/query/internal_plans.cpp
+++ b/src/mongo/db/query/internal_plans.cpp
@@ -211,7 +211,7 @@ std::unique_ptr<PlanStage> InternalPlanner::_indexScan(OperationContext* opCtx,
params.bounds.startKey = startKey;
params.bounds.endKey = endKey;
params.bounds.boundInclusion = boundInclusion;
- params.shouldDedup = descriptor->isMultikey(opCtx);
+ params.shouldDedup = descriptor->isMultikey();
std::unique_ptr<PlanStage> root =
std::make_unique<IndexScan>(opCtx, std::move(params), ws, nullptr);
diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp
index 451e809ef55..a5502f21cb2 100644
--- a/src/mongo/db/repl/storage_interface_impl_test.cpp
+++ b/src/mongo/db/repl/storage_interface_impl_test.cpp
@@ -2649,7 +2649,7 @@ TEST_F(StorageInterfaceImplTest, SetIndexIsMultikeySucceeds) {
AutoGetCollectionForReadCommand autoColl(opCtx, nss);
ASSERT_TRUE(autoColl.getCollection());
auto indexCatalog = autoColl.getCollection()->getIndexCatalog();
- ASSERT(indexCatalog->isMultikey(opCtx, indexCatalog->findIndexByName(opCtx, indexName)));
+ ASSERT(indexCatalog->isMultikey(indexCatalog->findIndexByName(opCtx, indexName)));
ASSERT(paths ==
indexCatalog->getMultikeyPaths(opCtx, indexCatalog->findIndexByName(opCtx, indexName)));
}
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index 56f063aa784..1e2327cdd3b 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -2071,7 +2071,6 @@ void TransactionParticipant::Participant::_resetTransactionState(
p().transactionOperations.clear();
o(wl).prepareOpTime = repl::OpTime();
o(wl).recoveryPrepareOpTime = repl::OpTime();
- p().multikeyPathInfo.clear();
p().autoCommit = boost::none;
// Release any locks held by this participant and abort the storage transaction.
diff --git a/src/mongo/db/transaction_participant.h b/src/mongo/db/transaction_participant.h
index caa0027a6b9..29f4f0e31c4 100644
--- a/src/mongo/db/transaction_participant.h
+++ b/src/mongo/db/transaction_participant.h
@@ -558,24 +558,6 @@ public:
void refreshLocksForPreparedTransaction(OperationContext* opCtx, bool yieldLocks);
/**
- * May only be called while a multi-document transaction is not committed and adds the
- * multi-key path info to the set of path infos to be updated at commit time.
- */
- void addUncommittedMultikeyPathInfo(MultikeyPathInfo info) {
- invariant(transactionIsOpen());
- p().multikeyPathInfo.emplace_back(std::move(info));
- }
-
- /**
- * May only be called while a multi-document transaction is not committed and returns the
- * path infos which have been added so far.
- */
- const std::vector<MultikeyPathInfo>& getUncommittedMultikeyPathInfos() const {
- invariant(transactionIsOpen());
- return p().multikeyPathInfo;
- }
-
- /**
* Called after a write under the specified transaction completes while the node is a
* primary and specifies the statement ids which were written. Must be called while the
* caller is still in the write's WUOW. Updates the on-disk state of the session to match
@@ -960,11 +942,6 @@ private:
// transaction. Currently only needed for diagnostics reporting.
boost::optional<bool> autoCommit;
- // Contains uncommitted multi-key path info entries which were modified under this
- // transaction so they can be applied to subsequent opreations before the transaction
- // commits
- std::vector<MultikeyPathInfo> multikeyPathInfo;
-
//
// Retryable writes state
//