Skip to content

Commit faba5ab

Browse files
committed
SERVER-38559 move catalog_control.cpp into its own library
1 parent 2c56931 commit faba5ab

File tree

6 files changed

+158
-5
lines changed

6 files changed

+158
-5
lines changed

src/mongo/db/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,7 @@ env.Library(
18391839
'service_context_test_fixture',
18401840
],
18411841
LIBDEPS_PRIVATE=[
1842+
'catalog/catalog_impl',
18421843
'commands/mongod',
18431844
'index_builds_coordinator_mongod',
18441845
'service_context_d',

src/mongo/db/catalog/SConscript

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,34 @@ env.Library(
326326
)
327327

328328
env.Library(
329-
target='catalog_impl',
329+
target='catalog_control',
330330
source=[
331331
"catalog_control.cpp",
332+
],
333+
LIBDEPS_PRIVATE=[
334+
'collection',
335+
'database',
336+
'uuid_catalog',
337+
'$BUILD_DIR/mongo/db/repair_database',
338+
'$BUILD_DIR/mongo/db/service_context',
339+
],
340+
)
341+
342+
env.CppUnitTest(
343+
target='catalog_control_test',
344+
source=[
345+
'catalog_control_test.cpp'
346+
],
347+
LIBDEPS=[
348+
'catalog_control',
349+
'database_holder_mock',
350+
'$BUILD_DIR/mongo/db/service_context',
351+
],
352+
)
353+
354+
env.Library(
355+
target='catalog_impl',
356+
source=[
332357
"collection_impl.cpp",
333358
"collection_info_cache_impl.cpp",
334359
"database_holder_impl.cpp",
@@ -358,7 +383,6 @@ env.Library(
358383
'$BUILD_DIR/mongo/db/index_d',
359384
'$BUILD_DIR/mongo/db/op_observer',
360385
'$BUILD_DIR/mongo/db/query_exec',
361-
'$BUILD_DIR/mongo/db/repair_database',
362386
'$BUILD_DIR/mongo/db/repl/drop_pending_collection_reaper',
363387
'$BUILD_DIR/mongo/db/repl/oplog',
364388
'$BUILD_DIR/mongo/db/server_options_core',
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
2+
/**
3+
* Copyright (C) 2018-present MongoDB, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the Server Side Public License, version 1,
7+
* as published by MongoDB, Inc.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* Server Side Public License for more details.
13+
*
14+
* You should have received a copy of the Server Side Public License
15+
* along with this program. If not, see
16+
* <http://www.mongodb.com/licensing/server-side-public-license>.
17+
*
18+
* As a special exception, the copyright holders give permission to link the
19+
* code of portions of this program with the OpenSSL library under certain
20+
* conditions as described in each individual source file and distribute
21+
* linked combinations including the program with the OpenSSL library. You
22+
* must comply with the Server Side Public License in all respects for
23+
* all of the code used other than as permitted herein. If you modify file(s)
24+
* with this exception, you may extend this exception to your version of the
25+
* file(s), but you are not obligated to do so. If you do not wish to do so,
26+
* delete this exception statement from your version. If you delete this
27+
* exception statement from all source files in the program, then also delete
28+
* it in the license file.
29+
*/
30+
31+
#include "mongo/db/catalog/catalog_control.h"
32+
33+
#include "mongo/db/client.h"
34+
#include "mongo/db/operation_context_noop.h"
35+
#include "mongo/db/service_context.h"
36+
#include "mongo/db/storage/storage_engine.h"
37+
#include "mongo/unittest/unittest.h"
38+
39+
namespace mongo {
40+
namespace {
41+
42+
/**
43+
* Mock storage engine.
44+
*/
45+
class MockStorageEngine : public StorageEngine {
46+
public:
47+
RecoveryUnit* newRecoveryUnit() final {
48+
return nullptr;
49+
}
50+
void listDatabases(std::vector<std::string>* out) const final {}
51+
DatabaseCatalogEntry* getDatabaseCatalogEntry(OperationContext* opCtx, StringData db) final {
52+
return nullptr;
53+
}
54+
bool supportsDocLocking() const final {
55+
return false;
56+
}
57+
bool isDurable() const final {
58+
return false;
59+
}
60+
bool isEphemeral() const {
61+
return true;
62+
}
63+
Status closeDatabase(OperationContext* opCtx, StringData db) final {
64+
return Status::OK();
65+
}
66+
Status dropDatabase(OperationContext* opCtx, StringData db) final {
67+
return Status::OK();
68+
}
69+
int flushAllFiles(OperationContext* opCtx, bool sync) final {
70+
return 0;
71+
}
72+
Status repairRecordStore(OperationContext* opCtx, const std::string& ns) final {
73+
return Status::OK();
74+
}
75+
std::unique_ptr<TemporaryRecordStore> makeTemporaryRecordStore(OperationContext* opCtx) final {
76+
return {};
77+
}
78+
void cleanShutdown() final {}
79+
void setJournalListener(JournalListener* jl) final {}
80+
Timestamp getAllCommittedTimestamp() const final {
81+
return {};
82+
}
83+
Timestamp getOldestOpenReadTimestamp() const final {
84+
return {};
85+
}
86+
std::string getFilesystemPathForDb(const std::string& dbName) const final {
87+
return "";
88+
}
89+
};
90+
91+
/**
92+
* Simple test for openCatalog() and closeCatalog() to check library dependencies.
93+
*/
94+
class CatalogControlTest : public unittest::Test {
95+
private:
96+
void setUp() override;
97+
void tearDown() override;
98+
99+
std::unique_ptr<ThreadClient> _tc;
100+
};
101+
102+
void CatalogControlTest::setUp() {
103+
{
104+
auto serviceContext = ServiceContext::make();
105+
auto storageEngine = std::make_unique<MockStorageEngine>();
106+
serviceContext->setStorageEngine(std::move(storageEngine));
107+
setGlobalServiceContext(std::move(serviceContext));
108+
}
109+
110+
_tc = std::make_unique<ThreadClient>(getGlobalServiceContext());
111+
}
112+
113+
void CatalogControlTest::tearDown() {
114+
_tc = {};
115+
}
116+
117+
TEST_F(CatalogControlTest, CloseAndOpenCatalog) {
118+
OperationContextNoop opCtx(&cc(), 0);
119+
auto map = catalog::closeCatalog(&opCtx);
120+
ASSERT_EQUALS(0U, map.size());
121+
catalog::openCatalog(&opCtx, {});
122+
}
123+
124+
} // namespace
125+
} // namespace mongo

src/mongo/db/commands/SConscript

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ env.Library(
280280
],
281281
LIBDEPS_PRIVATE=[
282282
'$BUILD_DIR/mongo/db/catalog/catalog_helpers',
283-
'$BUILD_DIR/mongo/db/catalog/catalog_impl',
283+
'$BUILD_DIR/mongo/db/catalog/collection',
284+
'$BUILD_DIR/mongo/db/catalog/database',
284285
'$BUILD_DIR/mongo/db/commands',
285286
'test_commands_enabled',
286287
],
@@ -333,12 +334,13 @@ env.Library(
333334
'$BUILD_DIR/mongo/db/auth/user_document_parser',
334335
'$BUILD_DIR/mongo/db/auth/user',
335336
'$BUILD_DIR/mongo/db/background',
337+
'$BUILD_DIR/mongo/db/catalog/catalog_control',
336338
'$BUILD_DIR/mongo/db/catalog/catalog_helpers',
337-
'$BUILD_DIR/mongo/db/catalog/catalog_impl',
338339
'$BUILD_DIR/mongo/db/catalog/index_key_validate',
339340
'$BUILD_DIR/mongo/db/cloner',
340341
'$BUILD_DIR/mongo/db/commands',
341342
'$BUILD_DIR/mongo/db/curop_failpoint_helpers',
343+
'$BUILD_DIR/mongo/db/dbhelpers',
342344
'$BUILD_DIR/mongo/db/exec/stagedebug_cmd',
343345
'$BUILD_DIR/mongo/db/index_builds_coordinator_interface',
344346
'$BUILD_DIR/mongo/db/index_d',

src/mongo/db/storage/kv/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ env.Library(
6262
],
6363
LIBDEPS=[
6464
'$BUILD_DIR/mongo/base',
65-
'$BUILD_DIR/mongo/db/catalog/catalog_impl',
65+
'$BUILD_DIR/mongo/db/catalog/catalog_control',
6666
'$BUILD_DIR/mongo/db/storage/kv/kv_engine_core',
6767
'$BUILD_DIR/mongo/db/storage/storage_options',
6868
'kv_database_catalog_entry_core',

src/mongo/dbtests/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ env.Library(
2626
'framework_options_init.cpp',
2727
],
2828
LIBDEPS=[
29+
'$BUILD_DIR/mongo/db/catalog/catalog_impl',
2930
'$BUILD_DIR/mongo/db/dbdirectclient',
3031
'$BUILD_DIR/mongo/db/op_observer',
3132
'$BUILD_DIR/mongo/db/service_context_d',

0 commit comments

Comments
 (0)