forked from TrueCloudLab/frostfs-node
[#1609] config: Allow to prioritize N3 endpoints
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
aed83d1660
commit
7410827db8
15 changed files with 123 additions and 85 deletions
|
@ -2,9 +2,11 @@ package morphconfig
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -28,13 +30,27 @@ const (
|
|||
// from "morph" section.
|
||||
//
|
||||
// Throws panic if list is empty.
|
||||
func RPCEndpoint(c *config.Config) []string {
|
||||
v := config.StringSliceSafe(c.Sub(subsection), "rpc_endpoint")
|
||||
if len(v) == 0 {
|
||||
panic(fmt.Errorf("no morph chain RPC endpoints, see `morph.rpc_endpoint` section"))
|
||||
func RPCEndpoint(c *config.Config) []client.Endpoint {
|
||||
var es []client.Endpoint
|
||||
|
||||
sub := c.Sub(subsection).Sub("rpc_endpoint")
|
||||
for i := 0; ; i++ {
|
||||
s := sub.Sub(strconv.FormatInt(int64(i), 10))
|
||||
addr := config.StringSafe(s, "address")
|
||||
if addr == "" {
|
||||
break
|
||||
}
|
||||
|
||||
es = append(es, client.Endpoint{
|
||||
Address: addr,
|
||||
Priority: int(config.IntSafe(s, "priority")),
|
||||
})
|
||||
}
|
||||
|
||||
return v
|
||||
if len(es) == 0 {
|
||||
panic(fmt.Errorf("no morph chain RPC endpoints, see `morph.rpc_endpoint` section"))
|
||||
}
|
||||
return es
|
||||
}
|
||||
|
||||
// DialTimeout returns the value of "dial_timeout" config parameter
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
morphconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/morph"
|
||||
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -22,9 +23,9 @@ func TestMorphSection(t *testing.T) {
|
|||
const path = "../../../../config/example/node"
|
||||
|
||||
var (
|
||||
rpcs = []string{
|
||||
"wss://rpc1.morph.fs.neo.org:40341/ws",
|
||||
"wss://rpc2.morph.fs.neo.org:40341/ws",
|
||||
rpcs = []client.Endpoint{
|
||||
{"wss://rpc1.morph.fs.neo.org:40341/ws", 2},
|
||||
{"wss://rpc2.morph.fs.neo.org:40341/ws", 1},
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -35,18 +35,17 @@ func initMorphComponents(c *cfg) {
|
|||
var err error
|
||||
|
||||
addresses := morphconfig.RPCEndpoint(c.appCfg)
|
||||
if len(addresses) == 0 {
|
||||
fatalOnErr(errors.New("missing Neo RPC endpoints"))
|
||||
}
|
||||
|
||||
// Morph client stable-sorts endpoints by priority. Shuffle here to randomize
|
||||
// order of endpoints with the same priority.
|
||||
rand.Shuffle(len(addresses), func(i, j int) {
|
||||
addresses[i], addresses[j] = addresses[j], addresses[i]
|
||||
})
|
||||
|
||||
cli, err := client.New(c.key, addresses[0],
|
||||
cli, err := client.New(c.key,
|
||||
client.WithDialTimeout(morphconfig.DialTimeout(c.appCfg)),
|
||||
client.WithLogger(c.log),
|
||||
client.WithExtraEndpoints(addresses[1:]),
|
||||
client.WithEndpoints(addresses...),
|
||||
client.WithConnLostCallback(func() {
|
||||
c.internalErr <- errors.New("morph connection has been lost")
|
||||
}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue