forked from TrueCloudLab/frostfs-node
[#694] pkg/network: Use single function to get or create client instance
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
2c02261709
commit
aed76f6b5a
1 changed files with 6 additions and 11 deletions
17
pkg/network/cache/multi.go
vendored
17
pkg/network/cache/multi.go
vendored
|
@ -61,18 +61,9 @@ func (x *multiClient) iterateClients(f func(client.Client) error) error {
|
||||||
var firstErr error
|
var firstErr error
|
||||||
|
|
||||||
x.addr.IterateAddresses(func(addr network.Address) bool {
|
x.addr.IterateAddresses(func(addr network.Address) bool {
|
||||||
x.mtx.Lock()
|
|
||||||
|
|
||||||
strAddr := addr.String()
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
c, cached := x.clients[strAddr]
|
c := x.client(addr)
|
||||||
if !cached {
|
|
||||||
c = x.createForAddress(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
x.mtx.Unlock()
|
|
||||||
|
|
||||||
err = f(c)
|
err = f(c)
|
||||||
|
|
||||||
|
@ -322,6 +313,10 @@ func (x *multiClient) Close() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *multiClient) RawForAddress(addr network.Address) *rawclient.Client {
|
func (x *multiClient) RawForAddress(addr network.Address) *rawclient.Client {
|
||||||
|
return x.client(addr).Raw()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *multiClient) client(addr network.Address) client.Client {
|
||||||
x.mtx.Lock()
|
x.mtx.Lock()
|
||||||
|
|
||||||
strAddr := addr.String()
|
strAddr := addr.String()
|
||||||
|
@ -333,5 +328,5 @@ func (x *multiClient) RawForAddress(addr network.Address) *rawclient.Client {
|
||||||
|
|
||||||
x.mtx.Unlock()
|
x.mtx.Unlock()
|
||||||
|
|
||||||
return c.Raw()
|
return c
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue