Skip to content

Commit 36ea872

Browse files
dhly-etcEvergreen Agent
authored andcommitted
SERVER-83485 Fix multikey-path serialization code used during validation
1 parent 5b4326e commit 36ea872

File tree

5 files changed

+151
-29
lines changed

5 files changed

+151
-29
lines changed

src/mongo/db/catalog/collection_validation.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -456,35 +456,6 @@ void addErrorIfUnequal(boost::optional<ValidationActionEnum> stored,
456456
results);
457457
}
458458

459-
std::string multikeyPathsToString(MultikeyPaths paths) {
460-
str::stream builder;
461-
builder << "[";
462-
auto pathIt = paths.begin();
463-
while (true) {
464-
builder << "{";
465-
466-
auto pathSet = *pathIt;
467-
auto setIt = pathSet.begin();
468-
while (true) {
469-
builder << *setIt++;
470-
if (setIt == pathSet.end()) {
471-
break;
472-
} else {
473-
builder << ",";
474-
}
475-
}
476-
builder << "}";
477-
478-
if (++pathIt == paths.end()) {
479-
break;
480-
} else {
481-
builder << ",";
482-
}
483-
}
484-
builder << "]";
485-
return builder;
486-
}
487-
488459
void _validateCatalogEntry(OperationContext* opCtx,
489460
ValidateState* validateState,
490461
ValidateResults* results) {

src/mongo/db/index/SConscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ iamEnv.Library(
4949
'index_build_interceptor.cpp',
5050
'index_build_interceptor.idl',
5151
'index_descriptor.cpp',
52+
'multikey_paths.cpp',
5253
's2_access_method.cpp',
5354
's2_bucket_access_method.cpp',
5455
'skipped_record_tracker.cpp',
@@ -125,6 +126,7 @@ indexTestEnv.CppUnitTest(
125126
'columns_access_method_test.cpp',
126127
'hash_key_generator_test.cpp',
127128
'index_build_interceptor_test.cpp',
129+
'multikey_paths_test.cpp',
128130
's2_key_generator_test.cpp',
129131
's2_bucket_key_generator_test.cpp',
130132
'sort_key_generator_test.cpp',

src/mongo/db/index/multikey_paths.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Copyright (C) 2019-present MongoDB, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*
17+
* As a special exception, the copyright holders give permission to link the
18+
* code of portions of this program with the OpenSSL library under certain
19+
* conditions as described in each individual source file and distribute
20+
* linked combinations including the program with the OpenSSL library. You
21+
* must comply with the Server Side Public License in all respects for
22+
* all of the code used other than as permitted herein. If you modify file(s)
23+
* with this exception, you may extend this exception to your version of the
24+
* file(s), but you are not obligated to do so. If you do not wish to do so,
25+
* delete this exception statement from your version. If you delete this
26+
* exception statement from all source files in the program, then also delete
27+
* it in the license file.
28+
*/
29+
30+
#include "mongo/db/index/multikey_paths.h"
31+
32+
#include "mongo/util/str.h"
33+
34+
namespace mongo {
35+
36+
std::string multikeyPathsToString(MultikeyPaths paths) {
37+
str::stream builder;
38+
builder << "[";
39+
auto pathIt = paths.begin();
40+
while (true) {
41+
if (pathIt == paths.end()) {
42+
break;
43+
}
44+
45+
builder << "{";
46+
47+
auto pathSet = *pathIt;
48+
auto setIt = pathSet.begin();
49+
while (true) {
50+
if (setIt == pathSet.end()) {
51+
break;
52+
}
53+
54+
builder << *setIt;
55+
if (++setIt == pathSet.end()) {
56+
break;
57+
} else {
58+
builder << ",";
59+
}
60+
}
61+
62+
builder << "}";
63+
64+
if (++pathIt == paths.end()) {
65+
break;
66+
} else {
67+
builder << ",";
68+
}
69+
}
70+
builder << "]";
71+
return builder;
72+
}
73+
74+
} // namespace mongo

src/mongo/db/index/multikey_paths.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ using MultikeyComponents = boost::container::flat_set<
6767
constexpr std::size_t kFewCompoundIndexFields = 4;
6868
using MultikeyPaths = boost::container::small_vector<MultikeyComponents, kFewCompoundIndexFields>;
6969

70+
std::string multikeyPathsToString(MultikeyPaths paths);
7071
} // namespace mongo
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Copyright (C) 2023-present MongoDB, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*
17+
* As a special exception, the copyright holders give permission to link the
18+
* code of portions of this program with the OpenSSL library under certain
19+
* conditions as described in each individual source file and distribute
20+
* linked combinations including the program with the OpenSSL library. You
21+
* must comply with the Server Side Public License in all respects for
22+
* all of the code used other than as permitted herein. If you modify file(s)
23+
* with this exception, you may extend this exception to your version of the
24+
* file(s), but you are not obligated to do so. If you do not wish to do so,
25+
* delete this exception statement from your version. If you delete this
26+
* exception statement from all source files in the program, then also delete
27+
* it in the license file.
28+
*/
29+
30+
#include "mongo/db/index/multikey_paths.h"
31+
#include "mongo/unittest/assert.h"
32+
#include "mongo/unittest/framework.h"
33+
34+
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
35+
36+
namespace mongo {
37+
namespace {
38+
39+
TEST(MultikeyPaths, PrintEmptyPaths) {
40+
MultikeyPaths paths;
41+
ASSERT_EQ(multikeyPathsToString(paths), "[]");
42+
}
43+
44+
TEST(MultikeyPaths, PrintEmptySetPaths) {
45+
MultikeyPaths paths;
46+
paths.resize(1);
47+
ASSERT_EQ(multikeyPathsToString(paths), "[{}]");
48+
}
49+
50+
TEST(MultikeyPaths, PrintEmptySetsPaths) {
51+
MultikeyPaths paths;
52+
paths.resize(2);
53+
ASSERT_EQ(multikeyPathsToString(paths), "[{},{}]");
54+
}
55+
56+
TEST(MultikeyPaths, PrintNonEmptySetPaths) {
57+
MultikeyPaths paths;
58+
paths.resize(2);
59+
paths[1].insert(2);
60+
ASSERT_EQ(multikeyPathsToString(paths), "[{},{2}]");
61+
}
62+
63+
TEST(MultikeyPaths, PrintNonEmptySetsPaths) {
64+
MultikeyPaths paths;
65+
paths.resize(4);
66+
paths[1].insert(2);
67+
paths[3].insert(0);
68+
paths[3].insert(1);
69+
paths[3].insert(2);
70+
ASSERT_EQ(multikeyPathsToString(paths), "[{},{2},{},{0,1,2}]");
71+
}
72+
73+
} // namespace
74+
} // namespace mongo

0 commit comments

Comments
 (0)