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 class
When anyCachingRlsLbClient.CacheEntry
is evicted fromLruCache
, it performsCachingRlsLbClient.CacheEntry.cleanup()
after originalLruCache.EvictionListener
is finished.private static final class
Implementation ofCachingRlsLbClient.CacheEntry
contains error.private final class
LbStatusListener refreshesCachingRlsLbClient.BackoffCacheEntry
when lb state is changed toConnectivityState.READY
fromConnectivityState.TRANSIENT_FAILURE
.(package private) static final class
A Builder forCachingRlsLbClient
.(package private) static final class
Viewer class for cachedRlsProtoData.RouteLookupResponse
and associatedLbPolicyConfiguration.ChildPolicyWrapper
.(package private) static class
Common cache entry data forCachingRlsLbClient.RlsAsyncLruCache
.(package private) final class
Implementation ofCachingRlsLbClient.CacheEntry
contains valid data.private static final class
A Throttler never throttles.(package private) static final class
A pending cache entry when the async RouteLookup RPC is still on the fly.private static final class
Implementation ofLinkedHashLruCache
for RLS.private static final class
(package private) final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BackoffPolicy.Provider
static final int
private static final LongGaugeMetricInstrument
private static final LongGaugeMetricInstrument
private final long
private final ResolvedAddressFactory
private static final LongCounterMetricInstrument
private static final LongCounterMetricInstrument
private final MetricRecorder.Registration
private final CachingRlsLbClient.RlsLbHelper
private final LbPolicyConfiguration
private final CachingRlsLbClient.RlsAsyncLruCache
private final Object
private final ChannelLogger
private final long
private final String
static final long
static final int
Minimum 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 ManagedChannel
private final CachingRlsLbClient.RlsPicker
private final RouteLookupServiceGrpc.RouteLookupServiceStub
private final ScheduledExecutorService
private final long
static final int
private static final LongCounterMetricInstrument
private final Throttler
private 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) void
close()
Performs any pending maintenance operations needed by the cache.(package private) static Status
convertRlsServerStatus
(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.CachedRouteLookupResponse
get
(RlsProtoData.RouteLookupRequest request) Returns async response of therequest
.(package private) void
init()
(package private) static CachingRlsLbClient.Builder
Returns a Builder forCachingRlsLbClient
.private void
private void
private 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
.
-