From 19aff22bc75ff36495f43f2244c04fa3760c85cc Mon Sep 17 00:00:00 2001 From: Andrey Butusov Date: Tue, 29 Oct 2024 17:52:58 +0300 Subject: [PATCH] morph: support reloading morph endpoints with SIGHUP Add a new function `Client.Reload` that passes the `WithEndpoints` option and updates the `Client` endpoints. Add docs. Closes #1871. Signed-off-by: Andrey Butusov --- CHANGELOG.md | 1 + cmd/neofs-node/config.go | 4 ++++ docs/sighup.md | 6 ++++++ pkg/morph/client/constructor.go | 4 +++- pkg/morph/client/multi.go | 3 +++ pkg/morph/client/reload.go | 15 +++++++++++++++ 6 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 pkg/morph/client/reload.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aef08c7f4..3215b51138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ attribute, which is used for container domain name in NNS contracts (#2954) - `neofs-cli control object revive` command (#2968) - `--disable-auto-gen-tag` flag for gendoc command (#2983) - Docs files for cli commands to the `docs/cli-commands` folder (#2983) +- Reloading morph endpoints with SIGHUP (#2998) ### Fixed - Do not search for tombstones when handling their expiration, use local indexes instead (#2929) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 76d762ad92..56beef3bd2 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -870,6 +870,10 @@ func (c *cfg) configWatcher(ctx context.Context) { continue } + // Morph + + c.cli.Reload(client.WithEndpoints(c.morph.endpoints)) + c.log.Info("configuration has been reloaded successfully") case <-ctx.Done(): return diff --git a/docs/sighup.md b/docs/sighup.md index 9b32a0761a..4a879d7ddc 100644 --- a/docs/sighup.md +++ b/docs/sighup.md @@ -32,3 +32,9 @@ comparing paths from `shard.blobstor` section. After this we have 3 sets: | Changed section | Actions | |-----------------|----------------------------------------------------------------------------------------------------------------------| | `path` | If `path` is different, metabase is closed and opened with a new path. All other configuration will also be updated. | + +### Morph + +| Changed section | Actions | +|-----------------|----------------------| +| `endpoints` | Update N3 endpoints. | diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index c852b0f941..dd827345e5 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -40,7 +40,8 @@ type cfg struct { autoSidechainScope bool signer *transaction.Signer - endpoints []string + endpoints []string + endpointsLock *sync.RWMutex singleCli *rpcclient.WSClient // neo-go client for single client mode @@ -63,6 +64,7 @@ func defaultConfig() *cfg { signer: &transaction.Signer{ Scopes: transaction.CalledByEntry, }, + endpointsLock: &sync.RWMutex{}, reconnectionDelay: 5 * time.Second, reconnectionRetries: 5, } diff --git a/pkg/morph/client/multi.go b/pkg/morph/client/multi.go index 160e71534c..1de456ef63 100644 --- a/pkg/morph/client/multi.go +++ b/pkg/morph/client/multi.go @@ -33,6 +33,9 @@ func (c *Client) switchRPC() *connection { } func (c *Client) connEndpoints() *connection { + c.cfg.endpointsLock.RLock() + defer c.cfg.endpointsLock.RUnlock() + // Iterate endpoints. for _, e := range c.cfg.endpoints { conn, err := c.newConnection(e) diff --git a/pkg/morph/client/reload.go b/pkg/morph/client/reload.go new file mode 100644 index 0000000000..7288993c09 --- /dev/null +++ b/pkg/morph/client/reload.go @@ -0,0 +1,15 @@ +package client + +// Reload allows runtime reconfiguration for WithEndpoints parameter. +func (c *Client) Reload(opts ...Option) { + cfg := new(cfg) + for _, o := range opts { + o(cfg) + } + + c.cfg.endpointsLock.Lock() + + c.cfg.endpoints = cfg.endpoints + + c.cfg.endpointsLock.Unlock() +}