diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2018-04-05 13:50:28 -0400 |
---|---|---|
committer | Henrik Edin <henrik.edin@mongodb.com> | 2018-04-09 16:03:07 -0400 |
commit | 1b7dff4b1c26efeb5bf6f9840e44978b098bf86c (patch) | |
tree | 75525b8927ef7de7daa12b042ad54544d165753f /src/mongo/client/embedded | |
parent | f865d1064012f1c703b4329cab82a40196c4836b (diff) | |
download | mongo-1b7dff4b1c26efeb5bf6f9840e44978b098bf86c.tar.gz |
SERVER-33457 Index creation in background not allowed in embedded.
Diffstat (limited to 'src/mongo/client/embedded')
-rw-r--r-- | src/mongo/client/embedded/SConscript | 11 | ||||
-rw-r--r-- | src/mongo/client/embedded/index_create_impl_embedded.cpp | 57 | ||||
-rw-r--r-- | src/mongo/client/embedded/libmongodbcapi_test.cpp | 30 |
3 files changed, 97 insertions, 1 deletions
diff --git a/src/mongo/client/embedded/SConscript b/src/mongo/client/embedded/SConscript index 1c36d56f557..369ff49dcb0 100644 --- a/src/mongo/client/embedded/SConscript +++ b/src/mongo/client/embedded/SConscript @@ -85,6 +85,16 @@ env.Library( ) env.Library( + target='index_create_impl_embedded', + source=[ + 'index_create_impl_embedded.cpp', + ], + LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/db/catalog/catalog_impl', + ], +) + +env.Library( target='embedded', source=[ 'embedded.cpp', @@ -104,6 +114,7 @@ env.Library( '$BUILD_DIR/mongo/util/version_impl', 'embedded_commands', 'embedded_options', + 'index_create_impl_embedded', 'repl_coordinator_embedded', 'service_context_embedded', 'service_entry_point_embedded', diff --git a/src/mongo/client/embedded/index_create_impl_embedded.cpp b/src/mongo/client/embedded/index_create_impl_embedded.cpp new file mode 100644 index 00000000000..de56784d039 --- /dev/null +++ b/src/mongo/client/embedded/index_create_impl_embedded.cpp @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2018 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/base/init.h" +#include "mongo/db/catalog/index_create_impl.h" + +namespace mongo { +namespace { + +class MultiIndexBlockImplEmbedded : public MultiIndexBlockImpl { + using MultiIndexBlockImpl::MultiIndexBlockImpl; + + bool initBackgroundIndexFromSpec(const BSONObj& spec) const override { + uassert(ErrorCodes::IllegalOperation, + "Background index building not supported on embedded"_sd, + !spec["background"].trueValue()); + return false; + } +}; + +MONGO_INITIALIZER(InitializeMultiIndexBlockFactory)(InitializerContext* const) { + MultiIndexBlock::registerFactory( + [](OperationContext* const opCtx, Collection* const collection) { + return stdx::make_unique<MultiIndexBlockImplEmbedded>(opCtx, collection); + }); + return Status::OK(); +} + +} // namespace +} // namespace mongo diff --git a/src/mongo/client/embedded/libmongodbcapi_test.cpp b/src/mongo/client/embedded/libmongodbcapi_test.cpp index 918778ff7c8..8a388b2f757 100644 --- a/src/mongo/client/embedded/libmongodbcapi_test.cpp +++ b/src/mongo/client/embedded/libmongodbcapi_test.cpp @@ -191,12 +191,40 @@ TEST_F(MongodbCAPITest, CreateIndex) { } ] })raw_delimiter"); - auto inputOpMsg = mongo::OpMsgRequest::fromDBAndBody("todo", inputObj); + auto inputOpMsg = mongo::OpMsgRequest::fromDBAndBody("index_db", inputObj); auto output = performRpc(client, inputOpMsg); + ASSERT(output.hasField("ok")); + ASSERT(output.getField("ok").numberDouble() == 1.0); ASSERT(output.getIntField("numIndexesAfter") == output.getIntField("numIndexesBefore") + 1); } +TEST_F(MongodbCAPITest, CreateBackgroundIndex) { + // create the client object + auto client = createClient(); + + // craft the createIndexes message + mongo::BSONObj inputObj = mongo::fromjson( + R"raw_delimiter({ + createIndexes: 'items', + indexes: + [ + { + key: { + task: 1 + }, + name: 'task_1', + background: true + } + ] + })raw_delimiter"); + auto inputOpMsg = mongo::OpMsgRequest::fromDBAndBody("background_index_db", inputObj); + auto output = performRpc(client, inputOpMsg); + + ASSERT(output.hasField("ok")); + ASSERT(output.getField("ok").numberDouble() != 1.0); +} + TEST_F(MongodbCAPITest, TrimMemory) { // create the client object auto client = createClient(); |