2014-03-07 13:50:58 +00:00
|
|
|
#pragma once
|
2016-01-11 21:46:36 +00:00
|
|
|
|
2018-04-03 18:24:18 +00:00
|
|
|
#include "Types.h"
|
2016-10-24 02:02:37 +00:00
|
|
|
|
2014-03-07 13:50:58 +00:00
|
|
|
|
|
|
|
namespace zkutil
|
|
|
|
{
|
|
|
|
|
2017-10-03 14:44:10 +00:00
|
|
|
|
|
|
|
/// You should reinitialize ZooKeeper session in case of these errors
|
2018-03-21 21:40:53 +00:00
|
|
|
inline bool isHardwareError(int32_t zk_return_code)
|
2017-10-03 14:44:10 +00:00
|
|
|
{
|
2018-03-22 12:15:06 +00:00
|
|
|
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;
|
2017-10-03 14:44:10 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 22:37:50 +00:00
|
|
|
/// Valid errors sent from server
|
|
|
|
inline bool isUserError(int32_t zk_return_code)
|
|
|
|
{
|
2018-03-22 12:15:06 +00:00
|
|
|
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;
|
2018-01-19 22:37:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 14:44:10 +00:00
|
|
|
|
2018-04-03 18:24:18 +00:00
|
|
|
using KeeperException = ZooKeeperImpl::Exception;
|
2014-03-07 13:50:58 +00:00
|
|
|
|
2018-03-13 20:36:22 +00:00
|
|
|
|
|
|
|
class KeeperMultiException : public KeeperException
|
|
|
|
{
|
|
|
|
public:
|
2018-03-21 21:40:53 +00:00
|
|
|
Requests requests;
|
|
|
|
Responses responses;
|
2018-03-24 20:00:16 +00:00
|
|
|
size_t failed_op_index = 0;
|
|
|
|
|
|
|
|
std::string getPathForFirstFailedOp() const;
|
2018-03-13 20:36:22 +00:00
|
|
|
|
|
|
|
/// If it is user error throws KeeperMultiException else throws ordinary KeeperException
|
|
|
|
/// If it is ZOK does nothing
|
2018-03-21 21:40:53 +00:00
|
|
|
static void check(int32_t code, const Requests & requests, const Responses & responses);
|
2018-03-13 20:36:22 +00:00
|
|
|
|
2018-03-23 23:15:14 +00:00
|
|
|
KeeperMultiException(int32_t code, const Requests & requests, const Responses & responses);
|
2018-03-25 00:56:08 +00:00
|
|
|
|
|
|
|
private:
|
2018-07-10 13:43:01 +00:00
|
|
|
static size_t getFailedOpIndex(int32_t code, const Responses & responses);
|
2018-03-13 20:36:22 +00:00
|
|
|
};
|
|
|
|
|
2014-03-07 13:50:58 +00:00
|
|
|
};
|