scwhittle commented on code in PR #41825:
URL: https://github.com/apache/beam/pull/41825#discussion_r4754471899
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/windmill/client/grpc/GrpcGetDataStream.java:
##########
Review Comment:
AI indicates that there are related bugs that unfinished things can end up
in the queue due to non-shutdown issues causing batches to fail and how
waitForSendOrFailNotification works. Currently it throws a shutdown exception
for any failure which can confuse further logic. We should remove that logic
in GrpcGetDataStreamRequests.java. Without the exception thrown we just
proceed to attempt this batch and will notice shutdown if relevant.
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/windmill/client/grpc/GrpcCommitWorkStream.java:
##########
@@ -246,18 +245,19 @@ public void onDone(Status status) {
// Remove the requests that have exceeded the retry time so they are
not retried.
long nowNanos = System.nanoTime();
long maxRetryDurationNanos = maxRetryDuration.toNanos();
- Iterator<Map.Entry<Long, StreamAndRequest>> iterator =
pending.entrySet().iterator();
int keptRequests = 0, removedRequests = 0;
- while (iterator.hasNext()) {
- StreamAndRequest streamAndRequest =
checkNotNull(iterator.next().getValue());
+ for (Map.Entry<Long, StreamAndRequest> entry : pending.entrySet()) {
+ StreamAndRequest streamAndRequest = checkNotNull(entry.getValue());
PendingRequest pendingRequest = streamAndRequest.request;
if (!belongsToThisHandler(streamAndRequest)
|| nowNanos - pendingRequest.getStartTimeNanos() <
maxRetryDurationNanos) {
++keptRequests;
continue;
}
+ if (!pending.remove(entry.getKey(), streamAndRequest)) {
+ continue;
Review Comment:
add comment, // Handle concurrent removal by shutdownInternal.
##########
runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/windmill/client/grpc/GrpcGetDataStreamTest.java:
##########
@@ -1138,6 +1141,123 @@ public <ReqT, RespT> ClientCall<ReqT, RespT>
interceptCall(
assertTrue(sendFuture.isCompletedExceptionally());
}
+ @Test
+ public void
testRequestKeyedData_sendFailureCleansPendingSoBatchWaitersRetry() throws
Exception {
+ AtomicBoolean failFirstMultiRequestBatchSend = new AtomicBoolean(true);
+ GrpcGetDataStream getDataStream =
+ (GrpcGetDataStream)
+ GrpcWindmillStreamFactory.of(TEST_JOB_HEADER)
+ .setSendKeyedGetDataRequests(false)
+ .build()
+ .createGetDataStream(
+ CloudWindmillServiceV1Alpha1Grpc.newStub(inProcessChannel)
+ .withInterceptors(
+ new ClientInterceptor() {
+ @Override
+ public <ReqT, RespT> ClientCall<ReqT, RespT>
interceptCall(
+ MethodDescriptor<ReqT, RespT>
methodDescriptor,
+ CallOptions callOptions,
+ Channel channel) {
+ return new
ForwardingClientCall.SimpleForwardingClientCall<
+ ReqT,
RespT>(channel.newCall(methodDescriptor, callOptions)) {
+ @Override
+ public void sendMessage(ReqT message) {
+ if (message instanceof
Windmill.StreamingGetDataRequest
+ && ((Windmill.StreamingGetDataRequest)
message)
+ .getRequestIdCount()
+ > 1
+ &&
failFirstMultiRequestBatchSend.compareAndSet(
+ true, false)) {
+ throw new RuntimeException("injected
send error");
+ }
+ super.sendMessage(message);
+ }
+ };
+ }
+ }));
+ getDataStream.start();
+ FakeWindmillGrpcService.GetDataStreamInfo streamInfo =
waitForConnectionAndConsumeHeader();
+
+ int numThreads = 8;
+ ExecutorService executor = Executors.newFixedThreadPool(numThreads);
+ CyclicBarrier barrier = new CyclicBarrier(numThreads);
+ try {
+ for (int attempt = 0; attempt < 5 &&
failFirstMultiRequestBatchSend.get(); attempt++) {
+ List<CompletableFuture<Windmill.KeyedGetDataResponse>> futures = new
ArrayList<>();
+ for (int i = 1; i <= numThreads; i++) {
+ long requestKey = i;
+ futures.add(
+ CompletableFuture.supplyAsync(
+ () -> {
+ try {
+ // Synchronize threads so they batch together within the
1ms batch window.
Review Comment:
this will be racy.
Could we instead just have a test that sometimes reproduces the race and
would be flaky without the fix? Instead of trying to generate conditions over
multiple attempts in this single test.
##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/streaming/ActiveWorkState.java:
##########
@@ -223,17 +223,19 @@ synchronized Optional<ExecutableWork>
completeWorkAndGetNextWorkForKey(
return Optional.empty();
}
- removeCompletedWorkFromQueue(workQueue, shardedKey, workId);
+ if (!removeCompletedWorkFromQueue(workQueue, shardedKey, workId)) {
Review Comment:
can we inline removeCompletedWorkFromQueue? it's not big and it is clearer
that the activeWork.remove is correct based upon where workQueue came from
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]