summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2018-11-21 09:38:18 -0500
committerGeert Bosch <geert@mongodb.com>2018-11-26 18:11:04 -0500
commitf99f0d98273f96e769ff39652480c359d831c19f (patch)
treece08527e6ed327fdcdd8fdf5aff3c475cd706578 /src/mongo
parent65afd95ebe12305877f357227b99d231ffd85d39 (diff)
downloadmongo-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')
-rw-r--r--src/mongo/db/storage/biggie/biggie_sorted_impl.cpp2
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp27
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_insert.cpp13
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