From e758c246b7b4c215968e5fc052aa840b27cbffb9 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 30 Nov 2020 17:59:00 +0300 Subject: [PATCH] [#220] localstorage: Implement Open/Init/Close methods Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/engine/control.go | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 pkg/local_object_storage/engine/control.go diff --git a/pkg/local_object_storage/engine/control.go b/pkg/local_object_storage/engine/control.go new file mode 100644 index 000000000..f11892bf6 --- /dev/null +++ b/pkg/local_object_storage/engine/control.go @@ -0,0 +1,51 @@ +package engine + +import ( + "github.com/pkg/errors" + "go.uber.org/zap" +) + +// Open opens all StorageEngine's components. +func (e *StorageEngine) Open() error { + e.mtx.RLock() + defer e.mtx.RUnlock() + + for id, sh := range e.shards { + if err := sh.Open(); err != nil { + return errors.Wrapf(err, "could not initialize shard %s", id) + } + } + + return nil +} + +// Init initializes all StorageEngine's components. +func (e *StorageEngine) Init() error { + e.mtx.RLock() + defer e.mtx.RUnlock() + + for id, sh := range e.shards { + if err := sh.Init(); err != nil { + return errors.Wrapf(err, "could not initialize shard %s", id) + } + } + + return nil +} + +// Close releases all StorageEngine's components. +func (e *StorageEngine) Close() error { + e.mtx.RLock() + defer e.mtx.RUnlock() + + for id, sh := range e.shards { + if err := sh.Close(); err != nil { + e.log.Debug("could not close shard", + zap.String("id", id), + zap.String("error", err.Error()), + ) + } + } + + return nil +}