The numbering from before G goes (design 47 H §756, G §372): the builder keeps no state versions, marks no numbered entry on a registry seat's word and arms no numbered version's publish bound; the publishes' findings and the reservations still hear the same events (DQ-11), and a reserved version's bound is the reservation's (DQ-10). builder_versions keeps answering, from the reservations alone (DMC-5): what the seat mesh-builds' reserved answers for a name and, with a version and a digest, whether that version is reserved or released with that digest. Builds: design 47 H §756, G §372, G §381, H2 H-A-532 (DMC-5, DQ-10, DQ-11), spec 29, 41, 48
117 lines
4.9 KiB
Go
117 lines
4.9 KiB
Go
package versions
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// **A publish that ends badly is loud** (design 51 *Health and conditions*; review round 1): the builder raises the
|
|
// finding publish-refused when a holder says refused, about the name, so a later published of any version of it clears
|
|
// it. A seat's outcome that does not read is the finding seat-outcome-unread about the seat, cleared by its next outcome
|
|
// that reads. A reserved version left unpublished past its bound is the reservation's finding (version-unreleased,
|
|
// design 47 G §369); the numbered version's bound goes with the numbering from before G (design 47 H §756).
|
|
const (
|
|
// BoundsState is the builder's state of its expiring keys, each with its own time to live: a node's seven days holding the old form's window (OldFormBoundKey) and a build key left
|
|
// building unput (UnputBoundKey). Its end, the bus's marker heard on the watch, is what acts.
|
|
BoundsState = "bounds"
|
|
PublishRefused = "publish-refused"
|
|
PublishUnanswered = "publish-unanswered"
|
|
SeatOutcomeUnread = "seat-outcome-unread"
|
|
)
|
|
|
|
// The prefixes of the keys of BoundsState.
|
|
const (
|
|
oldFormBoundPrefix = "old-form."
|
|
unputBoundPrefix = "unput."
|
|
stepsBoundPrefix = "steps."
|
|
)
|
|
|
|
// UnputBoundKey is the bound of a build key a look left building because its end could not be written (issue 1966,
|
|
// novox/hq ADR 0668 §3): `unput.<build key>`. Its end while the key still stands so, with no look holding it, is the
|
|
// finding call-unanswered about the key.
|
|
func UnputBoundKey(buildKey string) string { return unputBoundPrefix + buildKey }
|
|
|
|
// StepsBoundKey is the bound of the builder's read of an ask's steps while the bus does not answer it (design 47 G §568, A-77):
|
|
// `steps.<build module>.<ask id>`. Its end, the bus's marker of its time to live, while the read is unanswered, is the finding
|
|
// call-unanswered about the ask.
|
|
func StepsBoundKey(module, askID string) string { return stepsBoundPrefix + module + "." + askID }
|
|
|
|
// StepsBoundOf is the build module and ask a steps bound names, and whether key is one.
|
|
func StepsBoundOf(key string) (module, askID string, ok bool) {
|
|
rest, ok := strings.CutPrefix(key, stepsBoundPrefix)
|
|
if !ok {
|
|
return "", "", false
|
|
}
|
|
module, askID, ok = strings.Cut(rest, ".")
|
|
return module, askID, ok && module != "" && askID != ""
|
|
}
|
|
|
|
// UnputBoundOf is the build key an unput bound names, and whether key is one.
|
|
func UnputBoundOf(key string) (string, bool) { return strings.CutPrefix(key, unputBoundPrefix) }
|
|
|
|
// OldFormBoundKey is the bound of node's seven days holding the old form's window: `old-form.<node>`.
|
|
func OldFormBoundKey(node string) string { return oldFormBoundPrefix + EscapeToken(node) }
|
|
|
|
// IsOldFormBound says key is a node's bound of the old form's window: its end steps the window, which raises the
|
|
// finding for every node past FindingAfter.
|
|
func IsOldFormBound(key string) bool { return strings.HasPrefix(key, oldFormBoundPrefix) }
|
|
|
|
// BoundsTool is builder_bounds: every key of BoundsState, what it bounds and when it ends.
|
|
const BoundsTool = "builder_bounds"
|
|
|
|
// BoundsDescription is builder_bounds' description.
|
|
const BoundsDescription = "The builder's expiring keys, its state " + BoundsState + " (design 51 *Health and conditions*): each key with what it " +
|
|
"bounds (a node's seven days holding the old " +
|
|
"form's window, whose end is the finding " + OldFormHeld + "; or a build key left building because its end could not be written, " +
|
|
"whose end is the finding call-unanswered; or a dependent's wait for a package member of a group's run, whose end fails its " +
|
|
"step), when it ends, and how long is left. The bus ends each key by its own time to live."
|
|
|
|
// Bound is a key's value in BoundsState: what it bounds, in plain words, and when it ends.
|
|
type Bound struct {
|
|
Bounds string `json:"bounds"`
|
|
Ends time.Time `json:"ends"`
|
|
}
|
|
|
|
// EncodeBound is a Bound's bytes.
|
|
func EncodeBound(what string, ends time.Time) []byte {
|
|
raw, _ := json.Marshal(Bound{Bounds: what, Ends: ends.UTC()})
|
|
return raw
|
|
}
|
|
|
|
// BoundRow is one row of builder_bounds.
|
|
type BoundRow struct {
|
|
Key string `json:"key"`
|
|
Bounds string `json:"bounds"`
|
|
Ends time.Time `json:"ends,omitzero"`
|
|
Left string `json:"left,omitempty"`
|
|
}
|
|
|
|
// AnswerBounds is builder_bounds: every key, sorted, with what it bounds and when it ends; a value that does not read
|
|
// says so in bounds.
|
|
func AnswerBounds(r Reader, now time.Time) ([]BoundRow, error) {
|
|
keys, err := r.Keys()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the state %s cannot be listed: %w", BoundsState, err)
|
|
}
|
|
sort.Strings(keys)
|
|
out := []BoundRow{}
|
|
for _, k := range keys {
|
|
raw, ok, err := r.Get(k)
|
|
if err != nil || !ok {
|
|
continue
|
|
}
|
|
var b Bound
|
|
row := BoundRow{Key: k}
|
|
if json.Unmarshal(raw, &b) != nil || b.Bounds == "" {
|
|
row.Bounds = "a value that does not read: " + string(raw)
|
|
} else {
|
|
row.Bounds, row.Ends, row.Left = b.Bounds, b.Ends, b.Ends.Sub(now).Round(time.Second).String()
|
|
}
|
|
out = append(out, row)
|
|
}
|
|
return out, nil
|
|
}
|