zkutil: fixed a bug, removed unused code. [#METR-10202]

This commit is contained in:
Michael Kolupaev 2014-07-08 16:45:10 +04:00
parent 146378633a
commit 039858e3f7
3 changed files with 11 additions and 20 deletions

View File

@ -87,8 +87,6 @@ typedef std::vector<OpResult> OpResults;
typedef std::shared_ptr<OpResults> OpResultsPtr;
typedef std::vector<std::string> Strings;
typedef void (*WatchFunction)(zhandle_t *zh, int type, int state, const char *path, void *watcherCtx);
namespace CreateMode
{
extern const int Persistent;

View File

@ -29,7 +29,7 @@ class ZooKeeper
public:
typedef Poco::SharedPtr<ZooKeeper> Ptr;
ZooKeeper(const std::string & hosts, int32_t sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT, WatchFunction * watch = nullptr);
ZooKeeper(const std::string & hosts, int32_t sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT);
/** конфиг вида
<zookeeper>
@ -44,8 +44,7 @@ public:
<session_timeout_ms>30000</session_timeout_ms>
</zookeeper>
*/
ZooKeeper(const Poco::Util::AbstractConfiguration & config, const std::string & config_name,
WatchFunction * watch = nullptr);
ZooKeeper(const Poco::Util::AbstractConfiguration & config, const std::string & config_name);
~ZooKeeper();
@ -169,7 +168,7 @@ public:
private:
friend struct WatchWithEvent;
void init(const std::string & hosts, int32_t sessionTimeoutMs, WatchFunction * watch_);
void init(const std::string & hosts, int32_t sessionTimeoutMs);
void removeChildrenRecursive(const std::string & path);
void tryRemoveChildrenRecursive(const std::string & path);
void * watchForEvent(EventPtr event);
@ -211,7 +210,6 @@ private:
AclPtr default_acl;
zhandle_t * impl;
WatchFunction * state_watch;
std::unordered_set<WatchWithEvent *> watch_store;
/// Количество попыток повторить операцию чтения при OperationTimeout, ConnectionLoss

View File

@ -32,7 +32,7 @@ struct WatchWithEvent
void process(zhandle_t * zh, int32_t event_type, int32_t state, const char * path)
{
if (!event)
if (event)
{
event->set();
event = nullptr;
@ -56,18 +56,14 @@ void ZooKeeper::processEvent(zhandle_t * zh, int type, int state, const char * p
}
}
void ZooKeeper::init(const std::string & hosts_, int32_t sessionTimeoutMs_, WatchFunction * watch_)
void ZooKeeper::init(const std::string & hosts_, int32_t sessionTimeoutMs_)
{
log = &Logger::get("ZooKeeper");
zoo_set_debug_level(ZOO_LOG_LEVEL_ERROR);
hosts = hosts_;
sessionTimeoutMs = sessionTimeoutMs_;
state_watch = watch_;
if (watch_)
impl = zookeeper_init(hosts.c_str(), *watch_, sessionTimeoutMs, nullptr, nullptr, 0);
else
impl = zookeeper_init(hosts.c_str(), nullptr, sessionTimeoutMs, nullptr, nullptr, 0);
impl = zookeeper_init(hosts.c_str(), nullptr, sessionTimeoutMs, nullptr, nullptr, 0);
if (!impl)
throw KeeperException("Fail to initialize zookeeper. Hosts are " + hosts);
@ -75,9 +71,9 @@ void ZooKeeper::init(const std::string & hosts_, int32_t sessionTimeoutMs_, Watc
default_acl = &ZOO_OPEN_ACL_UNSAFE;
}
ZooKeeper::ZooKeeper(const std::string & hosts, int32_t sessionTimeoutMs, WatchFunction * watch_)
ZooKeeper::ZooKeeper(const std::string & hosts, int32_t sessionTimeoutMs)
{
init(hosts, sessionTimeoutMs, watch_);
init(hosts, sessionTimeoutMs);
}
struct ZooKeeperArgs
@ -109,11 +105,10 @@ struct ZooKeeperArgs
size_t session_timeout_ms;
};
ZooKeeper::ZooKeeper(const Poco::Util::AbstractConfiguration & config, const std::string & config_name,
WatchFunction * watch)
ZooKeeper::ZooKeeper(const Poco::Util::AbstractConfiguration & config, const std::string & config_name)
{
ZooKeeperArgs args(config, config_name);
init(args.hosts, args.session_timeout_ms, watch);
init(args.hosts, args.session_timeout_ms);
}
void * ZooKeeper::watchForEvent(EventPtr event)
@ -476,7 +471,7 @@ ZooKeeper::~ZooKeeper()
ZooKeeperPtr ZooKeeper::startNewSession() const
{
return new ZooKeeper(hosts, sessionTimeoutMs, state_watch);
return new ZooKeeper(hosts, sessionTimeoutMs);
}
Op::Create::Create(const std::string & path_, const std::string & value_, AclPtr acl, int32_t flags)