diff options
author | Randolph Tan <randolph@10gen.com> | 2014-07-15 16:13:31 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2014-07-15 16:13:50 -0400 |
commit | 37f2a1e3b724dbd9e1f8eafd4ac87c5bf613c048 (patch) | |
tree | 2bcd919c93803f294d562761c2920fc9dd712bcd /src/mongo/db | |
parent | d60fd22dec1c0bd104622eab463cdbba18bf11a9 (diff) | |
download | mongo-37f2a1e3b724dbd9e1f8eafd4ac87c5bf613c048.tar.gz |
Revert "SERVER-14041 enhance secondaryThrottle parameter"
This reverts commit fa1233fbe4a48ef0675820f381987f1df4f42f75.
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/commands/cleanup_orphaned_cmd.cpp | 59 | ||||
-rw-r--r-- | src/mongo/db/dbhelpers.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/dbhelpers.h | 5 | ||||
-rw-r--r-- | src/mongo/db/field_parser.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/range_deleter.cpp | 27 | ||||
-rw-r--r-- | src/mongo/db/range_deleter.h | 9 | ||||
-rw-r--r-- | src/mongo/db/range_deleter_db_env.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/range_deleter_test.cpp | 101 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator.h | 11 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_hybrid.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_hybrid.h | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_impl.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_impl.h | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_legacy.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_legacy.h | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_mock.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_mock.h | 3 | ||||
-rw-r--r-- | src/mongo/db/write_concern_options.cpp | 103 | ||||
-rw-r--r-- | src/mongo/db/write_concern_options.h | 47 |
19 files changed, 69 insertions, 359 deletions
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, - ¬ifyDone, - NULL /* errMsg not needed */)); + ASSERT_TRUE(deleter.queueDelete(ns, BSON("x" << 0), BSON("x" << 10), BSON("x" << 1), + true, ¬ifyDone, 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, - ¬ifyDone, - NULL /* errMsg not needed */)); + ASSERT_TRUE(deleter.queueDelete(ns, BSON("x" << 0), BSON("x" << 10), BSON("x" << 1), + true, ¬ifyDone, 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, ¬ifyDone1, NULL /* don't care errMsg */)); @@ -288,7 +276,7 @@ namespace { BSON("x" << 20), BSON("x" << 30), BSON("x" << 1), - dummyWriteConcern, + true, ¬ifyDone2, NULL /* don't care errMsg */)); @@ -297,7 +285,7 @@ namespace { BSON("x" << 30), BSON("x" << 40), BSON("x" << 1), - dummyWriteConcern, + true, ¬ifyDone3, 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, - ¬ifyDone, - NULL /* errMsg not needed */); + deleter.queueDelete(ns, BSON("x" << 0), BSON("x" << 10), BSON("x" << 1), + false, ¬ifyDone, 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; }; |