summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2014-07-15 16:13:31 -0400
committerRandolph Tan <randolph@10gen.com>2014-07-15 16:13:50 -0400
commit37f2a1e3b724dbd9e1f8eafd4ac87c5bf613c048 (patch)
tree2bcd919c93803f294d562761c2920fc9dd712bcd /src/mongo
parentd60fd22dec1c0bd104622eab463cdbba18bf11a9 (diff)
downloadmongo-37f2a1e3b724dbd9e1f8eafd4ac87c5bf613c048.tar.gz
Revert "SERVER-14041 enhance secondaryThrottle parameter"
This reverts commit fa1233fbe4a48ef0675820f381987f1df4f42f75.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/base/error_codes.err2
-rw-r--r--src/mongo/db/commands/cleanup_orphaned_cmd.cpp59
-rw-r--r--src/mongo/db/dbhelpers.cpp12
-rw-r--r--src/mongo/db/dbhelpers.h5
-rw-r--r--src/mongo/db/field_parser.cpp2
-rw-r--r--src/mongo/db/range_deleter.cpp27
-rw-r--r--src/mongo/db/range_deleter.h9
-rw-r--r--src/mongo/db/range_deleter_db_env.cpp6
-rw-r--r--src/mongo/db/range_deleter_test.cpp101
-rw-r--r--src/mongo/db/repl/repl_coordinator.h11
-rw-r--r--src/mongo/db/repl/repl_coordinator_hybrid.cpp7
-rw-r--r--src/mongo/db/repl/repl_coordinator_hybrid.h3
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl.cpp7
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl.h3
-rw-r--r--src/mongo/db/repl/repl_coordinator_legacy.cpp14
-rw-r--r--src/mongo/db/repl/repl_coordinator_legacy.h3
-rw-r--r--src/mongo/db/repl/repl_coordinator_mock.cpp6
-rw-r--r--src/mongo/db/repl/repl_coordinator_mock.h3
-rw-r--r--src/mongo/db/write_concern_options.cpp103
-rw-r--r--src/mongo/db/write_concern_options.h47
-rw-r--r--src/mongo/dbtests/dbhelper_tests.cpp4
-rw-r--r--src/mongo/s/balance.cpp40
-rw-r--r--src/mongo/s/balance.h6
-rw-r--r--src/mongo/s/chunk.cpp67
-rw-r--r--src/mongo/s/chunk.h5
-rw-r--r--src/mongo/s/commands_admin.cpp19
-rw-r--r--src/mongo/s/d_migrate.cpp200
-rw-r--r--src/mongo/s/grid.cpp72
-rw-r--r--src/mongo/s/grid.h30
-rw-r--r--src/mongo/s/type_settings.cpp82
-rw-r--r--src/mongo/s/type_settings.h72
-rw-r--r--src/mongo/s/type_settings_test.cpp31
32 files changed, 224 insertions, 834 deletions
diff --git a/src/mongo/base/error_codes.err b/src/mongo/base/error_codes.err
index 95076f74414..2415fee1c91 100644
--- a/src/mongo/base/error_codes.err
+++ b/src/mongo/base/error_codes.err
@@ -98,8 +98,6 @@ error_code("NotSecondary", 95)
error_code("OperationFailed", 96)
error_code("NoProjectionFound", 97)
error_code("DBPathInUse", 98)
-error_code("WriteConcernNotDefined", 99)
-error_code("CannotSatisfyWriteConcern", 100)
# Non-sequential error codes (for compatibility only)
error_code("NotMaster", 10107) #this comes from assert_util.h
diff --git a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp
index 3fd6dbcb9d2..89e7f49ab4b 100644
--- a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp
+++ b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp
@@ -41,22 +41,11 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/namespace_string.h"
#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/range_arithmetic.h"
-#include "mongo/s/type_settings.h"
#include "mongo/util/log.h"
-namespace {
- using mongo::WriteConcernOptions;
-
- const int kDefaultWTimeoutMs = 60 * 1000;
- const WriteConcernOptions DefaultWriteConcern("majority",
- WriteConcernOptions::NONE,
- kDefaultWTimeoutMs);
-}
-
namespace mongo {
MONGO_LOG_DEFAULT_COMPONENT_FILE(::mongo::logger::LogComponent::kCommands);
@@ -80,7 +69,7 @@ namespace mongo {
CleanupResult cleanupOrphanedData( OperationContext* txn,
const NamespaceString& ns,
const BSONObj& startingFromKeyConst,
- const WriteConcernOptions& secondaryThrottle,
+ bool secondaryThrottle,
BSONObj* stoppedAtKey,
string* errMsg ) {
@@ -164,17 +153,6 @@ namespace mongo {
* the balancer is off.
*
* Safe to call with the balancer on.
- *
- * Format:
- *
- * {
- * cleanupOrphaned: <ns>,
- * // optional parameters:
- * startingAtKey: { <shardKeyValue> }, // defaults to lowest value
- * secondaryThrottle: <bool>, // defaults to true
- * // defaults to { w: "majority", wtimeout: 60000 }. Applies to individual writes.
- * writeConcern: { <writeConcern options> }
- * }
*/
class CleanupOrphanedCommand : public Command {
public:
@@ -201,6 +179,7 @@ namespace mongo {
// Input
static BSONField<string> nsField;
static BSONField<BSONObj> startingFromKeyField;
+ static BSONField<bool> secondaryThrottleField;
// Output
static BSONField<BSONObj> stoppedAtKeyField;
@@ -231,29 +210,12 @@ namespace mongo {
return false;
}
- WriteConcernOptions writeConcern;
- Status status = writeConcern.parseSecondaryThrottle(cmdObj, NULL);
-
- if (!status.isOK()){
- if (status.code() != ErrorCodes::WriteConcernNotDefined) {
- return appendCommandStatus(result, status);
- }
-
- writeConcern = DefaultWriteConcern;
- }
- else {
- repl::ReplicationCoordinator* replCoordinator =
- repl::getGlobalReplicationCoordinator();
- Status status = replCoordinator->checkIfWriteConcernCanBeSatisfied(writeConcern);
- if (!status.isOK()) {
- return appendCommandStatus(result, status);
- }
- }
-
- if (writeConcern.shouldWaitForOtherNodes() &&
- writeConcern.wTimeout == WriteConcernOptions::kNoTimeout) {
- // Don't allow no timeout.
- writeConcern.wTimeout = kDefaultWTimeoutMs;
+ bool secondaryThrottle = true;
+ if ( !FieldParser::extract( cmdObj,
+ secondaryThrottleField,
+ &secondaryThrottle,
+ &errmsg ) ) {
+ return false;
}
if (!shardingState.enabled()) {
@@ -263,7 +225,7 @@ namespace mongo {
}
ChunkVersion shardVersion;
- status = shardingState.refreshMetadataNow( ns, &shardVersion );
+ Status status = shardingState.refreshMetadataNow( ns, &shardVersion );
if ( !status.isOK() ) {
if ( status.code() == ErrorCodes::RemoteChangeDetected ) {
warning() << "Shard version in transition detected while refreshing "
@@ -280,7 +242,7 @@ namespace mongo {
CleanupResult cleanupResult = cleanupOrphanedData( txn,
NamespaceString( ns ),
startingFromKey,
- writeConcern,
+ secondaryThrottle,
&stoppedAtKey,
&errmsg );
@@ -301,6 +263,7 @@ namespace mongo {
BSONField<string> CleanupOrphanedCommand::nsField( "cleanupOrphaned" );
BSONField<BSONObj> CleanupOrphanedCommand::startingFromKeyField( "startingFromKey" );
+ BSONField<bool> CleanupOrphanedCommand::secondaryThrottleField( "secondaryThrottle" );
BSONField<BSONObj> CleanupOrphanedCommand::stoppedAtKeyField( "stoppedAtKey" );
MONGO_INITIALIZER(RegisterCleanupOrphanedCommand)(InitializerContext* context) {
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp
index 8cc0eb0bd1c..83b5b0b7ec5 100644
--- a/src/mongo/db/dbhelpers.cpp
+++ b/src/mongo/db/dbhelpers.cpp
@@ -52,7 +52,6 @@
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/repl_coordinator_global.h"
#include "mongo/db/write_concern.h"
-#include "mongo/db/write_concern_options.h"
#include "mongo/db/operation_context_impl.h"
#include "mongo/db/storage_options.h"
#include "mongo/db/catalog/collection.h"
@@ -306,7 +305,7 @@ namespace mongo {
long long Helpers::removeRange( OperationContext* txn,
const KeyRange& range,
bool maxInclusive,
- const WriteConcernOptions& writeConcern,
+ bool secondaryThrottle,
RemoveSaver* callback,
bool fromMigrate,
bool onlyRemoveOrphanedDocs )
@@ -343,7 +342,7 @@ namespace mongo {
Helpers::toKeyFormat( indexKeyPattern.extendRangeBound(range.maxKey,maxInclusive));
LOG(1) << "begin removal of " << min << " to " << max << " in " << ns
- << " with write concern: " << writeConcern.toBSON() << endl;
+ << (secondaryThrottle ? " (waiting for secondaries)" : "" ) << endl;
Client& c = cc();
@@ -436,7 +435,10 @@ namespace mongo {
// TODO remove once the yielding below that references this timer has been removed
Timer secondaryThrottleTime;
- if (writeConcern.shouldWaitForOtherNodes() && numDeleted > 0) {
+ if ( secondaryThrottle && numDeleted > 0 ) {
+ WriteConcernOptions writeConcern;
+ writeConcern.wNumNodes = 2;
+ writeConcern.wTimeout = 60 * 1000;
repl::ReplicationCoordinator::StatusAndDuration replStatus =
repl::getGlobalReplicationCoordinator()->awaitReplication(txn,
c.getLastOp(),
@@ -452,7 +454,7 @@ namespace mongo {
}
}
- if (writeConcern.shouldWaitForOtherNodes())
+ if ( secondaryThrottle )
log() << "Helpers::removeRangeUnlocked time spent waiting for replication: "
<< millisWaitingForReplication << "ms" << endl;
diff --git a/src/mongo/db/dbhelpers.h b/src/mongo/db/dbhelpers.h
index 865543c74f9..be0ca859248 100644
--- a/src/mongo/db/dbhelpers.h
+++ b/src/mongo/db/dbhelpers.h
@@ -41,7 +41,6 @@ namespace mongo {
class Collection;
class Cursor;
class OperationContext;
- struct WriteConcernOptions;
/**
* db helpers are helper functions and classes that let us easily manipulate the local
@@ -165,8 +164,8 @@ namespace mongo {
*/
static long long removeRange( OperationContext* txn,
const KeyRange& range,
- bool maxInclusive,
- const WriteConcernOptions& secondaryThrottle,
+ bool maxInclusive = false,
+ bool secondaryThrottle = false,
RemoveSaver* callback = NULL,
bool fromMigrate = false,
bool onlyRemoveOrphanedDocs = false );
diff --git a/src/mongo/db/field_parser.cpp b/src/mongo/db/field_parser.cpp
index 47b5b8cf1c0..40c8c9664eb 100644
--- a/src/mongo/db/field_parser.cpp
+++ b/src/mongo/db/field_parser.cpp
@@ -111,7 +111,7 @@ namespace mongo {
{
if (elem.eoo()) {
if (field.hasDefault()) {
- *out = field.getDefault().getOwned();
+ *out = field.getDefault();
return FIELD_DEFAULT;
}
else {
diff --git a/src/mongo/db/range_deleter.cpp b/src/mongo/db/range_deleter.cpp
index e75ce96f0bd..d096cab1219 100644
--- a/src/mongo/db/range_deleter.cpp
+++ b/src/mongo/db/range_deleter.cpp
@@ -189,7 +189,7 @@ namespace mongo {
const BSONObj& min,
const BSONObj& max,
const BSONObj& shardKeyPattern,
- const WriteConcernOptions& writeConcern,
+ bool secondaryThrottle,
Notification* notifyDone,
std::string* errMsg) {
string dummy;
@@ -199,7 +199,7 @@ namespace mongo {
min.getOwned(),
max.getOwned(),
shardKeyPattern.getOwned(),
- writeConcern));
+ secondaryThrottle));
toDelete->notifyDone = notifyDone;
{
@@ -243,13 +243,10 @@ namespace mongo {
}
namespace {
- const int kWTimeoutMillis = 60 * 60 * 1000;
-
- bool _waitForMajority(OperationContext* txn, std::string* errMsg) {
- const WriteConcernOptions writeConcern("majority",
- WriteConcernOptions::NONE,
- kWTimeoutMillis);
-
+ bool _waitForReplication(OperationContext* txn, std::string* errMsg) {
+ WriteConcernOptions writeConcern;
+ writeConcern.wMode = "majority";
+ writeConcern.wTimeout = 60 * 60 * 1000;
repl::ReplicationCoordinator::StatusAndDuration replStatus =
repl::getGlobalReplicationCoordinator()->awaitReplicationOfLastOp(txn,
writeConcern);
@@ -282,7 +279,7 @@ namespace {
const BSONObj& min,
const BSONObj& max,
const BSONObj& shardKeyPattern,
- const WriteConcernOptions& writeConcern,
+ bool secondaryThrottle,
string* errMsg) {
if (stopRequested()) {
*errMsg = "deleter is already stopped.";
@@ -317,7 +314,7 @@ namespace {
<< " cursors in " << ns << " to finish" << endl;
}
- RangeDeleteEntry taskDetails(ns, min, max, shardKeyPattern, writeConcern);
+ RangeDeleteEntry taskDetails(ns, min, max, shardKeyPattern, secondaryThrottle);
taskDetails.stats.queueStartTS = jsTime();
Date_t timeSinceLastLog;
@@ -376,7 +373,7 @@ namespace {
if (result) {
taskDetails.stats.waitForReplStartTS = jsTime();
- result = _waitForMajority(txn, errMsg);
+ result = _waitForReplication(txn, errMsg);
taskDetails.stats.waitForReplEndTS = jsTime();
}
@@ -558,7 +555,7 @@ namespace {
if (delResult) {
nextTask->stats.waitForReplStartTS = jsTime();
- if (!_waitForMajority(txn.get(), &errMsg)) {
+ if (!_waitForReplication(txn.get(), &errMsg)) {
warning() << "Error encountered while waiting for replication: " << errMsg;
}
@@ -665,12 +662,12 @@ namespace {
const BSONObj& min,
const BSONObj& max,
const BSONObj& shardKey,
- const WriteConcernOptions& writeConcern):
+ bool secondaryThrottle):
ns(ns),
min(min),
max(max),
shardKeyPattern(shardKey),
- writeConcern(writeConcern),
+ secondaryThrottle(secondaryThrottle),
notifyDone(NULL) {
}
diff --git a/src/mongo/db/range_deleter.h b/src/mongo/db/range_deleter.h
index cda4578b02b..022f3c84872 100644
--- a/src/mongo/db/range_deleter.h
+++ b/src/mongo/db/range_deleter.h
@@ -39,7 +39,6 @@
#include "mongo/db/clientcursor.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/operation_context.h"
-#include "mongo/db/write_concern_options.h"
#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/concurrency/synchronization.h"
#include "mongo/util/time_support.h"
@@ -139,7 +138,7 @@ namespace mongo {
const BSONObj& min,
const BSONObj& max,
const BSONObj& shardKeyPattern,
- const WriteConcernOptions& writeConcern,
+ bool secondaryThrottle,
Notification* notifyDone,
std::string* errMsg);
@@ -155,7 +154,7 @@ namespace mongo {
const BSONObj& min,
const BSONObj& max,
const BSONObj& shardKeyPattern,
- const WriteConcernOptions& writeConcern,
+ bool secondaryThrottle,
std::string* errMsg);
/**
@@ -310,7 +309,7 @@ namespace mongo {
const BSONObj& min,
const BSONObj& max,
const BSONObj& shardKey,
- const WriteConcernOptions& writeConcern);
+ bool secondaryThrottle);
const std::string ns;
@@ -325,7 +324,7 @@ namespace mongo {
// like hash indexes.
const BSONObj shardKeyPattern;
- const WriteConcernOptions writeConcern;
+ const bool secondaryThrottle;
// Sets of cursors to wait to close until this can be ready
// for deletion.
diff --git a/src/mongo/db/range_deleter_db_env.cpp b/src/mongo/db/range_deleter_db_env.cpp
index 29e96e4ead4..3658f99cd2c 100644
--- a/src/mongo/db/range_deleter_db_env.cpp
+++ b/src/mongo/db/range_deleter_db_env.cpp
@@ -63,7 +63,7 @@ namespace mongo {
const BSONObj inclusiveLower(taskDetails.min);
const BSONObj exclusiveUpper(taskDetails.max);
const BSONObj keyPattern(taskDetails.shardKeyPattern);
- const WriteConcernOptions writeConcern(taskDetails.writeConcern);
+ const bool secondaryThrottle(taskDetails.secondaryThrottle);
const bool initiallyHaveClient = haveClient();
@@ -85,6 +85,8 @@ namespace mongo {
<< endl;
try {
+ bool throttle = repl::getGlobalReplicationCoordinator()->getReplicationMode() ==
+ repl::ReplicationCoordinator::modeReplSet ? secondaryThrottle : false;
*deletedDocs =
Helpers::removeRange(txn,
KeyRange(ns,
@@ -92,7 +94,7 @@ namespace mongo {
exclusiveUpper,
keyPattern),
false, /*maxInclusive*/
- writeConcern,
+ throttle,
serverGlobalParams.moveParanoia ? &removeSaver : NULL,
true, /*fromMigrate*/
true); /*onlyRemoveOrphans*/
diff --git a/src/mongo/db/range_deleter_test.cpp b/src/mongo/db/range_deleter_test.cpp
index c0b50aee619..05ce3918320 100644
--- a/src/mongo/db/range_deleter_test.cpp
+++ b/src/mongo/db/range_deleter_test.cpp
@@ -35,7 +35,6 @@
#include "mongo/db/repl/repl_coordinator_global.h"
#include "mongo/db/repl/repl_coordinator_mock.h"
#include "mongo/db/repl/repl_settings.h"
-#include "mongo/db/write_concern_options.h"
#include "mongo/stdx/functional.h"
#include "mongo/unittest/unittest.h"
@@ -58,7 +57,6 @@ namespace {
const int MAX_IMMEDIATE_DELETE_WAIT_SECS = 2;
const mongo::repl::ReplSettings replSettings;
- const mongo::WriteConcernOptions dummyWriteConcern;
// Should not be able to queue deletes if deleter workers were not started.
TEST(QueueDelete, CantAfterStop) {
@@ -75,7 +73,7 @@ namespace {
BSON("x" << 120),
BSON("x" << 200),
BSON("x" << 1),
- dummyWriteConcern,
+ true,
NULL /* notifier not needed */,
&errMsg));
ASSERT_FALSE(errMsg.empty());
@@ -95,13 +93,8 @@ namespace {
env->addCursorId(ns, 345);
Notification notifyDone;
- ASSERT_TRUE(deleter.queueDelete(ns,
- BSON("x" << 0),
- BSON("x" << 10),
- BSON("x" << 1),
- dummyWriteConcern,
- &notifyDone,
- NULL /* errMsg not needed */));
+ ASSERT_TRUE(deleter.queueDelete(ns, BSON("x" << 0), BSON("x" << 10), BSON("x" << 1),
+ true, &notifyDone, NULL /* errMsg not needed */));
env->waitForNthGetCursor(1u);
@@ -136,13 +129,8 @@ namespace {
env->addCursorId(ns, 345);
Notification notifyDone;
- ASSERT_TRUE(deleter.queueDelete(ns,
- BSON("x" << 0),
- BSON("x" << 10),
- BSON("x" << 1),
- dummyWriteConcern,
- &notifyDone,
- NULL /* errMsg not needed */));
+ ASSERT_TRUE(deleter.queueDelete(ns, BSON("x" << 0), BSON("x" << 10), BSON("x" << 1),
+ true, &notifyDone, NULL /* errMsg not needed */));
env->waitForNthGetCursor(1u);
@@ -157,9 +145,9 @@ namespace {
const BSONObj& min,
const BSONObj& max,
const BSONObj& shardKeyPattern,
- const mongo::WriteConcernOptions& secondaryThrottle,
+ bool secondaryThrottle,
std::string* errMsg) {
- deleter->deleteNow(txn,ns, min, max, shardKeyPattern, secondaryThrottle, errMsg);
+ deleter->deleteNow(txn, ns, min, max, shardKeyPattern, secondaryThrottle, errMsg);
}
// Should not start delete if the set of cursors that were open when the
@@ -183,7 +171,7 @@ namespace {
BSON("x" << 0),
BSON("x" << 10),
BSON("x" << 1),
- dummyWriteConcern,
+ true,
&errMsg));
env->waitForNthGetCursor(1u);
@@ -232,7 +220,7 @@ namespace {
BSON("x" << 0),
BSON("x" << 10),
BSON("x" << 1),
- dummyWriteConcern,
+ true,
&errMsg));
env->waitForNthGetCursor(1u);
@@ -274,7 +262,7 @@ namespace {
BSON("x" << 10),
BSON("x" << 20),
BSON("x" << 1),
- dummyWriteConcern,
+ true,
&notifyDone1,
NULL /* don't care errMsg */));
@@ -288,7 +276,7 @@ namespace {
BSON("x" << 20),
BSON("x" << 30),
BSON("x" << 1),
- dummyWriteConcern,
+ true,
&notifyDone2,
NULL /* don't care errMsg */));
@@ -297,7 +285,7 @@ namespace {
BSON("x" << 30),
BSON("x" << 40),
BSON("x" << 1),
- dummyWriteConcern,
+ true,
&notifyDone3,
NULL /* don't care errMsg */));
@@ -370,23 +358,13 @@ namespace {
ASSERT_TRUE(errMsg.empty());
errMsg.clear();
- ASSERT_FALSE(deleter.queueDelete(ns,
- BSON("x" << 120),
- BSON("x" << 140),
- BSON("x" << 1),
- dummyWriteConcern,
- NULL /* notifier not needed */,
- &errMsg));
+ ASSERT_FALSE(deleter.queueDelete(ns, BSON("x" << 120), BSON("x" << 140), BSON("x" << 1),
+ false, NULL /* notifier not needed */, &errMsg));
ASSERT_FALSE(errMsg.empty());
errMsg.clear();
- ASSERT_FALSE(deleter.deleteNow(noTxn,
- ns,
- BSON("x" << 120),
- BSON("x" << 140),
- BSON("x" << 1),
- dummyWriteConcern,
- &errMsg));
+ ASSERT_FALSE(deleter.deleteNow(noTxn, ns, BSON("x" << 120), BSON("x" << 140),
+ BSON("x" << 1), false, &errMsg));
ASSERT_FALSE(errMsg.empty());
ASSERT_FALSE(env->deleteOccured());
@@ -432,13 +410,8 @@ namespace {
env->addCursorId(ns, 58);
Notification notifyDone;
- deleter.queueDelete(ns,
- BSON("x" << 0),
- BSON("x" << 10),
- BSON("x" << 1),
- dummyWriteConcern,
- &notifyDone,
- NULL /* errMsg not needed */);
+ deleter.queueDelete(ns, BSON("x" << 0), BSON("x" << 10), BSON("x" << 1),
+ false, &notifyDone, NULL /* errMsg not needed */);
string errMsg;
ASSERT_FALSE(deleter.addToBlackList(ns, BSON("x" << 5), BSON("x" << 15), &errMsg));
@@ -475,7 +448,7 @@ namespace {
BSON("x" << 64),
BSON("x" << 70),
BSON("x" << 1),
- dummyWriteConcern,
+ true,
&delErrMsg));
env->waitForNthPausedDelete(1u);
@@ -511,13 +484,8 @@ namespace {
ASSERT_FALSE(deleter.removeFromBlackList(ns, BSON("x" << 1234), BSON("x" << 9000)));
// Range should still be blacklisted
- ASSERT_FALSE(deleter.deleteNow(noTxn,
- ns,
- BSON("x" << 2000),
- BSON("x" << 4000),
- BSON("x" << 1),
- dummyWriteConcern,
- NULL /* errMsg not needed */));
+ ASSERT_FALSE(deleter.deleteNow(noTxn, ns, BSON("x" << 2000), BSON("x" << 4000), BSON("x" << 1),
+ false, NULL /* errMsg not needed */));
deleter.stopWorkers();
}
@@ -535,25 +503,15 @@ namespace {
ASSERT_TRUE(errMsg.empty());
errMsg.clear();
- ASSERT_FALSE(deleter.deleteNow(noTxn,
- ns,
- BSON("x" << 600),
- BSON("x" << 700),
- BSON("x" << 1),
- dummyWriteConcern,
- &errMsg));
+ ASSERT_FALSE(deleter.deleteNow(noTxn, ns, BSON("x" << 600), BSON("x" << 700),
+ BSON("x" << 1), false, &errMsg));
ASSERT_FALSE(errMsg.empty());
ASSERT_TRUE(deleter.removeFromBlackList(ns, BSON("x" << 500), BSON("x" << 801)));
errMsg.clear();
- ASSERT_TRUE(deleter.deleteNow(noTxn,
- ns,
- BSON("x" << 600),
- BSON("x" << 700),
- BSON("x" << 1),
- dummyWriteConcern,
- &errMsg));
+ ASSERT_TRUE(deleter.deleteNow(noTxn, ns, BSON("x" << 600), BSON("x" << 700),
+ BSON("x" << 1), false, &errMsg));
ASSERT_TRUE(errMsg.empty());
deleter.stopWorkers();
@@ -569,13 +527,8 @@ namespace {
deleter.addToBlackList("foo.bar", BSON("x" << 100), BSON("x" << 200),
NULL /* errMsg not needed */);
- ASSERT_TRUE(deleter.deleteNow(noTxn,
- "test.user",
- BSON("x" << 120),
- BSON("x" << 140),
- BSON("x" << 1),
- dummyWriteConcern,
- NULL /* errMsg not needed */));
+ ASSERT_TRUE(deleter.deleteNow(noTxn, "test.user", BSON("x" << 120), BSON("x" << 140),
+ BSON("x" << 1), true, NULL /* errMsg not needed */));
deleter.stopWorkers();
}
diff --git a/src/mongo/db/repl/repl_coordinator.h b/src/mongo/db/repl/repl_coordinator.h
index 000476fd4e8..cf9b20630e6 100644
--- a/src/mongo/db/repl/repl_coordinator.h
+++ b/src/mongo/db/repl/repl_coordinator.h
@@ -201,17 +201,6 @@ namespace repl {
virtual bool canAcceptWritesForDatabase(const StringData& dbName) = 0;
/**
- * Checks if the current replica set configuration can satisfy the given write concern.
- *
- * Things that are taken into consideration include:
- * 1. If the set has enough members.
- * 2. If the tag exists.
- * 3. If there are enough members for the tag specified.
- */
- virtual Status checkIfWriteConcernCanBeSatisfied(
- const WriteConcernOptions& writeConcern) const = 0;
-
- /*
* Returns Status::OK() if it is valid for this node to serve reads on the given collection
* and an errorcode indicating why the node cannot if it cannot.
*/
diff --git a/src/mongo/db/repl/repl_coordinator_hybrid.cpp b/src/mongo/db/repl/repl_coordinator_hybrid.cpp
index 7ca34597f20..c065008e033 100644
--- a/src/mongo/db/repl/repl_coordinator_hybrid.cpp
+++ b/src/mongo/db/repl/repl_coordinator_hybrid.cpp
@@ -275,12 +275,5 @@ namespace repl {
return legacyResponse;
}
- Status HybridReplicationCoordinator::checkIfWriteConcernCanBeSatisfied(
- const WriteConcernOptions& writeConcern) const {
- Status legacyStatus = _legacy.checkIfWriteConcernCanBeSatisfied(writeConcern);
- Status implStatus = _impl.checkIfWriteConcernCanBeSatisfied(writeConcern);
- return legacyStatus;
- }
-
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/repl_coordinator_hybrid.h b/src/mongo/db/repl/repl_coordinator_hybrid.h
index bf375e0a0ee..8a339e556d5 100644
--- a/src/mongo/db/repl/repl_coordinator_hybrid.h
+++ b/src/mongo/db/repl/repl_coordinator_hybrid.h
@@ -83,9 +83,6 @@ namespace repl {
virtual bool canAcceptWritesForDatabase(const StringData& dbName);
- virtual Status checkIfWriteConcernCanBeSatisfied(
- const WriteConcernOptions& writeConcern) const;
-
virtual Status canServeReadsFor(const NamespaceString& ns, bool slaveOk);
virtual bool shouldIgnoreUniqueIndex(const IndexDescriptor* idx);
diff --git a/src/mongo/db/repl/repl_coordinator_impl.cpp b/src/mongo/db/repl/repl_coordinator_impl.cpp
index 5da1a1deb39..9949b10a673 100644
--- a/src/mongo/db/repl/repl_coordinator_impl.cpp
+++ b/src/mongo/db/repl/repl_coordinator_impl.cpp
@@ -446,12 +446,5 @@ namespace repl {
// TODO
return std::vector<BSONObj>();
}
-
- Status ReplicationCoordinatorImpl::checkIfWriteConcernCanBeSatisfied(
- const WriteConcernOptions& writeConcern) const {
- // TODO
- return Status::OK();
- }
-
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/repl_coordinator_impl.h b/src/mongo/db/repl/repl_coordinator_impl.h
index 62e043f9d0c..095c3897a70 100644
--- a/src/mongo/db/repl/repl_coordinator_impl.h
+++ b/src/mongo/db/repl/repl_coordinator_impl.h
@@ -89,9 +89,6 @@ namespace repl {
virtual bool canAcceptWritesForDatabase(const StringData& database);
- virtual Status checkIfWriteConcernCanBeSatisfied(
- const WriteConcernOptions& writeConcern) const;
-
virtual Status canServeReadsFor(const NamespaceString& ns, bool slaveOk);
virtual bool shouldIgnoreUniqueIndex(const IndexDescriptor* idx);
diff --git a/src/mongo/db/repl/repl_coordinator_legacy.cpp b/src/mongo/db/repl/repl_coordinator_legacy.cpp
index 17c30dfb9e0..f4be0d26369 100644
--- a/src/mongo/db/repl/repl_coordinator_legacy.cpp
+++ b/src/mongo/db/repl/repl_coordinator_legacy.cpp
@@ -944,19 +944,5 @@ namespace {
return repl::getHostsWrittenTo(op);
}
- Status LegacyReplicationCoordinator::checkIfWriteConcernCanBeSatisfied(
- const WriteConcernOptions& writeConcern) const {
- // TODO: rewrite this method with the correct version. Note that this just a
- // temporary stub for secondary throttle.
-
- if (getReplicationMode() == ReplicationCoordinator::modeReplSet) {
- if (writeConcern.wNumNodes > 1 && theReplSet->config().getMajority() <= 1) {
- return Status(ErrorCodes::CannotSatisfyWriteConcern, "not enough nodes");
- }
- }
-
- return Status::OK();
- }
-
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/repl_coordinator_legacy.h b/src/mongo/db/repl/repl_coordinator_legacy.h
index f9cf15be96c..a9095f80a09 100644
--- a/src/mongo/db/repl/repl_coordinator_legacy.h
+++ b/src/mongo/db/repl/repl_coordinator_legacy.h
@@ -79,9 +79,6 @@ namespace repl {
virtual bool canAcceptWritesForDatabase(const StringData& dbName);
- virtual Status checkIfWriteConcernCanBeSatisfied(
- const WriteConcernOptions& writeConcern) const;
-
virtual Status canServeReadsFor(const NamespaceString& ns, bool slaveOk);
virtual bool shouldIgnoreUniqueIndex(const IndexDescriptor* idx);
diff --git a/src/mongo/db/repl/repl_coordinator_mock.cpp b/src/mongo/db/repl/repl_coordinator_mock.cpp
index aab04be4938..b7b712bd0d4 100644
--- a/src/mongo/db/repl/repl_coordinator_mock.cpp
+++ b/src/mongo/db/repl/repl_coordinator_mock.cpp
@@ -223,11 +223,5 @@ namespace repl {
// TODO
return std::vector<BSONObj>();
}
-
- Status ReplicationCoordinatorMock::checkIfWriteConcernCanBeSatisfied(
- const WriteConcernOptions& writeConcern) const {
- return Status::OK();
- }
-
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/repl_coordinator_mock.h b/src/mongo/db/repl/repl_coordinator_mock.h
index 1ac42d4a248..260ed685705 100644
--- a/src/mongo/db/repl/repl_coordinator_mock.h
+++ b/src/mongo/db/repl/repl_coordinator_mock.h
@@ -82,9 +82,6 @@ namespace repl {
virtual bool canAcceptWritesForDatabase(const StringData& dbName);
- virtual Status checkIfWriteConcernCanBeSatisfied(
- const WriteConcernOptions& writeConcern) const;
-
virtual Status canServeReadsFor(const NamespaceString& ns, bool slaveOk);
virtual bool shouldIgnoreUniqueIndex(const IndexDescriptor* idx);
diff --git a/src/mongo/db/write_concern_options.cpp b/src/mongo/db/write_concern_options.cpp
index 90690b87599..848c4e4464c 100644
--- a/src/mongo/db/write_concern_options.cpp
+++ b/src/mongo/db/write_concern_options.cpp
@@ -27,9 +27,7 @@
#include "mongo/db/write_concern_options.h"
-#include "mongo/bson/bson_field.h"
#include "mongo/client/dbclientinterface.h"
-#include "mongo/db/field_parser.h"
namespace mongo {
@@ -38,27 +36,6 @@ namespace mongo {
const BSONObj WriteConcernOptions::AllConfigs = BSONObj();
const BSONObj WriteConcernOptions::Unacknowledged(BSON("w" << W_NONE));
- static const BSONField<bool> mongosSecondaryThrottleField("_secondaryThrottle", true);
- static const BSONField<bool> secondaryThrottleField("secondaryThrottle", true);
- static const BSONField<BSONObj> writeConcernField("writeConcern");
-
- WriteConcernOptions::WriteConcernOptions(int numNodes,
- SyncMode sync,
- int timeout):
- syncMode(sync),
- wNumNodes(numNodes),
- wTimeout(timeout) {
- }
-
- WriteConcernOptions::WriteConcernOptions(const std::string& mode,
- SyncMode sync,
- int timeout):
- syncMode(sync),
- wNumNodes(0),
- wMode(mode),
- wTimeout(timeout) {
- }
-
Status WriteConcernOptions::parse( const BSONObj& obj ) {
if ( obj.isEmpty() ) {
return Status( ErrorCodes::FailedToParse, "write concern object cannot be empty" );
@@ -109,84 +86,4 @@ namespace mongo {
return Status::OK();
}
-
- Status WriteConcernOptions::parseSecondaryThrottle(const BSONObj& doc,
- BSONObj* rawWriteConcernObj) {
- string errMsg;
- bool isSecondaryThrottle;
- FieldParser::FieldState fieldState = FieldParser::extract(doc,
- secondaryThrottleField,
- &isSecondaryThrottle,
- &errMsg);
- if (fieldState == FieldParser::FIELD_INVALID) {
- return Status(ErrorCodes::FailedToParse, errMsg);
- }
-
- if (fieldState != FieldParser::FIELD_SET) {
- fieldState = FieldParser::extract(doc,
- mongosSecondaryThrottleField,
- &isSecondaryThrottle,
- &errMsg);
-
- if (fieldState == FieldParser::FIELD_INVALID) {
- return Status(ErrorCodes::FailedToParse, errMsg);
- }
- }
-
- BSONObj dummyBSON;
- if (!rawWriteConcernObj) {
- rawWriteConcernObj = &dummyBSON;
- }
-
- fieldState = FieldParser::extract(doc,
- writeConcernField,
- rawWriteConcernObj,
- &errMsg);
- if (fieldState == FieldParser::FIELD_INVALID) {
- return Status(ErrorCodes::FailedToParse, errMsg);
- }
-
- if (!isSecondaryThrottle) {
- if (!rawWriteConcernObj->isEmpty()) {
- return Status(ErrorCodes::UnsupportedFormat,
- "Cannot have write concern when secondary throttle is false");
- }
-
- wNumNodes = 1;
- return Status::OK();
- }
-
- if (rawWriteConcernObj->isEmpty()) {
- return Status(ErrorCodes::WriteConcernNotDefined,
- "Secondary throttle is on, but write concern is not specified");
- }
-
- return parse(*rawWriteConcernObj);
- }
-
- BSONObj WriteConcernOptions::toBSON() const {
- BSONObjBuilder builder;
-
- if (wMode.empty()) {
- builder.append("w", wNumNodes);
- }
- else {
- builder.append("w", wMode);
- }
-
- if (syncMode == FSYNC) {
- builder.append("fsync", true);
- }
- else if (syncMode == JOURNAL) {
- builder.append("j", true);
- }
-
- builder.append("wtimeout", wTimeout);
-
- return builder.obj();
- }
-
- bool WriteConcernOptions::shouldWaitForOtherNodes() const {
- return !wMode.empty() || wNumNodes > 1;
- }
}
diff --git a/src/mongo/db/write_concern_options.h b/src/mongo/db/write_concern_options.h
index 31b0f556c30..44c67b2938b 100644
--- a/src/mongo/db/write_concern_options.h
+++ b/src/mongo/db/write_concern_options.h
@@ -37,11 +37,8 @@ namespace mongo {
struct WriteConcernOptions {
public:
- enum SyncMode { NONE, FSYNC, JOURNAL };
-
static const int kNoTimeout = 0;
static const int kNoWaiting = -1;
-
static const BSONObj Default;
static const BSONObj Acknowledged;
static const BSONObj AllConfigs;
@@ -49,43 +46,8 @@ namespace mongo {
WriteConcernOptions() { reset(); }
- WriteConcernOptions(int numNodes,
- SyncMode sync,
- int timeout);
-
- WriteConcernOptions(const std::string& mode,
- SyncMode sync,
- int timeout);
-
Status parse( const BSONObj& obj );
- /**
- * Extracts the write concern settings from the BSONObj. The BSON object should have
- * the format:
- *
- * {
- * ...
- * secondaryThrottle: <bool>, // optional
- * _secondaryThrottle: <bool>, // optional
- * writeConcern: <BSONObj> // optional
- * }
- *
- * Note: secondaryThrottle takes precedence over _secondaryThrottle.
- *
- * Also sets output parameter rawWriteConcernObj if the writeCocnern field exists.
- *
- * Returns OK if the parse was successful. Also returns ErrorCodes::WriteConcernNotDefined
- * when secondary throttle is true but write concern was not specified.
- */
- Status parseSecondaryThrottle(const BSONObj& doc,
- BSONObj* rawWriteConcernObj);
-
- /**
- * Return true if the server needs to wait for other secondary nodes to satisfy this
- * write concern setting. Errs on the false positive for non-empty wMode.
- */
- bool shouldWaitForOtherNodes() const;
-
void reset() {
syncMode = NONE;
wNumNodes = 0;
@@ -93,18 +55,11 @@ namespace mongo {
wTimeout = 0;
}
- // Returns the BSON representation of this object.
- // Warning: does not return the same object passed on the last parse() call.
- BSONObj toBSON() const;
-
- SyncMode syncMode;
+ enum SyncMode { NONE, FSYNC, JOURNAL } syncMode;
- // The w parameter for this write concern. The wMode represents the string format and
- // takes precedence over the numeric format wNumNodes.
int wNumNodes;
std::string wMode;
- // Timeout in milliseconds.
int wTimeout;
};
diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp
index 5877cfc85a2..33d190ed34c 100644
--- a/src/mongo/dbtests/dbhelper_tests.cpp
+++ b/src/mongo/dbtests/dbhelper_tests.cpp
@@ -30,7 +30,6 @@
#include "mongo/db/catalog/collection.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/operation_context_impl.h"
-#include "mongo/db/write_concern_options.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/unittest/unittest.h"
@@ -69,8 +68,7 @@ namespace mongo {
BSON( "_id" << _min ),
BSON( "_id" << _max ),
BSON( "_id" << 1 ) );
- mongo::WriteConcernOptions dummyWriteConcern;
- Helpers::removeRange(&txn, range, false, dummyWriteConcern);
+ Helpers::removeRange( &txn, range );
wunit.commit();
}
diff --git a/src/mongo/s/balance.cpp b/src/mongo/s/balance.cpp
index d4fbc5cdb79..b2be36d2113 100644
--- a/src/mongo/s/balance.cpp
+++ b/src/mongo/s/balance.cpp
@@ -33,7 +33,6 @@
#include "mongo/client/dbclientcursor.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/write_concern.h"
-#include "mongo/db/write_concern_options.h"
#include "mongo/s/chunk.h"
#include "mongo/s/cluster_write.h"
#include "mongo/s/config.h"
@@ -62,7 +61,7 @@ namespace mongo {
}
int Balancer::_moveChunks(const vector<CandidateChunkPtr>* candidateChunks,
- const WriteConcernOptions* writeConcern,
+ bool secondaryThrottle,
bool waitForDelete)
{
int movedCount = 0;
@@ -99,7 +98,7 @@ namespace mongo {
BSONObj res;
if (c->moveAndCommit(Shard::make(chunkInfo.to),
Chunk::MaxChunkSize,
- writeConcern,
+ secondaryThrottle,
waitForDelete,
0, /* maxTimeMS */
res)) {
@@ -457,16 +456,9 @@ 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 ;
- }
-
+ BSONObj balancerConfig;
// now make sure we should even be running
- if (!grid.shouldBalance(balancerConfig)) {
+ if ( ! grid.shouldBalance( "", &balancerConfig ) ) {
LOG(1) << "skipping balancing round because balancing is disabled" << endl;
// Ping again so scripts can determine if we're active without waiting
@@ -502,22 +494,20 @@ namespace mongo {
continue;
}
- const bool waitForDelete = (balancerConfig.isWaitForDeleteSet() ?
- balancerConfig.getWaitForDelete() : false);
+ LOG(1) << "*** start balancing round" << endl;
- StatusWith<WriteConcernOptions*> extractStatus =
- balancerConfig.extractWriteConcern();
- if (!extractStatus.isOK()) {
- warning() << extractStatus.toString();
+ bool waitForDelete = false;
+ if (balancerConfig["_waitForDelete"].trueValue()) {
+ waitForDelete = balancerConfig["_waitForDelete"].trueValue();
}
- scoped_ptr<WriteConcernOptions> writeConcern(extractStatus.getValue());
+ bool secondaryThrottle = true; // default to on
+ if ( balancerConfig[SettingsType::secondaryThrottle()].type() ) {
+ secondaryThrottle = balancerConfig[SettingsType::secondaryThrottle()].trueValue();
+ }
- LOG(1) << "*** start balancing round. "
- << "waitForDelete: " << waitForDelete
- << ", secondaryThrottle: "
- << (writeConcern.get() ? writeConcern->toBSON().toString() : "default")
- << endl;
+ LOG(1) << "waitForDelete: " << waitForDelete << endl;
+ LOG(1) << "secondaryThrottle: " << secondaryThrottle << endl;
vector<CandidateChunkPtr> candidateChunks;
_doBalanceRound( conn.conn() , &candidateChunks );
@@ -527,7 +517,7 @@ namespace mongo {
}
else {
_balancedLastTime = _moveChunks(&candidateChunks,
- writeConcern.get(),
+ secondaryThrottle,
waitForDelete );
}
diff --git a/src/mongo/s/balance.h b/src/mongo/s/balance.h
index 87504bd2033..4e97c38b4f4 100644
--- a/src/mongo/s/balance.h
+++ b/src/mongo/s/balance.h
@@ -38,8 +38,6 @@
namespace mongo {
- class WriteConcernOptions;
-
/**
* The balancer is a background task that tries to keep the number of chunks across all servers of the cluster even. Although
* every mongos will have one balancer running, only one of them will be active at the any given point in time. The balancer
@@ -98,12 +96,12 @@ namespace mongo {
* Issues chunk migration request, one at a time.
*
* @param candidateChunks possible chunks to move
- * @param writeConcern detailed write concern. NULL means the default write concern.
+ * @param secondaryThrottle wait for secondaries to catch up before pushing more deletes
* @param waitForDelete wait for deletes to complete after each chunk move
* @return number of chunks effectively moved
*/
int _moveChunks(const std::vector<CandidateChunkPtr>* candidateChunks,
- const WriteConcernOptions* writeConcern,
+ bool secondaryThrottle,
bool waitForDelete);
/**
diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp
index d6611f4fdd7..4aef8141a88 100644
--- a/src/mongo/s/chunk.cpp
+++ b/src/mongo/s/chunk.cpp
@@ -56,7 +56,6 @@
#include "mongo/db/query/query_planner.h"
#include "mongo/db/query/query_planner_common.h"
#include "mongo/db/query/index_bounds_builder.h"
-#include "mongo/db/write_concern_options.h"
namespace mongo {
@@ -356,50 +355,37 @@ namespace mongo {
bool Chunk::moveAndCommit(const Shard& to,
long long chunkSize /* bytes */,
- const WriteConcernOptions* writeConcern,
+ bool secondaryThrottle,
bool waitForDelete,
int maxTimeMS,
- BSONObj& res) const {
+ BSONObj& res) const
+ {
uassert( 10167 , "can't move shard to its current location!" , getShard() != to );
- log() << "moving chunk ns: " << _manager->getns() << " moving ( " << toString() << ") "
- << _shard.toString() << " -> " << to.toString() << endl;
+ log() << "moving chunk ns: " << _manager->getns() << " moving ( " << toString() << ") " << _shard.toString() << " -> " << to.toString() << endl;
Shard from = _shard;
- ScopedDbConnection fromconn(from.getConnString());
-
- BSONObjBuilder builder;
- builder.append("moveChunk", _manager->getns());
- builder.append("from", from.getAddress().toString());
- builder.append("to", to.getAddress().toString());
- // NEEDED FOR 2.0 COMPATIBILITY
- builder.append("fromShard", from.getName());
- builder.append("toShard", to.getName());
- ///////////////////////////////
- builder.append("min", _min);
- builder.append("max", _max);
- builder.append("maxChunkSizeBytes", chunkSize);
- builder.append("shardId", genID());
- builder.append("configdb", configServer.modelServer());
-
- // For legacy secondary throttle setting.
- bool secondaryThrottle = true;
- if (writeConcern &&
- writeConcern->wNumNodes <= 1 &&
- writeConcern->wMode.empty()) {
- secondaryThrottle = false;
- }
- builder.append("secondaryThrottle", secondaryThrottle);
-
- if (secondaryThrottle && writeConcern) {
- builder.append("writeConcern", writeConcern->toBSON());
- }
-
- builder.append("waitForDelete", waitForDelete);
- builder.append(LiteParsedQuery::cmdOptionMaxTimeMS, maxTimeMS);
+ ScopedDbConnection fromconn(from.getConnString());
- bool worked = fromconn->runCommand("admin", builder.done(), res);
+ bool worked = fromconn->runCommand( "admin" ,
+ BSON( "moveChunk" << _manager->getns() <<
+ "from" << from.getAddress().toString() <<
+ "to" << to.getAddress().toString() <<
+ // NEEDED FOR 2.0 COMPATIBILITY
+ "fromShard" << from.getName() <<
+ "toShard" << to.getName() <<
+ ///////////////////////////////
+ "min" << _min <<
+ "max" << _max <<
+ "maxChunkSizeBytes" << chunkSize <<
+ "shardId" << genID() <<
+ "configdb" << configServer.modelServer() <<
+ "secondaryThrottle" << secondaryThrottle <<
+ "waitForDelete" << waitForDelete <<
+ LiteParsedQuery::cmdOptionMaxTimeMS << maxTimeMS
+ ) ,
+ res);
fromconn.done();
LOG( worked ? 1 : 0 ) << "moveChunk result: " << res << endl;
@@ -464,8 +450,7 @@ namespace mongo {
_dataWritten = 0; // we're splitting, so should wait a bit
}
- const bool shouldBalance = grid.getConfigShouldBalance() &&
- grid.getCollShouldBalance(_manager->getns());
+ bool shouldBalance = grid.shouldBalance( _manager->getns() );
log() << "autosplitted " << _manager->getns()
<< " shard: " << toString()
@@ -504,13 +489,11 @@ namespace mongo {
log().stream() << "moving chunk (auto): " << toMove << " to: " << newLocation.toString() << endl;
BSONObj res;
-
- WriteConcernOptions noThrottle;
massert( 10412 ,
str::stream() << "moveAndCommit failed: " << res ,
toMove->moveAndCommit( newLocation ,
MaxChunkSize ,
- &noThrottle, /* secondaryThrottle */
+ false , /* secondaryThrottle - small chunk, no need */
false, /* waitForDelete - small chunk, no need */
0, /* maxTimeMS - don't time out */
res ) );
diff --git a/src/mongo/s/chunk.h b/src/mongo/s/chunk.h
index 71baafad061..f8f18df1474 100644
--- a/src/mongo/s/chunk.h
+++ b/src/mongo/s/chunk.h
@@ -46,7 +46,6 @@ namespace mongo {
class ChunkRange;
class ChunkManager;
class ChunkObjUnitTest;
- class WriteConcernOptions;
typedef shared_ptr<const Chunk> ChunkPtr;
@@ -173,7 +172,7 @@ namespace mongo {
*
* @param to shard to move this chunk to
* @param chunSize maximum number of bytes beyond which the migrate should no go trhough
- * @param writeConcern detailed write concern. NULL means the default write concern.
+ * @param secondaryThrottle whether during migrate all writes should block for repl
* @param waitForDelete whether chunk move should wait for cleanup or return immediately
* @param maxTimeMS max time for the migrate request
* @param res the object containing details about the migrate execution
@@ -181,7 +180,7 @@ namespace mongo {
*/
bool moveAndCommit(const Shard& to,
long long chunkSize,
- const WriteConcernOptions* writeConcern,
+ bool secondaryThrottle,
bool waitForDelete,
int maxTimeMS,
BSONObj& res) const;
diff --git a/src/mongo/s/commands_admin.cpp b/src/mongo/s/commands_admin.cpp
index aa66197d0fa..79372173622 100644
--- a/src/mongo/s/commands_admin.cpp
+++ b/src/mongo/s/commands_admin.cpp
@@ -48,7 +48,6 @@
#include "mongo/db/stats/counters.h"
#include "mongo/db/wire_version.h"
#include "mongo/db/write_concern.h"
-#include "mongo/db/write_concern_options.h"
#include "mongo/s/chunk.h"
#include "mongo/s/client_info.h"
#include "mongo/s/cluster_write.h"
@@ -773,9 +772,8 @@ namespace mongo {
continue;
BSONObj moveResult;
- WriteConcernOptions noThrottle;
if (!chunk->moveAndCommit(to, Chunk::MaxChunkSize,
- &noThrottle, true, 0, moveResult)) {
+ false, true, 0, moveResult)) {
warning().stream()
<< "Couldn't move chunk " << chunk << " to shard " << to
<< " while sharding collection " << ns << ". Reason: "
@@ -1135,23 +1133,10 @@ namespace mongo {
return false;
}
- scoped_ptr<WriteConcernOptions> writeConcern(new WriteConcernOptions());
- Status status = writeConcern->parseSecondaryThrottle(cmdObj, NULL);
-
- if (!status.isOK()){
- if (status.code() != ErrorCodes::WriteConcernNotDefined) {
- errmsg = status.toString();
- return false;
- }
-
- // Let the shard decide what write concern to use.
- writeConcern.reset();
- }
-
BSONObj res;
if (!c->moveAndCommit(to,
maxChunkSizeBytes,
- writeConcern.get(),
+ cmdObj["_secondaryThrottle"].trueValue(),
cmdObj["_waitForDelete"].trueValue(),
maxTimeMS.getValue(),
res)) {
diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp
index 414bc337249..2fb6aa8be8f 100644
--- a/src/mongo/s/d_migrate.cpp
+++ b/src/mongo/s/d_migrate.cpp
@@ -88,31 +88,6 @@
using namespace std;
-namespace {
- using mongo::WriteConcernOptions;
- using mongo::repl::ReplicationCoordinator;
-
- const int kDefaultWTimeoutMs = 60 * 1000;
- const WriteConcernOptions DefaultWriteConcern(2, WriteConcernOptions::NONE, kDefaultWTimeoutMs);
-
- /**
- * Returns the default write concern for migration cleanup (at donor shard) and
- * cloning documents (at recipient shard).
- */
- WriteConcernOptions getDefaultWriteConcern() {
- ReplicationCoordinator* replCoordinator =
- mongo::repl::getGlobalReplicationCoordinator();
- mongo::Status status =
- replCoordinator->checkIfWriteConcernCanBeSatisfied(DefaultWriteConcern);
-
- if (status.isOK()) {
- return DefaultWriteConcern;
- }
-
- return WriteConcernOptions(1, WriteConcernOptions::NONE, 0);
- }
-}
-
namespace mongo {
MONGO_LOG_DEFAULT_COMPONENT_FILE(::mongo::logger::LogComponent::kSharding);
@@ -771,24 +746,6 @@ namespace mongo {
* called to initial a move
* usually by a mongos
* this is called on the "from" side
- *
- * Format:
- * {
- * moveChunk: "namespace",
- * from: "hostAndPort",
- * fromShard: "shardName",
- * to: "hostAndPort",
- * toShard: "shardName",
- * min: {},
- * max: {},
- * maxChunkBytes: numeric,
- * shardId: "_id of chunk document in config.chunks",
- * configdb: "hostAndPort",
- *
- * // optional
- * secondaryThrottle: bool, //defaults to true.
- * writeConcern: {} // applies to individual writes.
- * }
*/
class MoveChunkCommand : public Command {
public:
@@ -845,33 +802,28 @@ namespace mongo {
to = cmdObj["toShard"].String();
}
- // Process secondary throttle settings and assign defaults if necessary.
- BSONObj secThrottleObj;
- WriteConcernOptions writeConcern;
- Status status = writeConcern.parseSecondaryThrottle(cmdObj, &secThrottleObj);
-
- if (!status.isOK()){
- if (status.code() != ErrorCodes::WriteConcernNotDefined) {
- warning() << status.toString() << endl;
- return appendCommandStatus(result, status);
+ // if we do a w=2 after every write
+ bool secondaryThrottle = cmdObj["secondaryThrottle"].trueValue();
+ if ( secondaryThrottle ) {
+ const repl::ReplicationCoordinator::Mode replMode =
+ repl::getGlobalReplicationCoordinator()->getReplicationMode();
+ if (replMode == repl::ReplicationCoordinator::modeReplSet) {
+ if (repl::theReplSet->config().getMajority() <= 1) {
+ secondaryThrottle = false;
+ warning() << "not enough nodes in set to use secondaryThrottle: "
+ << " majority: " << repl::theReplSet->config().getMajority()
+ << endl;
+ }
}
-
- writeConcern = getDefaultWriteConcern();
- }
- else {
- repl::ReplicationCoordinator* replCoordinator =
- repl::getGlobalReplicationCoordinator();
- Status status = replCoordinator->checkIfWriteConcernCanBeSatisfied(writeConcern);
- if (!status.isOK()) {
- warning() << status.toString() << endl;
- return appendCommandStatus(result, status);
+ else if (replMode == repl::ReplicationCoordinator::modeNone) {
+ secondaryThrottle = false;
+ warning() << "secondaryThrottle selected but no replication" << endl;
+ }
+ else {
+ // master/slave
+ secondaryThrottle = false;
+ warning() << "secondaryThrottle not allowed with master/slave" << endl;
}
- }
-
- if (writeConcern.shouldWaitForOtherNodes() &&
- writeConcern.wTimeout == WriteConcernOptions::kNoTimeout) {
- // Don't allow no timeout.
- writeConcern.wTimeout = kDefaultWTimeoutMs;
}
// Do inline deletion
@@ -1104,27 +1056,19 @@ namespace mongo {
ScopedDbConnection connTo(toShard.getConnString());
BSONObj res;
bool ok;
-
- const bool isSecondaryThrottle(writeConcern.shouldWaitForOtherNodes());
-
- BSONObjBuilder recvChunkStartBuilder;
- recvChunkStartBuilder.append("_recvChunkStart", ns);
- recvChunkStartBuilder.append("from", fromShard.getConnString());
- recvChunkStartBuilder.append("fromShardName", fromShard.getName());
- recvChunkStartBuilder.append("toShardName", toShard.getName());
- recvChunkStartBuilder.append("min", min);
- recvChunkStartBuilder.append("max", max);
- recvChunkStartBuilder.append("shardKeyPattern", shardKeyPattern);
- recvChunkStartBuilder.append("configServer", configServer.modelServer());
- recvChunkStartBuilder.append("secondaryThrottle", isSecondaryThrottle);
-
- // Follow the same convention in moveChunk.
- if (isSecondaryThrottle && !secThrottleObj.isEmpty()) {
- recvChunkStartBuilder.append("writeConcern", secThrottleObj);
- }
-
try{
- ok = connTo->runCommand("admin", recvChunkStartBuilder.done(), res);
+ ok = connTo->runCommand( "admin" ,
+ BSON( "_recvChunkStart" << ns <<
+ "from" << fromShard.getConnString() <<
+ "fromShardName" << fromShard.getName() <<
+ "toShardName" << toShard.getName() <<
+ "min" << min <<
+ "max" << max <<
+ "shardKeyPattern" << shardKeyPattern <<
+ "configServer" << configServer.modelServer() <<
+ "secondaryThrottle" << secondaryThrottle
+ ) ,
+ res );
}
catch( DBException& e ){
errmsg = str::stream() << "moveChunk could not contact to: shard "
@@ -1557,7 +1501,7 @@ namespace mongo {
min.getOwned(),
max.getOwned(),
shardKeyPattern.getOwned(),
- writeConcern,
+ secondaryThrottle,
&errMsg)) {
log() << "Error occured while performing cleanup: " << errMsg << endl;
}
@@ -1570,7 +1514,7 @@ namespace mongo {
min.getOwned(),
max.getOwned(),
shardKeyPattern.getOwned(),
- writeConcern,
+ secondaryThrottle,
NULL, // Don't want to be notified.
&errMsg)) {
log() << "could not queue migration cleanup: " << errMsg << endl;
@@ -1784,7 +1728,7 @@ namespace mongo {
long long num = Helpers::removeRange( txn,
range,
false, /*maxInclusive*/
- writeConcern,
+ secondaryThrottle, /* secondaryThrottle */
/*callback*/
serverGlobalParams.moveParanoia ? &rs : 0,
true ); /* flag fromMigrate in oplog */
@@ -1816,7 +1760,7 @@ namespace mongo {
State currentState = getState();
if (currentState == FAIL || currentState == ABORT) {
string errMsg;
- if (!getDeleter()->queueDelete(ns, min, max, shardKeyPattern, writeConcern,
+ if (!getDeleter()->queueDelete(ns, min, max, shardKeyPattern, secondaryThrottle,
NULL /* notifier */, &errMsg)) {
warning() << "Failed to queue delete for migrate abort: " << errMsg << endl;
}
@@ -1876,15 +1820,18 @@ namespace mongo {
numCloned++;
clonedBytes += o.objsize();
- if (writeConcern.shouldWaitForOtherNodes() && thisTime > 0) {
+ if ( secondaryThrottle && thisTime > 0 ) {
+ WriteConcernOptions writeConcern;
+ writeConcern.wNumNodes = 2;
+ writeConcern.wTimeout = 60 * 1000;
repl::ReplicationCoordinator::StatusAndDuration replStatus =
repl::getGlobalReplicationCoordinator()->awaitReplication(
txn,
cc().getLastOp(),
writeConcern);
if (replStatus.status.code() == ErrorCodes::ExceededTimeLimit) {
- warning() << "secondaryThrottle on, but doc insert timed out; "
- "continuing";
+ warning() << "secondaryThrottle on, but doc insert timed out "
+ "after 60 seconds, continuing";
}
else {
massertStatusOK(replStatus.status);
@@ -2097,12 +2044,10 @@ namespace mongo {
// TODO: create a better interface to remove objects directly
KeyRange range( ns, id, id, idIndexPattern );
- const WriteConcernOptions singleNodeWrite(1, WriteConcernOptions::NONE,
- WriteConcernOptions::kNoTimeout);
Helpers::removeRange( txn,
range ,
true , /*maxInclusive*/
- singleNodeWrite,
+ false , /* secondaryThrottle */
serverGlobalParams.moveParanoia ? &rs : 0 , /*callback*/
true ); /*fromMigrate*/
@@ -2267,7 +2212,7 @@ namespace mongo {
long long clonedBytes;
long long numCatchup;
long long numSteady;
- WriteConcernOptions writeConcern;
+ bool secondaryThrottle;
int replSetMajorityCount;
@@ -2293,25 +2238,6 @@ namespace mongo {
cc().shutdown();
}
- /**
- * Command for initiating the recipient side of the migration to start copying data
- * from the donor shard.
- *
- * {
- * _recvChunkStart: "namespace",
- * congfigServer: "hostAndPort",
- * from: "hostAndPort",
- * fromShardName: "shardName",
- * toShardName: "shardName",
- * min: {},
- * max: {},
- * shardKeyPattern: {},
- *
- * // optional
- * secondaryThrottle: bool, // defaults to true
- * writeConcern: {} // applies to individual writes.
- * }
- */
class RecvChunkStartCommand : public ChunkCommandHelper {
public:
void help(stringstream& h) const { h << "internal"; }
@@ -2378,37 +2304,7 @@ namespace mongo {
migrateStatus.min = min;
migrateStatus.max = max;
migrateStatus.epoch = currentVersion.epoch();
-
- // Process secondary throttle settings and assign defaults if necessary.
- WriteConcernOptions writeConcern;
- status = writeConcern.parseSecondaryThrottle(cmdObj, NULL);
-
- if (!status.isOK()){
- if (status.code() != ErrorCodes::WriteConcernNotDefined) {
- warning() << status.toString() << endl;
- return appendCommandStatus(result, status);
- }
-
- writeConcern = getDefaultWriteConcern();
- }
- else {
- repl::ReplicationCoordinator* replCoordinator =
- repl::getGlobalReplicationCoordinator();
- Status status = replCoordinator->checkIfWriteConcernCanBeSatisfied(writeConcern);
- if (!status.isOK()) {
- warning() << status.toString() << endl;
- return appendCommandStatus(result, status);
- }
- }
-
- if (writeConcern.shouldWaitForOtherNodes() &&
- writeConcern.wTimeout == WriteConcernOptions::kNoTimeout) {
- // Don't allow no timeout.
- writeConcern.wTimeout = kDefaultWTimeoutMs;
- }
-
- migrateStatus.writeConcern = writeConcern;
-
+ migrateStatus.secondaryThrottle = cmdObj["secondaryThrottle"].trueValue();
if (cmdObj.hasField("shardKeyPattern")) {
migrateStatus.shardKeyPattern = cmdObj["shardKeyPattern"].Obj().getOwned();
} else {
@@ -2427,6 +2323,12 @@ namespace mongo {
migrateStatus.shardKeyPattern = keya.getOwned();
}
+ if (migrateStatus.secondaryThrottle &&
+ !repl::getGlobalReplicationCoordinator()->isReplEnabled()) {
+ warning() << "secondaryThrottle asked for, but no replication is enabled" << endl;
+ migrateStatus.secondaryThrottle = false;
+ }
+
// Set the TO-side migration to active
migrateStatus.prepare();
diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp
index 93b3e0a3f77..49804a42359 100644
--- a/src/mongo/s/grid.cpp
+++ b/src/mongo/s/grid.cpp
@@ -498,70 +498,48 @@ namespace mongo {
* Returns whether balancing is enabled, with optional namespace "ns" parameter for balancing on a particular
* collection.
*/
+ bool Grid::shouldBalance( const string& ns, BSONObj* balancerDocOut ) const {
- bool Grid::shouldBalance(const SettingsType& balancerSettings) const {
// Allow disabling the balancer for testing
- if (MONGO_FAIL_POINT(neverBalance)) return false;
+ if ( MONGO_FAIL_POINT(neverBalance) ) return false;
- if (balancerSettings.isBalancerStoppedSet() && balancerSettings.getBalancerStopped()) {
- return false;
- }
-
- if (balancerSettings.isBalancerActiveWindowSet()) {
- boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
- return _inBalancingWindow(balancerSettings.getBalancerActiveWindow(), now);
- }
-
- return true;
- }
-
- bool Grid::getBalancerSettings(SettingsType* settings, string* errMsg) const {
- BSONObj balancerDoc;
ScopedDbConnection conn(configServer.getPrimary().getConnString(), 30);
+ BSONObj balancerDoc;
+ BSONObj collDoc;
try {
- balancerDoc = conn->findOne(SettingsType::ConfigNS,
- BSON(SettingsType::key("balancer")));
+ // look for the stop balancer marker
+ balancerDoc = conn->findOne( SettingsType::ConfigNS,
+ BSON( SettingsType::key("balancer") ) );
+ if( ns.size() > 0 ) collDoc = conn->findOne(CollectionType::ConfigNS,
+ BSON( CollectionType::ns(ns)));
conn.done();
}
- catch (const DBException& ex) {
- *errMsg = str::stream() << "failed to read balancer settings from " << conn.getHost()
- << ": " << causedBy(ex);
+ catch( DBException& e ){
+ conn.kill();
+ warning() << "could not determine whether balancer should be running, error getting"
+ "config data from " << conn.getHost() << causedBy( e ) << endl;
+ // if anything goes wrong, we shouldn't try balancing
return false;
}
- return settings->parseBSON(balancerDoc, errMsg);
- }
+ if ( balancerDocOut )
+ *balancerDocOut = balancerDoc;
- bool Grid::getConfigShouldBalance() const {
- SettingsType balSettings;
- string errMsg;
-
- if (!getBalancerSettings(&balSettings, &errMsg)) {
- warning() << errMsg;
+ boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
+ if ( _balancerStopped( balancerDoc ) || ! _inBalancingWindow( balancerDoc , now ) ) {
return false;
}
- return shouldBalance(balSettings);
+ if( collDoc["noBalance"].trueValue() ) return false;
+ return true;
}
- bool Grid::getCollShouldBalance(const std::string& ns) const {
- BSONObj collDoc;
- ScopedDbConnection conn(configServer.getPrimary().getConnString(), 30);
-
- try {
- collDoc = conn->findOne(CollectionType::ConfigNS, BSON(CollectionType::ns(ns)));
- conn.done();
- }
- catch (const DBException& e){
- conn.kill();
- warning() << "could not determine whether balancer should be running, error getting"
- << "config data from " << conn.getHost() << causedBy(e) << endl;
- // if anything goes wrong, we shouldn't try balancing
- return false;
- }
-
- return !collDoc[CollectionType::noBalance()].trueValue();
+ bool Grid::_balancerStopped( const BSONObj& balancerDoc ) {
+ // check the 'stopped' marker maker
+ // if present, it is a simple bool
+ BSONElement stoppedElem = balancerDoc[SettingsType::balancerStopped()];
+ return stoppedElem.trueValue();
}
bool Grid::_inBalancingWindow( const BSONObj& balancerDoc , const boost::posix_time::ptime& now ) {
diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h
index 7d4e2a575d5..e68918abce8 100644
--- a/src/mongo/s/grid.h
+++ b/src/mongo/s/grid.h
@@ -35,8 +35,7 @@
#include "mongo/util/time_support.h"
#include "mongo/util/concurrency/mutex.h"
-#include "mongo/s/config.h" // DBConfigPtr
-#include "mongo/s/type_settings.h"
+#include "config.h" // DBConfigPtr
namespace mongo {
@@ -108,24 +107,9 @@ namespace mongo {
bool knowAboutShard( const std::string& name ) const;
/**
- * Returns true if the balancer should be running.
+ * @return true if the chunk balancing functionality is enabled
*/
- bool shouldBalance(const SettingsType& balancerSettings) const;
-
- /**
- * Retrieve the balancer settings from the config server.
- */
- bool getBalancerSettings(SettingsType* settings, string* errMsg) const;
-
- /**
- * Returns true if the config server settings indicate that the balancer should be active.
- */
- bool getConfigShouldBalance() const;
-
- /**
- * Returns true if the given collection can be balanced.
- */
- bool getCollShouldBalance(const std::string& ns) const;
+ bool shouldBalance( const std::string& ns = "", BSONObj* balancerDocOut = 0 ) const;
/**
*
@@ -165,6 +149,14 @@ namespace mongo {
* @return whether a give dbname is used for shard "local" databases (e.g., admin or local)
*/
static bool _isSpecialLocalDB( const std::string& dbName );
+
+ /**
+ * @param balancerDoc bson that may contain a marker to stop the balancer
+ * format { ... , stopped: [ "true" | "false" ] , ... }
+ * @return true if the marker is present and is set to true
+ */
+ static bool _balancerStopped( const BSONObj& balancerDoc );
+
};
extern Grid grid;
diff --git a/src/mongo/s/type_settings.cpp b/src/mongo/s/type_settings.cpp
index 437c4b9f230..08ada19d680 100644
--- a/src/mongo/s/type_settings.cpp
+++ b/src/mongo/s/type_settings.cpp
@@ -28,7 +28,6 @@
#include "mongo/s/type_settings.h"
#include "mongo/db/field_parser.h"
-#include "mongo/db/write_concern_options.h"
#include "mongo/util/mongoutils/str.h"
#include "mongo/util/time_support.h"
@@ -42,9 +41,7 @@ namespace mongo {
const BSONField<int> SettingsType::chunksize("value");
const BSONField<bool> SettingsType::balancerStopped("stopped");
const BSONField<BSONObj> SettingsType::balancerActiveWindow("activeWindow");
- const BSONField<bool> SettingsType::deprecated_secondaryThrottle("_secondaryThrottle", true);
- const BSONField<BSONObj> SettingsType::migrationWriteConcern("_secondaryThrottle");
- const BSONField<bool> SettingsType::waitForDelete("_waitForDelete");
+ const BSONField<bool> SettingsType::secondaryThrottle("_secondaryThrottle");
SettingsType::SettingsType() {
clear();
@@ -97,12 +94,6 @@ namespace mongo {
" format is { start: \"hh:mm\" , stop: \"hh:mm\" }";
return false;
}
-
- if (_isSecondaryThrottleSet && _isMigrationWriteConcernSet) {
- *errMsg = stream() << "cannot have both secondary throttle and migration "
- << "write concern set at the same time";
- return false;
- }
}
return true;
}
@@ -121,13 +112,8 @@ namespace mongo {
if (_isBalancerActiveWindowSet) {
builder.append(balancerActiveWindow(), _balancerActiveWindow);
}
- if (_isSecondaryThrottleSet) {
- builder.append(deprecated_secondaryThrottle(), _secondaryThrottle);
- }
+ if (_isSecondaryThrottleSet) builder.append(secondaryThrottle(), _secondaryThrottle);
- if (_isMigrationWriteConcernSet) {
- builder.append(migrationWriteConcern(), _migrationWriteConcern);
- }
return builder.obj();
}
@@ -155,23 +141,9 @@ namespace mongo {
if (fieldState == FieldParser::FIELD_INVALID) return false;
_isBalancerActiveWindowSet = fieldState == FieldParser::FIELD_SET;
- fieldState = FieldParser::extract(source,
- migrationWriteConcern,
- &_migrationWriteConcern,
- errMsg);
- _isMigrationWriteConcernSet = fieldState == FieldParser::FIELD_SET;
-
- if (fieldState == FieldParser::FIELD_INVALID) {
- fieldState = FieldParser::extract(source, deprecated_secondaryThrottle,
- &_secondaryThrottle, errMsg);
- if (fieldState == FieldParser::FIELD_INVALID) return false;
- errMsg->clear(); // Note: extract method doesn't clear errMsg.
- _isSecondaryThrottleSet = fieldState == FieldParser::FIELD_SET;
- }
-
- fieldState = FieldParser::extract(source, waitForDelete, &_waitForDelete, errMsg);
+ fieldState = FieldParser::extract(source, secondaryThrottle, &_secondaryThrottle, errMsg);
if (fieldState == FieldParser::FIELD_INVALID) return false;
- _isWaitForDeleteSet = fieldState == FieldParser::FIELD_SET;
+ _isSecondaryThrottleSet = fieldState == FieldParser::FIELD_SET;
return true;
}
@@ -190,14 +162,12 @@ namespace mongo {
_balancerActiveWindow = BSONObj();
_isBalancerActiveWindowSet = false;
+ _shortBalancerSleep = false;
+ _isShortBalancerSleepSet = false;
+
_secondaryThrottle = false;
_isSecondaryThrottleSet = false;
- _migrationWriteConcern = BSONObj();
- _isMigrationWriteConcernSet= false;
-
- _waitForDelete = false;
- _isWaitForDeleteSet = false;
}
void SettingsType::cloneTo(SettingsType* other) const {
@@ -212,49 +182,19 @@ namespace mongo {
other->_balancerStopped = _balancerStopped;
other->_isBalancerStoppedSet = _isBalancerStoppedSet;
- other->_balancerActiveWindow = _balancerActiveWindow.copy();
+ other->_balancerActiveWindow = _balancerActiveWindow;
other->_isBalancerActiveWindowSet = _isBalancerActiveWindowSet;
+ other->_shortBalancerSleep = _shortBalancerSleep;
+ other->_isShortBalancerSleepSet = _isShortBalancerSleepSet;
+
other->_secondaryThrottle = _secondaryThrottle;
other->_isSecondaryThrottleSet = _isSecondaryThrottleSet;
- other->_migrationWriteConcern = _migrationWriteConcern.copy();
- other->_isMigrationWriteConcernSet = _isMigrationWriteConcernSet;
-
- other->_waitForDelete = _waitForDelete;
- other->_isWaitForDeleteSet = _isWaitForDeleteSet;
}
std::string SettingsType::toString() const {
return toBSON().toString();
}
- StatusWith<WriteConcernOptions*> SettingsType::extractWriteConcern() const {
- dassert(_isKeySet);
- dassert(_key == "balancer");
-
- const bool isSecondaryThrottle = getSecondaryThrottle();
- if (!isSecondaryThrottle) {
- return(StatusWith<WriteConcernOptions*>(
- new WriteConcernOptions(1, WriteConcernOptions::NONE, 0)));
- }
-
- const BSONObj migrationWOption(isMigrationWriteConcernSet() ?
- getMigrationWriteConcern() : BSONObj());
-
- if (migrationWOption.isEmpty()) {
- // Default setting.
- return StatusWith<WriteConcernOptions*>(NULL);
- }
-
- auto_ptr<WriteConcernOptions> writeConcern(new WriteConcernOptions());
- Status status = writeConcern->parse(migrationWOption);
-
- if (!status.isOK()) {
- return StatusWith<WriteConcernOptions*>(status);
- }
-
- return StatusWith<WriteConcernOptions*>(writeConcern.release());
- }
-
} // namespace mongo
diff --git a/src/mongo/s/type_settings.h b/src/mongo/s/type_settings.h
index f3d2b4c4739..fa8a76e0480 100644
--- a/src/mongo/s/type_settings.h
+++ b/src/mongo/s/type_settings.h
@@ -31,14 +31,11 @@
#include <string>
#include "mongo/base/disallow_copying.h"
-#include "mongo/base/status_with.h"
#include "mongo/base/string_data.h"
#include "mongo/db/jsobj.h"
namespace mongo {
- struct WriteConcernOptions;
-
/**
* This class represents the layout and contents of documents contained in the
* config.settings collection. All manipulation of documents coming from that
@@ -76,9 +73,7 @@ namespace mongo {
static const BSONField<int> chunksize;
static const BSONField<bool> balancerStopped;
static const BSONField<BSONObj> balancerActiveWindow;
- static const BSONField<bool> deprecated_secondaryThrottle;
- static const BSONField<BSONObj> migrationWriteConcern;
- static const BSONField<bool> waitForDelete;
+ static const BSONField<bool> secondaryThrottle;
//
// settings type methods
@@ -212,7 +207,7 @@ namespace mongo {
void unsetSecondaryThrottle() { _isSecondaryThrottleSet = false; }
bool isSecondaryThrottleSet() const {
- return _isSecondaryThrottleSet || deprecated_secondaryThrottle.hasDefault();
+ return _isSecondaryThrottleSet || secondaryThrottle.hasDefault();
}
// Calling get*() methods when the member is not set and has no default results in undefined
@@ -222,59 +217,10 @@ namespace mongo {
return _secondaryThrottle;
} else {
dassert(secondaryThrottle.hasDefault());
- return deprecated_secondaryThrottle.getDefault();
+ return secondaryThrottle.getDefault();
}
}
- void setMigrationWriteConcern(const BSONObj& writeConcern) {
- _migrationWriteConcern = writeConcern;
- _isMigrationWriteConcernSet = true;
- }
-
- void unsetMigrationWriteConcern() {
- _isMigrationWriteConcernSet = false;
- }
-
- bool isMigrationWriteConcernSet() const {
- return _isMigrationWriteConcernSet;
- }
-
- // Calling get*() methods when the member is not set and has no default results in undefined
- // behavior
- BSONObj getMigrationWriteConcern() const {
- dassert (_isBalancerWriteConcernSet);
- return _migrationWriteConcern;
- }
-
- void setWaitForDelete(bool waitForDelete) {
- _waitForDelete = waitForDelete;
- _isWaitForDeleteSet = true;
- }
-
- void unsetWaitForDelete() {
- _isWaitForDeleteSet = false;
- }
-
- bool isWaitForDeleteSet() const {
- return _isWaitForDeleteSet;
- }
-
- // Calling get*() methods when the member is not set and has no default results in undefined
- // behavior
- bool getWaitForDelete() const {
- dassert (_isWaitForDeleteSet);
- return _waitForDelete;
- }
-
- // Helper methods
-
- /**
- * Extract the write concern settings from this settings. This is only valid when
- * key is "balancer". Returns NULL if secondary throttle is true but write
- * concern is not specified.
- */
- StatusWith<WriteConcernOptions*> extractWriteConcern() const;
-
private:
// Convention: (M)andatory, (O)ptional, (S)pecial rule.
std::string _key; // (M) key determining the type of options to use
@@ -292,19 +238,11 @@ namespace mongo {
// Format: { start: "08:00" , stop:
// "19:30" }, strftime format is %H:%M
+ bool _shortBalancerSleep; // (O) controls how long the balancer sleeps
+ bool _isShortBalancerSleepSet; // in some situations
bool _secondaryThrottle; // (O) only migrate chunks as fast as at least
bool _isSecondaryThrottleSet; // one secondary can keep up with
-
- // (O) detailed write concern for *individual* writes during migration.
- // From side: deletes during cleanup.
- // To side: deletes to clear the incoming range, deletes to undo migration at abort,
- // and writes during cloning.
- BSONObj _migrationWriteConcern;
- bool _isMigrationWriteConcernSet;
-
- bool _waitForDelete; // (O) synchronous migration cleanup.
- bool _isWaitForDeleteSet;
};
} // namespace mongo
diff --git a/src/mongo/s/type_settings_test.cpp b/src/mongo/s/type_settings_test.cpp
index 651c53d056c..9b605464794 100644
--- a/src/mongo/s/type_settings_test.cpp
+++ b/src/mongo/s/type_settings_test.cpp
@@ -91,10 +91,10 @@ namespace {
ASSERT_EQUALS(settings.getChunksize(), 1);
BSONObj objBalancer = BSON(SettingsType::key("balancer") <<
- SettingsType::balancerStopped(true) <<
- SettingsType::balancerActiveWindow(BSON("start" << "23:00" <<
- "stop" << "6:00" )) <<
- SettingsType::migrationWriteConcern(BSON("w" << 2)));
+ SettingsType::balancerStopped(true) <<
+ SettingsType::balancerActiveWindow(BSON("start" << "23:00" <<
+ "stop" << "6:00" )) <<
+ SettingsType::secondaryThrottle(true));
ASSERT(settings.parseBSON(objBalancer, &errMsg));
ASSERT_EQUALS(errMsg, "");
ASSERT_TRUE(settings.isValid(NULL));
@@ -102,28 +102,7 @@ namespace {
ASSERT_EQUALS(settings.getBalancerStopped(), true);
ASSERT_EQUALS(settings.getBalancerActiveWindow(), BSON("start" << "23:00" <<
"stop" << "6:00" ));
- ASSERT(settings.getSecondaryThrottle());
- ASSERT_EQUALS(0, settings.getMigrationWriteConcern().woCompare(BSON("w" << 2)));
- }
-
- TEST(Validity, ValidWithDeprecatedThrottle) {
- SettingsType settings;
- BSONObj objChunksize = BSON(SettingsType::key("chunksize") <<
- SettingsType::chunksize(1));
- string errMsg;
- ASSERT(settings.parseBSON(objChunksize, &errMsg));
- ASSERT_EQUALS(errMsg, "");
- ASSERT_TRUE(settings.isValid(NULL));
- ASSERT_EQUALS(settings.getKey(), "chunksize");
- ASSERT_EQUALS(settings.getChunksize(), 1);
-
- BSONObj objBalancer = BSON(SettingsType::key("balancer") <<
- SettingsType::deprecated_secondaryThrottle(true));
- ASSERT(settings.parseBSON(objBalancer, &errMsg));
- ASSERT_EQUALS(errMsg, "");
- ASSERT_TRUE(settings.isValid(NULL));
- ASSERT_EQUALS(settings.getKey(), "balancer");
- ASSERT(settings.getSecondaryThrottle());
+ ASSERT_EQUALS(settings.getSecondaryThrottle(), true);
}
TEST(Validity, BadType) {