diff options
author | Louis Williams <louis.williams@mongodb.com> | 2021-01-27 10:11:51 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-27 20:35:55 +0000 |
commit | 7bda8e0a10dd620716b7530b35eac70c75810696 (patch) | |
tree | cea72e77fae621e816703486b8492ee962771b66 /src/mongo/db/storage/wiredtiger | |
parent | ee7a58e7af9fa14cf837a8f066eec784d1a9e2a6 (diff) | |
download | mongo-7bda8e0a10dd620716b7530b35eac70c75810696.tar.gz |
SERVER-53982 Delete prefixed RecordStore code
Diffstat (limited to 'src/mongo/db/storage/wiredtiger')
15 files changed, 75 insertions, 875 deletions
diff --git a/src/mongo/db/storage/wiredtiger/SConscript b/src/mongo/db/storage/wiredtiger/SConscript index 3dad11475c2..efc97da2658 100644 --- a/src/mongo/db/storage/wiredtiger/SConscript +++ b/src/mongo/db/storage/wiredtiger/SConscript @@ -74,7 +74,6 @@ if wiredtiger: '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/storage/index_entry_comparison', '$BUILD_DIR/mongo/db/storage/key_string', - '$BUILD_DIR/mongo/db/storage/kv/kv_prefix', '$BUILD_DIR/mongo/db/storage/oplog_hack', '$BUILD_DIR/mongo/db/storage/recovery_unit_base', '$BUILD_DIR/mongo/db/storage/storage_file_util', @@ -208,22 +207,6 @@ if wiredtiger: ], ) - wtEnv.CppUnitTest( - target='storage_wiredtiger_prefixed_record_store_and_index_test', - source=[ - 'wiredtiger_prefixed_index_test.cpp', - 'wiredtiger_prefixed_record_store_test.cpp', - ], - LIBDEPS=[ - '$BUILD_DIR/mongo/db/auth/authmocks', - '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface', - '$BUILD_DIR/mongo/db/repl/replmocks', - '$BUILD_DIR/mongo/db/service_context_test_fixture', - 'additional_wiredtiger_index_tests', - 'additional_wiredtiger_record_store_tests', - ], - ) - wtEnv.Benchmark( target='storage_wiredtiger_begin_transaction_block_bm', source='wiredtiger_begin_transaction_block_bm.cpp', diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp index d1a5f89d267..7e107a0fd29 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp @@ -101,21 +101,11 @@ const int kMinimumIndexVersion = kDataFormatV1KeyStringV0IndexVersionV1; const int kMaximumIndexVersion = kDataFormatV4KeyStringV1UniqueIndexVersionV2; void WiredTigerIndex::setKey(WT_CURSOR* cursor, const WT_ITEM* item) { - if (_prefix == KVPrefix::kNotPrefixed) { - cursor->set_key(cursor, item); - } else { - cursor->set_key(cursor, _prefix.repr(), item); - } + cursor->set_key(cursor, item); } void WiredTigerIndex::getKey(OperationContext* opCtx, WT_CURSOR* cursor, WT_ITEM* key) { - if (_prefix == KVPrefix::kNotPrefixed) { - invariantWTOK(cursor->get_key(cursor, key)); - } else { - int64_t prefix; - invariantWTOK(cursor->get_key(cursor, &prefix, key)); - invariant(_prefix.repr() == prefix); - } + invariantWTOK(cursor->get_key(cursor, key)); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); metricsCollector.incrementOneIdxEntryRead(key->size); @@ -170,8 +160,7 @@ StatusWith<std::string> WiredTigerIndex::generateCreateString( const std::string& sysIndexConfig, const std::string& collIndexConfig, const NamespaceString& collectionNamespace, - const IndexDescriptor& desc, - bool isPrefixed) { + const IndexDescriptor& desc) { str::stream ss; // Separate out a prefix and suffix in the default string. User configuration will override @@ -210,11 +199,7 @@ StatusWith<std::string> WiredTigerIndex::generateCreateString( // for correct behavior of the server. // Indexes need to store the metadata for collation to work as expected. - if (isPrefixed) { - ss << ",key_format=qu"; - } else { - ss << ",key_format=u"; - } + ss << ",key_format=u"; ss << ",value_format=u"; // Index metadata @@ -254,7 +239,6 @@ WiredTigerIndex::WiredTigerIndex(OperationContext* ctx, const std::string& uri, StringData ident, const IndexDescriptor* desc, - KVPrefix prefix, bool isReadOnly) : SortedDataInterface(ident, _handleVersionInfo(ctx, uri, desc, isReadOnly), @@ -264,8 +248,7 @@ WiredTigerIndex::WiredTigerIndex(OperationContext* ctx, _desc(desc), _indexName(desc->indexName()), _keyPattern(desc->keyPattern()), - _collation(desc->collation()), - _prefix(prefix) {} + _collation(desc->collation()) {} NamespaceString WiredTigerIndex::getCollectionNamespace(OperationContext* opCtx) const { return _desc->getEntry()->getNSSFromCatalog(opCtx); @@ -410,20 +393,6 @@ Status WiredTigerIndex::dupKeyCheck(OperationContext* opCtx, const KeyString::Va } bool WiredTigerIndex::isEmpty(OperationContext* opCtx) { - if (_prefix != KVPrefix::kNotPrefixed) { - auto cursor = newCursor(opCtx, true /* forward */); - - KeyString::Value keyStringForSeek = - IndexEntryComparison::makeKeyStringFromBSONKeyForSeek(kMinBSONKey, - getKeyStringVersion(), - getOrdering(), - true /* forward */, - false /* inclusive */ - ); - - return cursor->seek(keyStringForSeek, Cursor::RequestedInfo::kJustExistance) == boost::none; - } - WiredTigerCursor curwrap(_uri, _tableId, false, opCtx); WT_CURSOR* c = curwrap.get(); if (!c) @@ -565,12 +534,11 @@ KeyString::Version WiredTigerIndex::_handleVersionInfo(OperationContext* ctx, */ class WiredTigerIndex::BulkBuilder : public SortedDataBuilderInterface { public: - BulkBuilder(WiredTigerIndex* idx, OperationContext* opCtx, KVPrefix prefix) + BulkBuilder(WiredTigerIndex* idx, OperationContext* opCtx) : _ordering(idx->_ordering), _opCtx(opCtx), _session(WiredTigerRecoveryUnit::get(_opCtx)->getSessionCache()->getSession()), - _cursor(openBulkCursor(idx)), - _prefix(prefix) {} + _cursor(openBulkCursor(idx)) {} ~BulkBuilder() { _cursor->close(_cursor); @@ -607,18 +575,13 @@ protected: } void setKey(WT_CURSOR* cursor, const WT_ITEM* item) { - if (_prefix == KVPrefix::kNotPrefixed) { - cursor->set_key(cursor, item); - } else { - cursor->set_key(cursor, _prefix.repr(), item); - } + cursor->set_key(cursor, item); } const Ordering _ordering; OperationContext* const _opCtx; UniqueWiredTigerSession const _session; WT_CURSOR* const _cursor; - KVPrefix _prefix; }; @@ -627,8 +590,8 @@ protected: */ class WiredTigerIndex::StandardBulkBuilder : public BulkBuilder { public: - StandardBulkBuilder(WiredTigerIndex* idx, OperationContext* opCtx, KVPrefix prefix) - : BulkBuilder(idx, opCtx, prefix), _idx(idx) {} + StandardBulkBuilder(WiredTigerIndex* idx, OperationContext* opCtx) + : BulkBuilder(idx, opCtx), _idx(idx) {} Status addKey(const KeyString::Value& keyString) override { dassert( @@ -667,11 +630,8 @@ private: */ class WiredTigerIndex::UniqueBulkBuilder : public BulkBuilder { public: - UniqueBulkBuilder(WiredTigerIndex* idx, - OperationContext* opCtx, - bool dupsAllowed, - KVPrefix prefix) - : BulkBuilder(idx, opCtx, prefix), + UniqueBulkBuilder(WiredTigerIndex* idx, OperationContext* opCtx, bool dupsAllowed) + : BulkBuilder(idx, opCtx), _idx(idx), _dupsAllowed(dupsAllowed), _previousKeyString(idx->getKeyStringVersion()) { @@ -735,10 +695,8 @@ private: class WiredTigerIndex::IdBulkBuilder : public BulkBuilder { public: - IdBulkBuilder(WiredTigerIndex* idx, OperationContext* opCtx, KVPrefix prefix) - : BulkBuilder(idx, opCtx, prefix), - _idx(idx), - _previousKeyString(idx->getKeyStringVersion()) { + IdBulkBuilder(WiredTigerIndex* idx, OperationContext* opCtx) + : BulkBuilder(idx, opCtx), _idx(idx), _previousKeyString(idx->getKeyStringVersion()) { invariant(_idx->isIdIndex()); } @@ -788,7 +746,7 @@ std::unique_ptr<SortedDataBuilderInterface> WiredTigerIdIndex::makeBulkBuilder( OperationContext* opCtx, bool dupsAllowed) { // Duplicates are not actually allowed on the _id index, however we accept the parameter // regardless. - return std::make_unique<IdBulkBuilder>(this, opCtx, _prefix); + return std::make_unique<IdBulkBuilder>(this, opCtx); } namespace { @@ -798,17 +756,13 @@ namespace { */ class WiredTigerIndexCursorBase : public SortedDataInterface::Cursor { public: - WiredTigerIndexCursorBase(const WiredTigerIndex& idx, - OperationContext* opCtx, - bool forward, - KVPrefix prefix) + WiredTigerIndexCursorBase(const WiredTigerIndex& idx, OperationContext* opCtx, bool forward) : _opCtx(opCtx), _idx(idx), _forward(forward), _key(idx.getKeyStringVersion()), _typeBits(idx.getKeyStringVersion()), - _query(idx.getKeyStringVersion()), - _prefix(prefix) { + _query(idx.getKeyStringVersion()) { _cursor.emplace(_idx.uri(), _idx.tableId(), false, _opCtx); } @@ -988,37 +942,16 @@ protected: } void setKey(WT_CURSOR* cursor, const WT_ITEM* item) { - if (_prefix == KVPrefix::kNotPrefixed) { - cursor->set_key(cursor, item); - } else { - cursor->set_key(cursor, _prefix.repr(), item); - } + cursor->set_key(cursor, item); } void getKey(WT_CURSOR* cursor, WT_ITEM* key) { - if (_prefix == KVPrefix::kNotPrefixed) { - invariantWTOK(cursor->get_key(cursor, key)); - } else { - int64_t prefix; - invariantWTOK(cursor->get_key(cursor, &prefix, key)); - invariant(_prefix.repr() == prefix); - } + invariantWTOK(cursor->get_key(cursor, key)); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(_opCtx); metricsCollector.incrementOneIdxEntryRead(key->size); } - bool hasWrongPrefix(WT_CURSOR* cursor) { - if (_prefix == KVPrefix::kNotPrefixed) { - return false; - } - - int64_t prefix; - WT_ITEM item; - invariantWTOK(cursor->get_key(cursor, &prefix, &item)); - return _prefix.repr() != prefix; - } - boost::optional<IndexKeyEntry> curr(RequestedInfo parts) const { if (_eof) return {}; @@ -1068,11 +1001,6 @@ protected: return; } invariantWTOK(ret); - if (hasWrongPrefix(c)) { - _cursorAtEof = true; - return; - } - _cursorAtEof = false; } @@ -1241,7 +1169,6 @@ protected: bool _lastMoveSkippedKey = false; KeyString::Builder _query; - KVPrefix _prefix; std::unique_ptr<KeyString::Builder> _endPosition; }; @@ -1251,11 +1178,8 @@ using WiredTigerIndexStandardCursor = WiredTigerIndexCursorBase; class WiredTigerIndexUniqueCursor final : public WiredTigerIndexCursorBase { public: - WiredTigerIndexUniqueCursor(const WiredTigerIndex& idx, - OperationContext* opCtx, - bool forward, - KVPrefix prefix) - : WiredTigerIndexCursorBase(idx, opCtx, forward, prefix) {} + WiredTigerIndexUniqueCursor(const WiredTigerIndex& idx, OperationContext* opCtx, bool forward) + : WiredTigerIndexCursorBase(idx, opCtx, forward) {} // Called after _key has been filled in, ie a new key to be processed has been fetched. // Must not throw WriteConflictException, throwing a WriteConflictException will retry the @@ -1348,11 +1272,8 @@ private: class WiredTigerIdIndexCursor final : public WiredTigerIndexCursorBase { public: - WiredTigerIdIndexCursor(const WiredTigerIndex& idx, - OperationContext* opCtx, - bool forward, - KVPrefix prefix) - : WiredTigerIndexCursorBase(idx, opCtx, forward, prefix) {} + WiredTigerIdIndexCursor(const WiredTigerIndex& idx, OperationContext* opCtx, bool forward) + : WiredTigerIndexCursorBase(idx, opCtx, forward) {} // Called after _key has been filled in, i.e. a new key to be processed has been fetched. // Must not throw WriteConflictException, throwing a WriteConflictException will retry the @@ -1384,9 +1305,8 @@ WiredTigerIndexUnique::WiredTigerIndexUnique(OperationContext* ctx, const std::string& uri, StringData ident, const IndexDescriptor* desc, - KVPrefix prefix, bool isReadOnly) - : WiredTigerIndex(ctx, uri, ident, desc, prefix, isReadOnly), _partial(desc->isPartial()) { + : WiredTigerIndex(ctx, uri, ident, desc, isReadOnly), _partial(desc->isPartial()) { // _id indexes must use WiredTigerIdIndex invariant(!isIdIndex()); // All unique indexes should be in the timestamp-safe format version as of version 4.2. @@ -1395,12 +1315,12 @@ WiredTigerIndexUnique::WiredTigerIndexUnique(OperationContext* ctx, std::unique_ptr<SortedDataInterface::Cursor> WiredTigerIndexUnique::newCursor( OperationContext* opCtx, bool forward) const { - return std::make_unique<WiredTigerIndexUniqueCursor>(*this, opCtx, forward, _prefix); + return std::make_unique<WiredTigerIndexUniqueCursor>(*this, opCtx, forward); } std::unique_ptr<SortedDataBuilderInterface> WiredTigerIndexUnique::makeBulkBuilder( OperationContext* opCtx, bool dupsAllowed) { - return std::make_unique<UniqueBulkBuilder>(this, opCtx, dupsAllowed, _prefix); + return std::make_unique<UniqueBulkBuilder>(this, opCtx, dupsAllowed); } bool WiredTigerIndexUnique::isTimestampSafeUniqueIdx() const { @@ -1492,15 +1412,14 @@ WiredTigerIdIndex::WiredTigerIdIndex(OperationContext* ctx, const std::string& uri, StringData ident, const IndexDescriptor* desc, - KVPrefix prefix, bool isReadOnly) - : WiredTigerIndex(ctx, uri, ident, desc, prefix, isReadOnly) { + : WiredTigerIndex(ctx, uri, ident, desc, isReadOnly) { invariant(isIdIndex()); } std::unique_ptr<SortedDataInterface::Cursor> WiredTigerIdIndex::newCursor(OperationContext* opCtx, bool forward) const { - return std::make_unique<WiredTigerIdIndexCursor>(*this, opCtx, forward, _prefix); + return std::make_unique<WiredTigerIdIndexCursor>(*this, opCtx, forward); } Status WiredTigerIdIndex::_insert(OperationContext* opCtx, @@ -1730,20 +1649,19 @@ WiredTigerIndexStandard::WiredTigerIndexStandard(OperationContext* ctx, const std::string& uri, StringData ident, const IndexDescriptor* desc, - KVPrefix prefix, bool isReadOnly) - : WiredTigerIndex(ctx, uri, ident, desc, prefix, isReadOnly) {} + : WiredTigerIndex(ctx, uri, ident, desc, isReadOnly) {} std::unique_ptr<SortedDataInterface::Cursor> WiredTigerIndexStandard::newCursor( OperationContext* opCtx, bool forward) const { - return std::make_unique<WiredTigerIndexStandardCursor>(*this, opCtx, forward, _prefix); + return std::make_unique<WiredTigerIndexStandardCursor>(*this, opCtx, forward); } std::unique_ptr<SortedDataBuilderInterface> WiredTigerIndexStandard::makeBulkBuilder( OperationContext* opCtx, bool dupsAllowed) { // We aren't unique so dups better be allowed. invariant(dupsAllowed); - return std::make_unique<StandardBulkBuilder>(this, opCtx, _prefix); + return std::make_unique<StandardBulkBuilder>(this, opCtx); } Status WiredTigerIndexStandard::_insert(OperationContext* opCtx, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h index 483d905d2f9..e8058e2350f 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h @@ -34,7 +34,6 @@ #include "mongo/base/status_with.h" #include "mongo/db/storage/index_entry_comparison.h" #include "mongo/db/storage/key_string.h" -#include "mongo/db/storage/kv/kv_prefix.h" #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.h" #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" @@ -77,8 +76,7 @@ public: const std::string& sysIndexConfig, const std::string& collIndexConfig, const NamespaceString& collectionNamespace, - const IndexDescriptor& desc, - bool isPrefixed); + const IndexDescriptor& desc); /** * Creates a WiredTiger table suitable for implementing a MongoDB index. @@ -95,7 +93,6 @@ public: const std::string& uri, StringData ident, const IndexDescriptor* desc, - KVPrefix prefix, bool readOnly); virtual Status insert(OperationContext* opCtx, @@ -193,7 +190,6 @@ protected: const std::string _indexName; const BSONObj _keyPattern; const BSONObj _collation; - KVPrefix _prefix; }; class WiredTigerIndexUnique : public WiredTigerIndex { @@ -202,7 +198,6 @@ public: const std::string& uri, StringData ident, const IndexDescriptor* desc, - KVPrefix prefix, bool readOnly = false); std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* opCtx, @@ -245,7 +240,6 @@ public: const std::string& uri, StringData ident, const IndexDescriptor* desc, - KVPrefix prefix, bool readOnly = false); std::unique_ptr<Cursor> newCursor(OperationContext* opCtx, @@ -289,7 +283,6 @@ public: const std::string& uri, StringData ident, const IndexDescriptor* desc, - KVPrefix prefix, bool readOnly = false); std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* opCtx, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp index 95ba5e3196e..b5cc39473fe 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp @@ -36,7 +36,6 @@ #include "mongo/db/catalog/index_catalog_entry.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/json.h" -#include "mongo/db/storage/kv/kv_prefix.h" #include "mongo/db/storage/sorted_data_interface_test_harness.h" #include "mongo/db/storage/wiredtiger/wiredtiger_index.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index b9c373702b1..83d7819ec4b 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -1326,17 +1326,15 @@ void WiredTigerKVEngine::setSortedDataInterfaceExtraOptions(const std::string& o _indexOptions = options; } -Status WiredTigerKVEngine::createGroupedRecordStore(OperationContext* opCtx, - StringData ns, - StringData ident, - const CollectionOptions& options, - KVPrefix prefix) { +Status WiredTigerKVEngine::createRecordStore(OperationContext* opCtx, + StringData ns, + StringData ident, + const CollectionOptions& options) { _ensureIdentPath(ident); WiredTigerSession session(_conn); - const bool prefixed = prefix.isPrefixed(); - StatusWith<std::string> result = WiredTigerRecordStore::generateCreateString( - _canonicalName, ns, options, _rsOptions, prefixed); + StatusWith<std::string> result = + WiredTigerRecordStore::generateCreateString(_canonicalName, ns, options, _rsOptions); if (!result.isOK()) { return result.getStatus(); } @@ -1412,7 +1410,7 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx, "namespace"_attr = nss, "uuid"_attr = options.uuid); - status = createGroupedRecordStore(opCtx, nss.ns(), ident, options, KVPrefix::kNotPrefixed); + status = createRecordStore(opCtx, nss.ns(), ident, options); if (!status.isOK()) { return status; } @@ -1456,12 +1454,10 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx, #endif } -std::unique_ptr<RecordStore> WiredTigerKVEngine::getGroupedRecordStore( - OperationContext* opCtx, - StringData ns, - StringData ident, - const CollectionOptions& options, - KVPrefix prefix) { +std::unique_ptr<RecordStore> WiredTigerKVEngine::getRecordStore(OperationContext* opCtx, + StringData ns, + StringData ident, + const CollectionOptions& options) { WiredTigerRecordStore::Params params; params.ns = ns; @@ -1487,11 +1483,7 @@ std::unique_ptr<RecordStore> WiredTigerKVEngine::getGroupedRecordStore( params.cappedMaxDocs = options.cappedMaxDocs; std::unique_ptr<WiredTigerRecordStore> ret; - if (prefix == KVPrefix::kNotPrefixed) { - ret = std::make_unique<StandardWiredTigerRecordStore>(this, opCtx, params); - } else { - ret = std::make_unique<PrefixedWiredTigerRecordStore>(this, opCtx, params, prefix); - } + ret = std::make_unique<StandardWiredTigerRecordStore>(this, opCtx, params); ret->postConstructorInit(opCtx); // Sizes should always be checked when creating a collection during rollback or replication @@ -1512,11 +1504,10 @@ string WiredTigerKVEngine::_uri(StringData ident) const { return kTableUriPrefix + ident.toString(); } -Status WiredTigerKVEngine::createGroupedSortedDataInterface(OperationContext* opCtx, - const CollectionOptions& collOptions, - StringData ident, - const IndexDescriptor* desc, - KVPrefix prefix) { +Status WiredTigerKVEngine::createSortedDataInterface(OperationContext* opCtx, + const CollectionOptions& collOptions, + StringData ident, + const IndexDescriptor* desc) { _ensureIdentPath(ident); std::string collIndexOptions; @@ -1532,7 +1523,7 @@ Status WiredTigerKVEngine::createGroupedSortedDataInterface(OperationContext* op : NamespaceString(); StatusWith<std::string> result = WiredTigerIndex::generateCreateString( - _canonicalName, _indexOptions, collIndexOptions, ns, *desc, prefix.isPrefixed()); + _canonicalName, _indexOptions, collIndexOptions, ns, *desc); if (!result.isOK()) { return result.getStatus(); } @@ -1566,24 +1557,20 @@ Status WiredTigerKVEngine::importSortedDataInterface(OperationContext* opCtx, return wtRCToStatus(WiredTigerIndex::Create(opCtx, _uri(ident), config)); } -Status WiredTigerKVEngine::dropGroupedSortedDataInterface(OperationContext* opCtx, - StringData ident) { +Status WiredTigerKVEngine::dropSortedDataInterface(OperationContext* opCtx, StringData ident) { return wtRCToStatus(WiredTigerIndex::Drop(opCtx, _uri(ident))); } -std::unique_ptr<SortedDataInterface> WiredTigerKVEngine::getGroupedSortedDataInterface( - OperationContext* opCtx, StringData ident, const IndexDescriptor* desc, KVPrefix prefix) { +std::unique_ptr<SortedDataInterface> WiredTigerKVEngine::getSortedDataInterface( + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) { if (desc->isIdIndex()) { - return std::make_unique<WiredTigerIdIndex>( - opCtx, _uri(ident), ident, desc, prefix, _readOnly); + return std::make_unique<WiredTigerIdIndex>(opCtx, _uri(ident), ident, desc, _readOnly); } if (desc->unique()) { - return std::make_unique<WiredTigerIndexUnique>( - opCtx, _uri(ident), ident, desc, prefix, _readOnly); + return std::make_unique<WiredTigerIndexUnique>(opCtx, _uri(ident), ident, desc, _readOnly); } - return std::make_unique<WiredTigerIndexStandard>( - opCtx, _uri(ident), ident, desc, prefix, _readOnly); + return std::make_unique<WiredTigerIndexStandard>(opCtx, _uri(ident), ident, desc, _readOnly); } std::unique_ptr<RecordStore> WiredTigerKVEngine::makeTemporaryRecordStore(OperationContext* opCtx, @@ -1595,7 +1582,7 @@ std::unique_ptr<RecordStore> WiredTigerKVEngine::makeTemporaryRecordStore(Operat CollectionOptions noOptions; StatusWith<std::string> swConfig = WiredTigerRecordStore::generateCreateString( - _canonicalName, "" /* internal table */, noOptions, _rsOptions, false /* prefixed */); + _canonicalName, "" /* internal table */, noOptions, _rsOptions); uassertStatusOK(swConfig.getStatus()); std::string config = swConfig.getValue(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index c5a3a59d5cc..09dfe563399 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -135,16 +135,12 @@ public: Status createRecordStore(OperationContext* opCtx, StringData ns, StringData ident, - const CollectionOptions& options) override { - return createGroupedRecordStore(opCtx, ns, ident, options, KVPrefix::kNotPrefixed); - } + const CollectionOptions& options) override; std::unique_ptr<RecordStore> getRecordStore(OperationContext* opCtx, StringData ns, StringData ident, - const CollectionOptions& options) override { - return getGroupedRecordStore(opCtx, ns, ident, options, KVPrefix::kNotPrefixed); - } + const CollectionOptions& options) override; std::unique_ptr<RecordStore> makeTemporaryRecordStore(OperationContext* opCtx, StringData ident) override; @@ -152,38 +148,15 @@ public: Status createSortedDataInterface(OperationContext* opCtx, const CollectionOptions& collOptions, StringData ident, - const IndexDescriptor* desc) override { - return createGroupedSortedDataInterface( - opCtx, collOptions, ident, desc, KVPrefix::kNotPrefixed); - } + const IndexDescriptor* desc) override; std::unique_ptr<SortedDataInterface> getSortedDataInterface( - OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) override { - return getGroupedSortedDataInterface(opCtx, ident, desc, KVPrefix::kNotPrefixed); - } - - Status createGroupedRecordStore(OperationContext* opCtx, - StringData ns, - StringData ident, - const CollectionOptions& options, - KVPrefix prefix) override; + OperationContext* opCtx, StringData ident, const IndexDescriptor* desc) override; Status importRecordStore(OperationContext* opCtx, StringData ident, const BSONObj& storageMetadata) override; - std::unique_ptr<RecordStore> getGroupedRecordStore(OperationContext* opCtx, - StringData ns, - StringData ident, - const CollectionOptions& options, - KVPrefix prefix) override; - - Status createGroupedSortedDataInterface(OperationContext* opCtx, - const CollectionOptions& collOptions, - StringData ident, - const IndexDescriptor* desc, - KVPrefix prefix) override; - Status importSortedDataInterface(OperationContext* opCtx, StringData ident, const BSONObj& storageMetadata) override; @@ -191,12 +164,7 @@ public: /** * Drops the specified ident for resumable index builds. */ - Status dropGroupedSortedDataInterface(OperationContext* opCtx, StringData ident) override; - - std::unique_ptr<SortedDataInterface> getGroupedSortedDataInterface(OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc, - KVPrefix prefix) override; + Status dropSortedDataInterface(OperationContext* opCtx, StringData ident) override; Status dropIdent(RecoveryUnit* ru, StringData ident, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp deleted file mode 100644 index c665f3fe362..00000000000 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_index_test.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include <memory> - -#include "mongo/base/init.h" -#include "mongo/bson/bsonobjbuilder.h" -#include "mongo/db/catalog/collection_mock.h" -#include "mongo/db/catalog/index_catalog_entry.h" -#include "mongo/db/index/index_descriptor.h" -#include "mongo/db/json.h" -#include "mongo/db/operation_context_noop.h" -#include "mongo/db/storage/kv/kv_prefix.h" -#include "mongo/db/storage/sorted_data_interface_test_harness.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_index.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_util.h" -#include "mongo/unittest/temp_dir.h" -#include "mongo/unittest/unittest.h" -#include "mongo/util/system_clock_source.h" - -namespace mongo { -namespace { - -using std::string; - -class WiredTigerPrefixedIndexHarnessHelper final : public SortedDataInterfaceHarnessHelper { -public: - WiredTigerPrefixedIndexHarnessHelper() : _dbpath("wt_test"), _conn(nullptr) { - const char* config = "create,cache_size=1G,"; - int ret = wiredtiger_open(_dbpath.path().c_str(), nullptr, config, &_conn); - invariantWTOK(ret); - - _fastClockSource = std::make_unique<SystemClockSource>(); - _sessionCache = new WiredTigerSessionCache(_conn, _fastClockSource.get()); - } - - ~WiredTigerPrefixedIndexHarnessHelper() final { - delete _sessionCache; - _conn->close(_conn, nullptr); - } - - std::unique_ptr<SortedDataInterface> newIdIndexSortedDataInterface() final { - NamespaceString nss = {"test", "wt"}; - OperationContextNoop opCtx(newRecoveryUnit().release()); - - BSONObj spec = BSON("key" << BSON("_id" << 1) << "name" - << "_id_" - << "v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion) - << "unique" << true); - auto collection = std::make_unique<CollectionMock>(nss); - IndexDescriptor desc("", spec); - invariant(desc.isIdIndex()); - - KVPrefix prefix = KVPrefix::generateNextPrefix(); - StatusWith<std::string> result = WiredTigerIndex::generateCreateString( - kWiredTigerEngineName, "", "", nss, desc, prefix.isPrefixed()); - ASSERT_OK(result.getStatus()); - - string uri = "table:" + nss.ns(); - invariantWTOK(WiredTigerIndex::Create(&opCtx, uri, result.getValue())); - - return std::make_unique<WiredTigerIdIndex>(&opCtx, uri, "" /* ident */, &desc, prefix); - } - - std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique, bool partial) final { - - NamespaceString nss = {"test", "wt"}; - OperationContextNoop opCtx(newRecoveryUnit().release()); - - BSONObj spec = BSON("key" << BSON("a" << 1) << "name" - << "testIndex" - << "v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion) - << "unique" << unique); - - if (partial) { - auto partialBSON = - BSON(IndexDescriptor::kPartialFilterExprFieldName.toString() << BSON("" - << "")); - spec = spec.addField(partialBSON.firstElement()); - } - - auto collection = std::make_unique<CollectionMock>(nss); - IndexDescriptor& desc = _descriptors.emplace_back("", spec); - - KVPrefix prefix = KVPrefix::generateNextPrefix(); - StatusWith<std::string> result = WiredTigerIndex::generateCreateString( - kWiredTigerEngineName, "", "", nss, desc, prefix.isPrefixed()); - ASSERT_OK(result.getStatus()); - - string uri = "table:" + nss.ns(); - invariantWTOK(WiredTigerIndex::Create(&opCtx, uri, result.getValue())); - - if (unique) - return std::make_unique<WiredTigerIndexUnique>( - &opCtx, uri, "" /* ident */, &desc, prefix); - return std::make_unique<WiredTigerIndexStandard>( - &opCtx, uri, "" /* ident */, &desc, prefix); - } - - std::unique_ptr<RecoveryUnit> newRecoveryUnit() final { - return std::make_unique<WiredTigerRecoveryUnit>(_sessionCache, &_oplogManager); - } - -private: - unittest::TempDir _dbpath; - std::unique_ptr<ClockSource> _fastClockSource; - std::vector<IndexDescriptor> _descriptors; - WT_CONNECTION* _conn; - WiredTigerSessionCache* _sessionCache; - WiredTigerOplogManager _oplogManager; -}; - -std::unique_ptr<SortedDataInterfaceHarnessHelper> makeWTPrefixedIndexHarnessHelper() { - return std::make_unique<WiredTigerPrefixedIndexHarnessHelper>(); -} - -MONGO_INITIALIZER(RegisterSortedDataInterfaceHarnessFactory)(InitializerContext* const) { - mongo::registerSortedDataInterfaceHarnessHelperFactory(makeWTPrefixedIndexHarnessHelper); -} -} // namespace -} // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_record_store_test.cpp deleted file mode 100644 index 43c6e9a706e..00000000000 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_prefixed_record_store_test.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include <memory> -#include <sstream> -#include <string> -#include <time.h> - -#include "mongo/base/checked_cast.h" -#include "mongo/base/init.h" -#include "mongo/base/string_data.h" -#include "mongo/bson/bsonobjbuilder.h" -#include "mongo/db/concurrency/write_conflict_exception.h" -#include "mongo/db/json.h" -#include "mongo/db/operation_context_noop.h" -#include "mongo/db/repl/repl_settings.h" -#include "mongo/db/repl/replication_coordinator_mock.h" -#include "mongo/db/service_context.h" -#include "mongo/db/storage/kv/kv_engine_test_harness.h" -#include "mongo/db/storage/kv/kv_prefix.h" -#include "mongo/db/storage/record_store_test_harness.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_record_store_oplog_stones.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_size_storer.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_util.h" -#include "mongo/unittest/temp_dir.h" -#include "mongo/unittest/unittest.h" -#include "mongo/util/clock_source_mock.h" -#include "mongo/util/fail_point.h" -#include "mongo/util/scopeguard.h" - -namespace mongo { -namespace { - -using std::string; -using std::stringstream; -using std::unique_ptr; - -class PrefixedWiredTigerHarnessHelper final : public RecordStoreHarnessHelper { -public: - PrefixedWiredTigerHarnessHelper() - : _dbpath("wt_test"), - _engine(new WiredTigerKVEngine(kWiredTigerEngineName, - _dbpath.path(), - _cs.get(), - "", - 1, - 0, - false, - false, - false, - false)) { - repl::ReplicationCoordinator::set( - getGlobalServiceContext(), - std::unique_ptr<repl::ReplicationCoordinator>(new repl::ReplicationCoordinatorMock( - getGlobalServiceContext(), repl::ReplSettings()))); - _engine->notifyStartupComplete(); - } - - PrefixedWiredTigerHarnessHelper(StringData extraStrings) : _dbpath("wt_test") {} - - virtual std::unique_ptr<RecordStore> newNonCappedRecordStore() { - return newNonCappedRecordStore("a.b"); - } - - virtual std::unique_ptr<RecordStore> newNonCappedRecordStore(const std::string& ns) { - WiredTigerRecoveryUnit* ru = - checked_cast<WiredTigerRecoveryUnit*>(_engine->newRecoveryUnit()); - OperationContextNoop opCtx(ru); - string ident = ns; - string uri = WiredTigerKVEngine::kTableUriPrefix + ns; - - const bool prefixed = true; - StatusWith<std::string> result = WiredTigerRecordStore::generateCreateString( - kWiredTigerEngineName, StringData(ns), CollectionOptions(), "", prefixed); - ASSERT_TRUE(result.isOK()); - std::string config = result.getValue(); - - { - WriteUnitOfWork uow(&opCtx); - WT_SESSION* s = ru->getSession()->getSession(); - invariantWTOK(s->create(s, uri.c_str(), config.c_str())); - uow.commit(); - } - - WiredTigerRecordStore::Params params; - params.ns = ns; - params.ident = ident; - params.engineName = kWiredTigerEngineName; - params.isCapped = false; - params.isEphemeral = false; - params.cappedMaxSize = -1; - params.cappedMaxDocs = -1; - params.cappedCallback = nullptr; - params.sizeStorer = nullptr; - params.tracksSizeAdjustments = true; - - auto ret = std::make_unique<PrefixedWiredTigerRecordStore>( - _engine.get(), &opCtx, params, KVPrefix::generateNextPrefix()); - ret->postConstructorInit(&opCtx); - return std::move(ret); - } - - virtual std::unique_ptr<RecordStore> newCappedRecordStore(int64_t cappedSizeBytes, - int64_t cappedMaxDocs) final { - return newCappedRecordStore("a.b", cappedSizeBytes, cappedMaxDocs); - } - - virtual std::unique_ptr<RecordStore> newCappedRecordStore(const std::string& ns, - int64_t cappedMaxSize, - int64_t cappedMaxDocs) { - WiredTigerRecoveryUnit* ru = - checked_cast<WiredTigerRecoveryUnit*>(_engine->newRecoveryUnit()); - OperationContextNoop opCtx(ru); - string ident = "a.b"; - string uri = WiredTigerKVEngine::kTableUriPrefix + ident; - - CollectionOptions options; - options.capped = true; - - KVPrefix prefix = KVPrefix::generateNextPrefix(); - StatusWith<std::string> result = WiredTigerRecordStore::generateCreateString( - kWiredTigerEngineName, StringData(ns), options, "", prefix.isPrefixed()); - ASSERT_TRUE(result.isOK()); - std::string config = result.getValue(); - - { - WriteUnitOfWork uow(&opCtx); - WT_SESSION* s = ru->getSession()->getSession(); - invariantWTOK(s->create(s, uri.c_str(), config.c_str())); - uow.commit(); - } - - WiredTigerRecordStore::Params params; - params.ns = ns; - params.ident = ident; - params.engineName = kWiredTigerEngineName; - params.isCapped = true; - params.isEphemeral = false; - params.cappedMaxSize = cappedMaxSize; - params.cappedMaxDocs = cappedMaxDocs; - params.cappedCallback = nullptr; - params.sizeStorer = nullptr; - params.tracksSizeAdjustments = true; - - auto ret = - std::make_unique<PrefixedWiredTigerRecordStore>(_engine.get(), &opCtx, params, prefix); - ret->postConstructorInit(&opCtx); - return std::move(ret); - } - - virtual std::unique_ptr<RecoveryUnit> newRecoveryUnit() final { - return std::unique_ptr<WiredTigerRecoveryUnit>( - checked_cast<WiredTigerRecoveryUnit*>(_engine->newRecoveryUnit())); - } - - virtual WT_CONNECTION* conn() const { - return _engine->getConnection(); - } - -private: - unittest::TempDir _dbpath; - const std::unique_ptr<ClockSource> _cs = std::make_unique<ClockSourceMock>(); - - std::unique_ptr<WiredTigerKVEngine> _engine; -}; - -std::unique_ptr<RecordStoreHarnessHelper> makeWTRSHarnessHelper() { - return std::make_unique<PrefixedWiredTigerHarnessHelper>(); -} - -MONGO_INITIALIZER(RegisterRecordStoreHarnessFactory)(InitializerContext* const) { - mongo::registerRecordStoreHarnessHelperFactory(makeWTRSHarnessHelper); -} - -TEST(WiredTigerRecordStoreTest, PrefixedTableScan) { - unique_ptr<RecordStoreHarnessHelper> harnessHelper = newRecordStoreHarnessHelper(); - unique_ptr<RecordStore> rs = harnessHelper->newNonCappedRecordStore("a.b"); - - const int numDocs = 1000; - { // Insert documents. - ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); - for (int num = 0; num < numDocs; ++num) { - WriteUnitOfWork uow(opCtx.get()); - StatusWith<RecordId> res = rs->insertRecord(opCtx.get(), "a", 2, Timestamp()); - ASSERT_OK(res.getStatus()); - uow.commit(); - } - } - - auto client = harnessHelper->serviceContext()->makeClient("client"); - auto cursorCtx = harnessHelper->newOperationContext(client.get()); - - auto cursor = rs->getCursor(cursorCtx.get()); - for (int num = 0; num < numDocs; ++num) { - ASSERT(cursor->next()); - } - ASSERT(!cursor->next()); -} - -TEST(WiredTigerRecordStoreTest, PrefixedSeekingCursor) { - unique_ptr<RecordStoreHarnessHelper> harnessHelper = newRecordStoreHarnessHelper(); - unique_ptr<RecordStore> rs = harnessHelper->newNonCappedRecordStore("a.b"); - - RecordId startRecordId; - const int numDocs = 1000; - { // Insert documents. - ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); - for (int num = 0; num < numDocs; ++num) { - WriteUnitOfWork uow(opCtx.get()); - StatusWith<RecordId> res = rs->insertRecord(opCtx.get(), "a", 2, Timestamp()); - if (startRecordId.isNull()) { - startRecordId = res.getValue(); - } - ASSERT_OK(res.getStatus()); - uow.commit(); - } - } - - auto client = harnessHelper->serviceContext()->makeClient("client"); - auto cursorCtx = harnessHelper->newOperationContext(client.get()); - - auto cursor = rs->getCursor(cursorCtx.get()); - for (int num = 0; num < numDocs; ++num) { - ASSERT(cursor->seekExact(RecordId(startRecordId.repr() + num))); - } - ASSERT(!cursor->seekExact(RecordId(startRecordId.repr() + numDocs))); -} - -} // namespace -} // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp index 81c0a7b0e37..d6cb545542c 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp @@ -754,8 +754,7 @@ StatusWith<std::string> WiredTigerRecordStore::generateCreateString( const std::string& engineName, StringData ns, const CollectionOptions& options, - StringData extraStrings, - const bool prefixed) { + StringData extraStrings) { // Separate out a prefix and suffix in the default string. User configuration will // override values in the prefix, but not values in the suffix. str::stream ss; @@ -794,11 +793,7 @@ StatusWith<std::string> WiredTigerRecordStore::generateCreateString( // WARNING: No user-specified config can appear below this line. These options are required // for correct behavior of the server. - if (prefixed) { - ss << "key_format=qq"; - } else { - ss << "key_format=q"; - } + ss << "key_format=q"; ss << ",value_format=u"; // Record store metadata @@ -2281,10 +2276,7 @@ boost::optional<Record> WiredTigerRecordStoreCursorBase::next() { return {}; } invariantWTOK(advanceRet); - if (hasWrongPrefix(c, &id)) { - _eof = true; - return {}; - } + id = getKey(c); } _skipNextAdvance = false; @@ -2341,7 +2333,6 @@ boost::optional<Record> WiredTigerRecordStoreCursorBase::seekExact(const RecordI // Nothing after the next line can throw WCEs. int seekRet = wiredTigerPrepareConflictRetry(_opCtx, [&] { return c->search(c); }); if (seekRet == WT_NOTFOUND) { - // hasWrongPrefix check not needed for a precise 'WT_CURSOR::search'. _eof = true; return {}; } @@ -2413,10 +2404,7 @@ bool WiredTigerRecordStoreCursorBase::restore() { return !_rs._isCapped; } invariantWTOK(ret); - if (hasWrongPrefix(c, &id)) { - _eof = true; - return !_rs._isCapped; - } + id = getKey(c); if (cmp == 0) return true; // Landed right where we left off. @@ -2503,142 +2491,6 @@ RecordId WiredTigerRecordStoreStandardCursor::getKey(WT_CURSOR* cursor) const { return RecordId(recordId); } -bool WiredTigerRecordStoreStandardCursor::hasWrongPrefix(WT_CURSOR* cursor, - RecordId* recordId) const { - invariantWTOK(cursor->get_key(cursor, recordId)); - return false; -} - - -// Prefixed Implementations: - -PrefixedWiredTigerRecordStore::PrefixedWiredTigerRecordStore(WiredTigerKVEngine* kvEngine, - OperationContext* opCtx, - Params params, - KVPrefix prefix) - : WiredTigerRecordStore(kvEngine, opCtx, params), _prefix(prefix) {} - -std::unique_ptr<SeekableRecordCursor> PrefixedWiredTigerRecordStore::getCursor( - OperationContext* opCtx, bool forward) const { - if (_isOplog && forward) { - WiredTigerRecoveryUnit* wru = WiredTigerRecoveryUnit::get(opCtx); - // If we already have a snapshot we don't know what it can see, unless we know no one - // else could be writing (because we hold an exclusive lock). - invariant(!wru->isActive() || - opCtx->lockState()->isCollectionLockedForMode(NamespaceString(_ns), MODE_X) || - wru->getIsOplogReader()); - wru->setIsOplogReader(); - } - - return std::make_unique<WiredTigerRecordStorePrefixedCursor>(opCtx, *this, _prefix, forward); -} - -std::unique_ptr<RecordCursor> PrefixedWiredTigerRecordStore::getRandomCursorWithOptions( - OperationContext* opCtx, StringData extraConfig) const { - return {}; -} - -RecordId PrefixedWiredTigerRecordStore::getKey(WT_CURSOR* cursor) const { - std::int64_t prefix; - std::int64_t recordId; - invariantWTOK(cursor->get_key(cursor, &prefix, &recordId)); - invariant(prefix == _prefix.repr()); - return RecordId(recordId); -} - -void PrefixedWiredTigerRecordStore::setKey(WT_CURSOR* cursor, RecordId id) const { - cursor->set_key(cursor, _prefix.repr(), id.repr()); -} - -WiredTigerRecordStorePrefixedCursor::WiredTigerRecordStorePrefixedCursor( - OperationContext* opCtx, const WiredTigerRecordStore& rs, KVPrefix prefix, bool forward) - : WiredTigerRecordStoreCursorBase(opCtx, rs, forward), _prefix(prefix) { - initCursorToBeginning(); -} - -void WiredTigerRecordStorePrefixedCursor::setKey(WT_CURSOR* cursor, RecordId id) const { - cursor->set_key(cursor, _prefix.repr(), id.repr()); -} - -RecordId WiredTigerRecordStorePrefixedCursor::getKey(WT_CURSOR* cursor) const { - std::int64_t prefix; - std::int64_t recordId; - invariantWTOK(cursor->get_key(cursor, &prefix, &recordId)); - invariant(prefix == _prefix.repr()); - - return RecordId(recordId); -} - -bool WiredTigerRecordStorePrefixedCursor::hasWrongPrefix(WT_CURSOR* cursor, - RecordId* recordId) const { - std::int64_t prefix; - invariantWTOK(cursor->get_key(cursor, &prefix, recordId)); - - return prefix != _prefix.repr(); -} - -void WiredTigerRecordStorePrefixedCursor::initCursorToBeginning() { - WT_CURSOR* cursor = _cursor->get(); - if (_forward) { - cursor->set_key(cursor, _prefix.repr(), RecordId::min()); - } else { - cursor->set_key(cursor, _prefix.repr(), RecordId::max()); - } - - int exact; - int err = cursor->search_near(cursor, &exact); - if (err == WT_NOTFOUND) { - _eof = true; - return; - } - invariantWTOK(err); - - auto& metricsCollector = ResourceConsumption::MetricsCollector::get(_opCtx); - metricsCollector.incrementOneCursorSeek(); - - RecordId recordId; - if (_forward) { - invariant(exact != 0); // `RecordId::min` cannot exist. - if (exact > 0) { - // Cursor is positioned after <Prefix, RecordId::min>. It may be the first record of - // this collection or a following collection with a larger prefix. - // - // In the case the cursor is positioned a matching prefix, `_skipNextAdvance` must - // be set to true. However, `WiredTigerRecordStore::Cursor::next` does not check - // for EOF if `_skipNextAdvance` is true. Eagerly check and set `_eof` if - // necessary. - if (hasWrongPrefix(cursor, &recordId)) { - _eof = true; - return; - } - - _skipNextAdvance = true; - } else { - _eof = true; - } - } else { // Backwards. - invariant(exact != 0); // `RecordId::min` cannot exist. - if (exact > 0) { - // Cursor is positioned after <Prefix, RecordId::max>. This implies it is - // positioned at the first record for a collection with a larger - // prefix. `_skipNextAdvance` should remain false and a following call to - // `WiredTigerRecordStore::Cursor::next` will advance the cursor and appropriately - // check for EOF. - _skipNextAdvance = false; // Simply for clarity and symmetry to the `forward` case. - } else { - // Cursor is positioned before <Prefix, RecordId::max>. This is a symmetric case - // to `forward: true, exact > 0`. It may be positioned at the last document of - // this collection or the last document of a collection with a smaller prefix. - if (hasWrongPrefix(cursor, &recordId)) { - _eof = true; - return; - } - - _skipNextAdvance = true; - } - } -} - Status WiredTigerRecordStore::updateCappedSize(OperationContext* opCtx, long long cappedSize) { if (_cappedMaxSize == cappedSize) { return Status::OK(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h index d551e860e26..85275dca259 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h @@ -36,7 +36,6 @@ #include "mongo/db/catalog/collection_options.h" #include "mongo/db/storage/capped_callback.h" -#include "mongo/db/storage/kv/kv_prefix.h" #include "mongo/db/storage/record_store.h" #include "mongo/db/storage/wiredtiger/wiredtiger_cursor.h" #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" @@ -74,7 +73,6 @@ class WiredTigerRecordStore : public RecordStore { friend class WiredTigerRecordStoreCursorBase; friend class StandardWiredTigerRecordStore; - friend class PrefixedWiredTigerRecordStore; public: /** @@ -99,8 +97,7 @@ public: static StatusWith<std::string> generateCreateString(const std::string& engineName, StringData ns, const CollectionOptions& options, - StringData extraStrings, - bool prefixed); + StringData extraStrings); struct Params { StringData ns; @@ -414,32 +411,6 @@ protected: virtual void setKey(WT_CURSOR* cursor, RecordId id) const; }; -class PrefixedWiredTigerRecordStore final : public WiredTigerRecordStore { -public: - PrefixedWiredTigerRecordStore(WiredTigerKVEngine* kvEngine, - OperationContext* opCtx, - Params params, - KVPrefix prefix); - - virtual std::unique_ptr<SeekableRecordCursor> getCursor(OperationContext* opCtx, - bool forward) const override; - - virtual std::unique_ptr<RecordCursor> getRandomCursorWithOptions( - OperationContext* opCtx, StringData extraConfig) const override; - - virtual KVPrefix getPrefix() const { - return _prefix; - } - -protected: - virtual RecordId getKey(WT_CURSOR* cursor) const; - - virtual void setKey(WT_CURSOR* cursor, RecordId id) const; - -private: - KVPrefix _prefix; -}; - class WiredTigerRecordStoreCursorBase : public SeekableRecordCursor { public: WiredTigerRecordStoreCursorBase(OperationContext* opCtx, @@ -466,15 +437,6 @@ protected: virtual void setKey(WT_CURSOR* cursor, RecordId id) const = 0; /** - * Callers must have already checked the return value of a positioning method against - * 'WT_NOTFOUND'. This method allows for additional predicates to be considered on a validly - * positioned cursor. 'id' is an out parameter. Implementations are not required to fill it - * in. It's simply a possible optimization to avoid a future 'getKey' call if 'hasWrongPrefix' - * already did one. - */ - virtual bool hasWrongPrefix(WT_CURSOR* cursor, RecordId* id) const = 0; - - /** * Called when restoring a cursor that has not been advanced. */ virtual void initCursorToBeginning() = 0; @@ -510,45 +472,9 @@ protected: virtual void setKey(WT_CURSOR* cursor, RecordId id) const override; - /** - * Callers must have already checked the return value of a positioning method against - * 'WT_NOTFOUND'. This method allows for additional predicates to be considered on a validly - * positioned cursor. 'id' is an out parameter. Implementations are not required to fill it - * in. It's simply a possible optimization to avoid a future 'getKey' call if 'hasWrongPrefix' - * already did one. - */ - virtual bool hasWrongPrefix(WT_CURSOR* cursor, RecordId* id) const override; - virtual void initCursorToBeginning(){}; }; -class WiredTigerRecordStorePrefixedCursor final : public WiredTigerRecordStoreCursorBase { -public: - WiredTigerRecordStorePrefixedCursor(OperationContext* opCtx, - const WiredTigerRecordStore& rs, - KVPrefix prefix, - bool forward = true); - -protected: - virtual RecordId getKey(WT_CURSOR* cursor) const override; - - virtual void setKey(WT_CURSOR* cursor, RecordId id) const override; - - /** - * Callers must have already checked the return value of a positioning method against - * 'WT_NOTFOUND'. This method allows for additional predicates to be considered on a validly - * positioned cursor. 'id' is an out parameter. Implementations are not required to fill it - * in. It's simply a possible optimization to avoid a future 'getKey' call if 'hasWrongPrefix' - * already did one. - */ - virtual bool hasWrongPrefix(WT_CURSOR* cursor, RecordId* id) const override; - - virtual void initCursorToBeginning() override; - -private: - KVPrefix _prefix; -}; - // WT failpoint to throw write conflict exceptions randomly extern FailPoint WTWriteConflictException; extern FailPoint WTWriteConflictExceptionForReads; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp index e097e6a2e3e..cfd4b8a43ca 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp @@ -41,7 +41,6 @@ #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/json.h" #include "mongo/db/operation_context_noop.h" -#include "mongo/db/storage/kv/kv_prefix.h" #include "mongo/db/storage/record_store_test_harness.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store_oplog_stones.h" diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp index 0fe252a0f3a..97d8c8d4943 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit_test.cpp @@ -78,9 +78,8 @@ public: const std::string& ns) final { std::string ident = ns; std::string uri = WiredTigerKVEngine::kTableUriPrefix + ns; - const bool prefixed = false; StatusWith<std::string> result = WiredTigerRecordStore::generateCreateString( - kWiredTigerEngineName, ns, CollectionOptions(), "", prefixed); + kWiredTigerEngineName, ns, CollectionOptions(), ""); ASSERT_TRUE(result.isOK()); std::string config = result.getValue(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp index 9f3669ad8fc..a587089e5c5 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_index_test.cpp @@ -38,7 +38,6 @@ #include "mongo/db/index/index_descriptor.h" #include "mongo/db/json.h" #include "mongo/db/operation_context_noop.h" -#include "mongo/db/storage/kv/kv_prefix.h" #include "mongo/db/storage/sorted_data_interface_test_harness.h" #include "mongo/db/storage/wiredtiger/wiredtiger_index.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" @@ -83,15 +82,14 @@ public: IndexDescriptor desc("", spec); invariant(desc.isIdIndex()); - KVPrefix prefix = KVPrefix::kNotPrefixed; StatusWith<std::string> result = WiredTigerIndex::generateCreateString( - kWiredTigerEngineName, "", "", NamespaceString(ns), desc, prefix.isPrefixed()); + kWiredTigerEngineName, "", "", NamespaceString(ns), desc); ASSERT_OK(result.getStatus()); string uri = "table:" + ns; invariantWTOK(WiredTigerIndex::Create(&opCtx, uri, result.getValue())); - return std::make_unique<WiredTigerIdIndex>(&opCtx, uri, "" /* ident */, &desc, prefix); + return std::make_unique<WiredTigerIdIndex>(&opCtx, uri, "" /* ident */, &desc); } std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique, bool partial) final { @@ -114,19 +112,16 @@ public: IndexDescriptor& desc = _descriptors.emplace_back("", spec); - KVPrefix prefix = KVPrefix::kNotPrefixed; StatusWith<std::string> result = WiredTigerIndex::generateCreateString( - kWiredTigerEngineName, "", "", NamespaceString(ns), desc, prefix.isPrefixed()); + kWiredTigerEngineName, "", "", NamespaceString(ns), desc); ASSERT_OK(result.getStatus()); string uri = "table:" + ns; invariantWTOK(WiredTigerIndex::Create(&opCtx, uri, result.getValue())); if (unique) - return std::make_unique<WiredTigerIndexUnique>( - &opCtx, uri, "" /* ident */, &desc, prefix); - return std::make_unique<WiredTigerIndexStandard>( - &opCtx, uri, "" /* ident */, &desc, prefix); + return std::make_unique<WiredTigerIndexUnique>(&opCtx, uri, "" /* ident */, &desc); + return std::make_unique<WiredTigerIndexStandard>(&opCtx, uri, "" /* ident */, &desc); } std::unique_ptr<RecoveryUnit> newRecoveryUnit() final { diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp index 1f93a9fc63c..1de8c70658e 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp @@ -45,7 +45,6 @@ #include "mongo/db/repl/replication_coordinator_mock.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/kv/kv_engine_test_harness.h" -#include "mongo/db/storage/kv/kv_prefix.h" #include "mongo/db/storage/record_store_test_harness.h" #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" @@ -101,9 +100,8 @@ public: OperationContextNoop opCtx(ru); string uri = WiredTigerKVEngine::kTableUriPrefix + ns; - const bool prefixed = false; StatusWith<std::string> result = WiredTigerRecordStore::generateCreateString( - kWiredTigerEngineName, ns, CollectionOptions(), "", prefixed); + kWiredTigerEngineName, ns, CollectionOptions(), ""); ASSERT_TRUE(result.isOK()); std::string config = result.getValue(); @@ -149,9 +147,8 @@ public: CollectionOptions options; options.capped = true; - const bool prefixed = false; - StatusWith<std::string> result = WiredTigerRecordStore::generateCreateString( - kWiredTigerEngineName, ns, options, "", prefixed); + StatusWith<std::string> result = + WiredTigerRecordStore::generateCreateString(kWiredTigerEngineName, ns, options, ""); ASSERT_TRUE(result.isOK()); std::string config = result.getValue(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util_test.cpp index 81f1726267c..4decabddcba 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util_test.cpp @@ -34,7 +34,6 @@ #include "mongo/base/string_data.h" #include "mongo/db/operation_context_noop.h" -#include "mongo/db/storage/kv/kv_prefix.h" #include "mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h" #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" |