[
https://issues.apache.org/jira/browse/BEAM-6876?focusedWorklogId=220520&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-220520
]
ASF GitHub Bot logged work on BEAM-6876:
----------------------------------------
Author: ASF GitHub Bot
Created on: 29/Mar/19 13:20
Start Date: 29/Mar/19 13:20
Worklog Time Spent: 10m
Work Description: tweise commented on pull request #8118: [BEAM-6876]
Cleanup user state in portable Flink Runner
URL: https://github.com/apache/beam/pull/8118#discussion_r270404554
##########
File path:
runners/flink/src/test/java/org/apache/beam/runners/flink/translation/wrappers/streaming/ExecutableStageDoFnOperatorTest.java
##########
@@ -340,6 +359,101 @@ public void testStageBundleClosed() throws Exception {
verifyNoMoreInteractions(bundle);
}
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testEnsureStateCleanupWithKeyedInput() throws Exception {
+ TupleTag<Integer> mainOutput = new TupleTag<>("main-output");
+ DoFnOperator.MultiOutputOutputManagerFactory<Integer> outputManagerFactory
=
+ new DoFnOperator.MultiOutputOutputManagerFactory(mainOutput,
VarIntCoder.of());
+ VarIntCoder keyCoder = VarIntCoder.of();
+ ExecutableStageDoFnOperator<Integer, Integer> operator =
+ getOperator(mainOutput, Collections.emptyList(), outputManagerFactory,
keyCoder);
+
+ KeyedOneInputStreamOperatorTestHarness<Integer, WindowedValue<Integer>,
WindowedValue<Integer>>
+ testHarness =
+ new KeyedOneInputStreamOperatorTestHarness(
+ operator, val -> val, new CoderTypeInformation<>(keyCoder));
+
+ RemoteBundle bundle = Mockito.mock(RemoteBundle.class);
+ when(bundle.getInputReceivers())
+ .thenReturn(
+ ImmutableMap.<String, FnDataReceiver<WindowedValue>>builder()
+ .put("input", Mockito.mock(FnDataReceiver.class))
+ .build());
+ when(stageBundleFactory.getBundle(any(), any(), any())).thenReturn(bundle);
+
+ testHarness.open();
+
+ Object doFnRunner = Whitebox.getInternalState(operator, "doFnRunner");
+ assertThat(doFnRunner, instanceOf(DoFnRunnerWithMetricsUpdate.class));
+
+ // There should be a StatefulDoFnRunner installed which takes care of
clearing state
+ Object statefulDoFnRunner = Whitebox.getInternalState(doFnRunner,
"delegate");
+ assertThat(statefulDoFnRunner, instanceOf(StatefulDoFnRunner.class));
+ }
+
+ @Test
+ public void testEnsureStateCleanupWithKeyedInputCleanupTimer() throws
Exception {
+ InMemoryTimerInternals inMemoryTimerInternals = new
InMemoryTimerInternals();
+ Consumer<ByteBuffer> keyConsumer = Mockito.mock(Consumer.class);
+ KeyedStateBackend keyedStateBackend =
Mockito.mock(KeyedStateBackend.class);
+ Lock stateBackendLock = Mockito.mock(Lock.class);
+ StringUtf8Coder keyCoder = StringUtf8Coder.of();
+ GlobalWindow window = GlobalWindow.INSTANCE;
+ GlobalWindow.Coder windowCoder = GlobalWindow.Coder.INSTANCE;
+
+ // Test that cleanup timer is set correctly
+ ExecutableStageDoFnOperator.CleanupTimer cleanupTimer =
+ new ExecutableStageDoFnOperator.CleanupTimer<>(
+ inMemoryTimerInternals,
+ stateBackendLock,
+ WindowingStrategy.globalDefault(),
+ keyCoder,
+ windowCoder,
+ keyConsumer,
+ keyedStateBackend);
+ cleanupTimer.setForWindow(KV.of("key", "string"), window);
+
+ Mockito.verify(stateBackendLock).lock();
+ ByteBuffer key = ByteBuffer.wrap(CoderUtils.encodeToByteArray(keyCoder,
"key"));
+ Mockito.verify(keyConsumer).accept(key);
+ Mockito.verify(keyedStateBackend).setCurrentKey(key);
+ assertThat(
+ inMemoryTimerInternals.getNextTimer(TimeDomain.EVENT_TIME),
+ is(window.maxTimestamp().plus(1)));
+ Mockito.verify(stateBackendLock).unlock();
+ }
+
+ @Test
+ public void testEnsureStateCleanupWithKeyedInputStateCleaner() throws
Exception {
+ GlobalWindow.Coder windowCoder = GlobalWindow.Coder.INSTANCE;
+ InMemoryStateInternals<String> stateInternals =
InMemoryStateInternals.forKey("key");
+ List<String> userStateNames = ImmutableList.of("state1", "state2");
+ ImmutableList.Builder<BagState<String>> bagStateBuilder =
ImmutableList.builder();
+ for (String userStateName : userStateNames) {
+ BagState<String> state =
+ stateInternals.state(
+ StateNamespaces.window(windowCoder, GlobalWindow.INSTANCE),
+ StateTags.bag(userStateName, StringUtf8Coder.of()));
+ bagStateBuilder.add(state);
+ state.add("this should be cleaned");
+ }
+ ImmutableList<BagState<String>> bagStates = bagStateBuilder.build();
+
+ // Test that state is cleanup up correctly
Review comment:
```suggestion
// Test that state is cleaned up correctly
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 220520)
Time Spent: 2.5h (was: 2h 20m)
> User state cleanup in portable Flink runner
> -------------------------------------------
>
> Key: BEAM-6876
> URL: https://issues.apache.org/jira/browse/BEAM-6876
> Project: Beam
> Issue Type: Bug
> Components: runner-flink
> Affects Versions: 2.11.0
> Reporter: Thomas Weise
> Assignee: Maximilian Michels
> Priority: Major
> Labels: portability-flink, triaged
> Time Spent: 2.5h
> Remaining Estimate: 0h
>
> State is currently not being cleaned up by the runner.
> [https://lists.apache.org/thread.html/86f0809fbfa3da873051287b9ff249d6dd5a896b45409db1e484cf38@%3Cdev.beam.apache.org%3E]
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)