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
|
|
|
|
2023-08-30 20:36:48 +00:00
|
|
|
b.openManagers()
|
|
|
|
|
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-30 20:36:48 +00:00
|
|
|
shBlz := b.openBlobovniczaNoCache(p)
|
|
|
|
_, 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()
|
|
|
|
}
|
|
|
|
|
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-30 20:36:48 +00:00
|
|
|
b.activeDBManager.Close() //order important
|
|
|
|
b.commondbManager.Close()
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-07-18 06:16:36 +00:00
|
|
|
|
|
|
|
// opens and returns blobovnicza with path p.
|
|
|
|
//
|
|
|
|
// If blobovnicza is already opened and cached, instance from cache is returned w/o changes.
|
2023-08-30 20:36:48 +00:00
|
|
|
func (b *Blobovniczas) openBlobovnicza(p string) *sharedDB {
|
|
|
|
return b.openBlobovniczaNoCache(p)
|
2022-08-29 07:49:14 +00:00
|
|
|
}
|
|
|
|
|
2023-08-30 20:36:48 +00:00
|
|
|
func (b *Blobovniczas) openBlobovniczaNoCache(p string) *sharedDB {
|
|
|
|
return b.commondbManager.GetByPath(p)
|
2022-07-18 06:16:36 +00:00
|
|
|
}
|