-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
morph: support reloading morph endpoints with SIGHUP
Add a new function `Client.Reload` that passes the `WithEndpoints` option and closes the client if there is no endpoint in the config to which the client is connected. Add docs. Closes #1871. Signed-off-by: Andrey Butusov <[email protected]>
- Loading branch information
Showing
7 changed files
with
54 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package client | ||
|
||
import "slices" | ||
|
||
// Reload allows runtime reconfiguration for WithEndpoints parameter. | ||
func (c *Client) Reload(opts ...Option) { | ||
cfg := new(cfg) | ||
for _, o := range opts { | ||
o(cfg) | ||
} | ||
|
||
c.endpointsLock.Lock() | ||
|
||
c.cfg.endpoints = cfg.endpoints | ||
c.endpoints = cfg.endpoints | ||
|
||
c.endpointsLock.Unlock() | ||
|
||
var conn = c.conn.Load() | ||
if conn == nil { | ||
return | ||
} | ||
currentEndpoint := conn.client.Endpoint() | ||
|
||
// RPC reconnections are costly for node, so we avoid them | ||
// by using the current connection while it's alive | ||
// if the current endpoint is present in the config | ||
if !slices.Contains(cfg.endpoints, currentEndpoint) { | ||
conn.client.Close() | ||
} | ||
} |