diff options
29 files changed, 87 insertions, 144 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 6adb47124fd..c14c58d7eee 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -821,8 +821,7 @@ env.CppUnitTest('config_server_tests', [ 's/config_server_tests.cpp' ], env.CppUnitTest("fail_point_test", [ "util/fail_point_test.cpp" ], LIBDEPS=["fail_point"]) -serverOnlyFiles += [ "s/d_logic.cpp", - "s/d_migrate.cpp", +serverOnlyFiles += [ "s/d_migrate.cpp", "s/d_state.cpp", "s/d_split.cpp", "s/d_merge.cpp", diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index f1a503debbc..23a2b053c07 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -60,7 +60,7 @@ #include "mongo/db/repl/rs.h" #include "mongo/db/storage_options.h" #include "mongo/s/chunk_version.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/stale_exception.h" // for SendStaleConfigException #include "mongo/scripting/engine.h" #include "mongo/util/concurrency/thread_name.h" diff --git a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp index 3b6dfd490c9..83dbea1166b 100644 --- a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp +++ b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp @@ -45,7 +45,7 @@ #include "mongo/db/range_deleter_service.h" #include "mongo/db/repl/repl_coordinator_global.h" #include "mongo/s/collection_metadata.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/range_arithmetic.h" #include "mongo/s/type_settings.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index d7c3e05ccdc..58791dea990 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -42,7 +42,7 @@ #include "mongo/db/ops/insert.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/operation_context_impl.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/shard_key_pattern.h" namespace mongo { diff --git a/src/mongo/db/commands/merge_chunks_cmd.cpp b/src/mongo/db/commands/merge_chunks_cmd.cpp index faac3e57158..e14a5a40564 100644 --- a/src/mongo/db/commands/merge_chunks_cmd.cpp +++ b/src/mongo/db/commands/merge_chunks_cmd.cpp @@ -33,7 +33,7 @@ #include "mongo/db/commands.h" #include "mongo/db/field_parser.h" #include "mongo/db/namespace_string.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/d_merge.h" namespace mongo { diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index add4c69dd10..950df2d6d02 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -56,7 +56,7 @@ #include "mongo/db/storage_options.h" #include "mongo/scripting/engine.h" #include "mongo/s/collection_metadata.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/grid.h" #include "mongo/s/stale_exception.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index c1ba188d76e..34ef43b0872 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -58,7 +58,7 @@ #include "mongo/db/operation_context_impl.h" #include "mongo/db/write_concern.h" #include "mongo/s/collection_metadata.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/s/write_ops/batched_upsert_detail.h" #include "mongo/s/write_ops/write_error_detail.h" diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index aae0847312d..6c07ee0c21a 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -74,7 +74,7 @@ #include "mongo/db/storage/storage_engine.h" #include "mongo/db/storage/mmap_v1/dur_stats.h" #include "mongo/db/write_concern.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/stale_exception.h" // for SendStaleConfigException #include "mongo/scripting/engine.h" #include "mongo/server.h" diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index 959c4ca44ad..db184d1e7fd 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -57,7 +57,7 @@ #include "mongo/db/operation_context_impl.h" #include "mongo/db/storage_options.h" #include "mongo/db/catalog/collection.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/db/exec/idhack.cpp b/src/mongo/db/exec/idhack.cpp index 549bb8ce7f6..9f50743a64b 100644 --- a/src/mongo/db/exec/idhack.cpp +++ b/src/mongo/db/exec/idhack.cpp @@ -34,7 +34,7 @@ #include "mongo/db/exec/projection.h" #include "mongo/db/exec/working_set_computed_data.h" #include "mongo/db/index/btree_access_method.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" namespace mongo { diff --git a/src/mongo/db/exec/shard_filter.h b/src/mongo/db/exec/shard_filter.h index 2f40d149cd1..aecb31d92b8 100644 --- a/src/mongo/db/exec/shard_filter.h +++ b/src/mongo/db/exec/shard_filter.h @@ -32,7 +32,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/exec/plan_stage.h" #include "mongo/s/chunk_version.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/stale_exception.h" namespace mongo { diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 79af09b6dd1..f2a2470f0e1 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -74,7 +74,7 @@ #include "mongo/db/storage_options.h" #include "mongo/platform/atomic_word.h" #include "mongo/platform/process_id.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/stale_exception.h" // for SendStaleConfigException #include "mongo/scripting/engine.h" #include "mongo/util/exit.h" diff --git a/src/mongo/db/ops/update_lifecycle_impl.cpp b/src/mongo/db/ops/update_lifecycle_impl.cpp index 9a0c15e61fd..11a54b8ea2c 100644 --- a/src/mongo/db/ops/update_lifecycle_impl.cpp +++ b/src/mongo/db/ops/update_lifecycle_impl.cpp @@ -33,7 +33,7 @@ #include "mongo/db/field_ref.h" #include "mongo/db/catalog/collection.h" #include "mongo/s/chunk_version.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" namespace mongo { namespace { diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp index b173dafc407..bae0e53a680 100644 --- a/src/mongo/db/pipeline/document_source_cursor.cpp +++ b/src/mongo/db/pipeline/document_source_cursor.cpp @@ -37,7 +37,7 @@ #include "mongo/db/query/find_constants.h" #include "mongo/db/query/type_explain.h" #include "mongo/db/storage_options.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/stale_exception.h" // for SendStaleConfigException namespace mongo { diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp index 27dd0bb38c0..9f4d4c5b653 100644 --- a/src/mongo/db/pipeline/pipeline_d.cpp +++ b/src/mongo/db/pipeline/pipeline_d.cpp @@ -38,7 +38,7 @@ #include "mongo/db/pipeline/pipeline.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/query_planner.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" namespace mongo { diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index b2936c80e61..fc78b538c79 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -62,7 +62,7 @@ #include "mongo/db/index_names.h" #include "mongo/db/server_options.h" #include "mongo/db/server_parameters.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/db/query/new_find.cpp b/src/mongo/db/query/new_find.cpp index 507cbb0117a..6b7b8af08e1 100644 --- a/src/mongo/db/query/new_find.cpp +++ b/src/mongo/db/query/new_find.cpp @@ -51,7 +51,7 @@ #include "mongo/db/storage_options.h" #include "mongo/db/catalog/collection.h" #include "mongo/s/chunk_version.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/stale_exception.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" diff --git a/src/mongo/db/range_deleter_db_env.cpp b/src/mongo/db/range_deleter_db_env.cpp index e08431135ef..52d9ee3c9ec 100644 --- a/src/mongo/db/range_deleter_db_env.cpp +++ b/src/mongo/db/range_deleter_db_env.cpp @@ -40,7 +40,7 @@ #include "mongo/db/repl/repl_coordinator_global.h" #include "mongo/db/repl/rs.h" #include "mongo/db/write_concern_options.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 2a86ec23402..60f6f82d428 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -62,7 +62,7 @@ #include "mongo/db/storage_options.h" #include "mongo/db/storage/storage_engine.h" #include "mongo/db/catalog/collection.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/scripting/engine.h" #include "mongo/util/elapsed_tracker.h" #include "mongo/util/file.h" diff --git a/src/mongo/db/repl/repl_set_impl.cpp b/src/mongo/db/repl/repl_set_impl.cpp index 9325b72116e..8bd96bac732 100644 --- a/src/mongo/db/repl/repl_set_impl.cpp +++ b/src/mongo/db/repl/repl_set_impl.cpp @@ -48,7 +48,7 @@ #include "mongo/db/repl/repl_coordinator_hybrid.h" #include "mongo/db/repl/rslog.h" #include "mongo/db/storage/storage_engine.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/util/background.h" #include "mongo/util/exit.h" #include "mongo/util/log.h" diff --git a/src/mongo/dbtests/merge_chunk_tests.cpp b/src/mongo/dbtests/merge_chunk_tests.cpp index ceffaa9ff5f..aeab04a30d7 100644 --- a/src/mongo/dbtests/merge_chunk_tests.cpp +++ b/src/mongo/dbtests/merge_chunk_tests.cpp @@ -31,7 +31,7 @@ #include "mongo/s/chunk.h" // for genID #include "mongo/s/chunk_version.h" #include "mongo/s/collection_metadata.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/d_merge.h" #include "mongo/s/range_arithmetic.h" #include "mongo/s/type_collection.h" diff --git a/src/mongo/s/d_logic.cpp b/src/mongo/s/d_logic.cpp deleted file mode 100644 index 4e2f5b3e27a..00000000000 --- a/src/mongo/s/d_logic.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// @file d_logic.cpp - -/** -* Copyright (C) 2008 10gen 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. -*/ - - -/** - these are commands that live in mongod - mostly around shard management and checking - */ - -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding - -#include "mongo/platform/basic.h" - -#include "mongo/s/d_logic.h" - -#include <string> - -#include "mongo/db/client.h" -#include "mongo/db/dbmessage.h" -#include "mongo/db/jsobj.h" -#include "mongo/s/shard.h" -#include "mongo/util/log.h" - -using namespace std; - -namespace mongo { - - bool _checkShardVersion(Message &m, DbResponse* dbresponse) { - DEV verify( shardingState.enabled() ); - - int op = m.operation(); - if ( op < 2000 - || op >= 3000 - || op == dbGetMore // cursors are weird - ) - return true; - - DbMessage d(m); - const char *ns = d.getns(); - string errmsg; - ChunkVersion received, wanted; - if ( shardVersionOk( ns , errmsg, received, wanted ) ) { - return true; - } - - LOG(1) << "connection sharding metadata does not match for collection " << ns - << ", will retry (wanted : " << wanted - << ", received : " << received << ")" << endl; - - fassert(18664, op == dbQuery || op == dbGetMore); - - verify( dbresponse ); - BufBuilder b( 32768 ); - b.skip( sizeof( QueryResult::Value ) ); - { - BSONObjBuilder bob; - - bob.append( "$err", errmsg ); - bob.append( "ns", ns ); - wanted.addToBSON( bob, "vWanted" ); - received.addToBSON( bob, "vReceived" ); - - BSONObj obj = bob.obj(); - - b.appendBuf( obj.objdata() , obj.objsize() ); - } - - QueryResult::View qr = b.buf(); - qr.setResultFlags(ResultFlag_ErrSet | ResultFlag_ShardConfigStale); - qr.msgdata().setLen(b.len()); - qr.msgdata().setOperation( opReply ); - qr.setCursorId(0); - qr.setStartingFrom(0); - qr.setNReturned(1); - b.decouple(); - - Message * resp = new Message(); - resp->setData(qr.view2ptr(), true); - - dbresponse->response = resp; - dbresponse->responseTo = m.header().getId(); - return false; - } - -} diff --git a/src/mongo/s/d_merge.cpp b/src/mongo/s/d_merge.cpp index 861d932f5c3..a314f2161c7 100644 --- a/src/mongo/s/d_merge.cpp +++ b/src/mongo/s/d_merge.cpp @@ -30,7 +30,7 @@ #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/distlock.h" #include "mongo/s/chunk.h" // needed for genID #include "mongo/s/config.h" // needed for changelog write diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index 8d2c4c8404f..489c651e00f 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -75,7 +75,7 @@ #include "mongo/s/chunk.h" #include "mongo/s/chunk_version.h" #include "mongo/s/config.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/distlock.h" #include "mongo/s/shard.h" #include "mongo/s/type_chunk.h" diff --git a/src/mongo/s/d_split.cpp b/src/mongo/s/d_split.cpp index 06ccbd379ef..c6d8a6272ae 100644 --- a/src/mongo/s/d_split.cpp +++ b/src/mongo/s/d_split.cpp @@ -53,7 +53,7 @@ #include "mongo/s/chunk.h" // for static genID only #include "mongo/s/chunk_version.h" #include "mongo/s/config.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/distlock.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/s/type_chunk.h" diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp index 38a5cb74bdd..9e13f581681 100644 --- a/src/mongo/s/d_state.cpp +++ b/src/mongo/s/d_state.cpp @@ -56,7 +56,7 @@ #include "mongo/client/connpool.h" #include "mongo/s/chunk_version.h" #include "mongo/s/config.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/s/metadata_loader.h" #include "mongo/s/shard.h" #include "mongo/util/queue.h" @@ -1389,4 +1389,62 @@ namespace mongo { void usingAShardConnection( const string& addr ) { } + bool _checkShardVersion(Message &message, DbResponse* dbresponse) { + DEV verify( shardingState.enabled() ); + + int op = message.operation(); + if (op < 2000 + || op >= 3000 + || op == dbGetMore // cursors are weird + ) { + return true; + } + + DbMessage dbMsg(message); + const char *ns = dbMsg.getns(); + string errmsg; + ChunkVersion received, wanted; + if (shardVersionOk(ns, errmsg, received, wanted)) { + return true; + } + + LOG(1) << "connection sharding metadata does not match for collection " << ns + << ", will retry (wanted : " << wanted + << ", received : " << received << ")" << endl; + + // Handling of version mismatch on legacy writeOps are no long supported. + fassert(18664, op == dbQuery || op == dbGetMore); + + verify(dbresponse); + BufBuilder responseBuilder(32768); + responseBuilder.skip(sizeof(QueryResult::Value)); + { + BSONObjBuilder errorObjBuilder; + + errorObjBuilder.append("$err", errmsg); + errorObjBuilder.append("ns", ns); + wanted.addToBSON(errorObjBuilder, "vWanted"); + received.addToBSON(errorObjBuilder, "vReceived"); + + BSONObj obj = errorObjBuilder.obj(); + + responseBuilder.appendBuf(obj.objdata(), obj.objsize()); + } + + QueryResult::View qr = responseBuilder.buf(); + qr.setResultFlags(ResultFlag_ErrSet | ResultFlag_ShardConfigStale); + qr.msgdata().setLen(responseBuilder.len()); + qr.msgdata().setOperation(opReply); + qr.setCursorId(0); + qr.setStartingFrom(0); + qr.setNReturned(1); + responseBuilder.decouple(); + + Message* resp = new Message(); + resp->setData(qr.view2ptr(), true); + + dbresponse->response = resp; + dbresponse->responseTo = message.header().getId(); + return false; + } } diff --git a/src/mongo/s/d_logic.h b/src/mongo/s/d_state.h index 2c226d262f1..2cdafc45f75 100644 --- a/src/mongo/s/d_logic.h +++ b/src/mongo/s/d_state.h @@ -1,4 +1,3 @@ -// @file d_logic.h /* * Copyright (C) 2010 10gen Inc. * @@ -352,9 +351,6 @@ namespace mongo { // --- core --- // ----------------- - unsigned long long extractVersion( BSONElement e , std::string& errmsg ); - - /** * @return true if we have any shard info for the ns */ @@ -384,6 +380,8 @@ namespace mongo { /** * Returns true if the version of this thread is compatible with the global * version of this shard. + * + * Note: Last use of this function are for queries. */ inline bool checkShardVersion(Message &m, DbResponse* dbresponse) { if( !shardingState.enabled() ) diff --git a/src/mongo/scripting/v8-3.25_db.cpp b/src/mongo/scripting/v8-3.25_db.cpp index ba53950633a..2900893ce3a 100644 --- a/src/mongo/scripting/v8-3.25_db.cpp +++ b/src/mongo/scripting/v8-3.25_db.cpp @@ -37,7 +37,7 @@ #include "mongo/client/sasl_client_authenticate.h" #include "mongo/client/syncclusterconnection.h" #include "mongo/db/namespace_string.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/scripting/engine_v8-3.25.h" #include "mongo/scripting/v8-3.25_utils.h" #include "mongo/util/assert_util.h" diff --git a/src/mongo/scripting/v8_db.cpp b/src/mongo/scripting/v8_db.cpp index a81275b6c60..c6b94282bff 100644 --- a/src/mongo/scripting/v8_db.cpp +++ b/src/mongo/scripting/v8_db.cpp @@ -37,7 +37,7 @@ #include "mongo/client/sasl_client_authenticate.h" #include "mongo/client/syncclusterconnection.h" #include "mongo/db/namespace_string.h" -#include "mongo/s/d_logic.h" +#include "mongo/s/d_state.h" #include "mongo/scripting/engine_v8.h" #include "mongo/scripting/v8_utils.h" #include "mongo/util/assert_util.h" |