Skip to content

Commit f99f0d9

Browse files
committed
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.
1 parent 65afd95 commit f99f0d9

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/mongo/db/storage/biggie/biggie_sorted_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ StatusWith<SpecialFormatInserted> SortedDataBuilderInterface::addKey(const BSONO
190190
const RecordId& loc) {
191191
StringStore* workingCopy(RecoveryUnit::get(_opCtx)->getHead());
192192

193-
invariant(loc.isNormal());
193+
invariant(loc.isNormal() || loc.isReserved());
194194
invariant(!hasFieldNames(key));
195195

196196
std::unique_ptr<KeyString> newKS = keyToKeyString(key, _order);

src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ TEST(SortedDataInterface, BuilderAddKey) {
6565
}
6666
}
6767

68+
// Add a reserved RecordId using a bulk builder.
69+
TEST(SortedDataInterface, BuilderAddKeyWithReservedRecordId) {
70+
const auto harnessHelper(newSortedDataInterfaceHarnessHelper());
71+
const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
72+
{
73+
const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext());
74+
ASSERT(sorted->isEmpty(opCtx.get()));
75+
}
76+
77+
{
78+
const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext());
79+
const std::unique_ptr<SortedDataBuilderInterface> builder(
80+
sorted->getBulkBuilder(opCtx.get(), true));
81+
82+
RecordId reservedLoc(RecordId::ReservedId::kWildcardMultikeyMetadataId);
83+
ASSERT(reservedLoc.isReserved());
84+
85+
ASSERT_OK(builder->addKey(key1, reservedLoc));
86+
ASSERT_EQUALS(SpecialFormatInserted::NoSpecialFormatInserted, builder->commit(false));
87+
}
88+
89+
{
90+
const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext());
91+
ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
92+
}
93+
}
94+
6895
// Add a compound key using a bulk builder.
6996
TEST(SortedDataInterface, BuilderAddCompoundKey) {
7097
const auto harnessHelper(newSortedDataInterfaceHarnessHelper());

src/mongo/db/storage/sorted_data_interface_test_insert.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,5 +367,18 @@ TEST(SortedDataInterface, InsertMultipleCompoundKeys) {
367367
}
368368
}
369369

370+
TEST(SortedDataInterface, InsertReservedRecordId) {
371+
const auto harnessHelper(newSortedDataInterfaceHarnessHelper());
372+
const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
373+
const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext());
374+
ASSERT(sorted->isEmpty(opCtx.get()));
375+
WriteUnitOfWork uow(opCtx.get());
376+
RecordId reservedLoc(RecordId::ReservedId::kWildcardMultikeyMetadataId);
377+
ASSERT(reservedLoc.isReserved());
378+
ASSERT_OK(sorted->insert(opCtx.get(), key1, reservedLoc, /*dupsAllowed*/ true));
379+
uow.commit();
380+
ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
381+
}
382+
370383
} // namespace
371384
} // namespace mongo

0 commit comments

Comments
 (0)