diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/repl/replication_info.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/repl/replication_info.cpp')
-rw-r--r-- | src/mongo/db/repl/replication_info.cpp | 332 |
1 files changed, 168 insertions, 164 deletions
diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index 343a939fc95..57b403aa434 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -50,189 +50,193 @@ namespace mongo { - using std::unique_ptr; - using std::list; - using std::string; - using std::stringstream; +using std::unique_ptr; +using std::list; +using std::string; +using std::stringstream; namespace repl { - void appendReplicationInfo(OperationContext* txn, BSONObjBuilder& result, int level) { - ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); - if (replCoord->getSettings().usingReplSets()) { - IsMasterResponse isMasterResponse; - replCoord->fillIsMasterForReplSet(&isMasterResponse); - result.appendElements(isMasterResponse.toBSON()); - if (level) { - replCoord->appendSlaveInfoData(&result); - } - return; - } - - // TODO(dannenberg) replAllDead is bad and should be removed when master slave is removed - if (replAllDead) { - result.append("ismaster", 0); - string s = string("dead: ") + replAllDead; - result.append("info", s); +void appendReplicationInfo(OperationContext* txn, BSONObjBuilder& result, int level) { + ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); + if (replCoord->getSettings().usingReplSets()) { + IsMasterResponse isMasterResponse; + replCoord->fillIsMasterForReplSet(&isMasterResponse); + result.appendElements(isMasterResponse.toBSON()); + if (level) { + replCoord->appendSlaveInfoData(&result); } - else { - result.appendBool("ismaster", - getGlobalReplicationCoordinator()->isMasterForReportingPurposes()); + return; + } + + // TODO(dannenberg) replAllDead is bad and should be removed when master slave is removed + if (replAllDead) { + result.append("ismaster", 0); + string s = string("dead: ") + replAllDead; + result.append("info", s); + } else { + result.appendBool("ismaster", + getGlobalReplicationCoordinator()->isMasterForReportingPurposes()); + } + + if (level) { + BSONObjBuilder sources(result.subarrayStart("sources")); + + int n = 0; + list<BSONObj> src; + { + const char* localSources = "local.sources"; + AutoGetCollectionForRead ctx(txn, localSources); + unique_ptr<PlanExecutor> exec( + InternalPlanner::collectionScan(txn, localSources, ctx.getCollection())); + BSONObj obj; + PlanExecutor::ExecState state; + while (PlanExecutor::ADVANCED == (state = exec->getNext(&obj, NULL))) { + src.push_back(obj); + } } - - if (level) { - BSONObjBuilder sources( result.subarrayStart( "sources" ) ); - - int n = 0; - list<BSONObj> src; + + for (list<BSONObj>::const_iterator i = src.begin(); i != src.end(); i++) { + BSONObj s = *i; + BSONObjBuilder bb; + bb.append(s["host"]); + string sourcename = s["source"].valuestr(); + if (sourcename != "main") + bb.append(s["source"]); { - const char* localSources = "local.sources"; - AutoGetCollectionForRead ctx(txn, localSources); - unique_ptr<PlanExecutor> exec( - InternalPlanner::collectionScan(txn, localSources, ctx.getCollection())); - BSONObj obj; - PlanExecutor::ExecState state; - while (PlanExecutor::ADVANCED == (state = exec->getNext(&obj, NULL))) { - src.push_back(obj); - } + BSONElement e = s["syncedTo"]; + BSONObjBuilder t(bb.subobjStart("syncedTo")); + t.appendDate("time", e.timestampTime()); + t.append("inc", e.timestampInc()); + t.done(); } - - for( list<BSONObj>::const_iterator i = src.begin(); i != src.end(); i++ ) { - BSONObj s = *i; - BSONObjBuilder bb; - bb.append( s["host"] ); - string sourcename = s["source"].valuestr(); - if ( sourcename != "main" ) - bb.append( s["source"] ); - { - BSONElement e = s["syncedTo"]; - BSONObjBuilder t( bb.subobjStart( "syncedTo" ) ); - t.appendDate( "time" , e.timestampTime() ); - t.append( "inc" , e.timestampInc() ); - t.done(); - } - - if ( level > 1 ) { - wassert(!txn->lockState()->isLocked()); - // note: there is no so-style timeout on this connection; perhaps we should have one. - ScopedDbConnection conn(s["host"].valuestr()); - - DBClientConnection *cliConn = dynamic_cast< DBClientConnection* >( &conn.conn() ); - if ( cliConn && replAuthenticate(cliConn) ) { - BSONObj first = conn->findOne( (string)"local.oplog.$" + sourcename, - Query().sort( BSON( "$natural" << 1 ) ) ); - BSONObj last = conn->findOne( (string)"local.oplog.$" + sourcename, - Query().sort( BSON( "$natural" << -1 ) ) ); - bb.appendDate( "masterFirst" , first["ts"].timestampTime() ); - bb.appendDate( "masterLast" , last["ts"].timestampTime() ); - const auto lag = - (last["ts"].timestampTime() - s["syncedTo"].timestampTime()); - bb.append("lagSeconds", durationCount<Milliseconds>(lag) / 1000.0); - } - conn.done(); + + if (level > 1) { + wassert(!txn->lockState()->isLocked()); + // note: there is no so-style timeout on this connection; perhaps we should have one. + ScopedDbConnection conn(s["host"].valuestr()); + + DBClientConnection* cliConn = dynamic_cast<DBClientConnection*>(&conn.conn()); + if (cliConn && replAuthenticate(cliConn)) { + BSONObj first = conn->findOne((string) "local.oplog.$" + sourcename, + Query().sort(BSON("$natural" << 1))); + BSONObj last = conn->findOne((string) "local.oplog.$" + sourcename, + Query().sort(BSON("$natural" << -1))); + bb.appendDate("masterFirst", first["ts"].timestampTime()); + bb.appendDate("masterLast", last["ts"].timestampTime()); + const auto lag = (last["ts"].timestampTime() - s["syncedTo"].timestampTime()); + bb.append("lagSeconds", durationCount<Milliseconds>(lag) / 1000.0); } - - sources.append( BSONObjBuilder::numStr( n++ ) , bb.obj() ); + conn.done(); } - - sources.done(); - replCoord->appendSlaveInfoData(&result); + sources.append(BSONObjBuilder::numStr(n++), bb.obj()); } + + sources.done(); + + replCoord->appendSlaveInfoData(&result); } - - class ReplicationInfoServerStatus : public ServerStatusSection { - public: - ReplicationInfoServerStatus() : ServerStatusSection( "repl" ){} - bool includeByDefault() const { return true; } - - BSONObj generateSection(OperationContext* txn, - const BSONElement& configElement) const { - - if (!getGlobalReplicationCoordinator()->isReplEnabled()) { - return BSONObj(); - } - - int level = configElement.numberInt(); - - BSONObjBuilder result; - appendReplicationInfo(txn, result, level); - getGlobalReplicationCoordinator()->processReplSetGetRBID(&result); - - return result.obj(); +} + +class ReplicationInfoServerStatus : public ServerStatusSection { +public: + ReplicationInfoServerStatus() : ServerStatusSection("repl") {} + bool includeByDefault() const { + return true; + } + + BSONObj generateSection(OperationContext* txn, const BSONElement& configElement) const { + if (!getGlobalReplicationCoordinator()->isReplEnabled()) { + return BSONObj(); } - } replicationInfoServerStatus; + int level = configElement.numberInt(); - class OplogInfoServerStatus : public ServerStatusSection { - public: - OplogInfoServerStatus() : ServerStatusSection( "oplog" ){} - bool includeByDefault() const { return false; } + BSONObjBuilder result; + appendReplicationInfo(txn, result, level); + getGlobalReplicationCoordinator()->processReplSetGetRBID(&result); - BSONObj generateSection(OperationContext* txn, - const BSONElement& configElement) const { + return result.obj(); + } - ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); - if (!replCoord->isReplEnabled()) { - return BSONObj(); - } +} replicationInfoServerStatus; - BSONObjBuilder result; - // TODO(siyuan) Output term of OpTime - result.append("latestOptime", replCoord->getMyLastOptime().getTimestamp()); - - const std::string& oplogNS = - replCoord->getReplicationMode() == ReplicationCoordinator::modeReplSet ? - rsOplogName : masterSlaveOplogName; - BSONObj o; - uassert(17347, - "Problem reading earliest entry from oplog", - Helpers::getSingleton(txn, oplogNS.c_str(), o)); - result.append("earliestOptime", o["ts"].timestamp()); - return result.obj(); - } - } oplogInfoServerStatus; +class OplogInfoServerStatus : public ServerStatusSection { +public: + OplogInfoServerStatus() : ServerStatusSection("oplog") {} + bool includeByDefault() const { + return false; + } - class CmdIsMaster : public Command { - public: - virtual bool requiresAuth() { return false; } - virtual bool slaveOk() const { - return true; - } - virtual void help( stringstream &help ) const { - help << "Check if this server is primary for a replica pair/set; also if it is --master or --slave in simple master/slave setups.\n"; - help << "{ isMaster : 1 }"; - } - virtual bool isWriteCommandForConfigServer() const { return false; } - virtual void addRequiredPrivileges(const std::string& dbname, - const BSONObj& cmdObj, - std::vector<Privilege>* out) {} // No auth required - CmdIsMaster() : Command("isMaster", true, "ismaster") { } - virtual bool run(OperationContext* txn, - const string&, - BSONObj& cmdObj, - int, - string& errmsg, - BSONObjBuilder& result) { - /* currently request to arbiter is (somewhat arbitrarily) an ismaster request that is not - authenticated. - */ - if ( cmdObj["forShell"].trueValue() ) - LastError::get(txn->getClient()).disable(); - - appendReplicationInfo(txn, result, 0); - - result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize); - result.appendNumber("maxMessageSizeBytes", MaxMessageSizeBytes); - result.appendNumber("maxWriteBatchSize", BatchedCommandRequest::kMaxWriteBatchSize); - result.appendDate("localTime", jsTime()); - result.append("maxWireVersion", maxWireVersion); - result.append("minWireVersion", minWireVersion); - return true; + BSONObj generateSection(OperationContext* txn, const BSONElement& configElement) const { + ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); + if (!replCoord->isReplEnabled()) { + return BSONObj(); } - } cmdismaster; - OpCounterServerStatusSection replOpCounterServerStatusSection( "opcountersRepl", &replOpCounters ); + BSONObjBuilder result; + // TODO(siyuan) Output term of OpTime + result.append("latestOptime", replCoord->getMyLastOptime().getTimestamp()); + + const std::string& oplogNS = + replCoord->getReplicationMode() == ReplicationCoordinator::modeReplSet + ? rsOplogName + : masterSlaveOplogName; + BSONObj o; + uassert(17347, + "Problem reading earliest entry from oplog", + Helpers::getSingleton(txn, oplogNS.c_str(), o)); + result.append("earliestOptime", o["ts"].timestamp()); + return result.obj(); + } +} oplogInfoServerStatus; + +class CmdIsMaster : public Command { +public: + virtual bool requiresAuth() { + return false; + } + virtual bool slaveOk() const { + return true; + } + virtual void help(stringstream& help) const { + help << "Check if this server is primary for a replica pair/set; also if it is --master or " + "--slave in simple master/slave setups.\n"; + help << "{ isMaster : 1 }"; + } + virtual bool isWriteCommandForConfigServer() const { + return false; + } + virtual void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector<Privilege>* out) {} // No auth required + CmdIsMaster() : Command("isMaster", true, "ismaster") {} + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { + /* currently request to arbiter is (somewhat arbitrarily) an ismaster request that is not + authenticated. + */ + if (cmdObj["forShell"].trueValue()) + LastError::get(txn->getClient()).disable(); + + appendReplicationInfo(txn, result, 0); + + result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize); + result.appendNumber("maxMessageSizeBytes", MaxMessageSizeBytes); + result.appendNumber("maxWriteBatchSize", BatchedCommandRequest::kMaxWriteBatchSize); + result.appendDate("localTime", jsTime()); + result.append("maxWireVersion", maxWireVersion); + result.append("minWireVersion", minWireVersion); + return true; + } +} cmdismaster; + +OpCounterServerStatusSection replOpCounterServerStatusSection("opcountersRepl", &replOpCounters); -} // namespace repl -} // namespace mongo +} // namespace repl +} // namespace mongo |