Main reverted G's half merge (#189, reverted by8afc3ebin #191) and then took the reader release's S1-S5, which copied G's code. G's form holds where they differ (process_bus.go, seats.go, state.go and their tests); the release's kept names stay so main's callers keep building: SeatViewPrefix beside SeatReadPrefix, and QueueInvoke's empty strings on not-ok (with its test TestQueueInvoke). The tree differs from G's headf30dee54only by those and the release's two tests (objects cap option, seat states and stream kinds). Builds: design 47 G (the milestone's sdk part, as atf30dee54) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
64 lines
2.6 KiB
Go
64 lines
2.6 KiB
Go
package buscompose
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// The mesh's caps on a bucket, the same for every module: a value is a piece of state, not a file,
|
|
// and a bucket that grew without bound would be one module filling the bus's disk for everyone.
|
|
const (
|
|
StateMaxValueBytes = 256 * 1024
|
|
)
|
|
|
|
// A Bucket is one module's declared state as the bus holds it.
|
|
type Bucket struct {
|
|
Module string
|
|
Name string
|
|
// History is how many values a key keeps; zero is one.
|
|
History int
|
|
// TTLSeconds is how long a value lives; zero is until replaced or deleted.
|
|
TTLSeconds int
|
|
// PerMachine says each machine's instance writes only the keys of its machine (novox/hq ADR 0260; design 46
|
|
// 7-approval-mark §13): the key named for its machine and the keys below it, PerMachineKeys, and no other machine's.
|
|
PerMachine bool
|
|
// KeyTTL says the bucket allows a time to live per key (novox/hq ADR 0433 §1): its owner writes each key with its
|
|
// own, and the server writes a delete marker, kept KeyTTLMarkerTTL, when it ends.
|
|
KeyTTL bool
|
|
// MaxMiB is the bucket's cap in MiB (design 47 G §469); zero is no cap.
|
|
MaxMiB int
|
|
}
|
|
|
|
// MaxBytes is the bucket's cap in bytes as the bus's maximum size: -1, unbounded, where it names none.
|
|
func (b Bucket) MaxBytes() int64 {
|
|
if b.MaxMiB <= 0 {
|
|
return -1
|
|
}
|
|
return int64(b.MaxMiB) * 1024 * 1024
|
|
}
|
|
|
|
// PerMachineKeys are the keys a machine's instance of a per-machine state reaches (design 46 7-approval-mark §13): the key
|
|
// named for its machine, as every module's per-machine key keeps its form, and the keys below it, `<node>.>`; no other
|
|
// machine's. A membership's per-machine state (membership.StateIssued's Key) reaches the same.
|
|
func PerMachineKeys(node string) []string { return []string{node, node + ".>"} }
|
|
|
|
// BucketName is the bucket a module's state lives in: the module and the local name joined by an
|
|
// underscore, which neither may contain, so two modules can never derive one bucket.
|
|
func BucketName(module, name string) string { return module + "_" + name }
|
|
|
|
// Bucket is this bucket's name on the bus.
|
|
func (b Bucket) Bucket() string { return BucketName(b.Module, b.Name) }
|
|
|
|
// Why is carried into the server's description of the bucket, so somebody reading the server's
|
|
// own state finds whose it is and why it is kept.
|
|
func (b Bucket) Why() string {
|
|
return fmt.Sprintf("%s's state %q (novox/hq ADR 0201): its current value per key, written by %s, "+
|
|
"read by whatever declares it reads it; kept when %s is unassigned, because it is data",
|
|
b.Module, b.Name, b.Module, b.Module)
|
|
}
|
|
|
|
// KeyedRead is one key of another module's state a principal reads, and no other key of it.
|
|
type KeyedRead struct {
|
|
Read string `json:"read"`
|
|
Key string `json:"key"`
|
|
}
|