diff options
Diffstat (limited to 'src/mongo/db/repl/resync.cpp')
-rw-r--r-- | src/mongo/db/repl/resync.cpp | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/src/mongo/db/repl/resync.cpp b/src/mongo/db/repl/resync.cpp index 16e385c9b48..7581c572cfb 100644 --- a/src/mongo/db/repl/resync.cpp +++ b/src/mongo/db/repl/resync.cpp @@ -35,100 +35,100 @@ namespace mongo { - using std::string; - using std::stringstream; +using std::string; +using std::stringstream; namespace repl { - // operator requested resynchronization of replication (on a slave or secondary). {resync: 1} - class CmdResync : public Command { - public: - virtual bool slaveOk() const { - return true; - } - virtual bool adminOnly() const { - return true; - } - virtual bool isWriteCommandForConfigServer() const { return true; } - virtual void addRequiredPrivileges(const std::string& dbname, - const BSONObj& cmdObj, - std::vector<Privilege>* out) { - ActionSet actions; - actions.addAction(ActionType::resync); - out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); - } +// operator requested resynchronization of replication (on a slave or secondary). {resync: 1} +class CmdResync : public Command { +public: + virtual bool slaveOk() const { + return true; + } + virtual bool adminOnly() const { + return true; + } + virtual bool isWriteCommandForConfigServer() const { + return true; + } + virtual void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector<Privilege>* out) { + ActionSet actions; + actions.addAction(ActionType::resync); + out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); + } - void help(stringstream& h) const { - h << "resync (from scratch) a stale slave or replica set secondary node.\n"; - } + void help(stringstream& h) const { + h << "resync (from scratch) a stale slave or replica set secondary node.\n"; + } - CmdResync() : Command("resync") { } - virtual bool run(OperationContext* txn, - const string& dbname, - BSONObj& cmdObj, - int, - string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + CmdResync() : Command("resync") {} + virtual bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result, + bool fromRepl) { + ScopedTransaction transaction(txn, MODE_X); + Lock::GlobalWrite globalWriteLock(txn->lockState()); - ScopedTransaction transaction(txn, MODE_X); - Lock::GlobalWrite globalWriteLock(txn->lockState()); - - ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); - if (getGlobalReplicationCoordinator()->getSettings().usingReplSets()) { - const MemberState memberState = replCoord->getMemberState(); - if (memberState.startup()) { - return appendCommandStatus(result, Status(ErrorCodes::NotYetInitialized, - "no replication yet active")); - } - if (memberState.primary() || - !replCoord->setFollowerMode(MemberState::RS_STARTUP2)) { - return appendCommandStatus(result, Status(ErrorCodes::NotSecondary, - "primaries cannot resync")); - } - BackgroundSync::get()->setInitialSyncRequestedFlag(true); - return true; + ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); + if (getGlobalReplicationCoordinator()->getSettings().usingReplSets()) { + const MemberState memberState = replCoord->getMemberState(); + if (memberState.startup()) { + return appendCommandStatus( + result, Status(ErrorCodes::NotYetInitialized, "no replication yet active")); } - - // below this comment pertains only to master/slave replication - if ( cmdObj.getBoolField( "force" ) ) { - if ( !waitForSyncToFinish(txn, errmsg ) ) - return false; - replAllDead = "resync forced"; + if (memberState.primary() || !replCoord->setFollowerMode(MemberState::RS_STARTUP2)) { + return appendCommandStatus( + result, Status(ErrorCodes::NotSecondary, "primaries cannot resync")); } - // TODO(dannenberg) replAllDead is bad and should be removed when masterslave is removed - if (!replAllDead) { - errmsg = "not dead, no need to resync"; - return false; - } - if ( !waitForSyncToFinish(txn, errmsg ) ) - return false; - - ReplSource::forceResyncDead( txn, "client" ); - result.append( "info", "triggered resync for all sources" ); - + BackgroundSync::get()->setInitialSyncRequestedFlag(true); return true; } - bool waitForSyncToFinish(OperationContext* txn, string &errmsg) const { - // Wait for slave thread to finish syncing, so sources will be be - // reloaded with new saved state on next pass. - Timer t; - while ( 1 ) { - if ( syncing == 0 || t.millis() > 30000 ) - break; - { - Lock::TempRelease t(txn->lockState()); - relinquishSyncingSome = 1; - sleepmillis(1); - } - } - if ( syncing ) { - errmsg = "timeout waiting for sync() to finish"; + // below this comment pertains only to master/slave replication + if (cmdObj.getBoolField("force")) { + if (!waitForSyncToFinish(txn, errmsg)) return false; + replAllDead = "resync forced"; + } + // TODO(dannenberg) replAllDead is bad and should be removed when masterslave is removed + if (!replAllDead) { + errmsg = "not dead, no need to resync"; + return false; + } + if (!waitForSyncToFinish(txn, errmsg)) + return false; + + ReplSource::forceResyncDead(txn, "client"); + result.append("info", "triggered resync for all sources"); + + return true; + } + + bool waitForSyncToFinish(OperationContext* txn, string& errmsg) const { + // Wait for slave thread to finish syncing, so sources will be be + // reloaded with new saved state on next pass. + Timer t; + while (1) { + if (syncing == 0 || t.millis() > 30000) + break; + { + Lock::TempRelease t(txn->lockState()); + relinquishSyncingSome = 1; + sleepmillis(1); } - return true; } - } cmdResync; -} // namespace repl -} // namespace mongo + if (syncing) { + errmsg = "timeout waiting for sync() to finish"; + return false; + } + return true; + } +} cmdResync; +} // namespace repl +} // namespace mongo |