mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
metadb: add optional fast restart path that skips storage walk when (version + commit + storage config) matches metaDB stamp (#4026)
* chore(metadb): add writer version to interface Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * chore(metadb): add writer version to db mock Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * chore(metadb): implement writer version for bolt, redis, and dynamodb Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * feat(metadb): add optional fast restart path that skips storage walk when binary identity matches metaDB stamp binary identity is determined by the current release tag/commit and stored in metaDB after a successful storage parse. When fast restart is enabled, the next startup will skip the parse if the stored identity matches the current binary Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * chore(cli): serve: add a way to force reparse storage Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * refactor(meta): version: split to avoid global state mutation in tests Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * fix(meta): version: include commit in writerVersion to distinguish retags Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * chore(config): add IsFastRestartEnabled() test Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * fix(meta): skip writer-version stamp when storage parse is incomplete ParseStorage returns nil even when individual repos fail to parse or are only partially parsed (a missing manifest blob), so MaybeParseStorage would stamp a partially-populated metaDB as good. On the next restart fastRestart trusts the stamp, skips the storage walk, and never recovers. Track per-repo outcomes via parseStats and stamp only when the walk fully populated the metaDB, otherwise log and continue so the next restart reparses Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * fix(docs): readme: remove trailing comma from JSON config Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * fix(meta): dynamodb: use context.Background instead of context.TODO Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * fix(meta): invalidate fast restart on storage config changes Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * chore(meta): dynamodb: use context.Background() instead of context.TODO() Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * docs(meta): dynamodb: add comment about nil AttributeValue handling in GetWriterVersion Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * chore: rename writer-version stamp to fast-restart stamp also replaces the version/commit tracking to use BinaryVersion instead of WriterVersion This should make things more clear Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * fix(config): ensure FastRestart is on GlobalStorageConfig This is not a per-subpath setting Signed-off-by: Jacob McSwain <jacob@mcswain.dev> * fix(metadb): redis: tests: ensure clients are closed Signed-off-by: Jacob McSwain <jacob@mcswain.dev> --------- Signed-off-by: Jacob McSwain <jacob@mcswain.dev>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package version
|
||||
|
||||
import "zotregistry.dev/zot/v2/pkg/buildinfo"
|
||||
|
||||
// CurrentBinaryVersion returns this binary's identity used to stamp the
|
||||
// metaDB after a successful storage parse. For released builds it combines the
|
||||
// release tag and commit ("<tag>+<commit>"). For local development builds
|
||||
// without a release tag it is "dev-<commit>". Builds without either ldflag
|
||||
// (typically `go run` and `go test`) return "" which always forces a full parse.
|
||||
func CurrentBinaryVersion() string {
|
||||
return binaryVersion(buildinfo.ReleaseTag, buildinfo.Commit)
|
||||
}
|
||||
|
||||
// binaryVersion is the core of CurrentBinaryVersion, split out so the
|
||||
// release-tag/commit resolution can be tested directly without mutating the
|
||||
// process-global buildinfo values.
|
||||
func binaryVersion(releaseTag, commit string) string {
|
||||
switch {
|
||||
case releaseTag != "" && commit != "":
|
||||
return releaseTag + "+" + commit
|
||||
case releaseTag != "":
|
||||
return releaseTag
|
||||
case commit != "":
|
||||
return "dev-" + commit
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestBinaryVersion(t *testing.T) {
|
||||
Convey("binaryVersion combines release tag and commit", t, func() {
|
||||
So(binaryVersion("v2.3.4", "abc123"), ShouldEqual, "v2.3.4+abc123")
|
||||
})
|
||||
|
||||
Convey("binaryVersion distinguishes a retagged release", t, func() {
|
||||
// Same tag re-pointed at a different commit must yield a different stamp
|
||||
So(binaryVersion("v2.3.4", "abc123"), ShouldNotEqual, binaryVersion("v2.3.4", "def456"))
|
||||
})
|
||||
|
||||
Convey("binaryVersion falls back to the bare tag when commit is unset", t, func() {
|
||||
So(binaryVersion("v2.3.4", ""), ShouldEqual, "v2.3.4")
|
||||
})
|
||||
|
||||
Convey("binaryVersion falls back to dev-<commit> without a release tag", t, func() {
|
||||
So(binaryVersion("", "abc123"), ShouldEqual, "dev-abc123")
|
||||
})
|
||||
|
||||
Convey("binaryVersion returns empty when neither is set", t, func() {
|
||||
So(binaryVersion("", ""), ShouldEqual, "")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user