You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "tzy-0x7cf (via GitHub)" <gi...@apache.org> on 2023/10/12 17:01:50 UTC
[PR] [FLINK-32896] [Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
tzy-0x7cf opened a new pull request, #23518:
URL: https://github.com/apache/flink/pull/23518
<!--
*Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
*Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message (including the JIRA id)
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
## What is the purpose of the change
The are multiple cases in the code which look like this:
`map.computeIfAbsent(..., ArrayList::new)`
Not only does this create a new collection (here an ArrayList), but computeIfAbsent also passes the map key as argument to the mapping function, so instead of calling the no-args constructor such as new ArrayList<>(), this actually calls the constructor with int initial capacity parameter, such as new ArrayList<>(initialCapacity).
This can lead either to runtime exceptions in case the map key is negative, since the collection constructors reject negative initial capacity values, or it can lead to bad performance if the key (which is misinterpreted as initial capacity) is pretty low, such as 0, or is pretty large and therefore pre-allocates a lot of memory for the collection.
it might be good to replace them with lambda expressions to make this more explicit:
`map.computeIfAbsent(..., k -> new ArrayList<>())`
## Brief change log
- *Replace all `map.computeIfAbsent(..., ... ::new)` with `map.computeIfAbsent(..., k -> new ...)`*
## Verifying this change
Please make sure both new and modified tests in this PR follows the conventions defined in our code quality guide: https://flink.apache.org/contributing/code-style-and-quality-common.html#testing
This change is already covered by existing tests, such as *HsSpillingStrategyUtilsTest*.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (no)
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
- The serializers: (no)
- The runtime per-record code paths (performance sensitive): (no)
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
- The S3 file system connector: (no)
## Documentation
- Does this pull request introduce a new feature? (no)
- If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1776027042
@flinkbot run azure
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1777866572
> Could squash the commits and rebase the branch to most-recent `master`? We don't want have merge commits cluttering the git history.
>
> The Flink CI bot is known to have issues with force-pushes. You can try to work around it by pushing an empty commit after you've reorganized and rebased the branch (in a separate push to be on the save side).
Thanks Matthias! I'm new to flink and would like to contribute more , so if there's anything about test or simple issues, please feel free to assign them to me!
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "XComp (via GitHub)" <gi...@apache.org>.
XComp merged PR #23518:
URL: https://github.com/apache/flink/pull/23518
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "XComp (via GitHub)" <gi...@apache.org>.
XComp commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1778686399
That's great to hear. You might be lucky if you look for tickets that are labeled as [starter](https://issues.apache.org/jira/browse/FLINK-30649?jql=project%20%3D%20FLINK%20AND%20labels%20%3D%20starter%20ORDER%20BY%20updatedDate) in [Flink's Jira](https://issues.apache.org/jira/projects/FLINK/issues/FLINK-33358?filter=allissues). A bit more context around how the Flink community organizes Jira can be found in [this Confluence wiki page](https://cwiki.apache.org/confluence/display/FLINK/Flink+Jira+Process).
Other sources that might be worth reading (in case you haven't done so, yet):
* [Flink's Coding Guidlines](https://flink.apache.org/how-to-contribute/code-style-and-quality-formatting/)
* [Instructions on how to setup your IDE](https://nightlies.apache.org/flink/flink-docs-master/docs/flinkdev/ide_setup/)
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1773422247
@flinkbot run azure
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1776007749
@flinkbot run azure
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1776024606
@flinkbot run azure
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1760385322
@wuchong Can you look at it? I think it's a very simple change : )
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1760362681
@flinkbot run azure
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1760020240
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "1100f6cfe4f94541c93dcc0c288c31cb548bbe62",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "1100f6cfe4f94541c93dcc0c288c31cb548bbe62",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 1100f6cfe4f94541c93dcc0c288c31cb548bbe62 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1776030176
@flinkbot run azure
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1773621479
@flinkbot run azure
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "tzy-0x7cf (via GitHub)" <gi...@apache.org>.
tzy-0x7cf commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1773618695
@flinkbot run azure
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "XComp (via GitHub)" <gi...@apache.org>.
XComp commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1774505796
Could squash the commits and rebase the branch to most-recent `master`? We don't want have merge commits cluttering the git history.
The Flink CI bot is known to have issues with force-pushes. You can try to work around it by pushing an empty commit after you've reorganized and rebased the branch (in a separate push to be on the save side).
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-32896][Runtime/Coordination] Incorrect `Map.computeIfAbsent(..., ...::new)` usage which misinterprets key as initial capacity [flink]
Posted by "itonyli (via GitHub)" <gi...@apache.org>.
itonyli commented on PR #23518:
URL: https://github.com/apache/flink/pull/23518#issuecomment-1764353014
LGTM
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org