ClickHouse/dbms/src/Common/ZooKeeper/KeeperException.h

54 lines
1.6 KiB
C++
Raw Normal View History

2014-03-07 13:50:58 +00:00
#pragma once
#include "Types.h"
2014-03-07 13:50:58 +00:00
namespace zkutil
{
/// You should reinitialize ZooKeeper session in case of these errors
inline bool isHardwareError(int32_t zk_return_code)
{
return zk_return_code == ZooKeeperImpl::ZooKeeper::ZINVALIDSTATE
|| zk_return_code == ZooKeeperImpl::ZooKeeper::ZSESSIONEXPIRED
|| zk_return_code == ZooKeeperImpl::ZooKeeper::ZSESSIONMOVED
|| zk_return_code == ZooKeeperImpl::ZooKeeper::ZCONNECTIONLOSS
|| zk_return_code == ZooKeeperImpl::ZooKeeper::ZOPERATIONTIMEOUT;
}
/// Valid errors sent from server
inline bool isUserError(int32_t zk_return_code)
{
return zk_return_code == ZooKeeperImpl::ZooKeeper::ZNONODE
|| zk_return_code == ZooKeeperImpl::ZooKeeper::ZBADVERSION
|| zk_return_code == ZooKeeperImpl::ZooKeeper::ZNOCHILDRENFOREPHEMERALS
|| zk_return_code == ZooKeeperImpl::ZooKeeper::ZNODEEXISTS
|| zk_return_code == ZooKeeperImpl::ZooKeeper::ZNOTEMPTY;
}
using KeeperException = ZooKeeperImpl::Exception;
2014-03-07 13:50:58 +00:00
class KeeperMultiException : public KeeperException
{
public:
Requests requests;
Responses responses;
size_t failed_op_index = 0;
std::string getPathForFirstFailedOp() const;
/// If it is user error throws KeeperMultiException else throws ordinary KeeperException
/// If it is ZOK does nothing
static void check(int32_t code, const Requests & requests, const Responses & responses);
KeeperMultiException(int32_t code, const Requests & requests, const Responses & responses);
private:
2018-07-10 13:43:01 +00:00
static size_t getFailedOpIndex(int32_t code, const Responses & responses);
};
2014-03-07 13:50:58 +00:00
};