Skip to content

Commit ffd486c

Browse files
xy24evergreen
authored andcommitted
SERVER-42248 Remove SortedDataInterface::seek() which accepts a BSONObj
1 parent 9841354 commit ffd486c

26 files changed

+444
-262
lines changed

src/mongo/db/catalog/throttle_cursor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ SortedDataInterfaceThrottleCursor::SortedDataInterfaceThrottleCursor(
7676
_dataThrottle = dataThrottle;
7777
}
7878

79-
boost::optional<IndexKeyEntry> SortedDataInterfaceThrottleCursor::seek(OperationContext* opCtx,
80-
const BSONObj& key) {
81-
boost::optional<IndexKeyEntry> entry = _cursor->seek(key, /*inclusive=*/true);
79+
boost::optional<IndexKeyEntry> SortedDataInterfaceThrottleCursor::seek(
80+
OperationContext* opCtx, const KeyString::Value& key) {
81+
boost::optional<IndexKeyEntry> entry = _cursor->seek(key);
8282
if (entry) {
8383
const int64_t dataSize = entry->key.objsize() + sizeof(entry->loc.repr());
8484
_dataThrottle->awaitIfNeeded(opCtx, dataSize);

src/mongo/db/catalog/throttle_cursor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class SortedDataInterfaceThrottleCursor {
7272
const IndexAccessMethod* iam,
7373
std::shared_ptr<DataThrottle> dataThrottle);
7474

75-
boost::optional<IndexKeyEntry> seek(OperationContext* opCtx, const BSONObj& key);
75+
boost::optional<IndexKeyEntry> seek(OperationContext* opCtx, const KeyString::Value& key);
7676

7777
boost::optional<IndexKeyEntry> next(OperationContext* opCtx);
7878

src/mongo/db/catalog/throttle_cursor_test.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace mongo {
4646
namespace {
4747

4848
const NamespaceString kNss = NamespaceString("test.throttleCursor");
49+
const KeyString::Value kMinKeyString = KeyString::Value();
4950

5051
class ThrottleCursorTest : public CatalogTestFixture {
5152
private:
@@ -219,7 +220,7 @@ TEST_F(ThrottleCursorTest, TestSortedDataInterfaceThrottleCursorOff) {
219220
setMaxMbPerSec(0);
220221
Date_t start = getTime();
221222

222-
ASSERT_TRUE(cursor.seek(opCtx, BSONObj()));
223+
ASSERT_TRUE(cursor.seek(opCtx, kMinKeyString));
223224
int numRecords = 1;
224225

225226
while (cursor.next(opCtx)) {
@@ -249,7 +250,7 @@ TEST_F(ThrottleCursorTest, TestSortedDataInterfaceThrottleCursorOn) {
249250
setMaxMbPerSec(1);
250251
Date_t start = getTime();
251252

252-
ASSERT_TRUE(cursor.seek(opCtx, BSONObj()));
253+
ASSERT_TRUE(cursor.seek(opCtx, kMinKeyString));
253254
int numRecords = 1;
254255

255256
while (cursor.next(opCtx)) {
@@ -269,7 +270,7 @@ TEST_F(ThrottleCursorTest, TestSortedDataInterfaceThrottleCursorOn) {
269270
setMaxMbPerSec(5);
270271
Date_t start = getTime();
271272

272-
ASSERT_TRUE(cursor.seek(opCtx, BSONObj()));
273+
ASSERT_TRUE(cursor.seek(opCtx, kMinKeyString));
273274
int numRecords = 1;
274275

275276
while (cursor.next(opCtx)) {
@@ -302,7 +303,7 @@ TEST_F(ThrottleCursorTest, TestMixedCursorsWithSharedThrottleOff) {
302303
setMaxMbPerSec(10);
303304
Date_t start = getTime();
304305

305-
ASSERT_TRUE(indexCursor.seek(opCtx, BSONObj()));
306+
ASSERT_TRUE(indexCursor.seek(opCtx, kMinKeyString));
306307
int numRecords = 1;
307308

308309
while (indexCursor.next(opCtx)) {
@@ -345,7 +346,7 @@ TEST_F(ThrottleCursorTest, TestMixedCursorsWithSharedThrottleOn) {
345346
setMaxMbPerSec(2);
346347
Date_t start = getTime();
347348

348-
ASSERT_TRUE(indexCursor.seek(opCtx, BSONObj()));
349+
ASSERT_TRUE(indexCursor.seek(opCtx, kMinKeyString));
349350
ASSERT_TRUE(recordCursor.seekExact(opCtx, RecordId(1)));
350351
int numRecords = 2;
351352

@@ -367,7 +368,7 @@ TEST_F(ThrottleCursorTest, TestMixedCursorsWithSharedThrottleOn) {
367368
setMaxMbPerSec(5);
368369
Date_t start = getTime();
369370

370-
ASSERT_TRUE(indexCursor.seek(opCtx, BSONObj()));
371+
ASSERT_TRUE(indexCursor.seek(opCtx, kMinKeyString));
371372
ASSERT_TRUE(recordCursor.seekExact(opCtx, RecordId(1)));
372373
int numRecords = 2;
373374

src/mongo/db/catalog/validate_adaptor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ void ValidateAdaptor::traverseIndex(
177177

178178
int interruptInterval = 4096;
179179

180-
// Seeking to BSONObj() is equivalent to seeking to the first entry of an index.
181-
for (auto indexEntry = indexCursor->seek(opCtx, BSONObj()); indexEntry;
180+
KeyString::Builder firstKeyString(
181+
version, BSONObj(), ord, KeyString::Discriminator::kExclusiveBefore);
182+
183+
for (auto indexEntry = indexCursor->seek(opCtx, firstKeyString.getValueCopy()); indexEntry;
182184
indexEntry = indexCursor->next(opCtx)) {
183185
if (!(numKeys % interruptInterval)) {
184186
opCtx->checkForInterrupt();

src/mongo/db/exec/count_scan.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ PlanStage::StageState CountScan::doWork(WorkingSetID* out) {
115115
_cursor = indexAccessMethod()->newCursor(getOpCtx());
116116
_cursor->setEndPosition(_endKey, _endKeyInclusive);
117117

118-
entry = _cursor->seek(_startKey, _startKeyInclusive, kWantLoc);
118+
auto keyStringForSeek = IndexEntryComparison::makeKeyStringFromBSONKeyForSeek(
119+
_startKey,
120+
indexAccessMethod()->getSortedDataInterface()->getKeyStringVersion(),
121+
indexAccessMethod()->getSortedDataInterface()->getOrdering(),
122+
true, /* forward */
123+
_startKeyInclusive);
124+
entry = _cursor->seek(keyStringForSeek);
119125
} else {
120126
entry = _cursor->next(kWantLoc);
121127
}

src/mongo/db/exec/distinct_scan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ PlanStage::StageState DistinctScan::doWork(WorkingSetID* out) {
7979
try {
8080
if (!_cursor)
8181
_cursor = indexAccessMethod()->newCursor(getOpCtx(), _scanDirection == 1);
82-
kv = _cursor->seek(IndexEntryComparison::makeKeyStringForSeekPoint(
82+
kv = _cursor->seek(IndexEntryComparison::makeKeyStringFromSeekPointForSeek(
8383
_seekPoint,
8484
indexAccessMethod()->getSortedDataInterface()->getKeyStringVersion(),
8585
indexAccessMethod()->getSortedDataInterface()->getOrdering(),

src/mongo/db/exec/index_scan.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,35 @@ boost::optional<IndexKeyEntry> IndexScan::initIndexScan() {
100100
_startKey = _bounds.startKey;
101101
_endKey = _bounds.endKey;
102102
_indexCursor->setEndPosition(_endKey, _endKeyInclusive);
103-
return _indexCursor->seek(_startKey, _startKeyInclusive);
103+
104+
KeyString::Value keyStringForSeek = IndexEntryComparison::makeKeyStringFromBSONKeyForSeek(
105+
_startKey,
106+
indexAccessMethod()->getSortedDataInterface()->getKeyStringVersion(),
107+
indexAccessMethod()->getSortedDataInterface()->getOrdering(),
108+
_forward,
109+
_startKeyInclusive);
110+
return _indexCursor->seek(keyStringForSeek);
104111
} else {
105112
// For single intervals, we can use an optimized scan which checks against the position
106113
// of an end cursor. For all other index scans, we fall back on using
107114
// IndexBoundsChecker to determine when we've finished the scan.
108115
if (IndexBoundsBuilder::isSingleInterval(
109116
_bounds, &_startKey, &_startKeyInclusive, &_endKey, &_endKeyInclusive)) {
110117
_indexCursor->setEndPosition(_endKey, _endKeyInclusive);
111-
return _indexCursor->seek(_startKey, _startKeyInclusive);
118+
119+
auto keyStringForSeek = IndexEntryComparison::makeKeyStringFromBSONKeyForSeek(
120+
_startKey,
121+
indexAccessMethod()->getSortedDataInterface()->getKeyStringVersion(),
122+
indexAccessMethod()->getSortedDataInterface()->getOrdering(),
123+
_forward,
124+
_startKeyInclusive);
125+
return _indexCursor->seek(keyStringForSeek);
112126
} else {
113127
_checker.reset(new IndexBoundsChecker(&_bounds, _keyPattern, _direction));
114128

115129
if (!_checker->getStartSeekPoint(&_seekPoint))
116130
return boost::none;
117-
return _indexCursor->seek(IndexEntryComparison::makeKeyStringForSeekPoint(
131+
return _indexCursor->seek(IndexEntryComparison::makeKeyStringFromSeekPointForSeek(
118132
_seekPoint,
119133
indexAccessMethod()->getSortedDataInterface()->getKeyStringVersion(),
120134
indexAccessMethod()->getSortedDataInterface()->getOrdering(),
@@ -136,7 +150,7 @@ PlanStage::StageState IndexScan::doWork(WorkingSetID* out) {
136150
break;
137151
case NEED_SEEK:
138152
++_specificStats.seeks;
139-
kv = _indexCursor->seek(IndexEntryComparison::makeKeyStringForSeekPoint(
153+
kv = _indexCursor->seek(IndexEntryComparison::makeKeyStringFromSeekPointForSeek(
140154
_seekPoint,
141155
indexAccessMethod()->getSortedDataInterface()->getKeyStringVersion(),
142156
indexAccessMethod()->getSortedDataInterface()->getOrdering(),

src/mongo/db/index/wildcard_access_method.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ std::set<FieldRef> WildcardAccessMethod::_getMultikeyPathSet(
108108
}
109109

110110
std::set<FieldRef> multikeyPaths{};
111-
auto entry = cursor->seek(IndexEntryComparison::makeKeyStringForSeekPoint(
111+
auto entry = cursor->seek(IndexEntryComparison::makeKeyStringFromSeekPointForSeek(
112112
seekPoint,
113113
getSortedDataInterface()->getKeyStringVersion(),
114114
getSortedDataInterface()->getOrdering(),
@@ -127,11 +127,12 @@ std::set<FieldRef> WildcardAccessMethod::_getMultikeyPathSet(
127127

128128
case IndexBoundsChecker::MUST_ADVANCE:
129129
++stats->numSeeks;
130-
entry = cursor->seek(IndexEntryComparison::makeKeyStringForSeekPoint(
131-
seekPoint,
132-
getSortedDataInterface()->getKeyStringVersion(),
133-
getSortedDataInterface()->getOrdering(),
134-
kForward));
130+
entry =
131+
cursor->seek(IndexEntryComparison::makeKeyStringFromSeekPointForSeek(
132+
seekPoint,
133+
getSortedDataInterface()->getKeyStringVersion(),
134+
getSortedDataInterface()->getOrdering(),
135+
kForward));
135136

136137
break;
137138

@@ -237,7 +238,14 @@ std::set<FieldRef> WildcardAccessMethod::getMultikeyPathSet(
237238

238239
constexpr bool inclusive = true;
239240
cursor->setEndPosition(metadataKeyRangeEnd, inclusive);
240-
auto entry = cursor->seek(metadataKeyRangeBegin, inclusive);
241+
242+
auto keyStringForSeek = IndexEntryComparison::makeKeyStringFromBSONKeyForSeek(
243+
metadataKeyRangeBegin,
244+
getSortedDataInterface()->getKeyStringVersion(),
245+
getSortedDataInterface()->getOrdering(),
246+
true, /* forward */
247+
inclusive);
248+
auto entry = cursor->seek(keyStringForSeek);
241249
++stats->numSeeks;
242250

243251
// Iterate the cursor, copying the multikey paths into an in-memory set.

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -830,16 +830,6 @@ boost::optional<KeyStringEntry> SortedDataInterface::Cursor::seekAfterProcessing
830830
return keyStringToKeyStringEntry(_reverseIt->first, _reverseIt->second, _order);
831831
}
832832

833-
boost::optional<IndexKeyEntry> SortedDataInterface::Cursor::seek(const BSONObj& key,
834-
bool inclusive,
835-
RequestedInfo) {
836-
BSONObj finalKey = BSONObj::stripFieldNames(key);
837-
const auto discriminator = _forward == inclusive ? KeyString::Discriminator::kExclusiveBefore
838-
: KeyString::Discriminator::kExclusiveAfter;
839-
KeyString::Builder keyString(KeyString::Version::V1, finalKey, _order, discriminator);
840-
return seek(keyString.getValueCopy());
841-
}
842-
843833
boost::optional<IndexKeyEntry> SortedDataInterface::Cursor::seek(const KeyString::Value& keyString,
844834
RequestedInfo parts) {
845835
boost::optional<KeyStringEntry> ksValue = seekForKeyString(keyString);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ class SortedDataInterface : public ::mongo::SortedDataInterface {
120120
std::string KSForIdentEnd);
121121
virtual void setEndPosition(const BSONObj& key, bool inclusive) override;
122122
virtual boost::optional<IndexKeyEntry> next(RequestedInfo parts = kKeyAndLoc) override;
123-
virtual boost::optional<IndexKeyEntry> seek(const BSONObj& key,
124-
bool inclusive,
125-
RequestedInfo parts = kKeyAndLoc) override;
126123
virtual boost::optional<IndexKeyEntry> seek(const KeyString::Value& keyString,
127124
RequestedInfo parts = kKeyAndLoc) override;
128125
virtual boost::optional<KeyStringEntry> seekForKeyString(

0 commit comments

Comments
 (0)