Package io.grpc.rls
Class CachingRlsLbClient
- java.lang.Object
-
- io.grpc.rls.CachingRlsLbClient
-
@ThreadSafe final class CachingRlsLbClient extends java.lang.Object
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
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description private
CachingRlsLbClient(CachingRlsLbClient.Builder builder)
-
Method Summary
-
-
-
Field Detail
-
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:
- Constant Field Values
-
STRING_OVERHEAD_BYTES
public static final int STRING_OVERHEAD_BYTES
- See Also:
- Constant Field Values
-
OBJ_OVERHEAD_B
public static final int OBJ_OVERHEAD_B
Minimum bytes for a Java Object.- See Also:
- Constant Field Values
-
DEFAULT_TARGET_PICKS_COUNTER
private static final LongCounterMetricInstrument DEFAULT_TARGET_PICKS_COUNTER
-
TARGET_PICKS_COUNTER
private static final LongCounterMetricInstrument TARGET_PICKS_COUNTER
-
FAILED_PICKS_COUNTER
private static final LongCounterMetricInstrument FAILED_PICKS_COUNTER
-
CACHE_ENTRIES_GAUGE
private static final LongGaugeMetricInstrument CACHE_ENTRIES_GAUGE
-
CACHE_SIZE_GAUGE
private static final LongGaugeMetricInstrument CACHE_SIZE_GAUGE
-
gaugeRegistration
private final MetricRecorder.Registration gaugeRegistration
-
metricsInstanceUuid
private final java.lang.String metricsInstanceUuid
-
lock
private final java.lang.Object lock
-
linkedHashLruCache
private final CachingRlsLbClient.RlsAsyncLruCache linkedHashLruCache
-
periodicCleaner
private final java.util.concurrent.Future<?> periodicCleaner
-
pendingCallCache
private final java.util.Map<RlsProtoData.RouteLookupRequest,CachingRlsLbClient.PendingCacheEntry> pendingCallCache
-
scheduledExecutorService
private final java.util.concurrent.ScheduledExecutorService scheduledExecutorService
-
ticker
private final com.google.common.base.Ticker ticker
-
throttler
private final Throttler throttler
-
lbPolicyConfig
private final LbPolicyConfiguration lbPolicyConfig
-
backoffProvider
private final BackoffPolicy.Provider backoffProvider
-
maxAgeNanos
private final long maxAgeNanos
-
staleAgeNanos
private final long staleAgeNanos
-
callTimeoutNanos
private final long callTimeoutNanos
-
helper
private final CachingRlsLbClient.RlsLbHelper helper
-
rlsChannel
private final ManagedChannel rlsChannel
-
rlsStub
private final RouteLookupServiceGrpc.RouteLookupServiceStub rlsStub
-
rlsPicker
private final CachingRlsLbClient.RlsPicker rlsPicker
-
childLbResolvedAddressFactory
private final ResolvedAddressFactory childLbResolvedAddressFactory
-
refCountedChildPolicyWrapperFactory
private final LbPolicyConfiguration.RefCountedChildPolicyWrapperFactory refCountedChildPolicyWrapperFactory
-
logger
private final ChannelLogger logger
-
RLS_DATA_KEY
static final Metadata.Key<java.lang.String> RLS_DATA_KEY
A header will be added when RLS server respond with additional header data.
-
-
Constructor Detail
-
CachingRlsLbClient
private CachingRlsLbClient(CachingRlsLbClient.Builder builder)
-
-
Method Detail
-
init
void init()
-
convertRlsServerStatus
static Status convertRlsServerStatus(Status status, java.lang.String serverName)
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
private void pendingRpcComplete(CachingRlsLbClient.PendingCacheEntry entry)
-
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
private void refreshBackoffEntry(CachingRlsLbClient.BackoffCacheEntry entry)
-
newBuilder
static CachingRlsLbClient.Builder newBuilder()
Returns a Builder forCachingRlsLbClient
.
-
-