2022-07-05 13:47:39 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
2023-05-28 19:37:37 +00:00
|
|
|
"context"
|
2022-07-05 13:47:39 +00:00
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2022-07-05 13:47:39 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Open opens blobovnicza tree.
|
|
|
|
func (b *Blobovniczas) Open(readOnly bool) error {
|
|
|
|
b.readOnly = readOnly
|
2023-06-05 07:25:25 +00:00
|
|
|
b.metrics.SetMode(readOnly)
|
2023-08-30 20:36:48 +00:00
|
|
|
b.openManagers()
|
2022-07-05 13:47:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initializes blobovnicza tree.
|
|
|
|
//
|
|
|
|
// Should be called exactly once.
|
|
|
|
func (b *Blobovniczas) Init() error {
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Debug(logs.BlobovniczatreeInitializingBlobovniczas)
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
if b.readOnly {
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Debug(logs.BlobovniczatreeReadonlyModeSkipBlobovniczasInitialization)
|
2022-07-05 13:47:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-05-28 19:37:37 +00:00
|
|
|
return b.iterateLeaves(context.TODO(), func(p string) (bool, error) {
|
2023-08-31 08:32:09 +00:00
|
|
|
shBlz := b.getBlobovniczaWithoutCaching(p)
|
2023-08-30 20:36:48 +00:00
|
|
|
_, err := shBlz.Open()
|
2022-08-29 07:49:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
2023-08-30 20:36:48 +00:00
|
|
|
defer shBlz.Close()
|
2022-07-05 13:47:39 +00:00
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
b.log.Debug(logs.BlobovniczatreeBlobovniczaSuccessfullyInitializedClosing, zap.String("id", p))
|
2022-08-29 07:49:14 +00:00
|
|
|
return false, nil
|
2022-07-05 13:47:39 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-08-30 20:36:48 +00:00
|
|
|
func (b *Blobovniczas) openManagers() {
|
|
|
|
b.commondbManager.Open() //order important
|
|
|
|
b.activeDBManager.Open()
|
2023-08-31 08:32:09 +00:00
|
|
|
b.dbCache.Open()
|
2023-08-30 20:36:48 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 07:09:48 +00:00
|
|
|
// Close implements common.Storage.
|
2022-07-05 13:47:39 +00:00
|
|
|
func (b *Blobovniczas) Close() error {
|
2023-08-31 08:32:09 +00:00
|
|
|
b.dbCache.Close() //order important
|
|
|
|
b.activeDBManager.Close()
|
2023-08-30 20:36:48 +00:00
|
|
|
b.commondbManager.Close()
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
2023-08-31 08:32:09 +00:00
|
|
|
// returns blobovnicza with path p
|
2022-07-18 06:16:36 +00:00
|
|
|
//
|
2023-08-31 08:32:09 +00:00
|
|
|
// If blobovnicza is already cached, instance from cache is returned w/o changes.
|
|
|
|
func (b *Blobovniczas) getBlobovnicza(p string) *sharedDB {
|
|
|
|
return b.dbCache.GetOrCreate(p)
|
2022-08-29 07:49:14 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 08:32:09 +00:00
|
|
|
func (b *Blobovniczas) getBlobovniczaWithoutCaching(p string) *sharedDB {
|
2023-08-30 20:36:48 +00:00
|
|
|
return b.commondbManager.GetByPath(p)
|
2022-07-18 06:16:36 +00:00
|
|
|
}
|