mirror of
https://github.com/project-zot/zot.git
synced 2026-06-18 05:28:07 +08:00
273b15364b
* 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>
64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
package redis
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/alicebob/miniredis/v2"
|
|
"github.com/redis/go-redis/v9"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"zotregistry.dev/zot/v2/pkg/log"
|
|
)
|
|
|
|
func Test(t *testing.T) {
|
|
Convey("Test redis metadb key generation", t, func() {
|
|
miniRedis := miniredis.RunT(t)
|
|
|
|
log := log.NewTestLogger()
|
|
So(log, ShouldNotBeNil)
|
|
|
|
opts, err := redis.ParseURL("redis://" + miniRedis.Addr())
|
|
So(err, ShouldBeNil)
|
|
|
|
client := redis.NewClient(opts)
|
|
|
|
params := DBDriverParameters{KeyPrefix: "zot"}
|
|
|
|
metaDB, err := New(client, params, log)
|
|
So(err, ShouldBeNil)
|
|
So(metaDB.ImageMetaKey, ShouldEqual, "zot:ImageMeta")
|
|
So(metaDB.RepoMetaKey, ShouldEqual, "zot:RepoMeta")
|
|
So(metaDB.RepoLastUpdatedKey, ShouldEqual, "zot:RepoLastUpdated")
|
|
So(metaDB.RepoBlobsKey, ShouldEqual, "zot:RepoBlobsMeta")
|
|
So(metaDB.UserDataKey, ShouldEqual, "zot:UserData")
|
|
So(metaDB.UserAPIKeysKey, ShouldEqual, "zot:UserAPIKeys")
|
|
So(metaDB.VersionKey, ShouldEqual, "zot:Version")
|
|
So(metaDB.FastRestartStampKey, ShouldEqual, "zot:FastRestartStamp")
|
|
So(metaDB.LocksKey, ShouldEqual, "zot:Locks")
|
|
|
|
So(metaDB.getUserLockKey("user1"), ShouldEqual, "zot:Locks:User:user1")
|
|
So(metaDB.getRepoLockKey("repo1"), ShouldEqual, "zot:Locks:Repo:repo1")
|
|
So(metaDB.getImageLockKey("image1"), ShouldEqual, "zot:Locks:Image:image1")
|
|
So(metaDB.getVersionLockKey(), ShouldEqual, "zot:Locks:Version")
|
|
|
|
params = DBDriverParameters{KeyPrefix: "someprefix"}
|
|
|
|
metaDB, err = New(client, params, log)
|
|
So(err, ShouldBeNil)
|
|
So(metaDB.ImageMetaKey, ShouldEqual, "someprefix:ImageMeta")
|
|
So(metaDB.RepoMetaKey, ShouldEqual, "someprefix:RepoMeta")
|
|
So(metaDB.RepoLastUpdatedKey, ShouldEqual, "someprefix:RepoLastUpdated")
|
|
So(metaDB.RepoBlobsKey, ShouldEqual, "someprefix:RepoBlobsMeta")
|
|
So(metaDB.UserDataKey, ShouldEqual, "someprefix:UserData")
|
|
So(metaDB.UserAPIKeysKey, ShouldEqual, "someprefix:UserAPIKeys")
|
|
So(metaDB.VersionKey, ShouldEqual, "someprefix:Version")
|
|
So(metaDB.FastRestartStampKey, ShouldEqual, "someprefix:FastRestartStamp")
|
|
So(metaDB.LocksKey, ShouldEqual, "someprefix:Locks")
|
|
|
|
So(metaDB.getUserLockKey("user1"), ShouldEqual, "someprefix:Locks:User:user1")
|
|
So(metaDB.getRepoLockKey("repo1"), ShouldEqual, "someprefix:Locks:Repo:repo1")
|
|
So(metaDB.getImageLockKey("image1"), ShouldEqual, "someprefix:Locks:Image:image1")
|
|
So(metaDB.getVersionLockKey(), ShouldEqual, "someprefix:Locks:Version")
|
|
})
|
|
}
|