mirror of
https://github.com/project-zot/zot.git
synced 2026-06-18 05:28:07 +08:00
fix: close metadb on shutdown (#3277)
Fixes https://github.com/project-zot/helm-charts/issues/70 Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com>
This commit is contained in:
committed by
GitHub
parent
966d4584ba
commit
b2a5afc5c8
@@ -455,12 +455,18 @@ func (c *Controller) LoadNewConfig(newConfig *config.Config) {
|
||||
}
|
||||
|
||||
func (c *Controller) Shutdown() {
|
||||
// stop all background tasks
|
||||
c.StopBackgroundTasks()
|
||||
|
||||
if c.Server != nil {
|
||||
ctx := context.Background()
|
||||
_ = c.Server.Shutdown(ctx)
|
||||
}
|
||||
|
||||
// close metadb
|
||||
if c.MetaDB != nil {
|
||||
c.MetaDB.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// Will stop scheduler and wait for all tasks to finish their work.
|
||||
|
||||
@@ -2102,3 +2102,10 @@ func resetBucket(transaction *bbolt.Tx, bucketName string) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (bdw *BoltDB) Close() error {
|
||||
err := bdw.DB.Close()
|
||||
bdw.DB = nil
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2274,3 +2274,7 @@ func (dwr *DynamoDB) getDBVersion() (string, error) {
|
||||
|
||||
return version, nil
|
||||
}
|
||||
|
||||
func (dwr *DynamoDB) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -147,3 +147,7 @@ func toStringIfOk(cacheDriverConfig map[string]interface{},
|
||||
|
||||
return str, true
|
||||
}
|
||||
|
||||
func Close(metadb mTypes.MetaDB) error {
|
||||
return metadb.Close()
|
||||
}
|
||||
|
||||
@@ -2321,3 +2321,10 @@ func unmarshalProtoRepoBlobs(repo string, repoBlobsBytes []byte) (*proto_go.Repo
|
||||
func join(xs ...string) string {
|
||||
return strings.Join(xs, ":")
|
||||
}
|
||||
|
||||
func (rc *RedisDB) Close() error {
|
||||
err := rc.Client.Close()
|
||||
rc.Client = nil
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -156,6 +156,9 @@ type MetaDB interface { //nolint:interfacebloat
|
||||
ImageTrustStore() ImageTrustStore
|
||||
|
||||
SetImageTrustStore(imgTrustStore ImageTrustStore)
|
||||
|
||||
// Close will close the db
|
||||
Close() error
|
||||
}
|
||||
|
||||
type UserDB interface { //nolint:interfacebloat
|
||||
|
||||
@@ -103,6 +103,8 @@ type MetaDBMock struct {
|
||||
GetAllRepoNamesFn func() ([]string, error)
|
||||
|
||||
ResetDBFn func() error
|
||||
|
||||
CloseFn func() error
|
||||
}
|
||||
|
||||
func (sdm MetaDBMock) DeleteRepoMeta(repo string) error {
|
||||
@@ -461,3 +463,11 @@ func (sdm MetaDBMock) ResetRepoReferences(repo string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sdm MetaDBMock) Close() error {
|
||||
if sdm.CloseFn != nil {
|
||||
return sdm.CloseFn()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user