forked from TrueCloudLab/frostfs-node
[#959] node: Set mode to shard's components when open it
Avoid opening database for `metabase` and `cache` in `Degraded` mode. Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
60527abb65
commit
d19ade23c8
25 changed files with 219 additions and 74 deletions
|
@ -43,12 +43,17 @@ func (s *Shard) handleMetabaseFailure(stage string, err error) error {
|
|||
// Open opens all Shard's components.
|
||||
func (s *Shard) Open(ctx context.Context) error {
|
||||
components := []interface {
|
||||
Open(context.Context, bool) error
|
||||
Open(context.Context, mode.Mode) error
|
||||
}{
|
||||
s.blobStor, s.metaBase,
|
||||
s.blobStor,
|
||||
}
|
||||
m := s.GetMode()
|
||||
|
||||
if !m.NoMetabase() {
|
||||
components = append(components, s.metaBase)
|
||||
}
|
||||
|
||||
if s.hasWriteCache() {
|
||||
if s.hasWriteCache() && !m.NoMetabase() {
|
||||
components = append(components, s.writeCache)
|
||||
}
|
||||
|
||||
|
@ -57,12 +62,12 @@ func (s *Shard) Open(ctx context.Context) error {
|
|||
}
|
||||
|
||||
for i, component := range components {
|
||||
if err := component.Open(ctx, false); err != nil {
|
||||
if err := component.Open(ctx, m); err != nil {
|
||||
if component == s.metaBase {
|
||||
// We must first open all other components to avoid
|
||||
// opening non-existent DB in read-only mode.
|
||||
for j := i + 1; j < len(components); j++ {
|
||||
if err := components[j].Open(ctx, false); err != nil {
|
||||
if err := components[j].Open(ctx, m); err != nil {
|
||||
// Other components must be opened, fail.
|
||||
return fmt.Errorf("could not open %T: %w", components[j], err)
|
||||
}
|
||||
|
@ -97,8 +102,9 @@ func (s *Shard) Init(ctx context.Context) error {
|
|||
}
|
||||
|
||||
var components []initializer
|
||||
m := s.GetMode()
|
||||
|
||||
if !s.GetMode().NoMetabase() {
|
||||
if !m.NoMetabase() {
|
||||
var initMetabase initializer
|
||||
|
||||
if s.NeedRefillMetabase() {
|
||||
|
@ -114,7 +120,7 @@ func (s *Shard) Init(ctx context.Context) error {
|
|||
components = []initializer{s.blobStor}
|
||||
}
|
||||
|
||||
if s.hasWriteCache() {
|
||||
if s.hasWriteCache() && !m.NoMetabase() {
|
||||
components = append(components, s.writeCache)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue