From 7b92b411a55f23ed7dbd1c9df04e624b6f36dcd1 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Wed, 4 Nov 2026 17:09:04 -0800 Subject: [PATCH] fix: reconcile after a peer push, not only after a pull (#8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A push-only node — a replica with no peers of its own, which is exactly the dhg.lol deployment — received observations but never rebuilt entries, so search returned nothing while the log filled up. The batch handler now signals the sweep, and reconcile runs when either direction changed the log. --- internal/watch/gossip.go | 8 ++++++++ internal/watch/watch.go | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/watch/gossip.go b/internal/watch/gossip.go index f97ebc1..617837d 100644 --- a/internal/watch/gossip.go +++ b/internal/watch/gossip.go @@ -31,6 +31,11 @@ type Node struct { Name string Addr string // advertised base URL, e.g. http://192.168.1.20:8931 Metrics *metrics.Metrics + // OnIngest runs when a peer's push added observations. Receiving a push + // changes the log just like pulling does, so the caller needs to rebuild + // derived state — otherwise a push-only node (a replica with no peers of + // its own) keeps an empty entries cache. + OnIngest func(inserted int) } // pingResponse is the anti-entropy summary returned by /v1/ping. @@ -126,6 +131,9 @@ func (n *Node) handleBatch(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } + if inserted > 0 && n.OnIngest != nil { + n.OnIngest(inserted) + } writeJSON(w, map[string]any{ "accepted": inserted, "conflict": len(rows) - inserted, diff --git a/internal/watch/watch.go b/internal/watch/watch.go index ffde2c1..2dfbad6 100644 --- a/internal/watch/watch.go +++ b/internal/watch/watch.go @@ -51,6 +51,9 @@ type Watcher struct { metricsSrv *http.Server quit chan struct{} quitOnce sync.Once + // pendingReconcile is set when a peer's push added observations, so the + // next sweep rebuilds derived state without reconciling per HTTP request. + pendingReconcile atomic.Bool } // fileDebouncer schedules one ingest per path a settle-window after the last @@ -158,6 +161,7 @@ func (w *Watcher) Start() error { // seed is still ingesting. Vault/dirs are logged after the seed below. gossipAddr := ListenAddr() node := &Node{Kdb: w.knoxDB, Name: "knox", Addr: AdvertiseAddr(), Metrics: w.metrics} + node.OnIngest = func(int) { w.pendingReconcile.Store(true) } srv := &http.Server{ Addr: gossipAddr, Handler: httpauth.Middleware(node.Handler()), @@ -861,7 +865,10 @@ func (w *Watcher) syncGossip() { // auto-threads are derived state that reconcile rebuilds. Comparing entry // counts can never trigger this (pushes/pulls never touch entries directly), // so reconcile fires on the sweep's newly-inserted observation count. - if pulled > 0 { + // Reconcile when this sweep changed the log, in either direction: a pull + // inserts rows here, a peer's push inserted them in the HTTP handler. + pushedIn := w.pendingReconcile.Swap(false) + if pulled > 0 || pushedIn { created, linked, err := Reconcile(w.knoxDB) if err != nil { log.Printf("[knox] gossip reconcile: %v", err)