public class SnapshotCollectingCallback<T> extends Object implements DiscoveryServerCallbacks
Snapshots from the cache that are no longer referenced by any streams.
Works by monitoring the stream to determine what group they belong to and keeps a running count as well as when a request is seen that targets a given node group.
Every collectionIntervalMillis milliseconds a cleanup job runs which looks for snapshots with no
active streams that haven't been updated within the configured time frame. Checking the time since last update
is done to prevent snapshots from being prematurely removed from the cache. It ensures that a group must have
no active streams for collectAfterMillis milliseconds before being collected.
To be notified of snapshots that are removed, a set of callbacks may be provided which will be triggered whenever a snapshot is removed from the cache. Any other callback which maintains state about the snapshots that is cleaned up by one of these callbacks should be run *after* this callback. This helps ensure that if state is cleaned up while a request in inbound, the request will be blocked by the lock in this callback until collection finishes and the subsequent callbacks will see the new request come in after collection. If the order is reversed, another callback might have seen the new request but the refcount here hasn't been incremented, causing it to get cleaned up and wipe the state of the other callback even though we now have an active stream for that group.
| Constructor and Description |
|---|
SnapshotCollectingCallback(SnapshotCache<T> snapshotCache,
NodeGroup<T> nodeGroup,
Clock clock,
Set<Consumer<T>> collectorCallbacks,
long collectAfterMillis,
long collectionIntervalMillis)
Creates the callback.
|
| Modifier and Type | Method and Description |
|---|---|
void |
onStreamClose(long streamId,
String typeUrl)
onStreamClose is called just before the bi-directional gRPC stream is closed successfully for an envoy
instance. |
void |
onStreamCloseWithError(long streamId,
String typeUrl,
Throwable error)
onStreamCloseWithError is called just before the bi-directional gRPC stream is closed for an envoy instance
due to some error that has occurred. |
void |
onStreamRequest(long streamId,
envoy.api.v2.Discovery.DiscoveryRequest request)
onStreamRequest is called for each Discovery.DiscoveryRequest that is received on the stream. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonStreamOpen, onStreamResponsepublic SnapshotCollectingCallback(SnapshotCache<T> snapshotCache, NodeGroup<T> nodeGroup, Clock clock, Set<Consumer<T>> collectorCallbacks, long collectAfterMillis, long collectionIntervalMillis)
snapshotCache - the cache to evict snapshots fromnodeGroup - the node group used to map requests to groupsclock - system clockcollectorCallbacks - the callbacks to invoke when snapshot is collectedcollectAfterMillis - how long a snapshot must be referenced for before being collectedcollectionIntervalMillis - how often the collection background action should runpublic void onStreamRequest(long streamId,
envoy.api.v2.Discovery.DiscoveryRequest request)
DiscoveryServerCallbacksonStreamRequest is called for each Discovery.DiscoveryRequest that is received on the stream.onStreamRequest in interface DiscoveryServerCallbacksstreamId - an ID for this stream that is only unique to this discovery server instancerequest - the discovery request sent by the envoy instancepublic void onStreamClose(long streamId,
String typeUrl)
DiscoveryServerCallbacksonStreamClose is called just before the bi-directional gRPC stream is closed successfully for an envoy
instance.onStreamClose in interface DiscoveryServerCallbacksstreamId - an ID for this stream that is only unique to this discovery server instancetypeUrl - the resource type of the stream, or DiscoveryServer.ANY_TYPE_URL for ADSpublic void onStreamCloseWithError(long streamId,
String typeUrl,
Throwable error)
DiscoveryServerCallbacksonStreamCloseWithError is called just before the bi-directional gRPC stream is closed for an envoy instance
due to some error that has occurred.onStreamCloseWithError in interface DiscoveryServerCallbacksstreamId - an ID for this stream that is only unique to this discovery server instancetypeUrl - the resource type of the stream, or DiscoveryServer.ANY_TYPE_URL for ADSerror - the error that caused the stream to closeCopyright © 2018 The Envoy Project. All rights reserved.