You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "fredia (via GitHub)" <gi...@apache.org> on 2024/10/12 04:34:05 UTC
[PR] [FLINK-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
fredia opened a new pull request, #25501:
URL: https://github.com/apache/flink/pull/25501
<!--
*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
This PR supports storing timer in JVM heap when use async state backend.
Note: Timers are stored as raw keyed state instead of managed keyed state now, the snapshot/restore of jvm timer is managed by `InternalTimeServiceManager`.
## Brief change log
- Implement `ForStKeyedStateBackend#create() -> KeyGroupedInternalPriorityQueue`
- Support using async keyed state backend initializing `timeServiceManager` in `StreamTaskStateInitializerImpl`
## Verifying this change
This change added tests and can be verified as follows:
- `StateBackendTestV2Base#testKeyGroupedInternalPriorityQueue`
## 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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "Zakelly (via GitHub)" <gi...@apache.org>.
Zakelly commented on code in PR #25501:
URL: https://github.com/apache/flink/pull/25501#discussion_r1804441714
##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/InternalTimeServiceManager.java:
##########
@@ -111,6 +112,7 @@ interface Provider extends Serializable {
<K> InternalTimeServiceManager<K> create(
TaskIOMetricGroup taskIOMetricGroup,
CheckpointableKeyedStateBackend<K> keyedStatedBackend,
+ AsyncKeyedStateBackend<K> asyncKeyedStateBackend,
Review Comment:
How about merge the two parameter into one state backend? Like this
```suggestion
PriorityQueueSetFactory<K> factory,
KeyGroupRange keyGroupRange,
```
--
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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "fredia (via GitHub)" <gi...@apache.org>.
fredia merged PR #25501:
URL: https://github.com/apache/flink/pull/25501
--
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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "Zakelly (via GitHub)" <gi...@apache.org>.
Zakelly commented on code in PR #25501:
URL: https://github.com/apache/flink/pull/25501#discussion_r1805987455
##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java:
##########
@@ -244,6 +244,11 @@ void snapshotState(
&& ((AbstractKeyedStateBackend<?>) keyedStateBackend)
.requiresLegacySynchronousTimerSnapshots(
checkpointOptions.getCheckpointType());
+ requiresLegacyRawKeyedStateSnapshots |=
Review Comment:
I think here we could leverage the `useAsyncState` to determine whether to check via `AsyncKeyedStateBackend` or `AbstractKeyedStateBackend`.
--
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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "fredia (via GitHub)" <gi...@apache.org>.
fredia commented on code in PR #25501:
URL: https://github.com/apache/flink/pull/25501#discussion_r1798959007
##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java:
##########
@@ -244,6 +244,11 @@ void snapshotState(
&& ((AbstractKeyedStateBackend<?>) keyedStateBackend)
.requiresLegacySynchronousTimerSnapshots(
checkpointOptions.getCheckpointType());
+ requiresLegacyRawKeyedStateSnapshots |=
+ keyedStateBackend instanceof AsyncKeyedStateBackend
+ && ((AsyncKeyedStateBackend<?>) keyedStateBackend)
+ .requiresLegacySynchronousTimerSnapshots(
Review Comment:
> How about remove AsyncKeyedStateBackend#requiresLegacySynchronousTimerSnapshots and do the following
ForSt state backend may support storing timers in files in the future, so `requiresLegacySynchronousTimerSnapshots` will return false. I prefer to keep it as it is.
> should subclasses like AsyncKeyedStateBackendAdaptor override this method?
Good point, we can store timers in the form of `delegated keyed state backend`.
--
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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "yunfengzhou-hub (via GitHub)" <gi...@apache.org>.
yunfengzhou-hub commented on PR #25501:
URL: https://github.com/apache/flink/pull/25501#issuecomment-2428319498
Thanks for the update. The runtime part 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
Re: [PR] [FLINK-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "fredia (via GitHub)" <gi...@apache.org>.
fredia commented on PR #25501:
URL: https://github.com/apache/flink/pull/25501#issuecomment-2421222987
> I'd suggest split the two `InternalTimeServiceManager` in `StreamOperatorStateContext`, since there still a chance that we use state backend like ForSt in sync mode, the `InternalTimeServiceManager` should be the one created by `KeyedStateBackend` in this case.
Thanks for the suggestion, add `StreamOperatorStateContext#asyncInternalTimerServiceManager`.
--
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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "yunfengzhou-hub (via GitHub)" <gi...@apache.org>.
yunfengzhou-hub commented on code in PR #25501:
URL: https://github.com/apache/flink/pull/25501#discussion_r1809757295
##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateContext.java:
##########
@@ -67,6 +67,12 @@ default boolean isRestored() {
*/
InternalTimeServiceManager<?> internalTimerServiceManager();
+ /**
+ * Returns the internal timer service manager create by async state backend for the stream
+ * operator. This method returns null for non-keyed operators.
+ */
+ InternalTimeServiceManager<?> asyncInternalTimerServiceManager();
Review Comment:
Are there cases in which an operator needs to use async timer service and sync timer service simultaneously? I'm wondering if we could reduce `internalTimerServiceManager()` and `asyncInternalTimerServiceManager()` into one method, given that they have the same return type, and it might better help hiding implementation details from invokers.
--
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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "fredia (via GitHub)" <gi...@apache.org>.
fredia commented on code in PR #25501:
URL: https://github.com/apache/flink/pull/25501#discussion_r1809809121
##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateContext.java:
##########
@@ -67,6 +67,12 @@ default boolean isRestored() {
*/
InternalTimeServiceManager<?> internalTimerServiceManager();
+ /**
+ * Returns the internal timer service manager create by async state backend for the stream
+ * operator. This method returns null for non-keyed operators.
+ */
+ InternalTimeServiceManager<?> asyncInternalTimerServiceManager();
Review Comment:
> Are there cases in which an operator needs to use async timer service and sync timer service simultaneously?
No, it is up to the developer to decide which one to use.
This is to keep it consistent with the current `asyncStateBackend` and `KeyedStateBackend`, we will sort out the relationship between `asyncStateBackend`/`keyedStateBackend` and `asyncTimerManager`/`timerManager` in subsequent PR.
--
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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "Zakelly (via GitHub)" <gi...@apache.org>.
Zakelly commented on code in PR #25501:
URL: https://github.com/apache/flink/pull/25501#discussion_r1805992325
##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/StreamTaskStateInitializerImpl.java:
##########
@@ -241,33 +242,40 @@ public StreamOperatorStateContext streamOperatorStateContext(
streamTaskCloseableRegistry.registerCloseable(rawOperatorStateInputs);
// -------------- Internal Timer Service Manager --------------
+ // if the operator indicates that it is using custom raw keyed state,
+ // then whatever was written in the raw keyed state snapshot was NOT written
+ // by the internal timer services (because there is only ever one user of raw keyed
+ // state);
+ // in this case, timers should not attempt to restore timers from the raw keyed
+ // state.
+ final Iterable<KeyGroupStatePartitionStreamProvider> restoredRawKeyedStateTimers =
+ (prioritizedOperatorSubtaskStates.isRestored() && !isUsingCustomRawKeyedState)
+ ? rawKeyedStateInputs
+ : Collections.emptyList();
if (keyedStatedBackend != null) {
-
- // if the operator indicates that it is using custom raw keyed state,
- // then whatever was written in the raw keyed state snapshot was NOT written
- // by the internal timer services (because there is only ever one user of raw keyed
- // state);
- // in this case, timers should not attempt to restore timers from the raw keyed
- // state.
- final Iterable<KeyGroupStatePartitionStreamProvider> restoredRawKeyedStateTimers =
- (prioritizedOperatorSubtaskStates.isRestored()
- && !isUsingCustomRawKeyedState)
- ? rawKeyedStateInputs
- : Collections.emptyList();
-
timeServiceManager =
timeServiceManagerProvider.create(
environment.getMetricGroup().getIOMetricGroup(),
keyedStatedBackend,
+ keyedStatedBackend.getKeyGroupRange(),
+ environment.getUserCodeClassLoader().asClassLoader(),
+ keyContext,
+ processingTimeService,
+ restoredRawKeyedStateTimers,
+ cancellationContext);
+ }
+ if (asyncKeyedStateBackend != null) {
Review Comment:
How about this:
```
if (stateBackend.supportsAsyncKeyedStateBackend()) {
asyncTimeServiceManager =
timeServiceManagerProvider.create(xxxxxxx);
} else {
asyncTimeServiceManager = timeServiceManager;
}
```
In case `AsyncKeyedStateBackendAdaptor` is used, there is no need to create another `timeServiceManager`.
--
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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "Zakelly (via GitHub)" <gi...@apache.org>.
Zakelly commented on code in PR #25501:
URL: https://github.com/apache/flink/pull/25501#discussion_r1805798857
##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/AbstractStreamOperatorV2.java:
##########
@@ -220,7 +220,7 @@ public void initializeState(StreamTaskStateInitializer streamTaskStateManager)
isUsingCustomRawKeyedState());
stateHandler = new StreamOperatorStateHandler(context, getExecutionConfig(), cancelables);
- timeServiceManager = context.internalTimerServiceManager();
+ timeServiceManager = context.asyncInternalTimerServiceManager();
Review Comment:
I think this is not true. We'd better keep `context.internalTimerServiceManager` here, and re-assign `timeServiceManager` in `AbstractAsyncStateStreamOperatorV2` with `asyncInternalTimerServiceManager`.
--
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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #25501:
URL: https://github.com/apache/flink/pull/25501#issuecomment-2408387232
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "f8aef7729f7a9e19d709f502b22a0dbee1815a3c",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "f8aef7729f7a9e19d709f502b22a0dbee1815a3c",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* f8aef7729f7a9e19d709f502b22a0dbee1815a3c 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-35029][state/forst] Store timer in JVM heap when use async state backend [flink]
Posted by "yunfengzhou-hub (via GitHub)" <gi...@apache.org>.
yunfengzhou-hub commented on code in PR #25501:
URL: https://github.com/apache/flink/pull/25501#discussion_r1798718504
##########
flink-runtime/src/test/java/org/apache/flink/runtime/state/v2/AbstractKeyedStateTestBase.java:
##########
@@ -128,6 +133,18 @@ public boolean supportsAsyncKeyedStateBackend() {
public <K> AsyncKeyedStateBackend<K> createAsyncKeyedStateBackend(
KeyedStateBackendParameters<K> parameters) {
return new AsyncKeyedStateBackend<K>() {
+ @Nonnull
+ @Override
+ public <
+ T extends
+ HeapPriorityQueueElement & PriorityComparable<? super T>
+ & Keyed<?>>
+ KeyGroupedInternalPriorityQueue<T> create(
+ @Nonnull String stateName,
+ @Nonnull TypeSerializer<T> byteOrderedElementSerializer) {
+ return null;
Review Comment:
Might be better to `throw new UnsupportedOperationException();`
##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/StreamOperatorStateHandler.java:
##########
@@ -244,6 +244,11 @@ void snapshotState(
&& ((AbstractKeyedStateBackend<?>) keyedStateBackend)
.requiresLegacySynchronousTimerSnapshots(
checkpointOptions.getCheckpointType());
+ requiresLegacyRawKeyedStateSnapshots |=
+ keyedStateBackend instanceof AsyncKeyedStateBackend
+ && ((AsyncKeyedStateBackend<?>) keyedStateBackend)
+ .requiresLegacySynchronousTimerSnapshots(
Review Comment:
How about remove `AsyncKeyedStateBackend#requiresLegacySynchronousTimerSnapshots` and do the following
```java
// TODO remove this once heap-based timers are working with ForSt incremental snapshots!
requiresLegacyRawKeyedStateSnapshots |= keyedStateBackend instanceof AsyncKeyedStateBackend;
```
Or should subclasses like `AsyncKeyedStateBackendAdaptor` override this method?
--
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