[#1043] control: Add ResetEvacuationStatus implementation

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-03-12 18:57:38 +03:00 committed by Evgenii Stratonikov
parent 926cdeb072
commit 31e2396a5f
8 changed files with 82 additions and 0 deletions

View file

@ -733,3 +733,13 @@ func (e *StorageEngine) EnqueRunningEvacuationStop(ctx context.Context) error {
return e.evacuateLimiter.CancelIfRunning() return e.evacuateLimiter.CancelIfRunning()
} }
func (e *StorageEngine) ResetEvacuationStatus(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
return e.evacuateLimiter.ResetEvacuationStatus()
}

View file

@ -204,3 +204,18 @@ func (l *evacuationLimiter) CancelIfRunning() error {
l.cancel() l.cancel()
return nil return nil
} }
func (l *evacuationLimiter) ResetEvacuationStatus() error {
l.guard.Lock()
defer l.guard.Unlock()
if l.state.processState == EvacuateProcessStateRunning {
return logicerr.New("there is running evacuation task")
}
l.state = EvacuationState{}
l.eg = nil
l.cancel = nil
return nil
}

View file

@ -386,6 +386,8 @@ func TestEvacuateObjectsAsync(t *testing.T) {
require.ElementsMatch(t, expectedShardIDs, st.ShardIDs(), "invalid running shard ids") require.ElementsMatch(t, expectedShardIDs, st.ShardIDs(), "invalid running shard ids")
require.Equal(t, "", st.ErrorMessage(), "invalid init error message") require.Equal(t, "", st.ErrorMessage(), "invalid init error message")
require.Error(t, e.ResetEvacuationStatus(context.Background()))
close(blocker) close(blocker)
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
@ -401,6 +403,16 @@ func TestEvacuateObjectsAsync(t *testing.T) {
require.Equal(t, "", st.ErrorMessage(), "invalid final error message") require.Equal(t, "", st.ErrorMessage(), "invalid final error message")
require.NoError(t, eg.Wait()) require.NoError(t, eg.Wait())
require.NoError(t, e.ResetEvacuationStatus(context.Background()))
st, err = e.GetEvacuationState(context.Background())
require.NoError(t, err, "get state after reset failed")
require.Equal(t, EvacuateProcessStateUndefined, st.ProcessingStatus(), "invalid state after reset")
require.Equal(t, uint64(0), st.ObjectsEvacuated(), "invalid count after reset")
require.Nil(t, st.StartedAt(), "invalid started at after reset")
require.Nil(t, st.FinishedAt(), "invalid finished at after reset")
require.ElementsMatch(t, []string{}, st.ShardIDs(), "invalid shard ids after reset")
require.Equal(t, "", st.ErrorMessage(), "invalid error message after reset")
} }
func TestEvacuateTreesLocal(t *testing.T) { func TestEvacuateTreesLocal(t *testing.T) {

View file

@ -102,3 +102,29 @@ func (s *Server) StopShardEvacuation(ctx context.Context, req *control.StopShard
} }
return resp, nil return resp, nil
} }
func (s *Server) ResetShardEvacuationStatus(ctx context.Context, req *control.ResetShardEvacuationStatusRequest) (*control.ResetShardEvacuationStatusResponse, error) {
err := s.isValidRequest(req)
if err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error())
}
err = s.s.ResetEvacuationStatus(ctx)
if err != nil {
var logicalErr logicerr.Logical
if errors.As(err, &logicalErr) {
return nil, status.Error(codes.Aborted, err.Error())
}
return nil, status.Error(codes.Internal, err.Error())
}
resp := &control.ResetShardEvacuationStatusResponse{
Body: &control.ResetShardEvacuationStatusResponse_Body{},
}
err = SignMessage(s.key, resp)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return resp, nil
}

Binary file not shown.

View file

@ -36,6 +36,9 @@ service ControlService {
// GetShardEvacuationStatus returns evacuation status. // GetShardEvacuationStatus returns evacuation status.
rpc GetShardEvacuationStatus (GetShardEvacuationStatusRequest) returns (GetShardEvacuationStatusResponse); rpc GetShardEvacuationStatus (GetShardEvacuationStatusRequest) returns (GetShardEvacuationStatusResponse);
// ResetShardEvacuationStatus resets evacuation status if there is no running evacuation process.
rpc ResetShardEvacuationStatus (ResetShardEvacuationStatusRequest) returns (ResetShardEvacuationStatusResponse);
// StopShardEvacuation stops moving all data from one shard to the others. // StopShardEvacuation stops moving all data from one shard to the others.
rpc StopShardEvacuation (StopShardEvacuationRequest) returns (StopShardEvacuationResponse); rpc StopShardEvacuation (StopShardEvacuationRequest) returns (StopShardEvacuationResponse);
@ -426,6 +429,22 @@ message GetShardEvacuationStatusResponse {
Signature signature = 2; Signature signature = 2;
} }
// ResetShardEvacuationStatus request.
message ResetShardEvacuationStatusRequest {
message Body {}
Body body = 1;
Signature signature = 2;
}
// ResetShardEvacuationStatus response.
message ResetShardEvacuationStatusResponse {
message Body {}
Body body = 1;
Signature signature = 2;
}
// StopShardEvacuation request. // StopShardEvacuation request.
message StopShardEvacuationRequest { message StopShardEvacuationRequest {
// Request body structure. // Request body structure.

Binary file not shown.

Binary file not shown.