Package io.grpc.rls
Class CachingRlsLbClient
java.lang.Object
io.grpc.rls.CachingRlsLbClient
A CachingRlsLbClient is a core implementation of RLS loadbalancer supports dynamic request
routing by fetching the decision from route lookup server. Every single request is routed by
the server's decision. To reduce the performance penalty,
LruCache is used.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classWhen anyCachingRlsLbClient.CacheEntryis evicted fromLruCache, it performsCachingRlsLbClient.CacheEntry.cleanup()after originalLruCache.EvictionListeneris finished.private static final classImplementation ofCachingRlsLbClient.CacheEntrycontains error.private final classLbStatusListener refreshesCachingRlsLbClient.BackoffCacheEntrywhen lb state is changed toConnectivityState.READYfromConnectivityState.TRANSIENT_FAILURE.(package private) static final classA Builder forCachingRlsLbClient.(package private) static final classViewer class for cachedRlsProtoData.RouteLookupResponseand associatedLbPolicyConfiguration.ChildPolicyWrapper.(package private) static classCommon cache entry data forCachingRlsLbClient.RlsAsyncLruCache.(package private) final classImplementation ofCachingRlsLbClient.CacheEntrycontains valid data.private static final classA Throttler never throttles.(package private) static final classA pending cache entry when the async RouteLookup RPC is still on the fly.private static final classImplementation ofLinkedHashLruCachefor RLS.private static final class(package private) final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BackoffPolicy.Providerstatic final intprivate static final LongGaugeMetricInstrumentprivate static final LongGaugeMetricInstrumentprivate final longprivate final ResolvedAddressFactoryprivate static final LongCounterMetricInstrumentprivate static final LongCounterMetricInstrumentprivate final MetricRecorder.Registrationprivate final CachingRlsLbClient.RlsLbHelperprivate final LbPolicyConfigurationprivate final CachingRlsLbClient.RlsAsyncLruCacheprivate final Objectprivate final ChannelLoggerprivate final longprivate final Stringstatic final longstatic final intMinimum bytes for a Java Object.private final Future<?> private static final com.google.common.base.Converter<RlsProtoData.RouteLookupRequest, RouteLookupRequest> private static final com.google.common.base.Converter<RlsProtoData.RouteLookupResponse, RouteLookupResponse> (package private) static final Metadata.Key<String> A header will be added when RLS server respond with additional header data.private final ManagedChannelprivate final CachingRlsLbClient.RlsPickerprivate final RouteLookupServiceGrpc.RouteLookupServiceStubprivate final ScheduledExecutorServiceprivate final longstatic final intprivate static final LongCounterMetricInstrumentprivate final Throttlerprivate final com.google.common.base.Ticker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasyncRlsCall(RlsProtoData.RouteLookupRequest request, BackoffPolicy backoffPolicy) Populates async cache entry for new request.(package private) voidclose()Performs any pending maintenance operations needed by the cache.(package private) static StatusconvertRlsServerStatus(Status status, String serverName) Convert the status to UNAVAILABLE and enhance the error message.createBackOffEntry(RlsProtoData.RouteLookupRequest request, Status status, BackoffPolicy backoffPolicy) createDataEntry(RlsProtoData.RouteLookupRequest request, RlsProtoData.RouteLookupResponse routeLookupResponse) createPendingEntry(RlsProtoData.RouteLookupRequest request, com.google.common.util.concurrent.ListenableFuture<RlsProtoData.RouteLookupResponse> pendingCall, BackoffPolicy backoffPolicy) (package private) final CachingRlsLbClient.CachedRouteLookupResponseget(RlsProtoData.RouteLookupRequest request) Returns async response of therequest.(package private) voidinit()(package private) static CachingRlsLbClient.BuilderReturns a Builder forCachingRlsLbClient.private voidprivate voidprivate void(package private) void
-
Field Details
-
REQUEST_CONVERTER
private static final com.google.common.base.Converter<RlsProtoData.RouteLookupRequest,RouteLookupRequest> REQUEST_CONVERTER -
RESPONSE_CONVERTER
private static final com.google.common.base.Converter<RlsProtoData.RouteLookupResponse,RouteLookupResponse> RESPONSE_CONVERTER -
MIN_EVICTION_TIME_DELTA_NANOS
public static final long MIN_EVICTION_TIME_DELTA_NANOS -
BYTES_PER_CHAR
public static final int BYTES_PER_CHAR- See Also:
-
STRING_OVERHEAD_BYTES
public static final int STRING_OVERHEAD_BYTES- See Also:
-
OBJ_OVERHEAD_B
public static final int OBJ_OVERHEAD_BMinimum bytes for a Java Object.- See Also:
-
DEFAULT_TARGET_PICKS_COUNTER
-
TARGET_PICKS_COUNTER
-
FAILED_PICKS_COUNTER
-
CACHE_ENTRIES_GAUGE
-
CACHE_SIZE_GAUGE
-
gaugeRegistration
-
metricsInstanceUuid
-
lock
-
linkedHashLruCache
-
periodicCleaner
-
pendingCallCache
private final Map<RlsProtoData.RouteLookupRequest,CachingRlsLbClient.PendingCacheEntry> pendingCallCache -
scheduledExecutorService
-
ticker
private final com.google.common.base.Ticker ticker -
throttler
-
lbPolicyConfig
-
backoffProvider
-
maxAgeNanos
private final long maxAgeNanos -
staleAgeNanos
private final long staleAgeNanos -
callTimeoutNanos
private final long callTimeoutNanos -
helper
-
rlsChannel
-
rlsStub
-
rlsPicker
-
childLbResolvedAddressFactory
-
refCountedChildPolicyWrapperFactory
private final LbPolicyConfiguration.RefCountedChildPolicyWrapperFactory refCountedChildPolicyWrapperFactory -
logger
-
RLS_DATA_KEY
A header will be added when RLS server respond with additional header data.
-
-
Constructor Details
-
CachingRlsLbClient
-
-
Method Details
-
init
void init() -
convertRlsServerStatus
Convert the status to UNAVAILABLE and enhance the error message.- Parameters:
status- status as provided by serverserverName- Used for error description- Returns:
- Transformed status
-
periodicClean
private void periodicClean() -
asyncRlsCall
private CachingRlsLbClient.CachedRouteLookupResponse asyncRlsCall(RlsProtoData.RouteLookupRequest request, @Nullable BackoffPolicy backoffPolicy) Populates async cache entry for new request. -
get
@CheckReturnValue final CachingRlsLbClient.CachedRouteLookupResponse get(RlsProtoData.RouteLookupRequest request) Returns async response of therequest. The returned value can be in 3 different states; cached, pending and backed-off due to error. The result remains same even if the status is changed after the return. -
close
void close()Performs any pending maintenance operations needed by the cache. -
requestConnection
void requestConnection() -
createPendingEntry
private CachingRlsLbClient.PendingCacheEntry createPendingEntry(RlsProtoData.RouteLookupRequest request, com.google.common.util.concurrent.ListenableFuture<RlsProtoData.RouteLookupResponse> pendingCall, @Nullable BackoffPolicy backoffPolicy) -
pendingRpcComplete
-
createDataEntry
private CachingRlsLbClient.DataCacheEntry createDataEntry(RlsProtoData.RouteLookupRequest request, RlsProtoData.RouteLookupResponse routeLookupResponse) -
createBackOffEntry
private CachingRlsLbClient.BackoffCacheEntry createBackOffEntry(RlsProtoData.RouteLookupRequest request, Status status, @Nullable BackoffPolicy backoffPolicy) -
refreshBackoffEntry
-
newBuilder
Returns a Builder forCachingRlsLbClient.
-