1717
1818import com .google .api .core .InternalApi ;
1919import com .google .api .gax .grpc .ChannelFactory ;
20+ import com .google .bigtable .v2 .PeerInfo ;
21+ import com .google .cloud .bigtable .data .v2 .stub .MetadataExtractorInterceptor ;
2022import com .google .cloud .bigtable .gaxx .grpc .ChannelPoolHealthChecker .ProbeResult ;
2123import com .google .common .annotations .VisibleForTesting ;
2224import com .google .common .base .Preconditions ;
3436import java .time .Clock ;
3537import java .util .ArrayList ;
3638import java .util .List ;
39+ import java .util .Optional ;
3740import java .util .Random ;
3841import java .util .concurrent .CancellationException ;
3942import java .util .concurrent .ConcurrentLinkedQueue ;
@@ -543,9 +546,8 @@ static class Entry implements BigtableChannelObserver {
543546 * outstanding RPCs has to happen when the ClientCall is closed or the ClientCall failed to
544547 * start.
545548 */
546- @ VisibleForTesting final AtomicReference <Boolean > isAltsHolder = new AtomicReference <>(null );
547-
548549 @ VisibleForTesting final AtomicInteger errorCount = new AtomicInteger (0 );
550+
549551 @ VisibleForTesting final AtomicInteger successCount = new AtomicInteger (0 );
550552 @ VisibleForTesting final AtomicInteger outstandingUnaryRpcs = new AtomicInteger (0 );
551553
@@ -554,6 +556,10 @@ static class Entry implements BigtableChannelObserver {
554556 private final AtomicInteger maxOutstandingUnaryRpcs = new AtomicInteger ();
555557 private final AtomicInteger maxOutstandingStreamingRpcs = new AtomicInteger ();
556558
559+ /** this contains the PeerInfo field of the most recent rpc on this channel entry. */
560+ @ VisibleForTesting
561+ volatile PeerInfo .TransportType transportType = PeerInfo .TransportType .TRANSPORT_TYPE_UNKNOWN ;
562+
557563 /** Queue storing the last 5 minutes of probe results */
558564 @ VisibleForTesting
559565 final ConcurrentLinkedQueue <ProbeResult > probeHistory = new ConcurrentLinkedQueue <>();
@@ -576,10 +582,18 @@ static class Entry implements BigtableChannelObserver {
576582 this .channel = channel ;
577583 }
578584
579- void checkAndSetIsAlts (ClientCall <?, ?> call ) {
580- // TODO(populate ALTS holder)
581- boolean result = false ;
582- isAltsHolder .compareAndSet (null , result );
585+ void setTransportType (CallOptions callOptions ) {
586+ MetadataExtractorInterceptor .SidebandData sidebandData =
587+ MetadataExtractorInterceptor .SidebandData .from (callOptions );
588+
589+ // Set to the specific transport type if present, otherwise default to UNKNOWN
590+ // we could check the Status and set it to unknown, but we might have PeerInfo with some non
591+ // OK Status
592+ transportType =
593+ Optional .ofNullable (sidebandData )
594+ .map (MetadataExtractorInterceptor .SidebandData ::getPeerInfo )
595+ .map (PeerInfo ::getTransportType )
596+ .orElse (PeerInfo .TransportType .TRANSPORT_TYPE_UNKNOWN );
583597 }
584598
585599 ManagedChannel getManagedChannel () {
@@ -683,9 +697,8 @@ public long getAndResetSuccessCount() {
683697 }
684698
685699 @ Override
686- public boolean isAltsChannel () {
687- Boolean val = isAltsHolder .get ();
688- return val != null && val ;
700+ public PeerInfo .TransportType getTransportType () {
701+ return transportType ;
689702 }
690703
691704 void incrementErrorCount () {
@@ -717,7 +730,7 @@ public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
717730 methodDescriptor .getType () == MethodDescriptor .MethodType .SERVER_STREAMING ;
718731 Entry entry = getRetainedEntry (index , isStreaming );
719732 return new ReleasingClientCall <>(
720- entry .channel .newCall (methodDescriptor , callOptions ), entry , isStreaming );
733+ entry .channel .newCall (methodDescriptor , callOptions ), entry , isStreaming , callOptions );
721734 }
722735 }
723736
@@ -726,13 +739,19 @@ static class ReleasingClientCall<ReqT, RespT> extends SimpleForwardingClientCall
726739 @ Nullable private CancellationException cancellationException ;
727740 final Entry entry ;
728741 private final boolean isStreaming ;
742+ private final CallOptions callOptions ;
729743 private final AtomicBoolean wasClosed = new AtomicBoolean ();
730744 private final AtomicBoolean wasReleased = new AtomicBoolean ();
731745
732- public ReleasingClientCall (ClientCall <ReqT , RespT > delegate , Entry entry , boolean isStreaming ) {
746+ public ReleasingClientCall (
747+ ClientCall <ReqT , RespT > delegate ,
748+ Entry entry ,
749+ boolean isStreaming ,
750+ CallOptions callOptions ) {
733751 super (delegate );
734752 this .entry = entry ;
735753 this .isStreaming = isStreaming ;
754+ this .callOptions = callOptions ;
736755 }
737756
738757 @ Override
@@ -741,10 +760,14 @@ public void start(Listener<RespT> responseListener, Metadata headers) {
741760 throw new IllegalStateException ("Call is already cancelled" , cancellationException );
742761 }
743762 try {
744- entry .checkAndSetIsAlts (delegate ());
745-
746763 super .start (
747764 new SimpleForwardingClientCallListener <RespT >(responseListener ) {
765+ @ Override
766+ public void onHeaders (Metadata headers ) {
767+ super .onHeaders (headers );
768+ entry .setTransportType (callOptions );
769+ }
770+
748771 @ Override
749772 public void onClose (Status status , Metadata trailers ) {
750773 if (!wasClosed .compareAndSet (false , true )) {
0 commit comments