From 7fb15fa1d0df0f7102c257b1d776a19780f867be Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 31 Jan 2022 18:15:33 +0300 Subject: [PATCH] [#1118] services/control: allow to reset error counter in `SetShardMode` Signed-off-by: Evgenii Stratonikov --- cmd/neofs-cli/modules/control.go | 9 +++++++-- pkg/local_object_storage/engine/error_test.go | 6 ++++++ pkg/local_object_storage/engine/shards.go | 5 ++++- pkg/services/control/server/set_shard_mode.go | 2 +- pkg/services/control/service.go | 16 +++++++++++++++- pkg/services/control/service.pb.go | Bin 88777 -> 89362 bytes pkg/services/control/service.proto | 3 +++ 7 files changed, 36 insertions(+), 5 deletions(-) diff --git a/cmd/neofs-cli/modules/control.go b/cmd/neofs-cli/modules/control.go index 6e424bb64f..146f21b175 100644 --- a/cmd/neofs-cli/modules/control.go +++ b/cmd/neofs-cli/modules/control.go @@ -71,8 +71,9 @@ const ( netmapStatusOffline = "offline" netmapStatusMaintenance = "maintenance" - shardModeFlag = "mode" - shardIDFlag = "id" + shardModeFlag = "mode" + shardIDFlag = "id" + shardClearErrorsFlag = "clear-errors" shardModeReadOnly = "read-only" shardModeReadWrite = "read-write" @@ -127,6 +128,7 @@ func initControlSetShardModeCmd() { shardModeReadOnly, ), ) + flags.Bool(shardClearErrorsFlag, false, "Set shard error count to 0") } func initControlShardsListCmd() { @@ -510,6 +512,9 @@ func setShardMode(cmd *cobra.Command, _ []string) { body.SetMode(mode) body.SetShardID(rawID) + reset, _ := cmd.Flags().GetBool(shardClearErrorsFlag) + body.ClearErrorCounter(reset) + err = controlSvc.SignMessage(key, req) exitOnErr(cmd, errf("could not sign request: %w", err)) diff --git a/pkg/local_object_storage/engine/error_test.go b/pkg/local_object_storage/engine/error_test.go index 13d8a63f70..b968a37311 100644 --- a/pkg/local_object_storage/engine/error_test.go +++ b/pkg/local_object_storage/engine/error_test.go @@ -114,6 +114,12 @@ func TestErrorReporting(t *testing.T) { checkShardState(t, e, id[0], errThreshold+i, shard.ModeReadOnly) checkShardState(t, e, id[1], 0, shard.ModeReadWrite) } + + require.NoError(t, e.SetShardMode(id[0], shard.ModeReadWrite, false)) + checkShardState(t, e, id[0], errThreshold+1, shard.ModeReadWrite) + + require.NoError(t, e.SetShardMode(id[0], shard.ModeReadWrite, true)) + checkShardState(t, e, id[0], 0, shard.ModeReadWrite) }) } diff --git a/pkg/local_object_storage/engine/shards.go b/pkg/local_object_storage/engine/shards.go index d4c4fcde58..8fb4a13540 100644 --- a/pkg/local_object_storage/engine/shards.go +++ b/pkg/local_object_storage/engine/shards.go @@ -118,12 +118,15 @@ func (e *StorageEngine) iterateOverUnsortedShards(handler func(hashedShard) (sto // SetShardMode sets mode of the shard with provided identifier. // // Returns an error if shard mode was not set, or shard was not found in storage engine. -func (e *StorageEngine) SetShardMode(id *shard.ID, m shard.Mode) error { +func (e *StorageEngine) SetShardMode(id *shard.ID, m shard.Mode, resetErrorCounter bool) error { e.mtx.RLock() defer e.mtx.RUnlock() for shID, sh := range e.shards { if id.String() == shID { + if resetErrorCounter { + sh.errorCount.Store(0) + } return sh.SetMode(m) } } diff --git a/pkg/services/control/server/set_shard_mode.go b/pkg/services/control/server/set_shard_mode.go index 86e9c7dce3..01edcfdbda 100644 --- a/pkg/services/control/server/set_shard_mode.go +++ b/pkg/services/control/server/set_shard_mode.go @@ -33,7 +33,7 @@ func (s *Server) SetShardMode(_ context.Context, req *control.SetShardModeReques return nil, status.Error(codes.Internal, fmt.Sprintf("unknown shard mode: %s", requestedMode)) } - err = s.s.SetShardMode(requestedShard, mode) + err = s.s.SetShardMode(requestedShard, mode, false) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } diff --git a/pkg/services/control/service.go b/pkg/services/control/service.go index d14604914d..7f0b0d7aaa 100644 --- a/pkg/services/control/service.go +++ b/pkg/services/control/service.go @@ -761,10 +761,16 @@ func (x *SetShardModeRequest_Body) SetMode(v ShardMode) { x.Mode = v } +// ClearErrorCounter sets flag signifying whether error counter for shard should be cleared. +func (x *SetShardModeRequest_Body) ClearErrorCounter(reset bool) { + x.ResetErrorCounter = reset +} + const ( _ = iota setShardModeReqBodyShardIDFNum setShardModeReqBodyModeFNum + setShardModeReqBodyResetCounterFNum ) // StableMarshal reads binary representation of set shard mode request body @@ -797,7 +803,14 @@ func (x *SetShardModeRequest_Body) StableMarshal(buf []byte) ([]byte, error) { offset += n - _, err = proto.EnumMarshal(setShardModeReqBodyModeFNum, buf[offset:], int32(x.Mode)) + n, err = proto.EnumMarshal(setShardModeReqBodyModeFNum, buf[offset:], int32(x.Mode)) + if err != nil { + return nil, err + } + + offset += n + + _, err = proto.BoolMarshal(setShardModeReqBodyResetCounterFNum, buf[offset:], x.ResetErrorCounter) if err != nil { return nil, err } @@ -818,6 +831,7 @@ func (x *SetShardModeRequest_Body) StableSize() int { size += proto.BytesSize(setShardModeReqBodyShardIDFNum, x.Shard_ID) size += proto.EnumSize(setShardModeReqBodyModeFNum, int32(x.Mode)) + size += proto.BoolSize(setShardModeReqBodyResetCounterFNum, x.ResetErrorCounter) return size } diff --git a/pkg/services/control/service.pb.go b/pkg/services/control/service.pb.go index b6d8e046c1d007db11bf93c37dabcd2058f6c1b3..87e8913a591042833014f06d276b38a763c30764 100644 GIT binary patch delta 1711 zcma)6ZERCz6waCbyuJO{+=pRXce^d@6WVU0qY%ajZp4Xm^J35lI5s-KjkR_qVl-j= zG5#=s9Of~B;QWIoBv7qiQGt>90SSsA+Za$cCoob#mM{WgW%GUSt$;2j{<*pD`FP%Q zp69&h#OK;wUu(m^?`bePol2@}5ohZbSJG0mg_{L2cM@|}(+&-$d!V_cz$fr{x%%*cDu;JqSW)_)^QzJ&Sov}xz zqm6)F_sV%{LF`4W9@J=BIPBZ8DqJz?;P#qZ4t#&IO8u3wB+gsG{kLR%Cobv~l6<)D zPC7a!ycR_Q&R<0ZhmmeB#?@02Pna5BhOX0TN$%GFsLX|3Q)w8uAx0K{w-T^ncn(hs z+>x<&SR}gzoER80pzf|6r-ua0JY9lqeHPlM1t*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q z7&F7W*vTx)|LwQi06l*4oys^t#M zVUax2eVR)id~&^v-OHu0xch^t8VpPnvkMy9#paDv zsh~(`6{I*j<>jXZ|5d$JM-3VDO7jiJ4beG^ut@Z#%#P~0KaWk7L-}1Sx+>?<0B3|x zh7hw#q%>H~qMt=1UUO!y085ja%mgV!e6XA~>q*Tj^T;nI#ZerXFJ(Qsq+ttr6yk0+ zv1udUg$z_Da9msq2z#@cEHY6Gibfvi<6t-I(UBU?O?}sC@}|=ZB(gAOBm-U<)^)u_ zE_T((Etj5QYTg6K|E=uV*%jy>D`PL1Da@9$$i~i^scwfL!8f=d>*ll|Qv)^JFIIg} SQCJQN*o}kEZ$>TjRNX&fHZdpw diff --git a/pkg/services/control/service.proto b/pkg/services/control/service.proto index c34b2cf7af..3446e262e0 100644 --- a/pkg/services/control/service.proto +++ b/pkg/services/control/service.proto @@ -186,6 +186,9 @@ message SetShardModeRequest { // Mode that requested to be set. ShardMode mode = 2; + + // Flag signifying whether error counter should be set to 0. + bool resetErrorCounter = 3; } // Body of set shard mode request message.