[#60] control: Add GetNetmapStatus method

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-06-20 16:03:58 +03:00
parent 9ac74efc41
commit a83eeddb1d
9 changed files with 109 additions and 0 deletions

View file

@ -374,6 +374,15 @@ func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error {
return c.updateNetMapState(func(*nmClient.UpdatePeerPrm) {})
}
func (c *cfg) GetNetmapStatus() (control.NetmapStatus, uint64, error) {
epoch, err := c.netMapSource.Epoch()
if err != nil {
return control.NetmapStatus_STATUS_UNDEFINED, 0, fmt.Errorf("failed to get current epoch: %w", err)
}
st := c.NetmapStatus()
return st, epoch, nil
}
func (c *cfg) ForceMaintenance() error {
return c.setMaintenanceStatus(true)
}

View file

@ -10,6 +10,7 @@ const serviceName = "control.ControlService"
const (
rpcHealthCheck = "HealthCheck"
rpcSetNetmapStatus = "SetNetmapStatus"
rpcGetNetmapStatus = "GetNetmapStatus"
rpcDropObjects = "DropObjects"
rpcListShards = "ListShards"
rpcSetShardMode = "SetShardMode"
@ -70,6 +71,26 @@ func SetNetmapStatus(
return wResp.message, nil
}
// GetNetmapStatus executes ControlService.GetNetmapStatus RPC.
func GetNetmapStatus(
cli *client.Client,
req *GetNetmapStatusRequest,
opts ...client.CallOption,
) (*GetNetmapStatusResponse, error) {
wResp := newResponseWrapper[GetNetmapStatusResponse]()
wReq := &requestWrapper{
m: req,
}
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcGetNetmapStatus), wReq, wResp, opts...)
if err != nil {
return nil, err
}
return wResp.message, nil
}
// DropObjects executes ControlService.DropObjects RPC.
func DropObjects(
cli *client.Client,

View file

@ -242,6 +242,17 @@ func (a *auditService) SetNetmapStatus(ctx context.Context, req *ctl.SetNetmapSt
return res, err
}
// GetNetmapStatus implements control.ControlServiceServer.
func (a *auditService) GetNetmapStatus(ctx context.Context, req *ctl.GetNetmapStatusRequest) (*ctl.GetNetmapStatusResponse, error) {
res, err := a.next.GetNetmapStatus(ctx, req)
if !a.enabled.Load() {
return res, err
}
audit.LogRequestWithKey(a.log, ctl.ControlService_GetNetmapStatus_FullMethodName, req.GetSignature().GetKey(),
nil, err == nil)
return res, err
}
// SetShardMode implements control.ControlServiceServer.
func (a *auditService) SetShardMode(ctx context.Context, req *ctl.SetShardModeRequest) (*ctl.SetShardModeResponse, error) {
res, err := a.next.SetShardMode(ctx, req)

View file

@ -0,0 +1,35 @@
package control
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server/ctrlmessage"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// GetNetmapStatus gets node status in FrostFS network.
func (s *Server) GetNetmapStatus(_ context.Context, req *control.GetNetmapStatusRequest) (*control.GetNetmapStatusResponse, error) {
if err := s.isValidRequest(req); err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error())
}
st, epoch, err := s.nodeState.GetNetmapStatus()
if err != nil {
return nil, err
}
resp := &control.GetNetmapStatusResponse{
Body: &control.GetNetmapStatusResponse_Body{
Status: st,
Epoch: epoch,
},
}
if err := ctrlmessage.Sign(s.key, resp); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return resp, nil
}

View file

@ -50,6 +50,8 @@ type NodeState interface {
// ForceMaintenance works like SetNetmapStatus(control.NetmapStatus_MAINTENANCE)
// but starts local maintenance regardless of the network settings.
ForceMaintenance() error
GetNetmapStatus() (control.NetmapStatus, uint64, error)
}
// LocalOverrideStorageDecorator interface provides methods to decorate LocalOverrideEngine

Binary file not shown.

View file

@ -15,6 +15,9 @@ service ControlService {
// Sets status of the storage node in FrostFS network map.
rpc SetNetmapStatus(SetNetmapStatusRequest) returns (SetNetmapStatusResponse);
// Gets status of the storage node in FrostFS network map.
rpc GetNetmapStatus(GetNetmapStatusRequest) returns (GetNetmapStatusResponse);
// Mark objects to be removed from node's local object storage.
rpc DropObjects(DropObjectsRequest) returns (DropObjectsResponse);
@ -156,6 +159,34 @@ message SetNetmapStatusResponse {
Signature signature = 2;
}
// Get netmap status request.
message GetNetmapStatusRequest {
message Body {}
// Body of set netmap status request message.
Body body = 1;
// Body signature.
Signature signature = 2;
}
// Get netmap status response.
message GetNetmapStatusResponse {
message Body {
// Storage node status in FrostFS network map.
NetmapStatus status = 1;
// Network map epoch.
uint64 epoch = 2;
}
// Body of get netmap status response message.
Body body = 1;
// Body signature.
Signature signature = 2;
}
// Request to drop the objects.
message DropObjectsRequest {
// Request body structure.

Binary file not shown.

Binary file not shown.