Files
mesh-catalog/modules/zfs/cmd/zfs-tools/findings_writer.go
T
jschoubben 53351dd30d
mesh/delivery merged: source.main moved to novox/mesh-catalog@6ba73d4e2a4f
mesh/delivery-group group feat/47-G-join12 merged: every member is merged
mesh/check failed (2): mesh-delivery-checker: no published of the tagged version of go-meshconditions of me…; and 1 more | 53351dd30df2 on b1125c02cfe6
Merge main into feat/47-G-join11: the zfs module and pacman's config first (issue 1979); zfs's findings in G's form
mesh-conditions keeps G's form: the keeper reads no observer's state (no reads, no Observers list), so main's zfs entry there goes. The zfs follower says its findings through G's findings writer over its keeper: the keeper gains the publish of the writer's three events on the finding stream finding-events and the hear of mesh-conditions.findings-asked on its own durable, nothing else; each pool or device not ONLINE is scope module, id zfs.<pool>.<device> (the device's own name), kind not-online, on the node. The manifest asks its state findings by template in requires (G §529, §577), and gains the finding-events stream and the consumes, and the keeper's bus the three events and the consumes.

Builds: design 47 G §383, §384, §387, §529, §577, A-339, A-340, A-341, A-342; design 42 zfs-owns-zfs §27, A-32, A-37, A-39, A-41

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-13 09:32:48 +01:00

65 lines
2.5 KiB
Go

package main
import (
"context"
"errors"
"fmt"
"slices"
"strings"
seat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
"git.novox.be/novox/mesh-sdk/go/views"
)
// findingsWriter is G's findings writer of the seat mesh-conditions, as the follower runs it (design 47 G §383, §384).
type findingsWriter = views.Writer[seat.Finding, seat.FindingCleared, seat.FindingsStated, seat.FindingsAskedEvent]
// StartFindings makes the follower's findings writer over the keeper and starts it (design 47 G A-339, A-341): the writer
// keeps each finding in the state `findings` through the keeper, says its events through the keeper's `finding`, hears
// findings-asked through the keeper's `hear-asks`, and states every finding it observes at its start and on each ask.
func (m *Machine) StartFindings(ctx context.Context, logf func(string, ...any)) error {
if m.keeper == nil {
return errors.New("the keeper is not reached, so no finding is said")
}
k := *m.keeper
var w *findingsWriter
w, err := views.NewWriter(views.WriterConfig[seat.Finding, seat.FindingCleared, seat.FindingsStated, seat.FindingsAskedEvent]{
Module: FindingsObserver, State: keeperFindings{k}, Kinds: []string{FindingKind}, Asked: seat.SubjectFindingsAsked,
Node: m.Node, Logf: logf,
Observe: func(ctx context.Context) (views.Observed[seat.Finding], error) {
found, err := m.ObserveFindings(ctx)
return views.Observed[seat.Finding]{Findings: found}, err
},
Publish: func(_ context.Context, subject string, data []byte, id string) error {
event, err := findingEventOf(subject)
if err != nil {
return err
}
return k.finding(event, data, id)
},
Listen: func(_ context.Context, subject string, handle func([]byte)) (func(), error) {
if subject != seat.SubjectFindingsAsked {
return nil, fmt.Errorf("the keeper hears %s alone, not %s", seat.SubjectFindingsAsked, subject)
}
return k.hearAsks(handle, func(err error) {
logf("the keeper's hear of findings-asked ended (%v); hearing it again", err)
w.Reconnected()
})
},
})
if err != nil {
return err
}
m.Findings = w
return w.Start(ctx)
}
// findingEventOf is the writer's event a subject it formed names: `<...>.<event>.<node>` (views.FindingSubjects).
func findingEventOf(subject string) (string, error) {
p := strings.Split(subject, ".")
if len(p) >= 2 && slices.Contains(FindingEvents, p[len(p)-2]) {
return p[len(p)-2], nil
}
return "", fmt.Errorf("the subject %q names no event of the findings writer", subject)
}