2021-05-25 08:48:01 +00:00
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
2021-11-17 11:22:32 +00:00
|
|
|
"crypto/sha256"
|
2021-05-25 08:48:01 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-12-29 14:40:37 +00:00
|
|
|
"io"
|
2021-10-25 12:57:55 +00:00
|
|
|
"math"
|
2021-05-25 08:48:01 +00:00
|
|
|
"math/rand"
|
2021-11-16 13:50:33 +00:00
|
|
|
"sort"
|
2021-10-25 12:57:55 +00:00
|
|
|
"strings"
|
2021-05-25 08:48:01 +00:00
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2021-12-10 13:56:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2021-12-29 14:40:37 +00:00
|
|
|
apiclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
2021-12-17 10:36:07 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/accounting"
|
2021-11-09 08:20:09 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/container"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-01-25 16:20:32 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-11-09 08:20:09 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
2021-11-15 06:35:30 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/token"
|
2021-09-07 14:34:20 +00:00
|
|
|
"go.uber.org/zap"
|
2021-05-25 08:48:01 +00:00
|
|
|
)
|
|
|
|
|
2021-07-20 08:02:14 +00:00
|
|
|
// Client is a wrapper for client.Client to generate mock.
|
|
|
|
type Client interface {
|
2021-12-02 12:21:54 +00:00
|
|
|
GetBalance(context.Context, client.GetBalancePrm) (*client.GetBalanceRes, error)
|
|
|
|
PutContainer(context.Context, client.ContainerPutPrm) (*client.ContainerPutRes, error)
|
|
|
|
GetContainer(context.Context, client.ContainerGetPrm) (*client.ContainerGetRes, error)
|
|
|
|
ListContainers(context.Context, client.ContainerListPrm) (*client.ContainerListRes, error)
|
|
|
|
DeleteContainer(context.Context, client.ContainerDeletePrm) (*client.ContainerDeleteRes, error)
|
|
|
|
EACL(context.Context, client.EACLPrm) (*client.EACLRes, error)
|
|
|
|
SetEACL(context.Context, client.SetEACLPrm) (*client.SetEACLRes, error)
|
|
|
|
AnnounceContainerUsedSpace(context.Context, client.AnnounceSpacePrm) (*client.AnnounceSpaceRes, error)
|
|
|
|
EndpointInfo(context.Context, client.EndpointInfoPrm) (*client.EndpointInfoRes, error)
|
|
|
|
NetworkInfo(context.Context, client.NetworkInfoPrm) (*client.NetworkInfoRes, error)
|
2021-12-29 14:40:37 +00:00
|
|
|
PutObject(context.Context, *client.PutObjectParams, ...client.CallOption) (*client.ObjectPutRes, error)
|
|
|
|
DeleteObject(context.Context, *client.DeleteObjectParams, ...client.CallOption) (*client.ObjectDeleteRes, error)
|
|
|
|
GetObject(context.Context, *client.GetObjectParams, ...client.CallOption) (*client.ObjectGetRes, error)
|
|
|
|
HeadObject(context.Context, *client.ObjectHeaderParams, ...client.CallOption) (*client.ObjectHeadRes, error)
|
|
|
|
ObjectPayloadRangeData(context.Context, *client.RangeDataParams, ...client.CallOption) (*client.ObjectRangeRes, error)
|
|
|
|
HashObjectPayloadRanges(context.Context, *client.RangeChecksumParams, ...client.CallOption) (*client.ObjectRangeHashRes, error)
|
|
|
|
SearchObjects(context.Context, *client.SearchObjectParams, ...client.CallOption) (*client.ObjectSearchRes, error)
|
2021-12-02 12:21:54 +00:00
|
|
|
AnnounceLocalTrust(context.Context, client.AnnounceLocalTrustPrm) (*client.AnnounceLocalTrustRes, error)
|
|
|
|
AnnounceIntermediateTrust(context.Context, client.AnnounceIntermediateTrustPrm) (*client.AnnounceIntermediateTrustRes, error)
|
|
|
|
CreateSession(context.Context, client.CreateSessionPrm) (*client.CreateSessionRes, error)
|
2021-12-29 14:40:37 +00:00
|
|
|
|
|
|
|
Raw() *apiclient.Client
|
|
|
|
|
|
|
|
Conn() io.Closer
|
2021-07-20 08:02:14 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 11:46:58 +00:00
|
|
|
// BuilderOptions contains options used to build connection pool.
|
|
|
|
type BuilderOptions struct {
|
2021-05-25 08:48:01 +00:00
|
|
|
Key *ecdsa.PrivateKey
|
2021-09-07 14:34:20 +00:00
|
|
|
Logger *zap.Logger
|
2021-05-25 08:48:01 +00:00
|
|
|
NodeConnectionTimeout time.Duration
|
|
|
|
NodeRequestTimeout time.Duration
|
|
|
|
ClientRebalanceInterval time.Duration
|
|
|
|
SessionExpirationEpoch uint64
|
2021-11-16 13:50:33 +00:00
|
|
|
nodesParams []*NodesParam
|
2021-12-29 14:40:37 +00:00
|
|
|
clientBuilder func(opts ...client.Option) (Client, error)
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 13:50:33 +00:00
|
|
|
type NodesParam struct {
|
|
|
|
priority int
|
|
|
|
addresses []string
|
|
|
|
weights []float64
|
|
|
|
}
|
|
|
|
|
|
|
|
type NodeParam struct {
|
|
|
|
priority int
|
|
|
|
address string
|
|
|
|
weight float64
|
|
|
|
}
|
|
|
|
|
2021-05-25 11:46:58 +00:00
|
|
|
// Builder is an interim structure used to collect node addresses/weights and
|
2021-05-25 08:48:01 +00:00
|
|
|
// build connection pool subsequently.
|
2021-05-25 11:46:58 +00:00
|
|
|
type Builder struct {
|
2021-11-16 13:50:33 +00:00
|
|
|
nodeParams []NodeParam
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 09:15:21 +00:00
|
|
|
// ContainerPollingParams contains parameters used in polling is a container created or not.
|
|
|
|
type ContainerPollingParams struct {
|
|
|
|
CreationTimeout time.Duration
|
|
|
|
PollInterval time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultPollingParams creates ContainerPollingParams with default values.
|
|
|
|
func DefaultPollingParams() *ContainerPollingParams {
|
|
|
|
return &ContainerPollingParams{
|
|
|
|
CreationTimeout: 120 * time.Second,
|
|
|
|
PollInterval: 5 * time.Second,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-25 08:48:01 +00:00
|
|
|
// AddNode adds address/weight pair to node PoolBuilder list.
|
2021-11-16 13:50:33 +00:00
|
|
|
func (pb *Builder) AddNode(address string, priority int, weight float64) *Builder {
|
|
|
|
pb.nodeParams = append(pb.nodeParams, NodeParam{
|
|
|
|
address: address,
|
|
|
|
priority: priority,
|
|
|
|
weight: weight,
|
|
|
|
})
|
2021-05-25 08:48:01 +00:00
|
|
|
return pb
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build creates new pool based on current PoolBuilder state and options.
|
2021-05-25 11:46:58 +00:00
|
|
|
func (pb *Builder) Build(ctx context.Context, options *BuilderOptions) (Pool, error) {
|
2021-11-16 13:50:33 +00:00
|
|
|
if len(pb.nodeParams) == 0 {
|
2021-05-25 08:48:01 +00:00
|
|
|
return nil, errors.New("no NeoFS peers configured")
|
|
|
|
}
|
2021-06-09 11:56:11 +00:00
|
|
|
|
2021-11-16 13:50:33 +00:00
|
|
|
nodesParams := make(map[int]*NodesParam)
|
|
|
|
for _, param := range pb.nodeParams {
|
|
|
|
nodes, ok := nodesParams[param.priority]
|
|
|
|
if !ok {
|
|
|
|
nodes = &NodesParam{priority: param.priority}
|
|
|
|
}
|
|
|
|
nodes.addresses = append(nodes.addresses, param.address)
|
|
|
|
nodes.weights = append(nodes.weights, param.weight)
|
|
|
|
nodesParams[param.priority] = nodes
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, nodes := range nodesParams {
|
|
|
|
nodes.weights = adjustWeights(nodes.weights)
|
|
|
|
options.nodesParams = append(options.nodesParams, nodes)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(options.nodesParams, func(i, j int) bool {
|
|
|
|
return options.nodesParams[i].priority < options.nodesParams[j].priority
|
|
|
|
})
|
2021-07-20 08:02:14 +00:00
|
|
|
|
|
|
|
if options.clientBuilder == nil {
|
2021-12-29 14:40:37 +00:00
|
|
|
options.clientBuilder = func(opts ...client.Option) (Client, error) {
|
|
|
|
return client.New(opts...)
|
|
|
|
}
|
2021-07-20 08:02:14 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 20:12:58 +00:00
|
|
|
return newPool(ctx, options)
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pool is an interface providing connection artifacts on request.
|
|
|
|
type Pool interface {
|
2021-11-15 06:35:30 +00:00
|
|
|
Object
|
|
|
|
Container
|
2021-12-17 10:36:07 +00:00
|
|
|
Accounting
|
2021-12-29 14:40:37 +00:00
|
|
|
Connection() (Client, *session.Token, error)
|
2021-05-28 20:12:58 +00:00
|
|
|
OwnerID() *owner.ID
|
2021-06-22 14:28:12 +00:00
|
|
|
WaitForContainerPresence(context.Context, *cid.ID, *ContainerPollingParams) error
|
[#48] pool: add `Close` method
Fix occasional panic in tests:
```
> for i in (seq 1 100); go test -race -count=1 ./pool/... ; end
...
{"level":"warn","ts":1635251466.567485,"caller":"pool/pool.go:122","msg":"failed to create neofs session token for client","address":"peer0","error":"error session"}
panic: Fail in goroutine after TestTwoNodes has completed
goroutine 6 [running]:
testing.(*common).Fail(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:710 +0x1b4
testing.(*common).FailNow(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:732 +0x2f
testing.(*common).Fatalf(0xc000074070, {0xd9d816, 0x2e}, {0xc000094050, 0x5, 0x5})
/usr/lib/go/src/testing/testing.go:830 +0x85
github.com/golang/mock/gomock.(*Controller).Call.func1(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:231 +0x44d
github.com/golang/mock/gomock.(*Controller).Call(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:247 +0xce
github.com/nspcc-dev/neofs-sdk-go/pool.(*MockClient).EndpointInfo(0xc0002dac30, {0xe85528, 0xc00008a120}, {0x0, 0x0, 0x0})
/home/dzeta/repo/neofs-sdk-go/pool/mock_test.go:186 +0x298
github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth.func1(0x1, {0xe950d8, 0xc0002dac30})
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:183 +0x188
created by github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:174 +0x233
```
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-10-26 12:36:08 +00:00
|
|
|
Close()
|
2021-11-15 06:35:30 +00:00
|
|
|
}
|
2021-10-25 12:57:55 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
type Object interface {
|
2022-01-25 16:20:32 +00:00
|
|
|
PutObject(ctx context.Context, params *client.PutObjectParams, opts ...CallOption) (*oid.ID, error)
|
2021-11-15 06:35:30 +00:00
|
|
|
DeleteObject(ctx context.Context, params *client.DeleteObjectParams, opts ...CallOption) error
|
|
|
|
GetObject(ctx context.Context, params *client.GetObjectParams, opts ...CallOption) (*object.Object, error)
|
|
|
|
GetObjectHeader(ctx context.Context, params *client.ObjectHeaderParams, opts ...CallOption) (*object.Object, error)
|
|
|
|
ObjectPayloadRangeData(ctx context.Context, params *client.RangeDataParams, opts ...CallOption) ([]byte, error)
|
|
|
|
ObjectPayloadRangeSHA256(ctx context.Context, params *client.RangeChecksumParams, opts ...CallOption) ([][32]byte, error)
|
|
|
|
ObjectPayloadRangeTZ(ctx context.Context, params *client.RangeChecksumParams, opts ...CallOption) ([][64]byte, error)
|
2022-01-25 16:20:32 +00:00
|
|
|
SearchObject(ctx context.Context, params *client.SearchObjectParams, opts ...CallOption) ([]*oid.ID, error)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
type Container interface {
|
|
|
|
PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*cid.ID, error)
|
|
|
|
GetContainer(ctx context.Context, cid *cid.ID, opts ...CallOption) (*container.Container, error)
|
|
|
|
ListContainers(ctx context.Context, ownerID *owner.ID, opts ...CallOption) ([]*cid.ID, error)
|
|
|
|
DeleteContainer(ctx context.Context, cid *cid.ID, opts ...CallOption) error
|
2021-11-17 11:22:32 +00:00
|
|
|
GetEACL(ctx context.Context, cid *cid.ID, opts ...CallOption) (*eacl.Table, error)
|
2021-11-15 06:35:30 +00:00
|
|
|
SetEACL(ctx context.Context, table *eacl.Table, opts ...CallOption) error
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 10:36:07 +00:00
|
|
|
type Accounting interface {
|
|
|
|
Balance(ctx context.Context, owner *owner.ID, opts ...CallOption) (*accounting.Decimal, error)
|
|
|
|
}
|
|
|
|
|
2021-05-25 08:48:01 +00:00
|
|
|
type clientPack struct {
|
2021-12-29 14:40:37 +00:00
|
|
|
client Client
|
2021-10-25 12:57:55 +00:00
|
|
|
healthy bool
|
|
|
|
address string
|
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
type CallOption func(config *callConfig)
|
|
|
|
|
|
|
|
type callConfig struct {
|
2021-12-16 15:46:38 +00:00
|
|
|
isRetry bool
|
|
|
|
useDefaultSession bool
|
2021-10-25 12:57:55 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
key *ecdsa.PrivateKey
|
|
|
|
btoken *token.BearerToken
|
|
|
|
stoken *session.Token
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithKey(key *ecdsa.PrivateKey) CallOption {
|
|
|
|
return func(config *callConfig) {
|
|
|
|
config.key = key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithBearer(token *token.BearerToken) CallOption {
|
|
|
|
return func(config *callConfig) {
|
|
|
|
config.btoken = token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithSession(token *session.Token) CallOption {
|
|
|
|
return func(config *callConfig) {
|
|
|
|
config.stoken = token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func retry() CallOption {
|
|
|
|
return func(config *callConfig) {
|
|
|
|
config.isRetry = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 15:46:38 +00:00
|
|
|
func useDefaultSession() CallOption {
|
|
|
|
return func(config *callConfig) {
|
|
|
|
config.useDefaultSession = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func cfgFromOpts(opts ...CallOption) *callConfig {
|
|
|
|
var cfg = new(callConfig)
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(cfg)
|
|
|
|
}
|
|
|
|
return cfg
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 07:46:44 +00:00
|
|
|
var _ Pool = (*pool)(nil)
|
|
|
|
|
2021-05-25 08:48:01 +00:00
|
|
|
type pool struct {
|
2021-11-16 13:50:33 +00:00
|
|
|
innerPools []*innerPool
|
|
|
|
key *ecdsa.PrivateKey
|
|
|
|
owner *owner.ID
|
|
|
|
cancel context.CancelFunc
|
|
|
|
closedCh chan struct{}
|
|
|
|
cache *SessionCache
|
|
|
|
}
|
|
|
|
|
|
|
|
type innerPool struct {
|
2021-05-25 08:48:01 +00:00
|
|
|
lock sync.RWMutex
|
|
|
|
sampler *Sampler
|
|
|
|
clientPacks []*clientPack
|
|
|
|
}
|
|
|
|
|
2021-05-28 20:12:58 +00:00
|
|
|
func newPool(ctx context.Context, options *BuilderOptions) (Pool, error) {
|
2021-11-08 13:28:28 +00:00
|
|
|
cache, err := NewCache()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("couldn't create cache: %w", err)
|
|
|
|
}
|
2021-10-25 12:57:55 +00:00
|
|
|
|
2022-01-13 13:16:35 +00:00
|
|
|
ownerID := owner.NewIDFromPublicKey(&options.Key.PublicKey)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-16 13:50:33 +00:00
|
|
|
inner := make([]*innerPool, len(options.nodesParams))
|
2021-09-07 14:34:20 +00:00
|
|
|
var atLeastOneHealthy bool
|
2021-12-02 12:21:54 +00:00
|
|
|
|
|
|
|
var cliPrm client.CreateSessionPrm
|
|
|
|
|
|
|
|
cliPrm.SetExp(options.SessionExpirationEpoch)
|
|
|
|
|
2021-11-16 13:50:33 +00:00
|
|
|
for i, params := range options.nodesParams {
|
|
|
|
clientPacks := make([]*clientPack, len(params.weights))
|
|
|
|
for j, address := range params.addresses {
|
|
|
|
c, err := options.clientBuilder(client.WithDefaultPrivateKey(options.Key),
|
|
|
|
client.WithURIAddress(address, nil),
|
2022-01-11 17:17:31 +00:00
|
|
|
client.WithDialTimeout(options.NodeConnectionTimeout),
|
|
|
|
client.WithNeoFSErrorParsing())
|
2021-11-16 13:50:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var healthy bool
|
2021-12-02 12:21:54 +00:00
|
|
|
cliRes, err := c.CreateSession(ctx, cliPrm)
|
2021-11-16 13:50:33 +00:00
|
|
|
if err != nil && options.Logger != nil {
|
|
|
|
options.Logger.Warn("failed to create neofs session token for client",
|
|
|
|
zap.String("address", address),
|
|
|
|
zap.Error(err))
|
|
|
|
} else if err == nil {
|
|
|
|
healthy, atLeastOneHealthy = true, true
|
|
|
|
st := sessionTokenForOwner(ownerID, cliRes)
|
|
|
|
_ = cache.Put(formCacheKey(address, options.Key), st)
|
|
|
|
}
|
|
|
|
clientPacks[j] = &clientPack{client: c, healthy: healthy, address: address}
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
2021-11-16 13:50:33 +00:00
|
|
|
source := rand.NewSource(time.Now().UnixNano())
|
|
|
|
sampler := NewSampler(params.weights, source)
|
|
|
|
|
|
|
|
inner[i] = &innerPool{
|
|
|
|
sampler: sampler,
|
|
|
|
clientPacks: clientPacks,
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
2021-09-07 14:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !atLeastOneHealthy {
|
|
|
|
return nil, fmt.Errorf("at least one node must be healthy")
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
2021-09-07 14:34:20 +00:00
|
|
|
|
[#48] pool: add `Close` method
Fix occasional panic in tests:
```
> for i in (seq 1 100); go test -race -count=1 ./pool/... ; end
...
{"level":"warn","ts":1635251466.567485,"caller":"pool/pool.go:122","msg":"failed to create neofs session token for client","address":"peer0","error":"error session"}
panic: Fail in goroutine after TestTwoNodes has completed
goroutine 6 [running]:
testing.(*common).Fail(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:710 +0x1b4
testing.(*common).FailNow(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:732 +0x2f
testing.(*common).Fatalf(0xc000074070, {0xd9d816, 0x2e}, {0xc000094050, 0x5, 0x5})
/usr/lib/go/src/testing/testing.go:830 +0x85
github.com/golang/mock/gomock.(*Controller).Call.func1(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:231 +0x44d
github.com/golang/mock/gomock.(*Controller).Call(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:247 +0xce
github.com/nspcc-dev/neofs-sdk-go/pool.(*MockClient).EndpointInfo(0xc0002dac30, {0xe85528, 0xc00008a120}, {0x0, 0x0, 0x0})
/home/dzeta/repo/neofs-sdk-go/pool/mock_test.go:186 +0x298
github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth.func1(0x1, {0xe950d8, 0xc0002dac30})
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:183 +0x188
created by github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:174 +0x233
```
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-10-26 12:36:08 +00:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
2021-10-25 12:57:55 +00:00
|
|
|
pool := &pool{
|
2021-11-16 13:50:33 +00:00
|
|
|
innerPools: inner,
|
|
|
|
key: options.Key,
|
|
|
|
owner: ownerID,
|
|
|
|
cancel: cancel,
|
|
|
|
closedCh: make(chan struct{}),
|
|
|
|
cache: cache,
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
2021-06-21 11:12:08 +00:00
|
|
|
go startRebalance(ctx, pool, options)
|
|
|
|
return pool, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func startRebalance(ctx context.Context, p *pool, options *BuilderOptions) {
|
|
|
|
ticker := time.NewTimer(options.ClientRebalanceInterval)
|
2021-11-16 13:50:33 +00:00
|
|
|
buffers := make([][]float64, len(options.nodesParams))
|
|
|
|
for i, params := range options.nodesParams {
|
|
|
|
buffers[i] = make([]float64, len(params.weights))
|
|
|
|
}
|
2021-06-21 11:12:08 +00:00
|
|
|
|
2021-07-20 08:02:14 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
[#48] pool: add `Close` method
Fix occasional panic in tests:
```
> for i in (seq 1 100); go test -race -count=1 ./pool/... ; end
...
{"level":"warn","ts":1635251466.567485,"caller":"pool/pool.go:122","msg":"failed to create neofs session token for client","address":"peer0","error":"error session"}
panic: Fail in goroutine after TestTwoNodes has completed
goroutine 6 [running]:
testing.(*common).Fail(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:710 +0x1b4
testing.(*common).FailNow(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:732 +0x2f
testing.(*common).Fatalf(0xc000074070, {0xd9d816, 0x2e}, {0xc000094050, 0x5, 0x5})
/usr/lib/go/src/testing/testing.go:830 +0x85
github.com/golang/mock/gomock.(*Controller).Call.func1(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:231 +0x44d
github.com/golang/mock/gomock.(*Controller).Call(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:247 +0xce
github.com/nspcc-dev/neofs-sdk-go/pool.(*MockClient).EndpointInfo(0xc0002dac30, {0xe85528, 0xc00008a120}, {0x0, 0x0, 0x0})
/home/dzeta/repo/neofs-sdk-go/pool/mock_test.go:186 +0x298
github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth.func1(0x1, {0xe950d8, 0xc0002dac30})
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:183 +0x188
created by github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:174 +0x233
```
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-10-26 12:36:08 +00:00
|
|
|
close(p.closedCh)
|
2021-07-20 08:02:14 +00:00
|
|
|
return
|
|
|
|
case <-ticker.C:
|
2021-11-16 13:50:33 +00:00
|
|
|
updateNodesHealth(ctx, p, options, buffers)
|
2021-07-20 08:02:14 +00:00
|
|
|
ticker.Reset(options.ClientRebalanceInterval)
|
|
|
|
}
|
2021-06-21 11:12:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 13:50:33 +00:00
|
|
|
func updateNodesHealth(ctx context.Context, p *pool, options *BuilderOptions, buffers [][]float64) {
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
for i, inner := range p.innerPools {
|
|
|
|
wg.Add(1)
|
|
|
|
|
|
|
|
bufferWeights := buffers[i]
|
|
|
|
go func(i int, innerPool *innerPool) {
|
|
|
|
defer wg.Done()
|
|
|
|
updateInnerNodesHealth(ctx, p, i, options, bufferWeights)
|
|
|
|
}(i, inner)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateInnerNodesHealth(ctx context.Context, pool *pool, i int, options *BuilderOptions, bufferWeights []float64) {
|
|
|
|
if i > len(pool.innerPools)-1 {
|
|
|
|
return
|
2021-06-21 11:12:08 +00:00
|
|
|
}
|
2021-11-16 13:50:33 +00:00
|
|
|
p := pool.innerPools[i]
|
|
|
|
|
2021-06-21 11:12:08 +00:00
|
|
|
healthyChanged := false
|
|
|
|
wg := sync.WaitGroup{}
|
2021-12-02 12:21:54 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
prmEndpoint client.EndpointInfoPrm
|
|
|
|
prmSession client.CreateSessionPrm
|
|
|
|
)
|
|
|
|
|
|
|
|
prmSession.SetExp(options.SessionExpirationEpoch)
|
|
|
|
|
2021-11-16 13:50:33 +00:00
|
|
|
for j, cPack := range p.clientPacks {
|
2021-06-21 11:12:08 +00:00
|
|
|
wg.Add(1)
|
2021-12-02 12:21:54 +00:00
|
|
|
go func(j int, cli Client) {
|
2021-06-21 11:12:08 +00:00
|
|
|
defer wg.Done()
|
2021-05-25 08:48:01 +00:00
|
|
|
ok := true
|
2021-06-21 11:12:08 +00:00
|
|
|
tctx, c := context.WithTimeout(ctx, options.NodeRequestTimeout)
|
|
|
|
defer c()
|
2021-12-02 12:21:54 +00:00
|
|
|
|
|
|
|
if _, err := cli.EndpointInfo(tctx, prmEndpoint); err != nil {
|
2021-06-21 11:12:08 +00:00
|
|
|
ok = false
|
2021-11-16 13:50:33 +00:00
|
|
|
bufferWeights[j] = 0
|
2021-06-21 11:12:08 +00:00
|
|
|
}
|
2021-10-25 12:57:55 +00:00
|
|
|
p.lock.RLock()
|
2021-11-16 13:50:33 +00:00
|
|
|
cp := *p.clientPacks[j]
|
2021-10-25 12:57:55 +00:00
|
|
|
p.lock.RUnlock()
|
|
|
|
|
2021-06-21 11:12:08 +00:00
|
|
|
if ok {
|
2021-11-16 13:50:33 +00:00
|
|
|
bufferWeights[j] = options.nodesParams[i].weights[j]
|
2021-10-25 12:57:55 +00:00
|
|
|
if !cp.healthy {
|
2021-12-02 12:21:54 +00:00
|
|
|
if cliRes, err := cli.CreateSession(ctx, prmSession); err != nil {
|
2021-07-28 08:42:55 +00:00
|
|
|
ok = false
|
2021-11-16 13:50:33 +00:00
|
|
|
bufferWeights[j] = 0
|
2021-10-25 12:57:55 +00:00
|
|
|
} else {
|
2021-11-16 13:50:33 +00:00
|
|
|
tkn := pool.newSessionToken(cliRes)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-16 13:50:33 +00:00
|
|
|
_ = pool.cache.Put(formCacheKey(cp.address, pool.key), tkn)
|
2021-07-28 08:42:55 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-25 12:57:55 +00:00
|
|
|
} else {
|
2021-11-16 13:50:33 +00:00
|
|
|
pool.cache.DeleteByPrefix(cp.address)
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
2021-06-21 11:12:08 +00:00
|
|
|
|
|
|
|
p.lock.Lock()
|
2021-11-16 13:50:33 +00:00
|
|
|
if p.clientPacks[j].healthy != ok {
|
|
|
|
p.clientPacks[j].healthy = ok
|
2021-06-21 11:12:08 +00:00
|
|
|
healthyChanged = true
|
|
|
|
}
|
|
|
|
p.lock.Unlock()
|
2021-11-16 13:50:33 +00:00
|
|
|
}(j, cPack.client)
|
2021-06-21 11:12:08 +00:00
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
if healthyChanged {
|
|
|
|
probabilities := adjustWeights(bufferWeights)
|
|
|
|
source := rand.NewSource(time.Now().UnixNano())
|
|
|
|
p.lock.Lock()
|
|
|
|
p.sampler = NewSampler(probabilities, source)
|
|
|
|
p.lock.Unlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func adjustWeights(weights []float64) []float64 {
|
|
|
|
adjusted := make([]float64, len(weights))
|
|
|
|
sum := 0.0
|
|
|
|
for _, weight := range weights {
|
|
|
|
sum += weight
|
|
|
|
}
|
|
|
|
if sum > 0 {
|
|
|
|
for i, weight := range weights {
|
|
|
|
adjusted[i] = weight / sum
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
2021-06-21 11:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return adjusted
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 14:40:37 +00:00
|
|
|
func (p *pool) Connection() (Client, *session.Token, error) {
|
2021-10-25 12:57:55 +00:00
|
|
|
cp, err := p.connection()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
token := p.cache.Get(formCacheKey(cp.address, p.key))
|
|
|
|
return cp.client, token, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pool) connection() (*clientPack, error) {
|
2021-11-16 13:50:33 +00:00
|
|
|
for _, inner := range p.innerPools {
|
|
|
|
cp, err := inner.connection()
|
|
|
|
if err == nil {
|
|
|
|
return cp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errors.New("no healthy client")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *innerPool) connection() (*clientPack, error) {
|
2021-05-25 08:48:01 +00:00
|
|
|
p.lock.RLock()
|
|
|
|
defer p.lock.RUnlock()
|
|
|
|
if len(p.clientPacks) == 1 {
|
|
|
|
cp := p.clientPacks[0]
|
|
|
|
if cp.healthy {
|
2021-10-25 12:57:55 +00:00
|
|
|
return cp, nil
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
2021-10-25 12:57:55 +00:00
|
|
|
return nil, errors.New("no healthy client")
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
|
|
|
attempts := 3 * len(p.clientPacks)
|
|
|
|
for k := 0; k < attempts; k++ {
|
|
|
|
i := p.sampler.Next()
|
|
|
|
if cp := p.clientPacks[i]; cp.healthy {
|
2021-10-25 12:57:55 +00:00
|
|
|
return cp, nil
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-16 13:50:33 +00:00
|
|
|
|
2021-10-25 12:57:55 +00:00
|
|
|
return nil, errors.New("no healthy client")
|
2021-05-25 08:48:01 +00:00
|
|
|
}
|
2021-05-28 20:12:58 +00:00
|
|
|
|
|
|
|
func (p *pool) OwnerID() *owner.ID {
|
|
|
|
return p.owner
|
|
|
|
}
|
2021-06-13 12:18:43 +00:00
|
|
|
|
2021-10-25 12:57:55 +00:00
|
|
|
func formCacheKey(address string, key *ecdsa.PrivateKey) string {
|
2021-12-10 13:56:04 +00:00
|
|
|
k := keys.PrivateKey{PrivateKey: *key}
|
|
|
|
return address + k.String()
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) conn(ctx context.Context, cfg *callConfig) (*clientPack, []client.CallOption, error) {
|
2021-10-25 12:57:55 +00:00
|
|
|
cp, err := p.connection()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
clientCallOptions := make([]client.CallOption, 0, 3)
|
2021-10-25 12:57:55 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
key := p.key
|
|
|
|
if cfg.key != nil {
|
|
|
|
key = cfg.key
|
|
|
|
}
|
|
|
|
clientCallOptions = append(clientCallOptions, client.WithKey(key))
|
|
|
|
|
|
|
|
sessionToken := cfg.stoken
|
2021-12-16 15:46:38 +00:00
|
|
|
if sessionToken == nil && cfg.useDefaultSession {
|
2021-11-15 06:35:30 +00:00
|
|
|
cacheKey := formCacheKey(cp.address, key)
|
|
|
|
sessionToken = p.cache.Get(cacheKey)
|
|
|
|
if sessionToken == nil {
|
2021-12-02 12:21:54 +00:00
|
|
|
var cliPrm client.CreateSessionPrm
|
|
|
|
|
|
|
|
cliPrm.SetExp(math.MaxUint32)
|
|
|
|
|
|
|
|
cliRes, err := cp.client.CreateSession(ctx, cliPrm)
|
2021-11-15 06:35:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2022-01-13 13:16:35 +00:00
|
|
|
ownerID := owner.NewIDFromPublicKey(&key.PublicKey)
|
2022-01-17 10:35:39 +00:00
|
|
|
sessionToken = sessionTokenForOwner(ownerID, cliRes)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
cfg.stoken = sessionToken
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
_ = p.cache.Put(cacheKey, sessionToken)
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
2021-06-22 09:15:21 +00:00
|
|
|
}
|
2021-11-15 06:35:30 +00:00
|
|
|
clientCallOptions = append(clientCallOptions, client.WithSession(sessionToken))
|
2021-06-22 09:15:21 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if cfg.btoken != nil {
|
|
|
|
clientCallOptions = append(clientCallOptions, client.WithBearer(cfg.btoken))
|
2021-06-22 09:15:21 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
return cp, clientCallOptions, nil
|
2021-06-22 09:15:21 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 14:34:02 +00:00
|
|
|
func (p *pool) checkSessionTokenErr(err error, address string) bool {
|
2021-10-25 12:57:55 +00:00
|
|
|
if err == nil {
|
2021-11-03 14:34:02 +00:00
|
|
|
return false
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if strings.Contains(err.Error(), "session token does not exist") {
|
|
|
|
p.cache.DeleteByPrefix(address)
|
2021-11-03 14:34:02 +00:00
|
|
|
return true
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
2021-11-03 14:34:02 +00:00
|
|
|
|
|
|
|
return false
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 16:20:32 +00:00
|
|
|
func (p *pool) PutObject(ctx context.Context, params *client.PutObjectParams, opts ...CallOption) (*oid.ID, error) {
|
2021-12-16 15:46:38 +00:00
|
|
|
cfg := cfgFromOpts(append(opts, useDefaultSession())...)
|
2021-11-15 06:35:30 +00:00
|
|
|
cp, options, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-10-25 12:57:55 +00:00
|
|
|
res, err := cp.client.PutObject(ctx, params, options...)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.PutObject(ctx, params, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.ID(), nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) DeleteObject(ctx context.Context, params *client.DeleteObjectParams, opts ...CallOption) error {
|
2021-12-16 15:46:38 +00:00
|
|
|
cfg := cfgFromOpts(append(opts, useDefaultSession())...)
|
2021-11-15 06:35:30 +00:00
|
|
|
cp, options, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2022-01-11 17:17:31 +00:00
|
|
|
_, err = cp.client.DeleteObject(ctx, params, options...)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.DeleteObject(ctx, params, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
// here err already carries both status and client errors
|
|
|
|
|
2021-10-25 12:57:55 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) GetObject(ctx context.Context, params *client.GetObjectParams, opts ...CallOption) (*object.Object, error) {
|
2021-12-16 15:46:38 +00:00
|
|
|
cfg := cfgFromOpts(append(opts, useDefaultSession())...)
|
2021-11-15 06:35:30 +00:00
|
|
|
cp, options, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-10-25 12:57:55 +00:00
|
|
|
res, err := cp.client.GetObject(ctx, params, options...)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.GetObject(ctx, params, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Object(), nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) GetObjectHeader(ctx context.Context, params *client.ObjectHeaderParams, opts ...CallOption) (*object.Object, error) {
|
2021-12-16 15:46:38 +00:00
|
|
|
cfg := cfgFromOpts(append(opts, useDefaultSession())...)
|
2021-11-15 06:35:30 +00:00
|
|
|
cp, options, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-11-17 11:22:32 +00:00
|
|
|
res, err := cp.client.HeadObject(ctx, params, options...)
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.GetObjectHeader(ctx, params, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Object(), nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) ObjectPayloadRangeData(ctx context.Context, params *client.RangeDataParams, opts ...CallOption) ([]byte, error) {
|
2021-12-16 15:46:38 +00:00
|
|
|
cfg := cfgFromOpts(append(opts, useDefaultSession())...)
|
2021-11-15 06:35:30 +00:00
|
|
|
cp, options, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-10-25 12:57:55 +00:00
|
|
|
res, err := cp.client.ObjectPayloadRangeData(ctx, params, options...)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.ObjectPayloadRangeData(ctx, params, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Data(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func copyRangeChecksumParams(prm *client.RangeChecksumParams) *client.RangeChecksumParams {
|
|
|
|
var prmCopy client.RangeChecksumParams
|
|
|
|
|
|
|
|
prmCopy.WithAddress(prm.Address())
|
|
|
|
prmCopy.WithSalt(prm.Salt())
|
|
|
|
prmCopy.WithRangeList(prm.RangeList()...)
|
|
|
|
|
|
|
|
return &prmCopy
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) ObjectPayloadRangeSHA256(ctx context.Context, params *client.RangeChecksumParams, opts ...CallOption) ([][32]byte, error) {
|
2021-12-16 15:46:38 +00:00
|
|
|
cfg := cfgFromOpts(append(opts, useDefaultSession())...)
|
2021-11-15 06:35:30 +00:00
|
|
|
cp, options, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
// FIXME: pretty bad approach but we should not mutate params through the pointer
|
|
|
|
// If non-SHA256 algo is set then we need to reset it.
|
|
|
|
params = copyRangeChecksumParams(params)
|
|
|
|
// SHA256 by default, no need to do smth
|
|
|
|
|
|
|
|
res, err := cp.client.HashObjectPayloadRanges(ctx, params, options...)
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.ObjectPayloadRangeSHA256(ctx, params, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cliHashes := res.Hashes()
|
|
|
|
|
|
|
|
hs := make([][sha256.Size]byte, len(cliHashes))
|
|
|
|
|
|
|
|
for i := range cliHashes {
|
|
|
|
if ln := len(cliHashes[i]); ln != sha256.Size {
|
|
|
|
return nil, fmt.Errorf("invalid SHA256 checksum size %d", ln)
|
|
|
|
}
|
|
|
|
|
|
|
|
copy(hs[i][:], cliHashes[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return hs, nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) ObjectPayloadRangeTZ(ctx context.Context, params *client.RangeChecksumParams, opts ...CallOption) ([][64]byte, error) {
|
2021-12-16 15:46:38 +00:00
|
|
|
cfg := cfgFromOpts(append(opts, useDefaultSession())...)
|
2021-11-15 06:35:30 +00:00
|
|
|
cp, options, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
// FIXME: pretty bad approach but we should not mutate params through the pointer
|
|
|
|
// We need to set Tillich-Zemor algo.
|
|
|
|
params = copyRangeChecksumParams(params)
|
|
|
|
params.TZ()
|
|
|
|
|
|
|
|
res, err := cp.client.HashObjectPayloadRanges(ctx, params, options...)
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.ObjectPayloadRangeTZ(ctx, params, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cliHashes := res.Hashes()
|
|
|
|
|
|
|
|
hs := make([][client.TZSize]byte, len(cliHashes))
|
|
|
|
|
|
|
|
for i := range cliHashes {
|
|
|
|
if ln := len(cliHashes[i]); ln != client.TZSize {
|
|
|
|
return nil, fmt.Errorf("invalid TZ checksum size %d", ln)
|
|
|
|
}
|
|
|
|
|
|
|
|
copy(hs[i][:], cliHashes[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return hs, nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 16:20:32 +00:00
|
|
|
func (p *pool) SearchObject(ctx context.Context, params *client.SearchObjectParams, opts ...CallOption) ([]*oid.ID, error) {
|
2021-12-16 15:46:38 +00:00
|
|
|
cfg := cfgFromOpts(append(opts, useDefaultSession())...)
|
2021-11-15 06:35:30 +00:00
|
|
|
cp, options, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-11-17 11:22:32 +00:00
|
|
|
res, err := cp.client.SearchObjects(ctx, params, options...)
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.SearchObject(ctx, params, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.IDList(), nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*cid.ID, error) {
|
|
|
|
cfg := cfgFromOpts(opts...)
|
2021-12-02 12:21:54 +00:00
|
|
|
cp, _, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
var cliPrm client.ContainerPutPrm
|
|
|
|
|
|
|
|
if cnr != nil {
|
|
|
|
cliPrm.SetContainer(*cnr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.stoken != nil {
|
|
|
|
cliPrm.SetSessionToken(*cfg.stoken)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := cp.client.PutContainer(ctx, cliPrm)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.PutContainer(ctx, cnr, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.ID(), nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) GetContainer(ctx context.Context, cid *cid.ID, opts ...CallOption) (*container.Container, error) {
|
|
|
|
cfg := cfgFromOpts(opts...)
|
2021-12-02 12:21:54 +00:00
|
|
|
cp, _, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
var cliPrm client.ContainerGetPrm
|
|
|
|
|
|
|
|
if cid != nil {
|
|
|
|
cliPrm.SetContainer(*cid)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := cp.client.GetContainer(ctx, cliPrm)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.GetContainer(ctx, cid, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Container(), nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) ListContainers(ctx context.Context, ownerID *owner.ID, opts ...CallOption) ([]*cid.ID, error) {
|
|
|
|
cfg := cfgFromOpts(opts...)
|
2021-12-02 12:21:54 +00:00
|
|
|
cp, _, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
var cliPrm client.ContainerListPrm
|
|
|
|
|
|
|
|
if ownerID != nil {
|
|
|
|
cliPrm.SetAccount(*ownerID)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := cp.client.ListContainers(ctx, cliPrm)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.ListContainers(ctx, ownerID, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return res.Containers(), nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) DeleteContainer(ctx context.Context, cid *cid.ID, opts ...CallOption) error {
|
|
|
|
cfg := cfgFromOpts(opts...)
|
2021-12-02 12:21:54 +00:00
|
|
|
cp, _, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
var cliPrm client.ContainerDeletePrm
|
|
|
|
|
|
|
|
if cid != nil {
|
|
|
|
cliPrm.SetContainer(*cid)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.stoken != nil {
|
|
|
|
cliPrm.SetSessionToken(*cfg.stoken)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = cp.client.DeleteContainer(ctx, cliPrm)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.DeleteContainer(ctx, cid, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
// here err already carries both status and client errors
|
|
|
|
|
2021-10-25 12:57:55 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-11-17 11:22:32 +00:00
|
|
|
func (p *pool) GetEACL(ctx context.Context, cid *cid.ID, opts ...CallOption) (*eacl.Table, error) {
|
2021-11-15 06:35:30 +00:00
|
|
|
cfg := cfgFromOpts(opts...)
|
2021-12-02 12:21:54 +00:00
|
|
|
cp, _, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
var cliPrm client.EACLPrm
|
|
|
|
|
|
|
|
if cid != nil {
|
|
|
|
cliPrm.SetContainer(*cid)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := cp.client.EACL(ctx, cliPrm)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
|
|
|
return p.GetEACL(ctx, cid, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Table(), nil
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
func (p *pool) SetEACL(ctx context.Context, table *eacl.Table, opts ...CallOption) error {
|
|
|
|
cfg := cfgFromOpts(opts...)
|
2021-12-02 12:21:54 +00:00
|
|
|
cp, _, err := p.conn(ctx, cfg)
|
2021-10-25 12:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
var cliPrm client.SetEACLPrm
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
if table != nil {
|
|
|
|
cliPrm.SetTable(*table)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
if cfg.stoken != nil {
|
|
|
|
cliPrm.SetSessionToken(*cfg.stoken)
|
2021-10-25 12:57:55 +00:00
|
|
|
}
|
2022-01-11 17:17:31 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
_, err = cp.client.SetEACL(ctx, cliPrm)
|
2021-11-17 11:22:32 +00:00
|
|
|
|
2021-11-15 06:35:30 +00:00
|
|
|
if p.checkSessionTokenErr(err, cp.address) && !cfg.isRetry {
|
|
|
|
opts = append(opts, retry())
|
2021-12-02 12:21:54 +00:00
|
|
|
return p.SetEACL(ctx, table, opts...)
|
2021-11-03 14:34:02 +00:00
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
// here err already carries both status and client errors
|
|
|
|
|
2021-10-25 12:57:55 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-12-17 10:36:07 +00:00
|
|
|
func (p *pool) Balance(ctx context.Context, o *owner.ID, opts ...CallOption) (*accounting.Decimal, error) {
|
|
|
|
cfg := cfgFromOpts(opts...)
|
2021-12-02 12:21:54 +00:00
|
|
|
cp, _, err := p.conn(ctx, cfg)
|
2021-12-17 10:36:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
var cliPrm client.GetBalancePrm
|
|
|
|
|
|
|
|
if o != nil {
|
|
|
|
cliPrm.SetAccount(*o)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := cp.client.GetBalance(ctx, cliPrm)
|
2022-01-11 17:17:31 +00:00
|
|
|
if err != nil { // here err already carries both status and client errors
|
2021-12-17 10:36:07 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Amount(), nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 09:15:21 +00:00
|
|
|
func (p *pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollParams *ContainerPollingParams) error {
|
|
|
|
conn, _, err := p.Connection()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
wctx, cancel := context.WithTimeout(ctx, pollParams.CreationTimeout)
|
|
|
|
defer cancel()
|
|
|
|
ticker := time.NewTimer(pollParams.PollInterval)
|
|
|
|
defer ticker.Stop()
|
|
|
|
wdone := wctx.Done()
|
|
|
|
done := ctx.Done()
|
2021-12-02 12:21:54 +00:00
|
|
|
|
|
|
|
var cliPrm client.ContainerGetPrm
|
|
|
|
|
|
|
|
if cid != nil {
|
|
|
|
cliPrm.SetContainer(*cid)
|
|
|
|
}
|
|
|
|
|
2021-06-22 09:15:21 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
return ctx.Err()
|
|
|
|
case <-wdone:
|
|
|
|
return wctx.Err()
|
|
|
|
case <-ticker.C:
|
2021-12-02 12:21:54 +00:00
|
|
|
_, err = conn.GetContainer(ctx, cliPrm)
|
2021-06-22 09:15:21 +00:00
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ticker.Reset(pollParams.PollInterval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
[#48] pool: add `Close` method
Fix occasional panic in tests:
```
> for i in (seq 1 100); go test -race -count=1 ./pool/... ; end
...
{"level":"warn","ts":1635251466.567485,"caller":"pool/pool.go:122","msg":"failed to create neofs session token for client","address":"peer0","error":"error session"}
panic: Fail in goroutine after TestTwoNodes has completed
goroutine 6 [running]:
testing.(*common).Fail(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:710 +0x1b4
testing.(*common).FailNow(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:732 +0x2f
testing.(*common).Fatalf(0xc000074070, {0xd9d816, 0x2e}, {0xc000094050, 0x5, 0x5})
/usr/lib/go/src/testing/testing.go:830 +0x85
github.com/golang/mock/gomock.(*Controller).Call.func1(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:231 +0x44d
github.com/golang/mock/gomock.(*Controller).Call(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:247 +0xce
github.com/nspcc-dev/neofs-sdk-go/pool.(*MockClient).EndpointInfo(0xc0002dac30, {0xe85528, 0xc00008a120}, {0x0, 0x0, 0x0})
/home/dzeta/repo/neofs-sdk-go/pool/mock_test.go:186 +0x298
github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth.func1(0x1, {0xe950d8, 0xc0002dac30})
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:183 +0x188
created by github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:174 +0x233
```
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-10-26 12:36:08 +00:00
|
|
|
|
2021-11-16 13:50:33 +00:00
|
|
|
// Close closes the pool and releases all the associated resources.
|
[#48] pool: add `Close` method
Fix occasional panic in tests:
```
> for i in (seq 1 100); go test -race -count=1 ./pool/... ; end
...
{"level":"warn","ts":1635251466.567485,"caller":"pool/pool.go:122","msg":"failed to create neofs session token for client","address":"peer0","error":"error session"}
panic: Fail in goroutine after TestTwoNodes has completed
goroutine 6 [running]:
testing.(*common).Fail(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:710 +0x1b4
testing.(*common).FailNow(0xc0002e1380)
/usr/lib/go/src/testing/testing.go:732 +0x2f
testing.(*common).Fatalf(0xc000074070, {0xd9d816, 0x2e}, {0xc000094050, 0x5, 0x5})
/usr/lib/go/src/testing/testing.go:830 +0x85
github.com/golang/mock/gomock.(*Controller).Call.func1(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:231 +0x44d
github.com/golang/mock/gomock.(*Controller).Call(0xc0002f4120, {0xd68380, 0xc0002dac30}, {0xd8847f, 0xc}, {0xc000074020, 0x1, 0x1})
/home/dzeta/go/pkg/mod/github.com/golang/mock@v1.6.0/gomock/controller.go:247 +0xce
github.com/nspcc-dev/neofs-sdk-go/pool.(*MockClient).EndpointInfo(0xc0002dac30, {0xe85528, 0xc00008a120}, {0x0, 0x0, 0x0})
/home/dzeta/repo/neofs-sdk-go/pool/mock_test.go:186 +0x298
github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth.func1(0x1, {0xe950d8, 0xc0002dac30})
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:183 +0x188
created by github.com/nspcc-dev/neofs-sdk-go/pool.updateNodesHealth
/home/dzeta/repo/neofs-sdk-go/pool/pool.go:174 +0x233
```
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-10-26 12:36:08 +00:00
|
|
|
func (p *pool) Close() {
|
|
|
|
p.cancel()
|
|
|
|
<-p.closedCh
|
|
|
|
}
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
// creates new session token from CreateSession call result.
|
|
|
|
func (p *pool) newSessionToken(cliRes *client.CreateSessionRes) *session.Token {
|
|
|
|
return sessionTokenForOwner(p.owner, cliRes)
|
|
|
|
}
|
|
|
|
|
|
|
|
// creates new session token with specified owner from CreateSession call result.
|
|
|
|
func sessionTokenForOwner(id *owner.ID, cliRes *client.CreateSessionRes) *session.Token {
|
|
|
|
st := session.NewToken()
|
|
|
|
st.SetOwnerID(id)
|
|
|
|
st.SetID(cliRes.ID())
|
2021-12-02 12:21:54 +00:00
|
|
|
st.SetSessionKey(cliRes.PublicKey())
|
2021-11-17 11:22:32 +00:00
|
|
|
|
|
|
|
return st
|
|
|
|
}
|