#pragma once #include #include #include #include #include #include #include namespace zkutil { using namespace DB; struct TestKeeperStorageRequest; using TestKeeperStorageRequestPtr = std::shared_ptr; using ResponseCallback = std::function; class TestKeeperStorage { public: std::atomic session_id_counter{0}; struct Node { String data; Coordination::ACLs acls; bool is_ephemeral = false; bool is_sequental = false; Coordination::Stat stat{}; int32_t seq_num = 0; }; struct ResponseForSession { int64_t session_id; Coordination::ZooKeeperResponsePtr response; }; using ResponsesForSessions = std::vector; struct RequestForSession { int64_t session_id; Coordination::ZooKeeperRequestPtr request; }; using RequestsForSessions = std::vector; using Container = std::map; using Ephemerals = std::unordered_map>; using SessionAndWatcher = std::unordered_map>; using SessionIDs = std::vector; using Watches = std::map; Container container; Ephemerals ephemerals; SessionAndWatcher sessions_and_watchers; std::atomic zxid{0}; std::atomic finalized{false}; Watches watches; Watches list_watches; /// Watches for 'list' request (watches on children). void clearDeadWatches(int64_t session_id); int64_t getZXID() { return zxid.fetch_add(1); } public: TestKeeperStorage(); ResponsesForSessions processRequest(const Coordination::ZooKeeperRequestPtr & request, int64_t session_id); ResponsesForSessions finalize(const RequestsForSessions & expired_requests); int64_t getSessionID() { return session_id_counter.fetch_add(1); } }; }