我想在ZooKeeper中创建持久节点。为此,我有以下两个功能:
void create_completion(int rc, const char * value, const void * data){
// empty callback at this moment
}
void create(const char * path, const char * value){
zoo_acreate(zh, path, value, 0, &ZOO_OPEN_ACL_UNSAFE, 0, create_completion, NULL);
}
我觉得有趣的是,如果我从create
函数调用main
函数然后终止,则不会上传任何数据:
int main(){
... some code to initialize session
create("/newnode", ""); // node is not created
zookeeper_close(zh);
return 0;
}
而如果我这样做:
int main(){
... some code to initialize session
create("/newnode", ""); // node is created
bool flag = true;
while(flag){
usleep(10000000);
flag = false;
}
zookeeper_close(zh);
return 0;
}
然后"/newnode"
上传到ZooKeeper
。那么,这有什么问题,为什么我真的需要这个循环?