diff options
author | Zach Yam <zach.yam@mongodb.com> | 2019-06-07 16:04:08 -0400 |
---|---|---|
committer | Zach Yam <zach.yam@mongodb.com> | 2019-06-12 10:44:04 -0400 |
commit | 90a74a50044d4daff7fa66e050bd76e70a0c7e56 (patch) | |
tree | 217077f05cfebe7aa8a37a6ab60440ce111aaf88 /src/mongo/db/storage | |
parent | 2cd33c3953e54018d8ed687f6c03c7575fe518eb (diff) | |
download | mongo-90a74a50044d4daff7fa66e050bd76e70a0c7e56.tar.gz |
Make get(Grouped)SortedDataInterface return a unique pointer
Diffstat (limited to 'src/mongo/db/storage')
15 files changed, 58 insertions, 71 deletions
diff --git a/src/mongo/db/storage/biggie/biggie_kv_engine.cpp b/src/mongo/db/storage/biggie/biggie_kv_engine.cpp index d0c4a4b987a..3aeefdf59c2 100644 --- a/src/mongo/db/storage/biggie/biggie_kv_engine.cpp +++ b/src/mongo/db/storage/biggie/biggie_kv_engine.cpp @@ -111,11 +111,10 @@ Status KVEngine::createSortedDataInterface(OperationContext* opCtx, return Status::OK(); // I don't think we actually need to do anything here } -mongo::SortedDataInterface* KVEngine::getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) { +std::unique_ptr<mongo::SortedDataInterface> KVEngine::getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) { _idents[ident.toString()] = false; - return new SortedDataInterface(opCtx, ident, desc); + return std::make_unique<SortedDataInterface>(opCtx, ident, desc); } Status KVEngine::dropIdent(OperationContext* opCtx, StringData ident) { diff --git a/src/mongo/db/storage/biggie/biggie_kv_engine.h b/src/mongo/db/storage/biggie/biggie_kv_engine.h index e14a879bef6..e41f334a329 100644 --- a/src/mongo/db/storage/biggie/biggie_kv_engine.h +++ b/src/mongo/db/storage/biggie/biggie_kv_engine.h @@ -70,9 +70,8 @@ public: StringData ident, const IndexDescriptor* desc); - virtual mongo::SortedDataInterface* getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc); + virtual std::unique_ptr<mongo::SortedDataInterface> getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc); virtual Status beginBackup(OperationContext* opCtx) { return Status::OK(); diff --git a/src/mongo/db/storage/devnull/devnull_kv_engine.cpp b/src/mongo/db/storage/devnull/devnull_kv_engine.cpp index b53c345ceed..6500879bde3 100644 --- a/src/mongo/db/storage/devnull/devnull_kv_engine.cpp +++ b/src/mongo/db/storage/devnull/devnull_kv_engine.cpp @@ -256,10 +256,9 @@ std::unique_ptr<RecordStore> DevNullKVEngine::makeTemporaryRecordStore(Operation return std::make_unique<DevNullRecordStore>("", CollectionOptions()); } -SortedDataInterface* DevNullKVEngine::getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) { - return new DevNullSortedDataInterface(); +std::unique_ptr<SortedDataInterface> DevNullKVEngine::getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) { + return std::make_unique<DevNullSortedDataInterface>(); } int64_t DevNullKVEngine::getCacheOverflowTableInsertCount(OperationContext* opCtx) const { diff --git a/src/mongo/db/storage/devnull/devnull_kv_engine.h b/src/mongo/db/storage/devnull/devnull_kv_engine.h index d73f5a97768..33fe29d38f4 100644 --- a/src/mongo/db/storage/devnull/devnull_kv_engine.h +++ b/src/mongo/db/storage/devnull/devnull_kv_engine.h @@ -70,9 +70,8 @@ public: return Status::OK(); } - virtual SortedDataInterface* getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc); + virtual std::unique_ptr<SortedDataInterface> getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc); virtual Status dropIdent(OperationContext* opCtx, StringData ident) { return Status::OK(); 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 d9fa673dba5..c82d629a2af 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 @@ -521,21 +521,22 @@ private: // IndexCatalogEntry argument taken by non-const pointer for consistency with other Btree // factories. We don't actually modify it. -SortedDataInterface* getEphemeralForTestBtreeImpl(const Ordering& ordering, - bool isUnique, - const NamespaceString& collectionNamespace, - const std::string& indexName, - const BSONObj& keyPattern, - std::shared_ptr<void>* dataInOut) { +std::unique_ptr<SortedDataInterface> getEphemeralForTestBtreeImpl( + const Ordering& ordering, + bool isUnique, + const NamespaceString& collectionNamespace, + const std::string& indexName, + const BSONObj& keyPattern, + std::shared_ptr<void>* dataInOut) { invariant(dataInOut); if (!*dataInOut) { *dataInOut = std::make_shared<IndexSet>(IndexEntryComparison(ordering)); } - return new EphemeralForTestBtreeImpl(static_cast<IndexSet*>(dataInOut->get()), - isUnique, - collectionNamespace, - indexName, - keyPattern); + return std::make_unique<EphemeralForTestBtreeImpl>(static_cast<IndexSet*>(dataInOut->get()), + isUnique, + collectionNamespace, + indexName, + keyPattern); } } // namespace mongo 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 2b8b566e711..60431c1cfa7 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 @@ -40,11 +40,12 @@ class IndexCatalogEntry; * Caller takes ownership. * All permanent data will be stored and fetch from dataInOut. */ -SortedDataInterface* getEphemeralForTestBtreeImpl(const Ordering& ordering, - bool isUnique, - const NamespaceString& collectionNamespace, - const std::string& indexName, - const BSONObj& keyPattern, - std::shared_ptr<void>* dataInOut); +std::unique_ptr<SortedDataInterface> getEphemeralForTestBtreeImpl( + const Ordering& ordering, + bool isUnique, + const NamespaceString& collectionNamespace, + const std::string& indexName, + const BSONObj& keyPattern, + std::shared_ptr<void>* dataInOut); } // namespace mongo diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.cpp index 782c425ffd0..0cb25117917 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.cpp @@ -92,9 +92,8 @@ Status EphemeralForTestEngine::createSortedDataInterface(OperationContext* opCtx return Status::OK(); } -SortedDataInterface* EphemeralForTestEngine::getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) { +std::unique_ptr<SortedDataInterface> EphemeralForTestEngine::getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) { stdx::lock_guard<stdx::mutex> lk(_mutex); return getEphemeralForTestBtreeImpl(Ordering::make(desc->keyPattern()), desc->unique(), diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.h b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.h index 008c0084587..a499bba6b67 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.h +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.h @@ -61,9 +61,8 @@ public: StringData ident, const IndexDescriptor* desc); - virtual SortedDataInterface* getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc); + virtual std::unique_ptr<SortedDataInterface> getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc); virtual Status beginBackup(OperationContext* opCtx) { return Status::OK(); diff --git a/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper_test.cpp b/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper_test.cpp index e5fad9811a5..064a5ee66e6 100644 --- a/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper_test.cpp +++ b/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper_test.cpp @@ -71,9 +71,8 @@ public: const CollectionOptions& options) override { return {}; } - SortedDataInterface* getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) override { + std::unique_ptr<SortedDataInterface> getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) override { return nullptr; } Status createRecordStore(OperationContext* opCtx, diff --git a/src/mongo/db/storage/kv/kv_engine.h b/src/mongo/db/storage/kv/kv_engine.h index 4f622259075..e6801dab6c7 100644 --- a/src/mongo/db/storage/kv/kv_engine.h +++ b/src/mongo/db/storage/kv/kv_engine.h @@ -39,6 +39,7 @@ #include "mongo/db/catalog/collection_options.h" #include "mongo/db/storage/kv/kv_prefix.h" #include "mongo/db/storage/record_store.h" +#include "mongo/db/storage/sorted_data_interface.h" #include "mongo/db/storage/storage_engine.h" namespace mongo { @@ -47,7 +48,6 @@ class IndexDescriptor; class JournalListener; class OperationContext; class RecoveryUnit; -class SortedDataInterface; class SnapshotManager; class KVEngine { @@ -87,9 +87,8 @@ public: return getRecordStore(opCtx, ns, ident, options); } - virtual SortedDataInterface* getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) = 0; + virtual std::unique_ptr<SortedDataInterface> getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) = 0; /** * Get a SortedDataInterface that may share an underlying table with other @@ -100,10 +99,8 @@ public: * between indexes sharing an underlying table. A value of `KVPrefix::kNotPrefixed` * guarantees the index is the sole resident of the table. */ - virtual SortedDataInterface* getGroupedSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc, - KVPrefix prefix) { + virtual std::unique_ptr<SortedDataInterface> getGroupedSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc, KVPrefix prefix) { invariant(prefix == KVPrefix::kNotPrefixed); return getSortedDataInterface(opCtx, ident, desc); } diff --git a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp index afd0cbb68b8..22cb8778836 100644 --- a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp +++ b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp @@ -182,7 +182,7 @@ TEST(KVEngineTestHarness, SimpleSorted1) { { MyOperationContext opCtx(engine); ASSERT_OK(engine->createSortedDataInterface(&opCtx, ident, &desc)); - sorted.reset(engine->getSortedDataInterface(&opCtx, ident, &desc)); + sorted = engine->getSortedDataInterface(&opCtx, ident, &desc); ASSERT(sorted); } @@ -725,7 +725,7 @@ DEATH_TEST_F(KVCatalogTest, TerminateOnNonNumericIndexVersion, "Fatal Assertion { MyOperationContext opCtx(engine); ASSERT_OK(engine->createSortedDataInterface(&opCtx, ident, &desc)); - sorted.reset(engine->getSortedDataInterface(&opCtx, ident, &desc)); + sorted = engine->getSortedDataInterface(&opCtx, ident, &desc); ASSERT(sorted); } } diff --git a/src/mongo/db/storage/mobile/mobile_kv_engine.cpp b/src/mongo/db/storage/mobile/mobile_kv_engine.cpp index 3426827ee1e..4c8b2401683 100644 --- a/src/mongo/db/storage/mobile/mobile_kv_engine.cpp +++ b/src/mongo/db/storage/mobile/mobile_kv_engine.cpp @@ -235,13 +235,12 @@ Status MobileKVEngine::createSortedDataInterface(OperationContext* opCtx, return MobileIndex::create(opCtx, ident.toString()); } -SortedDataInterface* MobileKVEngine::getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) { +std::unique_ptr<SortedDataInterface> MobileKVEngine::getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) { if (desc->unique()) { - return new MobileIndexUnique(opCtx, desc, ident.toString()); + return std::make_unique<MobileIndexUnique>(opCtx, desc, ident.toString()); } - return new MobileIndexStandard(opCtx, desc, ident.toString()); + return std::make_unique<MobileIndexStandard>(opCtx, desc, ident.toString()); } Status MobileKVEngine::dropIdent(OperationContext* opCtx, StringData ident) { diff --git a/src/mongo/db/storage/mobile/mobile_kv_engine.h b/src/mongo/db/storage/mobile/mobile_kv_engine.h index a2e6f7702f1..10da2d2e1a0 100644 --- a/src/mongo/db/storage/mobile/mobile_kv_engine.h +++ b/src/mongo/db/storage/mobile/mobile_kv_engine.h @@ -68,9 +68,8 @@ public: StringData ident, const IndexDescriptor* desc) override; - SortedDataInterface* getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) override; + std::unique_ptr<SortedDataInterface> getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) override; Status beginBackup(OperationContext* opCtx) override { return Status::OK(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index 7e8aa78c7d1..9971b1e387d 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -1281,15 +1281,13 @@ Status WiredTigerKVEngine::createGroupedSortedDataInterface(OperationContext* op return wtRCToStatus(WiredTigerIndex::Create(opCtx, _uri(ident), config)); } -SortedDataInterface* WiredTigerKVEngine::getGroupedSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc, - KVPrefix prefix) { +std::unique_ptr<SortedDataInterface> WiredTigerKVEngine::getGroupedSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc, KVPrefix prefix) { if (desc->unique()) { - return new WiredTigerIndexUnique(opCtx, _uri(ident), desc, prefix, _readOnly); + return std::make_unique<WiredTigerIndexUnique>(opCtx, _uri(ident), desc, prefix, _readOnly); } - return new WiredTigerIndexStandard(opCtx, _uri(ident), desc, prefix, _readOnly); + return std::make_unique<WiredTigerIndexStandard>(opCtx, _uri(ident), desc, prefix, _readOnly); } std::unique_ptr<RecordStore> WiredTigerKVEngine::makeTemporaryRecordStore(OperationContext* opCtx, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index 1ad5243f710..bf194231e61 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -123,9 +123,8 @@ public: return createGroupedSortedDataInterface(opCtx, ident, desc, KVPrefix::kNotPrefixed); } - SortedDataInterface* getSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc) override { + std::unique_ptr<SortedDataInterface> getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) override { return getGroupedSortedDataInterface(opCtx, ident, desc, KVPrefix::kNotPrefixed); } @@ -146,10 +145,10 @@ public: const IndexDescriptor* desc, KVPrefix prefix) override; - SortedDataInterface* getGroupedSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc, - KVPrefix prefix) override; + std::unique_ptr<SortedDataInterface> getGroupedSortedDataInterface(OperationContext* opCtx, + StringData ident, + const IndexDescriptor* desc, + KVPrefix prefix) override; Status dropIdent(OperationContext* opCtx, StringData ident) override; |