[#1840] neofs-node: Allow to use mode: disabled in config

Currently, when removing shard special care must be taken with respect
to shard numbering. `mode: disabled` allows to leave shard configuration
in place while also ignoring it during initialization. This makes
disk replacement much more convenient.

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-10-05 14:40:37 +03:00 committed by fyrchik
parent 1360273fec
commit 9b241e4a17
4 changed files with 25 additions and 2 deletions

View file

@ -16,6 +16,7 @@ Changelog for NeoFS Node
- Validate policy before container creation (#1704) - Validate policy before container creation (#1704)
- `--timeout` flag in `neofs-cli` subcommands (#1837) - `--timeout` flag in `neofs-cli` subcommands (#1837)
- `container nodes` command to output list of nodes for container, grouped by replica (#1704) - `container nodes` command to output list of nodes for container, grouped by replica (#1704)
- Configuration flag to ignore shard in `neofs-node` (#1840)
### Changed ### Changed
- Allow to evacuate shard data with `EvacuateShard` control RPC (#1800) - Allow to evacuate shard data with `EvacuateShard` control RPC (#1800)
@ -56,6 +57,10 @@ When issuing an object session token for root (virtual, "big") objects,
additionally include all members of the split-chain. If session context additionally include all members of the split-chain. If session context
includes root object only, it is not spread to physical ("small") objects. includes root object only, it is not spread to physical ("small") objects.
`neofs-node` configuration now supports `mode: disabled` flag for a shard.
This can be used to temporarily ignore shards without completely removing them
from the config file.
## [0.32.0] - 2022-09-14 - Pungdo (풍도, 楓島) ## [0.32.0] - 2022-09-14 - Pungdo (풍도, 楓島)
### Added ### Added

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard" shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
) )
const ( const (
@ -31,6 +32,7 @@ func IterateShards(c *config.Config, required bool, f func(*shardconfig.Config)
c = c.Sub("shard") c = c.Sub("shard")
def := c.Sub("default") def := c.Sub("default")
alive := 0
i := uint64(0) i := uint64(0)
for ; ; i++ { for ; ; i++ {
si := strconv.FormatUint(i, 10) si := strconv.FormatUint(i, 10)
@ -48,11 +50,16 @@ func IterateShards(c *config.Config, required bool, f func(*shardconfig.Config)
} }
(*config.Config)(sc).SetDefault(def) (*config.Config)(sc).SetDefault(def)
if sc.Mode() == mode.Disabled {
continue
}
if err := f(sc); err != nil { if err := f(sc); err != nil {
return err return err
} }
alive++
} }
if i == 0 && required { if alive == 0 && required {
return ErrNoShardConfigured return ErrNoShardConfigured
} }
return nil return nil

View file

@ -128,6 +128,8 @@ func (x *Config) Mode() (m mode.Mode) {
m = mode.Degraded m = mode.Degraded
case "degraded-read-only": case "degraded-read-only":
m = mode.DegradedReadOnly m = mode.DegradedReadOnly
case "disabled":
m = mode.Disabled
default: default:
panic(fmt.Sprintf("unknown shard mode: %s", s)) panic(fmt.Sprintf("unknown shard mode: %s", s))
} }

View file

@ -1,5 +1,7 @@
package mode package mode
import "math"
// Mode represents enumeration of Shard work modes. // Mode represents enumeration of Shard work modes.
type Mode uint32 type Mode uint32
@ -12,6 +14,11 @@ const (
// after a certain number of errors is encountered. It is the same as // after a certain number of errors is encountered. It is the same as
// `mode.Degraded` but also is read-only. // `mode.Degraded` but also is read-only.
DegradedReadOnly = Degraded | ReadOnly DegradedReadOnly = Degraded | ReadOnly
// Disabled mode is a mode where a shard is disabled.
// An existing shard can't have this mode, but it can be used in
// the configuration or control service commands.
Disabled = math.MaxUint32
) )
const ( const (
@ -36,6 +43,8 @@ func (m Mode) String() string {
return "DEGRADED_READ_WRITE" return "DEGRADED_READ_WRITE"
case DegradedReadOnly: case DegradedReadOnly:
return "DEGRADED_READ_ONLY" return "DEGRADED_READ_ONLY"
case Disabled:
return "DISABLED"
} }
} }