support config clone timeout, do upgrades
This commit is contained in:
14
internal/cache/cache_migrations.go
vendored
14
internal/cache/cache_migrations.go
vendored
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// Migrations funcs should return errors along with
|
||||
// number of records updated
|
||||
type migrationFunc func(c *Cache) (error, int)
|
||||
type migrationFunc func(c *Cache) (int, error)
|
||||
|
||||
// Registry of migrations by version
|
||||
var migrations = map[string]map[string]migrationFunc{
|
||||
@@ -24,20 +24,20 @@ var migrations = map[string]map[string]migrationFunc{
|
||||
// of cache read from disk.
|
||||
// Does not check to ensure migrations were successful,
|
||||
// only checks if a version has been achieved
|
||||
func (c *Cache) DoMigrations() (error, int) {
|
||||
func (c *Cache) DoMigrations() (int, error) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
return c.doMigrations()
|
||||
}
|
||||
|
||||
func (c *Cache) doMigrations() (error, int) {
|
||||
func (c *Cache) doMigrations() (int, error) {
|
||||
var errs error
|
||||
var migrated int
|
||||
for version, migrationFuncs := range migrations {
|
||||
var funcMigrated int
|
||||
if semver.Compare(c.CacheVersion, version) < 0 {
|
||||
for name, migration := range migrationFuncs {
|
||||
err, numMigrated := migration(c)
|
||||
numMigrated, err := migration(c)
|
||||
if err != nil {
|
||||
errs = errors.Join(
|
||||
errs,
|
||||
@@ -57,10 +57,10 @@ func (c *Cache) doMigrations() (error, int) {
|
||||
migrated += funcMigrated
|
||||
}
|
||||
|
||||
return errs, migrated
|
||||
return migrated, errs
|
||||
}
|
||||
|
||||
func v010_aliases(c *Cache) (error, int) {
|
||||
func v010_aliases(c *Cache) (int, error) {
|
||||
var aliasesMigrated int
|
||||
var errs error
|
||||
for i, a := range c.Aliases {
|
||||
@@ -74,5 +74,5 @@ func v010_aliases(c *Cache) (error, int) {
|
||||
aliasesMigrated++
|
||||
}
|
||||
}
|
||||
return errs, aliasesMigrated
|
||||
return aliasesMigrated, errs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user