157
}
158
160
>
if err != nil {
161
return cacheEntry[C]{}, err
162
}
163
165
}
166
167
>
func (r *CachingRedirector[C]) cacheAddLocked(shardID int32, addr rpcAddress) cacheEntry[C] {
caching_redirector.go
168
>
// New history instances might reuse the address of a previously live history
169
>
// instance. Since we don't currently close GRPC connections when they become
170
>
// unused or idle, we might have a GRPC connection that has gone into its
171
>
// connection backoff state, due to the previous history instance becoming
172
>
// unreachable. A request on the GRPC connection, intended for the new history
173
>
// instance, would be delayed waiting for the next connection attempt, which
174
>
// could be many seconds.
175
>
// If we're adding a new cache entry for a shard, we take that as a hint that
176
>
// the next request should attempt to connect immediately if required. If the
177
>
// GRPC connection is not in connect backoff, this call has no effect.
178
>
connection := r.connections.getOrCreateClientConn(addr)
179
>
r.connections.resetConnectBackoff(connection)
180
>
181
>
entry := cacheEntry[C]{
182
>
shardID: shardID,
183
>
address: addr,
184
>
connection: connection,
185
>
// staleAt is left at zero; it's only set when r.staleTTL is set,
186
>
// and after a membership update informs us that this address is no
187
>
// longer the shard owner.
188
>
}
189
>
r.mu.cache[shardID] = entry
190
>
191
>
return entry
192
>
}
193
194
func (r *CachingRedirector[C]) cacheDeleteByAddress(address rpcAddress) {