@@ -196,6 +196,7 @@ static Status convertRlsServerStatus(Status status, String serverName) {
196
196
197
197
@ CheckReturnValue
198
198
private ListenableFuture <RouteLookupResponse > asyncRlsCall (RouteLookupRequest request ) {
199
+ logger .log (ChannelLogLevel .DEBUG , "Making an async call to RLS" );
199
200
final SettableFuture <RouteLookupResponse > response = SettableFuture .create ();
200
201
if (throttler .shouldThrottle ()) {
201
202
logger .log (ChannelLogLevel .DEBUG , "Request is throttled" );
@@ -224,6 +225,7 @@ public void onError(Throwable t) {
224
225
225
226
@ Override
226
227
public void onCompleted () {
228
+ logger .log (ChannelLogLevel .DEBUG , "routeLookup call completed" );
227
229
throttler .registerBackendResponse (false );
228
230
}
229
231
});
@@ -237,10 +239,13 @@ public void onCompleted() {
237
239
*/
238
240
@ CheckReturnValue
239
241
final CachedRouteLookupResponse get (final RouteLookupRequest request ) {
242
+ logger .log (ChannelLogLevel .DEBUG , "Acquiring lock to get cached entry" );
240
243
synchronized (lock ) {
244
+ logger .log (ChannelLogLevel .DEBUG , "Acquired lock to get cached entry" );
241
245
final CacheEntry cacheEntry ;
242
246
cacheEntry = linkedHashLruCache .read (request );
243
247
if (cacheEntry == null ) {
248
+ logger .log (ChannelLogLevel .DEBUG , "No cache entry found, making a new lrs request" );
244
249
return handleNewRequest (request );
245
250
}
246
251
@@ -249,10 +254,12 @@ final CachedRouteLookupResponse get(final RouteLookupRequest request) {
249
254
logger .log (ChannelLogLevel .DEBUG , "Cache hit for the request" );
250
255
DataCacheEntry dataEntry = ((DataCacheEntry ) cacheEntry );
251
256
if (dataEntry .isStaled (ticker .read ())) {
257
+ logger .log (ChannelLogLevel .DEBUG , "Cache entry is stale" );
252
258
dataEntry .maybeRefresh ();
253
259
}
254
260
return CachedRouteLookupResponse .dataEntry ((DataCacheEntry ) cacheEntry );
255
261
}
262
+ logger .log (ChannelLogLevel .DEBUG , "Cache hit for a backup entry" );
256
263
return CachedRouteLookupResponse .backoffEntry ((BackoffCacheEntry ) cacheEntry );
257
264
}
258
265
}
@@ -582,22 +589,31 @@ final class DataCacheEntry extends CacheEntry {
582
589
* </pre>
583
590
*/
584
591
void maybeRefresh () {
592
+ logger .log (ChannelLogLevel .DEBUG , "Acquiring lock to maybe refresh cache entry" );
585
593
synchronized (lock ) {
594
+ logger .log (ChannelLogLevel .DEBUG , "Lock to maybe refresh cache entry acquired" );
586
595
if (pendingCallCache .containsKey (request )) {
587
596
// pending already requested
597
+ logger .log (ChannelLogLevel .DEBUG ,
598
+ "A pending refresh request already created, no need to proceed with refresh" );
588
599
return ;
589
600
}
590
601
final ListenableFuture <RouteLookupResponse > asyncCall = asyncRlsCall (request );
591
602
if (!asyncCall .isDone ()) {
603
+ logger .log (ChannelLogLevel .DEBUG ,
604
+ "Async call to rls not yet complete, adding a pending cache entry" );
592
605
pendingCallCache .put (request , new PendingCacheEntry (request , asyncCall ));
593
606
} else {
594
607
// async call returned finished future is most likely throttled
595
608
try {
609
+ logger .log (ChannelLogLevel .DEBUG , "Waiting for RLS call to return" );
596
610
RouteLookupResponse response = asyncCall .get ();
611
+ logger .log (ChannelLogLevel .DEBUG , "RLS call to returned" );
597
612
linkedHashLruCache .cacheAndClean (request , new DataCacheEntry (request , response ));
598
613
} catch (InterruptedException e ) {
599
614
Thread .currentThread ().interrupt ();
600
615
} catch (Exception e ) {
616
+ logger .log (ChannelLogLevel .DEBUG , "RLS call failed, adding a backoff entry" , e );
601
617
BackoffCacheEntry backoffEntry =
602
618
new BackoffCacheEntry (request , Status .fromThrowable (e ), backoffProvider .get ());
603
619
linkedHashLruCache .cacheAndClean (request , backoffEntry );
@@ -710,33 +726,46 @@ public void run() {
710
726
delayNanos ,
711
727
TimeUnit .NANOSECONDS ,
712
728
scheduledExecutorService );
729
+ logger .log (ChannelLogLevel .DEBUG , "BackoffCacheEntry created with a delay of {0} nanos" ,
730
+ delayNanos );
713
731
}
714
732
715
733
/** Forcefully refreshes cache entry by ignoring the backoff timer. */
716
734
void forceRefresh () {
735
+ logger .log (ChannelLogLevel .DEBUG , "Forcefully refreshing cache entry" );
717
736
if (scheduledHandle .isPending ()) {
718
737
scheduledHandle .cancel ();
719
738
transitionToPending ();
720
739
}
721
740
}
722
741
723
742
private void transitionToPending () {
743
+ logger .log (ChannelLogLevel .DEBUG , "Acquiring lock to transition to pending" );
724
744
synchronized (lock ) {
745
+ logger .log (ChannelLogLevel .DEBUG , "Acquired lock to transition to pending" );
725
746
if (shutdown ) {
747
+ logger .log (ChannelLogLevel .DEBUG , "Already shut down, not transitioning to pending" );
726
748
return ;
727
749
}
750
+ logger .log (ChannelLogLevel .DEBUG , "Calling RLS for transition to pending" );
728
751
ListenableFuture <RouteLookupResponse > call = asyncRlsCall (request );
729
752
if (!call .isDone ()) {
753
+ logger .log (ChannelLogLevel .DEBUG ,
754
+ "Transition to pending RLS call not done, adding a pending cache entry" );
730
755
PendingCacheEntry pendingEntry = new PendingCacheEntry (request , call , backoffPolicy );
731
756
pendingCallCache .put (request , pendingEntry );
732
757
linkedHashLruCache .invalidate (request );
733
758
} else {
734
759
try {
760
+ logger .log (ChannelLogLevel .DEBUG ,
761
+ "Waiting for transition to pending RLS call response" );
735
762
RouteLookupResponse response = call .get ();
736
763
linkedHashLruCache .cacheAndClean (request , new DataCacheEntry (request , response ));
737
764
} catch (InterruptedException e ) {
738
765
Thread .currentThread ().interrupt ();
739
766
} catch (Exception e ) {
767
+ logger .log (ChannelLogLevel .DEBUG ,
768
+ "Transition to pending RLS call failed, creating a backoff entry" , e );
740
769
linkedHashLruCache .cacheAndClean (
741
770
request ,
742
771
new BackoffCacheEntry (request , Status .fromThrowable (e ), backoffPolicy ));
@@ -939,9 +968,13 @@ private final class BackoffRefreshListener implements ChildLbStatusListener {
939
968
940
969
@ Override
941
970
public void onStatusChanged (ConnectivityState newState ) {
971
+ logger .log (ChannelLogLevel .DEBUG , "LB status changed to: {0}" , newState );
942
972
if (prevState == ConnectivityState .TRANSIENT_FAILURE
943
973
&& newState == ConnectivityState .READY ) {
974
+ logger .log (ChannelLogLevel .DEBUG , "Transitioning from TRANSIENT_FAILURE to READY" );
975
+ logger .log (ChannelLogLevel .DEBUG , "Acquiring lock force refresh backoff cache entries" );
944
976
synchronized (lock ) {
977
+ logger .log (ChannelLogLevel .DEBUG , "Lock acquired for refreshing backoff cache entries" );
945
978
for (CacheEntry value : linkedHashLruCache .values ()) {
946
979
if (value instanceof BackoffCacheEntry ) {
947
980
((BackoffCacheEntry ) value ).forceRefresh ();
@@ -978,29 +1011,40 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
978
1011
new Object []{serviceName , methodName , args .getHeaders (), response });
979
1012
980
1013
if (response .getHeaderData () != null && !response .getHeaderData ().isEmpty ()) {
1014
+ logger .log (ChannelLogLevel .DEBUG , "Updating LRS metadata from the LRS response headers" );
981
1015
Metadata headers = args .getHeaders ();
982
1016
headers .discardAll (RLS_DATA_KEY );
983
1017
headers .put (RLS_DATA_KEY , response .getHeaderData ());
984
1018
}
985
1019
String defaultTarget = lbPolicyConfig .getRouteLookupConfig ().defaultTarget ();
1020
+ logger .log (ChannelLogLevel .DEBUG , "defaultTarget = {0}" , defaultTarget );
986
1021
boolean hasFallback = defaultTarget != null && !defaultTarget .isEmpty ();
987
1022
if (response .hasData ()) {
1023
+ logger .log (ChannelLogLevel .DEBUG , "LRS response has data, proceed with selecting a picker" );
988
1024
ChildPolicyWrapper childPolicyWrapper = response .getChildPolicyWrapper ();
989
1025
SubchannelPicker picker =
990
1026
(childPolicyWrapper != null ) ? childPolicyWrapper .getPicker () : null ;
991
1027
if (picker == null ) {
1028
+ logger .log (ChannelLogLevel .DEBUG ,
1029
+ "Child policy wrapper didn't return a picker, returning PickResult with no results" );
992
1030
return PickResult .withNoResult ();
993
1031
}
994
1032
// Happy path
1033
+ logger .log (ChannelLogLevel .DEBUG , "Returning PickResult" );
995
1034
return picker .pickSubchannel (args );
996
1035
} else if (response .hasError ()) {
1036
+ logger .log (ChannelLogLevel .DEBUG , "RLS response has errors" );
997
1037
if (hasFallback ) {
1038
+ logger .log (ChannelLogLevel .DEBUG , "Using RLS fallback" );
998
1039
return useFallback (args );
999
1040
}
1041
+ logger .log (ChannelLogLevel .DEBUG , "No RLS fallback, returning PickResult with an error" );
1000
1042
return PickResult .withError (
1001
1043
convertRlsServerStatus (response .getStatus (),
1002
1044
lbPolicyConfig .getRouteLookupConfig ().lookupService ()));
1003
1045
} else {
1046
+ logger .log (ChannelLogLevel .DEBUG ,
1047
+ "RLS response had no data, return a PickResult with no data" );
1004
1048
return PickResult .withNoResult ();
1005
1049
}
1006
1050
}
@@ -1021,7 +1065,9 @@ private PickResult useFallback(PickSubchannelArgs args) {
1021
1065
private void startFallbackChildPolicy () {
1022
1066
String defaultTarget = lbPolicyConfig .getRouteLookupConfig ().defaultTarget ();
1023
1067
logger .log (ChannelLogLevel .DEBUG , "starting fallback to {0}" , defaultTarget );
1068
+ logger .log (ChannelLogLevel .DEBUG , "Acquiring lock to start fallback child policy" );
1024
1069
synchronized (lock ) {
1070
+ logger .log (ChannelLogLevel .DEBUG , "Acquired lock for starting fallback child policy" );
1025
1071
if (fallbackChildPolicyWrapper != null ) {
1026
1072
return ;
1027
1073
}
@@ -1031,6 +1077,7 @@ private void startFallbackChildPolicy() {
1031
1077
1032
1078
// GuardedBy CachingRlsLbClient.lock
1033
1079
void close () {
1080
+ logger .log (ChannelLogLevel .DEBUG , "Closing RLS picker" );
1034
1081
if (fallbackChildPolicyWrapper != null ) {
1035
1082
refCountedChildPolicyWrapperFactory .release (fallbackChildPolicyWrapper );
1036
1083
}
0 commit comments