feat: always-on remote node — MCP over HTTP, TLS/token, Docker, CI, sqlc #9
@@ -31,6 +31,11 @@ type Node struct {
|
|||||||
Name string
|
Name string
|
||||||
Addr string // advertised base URL, e.g. http://192.168.1.20:8931
|
Addr string // advertised base URL, e.g. http://192.168.1.20:8931
|
||||||
Metrics *metrics.Metrics
|
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.
|
// 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)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if inserted > 0 && n.OnIngest != nil {
|
||||||
|
n.OnIngest(inserted)
|
||||||
|
}
|
||||||
writeJSON(w, map[string]any{
|
writeJSON(w, map[string]any{
|
||||||
"accepted": inserted,
|
"accepted": inserted,
|
||||||
"conflict": len(rows) - inserted,
|
"conflict": len(rows) - inserted,
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ type Watcher struct {
|
|||||||
metricsSrv *http.Server
|
metricsSrv *http.Server
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
quitOnce sync.Once
|
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
|
// 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.
|
// seed is still ingesting. Vault/dirs are logged after the seed below.
|
||||||
gossipAddr := ListenAddr()
|
gossipAddr := ListenAddr()
|
||||||
node := &Node{Kdb: w.knoxDB, Name: "knox", Addr: AdvertiseAddr(), Metrics: w.metrics}
|
node := &Node{Kdb: w.knoxDB, Name: "knox", Addr: AdvertiseAddr(), Metrics: w.metrics}
|
||||||
|
node.OnIngest = func(int) { w.pendingReconcile.Store(true) }
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: gossipAddr,
|
Addr: gossipAddr,
|
||||||
Handler: httpauth.Middleware(node.Handler()),
|
Handler: httpauth.Middleware(node.Handler()),
|
||||||
@@ -861,7 +865,10 @@ func (w *Watcher) syncGossip() {
|
|||||||
// auto-threads are derived state that reconcile rebuilds. Comparing entry
|
// auto-threads are derived state that reconcile rebuilds. Comparing entry
|
||||||
// counts can never trigger this (pushes/pulls never touch entries directly),
|
// counts can never trigger this (pushes/pulls never touch entries directly),
|
||||||
// so reconcile fires on the sweep's newly-inserted observation count.
|
// 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)
|
created, linked, err := Reconcile(w.knoxDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[knox] gossip reconcile: %v", err)
|
log.Printf("[knox] gossip reconcile: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user