@@ -185,12 +185,7 @@ static synchronized void initMetricInstruments() {
185185 ExternalProcessorFilterConfig getFilterConfig () {
186186 return filterConfig ;
187187 }
188-
189- @ VisibleForTesting
190- ManagedChannel getExtProcChannel () {
191- return extProcChannel ;
192- }
193-
188+
194189 @ Override
195190 @ SuppressWarnings ("unchecked" )
196191 public <ReqT , RespT > ClientCall <ReqT , RespT > interceptCall (
@@ -921,8 +916,8 @@ public void request(int numMessages) {
921916 if (normalFlowControl ) {
922917 pendingRequests .addAndGet (numMessages );
923918 downstreamRequestsPending += numMessages ;
919+ drainPendingMutatedResponseBodies ();
924920 if (isExtProcReady ()) {
925- drainPendingMutatedResponseBodies ();
926921 drainPendingRequests ();
927922 }
928923 } else {
@@ -1097,32 +1092,27 @@ private void handleRequestBodyResponse(BodyResponse bodyResponse) {
10971092 StreamedBodyResponse streamed = mutation .getStreamedResponse ();
10981093 if (!streamed .getEndOfStreamWithoutMessage ()) {
10991094 com .google .protobuf .ByteString body = streamed .getBody ();
1100- if (!config .getObservabilityMode ()
1101- && currentProcessingMode .getRequestBodyMode () == ProcessingMode .BodySendMode .GRPC ) {
1102- boolean sendImmediately = false ;
1103- synchronized (streamLock ) {
1104- if (sidestreamToUpstreamWindow <= 0 ) {
1105- internalOnError (Status .INTERNAL
1106- .withDescription (
1107- "Flow control violation: received client body from ext_proc "
1108- + "when window is closed" )
1109- .asRuntimeException ());
1110- return ;
1111- }
1112- sidestreamToUpstreamWindow -= body .size ();
1113- if (super .isReady () && pendingUpstreamBodyMessages .isEmpty ()) {
1114- sendImmediately = true ;
1115- accumulatedWindowUpdateSidestreamToUpstream += body .size ();
1116- } else {
1117- pendingUpstreamBodyMessages .add (body );
1118- }
1095+ boolean sendImmediately = false ;
1096+ synchronized (streamLock ) {
1097+ if (sidestreamToUpstreamWindow <= 0 ) {
1098+ internalOnError (Status .INTERNAL
1099+ .withDescription (
1100+ "Flow control violation: received client body from ext_proc "
1101+ + "when window is closed" )
1102+ .asRuntimeException ());
1103+ return ;
11191104 }
1120- if (sendImmediately ) {
1121- super .sendMessage (new KnownLengthInputStream (body ));
1122- trySendAccumulatedWindowUpdates ();
1105+ sidestreamToUpstreamWindow -= body .size ();
1106+ if (super .isReady () && pendingUpstreamBodyMessages .isEmpty ()) {
1107+ sendImmediately = true ;
1108+ accumulatedWindowUpdateSidestreamToUpstream += body .size ();
1109+ } else {
1110+ pendingUpstreamBodyMessages .add (body );
11231111 }
1124- } else {
1112+ }
1113+ if (sendImmediately ) {
11251114 super .sendMessage (new KnownLengthInputStream (body ));
1115+ trySendAccumulatedWindowUpdates ();
11261116 }
11271117 }
11281118 if (streamed .getEndOfStream () || streamed .getEndOfStreamWithoutMessage ()) {
@@ -1148,19 +1138,16 @@ private void handleResponseBodyResponse(
11481138 StreamedBodyResponse streamed = mutation .getStreamedResponse ();
11491139 com .google .protobuf .ByteString body = streamed .getBody ();
11501140 final int bodySize = body .size ();
1151- if (!config .getObservabilityMode ()
1152- && currentProcessingMode .getResponseBodyMode () == ProcessingMode .BodySendMode .GRPC ) {
1153- synchronized (streamLock ) {
1154- if (sidestreamToDownstreamWindow <= 0 ) {
1155- internalOnError (Status .INTERNAL
1156- .withDescription (
1157- "Flow control violation: received server body from ext_proc "
1158- + "when window is closed" )
1159- .asRuntimeException ());
1160- return ;
1161- }
1162- sidestreamToDownstreamWindow -= bodySize ;
1141+ synchronized (streamLock ) {
1142+ if (sidestreamToDownstreamWindow <= 0 ) {
1143+ internalOnError (Status .INTERNAL
1144+ .withDescription (
1145+ "Flow control violation: received server body from ext_proc "
1146+ + "when window is closed" )
1147+ .asRuntimeException ());
1148+ return ;
11631149 }
1150+ sidestreamToDownstreamWindow -= bodySize ;
11641151 }
11651152 deliverResponseBody (body , listener );
11661153 }
@@ -1169,12 +1156,6 @@ private void handleResponseBodyResponse(
11691156
11701157 private void deliverResponseBody (ByteString body , DataPlaneListener listener ) {
11711158 synchronized (streamLock ) {
1172- if (config .getObservabilityMode ()
1173- || currentProcessingMode .getResponseBodyMode () != ProcessingMode .BodySendMode .GRPC ) {
1174- callContext .run (() -> listener .onExternalBody (body ));
1175- return ;
1176- }
1177-
11781159 if (downstreamRequestsPending > 0 ) {
11791160 downstreamRequestsPending --;
11801161 final int bodySize = body .size ();
@@ -1199,23 +1180,18 @@ private void drainPendingMutatedResponseBodies() {
11991180 while (downstreamRequestsPending > 0 && !pendingMutatedResponseBodies .isEmpty ()) {
12001181 ByteString body = pendingMutatedResponseBodies .poll ();
12011182 downstreamRequestsPending --;
1202- if (pendingRequests .get () > 0 ) {
1203- pendingRequests .decrementAndGet ();
1204- }
1183+ pendingRequests .decrementAndGet ();
12051184 final int bodySize = body .size ();
1206- final DataPlaneListener listener = wrappedListener ;
1207- if (listener != null ) {
1208- callContext .run (() -> {
1209- try {
1210- listener .onExternalBody (body );
1211- } finally {
1212- synchronized (streamLock ) {
1213- accumulatedWindowUpdateSidestreamToDownstream += bodySize ;
1214- }
1215- trySendAccumulatedWindowUpdates ();
1185+ callContext .run (() -> {
1186+ try {
1187+ wrappedListener .onExternalBody (body );
1188+ } finally {
1189+ synchronized (streamLock ) {
1190+ accumulatedWindowUpdateSidestreamToDownstream += bodySize ;
12161191 }
1217- });
1218- }
1192+ trySendAccumulatedWindowUpdates ();
1193+ }
1194+ });
12191195 }
12201196 }
12211197 }
@@ -1227,9 +1203,7 @@ void drainPendingUpstreamBodyMessages() {
12271203 synchronized (streamLock ) {
12281204 if (super .isReady () && !pendingUpstreamBodyMessages .isEmpty ()) {
12291205 body = pendingUpstreamBodyMessages .poll ();
1230- if (body != null ) {
1231- accumulatedWindowUpdateSidestreamToUpstream += body .size ();
1232- }
1206+ accumulatedWindowUpdateSidestreamToUpstream += body .size ();
12331207 if (pendingUpstreamBodyMessages .isEmpty () && pendingUpstreamHalfClose .compareAndSet (true , false )) {
12341208 triggerHalfClose = true ;
12351209 }
0 commit comments