You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by yanghua <gi...@git.apache.org> on 2018/06/07 07:32:03 UTC

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

GitHub user yanghua opened a pull request:

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

    [FLINK-9538] Make KeyedStateFunction an interface

    ## What is the purpose of the change
    
    *This pull request makes KeyedStateFunction an interface*
    
    
    ## Brief change log
    
      - *Change abstract class `KeyedStateFunction` to be an interface*
      - *Change abstract method `process` to be an interface method*
    
    ## Verifying this change
    
    This change is already covered by existing tests, such as *StateBackendTestBase*.
    
    ## Does this pull request potentially affect one of the following parts:
    
      - Dependencies (does it add or upgrade a dependency): (yes / **no**)
      - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**)
      - The serializers: (yes / **no** / don't know)
      - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
      - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (yes / **no** / don't know)
      - The S3 file system connector: (yes / **no** / don't know)
    
    ## Documentation
    
      - Does this pull request introduce a new feature? (yes / **no**)
      - If yes, how is the feature documented? (not applicable / docs / JavaDocs / **not documented**)


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

    $ git pull https://github.com/yanghua/flink FLINK-9538

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

    https://github.com/apache/flink/pull/6134.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 #6134
    
----
commit c6e4cb6cef99306f402e6e7e50c066f8a60e41f4
Author: yanghua <ya...@...>
Date:   2018-06-07T07:27:25Z

    [FLINK-9538] Make KeyedStateFunction an interface

----


---

[GitHub] flink issue #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134
  
    LGTM, will merge soon.


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r193650651
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyedStateFunction.java ---
    @@ -25,13 +25,13 @@
      * <p>This functionality is only available through the
      * {@code BroadcastConnectedStream.process(final KeyedBroadcastProcessFunction function)}.
      */
    -public abstract class KeyedStateFunction<K, S extends State> {
    +public interface KeyedStateFunction<K, S extends State> {
    --- End diff --
    
    Add `@FunctionalInterface` annotation.


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r194346916
  
    --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/state/StateBackendTestBase.java ---
    @@ -3747,6 +3747,39 @@ public void process(Integer key, ListState<String> state) throws Exception {
     		}
     	}
     
    +	/**
    +	 * Since {@link AbstractKeyedStateBackend#getKeys(String, Object)} does't support concurrent modification
    +	 * and {@link AbstractKeyedStateBackend#applyToAllKeys(Object, TypeSerializer, StateDescriptor,
    +	 * KeyedStateFunction)} rely on it to get keys from backend. So we need this unit test to verify the concurrent
    +	 * modification with {@link AbstractKeyedStateBackend#applyToAllKeys(Object, TypeSerializer, StateDescriptor, KeyedStateFunction)}.
    +	 */
    +	@Test
    +	public void testConcurrentModificationWithApplyToAllKeysAndKeyedStateLambdaFunction() throws Exception {
    --- End diff --
    
    Wasn't the goal of this test to make sure you can pass lambda? Please correct the name of the test. Maybe: `testApplyToAllKeysLambdaFunction`?


---

[GitHub] flink issue #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134
  
    cc @dawidwys is this PR OK for you?


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r193976690
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyedStateFunction.java ---
    @@ -25,13 +25,13 @@
      * <p>This functionality is only available through the
      * {@code BroadcastConnectedStream.process(final KeyedBroadcastProcessFunction function)}.
      */
    -public abstract class KeyedStateFunction<K, S extends State> {
    +public interface KeyedStateFunction<K, S extends State> {
    --- End diff --
    
    hi @dawidwys the Travis is green, that means the lambda is right. I think there isn't necessary to  have a extra test? I think changing from anonymous implementation to lambda function can be treat as refactor.


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

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


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r194047289
  
    --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/state/StateBackendTestBase.java ---
    @@ -3747,6 +3747,67 @@ public void process(Integer key, ListState<String> state) throws Exception {
     		}
     	}
     
    +	/**
    +	 * Since {@link AbstractKeyedStateBackend#getKeys(String, Object)} does't support concurrent modification
    +	 * and {@link AbstractKeyedStateBackend#applyToAllKeys(Object, TypeSerializer, StateDescriptor,
    +	 * KeyedStateFunction)} rely on it to get keys from backend. So we need this unit test to verify the concurrent
    +	 * modification with {@link AbstractKeyedStateBackend#applyToAllKeys(Object, TypeSerializer, StateDescriptor, KeyedStateFunction)}.
    +	 */
    +	@Test
    +	public void testConcurrentModificationWithApplyToAllKeysAndKeyedStateLambdaFunction() throws Exception {
    --- End diff --
    
    Could you simplify the test to call the `applyToAllKeys` once.


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r193976994
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyedStateFunction.java ---
    @@ -25,13 +25,13 @@
      * <p>This functionality is only available through the
      * {@code BroadcastConnectedStream.process(final KeyedBroadcastProcessFunction function)}.
      */
    -public abstract class KeyedStateFunction<K, S extends State> {
    +public interface KeyedStateFunction<K, S extends State> {
    --- End diff --
    
    Yes, but the refactor is unnecessary and pollutes git history.


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r193651829
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyedStateFunction.java ---
    @@ -25,13 +25,13 @@
      * <p>This functionality is only available through the
      * {@code BroadcastConnectedStream.process(final KeyedBroadcastProcessFunction function)}.
      */
    -public abstract class KeyedStateFunction<K, S extends State> {
    +public interface KeyedStateFunction<K, S extends State> {
    --- End diff --
    
    @dawidwys can I change current usage like : 
    
    ```
    // valid state value via applyToAllKeys().
    			backend.applyToAllKeys(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, listStateDescriptor,
    				new KeyedStateFunction<Integer, ListState<String>>() {
    					@Override
    					public void process(Integer key, ListState<String> state) throws Exception {
    						assertEquals("Hello" + key, state.get().iterator().next());
    					}
    				});
    
    			// clear state via applyToAllKeys().
    			backend.applyToAllKeys(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, listStateDescriptor,
    				new KeyedStateFunction<Integer, ListState<String>>() {
    					@Override
    					public void process(Integer key, ListState<String> state) throws Exception {
    						state.clear();
    					}
    				});
    ```
    
    to lambda function style to verify the change?


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r193985722
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyedStateFunction.java ---
    @@ -25,13 +25,13 @@
      * <p>This functionality is only available through the
      * {@code BroadcastConnectedStream.process(final KeyedBroadcastProcessFunction function)}.
      */
    -public abstract class KeyedStateFunction<K, S extends State> {
    +public interface KeyedStateFunction<K, S extends State> {
    --- End diff --
    
    @dawidwys so, what about I just revert the refactor?


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r194346991
  
    --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/state/StateBackendTestBase.java ---
    @@ -3747,6 +3747,39 @@ public void process(Integer key, ListState<String> state) throws Exception {
     		}
     	}
     
    +	/**
    +	 * Since {@link AbstractKeyedStateBackend#getKeys(String, Object)} does't support concurrent modification
    --- End diff --
    
    This comment is irrelevant to the test.


---

[GitHub] flink issue #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134
  
    cc @dawidwys refactored code, please review again~


---

[GitHub] flink issue #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134
  
    cc @dawidwys 


---

[GitHub] flink issue #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134
  
    Sorry @yanghua , will have a look tomorrow. You really don't need to ping me every hour, will get to it as soon as I have some time.


---

[GitHub] flink issue #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134
  
    cc @dawidwys 


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r193989354
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyedStateFunction.java ---
    @@ -25,13 +25,13 @@
      * <p>This functionality is only available through the
      * {@code BroadcastConnectedStream.process(final KeyedBroadcastProcessFunction function)}.
      */
    -public abstract class KeyedStateFunction<K, S extends State> {
    +public interface KeyedStateFunction<K, S extends State> {
    --- End diff --
    
    Yes, and add single test for lambda? Why are you against adding a test for that?


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r194001177
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyedStateFunction.java ---
    @@ -25,13 +25,13 @@
      * <p>This functionality is only available through the
      * {@code BroadcastConnectedStream.process(final KeyedBroadcastProcessFunction function)}.
      */
    -public abstract class KeyedStateFunction<K, S extends State> {
    +public interface KeyedStateFunction<K, S extends State> {
    --- End diff --
    
    @dawidwys OK, I am not against adding test I just consider the lambda function has been verified.  Will add soon.


---

[GitHub] flink pull request #6134: [FLINK-9538] Make KeyedStateFunction an interface

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

    https://github.com/apache/flink/pull/6134#discussion_r193968855
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/KeyedStateFunction.java ---
    @@ -25,13 +25,13 @@
      * <p>This functionality is only available through the
      * {@code BroadcastConnectedStream.process(final KeyedBroadcastProcessFunction function)}.
      */
    -public abstract class KeyedStateFunction<K, S extends State> {
    +public interface KeyedStateFunction<K, S extends State> {
    --- End diff --
    
    IMO changing every test that uses this function is not the best practice. Anonymous functions are still a valid option, so there is no need to change valid tests. I would be in favour of adding just a single test that tests lambda can be passed.


---