Feat v0.6.0 cluster registry (#36)
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-go-pg (push) Successful in 2m40s
CI/CD / test-sqlite (push) Successful in 3m1s
CI/CD / build-and-deploy (push) Successful in 1m22s

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #36.
This commit is contained in:
2026-03-30 22:57:11 +00:00
committed by xcaliber
parent 768f15b3cd
commit 1a7f41493d
21 changed files with 1101 additions and 19 deletions

View File

@@ -0,0 +1,37 @@
package store
import (
"context"
"encoding/json"
"time"
)
// ClusterNode represents a registered node in the cluster registry.
type ClusterNode struct {
NodeID string `json:"node_id"`
Endpoint string `json:"endpoint"`
Seq int `json:"seq"`
RegisteredAt time.Time `json:"registered_at"`
Heartbeat time.Time `json:"heartbeat"`
Stats json.RawMessage `json:"stats"`
}
// ClusterStore manages the node_registry table for cluster self-assembly.
// Postgres-only — SQLite deployments set this to nil.
type ClusterStore interface {
// Register inserts or re-registers a node (idempotent).
Register(ctx context.Context, nodeID, endpoint string) error
// Heartbeat updates the node's heartbeat timestamp and stats.
// Returns rows affected — 0 means the node was swept (self-eviction).
Heartbeat(ctx context.Context, nodeID string, stats json.RawMessage) (int64, error)
// SweepStale deletes nodes whose heartbeat is older than threshold.
SweepStale(ctx context.Context, threshold time.Duration) (int64, error)
// ListNodes returns all registered nodes ordered by sequence.
ListNodes(ctx context.Context) ([]ClusterNode, error)
// Deregister removes a node (best-effort cleanup on shutdown).
Deregister(ctx context.Context, nodeID string) error
}