summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/sharding/fair_balancer_round.js12
-rw-r--r--src/mongo/db/commands/cleanup_orphaned_cmd.cpp1
-rw-r--r--src/mongo/dbtests/config_upgrade_tests.cpp2
-rw-r--r--src/mongo/s/SConscript5
-rw-r--r--src/mongo/s/balance.cpp25
-rw-r--r--src/mongo/s/balancing_window_test.cpp2
-rw-r--r--src/mongo/s/catalog/SConscript2
-rw-r--r--src/mongo/s/catalog/catalog_manager.h11
-rw-r--r--src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp27
-rw-r--r--src/mongo/s/catalog/legacy/catalog_manager_legacy.h2
-rw-r--r--src/mongo/s/catalog/legacy/config_upgrade.cpp2
-rw-r--r--src/mongo/s/catalog/type_settings.cpp (renamed from src/mongo/s/type_settings.cpp)2
-rw-r--r--src/mongo/s/catalog/type_settings.h (renamed from src/mongo/s/type_settings.h)1
-rw-r--r--src/mongo/s/catalog/type_settings_test.cpp (renamed from src/mongo/s/type_settings_test.cpp)2
-rw-r--r--src/mongo/s/chunk.cpp23
-rw-r--r--src/mongo/s/config.cpp2
-rw-r--r--src/mongo/s/grid.cpp46
-rw-r--r--src/mongo/s/grid.h17
18 files changed, 83 insertions, 101 deletions
diff --git a/jstests/sharding/fair_balancer_round.js b/jstests/sharding/fair_balancer_round.js
index d78f4ca2efd..a565b469667 100644
--- a/jstests/sharding/fair_balancer_round.js
+++ b/jstests/sharding/fair_balancer_round.js
@@ -9,13 +9,10 @@ var st = new ShardingTest({shards : 2, mongos : 2, other : options});
// Stop balancer initially
st.stopBalancer();
-var mongos = st.s0;
-var staleMongos = st.s1;
+var staleMongos = st.s0;
+var mongos = st.s1;
var coll = mongos.getCollection("foo.bar");
-// Stop first mongos from balancing
-assert(mongos.adminCommand({configureFailPoint : "neverBalance", mode : "alwaysOn"}).ok);
-
// Shard collection through first mongos
assert(mongos.adminCommand({enableSharding : coll.getDB() + ""}).ok);
assert(mongos.adminCommand({shardCollection : coll + "", key : {_id : 1}}).ok);
@@ -26,12 +23,15 @@ for ( var i = 0; i < numSplits; i++) {
assert(mongos.adminCommand({split : coll + "", middle : {_id : i}}).ok);
}
+// stop st.s1
+st.stopMongos(1);
+
// Start balancer, which lets the stale mongos balance
st.startBalancer();
// Make sure we eventually start moving chunks
assert.soon(function() {
- return mongos.getCollection("config.changelog").count({what : /moveChunk/}) > 0;
+ return staleMongos.getCollection("config.changelog").count({what : /moveChunk/}) > 0;
}, "no balance happened", 5 * 60 * 1000);
jsTest.log("DONE!");
diff --git a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp
index 876297e2d56..89f57103958 100644
--- a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp
+++ b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp
@@ -47,7 +47,6 @@
#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/s/collection_metadata.h"
#include "mongo/s/d_state.h"
-#include "mongo/s/type_settings.h"
#include "mongo/util/log.h"
namespace {
diff --git a/src/mongo/dbtests/config_upgrade_tests.cpp b/src/mongo/dbtests/config_upgrade_tests.cpp
index b500c082dbe..17ad4a25331 100644
--- a/src/mongo/dbtests/config_upgrade_tests.cpp
+++ b/src/mongo/dbtests/config_upgrade_tests.cpp
@@ -30,10 +30,10 @@
#include "mongo/s/catalog/legacy/cluster_client_internal.h"
#include "mongo/s/catalog/legacy/config_upgrade.h"
#include "mongo/s/catalog/type_chunk.h"
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/type_mongos.h"
-#include "mongo/s/type_settings.h"
#include "mongo/s/type_config_version.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/version.h"
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 06018a72e22..74bd0e54fc7 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -10,7 +10,6 @@ env.Library('base', ['mongo_version_range.cpp',
'type_database.cpp',
'type_locks.cpp',
'type_lockpings.cpp',
- 'type_settings.cpp',
'type_config_version.cpp',
'type_mongos.cpp',
'type_tags.cpp'],
@@ -42,10 +41,6 @@ env.CppUnitTest('type_lockpings_test', 'type_lockpings_test.cpp',
LIBDEPS=['base',
'$BUILD_DIR/mongo/db/common'])
-env.CppUnitTest('type_settings_test', 'type_settings_test.cpp',
- LIBDEPS=['base',
- '$BUILD_DIR/mongo/db/common'])
-
env.CppUnitTest('type_mongos_test', 'type_mongos_test.cpp',
LIBDEPS=['base',
'$BUILD_DIR/mongo/db/common'])
diff --git a/src/mongo/s/balance.cpp b/src/mongo/s/balance.cpp
index f4970f872bd..8e384939c25 100644
--- a/src/mongo/s/balance.cpp
+++ b/src/mongo/s/balance.cpp
@@ -46,6 +46,7 @@
#include "mongo/s/catalog/type_actionlog.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog/type_collection.h"
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/config.h"
#include "mongo/s/config_server_checker_service.h"
@@ -54,7 +55,6 @@
#include "mongo/s/server.h"
#include "mongo/s/client/shard.h"
#include "mongo/s/type_mongos.h"
-#include "mongo/s/type_settings.h"
#include "mongo/s/type_tags.h"
#include "mongo/util/exit.h"
#include "mongo/util/fail_point_service.h"
@@ -97,14 +97,13 @@ namespace mongo {
// If the balancer was disabled since we started this round, don't start new
// chunks moves.
- SettingsType balancerConfig;
- std::string errMsg;
-
- if (!grid.getBalancerSettings(&balancerConfig, &errMsg)) {
- warning() << errMsg;
- // No point in continuing the round if the config servers are unreachable.
+ auto balSettingsResult =
+ grid.catalogManager()->getGlobalSettings(SettingsType::BalancerDocKey);
+ if (!balSettingsResult.isOK()) {
+ warning() << balSettingsResult.getStatus();
return movedCount;
}
+ const SettingsType& balancerConfig = balSettingsResult.getValue();
if ((balancerConfig.isKeySet() && // balancer config doc exists
!grid.shouldBalance(balancerConfig)) ||
@@ -538,13 +537,13 @@ namespace mongo {
// refresh chunk size (even though another balancer might be active)
Chunk::refreshChunkSize();
- SettingsType balancerConfig;
- string errMsg;
-
- if (!grid.getBalancerSettings(&balancerConfig, &errMsg)) {
- warning() << errMsg;
- return ;
+ auto balSettingsResult =
+ grid.catalogManager()->getGlobalSettings(SettingsType::BalancerDocKey);
+ if (!balSettingsResult.isOK()) {
+ warning() << balSettingsResult.getStatus();
+ return;
}
+ const SettingsType& balancerConfig = balSettingsResult.getValue();
// now make sure we should even be running
if ((balancerConfig.isKeySet() && // balancer config doc exists
diff --git a/src/mongo/s/balancing_window_test.cpp b/src/mongo/s/balancing_window_test.cpp
index c24fe283318..f2390a6527a 100644
--- a/src/mongo/s/balancing_window_test.cpp
+++ b/src/mongo/s/balancing_window_test.cpp
@@ -27,8 +27,8 @@
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/s/grid.h"
-#include "mongo/s/type_settings.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
diff --git a/src/mongo/s/catalog/SConscript b/src/mongo/s/catalog/SConscript
index c0b21710cef..f8ae4049b1b 100644
--- a/src/mongo/s/catalog/SConscript
+++ b/src/mongo/s/catalog/SConscript
@@ -9,6 +9,7 @@ env.Library(
'type_changelog.cpp',
'type_chunk.cpp',
'type_collection.cpp',
+ 'type_settings.cpp',
'type_shard.cpp'
],
LIBDEPS=[
@@ -39,6 +40,7 @@ env.CppUnitTest(
'type_changelog_test.cpp',
'type_chunk_test.cpp',
'type_collection_test.cpp',
+ 'type_settings_test.cpp',
'type_shard_test.cpp'
],
LIBDEPS=[
diff --git a/src/mongo/s/catalog/catalog_manager.h b/src/mongo/s/catalog/catalog_manager.h
index 291f174ba16..b6af95df830 100644
--- a/src/mongo/s/catalog/catalog_manager.h
+++ b/src/mongo/s/catalog/catalog_manager.h
@@ -46,6 +46,7 @@ namespace mongo {
class ConnectionString;
class DatabaseType;
class OperationContext;
+ class SettingsType;
class Shard;
class ShardKeyPattern;
class ShardType;
@@ -267,6 +268,16 @@ namespace mongo {
const BSONObj& detail) = 0;
/**
+ * Returns global settings for a certain key.
+ * @param key: key for SettingsType::ConfigNS document.
+ *
+ * NOTE: If no document with such a key exists, an empty SettingsType object will
+ * will be returned. It is up to the caller to check if the SettingsType
+ * is non-empty (via the keySet() method on the SettingsType).
+ */
+ virtual StatusWith<SettingsType> getGlobalSettings(const std::string& key) = 0;
+
+ /**
* Directly sends the specified command to the config server and returns the response.
*
* NOTE: Usage of this function is disallowed in new code, which should instead go through
diff --git a/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp b/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp
index bb9cc4007ae..d296ff151ba 100644
--- a/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp
+++ b/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp
@@ -50,6 +50,7 @@
#include "mongo/s/catalog/type_changelog.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog/type_collection.h"
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/client/dbclient_multi_command.h"
@@ -1048,6 +1049,32 @@ namespace {
}
}
+ StatusWith<SettingsType> CatalogManagerLegacy::getGlobalSettings(const string& key) {
+ SettingsType settingsType;
+
+ try {
+ ScopedDbConnection conn(_configServerConnectionString, 30);
+ BSONObj settingsDoc = conn->findOne(SettingsType::ConfigNS,
+ BSON(SettingsType::key(key)));
+
+ string errMsg;
+ if (!settingsType.parseBSON(settingsDoc, &errMsg)) {
+ conn.done();
+ return Status(ErrorCodes::UnsupportedFormat,
+ str::stream() << "error parsing config.settings document: "
+ << errMsg);
+ }
+ conn.done();
+ }
+ catch (const DBException& ex) {
+ return Status(ErrorCodes::OperationFailed,
+ str::stream() << "unable to successfully obtain config.settings document: "
+ << causedBy(ex));
+ }
+
+ return settingsType;
+ }
+
void CatalogManagerLegacy::getDatabasesForShard(const string& shardName,
vector<string>* dbs) {
ScopedDbConnection conn(_configServerConnectionString, 30.0);
diff --git a/src/mongo/s/catalog/legacy/catalog_manager_legacy.h b/src/mongo/s/catalog/legacy/catalog_manager_legacy.h
index f0ff435e606..8f334d8b7e0 100644
--- a/src/mongo/s/catalog/legacy/catalog_manager_legacy.h
+++ b/src/mongo/s/catalog/legacy/catalog_manager_legacy.h
@@ -103,6 +103,8 @@ namespace mongo {
const std::string& ns,
const BSONObj& detail);
+ virtual StatusWith<SettingsType> getGlobalSettings(const std::string& key);
+
virtual void writeConfigServerDirect(const BatchedCommandRequest& request,
BatchedCommandResponse* response);
diff --git a/src/mongo/s/catalog/legacy/config_upgrade.cpp b/src/mongo/s/catalog/legacy/config_upgrade.cpp
index 6ce128d2764..3fa62946e42 100644
--- a/src/mongo/s/catalog/legacy/config_upgrade.cpp
+++ b/src/mongo/s/catalog/legacy/config_upgrade.cpp
@@ -37,13 +37,13 @@
#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/catalog/legacy/cluster_client_internal.h"
#include "mongo/s/catalog/type_collection.h"
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/distlock.h"
#include "mongo/s/grid.h"
#include "mongo/s/mongo_version_range.h"
#include "mongo/s/type_config_version.h"
#include "mongo/s/type_database.h"
-#include "mongo/s/type_settings.h"
#include "mongo/stdx/functional.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
diff --git a/src/mongo/s/type_settings.cpp b/src/mongo/s/catalog/type_settings.cpp
index dc6f0deca50..1544c9ce056 100644
--- a/src/mongo/s/type_settings.cpp
+++ b/src/mongo/s/catalog/type_settings.cpp
@@ -25,7 +25,7 @@
* delete this exception statement from all source files in the program,
* then also delete it in the license file.
*/
-#include "mongo/s/type_settings.h"
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/db/field_parser.h"
#include "mongo/db/write_concern_options.h"
diff --git a/src/mongo/s/type_settings.h b/src/mongo/s/catalog/type_settings.h
index 9d6cbe26b5b..11bd68c584e 100644
--- a/src/mongo/s/type_settings.h
+++ b/src/mongo/s/catalog/type_settings.h
@@ -65,7 +65,6 @@ namespace mongo {
* balancer settings or chunk size settings document).
*/
class SettingsType {
- MONGO_DISALLOW_COPYING(SettingsType);
public:
//
diff --git a/src/mongo/s/type_settings_test.cpp b/src/mongo/s/catalog/type_settings_test.cpp
index 651c53d056c..ca8755b6baf 100644
--- a/src/mongo/s/type_settings_test.cpp
+++ b/src/mongo/s/catalog/type_settings_test.cpp
@@ -26,7 +26,7 @@
* then also delete it in the license file.
*/
-#include "mongo/s/type_settings.h"
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/unittest/unittest.h"
namespace {
diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp
index dcdd528a548..b62a0da7512 100644
--- a/src/mongo/s/chunk.cpp
+++ b/src/mongo/s/chunk.cpp
@@ -46,12 +46,12 @@
#include "mongo/s/balancer_policy.h"
#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/catalog/type_collection.h"
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/config.h"
#include "mongo/s/config_server_checker_service.h"
#include "mongo/s/cursors.h"
#include "mongo/s/grid.h"
-#include "mongo/s/type_settings.h"
#include "mongo/util/concurrency/ticketholder.h"
#include "mongo/util/log.h"
@@ -730,20 +730,19 @@ namespace {
}
void Chunk::refreshChunkSize() {
- BSONObj o = grid.getConfigSetting("chunksize");
-
- if ( o.isEmpty() ) {
- return;
+ auto chunkSizeSettingsResult =
+ grid.catalogManager()->getGlobalSettings(SettingsType::ChunkSizeDocKey);
+ if (!chunkSizeSettingsResult.isOK()) {
+ log() << chunkSizeSettingsResult.getStatus();
+ return;
}
-
- int csize = o[SettingsType::chunksize()].numberInt();
-
- // validate chunksize before proceeding
- if ( csize == 0 ) {
- // setting was not modified; mark as such
- log() << "warning: invalid chunksize (" << csize << ") ignored";
+ SettingsType chunkSizeSettings = chunkSizeSettingsResult.getValue();
+ string errMsg;
+ if (!chunkSizeSettings.isValid(&errMsg)) {
+ log() << errMsg;
return;
}
+ int csize = chunkSizeSettings.getChunksize();
LOG(1) << "Refreshing MaxChunkSize: " << csize << "MB";
diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp
index f8e08ba12fa..e8dd8e60d44 100644
--- a/src/mongo/s/config.cpp
+++ b/src/mongo/s/config.cpp
@@ -45,6 +45,7 @@
#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog/type_chunk.h"
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/chunk_version.h"
@@ -55,7 +56,6 @@
#include "mongo/s/type_database.h"
#include "mongo/s/type_locks.h"
#include "mongo/s/type_lockpings.h"
-#include "mongo/s/type_settings.h"
#include "mongo/s/type_tags.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp
index 5cce580cc76..a9860fda1fa 100644
--- a/src/mongo/s/grid.cpp
+++ b/src/mongo/s/grid.cpp
@@ -36,9 +36,9 @@
#include "mongo/client/connpool.h"
#include "mongo/s/catalog/catalog_cache.h"
#include "mongo/s/catalog/catalog_manager.h"
+#include "mongo/s/catalog/type_settings.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/config.h"
-#include "mongo/s/type_settings.h"
#include "mongo/util/fail_point_service.h"
#include "mongo/util/log.h"
@@ -51,9 +51,6 @@ namespace mongo {
using std::string;
using std::vector;
- MONGO_FP_DECLARE(neverBalance);
-
-
Grid::Grid() : _allowLocalShard(true) {
}
@@ -96,11 +93,7 @@ namespace mongo {
* Returns whether balancing is enabled, with optional namespace "ns" parameter for balancing on a particular
* collection.
*/
-
bool Grid::shouldBalance(const SettingsType& balancerSettings) const {
- // Allow disabling the balancer for testing
- if (MONGO_FAIL_POINT(neverBalance)) return false;
-
if (balancerSettings.isBalancerStoppedSet() && balancerSettings.getBalancerStopped()) {
return false;
}
@@ -113,32 +106,14 @@ namespace mongo {
return true;
}
- bool Grid::getBalancerSettings(SettingsType* settings, string* errMsg) const {
- BSONObj balancerDoc;
- ScopedDbConnection conn(configServer.getPrimary().getConnString(), 30);
-
- try {
- balancerDoc = conn->findOne(SettingsType::ConfigNS,
- BSON(SettingsType::key("balancer")));
- conn.done();
- }
- catch (const DBException& ex) {
- *errMsg = str::stream() << "failed to read balancer settings from " << conn.getHost()
- << ": " << causedBy(ex);
- return false;
- }
-
- return settings->parseBSON(balancerDoc, errMsg);
- }
-
bool Grid::getConfigShouldBalance() const {
- SettingsType balSettings;
- string errMsg;
-
- if (!getBalancerSettings(&balSettings, &errMsg)) {
- warning() << errMsg;
+ auto balSettingsResult =
+ grid.catalogManager()->getGlobalSettings(SettingsType::BalancerDocKey);
+ if (!balSettingsResult.isOK()) {
+ warning() << balSettingsResult.getStatus();
return false;
}
+ SettingsType balSettings = balSettingsResult.getValue();
if (!balSettings.isKeySet()) {
// Balancer settings doc does not exist. Default to yes.
@@ -198,14 +173,5 @@ namespace mongo {
return false;
}
- BSONObj Grid::getConfigSetting( const std::string& name ) const {
- ScopedDbConnection conn(configServer.getPrimary().getConnString(), 30);
- BSONObj result = conn->findOne( SettingsType::ConfigNS,
- BSON( SettingsType::key(name) ) );
- conn.done();
-
- return result;
- }
-
Grid grid;
}
diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h
index 21b4be76fc9..d70db0ac01d 100644
--- a/src/mongo/s/grid.h
+++ b/src/mongo/s/grid.h
@@ -81,14 +81,6 @@ namespace mongo {
bool shouldBalance(const SettingsType& balancerSettings) const;
/**
- * Retrieve the balancer settings from the config server. Returns false if an error
- * occurred while retrieving the document. If the balancer settings document does not
- * exist, it is not considered as an error, but the "key" property of the settings
- * output parameter will not be set.
- */
- bool getBalancerSettings(SettingsType* settings, std::string* errMsg) const;
-
- /**
* Returns true if the config server settings indicate that the balancer should be active.
*/
bool getConfigShouldBalance() const;
@@ -96,15 +88,6 @@ namespace mongo {
CatalogManager* catalogManager() const { return _catalogManager.get(); }
CatalogCache* catalogCache() const { return _catalogCache.get(); }
- /**
- *
- * Obtain grid configuration and settings data.
- *
- * @param name identifies a particular type of configuration data.
- * @return a BSON object containing the requested data.
- */
- BSONObj getConfigSetting( const std::string& name ) const;
-
// exposed methods below are for testing only
/**