GetClientForInstance gets the client for the specified ring member. If it does not exist it will make a new client for that instance.
(inst ring.InstanceDesc)
| 138 | // GetClientForInstance gets the client for the specified ring member. If it does not exist |
| 139 | // it will make a new client for that instance. |
| 140 | func (p *Pool) GetClientForInstance(inst ring.InstanceDesc) (PoolClient, error) { |
| 141 | member, ok := p.fromCache(inst.Addr) |
| 142 | if ok { |
| 143 | return member.client, nil |
| 144 | } |
| 145 | |
| 146 | // No client in cache so create one |
| 147 | p.Lock() |
| 148 | defer p.Unlock() |
| 149 | |
| 150 | // Check if a client has been created just after checking the cache and before acquiring the lock. |
| 151 | member, ok = p.members[inst.Addr] |
| 152 | if ok { |
| 153 | return member.client, nil |
| 154 | } |
| 155 | |
| 156 | client, err := p.factory.FromInstance(inst) |
| 157 | if err != nil { |
| 158 | return nil, err |
| 159 | } |
| 160 | p.members[inst.Addr] = &poolMember{client: client} |
| 161 | if p.clientsMetric != nil { |
| 162 | p.clientsMetric.Add(1) |
| 163 | } |
| 164 | return client, nil |
| 165 | } |
| 166 | |
| 167 | // RemoveClientFor removes the client with the specified address |
| 168 | func (p *Pool) RemoveClientFor(addr string) { |
no test coverage detected