diff options
author | David Storch <david.storch@10gen.com> | 2015-11-16 15:08:15 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-11-17 15:43:20 -0500 |
commit | 009268e918a1e08d611daad34ec94fa5a351db60 (patch) | |
tree | 23d534eea2fbec3a9efaa8768635560591cc2f83 /src/mongo/db/storage | |
parent | 7d0ad1d8e1f4ba8e5b81b0242aae8bd5744530da (diff) | |
download | mongo-009268e918a1e08d611daad34ec94fa5a351db60.tar.gz |
SERVER-21403 plumb flag indicating whether or not index is unique down to MMAPv1 BtreeLogic
Includes similar plumbing for the ephemeralForTest storage
engine. WiredTiger integration layer changes are unnecessary
since WT index cursors are already unique-aware.
Diffstat (limited to 'src/mongo/db/storage')
10 files changed, 48 insertions, 19 deletions
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 0029b05374d..75df462418a 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 @@ -138,7 +138,7 @@ private: class EphemeralForTestBtreeImpl : public SortedDataInterface { public: - EphemeralForTestBtreeImpl(IndexSet* data) : _data(data) { + EphemeralForTestBtreeImpl(IndexSet* data, bool isUnique) : _data(data), _isUnique(isUnique) { _currentKeySize = 0; } @@ -224,8 +224,8 @@ public: class Cursor final : public SortedDataInterface::Cursor { public: - Cursor(OperationContext* txn, const IndexSet& data, bool isForward) - : _txn(txn), _data(data), _forward(isForward), _it(data.end()) {} + Cursor(OperationContext* txn, const IndexSet& data, bool isForward, bool isUnique) + : _txn(txn), _data(data), _forward(isForward), _isUnique(isUnique), _it(data.end()) {} boost::optional<IndexKeyEntry> next(RequestedInfo parts) override { if (_lastMoveWasRestore) { @@ -425,6 +425,7 @@ public: OperationContext* _txn; // not owned const IndexSet& _data; const bool _forward; + const bool _isUnique; bool _isEOF = true; IndexSet::const_iterator _it; @@ -449,7 +450,7 @@ public: virtual std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* txn, bool isForward) const { - return stdx::make_unique<Cursor>(txn, *_data, isForward); + return stdx::make_unique<Cursor>(txn, *_data, isForward, _isUnique); } virtual Status initAsEmpty(OperationContext* txn) { @@ -479,18 +480,20 @@ private: IndexSet* _data; long long _currentKeySize; + const bool _isUnique; }; } // namespace // 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, std::shared_ptr<void>* dataInOut) { invariant(dataInOut); if (!*dataInOut) { *dataInOut = std::make_shared<IndexSet>(IndexEntryComparison(ordering)); } - return new EphemeralForTestBtreeImpl(static_cast<IndexSet*>(dataInOut->get())); + return new EphemeralForTestBtreeImpl(static_cast<IndexSet*>(dataInOut->get()), isUnique); } } // 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 6e19eb4c945..9d44e3e80cd 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,6 +42,7 @@ class IndexCatalogEntry; * All permanent data will be stored and fetch from dataInOut. */ SortedDataInterface* getEphemeralForTestBtreeImpl(const Ordering& ordering, + bool isUnique, std::shared_ptr<void>* dataInOut); } // namespace mongo 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 f5d5a8dca3c..5a91de906f2 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 @@ -43,7 +43,8 @@ public: EphemeralForTestHarnessHelper() : _order(Ordering::make(BSONObj())) {} std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique) final { - return std::unique_ptr<SortedDataInterface>(getEphemeralForTestBtreeImpl(_order, &_data)); + return std::unique_ptr<SortedDataInterface>( + getEphemeralForTestBtreeImpl(_order, unique, &_data)); } std::unique_ptr<RecoveryUnit> newRecoveryUnit() final { 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 dad8c56e408..6f0cd2cbaae 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 @@ -76,7 +76,8 @@ SortedDataInterface* EphemeralForTestEngine::getSortedDataInterface(OperationCon StringData ident, const IndexDescriptor* desc) { stdx::lock_guard<stdx::mutex> lk(_mutex); - return getEphemeralForTestBtreeImpl(Ordering::make(desc->keyPattern()), &_dataMap[ident]); + return getEphemeralForTestBtreeImpl( + Ordering::make(desc->keyPattern()), desc->unique(), &_dataMap[ident]); } Status EphemeralForTestEngine::dropIdent(OperationContext* opCtx, StringData ident) { diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_interface.cpp b/src/mongo/db/storage/mmap_v1/btree/btree_interface.cpp index 2ae4b0e38bb..7c3798babd9 100644 --- a/src/mongo/db/storage/mmap_v1/btree/btree_interface.cpp +++ b/src/mongo/db/storage/mmap_v1/btree/btree_interface.cpp @@ -68,9 +68,10 @@ public: RecordStore* recordStore, SavedCursorRegistry* cursorRegistry, const Ordering& ordering, - const string& indexName) { + const string& indexName, + bool isUnique) { _btree.reset(new BtreeLogic<OnDiskFormat>( - headManager, recordStore, cursorRegistry, ordering, indexName)); + headManager, recordStore, cursorRegistry, ordering, indexName, isUnique)); } virtual ~BtreeInterfaceImpl() {} @@ -413,14 +414,15 @@ SortedDataInterface* getMMAPV1Interface(HeadManager* headManager, SavedCursorRegistry* cursorRegistry, const Ordering& ordering, const string& indexName, - int version) { + int version, + bool isUnique) { if (0 == version) { return new BtreeInterfaceImpl<BtreeLayoutV0>( - headManager, recordStore, cursorRegistry, ordering, indexName); + headManager, recordStore, cursorRegistry, ordering, indexName, isUnique); } else { invariant(1 == version); return new BtreeInterfaceImpl<BtreeLayoutV1>( - headManager, recordStore, cursorRegistry, ordering, indexName); + headManager, recordStore, cursorRegistry, ordering, indexName, isUnique); } } diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_interface.h b/src/mongo/db/storage/mmap_v1/btree/btree_interface.h index b5814c8a1f5..c2cc08671bc 100644 --- a/src/mongo/db/storage/mmap_v1/btree/btree_interface.h +++ b/src/mongo/db/storage/mmap_v1/btree/btree_interface.h @@ -46,5 +46,6 @@ SortedDataInterface* getMMAPV1Interface(HeadManager* headManager, SavedCursorRegistry* cursorRegistry, const Ordering& ordering, const std::string& indexName, - int version); + int version, + bool isUnique); } // namespace mongo diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_interface_test.cpp b/src/mongo/db/storage/mmap_v1/btree/btree_interface_test.cpp index 1272ea4d080..c66c5726717 100644 --- a/src/mongo/db/storage/mmap_v1/btree/btree_interface_test.cpp +++ b/src/mongo/db/storage/mmap_v1/btree/btree_interface_test.cpp @@ -42,8 +42,13 @@ public: MyHarnessHelper() : _recordStore("a.b"), _order(Ordering::make(BSONObj())) {} std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique) final { - std::unique_ptr<SortedDataInterface> sorted( - getMMAPV1Interface(&_headManager, &_recordStore, &_cursorRegistry, _order, "a_1", 1)); + std::unique_ptr<SortedDataInterface> sorted(getMMAPV1Interface(&_headManager, + &_recordStore, + &_cursorRegistry, + _order, + "a_1", // indexName + 1, // version + unique)); OperationContextNoop op; massertStatusOK(sorted->initAsEmpty(&op)); return sorted; diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_logic.h b/src/mongo/db/storage/mmap_v1/btree/btree_logic.h index 4859b476723..438cbc54f88 100644 --- a/src/mongo/db/storage/mmap_v1/btree/btree_logic.h +++ b/src/mongo/db/storage/mmap_v1/btree/btree_logic.h @@ -83,12 +83,14 @@ public: RecordStore* store, SavedCursorRegistry* cursors, const Ordering& ordering, - const std::string& indexName) + const std::string& indexName, + bool isUnique) : _headManager(head), _recordStore(store), _cursorRegistry(cursors), _ordering(ordering), - _indexName(indexName) {} + _indexName(indexName), + _isUnique(isUnique) {} // // Public-facing @@ -244,6 +246,10 @@ public: const IndexSeekPoint& seekPoint_right, int direction) const; + bool isUnique() const { + return _isUnique; + } + private: friend class BtreeLogic::Builder; @@ -571,6 +577,9 @@ private: Ordering _ordering; std::string _indexName; + + // True if this is a unique index, i.e. if duplicate key values are disallowed. + const bool _isUnique; }; } // namespace mongo diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_test_help.cpp b/src/mongo/db/storage/mmap_v1/btree/btree_test_help.cpp index 760095898be..663075e5cb8 100644 --- a/src/mongo/db/storage/mmap_v1/btree/btree_test_help.cpp +++ b/src/mongo/db/storage/mmap_v1/btree/btree_test_help.cpp @@ -63,7 +63,12 @@ BSONObj simpleKey(char c, int n) { template <class OnDiskFormat> BtreeLogicTestHelper<OnDiskFormat>::BtreeLogicTestHelper(const BSONObj& order) : recordStore("TestRecordStore"), - btree(&headManager, &recordStore, &cursorRegistry, Ordering::make(order), "TestIndex") { + btree(&headManager, + &recordStore, + &cursorRegistry, + Ordering::make(order), + "TestIndex", + /*isUnique*/ false) { static const string randomData("RandomStuff"); // Generate a valid record location for a "fake" record, which we will repeatedly use diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp b/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp index ad63d494d0f..878c4eab34d 100644 --- a/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp +++ b/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp @@ -711,7 +711,8 @@ IndexAccessMethod* MMAPV1DatabaseCatalogEntry::getIndex(OperationContext* txn, &rs->savedCursors, entry->ordering(), entry->descriptor()->indexNamespace(), - entry->descriptor()->version())); + entry->descriptor()->version(), + entry->descriptor()->unique())); if (IndexNames::HASHED == type) return new HashAccessMethod(entry, btree.release()); |