You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2015/06/24 15:35:48 UTC

[05/18] incubator-singa git commit: SINGA-21 Code review

SINGA-21 Code review

review cluster_rt.h, cluster_rt.cc
  -- change function name to follow coding style:
    * sWatchSGroup -> WatchSGroup
    * wJoinSGroup -> JoinSGroup
    * wLeaveSGroup -> LeaveSGroup
  -- reformat


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/b6f2950c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/b6f2950c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/b6f2950c

Branch: refs/heads/master
Commit: b6f2950cfb467ed295986d5c9c491c17e96330aa
Parents: b0a5832
Author: wang sheng <wa...@gmail.com>
Authored: Mon Jun 22 20:46:06 2015 +0800
Committer: wang wei <wa...@comp.nus.edu.sg>
Committed: Wed Jun 24 17:04:59 2015 +0800

----------------------------------------------------------------------
 include/communication/socket.h |   2 +-
 include/utils/cluster_rt.h     | 123 ++++++++----------
 src/trainer/worker.cc          |   7 +-
 src/utils/cluster_rt.cc        | 250 ++++++++++++++++--------------------
 4 files changed, 173 insertions(+), 209 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/b6f2950c/include/communication/socket.h
----------------------------------------------------------------------
diff --git a/include/communication/socket.h b/include/communication/socket.h
index 77c701a..d1cb400 100644
--- a/include/communication/socket.h
+++ b/include/communication/socket.h
@@ -13,7 +13,7 @@
 
 namespace singa {
 
-const char kInprocRouterEndpoint[] = "inproc://router";
+const std::string kInprocRouterEndpoint = "inproc://router";
 
 class SocketInterface {
  public:

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/b6f2950c/include/utils/cluster_rt.h
----------------------------------------------------------------------
diff --git a/include/utils/cluster_rt.h b/include/utils/cluster_rt.h
index 7ed7b68..08bea90 100644
--- a/include/utils/cluster_rt.h
+++ b/include/utils/cluster_rt.h
@@ -1,108 +1,99 @@
-#ifndef INCLUDE_UTILS_CLUSTER_RT_H_
-#define INCLUDE_UTILS_CLUSTER_RT_H_
-#include <glog/logging.h>
+#ifndef SINGA_UTILS_CLUSTER_RT_H_
+#define SINGA_UTILS_CLUSTER_RT_H_
+
+#include <zookeeper/zookeeper.h>
 #include <string>
 #include <vector>
-#include <utility>
-#include <zookeeper/zookeeper.h>
-
-using std::string;
-using std::vector;
 
 namespace singa {
 
+typedef void (*rt_callback)(void *contest);
+
 /**
- * ClusterRuntime is a runtime service that manages dynamic configuration and status
- * of the whole cluster. It mainly provides following services:
+ * ClusterRuntime is a runtime service that manages dynamic configuration 
+ * and status of the whole cluster. It mainly provides following services:
  *    1)  Provide running status of each server/worker
  *    2)  Translate process id to (hostname:port)
  */
-
-typedef void (*rt_callback)(void *contest);
-  
-class ClusterRuntime{
+class ClusterRuntime {
  public:
-  ClusterRuntime(){}
-  virtual ~ClusterRuntime(){}
-
+  virtual ~ClusterRuntime() {}
   /**
    * Initialize the runtime instance
    */
-  virtual bool Init(){ return false;}
-
+  virtual bool Init() = 0;
   /**
    * register the process, and get a unique process id
    *
    * \return the process id, -1 if failed
    */
-  virtual int RegistProc(const string& host_addr){ return -1;};
-
+  virtual int RegistProc(const std::string& host_addr) = 0;
   /**
    * translate the process id to host address
    *
    * \return the host and port, "" if no such proc id
    */
-  virtual string GetProcHost(int proc_id){ return "";};   
-
+  virtual std::string GetProcHost(int proc_id) = 0;
   /**
-   * Server: watch all workers in a server group, will be notified when all workers have left 
+   * Server: watch all workers in a server group, 
+   * will be notified when all workers have left 
    */
-  virtual bool sWatchSGroup(int gid, int sid, rt_callback fn, void *ctx){ return false;}
-
+  virtual bool WatchSGroup(int gid, int sid, rt_callback fn, void* ctx) = 0;
   /**
    * Worker: join a server group (i.e. start to read/update these servers)
    */
-  virtual bool wJoinSGroup(int gid, int wid, int s_group){ return false;}
-
+  virtual bool JoinSGroup(int gid, int wid, int s_group) = 0;
   /**
    * Worker: leave a server group (i.e. finish its all work)
    */
-  virtual bool wLeaveSGroup(int gid, int wid, int s_group){ return false;}
+  virtual bool LeaveSGroup(int gid, int wid, int s_group) = 0;
 };
 
+class ZKClusterRT : public ClusterRuntime {
+ public:
+  explicit ZKClusterRT(const std::string& host);
+  ZKClusterRT(const std::string& host, int timeout);
+  ~ZKClusterRT() override;
 
+  bool Init() override;
+  int RegistProc(const std::string& host_addr) override;
+  std::string GetProcHost(int proc_id) override;
+  bool WatchSGroup(int gid, int sid, rt_callback fn, void* ctx) override;
+  bool JoinSGroup(int gid, int wid, int s_group) override;
+  bool LeaveSGroup(int gid, int wid, int s_group) override;
 
-class ZKClusterRT : public ClusterRuntime{
- public:
-  ZKClusterRT(string host, int timeout = 30000);
-  ~ZKClusterRT();
-  bool Init();
-  int RegistProc(const string& host_addr);
-  string GetProcHost(int proc_id);   
-  bool sWatchSGroup(int gid, int sid, rt_callback fn, void *ctx);
-  bool wJoinSGroup(int gid, int wid, int s_group);
-  bool wLeaveSGroup(int gid, int wid, int s_group);
-  
  private:
-  static void WatcherGlobal(zhandle_t * zh, int type, int state, const char *path, void *watcherCtx);
-  static void ChildChanges(zhandle_t *zh, int type, int state, const char *path, void *watcherCtx);
-  bool CreateZKNode(const char* path, const char* val, int flag, char* output);
-  bool DeleteZKNode(const char* path);
-  bool GetZKNode(const char* path, char* output);
-  bool GetZKChild(const char* path, vector<string>& vt);
-  string groupPath(int gid);
-  string workerPath(int gid, int wid);
-
-  struct RTCallback{
+  struct RTCallback {
     rt_callback fn;
     void* ctx;
   };
- 
-  string host_;
-  int timeout_;
-  zhandle_t *zkhandle_;
-  vector<RTCallback *> cb_vec_;
-    
-  const int MAX_BUF_LEN = 50;
-  const int RETRY_NUM = 10;
-  const int SLEEP_SEC = 1;
-  const string ZPATH_SINGA = "/singa";
-  const string ZPATH_STATUS = "/singa/status";
-  const string ZPATH_REGIST = "/singa/regist";
-  const string ZPATH_REGIST_PROC = "/singa/regist/proc";
-  const string ZPATH_REGIST_LOCK = "/singa/regist/lock";
+
+  const int kMaxBufLen = 50;
+  const int kNumRetry = 10;
+  const int kSleepSec = 1;
+  const std::string kZPathSinga = "/singa";
+  const std::string kZPathStatus = "/singa/status";
+  const std::string kZPathRegist = "/singa/regist";
+  const std::string kZPathRegistProc = "/singa/regist/proc";
+  const std::string kZPathRegistLock = "/singa/regist/lock";
+
+  static void WatcherGlobal(zhandle_t* zh, int type, int state,
+                            const char *path, void* watcherCtx);
+  static void ChildChanges(zhandle_t* zh, int type, int state,
+                           const char *path, void* watcherCtx);
+  bool CreateZKNode(const char* path, const char* val, int flag, char* output);
+  bool DeleteZKNode(const char* path);
+  bool GetZKNode(const char* path, char* output);
+  bool GetZKChild(const char* path, std::vector<std::string>* vt);
+  inline std::string groupPath(int gid);
+  std::string workerPath(int gid, int wid);
+
+  int timeout_ = 30000;
+  std::string host_ = "";
+  zhandle_t* zkhandle_ = nullptr;
+  std::vector<RTCallback*> cb_vec_;
 };
 
-} // namespace singa
+}  // namespace singa
 
-#endif  //  INCLUDE_UTILS_CLUSTER_RT_H_
+#endif  // SINGA_UTILS_CLUSTER_RT_H_

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/b6f2950c/src/trainer/worker.cc
----------------------------------------------------------------------
diff --git a/src/trainer/worker.cc b/src/trainer/worker.cc
index 8ecb146..1e0dc30 100644
--- a/src/trainer/worker.cc
+++ b/src/trainer/worker.cc
@@ -19,7 +19,10 @@ void Worker::Setup(const ModelProto& model,
   train_net_=train_net;
   modelproto_=model;
   auto cluster=Cluster::Get();
-  if(!(cluster->nserver_groups()&&cluster->server_update())){
+  if(cluster->nserver_groups()&&cluster->server_update()){
+    int sgid=group_id_/cluster->nworker_groups_per_server_group();
+    CHECK(cluster->runtime()->JoinSGroup(group_id_, worker_id_, sgid));
+  }else{
     updater_=shared_ptr<Updater>(Singleton<Factory<Updater>>::Instance()
         ->Create("Updater"));
     updater_->Init(model.updater());
@@ -91,7 +94,7 @@ void Worker::Run(){
 void Worker::Stop(){
   auto cluster=Cluster::Get();
   int sgid=group_id_/cluster->nworker_groups_per_server_group();
-  cluster->runtime()->wLeaveSGroup(group_id_, worker_id_, sgid);
+  cluster->runtime()->LeaveSGroup(group_id_, worker_id_, sgid);
   Msg* msg=new Msg();
   msg->set_src(group_id_, worker_id_, kWorkerParam);
   msg->set_dst(-1,-1, kStub);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/b6f2950c/src/utils/cluster_rt.cc
----------------------------------------------------------------------
diff --git a/src/utils/cluster_rt.cc b/src/utils/cluster_rt.cc
index 514ea2e..748a261 100644
--- a/src/utils/cluster_rt.cc
+++ b/src/utils/cluster_rt.cc
@@ -1,278 +1,248 @@
 #include "utils/cluster_rt.h"
+
+#include <glog/logging.h>
 #include <algorithm>
 
 using std::to_string;
+using std::string;
 
 namespace singa {
 
-/********* Implementation for ZKClusterRT **************/
+ZKClusterRT::ZKClusterRT(const string& host) : ZKClusterRT(host, 30000) {}
 
-ZKClusterRT::ZKClusterRT(string host, int timeout){
+ZKClusterRT::ZKClusterRT(const string& host, int timeout) {
   host_ = host;
   timeout_ = timeout;
   zkhandle_ = nullptr;
 }
 
-ZKClusterRT::~ZKClusterRT(){
-  //close zookeeper handler
+ZKClusterRT::~ZKClusterRT() {
+  // close zookeeper handler
   zookeeper_close(zkhandle_);
-  //release callback vector
-  for (RTCallback *p : cb_vec_){
+  // release callback vector
+  for (RTCallback* p : cb_vec_) {
     delete p;
   }
 }
 
-bool ZKClusterRT::Init(){
+char zk_cxt[] = "ZKClusterRT";
 
+bool ZKClusterRT::Init() {
   zoo_set_debug_level(ZOO_LOG_LEVEL_WARN);
-
-  zkhandle_ = zookeeper_init(host_.c_str(), WatcherGlobal, timeout_, 0, "ZKClusterRT", 0);
-
-  if (zkhandle_ == NULL){
+  zkhandle_ = zookeeper_init(host_.c_str(), WatcherGlobal, timeout_, 0,
+                             static_cast<void *>(zk_cxt), 0);
+  if (zkhandle_ == NULL) {
     LOG(ERROR) << "Error when connecting to zookeeper servers...";
     LOG(ERROR) << "Please ensure zookeeper service is up in host(s):";
     LOG(ERROR) << host_.c_str();
     return false;
   }
-
-  //create ZPATH_SINGA
-  if (!CreateZKNode(ZPATH_SINGA.c_str(), nullptr, 0, nullptr)) return false;
-  //create ZPATH_STATUS
-  if (!CreateZKNode(ZPATH_STATUS.c_str(), nullptr, 0, nullptr)) return false;
-  //create ZPATH_REGIST
-  if (!CreateZKNode(ZPATH_REGIST.c_str(), nullptr, 0, nullptr)) return false;
-  //create ZPATH_REGIST_PROC
-  if (!CreateZKNode(ZPATH_REGIST_PROC.c_str(), nullptr, 0, nullptr)) return false;
-  //create ZPATH_REGIST_LOCK
-  if (!CreateZKNode(ZPATH_REGIST_LOCK.c_str(), nullptr, 0, nullptr)) return false;
+  // create kZPathSinga
+  if (!CreateZKNode(kZPathSinga.c_str(), nullptr, 0, nullptr))
+    return false;
+  // create kZPathStatus
+  if (!CreateZKNode(kZPathStatus.c_str(), nullptr, 0, nullptr))
+    return false;
+  // create kZPathRegist
+  if (!CreateZKNode(kZPathRegist.c_str(), nullptr, 0, nullptr))
+    return false;
+  // create kZPathRegistProc
+  if (!CreateZKNode(kZPathRegistProc.c_str(), nullptr, 0, nullptr))
+    return false;
+  // create kZPathRegistLock
+  if (!CreateZKNode(kZPathRegistLock.c_str(), nullptr, 0, nullptr))
+    return false;
 
   return true;
 }
 
-int ZKClusterRT::RegistProc(const string& host_addr){
- 
-  char buf[MAX_BUF_LEN];
-  string lock = ZPATH_REGIST_LOCK+"/lock-";
-
-  if (!CreateZKNode(lock.c_str(), nullptr, ZOO_EPHEMERAL | ZOO_SEQUENCE, buf)){
+int ZKClusterRT::RegistProc(const string& host_addr) {
+  char buf[kMaxBufLen];
+  string lock = kZPathRegistLock+"/lock-";
+  if (!CreateZKNode(lock.c_str(), nullptr, ZOO_EPHEMERAL | ZOO_SEQUENCE, buf)) {
     return -1;
   }
-
-  //get all children in lock folder
-  vector<string> vt;
-  if (!GetZKChild(ZPATH_REGIST_LOCK.c_str(), vt)){
+  // get all children in lock folder
+  std::vector<string> vt;
+  if (!GetZKChild(kZPathRegistLock.c_str(), &vt)) {
     return -1;
   }
-
-  //find own position among all locks
+  // find own position among all locks
   int id = -1;
   std::sort(vt.begin(), vt.end());
-  for (int i = 0; i < (int)vt.size(); ++i){
-    if (ZPATH_REGIST_LOCK+"/"+vt[i] == buf){
+  for (int i = 0; i < static_cast<int>(vt.size()); ++i) {
+    if (kZPathRegistLock+"/"+vt[i] == buf) {
       id = i;
       break;
     }
   }
-
-  if (id == -1){
+  if (id == -1) {
     LOG(ERROR) << "cannot find own node " << buf;
     return -1;
   }
-
-  //create a new node in proc path
-  string path = ZPATH_REGIST_PROC+"/proc-"+to_string(id);
-  if (!CreateZKNode(path.c_str(), host_addr.c_str(), ZOO_EPHEMERAL, nullptr)){
+  // create a new node in proc path
+  string path = kZPathRegistProc+"/proc-"+to_string(id);
+  if (!CreateZKNode(path.c_str(), host_addr.c_str(), ZOO_EPHEMERAL, nullptr)) {
     return -1;
   }
-
   return id;
 }
 
-string ZKClusterRT::GetProcHost(int proc_id){
-  
-  //char buf[MAX_BUF_LEN];
-  char val[MAX_BUF_LEN];
-
-  //construct file name
-  string path = ZPATH_REGIST_PROC+"/proc-"+to_string(proc_id);
-
+string ZKClusterRT::GetProcHost(int proc_id) {
+  // char buf[kMaxBufLen];
+  char val[kMaxBufLen];
+  // construct file name
+  string path = kZPathRegistProc+"/proc-"+to_string(proc_id);
   if (!GetZKNode(path.c_str(), val)) return "";
-
   return string(val);
 }
 
-bool ZKClusterRT::sWatchSGroup(int gid, int sid, rt_callback fn, void *ctx){
-
+bool ZKClusterRT::WatchSGroup(int gid, int sid, rt_callback fn, void *ctx) {
   CHECK_NOTNULL(fn);
-
   string path = groupPath(gid);
-
-  //create zk node
+  // create zk node
   if (!CreateZKNode(path.c_str(), nullptr, 0, nullptr)) return false;
-
   struct String_vector child;
-  //store the callback function and context for later usage
+  // store the callback function and context for later usage
   RTCallback *cb = new RTCallback;
   cb->fn = fn;
   cb->ctx = ctx;
   cb_vec_.push_back(cb);
-  //start to watch on the zk node, does not care about the first return value
-  int ret = zoo_wget_children(zkhandle_, path.c_str(), ChildChanges, cb, &child);
-
-  if (ret != ZOK){
+  // start to watch on the zk node, does not care about the first return value
+  int ret = zoo_wget_children(zkhandle_, path.c_str(), ChildChanges,
+                              cb, &child);
+  if (ret != ZOK) {
     LOG(ERROR) << "failed to get child of " << path;
     return false;
   }
-
   return true;
 }
 
-bool ZKClusterRT::wJoinSGroup(int gid, int wid, int s_group){
-
+bool ZKClusterRT::JoinSGroup(int gid, int wid, int s_group) {
   string path = groupPath(s_group) + workerPath(gid, wid);
-
-  //try to create an ephemeral node under server group path
-  if (!CreateZKNode(path.c_str(), nullptr, ZOO_EPHEMERAL, nullptr)){
+  // try to create an ephemeral node under server group path
+  if (!CreateZKNode(path.c_str(), nullptr, ZOO_EPHEMERAL, nullptr)) {
     return false;
   }
-
   return true;
 }
 
-bool ZKClusterRT::wLeaveSGroup(int gid, int wid, int s_group){
-
+bool ZKClusterRT::LeaveSGroup(int gid, int wid, int s_group) {
   string path = groupPath(s_group) + workerPath(gid, wid);
-
   if (!DeleteZKNode(path.c_str())) return false;
-  
   return true;
 }
 
-void ZKClusterRT::WatcherGlobal(zhandle_t * zh, int type, int state, const char *path, void *watcherCtx){
-  if (type == ZOO_SESSION_EVENT){
+void ZKClusterRT::WatcherGlobal(zhandle_t * zh, int type, int state,
+                                const char *path, void *watcherCtx) {
+  if (type == ZOO_SESSION_EVENT) {
     if (state == ZOO_CONNECTED_STATE)
-      LOG(INFO) << "GLOBAL_WATCHER connected to zookeeper service successfully!";
+      LOG(INFO) << "GLOBAL_WATCHER connected to zookeeper successfully!";
     else if (state == ZOO_EXPIRED_SESSION_STATE)
       LOG(INFO) << "GLOBAL_WATCHER zookeeper session expired!";
   }
 }
 
-void ZKClusterRT::ChildChanges(zhandle_t *zh, int type, int state, const char *path, void *watcherCtx){
-
-  //check if already callback
-  RTCallback *cb = (RTCallback *)watcherCtx;
+void ZKClusterRT::ChildChanges(zhandle_t *zh, int type, int state,
+                               const char *path, void *watcherCtx) {
+  // check if already callback
+  RTCallback *cb = static_cast<RTCallback*>(watcherCtx);
   if (cb->fn == nullptr) return;
-
-  if (type == ZOO_CHILD_EVENT){
+  if (type == ZOO_CHILD_EVENT) {
     struct String_vector child;
-    //check the child list and put another watcher
+    // check the child list and put another watcher
     int ret = zoo_wget_children(zh, path, ChildChanges, watcherCtx, &child);
-    if (ret == ZOK){
-      if (child.count == 0){
+    if (ret == ZOK) {
+      if (child.count == 0) {
         LOG(INFO) << "child.count = 0 in path: " << path;
-        //all workers leave, we do callback now
+        // all workers leave, we do callback now
         (*cb->fn)(cb->ctx);
         cb->fn = nullptr;
       }
+    } else {
+      LOG(ERROR) << "Unhandled ZK error code: " << ret
+                 << " (zoo_wget_children)";
     }
-    else{
-      LOG(ERROR) << "Unhandled ZK error code: " << ret << " (zoo_wget_children)";
-    }
-  }
-  else{
+  } else {
     LOG(ERROR) << "Unhandled callback type code: "<< type;
   }
 }
 
-bool ZKClusterRT::CreateZKNode(const char* path, const char* val, int flag, char* output){
-  
-  char buf[MAX_BUF_LEN];
+bool ZKClusterRT::CreateZKNode(const char* path, const char* val, int flag,
+                               char* output) {
+  char buf[kMaxBufLen];
   int ret;
-
-  //send the zk request
-  for (int i = 0; i < RETRY_NUM; ++i){
-    ret = zoo_create(zkhandle_, path, val, val == nullptr ? -1 : strlen(val), &ZOO_OPEN_ACL_UNSAFE, flag, buf, MAX_BUF_LEN);
+  // send the zk request
+  for (int i = 0; i < kNumRetry; ++i) {
+    ret = zoo_create(zkhandle_, path, val, val == nullptr ? -1 : strlen(val),
+                     &ZOO_OPEN_ACL_UNSAFE, flag, buf, kMaxBufLen);
     if (ret != ZNONODE) break;
-    LOG(WARNING) << "zookeeper parent node of " << path << " not exist, retry later";
-    sleep(SLEEP_SEC);
+    LOG(WARNING) << "zookeeper parent node of " << path
+                 << " not exist, retry later";
+    sleep(kSleepSec);
   }
- 
-  //copy the node name ot output
-  if (output != nullptr && (ret == ZOK || ret == ZNODEEXISTS)){
-    strcpy(output, buf);
+  // copy the node name ot output
+  if (output != nullptr && (ret == ZOK || ret == ZNODEEXISTS)) {
+    snprintf(output, strlen(buf), "%s", buf);
   }
-
-  if (ret == ZOK){
-    LOG(INFO) << "created zookeeper node " << buf << " (" << (val == nullptr ? "NULL" : val) << ")";
+  if (ret == ZOK) {
+    LOG(INFO) << "created zookeeper node " << buf
+              << " (" << (val == nullptr ? "NULL" : val) << ")";
     return true;
-  }
-  else if (ret == ZNODEEXISTS){
+  } else if (ret == ZNODEEXISTS) {
     LOG(WARNING) << "zookeeper node " << path << " already exists";
     return true;
   }
-    
   LOG(ERROR) << "Unhandled ZK error code: " << ret << " (zoo_create)";
   return false;
 }
 
-bool ZKClusterRT::DeleteZKNode(const char* path){
-  
+bool ZKClusterRT::DeleteZKNode(const char* path) {
   int ret = zoo_delete(zkhandle_, path, -1);
-  
-  if (ret == ZOK){
+  if (ret == ZOK) {
     LOG(INFO) << "deleted zookeeper node " << path;
     return true;
-  }
-  else if (ret == ZNONODE){
+  } else if (ret == ZNONODE) {
     LOG(WARNING) << "try to delete an non-existing zookeeper node " << path;
     return true;
   }
-
   LOG(ERROR) << "Unhandled ZK error code: " << ret << " (zoo_delete)";
   return false;
 }
 
-bool ZKClusterRT::GetZKNode(const char* path, char* output){
-  
+bool ZKClusterRT::GetZKNode(const char* path, char* output) {
   struct Stat stat;
-  int val_len = MAX_BUF_LEN;
-
+  int val_len = kMaxBufLen;
   int ret = zoo_get(zkhandle_, path, 0, output, &val_len, &stat);
-
-  if (ret == ZOK){
-    output[val_len] = 0;
+  if (ret == ZOK) {
+    output[val_len] = '\0';
     return true;
-  }
-  else if (ret == ZNONODE){
-    LOG(ERROR) << "zk node " << path << " does not exist"; 
+  } else if (ret == ZNONODE) {
+    LOG(ERROR) << "zk node " << path << " does not exist";
     return false;
   }
-  
   LOG(ERROR) << "Unhandled ZK error code: " << ret << " (zoo_get)";
   return false;
 }
 
-bool ZKClusterRT::GetZKChild(const char* path, vector<string>& vt){
-
-  //get all children in lock folder
+bool ZKClusterRT::GetZKChild(const char* path, std::vector<string>* vt) {
+  // get all children in lock folder
   struct String_vector child;
   int ret = zoo_get_children(zkhandle_, path, 0, &child);
-
-  if (ret == ZOK){
-    for (int i = 0; i < child.count; ++i) vt.push_back(child.data[i]);
+  if (ret == ZOK) {
+    for (int i = 0; i < child.count; ++i) vt->push_back(child.data[i]);
     return true;
   }
-  
   LOG(ERROR) << "Unhandled ZK error code: " << ret << " (zoo_create)";
   return false;
 }
 
-string ZKClusterRT::groupPath(int gid){
-  return ZPATH_STATUS+"/sg"+to_string(gid);
+string ZKClusterRT::groupPath(int gid) {
+  return kZPathStatus+"/sg"+to_string(gid);
 }
 
-string ZKClusterRT::workerPath(int gid, int wid){
+string ZKClusterRT::workerPath(int gid, int wid) {
   return "/g"+to_string(gid)+"_w"+to_string(wid);
 }
 
-} // namespace singa
+}  // namespace singa