ClickHouse/libs/libzkutil/include/zkutil/KeeperException.h

48 lines
1.6 KiB
C
Raw Normal View History

2014-03-07 13:50:58 +00:00
#pragma once
#include <statdaemons/Exception.h>
#include <zkutil/Types.h>
#include <DB/Common/ProfileEvents.h>
#include <DB/Core/ErrorCodes.h>
2014-03-07 13:50:58 +00:00
namespace zkutil
{
class KeeperException : public DB::Exception
2014-03-07 13:50:58 +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:
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) {}
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"; }
KeeperException * clone() const { return new KeeperException(*this); }
2014-04-02 13:45:39 +00:00
/// при этих ошибках надо переинициализировать сессию с zookeeper
bool isUnrecoverable() const
{
return code == ZINVALIDSTATE || code == ZSESSIONEXPIRED || code == ZSESSIONMOVED;
}
const int32_t code;
private:
static void incrementEventCounter()
{
ProfileEvents::increment(ProfileEvents::ZooKeeperExceptions);
}
2014-03-07 13:50:58 +00:00
};
};