MCPcopy Create free account
hub / github.com/baidu/tera / Init

Method Init

src/tabletnode/tabletnode_zk_adapter.cc:31–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29TabletNodeZkAdapter::~TabletNodeZkAdapter() {}
30
31void TabletNodeZkAdapter::Init() {
32 int zk_errno;
33
34 // init zk client
35 while (!ZooKeeperAdapter::Init(FLAGS_tera_zk_addr_list, FLAGS_tera_zk_root_path,
36 FLAGS_tera_zk_timeout, server_addr_, &zk_errno)) {
37 LOG(ERROR) << "fail to init zk : " << zk::ZkErrnoToString(zk_errno);
38 ThisThread::Sleep(FLAGS_tera_zk_retry_period);
39 }
40 LOG(INFO) << "init zk success";
41
42 // enter running state
43 int64_t session_id_int = 0;
44 if (!GetSessionId(&session_id_int, &zk_errno)) {
45 LOG(ERROR) << "get session id fail : " << zk::ZkErrnoToString(zk_errno);
46 return;
47 }
48 char session_id_str[32];
49 sprintf(session_id_str, "%016lx", session_id_int);
50 tabletnode_impl_->SetSessionId(session_id_str);
51 tabletnode_impl_->SetTabletNodeStatus(TabletNodeImpl::kIsRunning);
52
53 // create my node
54 while (!Register(tabletnode_impl_->GetSessionId(), &zk_errno)) {
55 LOG(ERROR) << "fail to create serve-node : " << zk::ZkErrnoToString(zk_errno);
56 ThisThread::Sleep(FLAGS_tera_zk_retry_period);
57 }
58 LOG(INFO) << "create serve-node success";
59
60 bool is_exist = false;
61
62 // watch my node
63 while (!WatchSelfNode(&is_exist, &zk_errno)) {
64 LOG(ERROR) << "fail to watch serve-node : " << zk::ZkErrnoToString(zk_errno);
65 ThisThread::Sleep(FLAGS_tera_zk_retry_period);
66 }
67 LOG(INFO) << "watch serve-node success";
68 if (!is_exist) {
69 OnSelfNodeDeleted();
70 }
71
72 // watch kick node
73 while (!WatchKickMark(&is_exist, &zk_errno)) {
74 LOG(ERROR) << "fail to watch kick mark : " << zk::ZkErrnoToString(zk_errno);
75 ThisThread::Sleep(FLAGS_tera_zk_retry_period);
76 }
77 LOG(INFO) << "watch kick mark success";
78 if (is_exist) {
79 OnKickMarkCreated();
80 }
81
82 // watch safemode node
83 while (!WatchSafeModeMark(&is_exist, &zk_errno)) {
84 LOG(ERROR) << "fail to watch safemode mark : " << zk::ZkErrnoToString(zk_errno);
85 ThisThread::Sleep(FLAGS_tera_zk_retry_period);
86 }
87 LOG(INFO) << "watch safemode mark success";
88 if (is_exist) {

Callers

nothing calls this directly

Calls 8

ZkErrnoToStringFunction · 0.85
SetSessionIdMethod · 0.80
SetTabletNodeStatusMethod · 0.80
SetRootTabletAddrMethod · 0.80
GetSessionIdMethod · 0.45
emptyMethod · 0.45
DeleteMethod · 0.45
LockMethod · 0.45

Tested by

no test coverage detected