forked from TrueCloudLab/frostfs-node
[#2048] network/cache: Optimize ClientCache
1. Remove a layer of indirection for mutex, `ClientCache` is already used by pointer. 2. Fix duplication of a `AllowExternal` field. Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
597ed18269
commit
659011c143
1 changed files with 6 additions and 9 deletions
15
pkg/network/cache/client.go
vendored
15
pkg/network/cache/client.go
vendored
|
@ -13,10 +13,9 @@ type (
|
||||||
// ClientCache is a structure around neofs-sdk-go/client to reuse
|
// ClientCache is a structure around neofs-sdk-go/client to reuse
|
||||||
// already created clients.
|
// already created clients.
|
||||||
ClientCache struct {
|
ClientCache struct {
|
||||||
mu *sync.RWMutex
|
mu sync.RWMutex
|
||||||
clients map[string]*multiClient
|
clients map[string]*multiClient
|
||||||
opts ClientCacheOpts
|
opts ClientCacheOpts
|
||||||
allowExternal bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientCacheOpts struct {
|
ClientCacheOpts struct {
|
||||||
|
@ -32,17 +31,15 @@ type (
|
||||||
// `opts` are used for new client creation.
|
// `opts` are used for new client creation.
|
||||||
func NewSDKClientCache(opts ClientCacheOpts) *ClientCache {
|
func NewSDKClientCache(opts ClientCacheOpts) *ClientCache {
|
||||||
return &ClientCache{
|
return &ClientCache{
|
||||||
mu: new(sync.RWMutex),
|
clients: make(map[string]*multiClient),
|
||||||
clients: make(map[string]*multiClient),
|
opts: opts,
|
||||||
opts: opts,
|
|
||||||
allowExternal: opts.AllowExternal,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get function returns existing client or creates a new one.
|
// Get function returns existing client or creates a new one.
|
||||||
func (c *ClientCache) Get(info clientcore.NodeInfo) (clientcore.Client, error) {
|
func (c *ClientCache) Get(info clientcore.NodeInfo) (clientcore.Client, error) {
|
||||||
netAddr := info.AddressGroup()
|
netAddr := info.AddressGroup()
|
||||||
if c.allowExternal {
|
if c.opts.AllowExternal {
|
||||||
netAddr = append(netAddr, info.ExternalAddressGroup()...)
|
netAddr = append(netAddr, info.ExternalAddressGroup()...)
|
||||||
}
|
}
|
||||||
cacheKey := string(info.PublicKey())
|
cacheKey := string(info.PublicKey())
|
||||||
|
|
Loading…
Reference in a new issue