Files
jschoubben 6304332ad5 The seat-list finding is read from the node's own state, not kept in memory (issue 1966)
A new node-engine process cleared nothing at its first full read of the seat list, because the Waiter remembered in memory whether
it had written the finding; ace and g14 kept the condition for ever. The Waiter now asks the node's state findings whether the
finding stands, clears it at the first full read and writes it at the bound only when it does not stand.

Builds: design 47 H-7, ADR 0636 §1 (the finding is cleared at the first full read), issue 1966

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
2026-11-11 02:20:42 +01:00

79 lines
2.0 KiB
Go

package link
import (
"errors"
"fmt"
"github.com/nats-io/nats.go"
)
// FindingsBucket is the node-engine's state `findings`: the findings this engine writes in its own bucket, one key each,
// which the condition keeper raises as conditions and clears when the key goes (novox/hq ADR 0564 §2, ADR 0636 §1).
const FindingsBucket = "mesh-host_findings"
func (l *natsLink) findingsKV() (nats.KeyValue, error) {
kv, err := l.js.KeyValue(FindingsBucket)
if err != nil {
return nil, fmt.Errorf("the node-engine's state %s cannot be bound (it is created from the node-engine's manifest; "+
"written again once it is): %w", FindingsBucket, err)
}
return kv, nil
}
func (q *Session) findings() (nats.KeyValue, error) {
q.init()
q.mu.Lock()
bus := q.bus
q.mu.Unlock()
l, ok := bus.(interface{ findingsKV() (nats.KeyValue, error) })
if bus == nil || !ok {
return nil, ErrNoLink
}
return l.findingsKV()
}
// PutFinding writes one finding of this engine over the link open now.
func (q *Session) PutFinding(key string, value []byte) error {
kv, err := q.findings()
if err != nil {
return err
}
_, err = kv.Put(key, value)
return err
}
// HasFinding says whether one finding of this engine stands in its state now.
func (q *Session) HasFinding(key string) (bool, error) {
kv, err := q.findings()
if err != nil {
return false, err
}
if _, err = kv.Get(key); err != nil {
if errors.Is(err, nats.ErrKeyNotFound) {
return false, nil
}
return false, err
}
return true, nil
}
// DeleteFinding clears one finding of this engine over the link open now; a finding already gone is cleared.
func (q *Session) DeleteFinding(key string) error {
kv, err := q.findings()
if err != nil {
return err
}
if err = kv.Delete(key); err != nil && !errors.Is(err, nats.ErrKeyNotFound) {
return err
}
return nil
}
func (o OverNATS) findingsKV() (nats.KeyValue, error) {
kv, err := o.JS.KeyValue(FindingsBucket)
if err != nil {
return nil, fmt.Errorf("the node-engine's state %s cannot be bound: %w", FindingsBucket, err)
}
return kv, nil
}