2014-03-07 13:50:58 +00:00
|
|
|
|
#pragma once
|
2014-04-02 10:38:27 +00:00
|
|
|
|
#include <statdaemons/Exception.h>
|
2014-03-07 19:18:48 +00:00
|
|
|
|
#include <zkutil/Types.h>
|
2014-09-11 20:34:41 +00:00
|
|
|
|
#include <DB/Common/ProfileEvents.h>
|
2014-03-07 13:50:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace zkutil
|
|
|
|
|
{
|
|
|
|
|
|
2014-04-02 10:38:27 +00:00
|
|
|
|
class KeeperException : public DB::Exception
|
2014-03-07 13:50:58 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2014-09-11 20:34:41 +00:00
|
|
|
|
KeeperException(const std::string & msg) : DB::Exception(msg), code(ZOK) { incrementEventCounter(); }
|
2014-06-04 13:48:36 +00:00
|
|
|
|
KeeperException(const std::string & msg, int32_t code_)
|
2014-09-11 20:34:41 +00:00
|
|
|
|
: DB::Exception(msg + " (" + zerror(code_) + ")"), code(code_) { incrementEventCounter(); }
|
2014-06-04 13:48:36 +00:00
|
|
|
|
KeeperException(int32_t code_)
|
2014-09-11 20:34:41 +00:00
|
|
|
|
: DB::Exception(zerror(code_)), code(code_) { incrementEventCounter(); }
|
2014-06-04 13:48:36 +00:00
|
|
|
|
KeeperException(int32_t code_, const std::string & path_)
|
2014-09-11 20:34:41 +00:00
|
|
|
|
: DB::Exception(std::string(zerror(code_)) + ", path: " + path_), code(code_) { incrementEventCounter(); }
|
|
|
|
|
KeeperException(const KeeperException & exc) : DB::Exception(exc), code(exc.code) { incrementEventCounter(); }
|
2014-03-07 13:50:58 +00:00
|
|
|
|
|
2014-04-02 13:45:39 +00:00
|
|
|
|
const char * name() const throw() { return "zkutil::KeeperException"; }
|
|
|
|
|
const char * className() const throw() { return "zkutil::KeeperException"; }
|
2014-06-27 13:47:00 +00:00
|
|
|
|
KeeperException * clone() const { return new KeeperException(*this); }
|
2014-04-02 13:45:39 +00:00
|
|
|
|
|
2014-10-30 13:28:45 +00:00
|
|
|
|
/// при этих ошибках надо переинициализировать сессию с zookeeper
|
|
|
|
|
bool isUnrecoverable() const
|
|
|
|
|
{
|
|
|
|
|
return code == ZINVALIDSTATE || code == ZSESSIONEXPIRED;
|
|
|
|
|
}
|
2014-06-04 13:48:36 +00:00
|
|
|
|
int32_t code;
|
2014-09-11 20:34:41 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void incrementEventCounter()
|
|
|
|
|
{
|
|
|
|
|
ProfileEvents::increment(ProfileEvents::ZooKeeperExceptions);
|
|
|
|
|
}
|
2014-10-30 13:28:45 +00:00
|
|
|
|
|
2014-03-07 13:50:58 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|