[#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)
- `--timeout` flag in `neofs-cli` subcommands (#1837)
- `container nodes` command to output list of nodes for container, grouped by replica (#1704)
- Configuration flag to ignore shard in `neofs-node` (#1840)
### Changed
- Allow to evacuate shard data with `EvacuateShard` control RPC (#1800)
@ -40,7 +41,7 @@ Changelog for NeoFS Node
### Updated
### Updating from v0.32.0
### Updating from v0.32.0
Replace using the `control netmap-snapshot` command with `netmap snapshot` one in NeoFS CLI.
Node can now specify additional addresses in `ExternalAddr` attribute. To allow a node to dial
other nodes external address, use `apiclient.allow_external` config setting.
@ -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
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 (풍도, 楓島)
### Added

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
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 (
@ -31,6 +32,7 @@ func IterateShards(c *config.Config, required bool, f func(*shardconfig.Config)
c = c.Sub("shard")
def := c.Sub("default")
alive := 0
i := uint64(0)
for ; ; i++ {
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)
if sc.Mode() == mode.Disabled {
continue
}
if err := f(sc); err != nil {
return err
}
alive++
}
if i == 0 && required {
if alive == 0 && required {
return ErrNoShardConfigured
}
return nil

View file

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

View file

@ -1,5 +1,7 @@
package mode
import "math"
// Mode represents enumeration of Shard work modes.
type Mode uint32
@ -12,6 +14,11 @@ const (
// after a certain number of errors is encountered. It is the same as
// `mode.Degraded` but also is read-only.
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 (
@ -36,6 +43,8 @@ func (m Mode) String() string {
return "DEGRADED_READ_WRITE"
case DegradedReadOnly:
return "DEGRADED_READ_ONLY"
case Disabled:
return "DISABLED"
}
}