I13c: the state build-edges and the branch-build keys go with outdated
Only outdated read the edges a build of another watched branch kept in the indexer's state build-edges and the heard keys branch-build.<module>.<branch>: the state leaves the seat mesh-catalog's definition (its def BuildEdges and fixture, the generated contracts) and the indexer's manifest, and the writes, the prune at registration-changed and their test go. Builds: design 47 H2 H-A-559, H-A-558 (1), H-A-548
This commit is contained in:
@@ -20,7 +20,7 @@ const Form = 6
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "6"
|
||||
generatedFieldsDigest = "ActingRule=8a83ce7e0457 Artifact=78b05c1a9ec3 ArtifactPackage=2a3a660a934d ArtifactRef=a2f06147f4b6 BuildEdge=76f0684e254a BuildEdges=d2b95000259e BuildEdgesByModuleBranchValue=4fdf7cc1e723 CandidatesByGroupValue=9ea8c6c580d2 CandidatesByGroupValuePullsItem=90fb03643258 CandidatesByGroupValuePullsItemFpsValue=4c6783201aa3 CatalogEntry=c0a4ea25d523 CatalogRevision=d1ecaaa484af CatalogRevisionDefinitionsItem=77fcff620d48 CatalogRevisionEvent=710cbc5bfff1 CatalogRevisionsByBranchRevisionValue=17e54f635d35 CatalogRevisionsByCandidateGroupHeadsValue=17e54f635d35 CatalogRevisionsByEntryDigestValue=8755036a3051 DependentsAnswer=7538f2f5e68e Edge=7242732afaef EntryAnswer=805c2ff28e1c EntryInputs=76a7f8690dd2 EntryRef=ff109e5089e1 Fill=80f442916429 FillingEvent=5bd4df78ed84 FingerprintInputs=99a6df7f991f FullEvent=5bd4df78ed84 Head=774b4bf88ba4 InputAnswer=cd41ee65565d InputsByTimeDigestValue=a2f06147f4b6 ManifestsByDigestValue=51b3822b29c6 ModuleAnswer=499a03ce9b27 ModuleAnswerModule=c0f679e09f08 ModulesAnswer=6d119571c69e ModulesAnswerModulesItem=a70f39c60b67 ModulesByModuleValue=fc7530ba893a ModulesByModuleValueInputs2=99a6df7f991f PackagesByModuleValue=2b62574b709f PackagesByModuleValuePackagesItem=a7d30558470d PackagesByPackageSeriesValue=07421d8d3411 PackagesByPackageSeriesValueNewest=aba144994370 PackagesByPackageSeriesValueNewestContents=eca2ccf56913 PackagesByPackageSeriesValueNewestContentsPackagesItem=a7d30558470d PackagesByPackageSeriesValueNumbered=c8ffc628599c PackagesByPackageSeriesValueNumberedContents=0def6c0794ee PackagesByPackageSeriesValueNumberedContentsPackagesItem=a7d30558470d Policy=719e2f460c6f PolicyAnswer=46cdf8430557 PredefinedByListValue=ec8e3febe8ac ProvidesAnswer=7538f2f5e68e RegisterAnswer=46cdf8430557 Registration=ef03d1b2e73f RegistrationAsked=b529a0e1c5ca RegistrationChangedEvent=99a3268edf41 RegistrationHistoryByModuleVersionValue=0999b5bb7dc7 RegistrationHistoryBySourceOwnerNameVersionValue=0999b5bb7dc7 RegistrationsAnswer=8849ef618cf3 RegistrationsByModuleValue=0999b5bb7dc7 RegistrationsBySourceOwnerNameValue=0999b5bb7dc7 RevisionAnswer=258ea5124931 RoomEvent=5bd4df78ed84 SeatDefinitionChangedEvent=e271d24d58f7 SeatDefinitionRemovedEvent=f7d6171111e6 SeatDefinitionsAnswer=0fd6a59fec59 SeatDefinitionsAnswerEntry=d006f68d2be5 SeatDefinitionsAnswerSeatsItem=e271d24d58f7 SeatListAnswer=04477a8044b1 SourceCheck=d1ed7cbbd579 StepStatuses=4f50aa633e61 TakeInEntry=545ec1528499 ToolchainUsed=43b6d42376fb UnwatchAnswer=46cdf8430557 VersionArtifact=438c49a392b0 VersionEdge=b0f80e83f4dc VersionEntry=33f5b00dbda9 VersionReleasedEvent=4ccf1ea90e7f VersionsAnswer=b59e6e057e7b VersionsByModuleVersionValue=e546dfadb913 WatchAnswer=46cdf8430557"
|
||||
generatedFieldsDigest = "ActingRule=8a83ce7e0457 Artifact=78b05c1a9ec3 ArtifactPackage=2a3a660a934d ArtifactRef=a2f06147f4b6 BuildEdge=76f0684e254a CandidatesByGroupValue=9ea8c6c580d2 CandidatesByGroupValuePullsItem=90fb03643258 CandidatesByGroupValuePullsItemFpsValue=4c6783201aa3 CatalogEntry=c0a4ea25d523 CatalogRevision=d1ecaaa484af CatalogRevisionDefinitionsItem=77fcff620d48 CatalogRevisionEvent=710cbc5bfff1 CatalogRevisionsByBranchRevisionValue=17e54f635d35 CatalogRevisionsByCandidateGroupHeadsValue=17e54f635d35 CatalogRevisionsByEntryDigestValue=8755036a3051 DependentsAnswer=7538f2f5e68e Edge=7242732afaef EntryAnswer=805c2ff28e1c EntryInputs=76a7f8690dd2 EntryRef=ff109e5089e1 Fill=80f442916429 FillingEvent=5bd4df78ed84 FingerprintInputs=99a6df7f991f FullEvent=5bd4df78ed84 Head=774b4bf88ba4 InputAnswer=cd41ee65565d InputsByTimeDigestValue=a2f06147f4b6 ManifestsByDigestValue=51b3822b29c6 ModuleAnswer=499a03ce9b27 ModuleAnswerModule=c0f679e09f08 ModulesAnswer=6d119571c69e ModulesAnswerModulesItem=a70f39c60b67 ModulesByModuleValue=fc7530ba893a ModulesByModuleValueInputs2=99a6df7f991f PackagesByModuleValue=2b62574b709f PackagesByModuleValuePackagesItem=a7d30558470d PackagesByPackageSeriesValue=07421d8d3411 PackagesByPackageSeriesValueNewest=aba144994370 PackagesByPackageSeriesValueNewestContents=eca2ccf56913 PackagesByPackageSeriesValueNewestContentsPackagesItem=a7d30558470d PackagesByPackageSeriesValueNumbered=c8ffc628599c PackagesByPackageSeriesValueNumberedContents=0def6c0794ee PackagesByPackageSeriesValueNumberedContentsPackagesItem=a7d30558470d Policy=719e2f460c6f PolicyAnswer=46cdf8430557 PredefinedByListValue=ec8e3febe8ac ProvidesAnswer=7538f2f5e68e RegisterAnswer=46cdf8430557 Registration=ef03d1b2e73f RegistrationAsked=b529a0e1c5ca RegistrationChangedEvent=99a3268edf41 RegistrationHistoryByModuleVersionValue=0999b5bb7dc7 RegistrationHistoryBySourceOwnerNameVersionValue=0999b5bb7dc7 RegistrationsAnswer=8849ef618cf3 RegistrationsByModuleValue=0999b5bb7dc7 RegistrationsBySourceOwnerNameValue=0999b5bb7dc7 RevisionAnswer=258ea5124931 RoomEvent=5bd4df78ed84 SeatDefinitionChangedEvent=e271d24d58f7 SeatDefinitionRemovedEvent=f7d6171111e6 SeatDefinitionsAnswer=0fd6a59fec59 SeatDefinitionsAnswerEntry=d006f68d2be5 SeatDefinitionsAnswerSeatsItem=e271d24d58f7 SeatListAnswer=04477a8044b1 SourceCheck=d1ed7cbbd579 StepStatuses=4f50aa633e61 TakeInEntry=545ec1528499 ToolchainUsed=43b6d42376fb UnwatchAnswer=46cdf8430557 VersionArtifact=438c49a392b0 VersionEdge=b0f80e83f4dc VersionEntry=33f5b00dbda9 VersionReleasedEvent=4ccf1ea90e7f VersionsAnswer=b59e6e057e7b VersionsByModuleVersionValue=e546dfadb913 WatchAnswer=46cdf8430557"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -151,7 +151,6 @@ const (
|
||||
StateRegistrations = "registrations"
|
||||
StateRegistrationHistory = "registration-history"
|
||||
StateVersions = "versions"
|
||||
StateBuildEdges = "build-edges"
|
||||
StateInputs = "inputs"
|
||||
)
|
||||
|
||||
@@ -584,37 +583,6 @@ func DecodeVersionsByModuleVersionValue(raw []byte) (VersionsByModuleVersionValu
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// BuildEdgesByModuleBranchKey is the key of one value of the state build-edges under the form "<module>.<branch>".
|
||||
func BuildEdgesByModuleBranchKey(module, branch string) string { return module + "." + branch }
|
||||
|
||||
// ParseBuildEdgesByModuleBranchKey reads the parts of a key of the form "<module>.<branch>", in the order of the form; the last result is false for a key of another form.
|
||||
func ParseBuildEdgesByModuleBranchKey(key string) (string, string, bool) {
|
||||
rest := key
|
||||
v0, after0, found0 := strings.Cut(rest, ".")
|
||||
if !found0 || v0 == "" {
|
||||
return "", "", false
|
||||
}
|
||||
rest = after0
|
||||
if rest == "" {
|
||||
return "", "", false
|
||||
}
|
||||
v2 := rest
|
||||
rest = ""
|
||||
if rest != "" {
|
||||
return "", "", false
|
||||
}
|
||||
return v0, v2, true
|
||||
}
|
||||
|
||||
// DecodeBuildEdgesByModuleBranchValue reads one value of the state build-edges under the form "<module>.<branch>" as another part wrote it: a field BuildEdgesByModuleBranchValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
|
||||
func DecodeBuildEdgesByModuleBranchValue(raw []byte) (BuildEdgesByModuleBranchValue, int, error) {
|
||||
var v BuildEdgesByModuleBranchValue
|
||||
if err := json.Unmarshal(raw, &v); err != nil {
|
||||
return v, 0, err
|
||||
}
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// InputsByTimeDigestKey is the key of one value of the state inputs under the form "<time>.<digest>".
|
||||
func InputsByTimeDigestKey(time, digest string) string { return time + "." + digest }
|
||||
|
||||
@@ -688,17 +656,6 @@ type BuildEdge struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
// BuildEdges is the newest build's edge entries of a module on a watched branch other than the first, keyed by its fingerprint, which releases no version (design 47 G section 374).
|
||||
type BuildEdges struct {
|
||||
Edges []VersionEdge `json:"edges"`
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
Form int64 `json:"form,omitempty"`
|
||||
// the build's fingerprint
|
||||
Fp string `json:"fp"`
|
||||
Source int64 `json:"source,omitempty"`
|
||||
V int64 `json:"v"`
|
||||
}
|
||||
|
||||
// CatalogEntry is one module of a catalog graph revision as its manifest declares it, stored once by its digest (ADR 0656, design 47 Two graphs).
|
||||
type CatalogEntry struct {
|
||||
// the acting rules of the seats it claims
|
||||
@@ -1716,9 +1673,6 @@ type RegistrationHistoryBySourceOwnerNameVersionValue = Registration
|
||||
// VersionsByModuleVersionValue is one value of the state versions under the key <module>.<version>.
|
||||
type VersionsByModuleVersionValue = VersionEntry
|
||||
|
||||
// BuildEdgesByModuleBranchValue is one value of the state build-edges under the key <module>.<branch>.
|
||||
type BuildEdgesByModuleBranchValue = BuildEdges
|
||||
|
||||
// InputsByTimeDigestValue is one value of the state inputs under the key <time>.<digest>.
|
||||
type InputsByTimeDigestValue = string
|
||||
|
||||
|
||||
@@ -111,12 +111,6 @@ func TestFixtures(t *testing.T) {
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
{name: "a build of another branch", subject: "", given: "{\"edges\":[{\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"kind\":1,\"part\":\"mesh-contracts:go-nodeengine\",\"stale\":true,\"version\":\"0.1.4\",\"word\":\"imports\"}],\"fp\":\"src2:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"source\":3589,\"v\":1}", wire: "{\"edges\":[{\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"kind\":1,\"part\":\"mesh-contracts:go-nodeengine\",\"stale\":true,\"version\":\"0.1.4\",\"word\":\"imports\"}],\"fp\":\"src2:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"source\":3589,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v BuildEdgesByModuleBranchValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
{name: "an input", subject: "", given: "\"eyJ2IjoxfQ==\"", wire: "\"eyJ2IjoxfQ==\"",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v InputsByTimeDigestValue
|
||||
|
||||
@@ -566,25 +566,6 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a build of another branch",
|
||||
"of": "state:build-edges/<module>.<branch>",
|
||||
"given": {
|
||||
"v": 1,
|
||||
"fp": "src2:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
||||
"source": 3589,
|
||||
"edges": [
|
||||
{
|
||||
"kind": 1,
|
||||
"stale": true,
|
||||
"word": "imports",
|
||||
"part": "mesh-contracts:go-nodeengine",
|
||||
"version": "0.1.4",
|
||||
"digest": "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "an input",
|
||||
"of": "state:inputs/<time>.<digest>",
|
||||
|
||||
@@ -1523,21 +1523,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "build-edges",
|
||||
"template": "state",
|
||||
"history": 1,
|
||||
"description": "the newest build's edges of a module on a watched branch other than the first (design 47 G section 374)",
|
||||
"key-forms": [
|
||||
{
|
||||
"key": "<module>.<branch>",
|
||||
"value": {
|
||||
"$ref": "#/defs/BuildEdges"
|
||||
},
|
||||
"description": "a build's edges"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "inputs",
|
||||
"template": "state",
|
||||
@@ -2417,33 +2402,6 @@
|
||||
"artifacts"
|
||||
]
|
||||
},
|
||||
"BuildEdges": {
|
||||
"type": "object",
|
||||
"description": "the newest build's edge entries of a module on a watched branch other than the first, keyed by its fingerprint, which releases no version (design 47 G section 374)",
|
||||
"properties": {
|
||||
"v": {
|
||||
"type": "integer"
|
||||
},
|
||||
"fp": {
|
||||
"type": "string",
|
||||
"description": "the build's fingerprint"
|
||||
},
|
||||
"source": {
|
||||
"type": "integer"
|
||||
},
|
||||
"edges": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/defs/VersionEdge"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"v",
|
||||
"fp",
|
||||
"edges"
|
||||
]
|
||||
},
|
||||
"Artifact": {
|
||||
"type": "object",
|
||||
"description": "one artifact of a module in the catalog graph entry",
|
||||
|
||||
@@ -67,7 +67,6 @@ export declare const states: {
|
||||
readonly registrations: "registrations";
|
||||
readonly registrationHistory: "registration-history";
|
||||
readonly versions: "versions";
|
||||
readonly buildEdges: "build-edges";
|
||||
readonly inputs: "inputs";
|
||||
};
|
||||
|
||||
@@ -155,12 +154,6 @@ export declare function versionsByModuleVersionKey(module: string, version: stri
|
||||
/** The parts of a key of the form "<module>.<version>", or undefined for a key of another form. */
|
||||
export declare function parseVersionsByModuleVersionKey(_key: string): { module: string; version: string } | undefined;
|
||||
|
||||
/** The key of one value of the state build-edges under the form "<module>.<branch>". */
|
||||
export declare function buildEdgesByModuleBranchKey(module: string, branch: string): string;
|
||||
|
||||
/** The parts of a key of the form "<module>.<branch>", or undefined for a key of another form. */
|
||||
export declare function parseBuildEdgesByModuleBranchKey(_key: string): { module: string; branch: string } | undefined;
|
||||
|
||||
/** The key of one value of the state inputs under the form "<time>.<digest>". */
|
||||
export declare function inputsByTimeDigestKey(time: string, digest: string): string;
|
||||
|
||||
@@ -209,17 +202,6 @@ export interface BuildEdge {
|
||||
"version": string;
|
||||
}
|
||||
|
||||
/** the newest build's edge entries of a module on a watched branch other than the first, keyed by its fingerprint, which releases no version (design 47 G section 374) */
|
||||
export interface BuildEdges {
|
||||
"edges": VersionEdge[];
|
||||
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
|
||||
"form"?: number;
|
||||
/** the build's fingerprint */
|
||||
"fp": string;
|
||||
"source"?: number;
|
||||
"v": number;
|
||||
}
|
||||
|
||||
/** one module of a catalog graph revision as its manifest declares it, stored once by its digest (ADR 0656, design 47 Two graphs) */
|
||||
export interface CatalogEntry {
|
||||
/** the acting rules of the seats it claims */
|
||||
@@ -1129,9 +1111,6 @@ export type RegistrationHistoryBySourceOwnerNameVersionValue = Registration;
|
||||
/** is one value of the state versions under the key <module>.<version>. */
|
||||
export type VersionsByModuleVersionValue = VersionEntry;
|
||||
|
||||
/** is one value of the state build-edges under the key <module>.<branch>. */
|
||||
export type BuildEdgesByModuleBranchValue = BuildEdges;
|
||||
|
||||
/** is one value of the state inputs under the key <time>.<digest>. */
|
||||
export type InputsByTimeDigestValue = string;
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ export const states = {
|
||||
registrations: "registrations",
|
||||
registrationHistory: "registration-history",
|
||||
versions: "versions",
|
||||
buildEdges: "build-edges",
|
||||
inputs: "inputs",
|
||||
};
|
||||
|
||||
@@ -322,25 +321,6 @@ export function parseVersionsByModuleVersionKey(_key) {
|
||||
return { module, version };
|
||||
}
|
||||
|
||||
/** The key of one value of the state build-edges under the form "<module>.<branch>". */
|
||||
export function buildEdgesByModuleBranchKey(module, branch) {
|
||||
return module + "." + branch;
|
||||
}
|
||||
|
||||
/** The parts of a key of the form "<module>.<branch>", or undefined for a key of another form. */
|
||||
export function parseBuildEdgesByModuleBranchKey(_key) {
|
||||
let _rest = _key;
|
||||
const _at0 = _rest.indexOf(".");
|
||||
if (_at0 <= 0) return undefined;
|
||||
const module = _rest.slice(0, _at0);
|
||||
_rest = _rest.slice(_at0 + 1);
|
||||
if (_rest === "") return undefined;
|
||||
const branch = _rest;
|
||||
_rest = "";
|
||||
if (_rest !== "") return undefined;
|
||||
return { module, branch };
|
||||
}
|
||||
|
||||
/** The key of one value of the state inputs under the form "<time>.<digest>". */
|
||||
export function inputsByTimeDigestKey(time, digest) {
|
||||
return time + "." + digest;
|
||||
|
||||
@@ -370,9 +370,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
SayCatalogRevision: refreshingBuildModules(sayingModulesView(sayCatalogRevision(cred, views.JetStreamPublish(js)), cred, views.JetStreamPublish(js)), &buildFollow),
|
||||
SayFill: sayFill(conn, cred),
|
||||
// The catalog's released versions (design 47 G §349): the state versions, bound when it appears, and the event version-released.
|
||||
Versions: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.VersionsState), "no released version is kept, so no package-published makes a version", logger.Printf)},
|
||||
BuildEdges: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.BuildEdgesState), "no build of another watched branch keeps its edges", logger.Printf)},
|
||||
Pins: pinsStore, PinsPending: pendingOf(js, cred),
|
||||
Versions: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.VersionsState), "no released version is kept, so no package-published makes a version", logger.Printf)},
|
||||
Pins: pinsStore, PinsPending: pendingOf(js, cred),
|
||||
Held: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.HeldState), "no held take-in is kept, so indexer_pending reads none", logger.Printf)},
|
||||
Imports: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.ImportsState), "no import set is kept, so every module keeps the version line", logger.Printf)},
|
||||
Inputs: inputsStore,
|
||||
@@ -385,7 +384,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.RegistrationsState), "no registration is kept or written", logger.Printf)},
|
||||
awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.ProposalsState), "no change of a registration waits for its warrant", logger.Printf)},
|
||||
routerRecordOf(cred.Module, calls.Call, calls.Ask), ix, logger.Printf)
|
||||
registry.Pruned = ix.PruneBranchBuilds
|
||||
ix.Registry = registry
|
||||
// The gate's source revisions, on one durable per watched branch (design 47 H §743, H-A-90), bound below.
|
||||
sources := &sourceMoved{ctx: ctx, ix: ix, branches: watchedBranches(registry), bind: bindBranch(js, cred, logger.Printf), source: sourceVia(calls.Call), logf: logger.Printf}
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
// The builds of a watched branch other than the first release no version (design 47 G §371); the indexer keeps each one's
|
||||
// edge entries in the state build-edges, under <module>.<branch>, and what the branch's newest build of the module
|
||||
// published as heard, branch-build.<module>.<branch> in the state heard (§374, A-83).
|
||||
const (
|
||||
BuildEdgesState = "build-edges"
|
||||
// BranchBuildPrefix opens branch-build.<module>.<branch>, each part escaped as a name (A-80).
|
||||
BranchBuildPrefix = "branch-build."
|
||||
)
|
||||
|
||||
// BranchBuild is what a branch-build key holds: the newest build of a module on a watched branch that was heard published,
|
||||
// its source revision, the fingerprint of the branch's catalog entry at that revision and each artifact's digest.
|
||||
type BranchBuild struct {
|
||||
V int64 `json:"v"`
|
||||
Version string `json:"version"`
|
||||
Source int64 `json:"source"`
|
||||
Fp string `json:"fp"`
|
||||
Artifacts map[string]string `json:"artifacts"`
|
||||
At time.Time `json:"at"`
|
||||
}
|
||||
|
||||
// BranchBuildKey is the key of the state heard of a module's newest build on a branch.
|
||||
func BranchBuildKey(module, branch string) string {
|
||||
return BranchBuildPrefix + keys.EscapeName(module) + "." + keys.EscapeName(branch)
|
||||
}
|
||||
|
||||
// BuildEdgesKey is the key of the state build-edges of a module's build on a branch, each part escaped as a name.
|
||||
func BuildEdgesKey(module, branch string) string {
|
||||
return meshcatalog.BuildEdgesByModuleBranchKey(keys.EscapeName(module), keys.EscapeName(branch))
|
||||
}
|
||||
|
||||
// branchEntryAt is the module's entry in the newest revision of the branch taken in from that source revision (A-83: the
|
||||
// revision whose source the build names, which the indexer holds itself).
|
||||
func (ix *Indexer) branchEntryAt(ctx context.Context, module, branch string, source int64) (meshcatalog.CatalogEntry, error) {
|
||||
if ix.Revisions == nil {
|
||||
return meshcatalog.CatalogEntry{}, errors.New("the catalog graph is not kept here: no entry says the build's fingerprint")
|
||||
}
|
||||
names, err := ix.Revisions.Names(ctx)
|
||||
if err != nil {
|
||||
return meshcatalog.CatalogEntry{}, err
|
||||
}
|
||||
number := TrunkRevisionOf
|
||||
if !isTrunkBranch(branch) {
|
||||
number = func(n string) (int64, bool) { return BranchRevisionOf(branch, n) }
|
||||
}
|
||||
var numbers []int64
|
||||
for _, n := range names {
|
||||
if r, ok := number(n); ok {
|
||||
numbers = append(numbers, r)
|
||||
}
|
||||
}
|
||||
slices.SortFunc(numbers, func(a, b int64) int { return cmp.Compare(b, a) })
|
||||
for _, n := range numbers {
|
||||
name := RevisionObject(meshcatalog.CatalogRevision{Branch: branch, Revision: n})
|
||||
rev, entries, err := ReadRevision(ctx, ix.Revisions, name)
|
||||
if err != nil {
|
||||
return meshcatalog.CatalogEntry{}, err
|
||||
}
|
||||
if rev.Source != source {
|
||||
continue
|
||||
}
|
||||
for _, e := range entries {
|
||||
if e.Module == module {
|
||||
return e, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return meshcatalog.CatalogEntry{}, fmt.Errorf("the indexer keeps no revision of the branch %s at source revision %d with an entry of %s", branch, source, module)
|
||||
}
|
||||
|
||||
// hearBranchBuild takes the package-published of a build of a watched branch other than the first (A-83): the build is kept as
|
||||
// heard, and its edge entries are kept in build-edges, keyed by the fingerprint of the entry in the revision of that branch the
|
||||
// build's source names. A build of an older source revision than the one kept leaves what is kept.
|
||||
func (ix *Indexer) hearBranchBuild(ctx context.Context, p meshbuilds.PackagePublished) error {
|
||||
if ix.BuildEdges == nil {
|
||||
return errors.New("the state build-edges is not kept here")
|
||||
}
|
||||
entry, err := ix.branchEntryAt(ctx, p.Module, p.Branch, p.Source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if entry.Fp == "" {
|
||||
ix.logf("build-edges: the entry of %s on %s at source revision %d has no fingerprint, so its build keeps none", p.Module, p.Branch, p.Source)
|
||||
return nil
|
||||
}
|
||||
at := ix.now().UTC()
|
||||
err = write(ctx, ix.Heard, BranchBuildKey(p.Module, p.Branch), func(raw []byte, found bool) ([]byte, bool, error) {
|
||||
var b BranchBuild
|
||||
if found && json.Unmarshal(raw, &b) == nil && b.Source > p.Source {
|
||||
return nil, false, nil
|
||||
}
|
||||
if !found || b.Source != p.Source || b.Fp != entry.Fp {
|
||||
b = BranchBuild{Artifacts: map[string]string{}}
|
||||
}
|
||||
b.V, b.Version, b.Source, b.Fp, b.At = 1, p.Version, p.Source, entry.Fp, at
|
||||
b.Artifacts[p.Artifact] = p.Digest
|
||||
data, err := json.Marshal(b)
|
||||
return data, false, err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
edges := releaseEdges(entry, p.Dependencies)
|
||||
return write(ctx, ix.BuildEdges, BuildEdgesKey(p.Module, p.Branch), func(raw []byte, found bool) ([]byte, bool, error) {
|
||||
be := meshcatalog.BuildEdges{V: 1, Fp: entry.Fp, Source: p.Source}
|
||||
if found {
|
||||
kept, _, err := meshcatalog.DecodeBuildEdgesByModuleBranchValue(raw)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if kept.Source > p.Source {
|
||||
return nil, false, nil
|
||||
}
|
||||
if kept.Source == p.Source && kept.Fp == entry.Fp {
|
||||
be.Edges = kept.Edges
|
||||
}
|
||||
}
|
||||
for _, e := range edges {
|
||||
if !slices.ContainsFunc(be.Edges, func(x meshcatalog.VersionEdge) bool { return x.Kind == e.Kind && x.Part == e.Part && x.Word == e.Word }) {
|
||||
be.Edges = append(be.Edges, e)
|
||||
}
|
||||
}
|
||||
data, err := json.Marshal(be)
|
||||
return data, false, err
|
||||
})
|
||||
}
|
||||
|
||||
// PruneBranchBuilds forgets a module's builds of the branches its registration no longer watches beside its first
|
||||
// (registration-changed, §374): its build-edges keys and its branch-build keys of every other branch.
|
||||
func (ix *Indexer) PruneBranchBuilds(ctx context.Context, module string, watched []string) error {
|
||||
keep := map[string]bool{}
|
||||
if len(watched) > 1 {
|
||||
for _, b := range watched[1:] {
|
||||
keep[keys.EscapeName(b)] = true
|
||||
}
|
||||
}
|
||||
var errs []error
|
||||
forget := func(st Store, key string) {
|
||||
if _, rev, found, err := st.Get(ctx, key); err != nil {
|
||||
errs = append(errs, err)
|
||||
} else if found {
|
||||
if err := st.Delete(ctx, key, rev); err != nil && !errors.Is(err, ErrConflict) {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ix.BuildEdges != nil {
|
||||
all, err := ix.BuildEdges.Keys(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, k := range all {
|
||||
if m, b, ok := meshcatalog.ParseBuildEdgesByModuleBranchKey(k); ok && m == keys.EscapeName(module) && !keep[b] {
|
||||
forget(ix.BuildEdges, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ix.Heard != nil {
|
||||
all, err := ix.Heard.Keys(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prefix := BranchBuildPrefix + keys.EscapeName(module) + "."
|
||||
for _, k := range all {
|
||||
if b, ok := strings.CutPrefix(k, prefix); ok && !keep[b] {
|
||||
forget(ix.Heard, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
)
|
||||
|
||||
// Design 47 G §374, A-83, A-85: a build of a watched branch other than the first releases no version; its edge entries are kept
|
||||
// in build-edges under <module>.<branch>, the fingerprint being the entry's in the branch's revision whose source the build
|
||||
// names; registration-changed prunes the branch's keys when it is no longer watched (outdated went, design 47 H2 H-A-548).
|
||||
func TestABuildOfAnotherWatchedBranchKeepsItsEdgesAndIsPrunedWithItsBranch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), BuildEdges: newMem(), Revisions: newMemObjects(1 << 20), Registry: &Registry{Registrations: MemoryStore()}}
|
||||
for _, m := range []string{"lib", "app"} {
|
||||
raw, _ := json.Marshal(meshcatalog.Registration{Module: m, Branches: []string{"main", "beta"}})
|
||||
if err := ix.Registry.Registrations.Create(ctx, RegistrationKey(m), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
fp := func(c string) string { return "src2:" + strings.Repeat(c, 64) }
|
||||
keep := func(source int64, libFp, appFp string) {
|
||||
t.Helper()
|
||||
err := ix.KeepBranchEntries(ctx, "beta", source, map[string]meshcatalog.CatalogEntry{
|
||||
"lib": {Module: "lib", Fp: libFp, Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "lib:pkg"}}},
|
||||
"app": {Module: "app", Fp: appFp, Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "app:program"}},
|
||||
Edges: []meshcatalog.Edge{{Kind: 1, From: "lib:pkg", To: "app:program", Part: "lib:pkg", Stale: true, Word: "imports"}}}}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
keep(7, fp("a"), fp("b"))
|
||||
keep(8, fp("c"), fp("b"))
|
||||
pub := func(module, artifact, digest string, source int64, deps ...meshbuilds.Dependency) {
|
||||
t.Helper()
|
||||
if err := ix.HearPackagePublished(ctx, meshbuilds.PackagePublished{Module: module, Artifact: artifact, Digest: digest, Version: "0.1.1", Source: source, Branch: "beta", Dependencies: deps}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
pub("lib", "lib:pkg", "d1", 7)
|
||||
pub("app", "app:program", "a1", 7, meshbuilds.Dependency{Kind: 1, Part: "lib:pkg", Version: "0.1.1", Digest: "d1"})
|
||||
if v, _ := ModuleVersions(ctx, ix.Versions, "app"); len(v) != 0 {
|
||||
t.Errorf("a build of beta released %v", v)
|
||||
}
|
||||
raw, _, found, _ := ix.BuildEdges.Get(ctx, BuildEdgesKey("app", "beta"))
|
||||
be, _, err := meshcatalog.DecodeBuildEdgesByModuleBranchValue(raw)
|
||||
if !found || err != nil || be.Fp != fp("b") || be.Source != 7 || len(be.Edges) != 1 || be.Edges[0].Digest != "d1" {
|
||||
t.Fatalf("build-edges of app on beta: %+v (found %v, %v), want the fingerprint of the entry at source 7 and its kind 1 edge", be, found, err)
|
||||
}
|
||||
if err := ix.PruneBranchBuilds(ctx, "app", []string{"main", "beta"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, found, _ := ix.BuildEdges.Get(ctx, BuildEdgesKey("app", "beta")); !found {
|
||||
t.Errorf("a branch still watched lost its build-edges")
|
||||
}
|
||||
if err := ix.PruneBranchBuilds(ctx, "app", []string{"main"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, found, _ := ix.BuildEdges.Get(ctx, BuildEdgesKey("app", "beta")); found {
|
||||
t.Errorf("build-edges of app on beta stayed after beta was unwatched")
|
||||
}
|
||||
if _, _, found, _ := ix.Heard.Get(ctx, BranchBuildKey("app", "beta")); found {
|
||||
t.Errorf("branch-build of app on beta stayed after beta was unwatched")
|
||||
}
|
||||
if _, _, found, _ := ix.Heard.Get(ctx, BranchBuildKey("lib", "beta")); !found {
|
||||
t.Errorf("lib's branch-build went with app's")
|
||||
}
|
||||
}
|
||||
@@ -91,9 +91,6 @@ type Indexer struct {
|
||||
SayFill func(ctx context.Context, event, id string, f meshcatalog.Fill) error
|
||||
// Versions is the state versions (versions.go, design 47 G §349): each module's released versions; nil keeps none.
|
||||
Versions Store
|
||||
// BuildEdges is the state build-edges (branch_builds.go, design 47 G §374): the edge entries of the newest build of a module on a
|
||||
// watched branch other than the first; nil keeps none.
|
||||
BuildEdges Store
|
||||
// SayVersionReleased says the seat mesh-catalog's event version-released under the duplicate id given (§349); nil says nothing.
|
||||
SayVersionReleased func(ctx context.Context, e meshcatalog.VersionReleasedEvent, id string) error
|
||||
// Inputs is the state inputs (run_inputs.go, design 47 G §354): the inputs of the indexer's run asks; nil keeps none.
|
||||
|
||||
@@ -184,9 +184,6 @@ type Registry struct {
|
||||
HistoryOf func(ctx context.Context, module string) ([]meshcatalog.Registration, error)
|
||||
// Say says the seat mesh-catalog's event registration-changed.
|
||||
Say func(ctx context.Context, e meshcatalog.RegistrationChangedEvent) error
|
||||
// Pruned is told after a registration changed which branches the module watches, so what is kept of its builds of a branch
|
||||
// it no longer watches goes (registration-changed, design 47 G §374); nil prunes none.
|
||||
Pruned func(ctx context.Context, module string, watched []string) error
|
||||
// Branch reads a branch through the seat git; an empty branch asks the repository's default branch.
|
||||
Branch func(repository, branch string) (gitseat.BranchAnswer, error)
|
||||
// ModuleDirs reads the directories of a commit that hold a module.json through the seat git's trees, the root as "": a
|
||||
@@ -1013,13 +1010,6 @@ func (r *Registry) write(ctx context.Context, key string, p Proposal, next meshc
|
||||
r.logf("registration-changed of %s %d is not said: %v", name, next.Version, err)
|
||||
}
|
||||
}
|
||||
// A first registration watched no branch before, so no branch's builds are to be pruned.
|
||||
if r.Pruned != nil && p.Was > 0 {
|
||||
defer step("builds of unwatched branches pruned")
|
||||
if err := r.Pruned(ctx, name, next.Branches); err != nil {
|
||||
r.logf("the builds of %s on the branches it no longer watches are not pruned: %v", name, err)
|
||||
}
|
||||
}
|
||||
if key == "" {
|
||||
return nil // a write of the seed's: no proposal key of its own to end
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func ModuleVersions(ctx context.Context, st Store, module string) ([]meshcatalog
|
||||
// HearPackagePublished takes one artifact's package-published (design 47 G §349): the artifact is kept as published at its
|
||||
// version, and once every artifact the module's catalog entry names is published at it the version is released: recorded,
|
||||
// and said as version-released unless a higher one is released already (then it is recorded marked late and not said). A
|
||||
// build of a watched branch other than the registration's first releases none (§371) and keeps its edges in build-edges (§374, A-83).
|
||||
// build of a watched branch other than the registration's first releases none (§371) (A-83).
|
||||
func (ix *Indexer) HearPackagePublished(ctx context.Context, p meshbuilds.PackagePublished) error {
|
||||
if ix.Versions == nil || ix.Heard == nil {
|
||||
return errors.New("the state versions is not kept here")
|
||||
@@ -123,8 +123,8 @@ func (ix *Indexer) HearPackagePublished(ctx context.Context, p meshbuilds.Packag
|
||||
case !found:
|
||||
ix.logf("versions: %s has no registration, so %s at %s is taken as the first watched branch's", p.Module, p.Artifact, p.Version)
|
||||
case len(r.Branches) > 0 && r.Branches[0] != p.Branch:
|
||||
ix.logf("versions: %s at %s is of the branch %q, not the first watched branch %q: it releases no version, its edges are kept in build-edges", p.Artifact, p.Version, p.Branch, r.Branches[0])
|
||||
return ix.hearBranchBuild(ctx, p) // releases no version; its edges are kept in build-edges (A-83)
|
||||
ix.logf("versions: %s at %s is of the branch %q, not the first watched branch %q: it releases no version", p.Artifact, p.Version, p.Branch, r.Branches[0])
|
||||
return nil // releases no version (A-83); what outdated read of it went with outdated (design 47 H2 H-A-559)
|
||||
}
|
||||
}
|
||||
if raw, _, found, err := ix.Versions.Get(ctx, meshcatalog.VersionsByModuleVersionKey(p.Module, p.Version)); err != nil {
|
||||
|
||||
@@ -149,7 +149,7 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
|
||||
{Name: index.SeatDefinitionsState, History: 5, MaxMiB: 32},
|
||||
{Name: index.EntryIndexState, History: 1, MaxMiB: 8}, {Name: index.NamedState, History: 1, MaxMiB: 4}, // design 47 G §695
|
||||
{Name: index.RegistrationsState, History: 1, MaxMiB: 8}, {Name: index.ProposalsState, History: 1, MaxMiB: 4},
|
||||
{Name: index.VersionsState, History: 1, MaxMiB: 64}, {Name: index.BuildEdgesState, History: 1, MaxMiB: 8}, {Name: index.InputsState, History: 1, MaxMiB: 8}, {Name: index.PinsState, History: 1, MaxMiB: index.PinsCapMiB}, {Name: index.HeldState, History: 1, MaxMiB: 8}, {Name: index.ImportsState, History: 1, MaxMiB: 8}, // H-A-532 DQ-3
|
||||
{Name: index.VersionsState, History: 1, MaxMiB: 64}, {Name: index.InputsState, History: 1, MaxMiB: 8}, {Name: index.PinsState, History: 1, MaxMiB: index.PinsCapMiB}, {Name: index.HeldState, History: 1, MaxMiB: 8}, {Name: index.ImportsState, History: 1, MaxMiB: 8}, // H-A-532 DQ-3
|
||||
|
||||
{Name: index.DryRunsState, History: 1, TTL: 3600, MaxMiB: 16}}; !reflect.DeepEqual(m.State, want) { // DLV-I7, DLV-I17; design 47 H2 §804, §820
|
||||
t.Errorf("state = %+v, want %+v", m.State, want)
|
||||
|
||||
@@ -164,7 +164,6 @@
|
||||
{ "name": "registrations", "history": 1, "max-mib": 8 },
|
||||
{ "name": "proposals", "history": 1, "max-mib": 4 },
|
||||
{ "name": "versions", "history": 1, "max-mib": 64 },
|
||||
{ "name": "build-edges", "history": 1, "max-mib": 8 },
|
||||
{ "name": "inputs", "history": 1, "max-mib": 8 },
|
||||
{ "name": "pins", "history": 1, "max-mib": 4 },
|
||||
{ "name": "held", "history": 1, "max-mib": 8 },
|
||||
|
||||
Reference in New Issue
Block a user