ClickHouse/src/Coordination/NuKeeperStorageSerializer.cpp

91 lines
2.8 KiB
C++
Raw Normal View History

2021-02-01 14:14:59 +00:00
#include <Coordination/NuKeeperStorageSerializer.h>
2021-01-21 11:07:55 +00:00
#include <IO/WriteHelpers.h>
#include <IO/ReadHelpers.h>
#include <Common/ZooKeeper/ZooKeeperIO.h>
namespace DB
{
namespace
{
2021-02-26 14:54:59 +00:00
void writeNode(const NuKeeperStorage::Node & node, WriteBuffer & out)
{
Coordination::write(node.data, out);
Coordination::write(node.acls, out);
Coordination::write(node.ephemeral_owner, out);
Coordination::write(node.is_sequental, out);
Coordination::write(node.stat, out);
Coordination::write(node.seq_num, out);
}
2021-01-21 11:07:55 +00:00
2021-02-26 14:54:59 +00:00
void readNode(NuKeeperStorage::Node & node, ReadBuffer & in)
{
Coordination::read(node.data, in);
Coordination::read(node.acls, in);
Coordination::read(node.ephemeral_owner, in);
Coordination::read(node.is_sequental, in);
Coordination::read(node.stat, in);
Coordination::read(node.seq_num, in);
}
2021-01-21 11:07:55 +00:00
}
2021-02-01 14:14:59 +00:00
void NuKeeperStorageSerializer::serialize(const NuKeeperStorage & storage, WriteBuffer & out)
2021-01-21 11:07:55 +00:00
{
Coordination::write(storage.zxid, out);
Coordination::write(storage.session_id_counter, out);
Coordination::write(storage.container.size(), out);
2021-02-26 13:53:34 +00:00
//for (const auto & [path, node] : storage.container)
//{
// Coordination::write(path, out);
// writeNode(node, out);
//}
2021-01-21 11:07:55 +00:00
Coordination::write(storage.ephemerals.size(), out);
for (const auto & [session_id, paths] : storage.ephemerals)
{
Coordination::write(session_id, out);
Coordination::write(paths.size(), out);
for (const auto & path : paths)
Coordination::write(path, out);
}
}
2021-02-01 14:14:59 +00:00
void NuKeeperStorageSerializer::deserialize(NuKeeperStorage & storage, ReadBuffer & in)
2021-01-21 11:07:55 +00:00
{
int64_t session_id_counter, zxid;
Coordination::read(zxid, in);
Coordination::read(session_id_counter, in);
storage.zxid = zxid;
storage.session_id_counter = session_id_counter;
size_t container_size;
Coordination::read(container_size, in);
2021-02-19 09:24:50 +00:00
2021-02-26 13:53:34 +00:00
//size_t current_size = 0;
//while (current_size < container_size)
//{
// std::string path;
// Coordination::read(path, in);
// NuKeeperStorage::Node node;
// readNode(node, in);
// storage.container[path] = node;
// current_size++;
//}
2021-01-21 11:07:55 +00:00
size_t ephemerals_size;
Coordination::read(ephemerals_size, in);
while (storage.ephemerals.size() < ephemerals_size)
{
int64_t session_id;
size_t ephemerals_for_session;
Coordination::read(session_id, in);
Coordination::read(ephemerals_for_session, in);
while (storage.ephemerals[session_id].size() < ephemerals_for_session)
{
std::string ephemeral_path;
Coordination::read(ephemeral_path, in);
storage.ephemerals[session_id].emplace(ephemeral_path);
}
}
}
}