diff options
author | Geert Bosch <geert@mongodb.com> | 2018-11-21 09:38:18 -0500 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2018-11-26 18:11:04 -0500 |
commit | f99f0d98273f96e769ff39652480c359d831c19f (patch) | |
tree | ce08527e6ed327fdcdd8fdf5aff3c475cd706578 /src/mongo | |
parent | 65afd95ebe12305877f357227b99d231ffd85d39 (diff) | |
download | mongo-f99f0d98273f96e769ff39652480c359d831c19f.tar.gz |
SERVER-38226 Support storing a reserved RecordId in biggie SortedDataInterface
Also add new unit test for storing a reserved RecordId to the general SortedDataInterface
testing framework.
Diffstat (limited to 'src/mongo')
3 files changed, 41 insertions, 1 deletions
diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp index efbbcc66416..ffeba709c05 100644 --- a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp +++ b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp @@ -190,7 +190,7 @@ StatusWith<SpecialFormatInserted> SortedDataBuilderInterface::addKey(const BSONO const RecordId& loc) { StringStore* workingCopy(RecoveryUnit::get(_opCtx)->getHead()); - invariant(loc.isNormal()); + invariant(loc.isNormal() || loc.isReserved()); invariant(!hasFieldNames(key)); std::unique_ptr<KeyString> newKS = keyToKeyString(key, _order); diff --git a/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp b/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp index 9b7c854d313..72ff41eff0e 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp @@ -65,6 +65,33 @@ TEST(SortedDataInterface, BuilderAddKey) { } } +// Add a reserved RecordId using a bulk builder. +TEST(SortedDataInterface, BuilderAddKeyWithReservedRecordId) { + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); + const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); + { + const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); + ASSERT(sorted->isEmpty(opCtx.get())); + } + + { + const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); + const std::unique_ptr<SortedDataBuilderInterface> builder( + sorted->getBulkBuilder(opCtx.get(), true)); + + RecordId reservedLoc(RecordId::ReservedId::kWildcardMultikeyMetadataId); + ASSERT(reservedLoc.isReserved()); + + ASSERT_OK(builder->addKey(key1, reservedLoc)); + ASSERT_EQUALS(SpecialFormatInserted::NoSpecialFormatInserted, builder->commit(false)); + } + + { + const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); + } +} + // Add a compound key using a bulk builder. TEST(SortedDataInterface, BuilderAddCompoundKey) { const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); diff --git a/src/mongo/db/storage/sorted_data_interface_test_insert.cpp b/src/mongo/db/storage/sorted_data_interface_test_insert.cpp index ec4017a5985..7ccb0c766c6 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_insert.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_insert.cpp @@ -367,5 +367,18 @@ TEST(SortedDataInterface, InsertMultipleCompoundKeys) { } } +TEST(SortedDataInterface, InsertReservedRecordId) { + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); + const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); + const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); + ASSERT(sorted->isEmpty(opCtx.get())); + WriteUnitOfWork uow(opCtx.get()); + RecordId reservedLoc(RecordId::ReservedId::kWildcardMultikeyMetadataId); + ASSERT(reservedLoc.isReserved()); + ASSERT_OK(sorted->insert(opCtx.get(), key1, reservedLoc, /*dupsAllowed*/ true)); + uow.commit(); + ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); +} + } // namespace } // namespace mongo |