You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2011/06/05 05:29:44 UTC
svn commit: r1131612 - in /incubator/mesos/trunk/src: ft_messaging.cpp
ft_messaging.hpp leader_detector.cpp leader_detector.hpp master.cpp
master.hpp nexus_sched.cpp slave.cpp slave.hpp task_info.hpp
url_processor.cpp
Author: benh
Date: Sun Jun 5 03:29:43 2011
New Revision: 1131612
URL: http://svn.apache.org/viewvc?rev=1131612&view=rev
Log:
Cleaned up my code after benh told me about Nexus coding conventions.
Modified:
incubator/mesos/trunk/src/ft_messaging.cpp
incubator/mesos/trunk/src/ft_messaging.hpp
incubator/mesos/trunk/src/leader_detector.cpp
incubator/mesos/trunk/src/leader_detector.hpp
incubator/mesos/trunk/src/master.cpp
incubator/mesos/trunk/src/master.hpp
incubator/mesos/trunk/src/nexus_sched.cpp
incubator/mesos/trunk/src/slave.cpp
incubator/mesos/trunk/src/slave.hpp
incubator/mesos/trunk/src/task_info.hpp
incubator/mesos/trunk/src/url_processor.cpp
Modified: incubator/mesos/trunk/src/ft_messaging.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/ft_messaging.cpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/ft_messaging.cpp (original)
+++ incubator/mesos/trunk/src/ft_messaging.cpp Sun Jun 5 03:29:43 2011
@@ -16,19 +16,19 @@ using namespace nexus::internal;
using namespace std;
FTMessaging *FTMessaging::getInstance() {
- if (instance==NULL)
+ if (instance == NULL)
instance = new FTMessaging();
return instance;
}
-FTMessaging *FTMessaging::getInstance(PID _master) {
- if (instance==NULL)
+FTMessaging *FTMessaging::getInstance(const PID &_master) {
+ if (instance == NULL)
instance = new FTMessaging(_master);
return instance;
}
-FTMessaging *FTMessaging::getInstance(string _master) {
- if (instance==NULL) {
+FTMessaging *FTMessaging::getInstance(const string &_master) {
+ if (instance == NULL) {
PID mPid;
istringstream ss(_master);
if (!(ss >> mPid)) {
@@ -40,10 +40,10 @@ FTMessaging *FTMessaging::getInstance(st
return instance;
}
-FTMessaging::FTMessaging(PID _master) :
+FTMessaging::FTMessaging(const PID &_master) :
master(_master), msgId(0)
{
- srand(time(0));
+ srand( time(0) );
char s[50];
sprintf(s, "%09i", (int)rand());
uniqPrefix = s;
@@ -70,7 +70,7 @@ void FTMessaging::gotAck(const string &f
}
void FTMessaging::deleteMessage(const string &ftId) {
- struct FTStoredMsg & msg = outMsgs[ftId];
+ struct FTStoredMsg &msg = outMsgs[ftId];
if (msg.callback != NULL)
delete msg.callback; // ugly and sad. shared_ptr would have been better
outMsgs.erase(ftId);
@@ -99,9 +99,9 @@ void FTMessaging::sendOutstanding() {
}
-// Careful: not idempotent function.
-bool FTMessaging::acceptMessage(string ftId, string from) {
- if (inMsgs.find(from)==inMsgs.end()) {
+// NB: not an idempotent method.
+bool FTMessaging::acceptMessage(const string &ftId, const string &from) {
+ if (inMsgs.find(from) == inMsgs.end()) {
DLOG(INFO) << "FT: new msgs seq: " << ftId;
inMsgs[from] = ftId;
return true;
@@ -109,12 +109,12 @@ bool FTMessaging::acceptMessage(string f
string oldSeq = inMsgs[from];
string oldRnd = oldSeq;
int pos;
- if ((pos=oldSeq.find_last_of(':'))!=string::npos ) {
- oldSeq.erase(0,pos+1);
- oldRnd.erase(pos,255);
+ if ( (pos = oldSeq.find_last_of(':')) != string::npos ) {
+ oldSeq.erase(0, pos + 1);
+ oldRnd.erase(pos, 255);
long seqNr = lexical_cast<long>(oldSeq);
- string nextFtId = oldRnd+":"+lexical_cast<string>(seqNr+1);
- if (nextFtId==ftId) {
+ string nextFtId = oldRnd + ":" + lexical_cast<string>(seqNr+1);
+ if (nextFtId == ftId) {
DLOG(INFO) << "FT: match - got ftId:" << ftId << " expecting " << nextFtId;
inMsgs[from] = nextFtId;
return true;
@@ -129,7 +129,7 @@ bool FTMessaging::acceptMessage(string f
}
}
-bool FTMessaging::acceptMessageAckTo(PID to, string ftId, string from) {
+bool FTMessaging::acceptMessageAckTo(const PID &to, const string &ftId, const string &from) {
DLOG(INFO) << "FT: Received msg with id: " << ftId << " sending FT_RELAY_ACK to " << to;
bool res = acceptMessage(from, ftId);
@@ -145,7 +145,7 @@ bool FTMessaging::acceptMessageAckTo(PID
return res;
}
-bool FTMessaging::acceptMessageAck(string ftId, string from) {
+bool FTMessaging::acceptMessageAck(const string &ftId, const string &from) {
return acceptMessageAckTo(master, ftId, from);
}
Modified: incubator/mesos/trunk/src/ft_messaging.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/ft_messaging.hpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/ft_messaging.hpp (original)
+++ incubator/mesos/trunk/src/ft_messaging.hpp Sun Jun 5 03:29:43 2011
@@ -6,49 +6,14 @@
#include <boost/lexical_cast.hpp>
#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
-#include <process.hpp>
-#include <iostream>
-#include <unistd.h>
-#include <climits>
-#include <cstdlib>
-#include <zookeeper.h>
#include <glog/logging.h>
#include <ctime>
-#include <cstdlib>
-#include "leader_detector.hpp"
-
-
-#include <dirent.h>
-#include <libgen.h>
-#include <netdb.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <strings.h>
-
-#include <iostream>
-#include <list>
-#include <sstream>
-#include <vector>
-
-#include <arpa/inet.h>
-
-#include <boost/lexical_cast.hpp>
-#include <boost/unordered_set.hpp>
-#include <boost/unordered_map.hpp>
-
-#include <glog/logging.h>
-
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
#include <process.hpp>
+#include "leader_detector.hpp"
#include "messages.hpp"
#include "tuple.hpp"
#include "foreach.hpp"
-#include <ctime>
namespace nexus { namespace internal {
@@ -81,10 +46,10 @@ public:
*/
struct FTStoredMsg {
- FTStoredMsg(const string &_ftId, const string &_data, const MSGID &_id, FTCallback *_cb=NULL) :
+ FTStoredMsg(const string &_ftId, const string &_data, const MSGID &_id, FTCallback *_cb = NULL) :
ftId(_ftId), data(_data), id(_id), count(1), ts(time(0)), callback(_cb) {}
- FTStoredMsg(bool _cb=false) : ftId(""), data(""), id(), count(1), ts(time(0)), callback(NULL) {}
+ FTStoredMsg(bool _cb = false) : ftId(""), data(""), id(), count(1), ts(time(0)), callback(NULL) {}
string ftId;
string data;
@@ -110,13 +75,13 @@ public:
* @return A singleton instance of this class.
* @param master libprocess PID to current master
*/
- static FTMessaging *getInstance(PID master);
+ static FTMessaging *getInstance(const PID &master);
/**
* @return A singleton instance of this class.
* @param masterStr string representing libprocess PID to current master (no nexus:// prefix)
*/
- static FTMessaging *getInstance(string masterStr);
+ static FTMessaging *getInstance(const string &masterStr);
/**
* Reliably sends a message with a given fault tolerant id
@@ -126,7 +91,7 @@ public:
* @param msgTuple libprocess tuple<ID>
* @param FTCallback if not null, then FTCallback will be called by sendOutstanding()
*/
- template<MSGID ID> void reliableSend(const string &ftId, const tuple<ID> &msgTuple, FTCallback *callback=NULL)
+ template<MSGID ID> void reliableSend(const string &ftId, const tuple<ID> &msgTuple, FTCallback *callback = NULL)
{
DLOG(INFO) << "FT: sending " << ftId;
string msgStr = Tuple<EmptyClass>::tupleToString(msgTuple);
@@ -156,7 +121,7 @@ public:
* @param from libprocess PID string representing the original sender of the message
* @return true if message has not been received before and it is the next message expected to be received, false otherwise.
*/
- bool acceptMessage(string ftId, string from);
+ bool acceptMessage(const string &ftId, const string &from);
/**
* Same as acceptMessage, but also sends an ACK back to the original sender if it returns true.
@@ -164,7 +129,7 @@ public:
* @param from libprocess PID string representing the original sender of the message
* @return true if message has not been received before and it is the next message expected to be received, false otherwise.
*/
- bool acceptMessageAck(string ftId, string from);
+ bool acceptMessageAck(const string &ftId, const string &from);
/**
* Same as acceptMessageAck, but explicitly specifies the pid of the node that should receive the ack.
@@ -173,7 +138,7 @@ public:
* @param from libprocess PID string representing the original sender of the message
* @return true if message has not been received before and it is the next message expected to be received, false otherwise.
*/
- bool acceptMessageAckTo(PID to, string ftId, string from);
+ bool acceptMessageAckTo(const PID &to, const string &ftId, const string &from);
/**
* @return a new unique FT ID for a message to be sent
@@ -210,9 +175,11 @@ private:
void deleteMessage(const string &ftId);
FTMessaging();
- FTMessaging(PID _master);
+
+ FTMessaging(const PID &_master);
FTMessaging(FTMessaging const ©) {}
+
FTMessaging &operator= (FTMessaging const ©) {}
};
Modified: incubator/mesos/trunk/src/leader_detector.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/leader_detector.cpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/leader_detector.cpp (original)
+++ incubator/mesos/trunk/src/leader_detector.cpp Sun Jun 5 03:29:43 2011
@@ -15,11 +15,12 @@ void LeaderDetector::initWatchWrap(zhand
// TODO ALI: Make this thread safe, will be called by ZooKeeper thread
void LeaderDetector::leaderWatchWrap(zhandle_t *zh, int type, int state, const char *path, void *watcherCtx) {
- ((LeaderDetector *)watcherCtx)->leaderWatch(zh, type, state, path);
+ ((LeaderDetector *) watcherCtx)->leaderWatch(zh, type, state, path);
}
-LeaderDetector::LeaderDetector(string server, bool contendLeader, string pid, LeaderListener *ll) :
+LeaderDetector::LeaderDetector(const string &server, const bool contendLeader, const string &pid,
+ LeaderListener *ll) :
leaderListener(ll),
zh(NULL),myPID(pid),
zooserver(server),currentLeaderSeq(""), mySeq("")
@@ -27,7 +28,7 @@ LeaderDetector::LeaderDetector(string se
zh = zookeeper_init(zooserver.c_str(), initWatchWrap, 1000, 0, NULL, 0);
LOG(INFO) << "Initialized ZooKeeper";
- LOG_IF(ERROR, zh==NULL)<<"zookeeper_init returned error:";
+ LOG_IF(ERROR, zh == NULL) << "zookeeper_init returned error:";
char buf[100];
@@ -36,10 +37,11 @@ LeaderDetector::LeaderDetector(string se
if (contendLeader) {
ret = zoo_create(zh, "/nxmaster/", myPID.c_str(), myPID.length(), &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE | ZOO_EPHEMERAL, buf, 100);
- LOG_IF(ERROR, ret!=ZOK)<<"zoo_create() ephemeral/sequence returned error:"<<ret;
- if (ret==ZOK) {
+ LOG_IF(ERROR, ret != ZOK) << "zoo_create() ephemeral/sequence returned error:" << ret;
+
+ if (ret == ZOK) {
setMySeq(string(buf));
- LOG(INFO)<<"Created ephemeral/sequence:"<<mySeq;
+ LOG(INFO) << "Created ephemeral/sequence:" << mySeq;
}
}
@@ -48,17 +50,17 @@ LeaderDetector::LeaderDetector(string se
void LeaderDetector::leaderWatch(zhandle_t *zh, int type, int state, const char *path) {
if (type == ZOO_CREATED_EVENT) {
- LOG(INFO)<<"Leader Watch Event type: ZOO_CREATED_EVENT";
+ DLOG(INFO) << "Leader Watch Event type: ZOO_CREATED_EVENT";
} else if (type == ZOO_DELETED_EVENT) {
- LOG(INFO)<<"Leader Watch Event type: ZOO_DELETED_EVENT";
+ DLOG(INFO) << "Leader Watch Event type: ZOO_DELETED_EVENT";
} else if (type == ZOO_CHANGED_EVENT) {
- LOG(INFO)<<"Leader Watch Event type: ZOO_CHANGED_EVENT";
+ DLOG(INFO) << "Leader Watch Event type: ZOO_CHANGED_EVENT";
} else if (type == ZOO_CHILD_EVENT) {
- LOG(INFO)<<"Leader Watch Event type: ZOO_CHILD_EVENT";
+ DLOG(INFO) << "Leader Watch Event type: ZOO_CHILD_EVENT";
} else if (type == ZOO_SESSION_EVENT) {
- LOG(INFO)<<"Leader Watch Event type: ZOO_SESSION_EVENT";
+ DLOG(INFO) << "Leader Watch Event type: ZOO_SESSION_EVENT";
} else if (type == ZOO_NOTWATCHING_EVENT) {
- LOG(INFO)<<"Leader Watch Event type: ZOO_NOTWATCHING_EVENT";
+ DLOG(INFO) << "Leader Watch Event type: ZOO_NOTWATCHING_EVENT";
}
detectLeader();
}
@@ -66,21 +68,21 @@ void LeaderDetector::leaderWatch(zhandle
bool LeaderDetector::detectLeader() {
String_vector sv;
int ret = zoo_wget_children(zh, "/nxmaster", leaderWatchWrap, (void*)this, &sv);
- LOG_IF(ERROR, ret!=ZOK)<<"zoo_wget_children (get leaders) returned error:"<<ret;
- LOG_IF(INFO, ret==ZOK)<<"zoo_wget_children returned "<<sv.count<<" registered leaders";
+ LOG_IF(ERROR, ret != ZOK) << "zoo_wget_children (get leaders) returned error:" << ret;
+ LOG_IF(INFO, ret == ZOK) << "zoo_wget_children returned " << sv.count << " registered leaders";
string leader;
long min = LONG_MAX;
- for (int x=0; x<sv.count; x++) {
+ for (int x = 0; x<sv.count; x++) {
int i = atol(sv.data[x]);
- if (i<min) {
- min=i;
+ if (i < min) {
+ min = i;
leader = sv.data[x];
}
}
- if (leader!=currentLeaderSeq) {
- currentLeaderSeq=leader;
+ if (leader != currentLeaderSeq) {
+ currentLeaderSeq = leader;
string data = fetchLeaderPID(leader);
@@ -91,54 +93,41 @@ bool LeaderDetector::detectLeader() {
return 0;
}
-string LeaderDetector::fetchLeaderPID(string id) {
- if (id=="") {
+string LeaderDetector::fetchLeaderPID(const string &id) {
+ if (id == "") {
currentLeaderPID = "";
return currentLeaderPID;
}
- string path="/nxmaster/";
- path+=id;
+
+ string path = "/nxmaster/";
+ path += id;
char buf[100];
int buflen = sizeof(buf);
int ret = zoo_get(zh, path.c_str(), 0, buf, &buflen, NULL);
- LOG_IF(ERROR, ret!=ZOK)<<"zoo_get returned error:"<<ret;
- LOG_IF(INFO, ret==ZOK)<<"zoo_get leader data fetch returned "<<buf[0];
+ LOG_IF(ERROR, ret != ZOK) << "zoo_get returned error:" << ret;
+ LOG_IF(INFO, ret == ZOK) << "zoo_get leader data fetch returned " << buf[0];
string tmp(buf,buflen);
- currentLeaderPID=tmp;
+ currentLeaderPID = tmp;
return currentLeaderPID;
}
-string LeaderDetector::getCurrentLeaderSeq() {
+string LeaderDetector::getCurrentLeaderSeq() const {
return currentLeaderSeq;
}
-string LeaderDetector::getCurrentLeaderPID() {
+string LeaderDetector::getCurrentLeaderPID() const {
return currentLeaderPID;
}
-void LeaderDetector::newLeader(string leader, string leaderPID) {
- LOG(INFO)<<"New leader ephemeral_id:"<<leader<<" data:"<<leaderPID;
- if (leaderListener!=NULL)
+void LeaderDetector::newLeader(const string &leader, const string &leaderPID) {
+ LOG(INFO) << "New leader ephemeral_id:" << leader << " data:" << leaderPID;
+ if (leaderListener != NULL)
leaderListener->newLeaderElected(leader,leaderPID);
}
LeaderDetector::~LeaderDetector() {
int ret = zookeeper_close(zh);
- LOG_IF(ERROR, ret!=ZOK)<<"zookeeper_close returned error:"<<ret;
- LOG_IF(INFO, ret==ZOK)<<"zookeeper_close OK";
-}
-
-/*
-int main(int argc, char **argv) {
- string name="testing";
- if (argc==2)
- name=argv[1];
- LeaderDetector ld(1, name);
- string s = ld.getCurrentLeaderSeq();
- debug("Leader is "<<s<<endl<<flush);
-
- sleep(50);
- return 0;
+ LOG_IF(ERROR, ret != ZOK) << "zookeeper_close returned error:" << ret;
+ LOG_IF(INFO, ret == ZOK) << "zookeeper_close OK";
}
-*/
Modified: incubator/mesos/trunk/src/leader_detector.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/leader_detector.hpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/leader_detector.hpp (original)
+++ incubator/mesos/trunk/src/leader_detector.hpp Sun Jun 5 03:29:43 2011
@@ -20,7 +20,7 @@ public:
* @param zkId ZooKeeper sequence number of the new leader
* @param pidStr libprocess PID of the new leader
*/
- virtual void newLeaderElected(string zkId, string pidStr) = 0;
+ virtual void newLeaderElected(const string &zkId, const string &pidStr) = 0;
};
/**
@@ -36,17 +36,18 @@ public:
* @param pid string containing libprocess id of this node (needed if it becomes a leader)
* @param ll callback object which will be invoked each time a new leader is elected
*/
- LeaderDetector(string server, bool contendLeader=0, string pid="", LeaderListener * ll=NULL);
+ LeaderDetector(const string &server, const bool contendLeader = 0,
+ const string &pid = "", LeaderListener * ll = NULL);
/**
* @return ZooKeeper unique sequence number of the current leader.
*/
- string getCurrentLeaderSeq();
+ string getCurrentLeaderSeq() const;
/**
* @return libprocess PID of the current leader.
*/
- string getCurrentLeaderPID();
+ string getCurrentLeaderPID() const;
/**
* Registers a listener that gets callbacks when a new leader is elected.
@@ -73,16 +74,20 @@ private:
void setMySeq(string seq) { // converts "/nxmaster/000000131" to "000000131"
int pos;
- if ((pos=seq.find_last_of('/'))!=string::npos ) {
+ if ( (pos = seq.find_last_of('/')) != string::npos ) {
mySeq = seq.erase(0,pos+1);
} else
mySeq = "";
}
+
void leaderWatch(zhandle_t *zh, int type, int state, const char *path);
+
bool detectLeader();
- string fetchLeaderPID(string id);
- void newLeader(string leader,string leaderPID);
+
+ string fetchLeaderPID(const string &id);
+
+ void newLeader(const string &leader, const string &leaderPID);
LeaderListener *leaderListener;
zhandle_t *zh;
Modified: incubator/mesos/trunk/src/master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master.cpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master.cpp (original)
+++ incubator/mesos/trunk/src/master.cpp Sun Jun 5 03:29:43 2011
@@ -111,14 +111,14 @@ public:
}
-Master::Master(const string zk)
+Master::Master(const string &zk)
: leaderDetector(NULL), nextFrameworkId(0), nextSlaveId(0),
nextSlotOfferId(0), allocatorType("simple"), masterId(0)
{
- if (zk!="") {
+ if (zk != "") {
pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(zk);
if (urlPair.first == UrlProcessor::ZOO) {
- isFT=true;
+ isFT = true;
zkservers = urlPair.second;
} else {
LOG(ERROR) << "Failed to parse URL for ZooKeeper servers. URL must start with zoo:// or zoofile://";
@@ -129,14 +129,14 @@ Master::Master(const string zk)
}
-Master::Master(const string& _allocatorType, const string zk)
+Master::Master(const string& _allocatorType, const string &zk)
: leaderDetector(NULL), nextFrameworkId(0), nextSlaveId(0),
nextSlotOfferId(0), allocatorType(_allocatorType), masterId(0)
{
- if (zk!="") {
+ if (zk != "") {
pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(zk);
if (urlPair.first == UrlProcessor::ZOO) {
- isFT=true;
+ isFT = true;
zkservers = urlPair.second;
} else {
LOG(ERROR) << "Failed to parse URL for ZooKeeper servers. URL must start with zoo:// or zoofile://";
@@ -149,7 +149,7 @@ Master::Master(const string& _allocatorT
Master::~Master()
{
- if (isFT && leaderDetector!=NULL)
+ if (isFT && leaderDetector != NULL)
delete leaderDetector;
LOG(INFO) << "Shutting down master";
delete allocator;
@@ -284,13 +284,18 @@ void Master::operator () ()
LOG(INFO) << "Master started at nexus://" << self();
if (isFT) {
- LOG(INFO) << "Connecting to ZooKeeper at "<<zkservers;
+ LOG(INFO) << "Connecting to ZooKeeper at " << zkservers;
ostringstream lpid;
- lpid<<self();
+ lpid << self();
leaderDetector = new LeaderDetector(zkservers, true, lpid.str());
- masterId = lexical_cast<long>(leaderDetector->getMySeq());
- LOG(INFO)<<"Master ID:"<<masterId;
+ string myLeaderSeq = leaderDetector->getMySeq();
+ if (myLeaderSeq == "") {
+ LOG(FATAL) << "Cannot proceed since new FT master sequence number could not be fetched from ZK.";
+ exit(1);
+ }
+ masterId = lexical_cast<long>(myLeaderSeq);
+ LOG(INFO) << "Master ID:" << masterId;
}
allocator = createAllocator();
@@ -649,9 +654,9 @@ void Master::operator () ()
framework->removeExpiredFilters();
allocator->timerTick();
- // int cnts=0;
+ // int cnts = 0;
// foreachpair(_, Framework *framework, frameworks) {
- // DLOG(INFO)<<(cnts++)<<" resourceInUse:"<<framework->resources;
+ // DLOG(INFO) << (cnts++) << " resourceInUse:" << framework->resources;
// }
break;
}
Modified: incubator/mesos/trunk/src/master.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master.hpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master.hpp (original)
+++ incubator/mesos/trunk/src/master.hpp Sun Jun 5 03:29:43 2011
@@ -116,7 +116,7 @@ struct Framework
// or 0 for slaves that we want to keep filtered forever
unordered_map<Slave *, time_t> slaveFilter;
- Framework(const PID &_pid, FrameworkID _id="")
+ Framework(const PID &_pid, FrameworkID _id = "")
: pid(_pid), id(_id), active(true)
{
time(&connectTime);
@@ -205,7 +205,7 @@ struct Slave
unordered_map<pair<FrameworkID, TaskID>, TaskInfo *> tasks;
unordered_set<SlotOffer *> slotOffers; // Active offers of slots on this slave
- Slave(const PID &_pid, SlaveID _id="") : pid(_pid), id(_id), active(true) {
+ Slave(const PID &_pid, SlaveID _id = "") : pid(_pid), id(_id), active(true) {
time(&connectTime);
}
@@ -283,9 +283,9 @@ protected:
FTMessaging *ftMsg;
public:
- Master(const string zk="");
+ Master(const string &zk = "");
- Master(const string& _allocatorType, const string zk="");
+ Master(const string& _allocatorType, const string &zk = "");
~Master();
Modified: incubator/mesos/trunk/src/nexus_sched.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_sched.cpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_sched.cpp (original)
+++ incubator/mesos/trunk/src/nexus_sched.cpp Sun Jun 5 03:29:43 2011
@@ -88,13 +88,13 @@ private:
// TODO(alig): make thread safe
SchedLeaderListener(SchedulerProcess *s, PID pp) : parent(s), parentPID(pp) {}
- virtual void newLeaderElected(string zkId, string pidStr) {
- if (zkId!="") {
- LOG(INFO) << "Leader listener detected leader at " << pidStr <<" with ephemeral id:"<<zkId;
+ virtual void newLeaderElected(const string &zkId, const string &pidStr) {
+ if (zkId != "") {
+ LOG(INFO) << "Leader listener detected leader at " << pidStr <<" with ephemeral id:" << zkId;
parent->zkservers = pidStr;
- LOG(INFO) << "Sending message to parent "<<parentPID<<" about new leader";
+ LOG(INFO) << "Sending message to parent " << parentPID << " about new leader";
parent->send(parentPID, parent->pack<LE_NEWLEADER>(pidStr));
}
@@ -111,10 +111,10 @@ private:
class TimeoutListener : public FTCallback {
public:
- TimeoutListener(SchedulerProcess *s, vector<TaskDescription> t) : parent(s), tasks(t) {}
+ TimeoutListener(SchedulerProcess *s, const vector<TaskDescription> t) : parent(s), tasks(t) {}
virtual void timeout() {
- foreach (TaskDescription &t, tasks) {
+ foreach (const TaskDescription &t, tasks) {
DLOG(INFO) << "FT: faking M2F_STATUS_UPDATE due to timeout to server during ReplyToOffer";
parent->send( parent->self(),
pack<M2F_STATUS_UPDATE>(t.taskId, TASK_LOST, ""));
@@ -143,11 +143,11 @@ public:
{
pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(_master);
if (urlPair.first == UrlProcessor::ZOO) {
- isFT=true;
+ isFT = true;
zkservers = urlPair.second;
// } else if (urlPair.first == UrlProcessor::NEXUS) {
} else {
- isFT=false;
+ isFT = false;
istringstream ss(urlPair.second); // the case nexus://
istringstream ss2(_master); // in case nexus:// is missing
if (!((ss >> master) || (ss2 >> master))) {
Modified: incubator/mesos/trunk/src/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.cpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave.cpp Sun Jun 5 03:29:43 2011
@@ -71,11 +71,11 @@ Slave::Slave(const string &_master, Reso
ftMsg = FTMessaging::getInstance();
pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(_master);
if (urlPair.first == UrlProcessor::ZOO) {
- isFT=true;
+ isFT = true;
zkserver = urlPair.second;
// } else if (urlPair.first == UrlProcessor::NEXUS) {
} else {
- isFT=false;
+ isFT = false;
istringstream iss(urlPair.second);
istringstream iss2(_master);
if (!((iss >> master) || (iss2 >> master) )) {
@@ -87,7 +87,7 @@ Slave::Slave(const string &_master, Reso
Slave::Slave(const string &_master, Resources _resources, bool _local,
- const string& _isolationType)
+ const string &_isolationType)
: leaderDetector(NULL),
resources(_resources), local(_local), id("-1"),
isolationType(_isolationType), isolationModule(NULL), slaveLeaderListener(this, getPID())
@@ -95,10 +95,10 @@ Slave::Slave(const string &_master, Reso
ftMsg = FTMessaging::getInstance();
pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(_master);
if (urlPair.first == UrlProcessor::ZOO) {
- isFT=true;
+ isFT = true;
zkserver = urlPair.second;
} else if (urlPair.first == UrlProcessor::NEXUS) {
- isFT=false;
+ isFT = false;
istringstream iss(urlPair.second);
if (!(iss >> master)) {
cerr << "Failed to resolve master PID " << urlPair.second << endl;
Modified: incubator/mesos/trunk/src/slave.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.hpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.hpp (original)
+++ incubator/mesos/trunk/src/slave.hpp Sun Jun 5 03:29:43 2011
@@ -186,13 +186,13 @@ public:
// TODO(alig): make thread safe
SlaveLeaderListener(Slave *s, PID pp) : parent(s), parentPID(pp) {}
- virtual void newLeaderElected(string zkId, string pidStr) {
- if (zkId!="") {
- LOG(INFO) << "Leader listener detected leader at " << pidStr <<" with ephemeral id:"<<zkId;
+ virtual void newLeaderElected(const string &zkId, const string &pidStr) {
+ if (zkId != "") {
+ LOG(INFO) << "Leader listener detected leader at " << pidStr <<" with ephemeral id:" << zkId;
parent->zkserver = pidStr;
- LOG(INFO) << "Sending message to parent "<<parentPID<<" about new leader";
+ LOG(INFO) << "Sending message to parent " << parentPID << " about new leader";
parent->send(parentPID, parent->pack<LE_NEWLEADER>(pidStr));
}
Modified: incubator/mesos/trunk/src/task_info.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/task_info.hpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/task_info.hpp (original)
+++ incubator/mesos/trunk/src/task_info.hpp Sun Jun 5 03:29:43 2011
@@ -20,10 +20,11 @@ struct TaskInfo
TaskInfo() {}
- TaskInfo(TaskID _id, Resources _res, SlaveID _sid="") : id(_id), resources(_res), slaveId(_sid) {}
+ TaskInfo(const TaskID &_id, const Resources &_res, const SlaveID &_sid = "") :
+ id(_id), resources(_res), slaveId(_sid) {}
- TaskInfo(TaskID _id, FrameworkID _fid, Resources _res, TaskState _s, string _n,
- string _m, SlaveID _sid="")
+ TaskInfo(const TaskID &_id, const FrameworkID &_fid, const Resources &_res,
+ const TaskState &_s, const string &_n, const string &_m, const SlaveID &_sid = "")
: id(_id), frameworkId(_fid), resources(_res), state(_s), name(_n),
message(_m), slaveId(_sid)
{ }
Modified: incubator/mesos/trunk/src/url_processor.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/url_processor.cpp?rev=1131612&r1=1131611&r2=1131612&view=diff
==============================================================================
--- incubator/mesos/trunk/src/url_processor.cpp (original)
+++ incubator/mesos/trunk/src/url_processor.cpp Sun Jun 5 03:29:43 2011
@@ -10,21 +10,21 @@ using namespace std;
namespace nexus { namespace internal {
string UrlProcessor::parseZooFile(const string &zooFilename) {
- string zoos="";
+ string zoos = "";
- LOG(INFO)<<"Opening ZooFile: "<<zooFilename;
+ LOG(INFO) << "Opening ZooFile: " << zooFilename;
ifstream zoofile(zooFilename.c_str());
if (!zoofile)
- LOG(ERROR)<<"ZooFile "<<zooFilename<<" could not be opened";
+ LOG(ERROR) << "ZooFile " << zooFilename << " could not be opened";
while(!zoofile.eof()) {
string line;
getline(zoofile, line);
- if (line=="")
+ if (line == "")
continue;
- if (zoos!="")
- zoos+=',';
- zoos+=line;
+ if (zoos != "")
+ zoos += ',';
+ zoos += line;
}
remove_if(zoos.begin(),zoos.end(), (int (*)(int)) isspace);
zoofile.close();
@@ -37,21 +37,25 @@ pair<UrlProcessor::URLType, string> UrlP
transform(urlCap.begin(), urlCap.end(), urlCap.begin(), (int (*)(int))toupper);
- if (urlCap.find("ZOO://")==0) {
+ if (urlCap.find("ZOO://") == 0) {
return pair<UrlProcessor::URLType, string>(UrlProcessor::ZOO, url.substr(6,1024));
- } else if (urlCap.find("ZOOFILE://")==0) {
+ } else if (urlCap.find("ZOOFILE://") == 0) {
string zoos = parseZooFile( url.substr(10,1024) );
return pair<UrlProcessor::URLType, string>(UrlProcessor::ZOO, zoos);
- } else if (urlCap.find("NEXUS://")==0) {
+ } else if (urlCap.find("NEXUS://") == 0) {
+
return pair<UrlProcessor::URLType, string>(UrlProcessor::NEXUS, url.substr(8,1024));
+
} else {
- LOG(ERROR)<<"Could not parse master/zoo URL";
+
+ LOG(ERROR) << "Could not parse master/zoo URL";
return pair<UrlProcessor::URLType, string>(UrlProcessor::UNKNOWN, "");
+
}
}