2022-03-15 08:54:15 +00:00
|
|
|
/*
|
|
|
|
Package pool provides a wrapper for several NeoFS API clients.
|
|
|
|
|
|
|
|
The main component is Pool type. It is a virtual connection to the network
|
|
|
|
and provides methods for executing operations on the server. It also supports
|
|
|
|
a weighted random selection of the underlying client to make requests.
|
|
|
|
|
|
|
|
Create pool instance with 3 nodes connection.
|
|
|
|
This InitParameters will make pool use 192.168.130.71 node while it is healthy. Otherwise, it will make the pool use
|
|
|
|
192.168.130.72 for 90% of requests and 192.168.130.73 for remaining 10%.
|
|
|
|
:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-15 12:49:14 +00:00
|
|
|
var prm pool.InitParameters
|
2023-04-25 08:31:27 +00:00
|
|
|
prm.SetSigner(signer)
|
2022-03-15 12:49:14 +00:00
|
|
|
prm.AddNode(NewNodeParam(1, "192.168.130.71", 1))
|
|
|
|
prm.AddNode(NewNodeParam(2, "192.168.130.72", 9))
|
|
|
|
prm.AddNode(NewNodeParam(2, "192.168.130.73", 1))
|
|
|
|
// ...
|
2022-03-15 08:54:15 +00:00
|
|
|
|
|
|
|
p, err := pool.NewPool(prm)
|
|
|
|
// ...
|
|
|
|
|
|
|
|
Connect to the NeoFS server:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-15 08:54:15 +00:00
|
|
|
err := p.Dial(ctx)
|
|
|
|
// ...
|
|
|
|
|
|
|
|
Execute NeoFS operation on the server:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-15 08:54:15 +00:00
|
|
|
var prm pool.PrmContainerPut
|
|
|
|
prm.SetContainer(cnr)
|
|
|
|
// ...
|
|
|
|
|
|
|
|
res, err := p.PutContainer(context.Background(), prm)
|
|
|
|
// ...
|
|
|
|
|
|
|
|
Execute NeoFS operation on the server and check error:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-15 08:54:15 +00:00
|
|
|
var prm pool.PrmObjectHead
|
|
|
|
prm.SetAddress(addr)
|
|
|
|
// ...
|
|
|
|
|
|
|
|
res, err := p.HeadObject(context.Background(), prm)
|
|
|
|
if client.IsErrObjectNotFound(err) {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
// ...
|
|
|
|
|
|
|
|
Close the connection:
|
|
|
|
|
2022-08-24 14:17:40 +00:00
|
|
|
p.Close()
|
2022-03-15 08:54:15 +00:00
|
|
|
*/
|
|
|
|
package pool
|