Commit 9a31a68f authored by jan.koester's avatar jan.koester
Browse files

test

parent 61da3198
Loading
Loading
Loading
Loading
Loading
+15 −2
Changes for src/backends/cluster.cpp: 15 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -214,7 +214,11 @@ namespace authdb {
    }

    void ClusterBackend::lock() {
        bool was_dirty = _Dirty.load();
        fetchFromCluster();
        // fetchFromCluster/vacuum may set _Dirty; restore if no user writes pending
        if (!was_dirty)
            _Dirty = false;
    }

    void ClusterBackend::unlock() {
@@ -239,11 +243,16 @@ namespace authdb {
        if (client) {
            try {
                auto &cmtx = g_Cluster->getClientMutex();
                // Retry up to 3 times to avoid silently dropping replication
                for (int attempt = 0; attempt < 3; ++attempt) {
                    std::unique_lock<std::timed_mutex> lock(cmtx, std::chrono::seconds(3));
                    if (lock.owns_lock()) {
                        client->replicate_to_peers(dgid, 0, buf.data(), buf.size());
                } else {
                    std::cerr << "ClusterBackend::pushToCluster: skipped (lock busy)" << std::endl;
                        break;
                    }
                    if (attempt == 2) {
                        std::cerr << "ClusterBackend::pushToCluster: replication failed after retries" << std::endl;
                    }
                }
            } catch (const std::exception &e) {
                std::cerr << "Cluster replicate failed: " << e.what() << std::endl;
@@ -347,8 +356,12 @@ namespace authdb {
                            entry.data.data(), entry.data.size());
        }

        // Only mark dirty if buffer content actually changed
        if (newbuf.size() != _Buffer.size() ||
            std::memcmp(newbuf.data(), _Buffer.data(), newbuf.size()) != 0) {
            _Buffer = std::move(newbuf);
            _Dirty = true;
        }
    }

}