You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "m-trieu (via GitHub)" <gi...@apache.org> on 2024/02/23 00:07:37 UTC

[PR] ActiveWorkRefresh [beam]

m-trieu opened a new pull request, #30390:
URL: https://github.com/apache/beam/pull/30390

   StreamingDataflowWorker is a very large class.  This breaks out the active work refresh and invalidating commit logic ( async work management) to another class.
   
   Initial implementation is what currently exists today.  There will be another implementation of `refreshActiveWork()` later for direct path, but this PR lays the ground work for it.  Also add tests to have more coverage over individual components than just the StreamingDataflowWorkerTest which is larger.
   
   R: @arunpandianp 
   
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
   


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ActiveWorkRefresh [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #30390:
URL: https://github.com/apache/beam/pull/30390#issuecomment-1964350931

   Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ActiveWorkRefresh [beam]

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on PR #30390:
URL: https://github.com/apache/beam/pull/30390#issuecomment-1981922464

   There is a flaky test added:
   
   testInvalidateStuckCommits: https://github.com/apache/beam/runs/22276370706
   
   ```
   Wanted but not invoked:
   forComputation.invalidate(
       <ByteString@3e931ad0 size=0 contents="">,
       0L
   );
   -> at org.apache.beam.runners.dataflow.worker.windmill.work.refresh.DispatchedActiveWorkRefresherTest.testInvalidateStuckCommits(DispatchedActiveWorkRefresherTest.java:231)
   Actually, there were zero interactions with this mock.
   
   	at org.apache.beam.runners.dataflow.worker.windmill.work.refresh.DispatchedActiveWorkRefresherTest.testInvalidateStuckCommits(DispatchedActiveWorkRefresherTest.java:231)
   ```


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ActiveWorkRefresh [beam]

Posted by "m-trieu (via GitHub)" <gi...@apache.org>.
m-trieu commented on PR #30390:
URL: https://github.com/apache/beam/pull/30390#issuecomment-1983793840

   I will take a look and fix thanks @Abacn !


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ActiveWorkRefresh [beam]

Posted by "riteshghorse (via GitHub)" <gi...@apache.org>.
riteshghorse merged PR #30390:
URL: https://github.com/apache/beam/pull/30390


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ActiveWorkRefresh [beam]

Posted by "arunpandianp (via GitHub)" <gi...@apache.org>.
arunpandianp commented on code in PR #30390:
URL: https://github.com/apache/beam/pull/30390#discussion_r1502767184


##########
runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/windmill/work/refresh/DispatchedActiveWorkRefresherTest.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.dataflow.worker.windmill.work.refresh;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import com.google.api.services.dataflow.model.MapTask;
+import com.google.common.truth.Correspondence;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+import org.apache.beam.runners.dataflow.worker.DataflowExecutionStateSampler;
+import org.apache.beam.runners.dataflow.worker.streaming.ComputationState;
+import org.apache.beam.runners.dataflow.worker.streaming.ShardedKey;
+import org.apache.beam.runners.dataflow.worker.streaming.Work;
+import org.apache.beam.runners.dataflow.worker.util.BoundedQueueExecutor;
+import org.apache.beam.runners.dataflow.worker.windmill.Windmill;
+import org.apache.beam.runners.dataflow.worker.windmill.Windmill.HeartbeatRequest;
+import org.apache.beam.runners.dataflow.worker.windmill.state.WindmillStateCache;
+import org.apache.beam.vendor.grpc.v1p60p1.com.google.protobuf.ByteString;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.HashBasedTable;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Table;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.Uninterruptibles;
+import org.joda.time.Instant;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class DispatchedActiveWorkRefresherTest {
+
+  private static final Supplier<Instant> A_LONG_TIME_AGO =
+      () -> Instant.parse("1998-09-04T00:00:00Z");
+  private static final String COMPUTATION_ID_PREFIX = "ComputationId-";
+
+  private static BoundedQueueExecutor workExecutor() {
+    return new BoundedQueueExecutor(
+        1,
+        60,
+        TimeUnit.SECONDS,
+        1,
+        10000000,
+        new ThreadFactoryBuilder().setNameFormat("DataflowWorkUnits-%d").setDaemon(true).build());
+  }
+
+  private static ComputationState createComputationState(int computationIdSuffix) {
+    return createComputationState(
+        computationIdSuffix, mock(WindmillStateCache.ForComputation.class));
+  }
+
+  private static ComputationState createComputationState(
+      int computationIdSuffix, WindmillStateCache.ForComputation stateCache) {
+    return new ComputationState(
+        COMPUTATION_ID_PREFIX + computationIdSuffix,
+        new MapTask().setStageName("stageName").setSystemName("systemName"),
+        workExecutor(),
+        new HashMap<>(),
+        stateCache);
+  }
+
+  private ActiveWorkRefresher createActiveWorkRefresher(
+      Supplier<Instant> clock,
+      int activeWorkRefreshPeriodMillis,
+      int stuckCommitDurationMillis,
+      Supplier<Collection<ComputationState>> computations,
+      Consumer<Map<String, List<HeartbeatRequest>>> activeWorkRefresherFn) {
+    return new DispatchedActiveWorkRefresher(
+        clock,
+        activeWorkRefreshPeriodMillis,
+        stuckCommitDurationMillis,
+        computations,
+        DataflowExecutionStateSampler.instance(),
+        activeWorkRefresherFn,
+        Executors.newSingleThreadScheduledExecutor());
+  }
+
+  private Work createOldWork(int workIds, Consumer<Work> processWork) {
+    return Work.create(
+        Windmill.WorkItem.newBuilder()
+            .setWorkToken(workIds)
+            .setCacheToken(workIds)
+            .setKey(ByteString.EMPTY)
+            .setShardingKey(workIds)
+            .build(),
+        DispatchedActiveWorkRefresherTest.A_LONG_TIME_AGO,
+        ImmutableList.of(),
+        processWork);
+  }
+
+  @Test
+  public void testActiveWorkRefresh() {
+    int activeWorkRefreshPeriodMillis = 100;
+
+    // Block work processing to queue up the work.
+    CountDownLatch workIsProcessed = new CountDownLatch(1);
+    Consumer<Work> processWork =
+        ignored -> {
+          try {
+            workIsProcessed.await();
+          } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+          }
+        };
+
+    List<ComputationState> computations = new ArrayList<>();
+    Map<String, List<Work>> computationsAndWork = new HashMap<>();
+    for (int i = 0; i < 5; i++) {
+      ComputationState computationState = createComputationState(i);
+      Work fakeWork = createOldWork(i, processWork);
+      computationState.activateWork(ShardedKey.create(ByteString.EMPTY, i), fakeWork);
+
+      computations.add(computationState);
+      List<Work> activeWorkForComputation =
+          computationsAndWork.computeIfAbsent(
+              computationState.getComputationId(), ignored -> new ArrayList<>());
+      activeWorkForComputation.add(fakeWork);
+    }
+
+    Map<String, List<HeartbeatRequest>> expectedHeartbeats = new HashMap<>();
+
+    ActiveWorkRefresher activeWorkRefresher =
+        createActiveWorkRefresher(
+            Instant::now,

Review Comment:
   Can we send a fake clock and control the passage of time instead of relying on sleeping?



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ActiveWorkRefresh [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #30390:
URL: https://github.com/apache/beam/pull/30390#issuecomment-1960585192

   Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
   
   R: @riteshghorse added as fallback since no labels match configuration
   
   Available commands:
   - `stop reviewer notifications` - opt out of the automated review tooling
   - `remind me after tests pass` - tag the comment author after tests pass
   - `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
   
   The PR bot will only process comments in the main thread (not review comments).


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ActiveWorkRefresh [beam]

Posted by "riteshghorse (via GitHub)" <gi...@apache.org>.
riteshghorse commented on PR #30390:
URL: https://github.com/apache/beam/pull/30390#issuecomment-1964347932

   R: @arunpandianp 


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org