Skip to content

Commit a16d5de

Browse files
committed
Re-introduce lost synchronization fixes in the tests during merge.
1 parent 06fff33 commit a16d5de

2 files changed

Lines changed: 668 additions & 673 deletions

File tree

xds/src/main/java/io/grpc/xds/ExternalProcessorClientInterceptor.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
228228
io.grpc.stub.MetadataUtils.newAttachHeadersInterceptor(extraHeaders));
229229
}
230230

231-
232231
// The filter chain is preceded by RawMessageClientInterceptor, so ReqT and RespT are
233232
// InputStream.
234233
MethodDescriptor<InputStream, InputStream> rawMethod =
@@ -379,8 +378,6 @@ protected DataPlaneClientCall(
379378
this.backendService = checkNotNull(backendService, "backendService");
380379
}
381380

382-
383-
384381
private void activateCall() {
385382
if ((extProcStreamState.get() == ExtProcStreamState.FAILED
386383
&& !config.getFailureModeAllow()
@@ -447,8 +444,6 @@ private boolean validateCompressionSupport(BodyResponse bodyResponse) {
447444
return true;
448445
}
449446

450-
451-
452447
@Override
453448
public void start(Listener<InputStream> responseListener, Metadata headers) {
454449
this.callContext = Context.current();
@@ -686,7 +681,7 @@ private void sendToExtProc(ProcessingRequest request) {
686681
if (extProcStreamState.get().isCompleted()) {
687682
return;
688683
}
689-
684+
690685
if (request.hasRequestHeaders()) {
691686
expectedRequestResponse = EventType.REQUEST_HEADERS;
692687
} else if (request.hasResponseHeaders()) {
@@ -806,7 +801,7 @@ void drainPendingRequests() {
806801
}
807802

808803
// Normal mode flow control: pull 1 message at a time
809-
if (isExtProcReady() && upstreamToSidestreamWindow > 0 && pendingRequests.get() > 0) {
804+
if (isSidecarReady() && upstreamToSidestreamWindow > 0 && pendingRequests.get() > 0) {
810805
super.request(1);
811806
pendingRequests.decrementAndGet();
812807
}
@@ -858,7 +853,7 @@ private void onReadyNotify() {
858853
wrappedListener.onReadyNotify();
859854
}
860855

861-
boolean isExtProcReady() {
856+
boolean isSidecarReady() {
862857
ExtProcStreamState state = extProcStreamState.get();
863858
if (state.isCompleted()) {
864859
return true;
@@ -884,11 +879,11 @@ public boolean isReady() {
884879
return false;
885880
}
886881
synchronized (streamLock) {
887-
boolean extProcReady = isExtProcReady();
882+
boolean sidecarReady = isSidecarReady();
888883
if (config.getObservabilityMode()) {
889-
return super.isReady() && extProcReady;
884+
return super.isReady() && sidecarReady;
890885
}
891-
return downstreamToSidestreamWindow > 0 && extProcReady
886+
return downstreamToSidestreamWindow > 0 && sidecarReady
892887
&& pendingRequestBodyMessages.isEmpty();
893888
}
894889
}
@@ -909,20 +904,22 @@ public void request(int numMessages) {
909904
return;
910905
}
911906

912-
// We send response bodies to ext_proc server (either in normal GRPC mode or observability mode).
907+
// We send response bodies to ext_proc server (either in normal GRPC mode or
908+
// observability mode).
913909
// Gated by ext_proc server readiness.
914-
boolean normalFlowControl = !config.getObservabilityMode(); // i.e. normal GRPC response body mode
910+
// i.e. normal GRPC response body mode
911+
boolean normalFlowControl = !config.getObservabilityMode();
915912

916913
if (normalFlowControl) {
917914
pendingRequests.addAndGet(numMessages);
918915
downstreamRequestsPending += numMessages;
919916
drainPendingMutatedResponseBodies();
920-
if (isExtProcReady()) {
917+
if (isSidecarReady()) {
921918
drainPendingRequests();
922919
}
923920
} else {
924921
// Observability mode: gate on readiness but pull all at once
925-
if (isExtProcReady()) {
922+
if (isSidecarReady()) {
926923
super.request(numMessages);
927924
} else {
928925
pendingRequests.addAndGet(numMessages);
@@ -1204,7 +1201,8 @@ void drainPendingUpstreamBodyMessages() {
12041201
if (super.isReady() && !pendingUpstreamBodyMessages.isEmpty()) {
12051202
body = pendingUpstreamBodyMessages.poll();
12061203
accumulatedWindowUpdateSidestreamToUpstream += body.size();
1207-
if (pendingUpstreamBodyMessages.isEmpty() && pendingUpstreamHalfClose.compareAndSet(true, false)) {
1204+
if (pendingUpstreamBodyMessages.isEmpty()
1205+
&& pendingUpstreamHalfClose.compareAndSet(true, false)) {
12081206
triggerHalfClose = true;
12091207
}
12101208
}
@@ -1473,7 +1471,7 @@ public void onMessage(InputStream message) {
14731471

14741472
void drainSavedMessages() {
14751473
synchronized (dataPlaneClientCall.getStreamLock()) {
1476-
while (dataPlaneClientCall.isExtProcReady()
1474+
while (dataPlaneClientCall.isSidecarReady()
14771475
&& dataPlaneClientCall.upstreamToSidestreamWindow > 0
14781476
&& !savedMessages.isEmpty()) {
14791477
InputStream msg = savedMessages.poll();

0 commit comments

Comments
 (0)