You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by bowenli86 <gi...@git.apache.org> on 2018/01/21 05:38:14 UTC

[GitHub] flink pull request #5326: [FLINK-8365] [State Backend] Relax List type in He...

GitHub user bowenli86 opened a pull request:

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

    [FLINK-8365] [State Backend] Relax List type in HeapListState and HeapKeyedStateBackend

    ## What is the purpose of the change
    
    `stateTable` in `HeapListState` and `HeapKeyedStateBackend#createListState()` are both strongly typed to `ArrayList` right now. Relaxing that to `List` so we can avoid extra copies in some cases.
    
    Well, the copies in `HeapListState#update()` cannot be completely avoided. When users pass in an `AbstractList` to `update()` when there's no state before, it will break and we have to convert it to an `ArrayList` explicitly
    
    ## Brief change log
    
    Relax List type in HeapListState and HeapKeyedStateBackend
    
    ## Verifying this change
    
    This change is already covered by existing tests, such as *MemoryStateBackendTest*.
    
    ## Does this pull request potentially affect one of the following parts:
    
    none
    
    ## Documentation
    
    none

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

    $ git pull https://github.com/bowenli86/flink FLINK-8365

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

    https://github.com/apache/flink/pull/5326.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 #5326
    
----
commit dd2ec2fb3ce53549ba2f0162591658db34f1ac13
Author: Bowen Li <bo...@...>
Date:   2018-01-21T05:29:38Z

    [FLINK-8365] Relax List type in HeapListState and HeapKeyedStateBackend

commit f9d648fe6d26129a5a126cc860ccc0a58484a193
Author: Bowen Li <bo...@...>
Date:   2018-01-21T05:31:33Z

    remove unused code

----


---

[GitHub] flink pull request #5326: [FLINK-8365] [State Backend] Relax List type in He...

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

    https://github.com/apache/flink/pull/5326#discussion_r162903235
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/state/heap/HeapListState.java ---
    @@ -128,27 +128,33 @@ public void update(List<V> values) throws Exception {
     
     		if (values != null && !values.isEmpty()) {
     			final N namespace = currentNamespace;
    -			final StateTable<K, N, ArrayList<V>> map = stateTable;
    +			final StateTable<K, N, List<V>> map = stateTable;
    +			List<V> list = map.get(namespace);
     
    -			map.put(namespace, new ArrayList<>(values));
    +			if (list == null) {
    +				list = new ArrayList<>(values);
    +				map.put(namespace, list);
    +			} else {
    +				list.clear();
    +				list.addAll(values);
    +			}
     		}
     	}
     
     	@Override
     	public void addAll(List<V> values) throws Exception {
     		if (values != null && !values.isEmpty()) {
     			final N namespace = currentNamespace;
    -			final StateTable<K, N, ArrayList<V>> map = stateTable;
    +			final StateTable<K, N, List<V>> map = stateTable;
     
    -			ArrayList<V> list = map.get(currentNamespace);
    +			List<V> list = map.get(currentNamespace);
     
     			if (list == null) {
     				list = new ArrayList<>();
    --- End diff --
    
    We could already create a `new ArrayList<>(values.size())`


---

[GitHub] flink pull request #5326: [FLINK-8365] [State Backend] Relax List type in He...

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

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


---

[GitHub] flink issue #5326: [FLINK-8365] [State Backend] Relax List type in HeapListS...

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

    https://github.com/apache/flink/pull/5326
  
    Thanks for the feedback! I updated the PR and squashed all commits


---