Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-18119][table-runtime-blink] Retract old records in time range … #12680

Closed
wants to merge 7 commits into from

Conversation

hyeonseop-lee
Copy link
Contributor

…bounded preceding functions

What is the purpose of the change

This fixes a bug in time range bounded preceding functions that the old records that is no longer required are retracted only if a new record with the same key comes in. This prevents unlimitedly growing state especially when the keyspace mutates over time.

Brief change log

  • Register retract timer when new record comes in
  • Retract all records when the timer fires and no more record has came in

Verifying this change

This change is already covered by existing tests, such as OverWindowITCase.

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): yes
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, 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

@flinkbot
Copy link
Collaborator

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Automated Checks

Last check on commit a71ca38 (Tue Jun 16 11:22:27 UTC 2020)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!

Mention the bot in a comment to re-run the automated checks.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

Please see the Pull Request Review Guide for a full explanation of the review process.


The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

@flinkbot
Copy link
Collaborator

flinkbot commented Jun 16, 2020

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run travis re-run the last Travis build
  • @flinkbot run azure re-run the last Azure build

@KurtYoung
Copy link
Contributor

Thanks for your contribution, could you add a unit test to this issue? This can help ensuring we don't introduce this bug again in the future.

@hyeonseop-lee
Copy link
Contributor Author

@KurtYoung Added unit tests and verified the tests fail without fix.

Copy link
Contributor

@KurtYoung KurtYoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I'm not super familiar with over aggregate, cc @wuchong to give another review.

Copy link
Member

@libenchao libenchao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@protos37 Thanks for you contribution, the changes LGTM generally, only left some minor comments.
And let's wait for @wuchong 's final review.

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great work @protos37 , nice catch! The changes looks good to me in general.

But I would like to go further with this PR. Actually, I don't think we need state ttl (The TableConfig.setIdleStateRetentionTime) for the bounded over aggregates. A bounded over aggregate is just like a processing/event-time interval join or window aggregation, the state size is bounded and stable. The operator should expire state automantically without lossing correctness. We also didn't introduce state ttl for interval join and window aggregation. Therefore, I think we can remove the state ttl logic in ProcTimeRangeBoundedPrecedingFunction and ProcTimeRowsBoundedPrecedingFunction, that means they shouldn't extend KeyedProcessFunctionWithCleanupState. What do you think?

@hyeonseop-lee
Copy link
Contributor Author

@wuchong Considering the cases you've mentioned it totally makes sense to me to remove the state ttl from time range bounded over aggregations. Thank you for opinion and I'd be glad to work on that.

// update timestamp and register timer if needed
Long curCleanupTimestamp = cleanupTsState.value();
if (curCleanupTimestamp == null || curCleanupTimestamp < cleanupTimestamp) {
// we don't delete existing timer since it may delete timer for data processing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may cause some performance problem if we register a timer for each record, because each timer is an entry in this state. A better solution might be to use AbstractStreamOperator provides InternalTimerService which can register timer by namespace. We can separate the namespace between cleanup and data processing.

Besides, it would also be better if we can make the cleanup timestamp in a range instead of a point, e.g. if the current cleanup timer is in (timestamp + precedingOffset, precedingOffset + precedingOffset * 1.5) (similar to CleanupState#registerProcessingCleanupTimer) , then we don't need to register a new one. This can avoid to remove/register for each record and be friendly to statebackend.

This might be a big refactoring. Thus I'm fine to add TODO comment here and create a following issue to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About having cleanup timestamp as range, if I understood correctly, it seems to be about tradeoff between immediate state reduction and timer related overhead. While we don't have specific criteria like maxRetentionTime, how can we choose the appropriate generosity for cleanup? Is it okay to go for 1.5 times as you mentioned?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is a tradeoff to avoid too many timers. But the 1.5 times is up to discuss.

@hyeonseop-lee
Copy link
Contributor Author

@wuchong Applied ranged timer timestamp. For the timer namespace it seems to be a big refactoring as you said so left it as TODO.

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updating. LGTM.

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, we need to update OverWindowHarnessTest because we changed the state TTL behavior, otherwise, the tests are failed.

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to merge when build is passed.

@hyeonseop-lee
Copy link
Contributor Author

It seems that the e2e test has failed by timeout. Is there anything I can do?

@wuchong
Copy link
Member

wuchong commented Jun 19, 2020

You can rebase to master and push force to trigger the build again.

wuchong pushed a commit to wuchong/flink that referenced this pull request Jun 19, 2020
…for time range bounded over aggregation

This changes the state expiration behavior for RowTimeRangeBoundedPrecedingFunction and ProcTimeRangeBoundedPrecedingFunction. In the previous version, we use TableConfig.setIdleStateRetentionTime to cleanup state when it is idle for some time. However, a bounded over aggregation is just like a processing/event-time interval join or window aggregation, the state size should be bounded and stable. The operator should expire state automatically based on watermark and processing time without losing correctness.

This closes apache#12680
@hyeonseop-lee
Copy link
Contributor Author

Rebased and force pushed to branch... Hope it didn't break anything you were doing?

@wuchong
Copy link
Member

wuchong commented Jun 20, 2020

@wuchong
Copy link
Member

wuchong commented Jun 20, 2020

Will merge it.

@wuchong wuchong closed this in 22abfe2 Jun 20, 2020
wuchong pushed a commit that referenced this pull request Jun 20, 2020
…for time range bounded over aggregation

This changes the state expiration behavior for RowTimeRangeBoundedPrecedingFunction and ProcTimeRangeBoundedPrecedingFunction. In the previous version, we use TableConfig.setIdleStateRetentionTime to cleanup state when it is idle for some time. However, a bounded over aggregation is just like a processing/event-time interval join or window aggregation, the state size should be bounded and stable. The operator should expire state automatically based on watermark and processing time without losing correctness.

This closes #12680
@hyeonseop-lee hyeonseop-lee deleted the flink-18119 branch June 23, 2020 08:43
zhangjun0x01 pushed a commit to zhangjun0x01/flink that referenced this pull request Jul 8, 2020
…for time range bounded over aggregation

This changes the state expiration behavior for RowTimeRangeBoundedPrecedingFunction and ProcTimeRangeBoundedPrecedingFunction. In the previous version, we use TableConfig.setIdleStateRetentionTime to cleanup state when it is idle for some time. However, a bounded over aggregation is just like a processing/event-time interval join or window aggregation, the state size should be bounded and stable. The operator should expire state automatically based on watermark and processing time without losing correctness.

This closes apache#12680
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants