feat: always-on remote node — MCP over HTTP, TLS/token, Docker, CI, sqlc #9
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user