summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2016-12-02 15:39:00 -0500
committerDavid Storch <david.storch@10gen.com>2016-12-21 12:27:49 -0500
commit2cfb3e0bdc46deb7ad4546cce529b6084cc9d922 (patch)
tree4d6f7c29399664202de3120a50790b5cab203b8f
parent1ab87806b9ad157bb205403f2c7e0226988af64f (diff)
downloadmongo-2cfb3e0bdc46deb7ad4546cce529b6084cc9d922.tar.gz
SERVER-27304 add internalQueryAlwaysMergeOnPrimaryShard setParameter
When set to true on a mongos, aggregation queries routed to that mongos which require a merging shard will always select the primary shard as the merger. Set to false by default, which means that the merging shard is chosen at random amongst nodes participating in answering the aggregation query. (cherry picked from commit 3f54fef03fdd7bd787a57387b84d298c9dd0222d) Conflicts: src/mongo/s/commands/cluster_aggregate.cpp
-rw-r--r--src/mongo/s/commands/cluster_pipeline_cmd.cpp4
-rw-r--r--src/mongo/s/query/SConscript1
-rw-r--r--src/mongo/s/query/cluster_query_knobs.cpp39
-rw-r--r--src/mongo/s/query/cluster_query_knobs.h40
4 files changed, 83 insertions, 1 deletions
diff --git a/src/mongo/s/commands/cluster_pipeline_cmd.cpp b/src/mongo/s/commands/cluster_pipeline_cmd.cpp
index 48544a41c3d..16ef0b05a55 100644
--- a/src/mongo/s/commands/cluster_pipeline_cmd.cpp
+++ b/src/mongo/s/commands/cluster_pipeline_cmd.cpp
@@ -51,6 +51,7 @@
#include "mongo/s/commands/cluster_commands_common.h"
#include "mongo/s/config.h"
#include "mongo/s/grid.h"
+#include "mongo/s/query/cluster_query_knobs.h"
#include "mongo/s/query/store_possible_cursor.h"
#include "mongo/s/stale_exception.h"
#include "mongo/util/log.h"
@@ -237,7 +238,8 @@ public:
// Run merging command on random shard, unless a stage needs the primary shard. Need to use
// ShardConnection so that the merging mongod is sent the config servers on connection init.
auto& prng = txn->getClient()->getPrng();
- const auto& mergingShardId = needPrimaryShardMerger
+ const auto& mergingShardId =
+ (needPrimaryShardMerger || internalQueryAlwaysMergeOnPrimaryShard)
? conf->getPrimaryId()
: shardResults[prng.nextInt32(shardResults.size())].shardTargetId;
const auto mergingShard = grid.shardRegistry()->getShard(txn, mergingShardId);
diff --git a/src/mongo/s/query/SConscript b/src/mongo/s/query/SConscript
index 18022507aa2..fd27f991f01 100644
--- a/src/mongo/s/query/SConscript
+++ b/src/mongo/s/query/SConscript
@@ -6,6 +6,7 @@ env.Library(
target="cluster_query",
source=[
"cluster_find.cpp",
+ "cluster_query_knobs.cpp",
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/commands',
diff --git a/src/mongo/s/query/cluster_query_knobs.cpp b/src/mongo/s/query/cluster_query_knobs.cpp
new file mode 100644
index 00000000000..76e82b4f914
--- /dev/null
+++ b/src/mongo/s/query/cluster_query_knobs.cpp
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2016 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/s/query/cluster_query_knobs.h"
+
+#include "mongo/db/server_parameters.h"
+
+namespace mongo {
+
+MONGO_EXPORT_SERVER_PARAMETER(internalQueryAlwaysMergeOnPrimaryShard, bool, false);
+
+} // namespace mongo
diff --git a/src/mongo/s/query/cluster_query_knobs.h b/src/mongo/s/query/cluster_query_knobs.h
new file mode 100644
index 00000000000..76df18fde4d
--- /dev/null
+++ b/src/mongo/s/query/cluster_query_knobs.h
@@ -0,0 +1,40 @@
+/**
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#include <atomic>
+
+namespace mongo {
+
+// If set to true on mongos, all aggregations delivered to the mongos which require a merging shard
+// will select the primary shard as the merger. False by default, which means that the merging shard
+// will be selected randomly amongst the shards participating in the query.
+extern std::atomic<bool> internalQueryAlwaysMergeOnPrimaryShard; // NOLINT
+
+} // namespace mongo