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

127 lines
2.4 KiB
C++
Raw Normal View History

#pragma once
2015-09-29 19:19:54 +00:00
#include <common/Common.h>
#include <future>
#include <memory>
#include <vector>
#include <zookeeper/zookeeper.h>
#include <Poco/Event.h>
namespace zkutil
{
using ACLPtr = const ACL_vector *;
using Stat = Stat;
struct Op
{
public:
Op() : data(new zoo_op_t) {}
virtual ~Op() {}
virtual std::string describe() = 0;
std::unique_ptr<zoo_op_t> data;
struct Remove;
struct Create;
struct SetData;
struct Check;
};
struct Op::Remove : public Op
{
Remove(const std::string & path_, int32_t version) :
path(path_)
{
zoo_delete_op_init(data.get(), path.c_str(), version);
}
2016-06-03 16:12:51 +00:00
std::string describe() override { return "command: remove, path: " + path; }
private:
std::string path;
};
struct Op::Create : public Op
{
2014-11-30 07:01:00 +00:00
Create(const std::string & path_, const std::string & value_, ACLPtr acl, int32_t flags);
std::string getPathCreated()
{
return created_path.data();
}
2016-06-03 16:12:51 +00:00
std::string describe() override
{
return "command: create"
", path: " + path +
", value: " + value;
}
private:
std::string path;
std::string value;
std::vector<char> created_path;
};
struct Op::SetData : public Op
{
SetData(const std::string & path_, const std::string & value_, int32_t version) :
path(path_), value(value_)
{
zoo_set_op_init(data.get(), path.c_str(), value.c_str(), value.size(), version, &stat);
}
2016-06-03 16:12:51 +00:00
std::string describe() override
{
return
"command: set"
", path: " + path +
", value: " + value +
", version: " + std::to_string(data->set_op.version);
}
private:
std::string path;
std::string value;
Stat stat;
};
struct Op::Check : public Op
{
Check(const std::string & path_, int32_t version) :
path(path_)
{
zoo_check_op_init(data.get(), path.c_str(), version);
}
2016-06-03 16:12:51 +00:00
std::string describe() override { return "command: check, path: " + path; }
2016-12-12 03:33:34 +00:00
private:
std::string path;
};
struct OpResult : public zoo_op_result_t
{
2014-07-03 17:24:17 +00:00
/// Указатели в этой структуре указывают на поля в классе Op.
/// Поэтому деструктор не нужен
};
using Ops = std::vector<std::unique_ptr<Op>>;
using OpResults = std::vector<OpResult>;
using OpResultsPtr = std::shared_ptr<OpResults>;
using Strings = std::vector<std::string>;
namespace CreateMode
{
extern const int Persistent;
extern const int Ephemeral;
extern const int EphemeralSequential;
extern const int PersistentSequential;
}
using EventPtr = std::shared_ptr<Poco::Event>;
}