Files
llmgw/internal/store/clusterstate.go
T
Ilker ManapandClaude Opus 5.5 8df78a4d41 The firewall setting reaches the mirror machine and the store's members
The leading control plane tells the mirror over its API (PUT /v1/firewall,
kept as .firewall.json beside the models and applied by the same path unit
control planes use), and keeps the state in the store's cluster_state for
members that run no llmgw, which a root timer reads from the member's own
copy. The mirror also lets in the network of every node and control plane
the leader knows. Tried on the PoC: off, on and a network added, on every
kind of machine.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-09 08:53:17 +02:00

31 lines
981 B
Go

package store
import (
"context"
"database/sql"
"errors"
"time"
)
// PutClusterState keeps a value under a key, for machines that read the
// store rather than a control plane; it reports whether it changed.
func (s *DB) PutClusterState(ctx context.Context, key, value string) (bool, error) {
if old, err := s.ClusterState(ctx, key); err == nil && old == value {
return false, nil
}
_, err := s.db.ExecContext(ctx, `INSERT INTO cluster_state (key, value, updated_at) VALUES (?, ?, ?)
ON CONFLICT (key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at`,
key, value, millis(time.Now()))
return err == nil, err
}
// ClusterState reads a value; ErrNotFound when there is none.
func (s *DB) ClusterState(ctx context.Context, key string) (string, error) {
var v string
err := s.db.QueryRowContext(ctx, `SELECT value FROM cluster_state WHERE key = ?`, key).Scan(&v)
if errors.Is(err, sql.ErrNoRows) {
return "", ErrNotFound
}
return v, err
}