Files
moloapp/src/supervisor/replication/version_vector.hpp
T
retoor 3c4334cec9 feat: implement MoloApp plans 01-15 with integration
Full C++23 framework tree: runtime, observability, security,
data, app, realtime, supervisor, clients, CLI, example plus
enterprise tenancy, audit, operability, governance,
supplychain. Postgres via docker compose for tests.
2026-10-23 18:20:04 +02:00

35 lines
976 B
C++

#pragma once
#include <cstdint>
#include <map>
#include <mutex>
#include <string>
namespace molo::replication {
enum class VectorOrder {
Equal,
Before, // this <= other with at least one strict <
After, // this >= other with at least one strict >
Concurrent, // neither dominates: a real conflict happened
};
// Version vector over per-instance oplog sequences, exchanged at sync so
// each side fetches only what the other has not seen (S7-7).
class VersionVector {
public:
void update(const std::string& instance, std::uint64_t seq);
std::uint64_t get(const std::string& instance) const;
void merge(const VersionVector& other);
VectorOrder compare(const VersionVector& other) const;
std::string encode() const; // JSON object {instance: seq}
static bool decode(const std::string& text, VersionVector& out);
private:
mutable std::mutex mutex_;
std::map<std::string, std::uint64_t> versions_;
};
} // namespace molo::replication