Skip to content

Commit

Permalink
[#1648] morph: Change endpoint priority order
Browse files Browse the repository at this point in the history
The lowest value means the highest priority.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Aug 4, 2022
1 parent 2467be0 commit a97dee0
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changelog for NeoFS Node

### Changed

- Priority order in the Morph client (#1648)

### Fixed

- Losing request context in eACL response checks (#1595)
Expand All @@ -28,6 +30,9 @@ Changelog for NeoFS Node
- `google.golang.org/grpc` to `v1.48.0`

### Updating from v0.30.0
Change `morph.endpoint.client` priority values using the following rule:
the higher the priority the lower the value (non-specified or `0` values are
interpreted as the highest priority -- `1`).

## [0.30.0] - 2022-07-22 - Saengildo (생일도, 生日島)

Expand Down
10 changes: 9 additions & 1 deletion cmd/neofs-node/config/morph/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const (

// MaxConnPerHostDefault is a default maximum of connections per host of the morph client.
MaxConnPerHostDefault = 10

// PriorityDefault is a default endpoint priority for the morph client.
PriorityDefault = 1
)

// RPCEndpoint returns list of the values of "rpc_endpoint" config parameter
Expand All @@ -41,9 +44,14 @@ func RPCEndpoint(c *config.Config) []client.Endpoint {
break
}

priority := int(config.IntSafe(s, "priority"))
if priority <= 0 {
priority = PriorityDefault
}

es = append(es, client.Endpoint{
Address: addr,
Priority: int(config.IntSafe(s, "priority")),
Priority: priority,
})
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-node/config/morph/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func TestMorphSection(t *testing.T) {

var (
rpcs = []client.Endpoint{
{"wss://rpc1.morph.fs.neo.org:40341/ws", 2},
{"wss://rpc2.morph.fs.neo.org:40341/ws", 1},
{"wss://rpc1.morph.fs.neo.org:40341/ws", 1},
{"wss://rpc2.morph.fs.neo.org:40341/ws", 2},
}
)

Expand Down
4 changes: 2 additions & 2 deletions config/example/node.env
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ NEOFS_CONTRACTS_PROXY=ad7c6b55b737b696e5c82c85445040964a03e97f
NEOFS_MORPH_DIAL_TIMEOUT=30s
NEOFS_MORPH_DISABLE_CACHE=true
NEOFS_MORPH_RPC_ENDPOINT_0_ADDRESS="wss://rpc1.morph.fs.neo.org:40341/ws"
NEOFS_MORPH_RPC_ENDPOINT_0_PRIORITY=2
NEOFS_MORPH_RPC_ENDPOINT_0_PRIORITY=0
NEOFS_MORPH_RPC_ENDPOINT_1_ADDRESS="wss://rpc2.morph.fs.neo.org:40341/ws"
NEOFS_MORPH_RPC_ENDPOINT_1_PRIORITY=1
NEOFS_MORPH_RPC_ENDPOINT_1_PRIORITY=2

# API Client section
NEOFS_APICLIENT_DIAL_TIMEOUT=15s
Expand Down
4 changes: 2 additions & 2 deletions config/example/node.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@
"rpc_endpoint": [
{
"address": "wss://rpc1.morph.fs.neo.org:40341/ws",
"priority": 2
"priority": 0
},
{
"address": "wss://rpc2.morph.fs.neo.org:40341/ws",
"priority": 1
"priority": 2
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions config/example/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ morph:
disable_cache: true # do not use TTL cache for side chain GET operations
rpc_endpoint: # side chain NEO RPC endpoints; are shuffled and used one by one until the first success
- address: wss://rpc1.morph.fs.neo.org:40341/ws
priority: 2
priority: 0
- address: wss://rpc2.morph.fs.neo.org:40341/ws
priority: 1
priority: 2

apiclient:
dial_timeout: 15s # timeout for NEOFS API client connection
Expand Down
12 changes: 6 additions & 6 deletions docs/storage-node-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ morph:
disable_cache: true
rpc_endpoint:
- address: wss://rpc1.morph.fs.neo.org:40341/ws
priority: 2
- address: wss://rpc2.morph.fs.neo.org:40341/ws
priority: 1
- address: wss://rpc2.morph.fs.neo.org:40341/ws
priority: 2
```

| Parameter | Type | Default value | Description |
Expand All @@ -146,10 +146,10 @@ morph:
| `rpc_endpoint` | list of [endpoint descriptions](#rpc_endpoint-subsection) | | Array of endpoint descriptions. |

## `rpc_endpoint` subsection
| Parameter | Type | Default value | Description |
|------------|----------|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `address` | `string` | | _WebSocket_ N3 endpoint. |
| `priority` | `int` | `0` | Priority of an endpoint. Endpoint with a higher priority has more chance of being used. Endpoints with equal priority are iterated over randomly. |
| Parameter | Type | Default value | Description |
|------------|----------|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `address` | `string` | | _WebSocket_ N3 endpoint. |
| `priority` | `int` | `1` | Priority of an endpoint. Endpoint with a higher priority (lower configuration value) has more chance of being used. Endpoints with equal priority are iterated over randomly; a negative priority is interpreted as `1`. |

# `storage` section

Expand Down
10 changes: 9 additions & 1 deletion pkg/innerring/innerring.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,16 +961,24 @@ func createClient(ctx context.Context, p *chainParams, errChan chan<- error) (*c
// config name left unchanged for compatibility, may be its better to rename it to "endpoints" or "clients"
var endpoints []client.Endpoint

// defaultPriority is a default endpoint priority
const defaultPriority = 1

section := p.name + ".endpoint.client"
for i := 0; ; i++ {
addr := p.cfg.GetString(fmt.Sprintf("%s.%d.%s", section, i, "address"))
if addr == "" {
break
}

priority := p.cfg.GetInt(section + ".priority")
if priority <= 0 {
priority = defaultPriority
}

endpoints = append(endpoints, client.Endpoint{
Address: addr,
Priority: p.cfg.GetInt(section + ".priority"),
Priority: priority,
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/morph/client/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type endpoints struct {

func (e *endpoints) init(ee []Endpoint) {
sort.SliceStable(ee, func(i, j int) bool {
return ee[i].Priority > ee[j].Priority
return ee[i].Priority < ee[j].Priority
})

e.curr = 0
Expand Down
29 changes: 29 additions & 0 deletions pkg/morph/client/multy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package client

import (
"math/rand"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestInitEndpoints(t *testing.T) {
rand.Seed(time.Now().UnixNano())

ee := make([]Endpoint, 100)
for i := range ee {
ee[i].Priority = rand.Int()
}

var eeInternal endpoints
eeInternal.init(ee)

prevValue := eeInternal.list[0].Priority

for _, e := range eeInternal.list {
require.True(t, prevValue <= e.Priority)

prevValue = e.Priority
}
}

0 comments on commit a97dee0

Please sign in to comment.