Commit ad973481 authored by jan.koester's avatar jan.koester
Browse files

deb

parent e823c1d2
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
mediadb (20260503+10) unstable; urgency=high

  * cluster: add runtime switch MEDIADB_AUTO_REPAIR=0 to disable automatic
    recovery scrub and periodic rebalance in health loop during import
    troubleshooting (avoids maintenance/import contention)

 -- Jan Koester <jan.koester@tuxist.de>  Sun, 03 May 2026 20:20:00 +0200

mediadb (20260503+9) unstable; urgency=high

  * cluster/sync: fix race where a sync cycle that started just before import
+15 −4
Original line number Diff line number Diff line
#include "cluster.h"

#include <iostream>
#include <cstdlib>
#include <netplus/exception.h>

#ifdef NDEBUG
@@ -11,6 +12,12 @@

namespace mediadb {

static bool auto_repair_enabled() {
    const char* v = std::getenv("MEDIADB_AUTO_REPAIR");
    if (!v || v[0] == '\0') return true;
    return !(v[0] == '0');
}

Cluster* g_Cluster = nullptr;

void Cluster::init(const ClusterConfig& cfg) {
@@ -613,16 +620,20 @@ void Cluster::health_loop() {
                critical_ = true;
            } else if (online >= n) {
                if (degraded_) {
                    if (auto_repair_enabled()) {
                        std::cerr << "[CLUSTER] recovered — all " << online << "/"
                                  << n << " nodes online, starting scrub\n";
                        std::thread([this](){ try { scrub(); } catch (...) {} }).detach();
                    } else {
                        std::cerr << "[CLUSTER] recovered — auto scrub disabled (MEDIADB_AUTO_REPAIR=0)\n";
                    }
                    healthy_cycles = 0;
                }
                degraded_ = false;
                critical_ = false;

                // Periodic rebalance while healthy
                if (++healthy_cycles >= REBALANCE_INTERVAL) {
                if (auto_repair_enabled() && ++healthy_cycles >= REBALANCE_INTERVAL) {
                    healthy_cycles = 0;
                    std::thread([this](){
                        std::unique_lock<std::mutex> lk(scrub_mutex_, std::try_to_lock);