[#177] pool: Support NetMapSnapshot method
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
fc4551b843
commit
abd38c918e
2 changed files with 51 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
46
pool/pool.go
46
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()
|
||||
|
|
Loading…
Reference in a new issue