[#177] pool: Support NetMapSnapshot method

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2023-10-18 11:30:25 +03:00
parent fc4551b843
commit abd38c918e
2 changed files with 51 additions and 0 deletions

View file

@ -124,6 +124,11 @@ func (m *mockClient) networkInfo(ctx context.Context, _ prmNetworkInfo) (netmap.
return ni, nil return ni, nil
} }
func (m *mockClient) netMapSnapshot(context.Context, prmNetMapSnapshot) (netmap.NetMap, error) {
var nm netmap.NetMap
return nm, nil
}
func (m *mockClient) objectPut(context.Context, PrmObjectPut) (oid.ID, error) { func (m *mockClient) objectPut(context.Context, PrmObjectPut) (oid.ID, error) {
return oid.ID{}, nil return oid.ID{}, nil
} }

View file

@ -57,6 +57,8 @@ type client interface {
endpointInfo(context.Context, prmEndpointInfo) (netmap.NodeInfo, error) endpointInfo(context.Context, prmEndpointInfo) (netmap.NodeInfo, error)
// see clientWrapper.networkInfo. // see clientWrapper.networkInfo.
networkInfo(context.Context, prmNetworkInfo) (netmap.NetworkInfo, error) networkInfo(context.Context, prmNetworkInfo) (netmap.NetworkInfo, error)
// see clientWrapper.netMapSnapshot
netMapSnapshot(context.Context, prmNetMapSnapshot) (netmap.NetMap, error)
// see clientWrapper.objectPut. // see clientWrapper.objectPut.
objectPut(context.Context, PrmObjectPut) (oid.ID, error) objectPut(context.Context, PrmObjectPut) (oid.ID, error)
// see clientWrapper.objectDelete. // see clientWrapper.objectDelete.
@ -160,6 +162,7 @@ const (
methodContainerSetEACL methodContainerSetEACL
methodEndpointInfo methodEndpointInfo
methodNetworkInfo methodNetworkInfo
methodNetMapSnapshot
methodObjectPut methodObjectPut
methodObjectDelete methodObjectDelete
methodObjectGet methodObjectGet
@ -190,6 +193,8 @@ func (m MethodIndex) String() string {
return "endpointInfo" return "endpointInfo"
case methodNetworkInfo: case methodNetworkInfo:
return "networkInfo" return "networkInfo"
case methodNetMapSnapshot:
return "netMapSnapshot"
case methodObjectPut: case methodObjectPut:
return "objectPut" return "objectPut"
case methodObjectDelete: case methodObjectDelete:
@ -658,6 +663,27 @@ func (c *clientWrapper) networkInfo(ctx context.Context, _ prmNetworkInfo) (netm
return res.Info(), nil return res.Info(), nil
} }
// networkInfo invokes sdkClient.NetworkInfo parse response status to error and return result as is.
func (c *clientWrapper) netMapSnapshot(ctx context.Context, _ prmNetMapSnapshot) (netmap.NetMap, error) {
cl, err := c.getClient()
if err != nil {
return netmap.NetMap{}, err
}
start := time.Now()
res, err := cl.NetMapSnapshot(ctx, sdkClient.PrmNetMapSnapshot{})
c.incRequests(time.Since(start), methodNetMapSnapshot)
var st apistatus.Status
if res != nil {
st = res.Status()
}
if err = c.handleError(ctx, st, err); err != nil {
return netmap.NetMap{}, fmt.Errorf("network map snapshot on client: %w", err)
}
return res.NetMap(), nil
}
// objectPut writes object to FrostFS. // objectPut writes object to FrostFS.
func (c *clientWrapper) objectPut(ctx context.Context, prm PrmObjectPut) (oid.ID, error) { func (c *clientWrapper) objectPut(ctx context.Context, prm PrmObjectPut) (oid.ID, error) {
if prm.bufferMaxSize == 0 { if prm.bufferMaxSize == 0 {
@ -1740,6 +1766,9 @@ type prmEndpointInfo struct{}
// prmNetworkInfo groups parameters of networkInfo operation. // prmNetworkInfo groups parameters of networkInfo operation.
type prmNetworkInfo struct{} type prmNetworkInfo struct{}
// prmNetMapSnapshot groups parameters of netMapSnapshot operation.
type prmNetMapSnapshot struct{}
// resCreateSession groups resulting values of sessionCreate operation. // resCreateSession groups resulting values of sessionCreate operation.
type resCreateSession struct { type resCreateSession struct {
id []byte id []byte
@ -2803,6 +2832,23 @@ func (p *Pool) NetworkInfo(ctx context.Context) (netmap.NetworkInfo, error) {
return netInfo, nil return netInfo, nil
} }
// NetMapSnapshot requests information about the FrostFS network map.
//
// Main return value MUST NOT be processed on an erroneous return.
func (p *Pool) NetMapSnapshot(ctx context.Context) (netmap.NetMap, error) {
cp, err := p.connection()
if err != nil {
return netmap.NetMap{}, err
}
netMap, err := cp.netMapSnapshot(ctx, prmNetMapSnapshot{})
if err != nil {
return netmap.NetMap{}, fmt.Errorf("get network map via client '%s': %w", cp.address(), err)
}
return netMap, nil
}
// Close closes the Pool and releases all the associated resources. // Close closes the Pool and releases all the associated resources.
func (p *Pool) Close() { func (p *Pool) Close() {
p.cancel() p.cancel()