diff options
author | nehakhatri5 <neha.khatr@mongodb.com> | 2018-02-01 23:00:54 +1100 |
---|---|---|
committer | nehakhatri5 <neha.khatr@mongodb.com> | 2018-02-07 13:54:10 +1100 |
commit | 43fbd6a4fbac7d1630a62b3b471c9eeb3222b7e5 (patch) | |
tree | f312d8f95b314906b539ea44c963bf74e0b5b7c4 /src/mongo/db/storage/wiredtiger/wiredtiger_index.h | |
parent | 603ffac833b945fddf962fc450c65bb67c7733a1 (diff) | |
download | mongo-43fbd6a4fbac7d1630a62b3b471c9eeb3222b7e5.tar.gz |
SERVER-32756 Enable selection of V2 format unique index
A new unique index format would get added in MongoDB4.0 to overcome the
anonmaly of duplicate keys in unique index on secondary instances. Enabled
selection of new V2 format unique index via a gating variable. The
IndexDescriptor::IndexVersion now has a new flag kV2Unique. The version in an
IndexDescriptor object can be either kV2 or kV2Unique. A version value kV2Unique
means a V2 format unique index would be created. In this commit all of the
V2 format unique index implemetation is a copy of V1(unique index) format. It
would change in future commits.
Diffstat (limited to 'src/mongo/db/storage/wiredtiger/wiredtiger_index.h')
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_index.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h index a90f770a529..8e37258aaf4 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h @@ -135,6 +135,11 @@ public: virtual bool unique() const = 0; + // Returns true if V2 unique index format is supported. + virtual bool isV2FormatUniqueIndex() const { + return false; + } + Status dupKeyError(const BSONObj& key); protected: @@ -153,6 +158,7 @@ protected: class BulkBuilder; class StandardBulkBuilder; class UniqueBulkBuilder; + class UniqueV2BulkBuilder; const Ordering _ordering; // The keystring version is effectively const after the WiredTigerIndex instance is constructed. @@ -190,6 +196,35 @@ private: bool _partial; }; +class WiredTigerIndexUniqueV2 : public WiredTigerIndex { +public: + WiredTigerIndexUniqueV2(OperationContext* ctx, + const std::string& uri, + const IndexDescriptor* desc, + KVPrefix prefix, + bool readOnly = false); + + std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* opCtx, + bool forward) const override; + + SortedDataBuilderInterface* getBulkBuilder(OperationContext* opCtx, bool dupsAllowed) override; + + bool unique() const override { + return true; + } + + bool isV2FormatUniqueIndex() const override { + return true; + } + + Status _insert(WT_CURSOR* c, const BSONObj& key, const RecordId& id, bool dupsAllowed) override; + + void _unindex(WT_CURSOR* c, const BSONObj& key, const RecordId& id, bool dupsAllowed) override; + +private: + bool _partial; +}; + class WiredTigerIndexStandard : public WiredTigerIndex { public: WiredTigerIndexStandard(OperationContext* ctx, |