diff --git a/pool/mock_test.go b/pool/mock_test.go index be7d4a8c..bf4916de 100644 --- a/pool/mock_test.go +++ b/pool/mock_test.go @@ -124,6 +124,11 @@ func (m *mockClient) networkInfo(ctx context.Context, _ prmNetworkInfo) (netmap. 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) { return oid.ID{}, nil } diff --git a/pool/pool.go b/pool/pool.go index 669970ff..5a8996ac 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -57,6 +57,8 @@ type client interface { endpointInfo(context.Context, prmEndpointInfo) (netmap.NodeInfo, error) // see clientWrapper.networkInfo. networkInfo(context.Context, prmNetworkInfo) (netmap.NetworkInfo, error) + // see clientWrapper.netMapSnapshot + netMapSnapshot(context.Context, prmNetMapSnapshot) (netmap.NetMap, error) // see clientWrapper.objectPut. objectPut(context.Context, PrmObjectPut) (oid.ID, error) // see clientWrapper.objectDelete. @@ -160,6 +162,7 @@ const ( methodContainerSetEACL methodEndpointInfo methodNetworkInfo + methodNetMapSnapshot methodObjectPut methodObjectDelete methodObjectGet @@ -190,6 +193,8 @@ func (m MethodIndex) String() string { return "endpointInfo" case methodNetworkInfo: return "networkInfo" + case methodNetMapSnapshot: + return "netMapSnapshot" case methodObjectPut: return "objectPut" case methodObjectDelete: @@ -658,6 +663,27 @@ func (c *clientWrapper) networkInfo(ctx context.Context, _ prmNetworkInfo) (netm 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. func (c *clientWrapper) objectPut(ctx context.Context, prm PrmObjectPut) (oid.ID, error) { if prm.bufferMaxSize == 0 { @@ -1740,6 +1766,9 @@ type prmEndpointInfo struct{} // prmNetworkInfo groups parameters of networkInfo operation. type prmNetworkInfo struct{} +// prmNetMapSnapshot groups parameters of netMapSnapshot operation. +type prmNetMapSnapshot struct{} + // resCreateSession groups resulting values of sessionCreate operation. type resCreateSession struct { id []byte @@ -2803,6 +2832,23 @@ func (p *Pool) NetworkInfo(ctx context.Context) (netmap.NetworkInfo, error) { 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. func (p *Pool) Close() { p.cancel()