forked from TrueCloudLab/frostfs-node
[#1213] morph/client: Use a separate cache for every client
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
61f60b8461
commit
a8d2001b35
2 changed files with 8 additions and 10 deletions
|
@ -84,7 +84,7 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error)
|
||||||
|
|
||||||
if cfg.singleCli != nil {
|
if cfg.singleCli != nil {
|
||||||
return &Client{
|
return &Client{
|
||||||
cache: initClientCache(),
|
cache: newClientCache(),
|
||||||
singleClient: blankSingleClient(cfg.singleCli, wallet.NewAccountFromPrivateKey(key), cfg),
|
singleClient: blankSingleClient(cfg.singleCli, wallet.NewAccountFromPrivateKey(key), cfg),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -92,17 +92,17 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error)
|
||||||
endpoints := append(cfg.extraEndpoints, endpoint)
|
endpoints := append(cfg.extraEndpoints, endpoint)
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
|
cache: newClientCache(),
|
||||||
multiClient: &multiClient{
|
multiClient: &multiClient{
|
||||||
cfg: *cfg,
|
cfg: *cfg,
|
||||||
account: wallet.NewAccountFromPrivateKey(key),
|
account: wallet.NewAccountFromPrivateKey(key),
|
||||||
endpoints: endpoints,
|
endpoints: endpoints,
|
||||||
clients: make(map[string]*Client, len(endpoints)),
|
clients: make(map[string]*Client, len(endpoints)),
|
||||||
sharedCache: initClientCache(),
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func initClientCache() cache {
|
func newClientCache() cache {
|
||||||
c, _ := lru.New(100) // returns error only if size is negative
|
c, _ := lru.New(100) // returns error only if size is negative
|
||||||
return cache{
|
return cache{
|
||||||
txHeights: c,
|
txHeights: c,
|
||||||
|
|
|
@ -15,8 +15,6 @@ type multiClient struct {
|
||||||
|
|
||||||
sharedNotary *notary // notary config needed for single client construction
|
sharedNotary *notary // notary config needed for single client construction
|
||||||
|
|
||||||
sharedCache cache
|
|
||||||
|
|
||||||
endpoints []string
|
endpoints []string
|
||||||
clientsMtx sync.Mutex
|
clientsMtx sync.Mutex
|
||||||
clients map[string]*Client
|
clients map[string]*Client
|
||||||
|
@ -48,7 +46,7 @@ func (x *multiClient) createForAddress(addr string) (*Client, error) {
|
||||||
sCli.notary = x.sharedNotary
|
sCli.notary = x.sharedNotary
|
||||||
|
|
||||||
c = &Client{
|
c = &Client{
|
||||||
cache: x.sharedCache,
|
cache: newClientCache(),
|
||||||
singleClient: sCli,
|
singleClient: sCli,
|
||||||
}
|
}
|
||||||
x.clients[addr] = c
|
x.clients[addr] = c
|
||||||
|
|
Loading…
Reference in a new issue