You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by kl0u <gi...@git.apache.org> on 2016/08/29 13:10:35 UTC

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

GitHub user kl0u opened a pull request:

    https://github.com/apache/flink/pull/2434

    [FLINK-4496] Refactor the TimeServiceProvider to take a Trigerable in\u2026

    This is a first step towards https://issues.apache.org/jira/browse/FLINK-4329
    
    R: @aljoscha @rmetzger 

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/kl0u/flink timeprovider_refactoring

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/flink/pull/2434.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2434
    
----
commit 1ca643800f2000df46d41d29189050fa8f7c2b0c
Author: kl0u <kk...@gmail.com>
Date:   2016-08-25T15:38:49Z

    [FLINK-4496] Refactor the TimeServiceProvider to take a Trigerable instead of a Runnable.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #2434: [FLINK-4496] Refactor the TimeServiceProvider to take a T...

Posted by kl0u <gi...@git.apache.org>.
Github user kl0u commented on the issue:

    https://github.com/apache/flink/pull/2434
  
    Thanks @mxm and @aljoscha !
    I already have the followup on this open here: 
    https://github.com/apache/flink/pull/2532 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r76612209
  
    --- Diff: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/DefaultTimeServiceProvider.java ---
    @@ -57,4 +67,49 @@ public void shutdownService() throws Exception {
     		}
     		timerService.shutdownNow();
     	}
    +
    +	/**
    +	 * Internal task that is invoked by the timer service and triggers the target.
    +	 */
    +	private static final class TriggerTask implements Runnable {
    +
    +		private final Object lock;
    +		private final Triggerable target;
    +		private final long timestamp;
    +		private final StreamTask<?, ?> task;
    +
    +		TriggerTask(StreamTask<?, ?> task, final Object lock, Triggerable target, long timestamp) {
    +			this.task = task;
    +			this.lock = lock;
    +			this.target = target;
    +			this.timestamp = timestamp;
    +		}
    +
    +		@Override
    +		public void run() {
    +			synchronized (lock) {
    +				try {
    +					target.trigger(timestamp);
    +				} catch (Throwable t) {
    +
    +					if (task != null) {
    +						// registers the exception with the calling task
    +						// so that it can be logged and (later) detected
    +						TimerException asyncException = new TimerException(t);
    +						task.registerAsyncException("Caught exception while processing timer.", asyncException);
    +					} else {
    +						// this is for when we are in testing mode and we
    +						// want to have real processing time.
    +						System.err.println("!!! Caught exception while processing timer. !!!");
    --- End diff --
    
    Why are you not using the regular logging for this?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r76624854
  
    --- Diff: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/DefaultTimeServiceProvider.java ---
    @@ -28,15 +31,22 @@
      */
     public class DefaultTimeServiceProvider extends TimeServiceProvider {
     
    +	/** The containing task that owns this time service provider. */
    +	private final StreamTask<?, ?> task;
    --- End diff --
    
    If the `StreamTask` is only used for the async exception handling then I think this can be abstracted behind an `AsynchronousExceptionHandler` interface that the task implements. This would have something like `notifyOfAsyncException()` and `checkAsyncExceptions()`. These are the same methods that `StreamTask` has now but we would not expose all of `StreamTask` to the time service provider but have clear-cut interfaces.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r76624448
  
    --- Diff: flink-streaming-connectors/flink-connector-kafka-base/src/test/java/org/apache/flink/streaming/connectors/kafka/testutils/MockRuntimeContext.java ---
    @@ -71,8 +71,7 @@ public MockRuntimeContext(
     		ExecutionConfig execConfig,
     		Object checkpointLock) {
     
    -		this(numberOfParallelSubtasks, indexOfThisSubtask, execConfig, checkpointLock,
    -			DefaultTimeServiceProvider.create(Executors.newSingleThreadScheduledExecutor()));
    +		this(numberOfParallelSubtasks, indexOfThisSubtask, execConfig, checkpointLock, null);
    --- End diff --
    
    Instead of passing `null` you can directly insert this line from below: `DefaultTimeServiceProvider.createForTesting(Executors.newSingleThreadScheduledExecutor(), this.checkpointLock)` and avoid the null check below.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r79854449
  
    --- Diff: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java ---
    @@ -486,6 +472,9 @@ private void disposeAllOperators() {
     	protected void finalize() throws Throwable {
     		super.finalize();
     		if (timerService != null) {
    +			if (!timerService.isTerminated()) {
    --- End diff --
    
    Should the actual call to `shutdownService()` also be inside the if block?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r79858930
  
    --- Diff: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/TimeProviderTest.java ---
    @@ -0,0 +1,198 @@
    +/*
    + * 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.flink.streaming.runtime.operators;
    +
    +import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
    +import org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter;
    +import org.apache.flink.streaming.api.graph.StreamConfig;
    +import org.apache.flink.streaming.api.operators.StreamMap;
    +import org.apache.flink.streaming.runtime.tasks.DefaultTimeServiceProvider;
    +import org.apache.flink.streaming.runtime.tasks.OneInputStreamTask;
    +import org.apache.flink.streaming.runtime.tasks.OneInputStreamTaskTestHarness;
    +import org.apache.flink.streaming.runtime.tasks.TestTimeServiceProvider;
    +import org.apache.flink.streaming.runtime.tasks.TimeServiceProvider;
    +import org.junit.Assert;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.powermock.core.classloader.annotations.PowerMockIgnore;
    +import org.powermock.core.classloader.annotations.PrepareForTest;
    +import org.powermock.modules.junit4.PowerMockRunner;
    +
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.Executors;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertTrue;
    +
    +@RunWith(PowerMockRunner.class)
    +@PrepareForTest(ResultPartitionWriter.class)
    +@PowerMockIgnore({"javax.management.*", "com.sun.jndi.*"})
    +public class TimeProviderTest {
    +
    +	@Test
    +	public void testDefaultTimeProvider() throws InterruptedException {
    +		final Object lock = new Object();
    +		TimeServiceProvider timeServiceProvider = DefaultTimeServiceProvider
    +			.createForTesting(Executors.newSingleThreadScheduledExecutor(), lock);
    +
    +		final List<Long> timestamps = new ArrayList<>();
    +
    +		long start = System.currentTimeMillis();
    +		long interval = 50L;
    +
    +		long noOfTimers = 5;
    +		for (int i = 0; i < noOfTimers; i++) {
    +			double nextTimer = start + i * interval;
    +
    +			timeServiceProvider.registerTimer((long) nextTimer, new Triggerable() {
    +				@Override
    +				public void trigger(long timestamp) throws Exception {
    +					timestamps.add(timestamp);
    +				}
    +			});
    +
    +			// add also out-of-order tasks to verify that eventually
    +			// they will be executed in the correct order.
    +
    +			if (i > 0) {
    +				timeServiceProvider.registerTimer((long) (nextTimer - 10), new Triggerable() {
    +					@Override
    +					public void trigger(long timestamp) throws Exception {
    +						timestamps.add(timestamp);
    +					}
    +				});
    +			}
    +		}
    +
    +		Thread.sleep(1000);
    --- End diff --
    
    Having a `Thread.sleep()` here is probably problematic when running on Travis: it might happen that not all timers fire within 1 second. Also, it always adds one second to the runtime of the test.
    
    I think you can do the verification of correct firing order directly in the `trigger()` methods. You have an atomic variable outside of the scope of the timers that you check and update within the trigger methods. Outside, in the test you can use a `OneShotLatch` to wait on success. Once you detect success inside the trigger methods you signal that using `OneShotLatch.trigger()`.
    
       


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #2434: [FLINK-4496] Refactor the TimeServiceProvider to take a T...

Posted by kl0u <gi...@git.apache.org>.
Github user kl0u commented on the issue:

    https://github.com/apache/flink/pull/2434
  
    R: @mxm @aljoscha @rmetzger 
    This is ready for review.
    Thanks a lot for the comments.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #2434: [FLINK-4496] Refactor the TimeServiceProvider to take a T...

Posted by mxm <gi...@git.apache.org>.
Github user mxm commented on the issue:

    https://github.com/apache/flink/pull/2434
  
    +1 Looks like a sensible change. Looking forward to fixing the `ContinuousFileReaderOperator`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by kl0u <gi...@git.apache.org>.
Github user kl0u commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r79390766
  
    --- Diff: flink-streaming-java/src/test/java/org/apache/flink/streaming/util/OneInputStreamOperatorTestHarness.java ---
    @@ -98,7 +99,7 @@ public OneInputStreamOperatorTestHarness(OneInputStreamOperator<IN, OUT> operato
     	public OneInputStreamOperatorTestHarness(
     			OneInputStreamOperator<IN, OUT> operator,
     			ExecutionConfig executionConfig) {
    -		this(operator, executionConfig, DefaultTimeServiceProvider.create(Executors.newSingleThreadScheduledExecutor()));
    +		this(operator, executionConfig, null);
    --- End diff --
    
    The null is because we do not yet have the mockTask here to pass as argument.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r79853936
  
    --- Diff: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java ---
    @@ -212,10 +212,6 @@ public void setTimeService(TimeServiceProvider timeProvider) {
     		timerService = timeProvider;
     	}
     
    -	public long getCurrentProcessingTime() {
    --- End diff --
    
    Moving this method does not seem necessary. Especially since it's planned for removal in FLINK-4494. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r79854646
  
    --- Diff: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java ---
    @@ -326,6 +322,9 @@ public Long getValue() {
     			// stop all timers and threads
     			if (timerService != null) {
     				try {
    +					if (!timerService.isTerminated()) {
    --- End diff --
    
    Should the actual call to `shutdownService()` also be inside the if block?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by kl0u <gi...@git.apache.org>.
Github user kl0u closed the pull request at:

    https://github.com/apache/flink/pull/2434


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #2434: [FLINK-4496] Refactor the TimeServiceProvider to take a T...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on the issue:

    https://github.com/apache/flink/pull/2434
  
    I had comments about introducing an interface for the asynchronous excepts, other than that and @rmetzger's comment this looks good. I like the addition of the `TimeProviderTest`. \U0001f44d 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r79854335
  
    --- Diff: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java ---
    @@ -365,19 +364,6 @@ public Long getValue() {
     		}
     	}
     
    -	/**
    --- End diff --
    
    This move also seems unnecessary. The current place in the code might not seem ideal but just moving around code does not help when trying to retrace the history of code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2434: [FLINK-4496] Refactor the TimeServiceProvider to t...

Posted by aljoscha <gi...@git.apache.org>.
Github user aljoscha commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2434#discussion_r76625434
  
    --- Diff: flink-streaming-java/src/test/java/org/apache/flink/streaming/util/OneInputStreamOperatorTestHarness.java ---
    @@ -98,7 +99,7 @@ public OneInputStreamOperatorTestHarness(OneInputStreamOperator<IN, OUT> operato
     	public OneInputStreamOperatorTestHarness(
     			OneInputStreamOperator<IN, OUT> operator,
     			ExecutionConfig executionConfig) {
    -		this(operator, executionConfig, DefaultTimeServiceProvider.create(Executors.newSingleThreadScheduledExecutor()));
    +		this(operator, executionConfig, null);
    --- End diff --
    
    This can directly be `DefaultTimeServiceProvider.create(mockTask, Executors.newSingleThreadScheduledExecutor())` instead of the `null` check below.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---