2014-03-07 13:50:58 +00:00
|
|
|
|
#pragma once
|
2015-10-05 01:26:43 +00:00
|
|
|
|
#include <DB/Common/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>
|
2016-01-11 21:46:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
|
{
|
|
|
|
|
extern const int KEEPER_EXCEPTION;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2015-05-26 14:40:36 +00:00
|
|
|
|
private:
|
|
|
|
|
/// delegate constructor, used to minimize repetition; last parameter used for overload resolution
|
|
|
|
|
KeeperException(const std::string & msg, const int32_t code, int)
|
|
|
|
|
: DB::Exception(msg, DB::ErrorCodes::KEEPER_EXCEPTION), code(code) { incrementEventCounter(); }
|
|
|
|
|
|
2014-03-07 13:50:58 +00:00
|
|
|
|
public:
|
2015-05-26 14:40:36 +00:00
|
|
|
|
KeeperException(const std::string & msg) : KeeperException(msg, ZOK, 0) {}
|
|
|
|
|
KeeperException(const std::string & msg, const int32_t code)
|
|
|
|
|
: KeeperException(msg + " (" + zerror(code) + ")", code, 0) {}
|
|
|
|
|
KeeperException(const int32_t code) : KeeperException(zerror(code), code, 0) {}
|
|
|
|
|
KeeperException(const int32_t code, const std::string & path)
|
|
|
|
|
: KeeperException(std::string{zerror(code)} + ", path: " + path, code, 0) {}
|
|
|
|
|
|
2014-09-11 20:34:41 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2015-05-26 14:40:36 +00:00
|
|
|
|
return code == ZINVALIDSTATE || code == ZSESSIONEXPIRED || code == ZSESSIONMOVED;
|
2014-10-30 13:28:45 +00:00
|
|
|
|
}
|
2015-05-26 14:40:36 +00:00
|
|
|
|
|
2015-12-21 09:55:56 +00:00
|
|
|
|
/// любая ошибка связанная с работой сети, перевыбором мастера
|
|
|
|
|
/// при этих ошибках надо либо повторить запрос повторно, либо переинициализировать сессию (см. isUnrecoverable())
|
|
|
|
|
bool isHardwareError() const
|
|
|
|
|
{
|
|
|
|
|
return isUnrecoverable() || code == ZCONNECTIONLOSS || code == ZOPERATIONTIMEOUT;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 14:40:36 +00:00
|
|
|
|
const int32_t code;
|
2014-09-11 20:34:41 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2015-05-26 14:40:36 +00:00
|
|
|
|
static void incrementEventCounter()
|
2014-09-11 20:34:41 +00:00
|
|
|
|
{
|
|
|
|
|
ProfileEvents::increment(ProfileEvents::ZooKeeperExceptions);
|
|
|
|
|
}
|
2014-10-30 13:28:45 +00:00
|
|
|
|
|
2014-03-07 13:50:58 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|