diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2019-04-02 14:35:00 -0400 |
---|---|---|
committer | Henrik Edin <henrik.edin@mongodb.com> | 2019-04-03 13:28:21 -0400 |
commit | b63457c9e8597a6704b0fb015d827425585a5bef (patch) | |
tree | 7f8fb28deac3077c3e568a0d9ac4b808a7e3079b /src/mongo | |
parent | 90d479b917e022ab0b7aa14a8d25ec12dfb99e65 (diff) | |
download | mongo-b63457c9e8597a6704b0fb015d827425585a5bef.tar.gz |
SERVER-40444 IndexCatalogEntry to use NamespaceString instead of plain string. This avoids converting between types later on.
Diffstat (limited to 'src/mongo')
22 files changed, 66 insertions, 55 deletions
diff --git a/src/mongo/db/catalog/index_catalog_entry.h b/src/mongo/db/catalog/index_catalog_entry.h index 5e80cefa661..6161c2feb90 100644 --- a/src/mongo/db/catalog/index_catalog_entry.h +++ b/src/mongo/db/catalog/index_catalog_entry.h @@ -62,7 +62,7 @@ public: inline IndexCatalogEntry(IndexCatalogEntry&&) = delete; inline IndexCatalogEntry& operator=(IndexCatalogEntry&&) = delete; - virtual const std::string& ns() const = 0; + virtual const NamespaceString& ns() const = 0; virtual void init(std::unique_ptr<IndexAccessMethod> accessMethod) = 0; diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.cpp b/src/mongo/db/catalog/index_catalog_entry_impl.cpp index ab574567009..f53f81c9205 100644 --- a/src/mongo/db/catalog/index_catalog_entry_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_entry_impl.cpp @@ -347,7 +347,7 @@ void IndexCatalogEntryImpl::setIndexKeyStringWithLongTypeBitsExistsOnDisk(Operat } void IndexCatalogEntryImpl::setNs(NamespaceString ns) { - _ns = ns.toString(); + _ns = ns; _descriptor->setNs(std::move(ns)); } diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.h b/src/mongo/db/catalog/index_catalog_entry_impl.h index eab59dfb287..812b7d65953 100644 --- a/src/mongo/db/catalog/index_catalog_entry_impl.h +++ b/src/mongo/db/catalog/index_catalog_entry_impl.h @@ -68,7 +68,7 @@ public: ~IndexCatalogEntryImpl() final; - const std::string& ns() const final { + const NamespaceString& ns() const final { return _ns; } @@ -209,7 +209,7 @@ private: // ----- - std::string _ns; + NamespaceString _ns; CollectionCatalogEntry* _collection; // not owned here diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index 230bec0e3fe..d9895b5aba1 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -1426,7 +1426,7 @@ void IndexCatalogImpl::prepareInsertDeleteOptions(OperationContext* opCtx, const IndexDescriptor* desc, InsertDeleteOptions* options) const { auto replCoord = repl::ReplicationCoordinator::get(opCtx); - if (replCoord->shouldRelaxIndexConstraints(opCtx, NamespaceString(desc->parentNS()))) { + if (replCoord->shouldRelaxIndexConstraints(opCtx, desc->parentNS())) { options->getKeysMode = IndexAccessMethod::GetKeysMode::kRelaxConstraints; } else { options->getKeysMode = IndexAccessMethod::GetKeysMode::kEnforceConstraints; diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp index 72ce0734bea..ab029faff3f 100644 --- a/src/mongo/db/commands/count_cmd.cpp +++ b/src/mongo/db/commands/count_cmd.cpp @@ -189,7 +189,7 @@ public: ctx.emplace(opCtx, CommandHelpers::parseNsOrUUID(dbname, cmdObj), AutoGetCollection::ViewMode::kViewsPermitted); - const auto nss = ctx->getNss(); + const auto& nss = ctx->getNss(); CurOpFailpointHelpers::waitWhileFailPointEnabled( &hangBeforeCollectionCount, opCtx, "hangBeforeCollectionCount", []() {}, false, nss); diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp index b0f63dc1a53..d06e244a2a0 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -145,9 +145,9 @@ bool AbstractIndexAccessMethod::ignoreKeyTooLong() { bool AbstractIndexAccessMethod::shouldCheckIndexKeySize(OperationContext* opCtx) { // Don't check index key size if we cannot write to the collection. That indicates we are a // secondary node and we should accept any index key. - const NamespaceString collName(_btreeState->ns()); const auto shouldRelaxConstraints = - repl::ReplicationCoordinator::get(opCtx)->shouldRelaxIndexConstraints(opCtx, collName); + repl::ReplicationCoordinator::get(opCtx)->shouldRelaxIndexConstraints(opCtx, + _btreeState->ns()); // Don't check index key size if FCV hasn't been initialized. return !shouldRelaxConstraints && diff --git a/src/mongo/db/index/index_build_interceptor.cpp b/src/mongo/db/index/index_build_interceptor.cpp index f4eb823e47e..99b6ac0c7e1 100644 --- a/src/mongo/db/index/index_build_interceptor.cpp +++ b/src/mongo/db/index/index_build_interceptor.cpp @@ -205,28 +205,31 @@ Status IndexBuildInterceptor::drainWritesIntoIndex(OperationContext* opCtx, // If we are here, either we have reached the end of the table or the batch is full, so // insert everything in one WriteUnitOfWork, and delete each inserted document from the side // writes table. - auto status = writeConflictRetry(opCtx, "index build drain", _indexCatalogEntry->ns(), [&] { - WriteUnitOfWork wuow(opCtx); - for (auto& operation : batch) { - auto status = - _applyWrite(opCtx, operation.second, options, &totalInserted, &totalDeleted); - if (!status.isOK()) { - return status; + auto status = + writeConflictRetry(opCtx, "index build drain", _indexCatalogEntry->ns().ns(), [&] { + WriteUnitOfWork wuow(opCtx); + for (auto& operation : batch) { + auto status = _applyWrite( + opCtx, operation.second, options, &totalInserted, &totalDeleted); + if (!status.isOK()) { + return status; + } + + // Delete the document from the table as soon as it has been inserted into the + // index. This ensures that no key is ever inserted twice and no keys are + // skipped. + _sideWritesTable->rs()->deleteRecord(opCtx, operation.first); } - // Delete the document from the table as soon as it has been inserted into the - // index. This ensures that no key is ever inserted twice and no keys are skipped. - _sideWritesTable->rs()->deleteRecord(opCtx, operation.first); - } - - // For rollback to work correctly, these writes need to be timestamped. The actual time - // is not important, as long as it not older than the most recent visible side write. - IndexTimestampHelper::setGhostCommitTimestampForWrite( - opCtx, NamespaceString(_indexCatalogEntry->ns())); + // For rollback to work correctly, these writes need to be timestamped. The actual + // time is not important, as long as it not older than the most recent visible side + // write. + IndexTimestampHelper::setGhostCommitTimestampForWrite(opCtx, + _indexCatalogEntry->ns()); - wuow.commit(); - return Status::OK(); - }); + wuow.commit(); + return Status::OK(); + }); if (!status.isOK()) { return status; } @@ -336,7 +339,7 @@ void IndexBuildInterceptor::_tryYield(OperationContext* opCtx) { MONGO_FAIL_POINT_BLOCK(hangDuringIndexBuildDrainYield, config) { StringData ns{config.getData().getStringField("namespace")}; - if (ns == _indexCatalogEntry->ns()) { + if (ns == _indexCatalogEntry->ns().ns()) { log() << "Hanging index build during drain yield"; MONGO_FAIL_POINT_PAUSE_WHILE_SET(hangDuringIndexBuildDrainYield); } diff --git a/src/mongo/db/index/index_descriptor.cpp b/src/mongo/db/index/index_descriptor.cpp index 44777ae30f9..96cb26f87ec 100644 --- a/src/mongo/db/index/index_descriptor.cpp +++ b/src/mongo/db/index/index_descriptor.cpp @@ -205,7 +205,7 @@ bool IndexDescriptor::areIndexOptionsEquivalent(const IndexDescriptor* other) co } void IndexDescriptor::setNs(NamespaceString ns) { - _parentNS = ns.toString(); + _parentNS = ns; _indexNamespace = ns.makeIndexNamespace(_indexName).ns(); // Construct a new infoObj with the namespace field replaced. diff --git a/src/mongo/db/index/index_descriptor.h b/src/mongo/db/index/index_descriptor.h index 3f405746931..a68eafbdfb7 100644 --- a/src/mongo/db/index/index_descriptor.h +++ b/src/mongo/db/index/index_descriptor.h @@ -160,7 +160,7 @@ public: } // Return the name of the indexed collection. - const std::string& parentNS() const { + const NamespaceString& parentNS() const { return _parentNS; } @@ -269,7 +269,7 @@ private: BSONObj _keyPattern; BSONObj _projection; std::string _indexName; - std::string _parentNS; + NamespaceString _parentNS; std::string _indexNamespace; bool _isIdIndex; bool _sparse; diff --git a/src/mongo/db/index/wildcard_access_method.cpp b/src/mongo/db/index/wildcard_access_method.cpp index 178af0d079b..80cc6377bf9 100644 --- a/src/mongo/db/index/wildcard_access_method.cpp +++ b/src/mongo/db/index/wildcard_access_method.cpp @@ -87,7 +87,7 @@ std::set<FieldRef> WildcardAccessMethod::_getMultikeyPathSet( MultikeyMetadataAccessStats* stats) const { return writeConflictRetry(opCtx, "wildcard multikey path retrieval", - _descriptor->parentNS(), + _descriptor->parentNS().ns(), [&]() -> std::set<FieldRef> { stats->numSeeks = 0; stats->keysExamined = 0; @@ -207,7 +207,7 @@ std::set<FieldRef> WildcardAccessMethod::getMultikeyPathSet( std::set<FieldRef> WildcardAccessMethod::getMultikeyPathSet( OperationContext* opCtx, MultikeyMetadataAccessStats* stats) const { return writeConflictRetry( - opCtx, "wildcard multikey path retrieval", _descriptor->parentNS(), [&]() { + opCtx, "wildcard multikey path retrieval", _descriptor->parentNS().ns(), [&]() { invariant(stats); stats->numSeeks = 0; stats->keysExamined = 0; diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript index f0b040be16c..49dca278980 100644 --- a/src/mongo/db/storage/SConscript +++ b/src/mongo/db/storage/SConscript @@ -33,6 +33,7 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/db/namespace_string', 'duplicate_key_error_info', ], ) diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp index 230b9363ca8..845e428e355 100644 --- a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp +++ b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp @@ -164,7 +164,7 @@ SortedDataBuilderInterface::SortedDataBuilderInterface(OperationContext* opCtx, Ordering order, const std::string& prefix, const std::string& identEnd, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern) : _opCtx(opCtx), diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl.h b/src/mongo/db/storage/biggie/biggie_sorted_impl.h index b56b9bdaf08..b399ec9da47 100644 --- a/src/mongo/db/storage/biggie/biggie_sorted_impl.h +++ b/src/mongo/db/storage/biggie/biggie_sorted_impl.h @@ -43,7 +43,7 @@ public: Ordering order, const std::string& prefix, const std::string& identEnd, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern); SpecialFormatInserted commit(bool mayInterrupt) override; @@ -59,7 +59,7 @@ private: std::string _prefix; std::string _identEnd; // Index metadata. - const std::string _collectionNamespace; + const NamespaceString _collectionNamespace; const std::string _indexName; const BSONObj _keyPattern; // Whether or not we've already added something before. @@ -188,7 +188,7 @@ private: std::string _prefix; std::string _identEnd; // Index metadata. - const std::string _collectionNamespace; + const NamespaceString _collectionNamespace; const std::string _indexName; const BSONObj _keyPattern; // These are the keystring representations of the _prefix and the _identEnd. diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp index f3b0968d0f1..13b26e66f37 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp @@ -91,7 +91,7 @@ public: EphemeralForTestBtreeBuilderImpl(IndexSet* data, long long* currentKeySize, bool dupsAllowed, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern) : _data(data), @@ -136,7 +136,7 @@ private: IndexEntryComparison _comparator; // used by the bulk builder to detect duplicate keys IndexSet::const_iterator _last; // or (key, RecordId) ordering violations - const std::string _collectionNamespace; + const NamespaceString _collectionNamespace; const std::string _indexName; const BSONObj _keyPattern; }; @@ -145,7 +145,7 @@ class EphemeralForTestBtreeImpl : public SortedDataInterface { public: EphemeralForTestBtreeImpl(IndexSet* data, bool isUnique, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern) : _data(data), @@ -513,7 +513,7 @@ private: long long _currentKeySize; const bool _isUnique; - const std::string _collectionNamespace; + const NamespaceString _collectionNamespace; const std::string _indexName; const BSONObj _keyPattern; }; @@ -523,7 +523,7 @@ private: // factories. We don't actually modify it. SortedDataInterface* getEphemeralForTestBtreeImpl(const Ordering& ordering, bool isUnique, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern, std::shared_ptr<void>* dataInOut) { diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h index fb4d62f7eff..2b8b566e711 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h @@ -42,7 +42,7 @@ class IndexCatalogEntry; */ SortedDataInterface* getEphemeralForTestBtreeImpl(const Ordering& ordering, bool isUnique, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern, std::shared_ptr<void>* dataInOut); diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl_test.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl_test.cpp index 1534ca34261..ad0b5b12d71 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl_test.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl_test.cpp @@ -45,8 +45,13 @@ public: EphemeralForBtreeImplTestHarnessHelper() : _order(Ordering::make(BSONObj())) {} std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique, bool partial) final { - return std::unique_ptr<SortedDataInterface>(getEphemeralForTestBtreeImpl( - _order, unique, "test.EphemeralForTest", "indexName", BSONObj(), &_data)); + return std::unique_ptr<SortedDataInterface>( + getEphemeralForTestBtreeImpl(_order, + unique, + NamespaceString("test.EphemeralForTest"), + "indexName", + BSONObj(), + &_data)); } std::unique_ptr<RecoveryUnit> newRecoveryUnit() final { diff --git a/src/mongo/db/storage/index_entry_comparison.cpp b/src/mongo/db/storage/index_entry_comparison.cpp index d9666478fca..c005f61885c 100644 --- a/src/mongo/db/storage/index_entry_comparison.cpp +++ b/src/mongo/db/storage/index_entry_comparison.cpp @@ -33,6 +33,7 @@ #include <ostream> #include "mongo/db/jsobj.h" +#include "mongo/db/namespace_string.h" #include "mongo/db/storage/duplicate_key_error_info.h" namespace mongo { @@ -168,7 +169,7 @@ BSONObj IndexEntryComparison::makeQueryObject(const BSONObj& keyPrefix, } Status buildDupKeyErrorStatus(const BSONObj& key, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern) { StringBuilder sb; diff --git a/src/mongo/db/storage/index_entry_comparison.h b/src/mongo/db/storage/index_entry_comparison.h index a8c0f18561b..649333a36ab 100644 --- a/src/mongo/db/storage/index_entry_comparison.h +++ b/src/mongo/db/storage/index_entry_comparison.h @@ -35,6 +35,7 @@ #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/db/jsobj.h" +#include "mongo/db/namespace_string.h" #include "mongo/db/record_id.h" namespace mongo { @@ -209,7 +210,7 @@ private: * Returns the formatted error status about the duplicate key. */ Status buildDupKeyErrorStatus(const BSONObj& key, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern); diff --git a/src/mongo/db/storage/mobile/mobile_index.cpp b/src/mongo/db/storage/mobile/mobile_index.cpp index 3736169fa69..f95440dfa85 100644 --- a/src/mongo/db/storage/mobile/mobile_index.cpp +++ b/src/mongo/db/storage/mobile/mobile_index.cpp @@ -265,7 +265,7 @@ public: BulkBuilderBase(MobileIndex* index, OperationContext* opCtx, bool dupsAllowed, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern) : _index(index), @@ -317,7 +317,7 @@ protected: OperationContext* const _opCtx; BSONObj _lastKey; const bool _dupsAllowed; - const std::string _collectionNamespace; + const NamespaceString _collectionNamespace; const std::string _indexName; const BSONObj _keyPattern; }; @@ -330,7 +330,7 @@ public: BulkBuilderStandard(MobileIndex* index, OperationContext* opCtx, bool dupsAllowed, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern) : BulkBuilderBase(index, opCtx, dupsAllowed, collectionNamespace, indexName, keyPattern) {} @@ -351,7 +351,7 @@ public: BulkBuilderUnique(MobileIndex* index, OperationContext* opCtx, bool dupsAllowed, - const std::string& collectionNamespace, + const NamespaceString& collectionNamespace, const std::string& indexName, const BSONObj& keyPattern) : BulkBuilderBase(index, opCtx, dupsAllowed, collectionNamespace, indexName, keyPattern) { diff --git a/src/mongo/db/storage/mobile/mobile_index.h b/src/mongo/db/storage/mobile/mobile_index.h index da8de94fde7..36e0736465b 100644 --- a/src/mongo/db/storage/mobile/mobile_index.h +++ b/src/mongo/db/storage/mobile/mobile_index.h @@ -138,7 +138,7 @@ protected: const Ordering _ordering; const KeyString::Version _keyStringVersion = KeyString::kLatestVersion; const std::string _ident; - const std::string _collectionNamespace; + const NamespaceString _collectionNamespace; const std::string _indexName; const BSONObj _keyPattern; }; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp index 63549bf5f6c..8d2804fba71 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp @@ -198,7 +198,7 @@ StatusWith<std::string> WiredTigerIndex::generateCreateString(const std::string& ss << "block_compressor=" << wiredTigerGlobalOptions.indexBlockCompressor << ","; ss << WiredTigerCustomizationHooks::get(getGlobalServiceContext()) - ->getTableCreateConfig(desc.parentNS()); + ->getTableCreateConfig(desc.parentNS().ns()); ss << sysIndexConfig << ","; ss << collIndexConfig << ","; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h index 355ef064e42..e4a6d84c447 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h @@ -138,7 +138,7 @@ public: return _keyStringVersion; } - std::string collectionNamespace() const { + const NamespaceString& collectionNamespace() const { return _collectionNamespace; } @@ -184,7 +184,7 @@ protected: int _dataFormatVersion; std::string _uri; uint64_t _tableId; - const std::string _collectionNamespace; + const NamespaceString _collectionNamespace; const std::string _indexName; const BSONObj _keyPattern; KVPrefix _prefix; |