zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Denis Samoilov <samoi...@gmail.com>
Subject c++ and zk session management
Date Fri, 19 Sep 2014 01:12:53 GMT
hi,

I have a service (long living) that establish connection to ZK and holds it:

zookeeper_init(zkConnectionString.c_str(), zkWatcherCallback, 10000,
NULL, callbackContext, 0);


and after I simply subscribe to notification. I did check when I
interrupt connection and it successfully reconnect by itself. I also
print debug message when connection lost and restored. But when I
deployed service to many servers I see that few services lost
connection and sit disconnected. So I definitely doing something
wrong. What is correct algorithm to keep service always connected (i
do not do anything special to reconnect as I saw during my test that
library did this for me, why not always?).

my zk callback function is the following:

void ConfigManagerImpl::zkWatcher(zhandle_t*, int type, int state,
const char *path, void* context)
{
    ConfigManagerImpl* me = (ConfigManagerImpl*)context;
    LOG(INFO) << "CM:zkWatcher event:" << type << ":" << state <<
            " (" << ZookeeperInterface::watcherEvent2String(type) <<
":" << ZookeeperInterface::state2String(state) + ")";

    if (ZOO_SESSION_EVENT == type) {
        me->updateZKConnected(state == ZOO_CONNECTED_STATE);
    } else if (ZOO_CHANGED_EVENT == type) {
        LOG(INFO) << "CM:zkWatcher changed event, path=" << path;

        if (me->_zkFullPathToActiveVersion == path) {
            me->_threadBlocker.signal(); // wake thread to read config
        }
    } else if (ZOO_DELETED_EVENT == type) {
        if (me->_zkFullPathToActiveVersion == path) {
            LOG(ERROR) << "CM:zkWatcher deleted active-external node
event, path=" << path;
            me->_threadBlocker.signal(); // wake thread to read config
in a loop because we just lost notifications
        }
    }
}

Thank you for any insights!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message