Skip to content

Conversation

@smattheis
Copy link
Contributor

What is the purpose of the change

Brief change log

  • Revised SplitFetcher threading model and add support to pause/resume SplitFetcher
  • Adds support for watermark alignment of individual source splits controlled by SourceOperator
  • Adds support for split watermark alignment for Kafka and Pulsar sources
  • Adds configuration parameter to allow unaligned splits as migration plan to support legacy sources that lack support for split alignment

Verifying this change

This change added and extended tests and can be verified as follows:

  • SplitFetcherTest extended to test pause/resume ofSplitFetcher
  • SourceOperatorSplitWatermarkAlignmentTest added to test split alignment based on split reader watermarks
  • SplitFetcherPauseResumeSplitReaderITCase added to test pause/resume of individual split readers

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): yes (according to FLIP-217)
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? docs (configuration parameter) and JavaDocs (changes of public APIs)

@flinkbot
Copy link
Collaborator

flinkbot commented Aug 7, 2022

CI report:

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

Copy link
Contributor

@mas-chen mas-chen left a comment

Choose a reason for hiding this comment

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

I did a quick first pass and still need to look deeper into the SplitFetcher changes. Lots of code changes! Do we have performance tests with analysis on the split fetcher changes, even without split alignment enabled?

<td>Whether name of vertex includes topological index or not. When it is true, the name will have a prefix of index of the vertex, like '[vertex-0]Source: source'. It is false by default</td>
</tr>
<tr>
<td><h5>pipeline.watermark-alignment.allow-unaligned-source-splits</h5></td>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think allow-aligned-source-splits is more intuitive. The emphasis is on alignment, rather than unalignment like in checkpoints.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO something like source.reader.synchronize.splits would be more understandable for users.


public void addPrefilledSplitsSingleReader(int numSplits, int numRecords) {
sourceReader.addSplits(createPrefilledSplits(numSplits, numRecords));
sourceReader.notifyNoMoreSplits();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a required assumption? We should also exercise the case where splits are dynamically discovered (e.g. Kafka source topic partition discovery).

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not required. The signal simply allows for a clean shutdown of the source.

Copy link
Contributor

@mxm mxm left a comment

Choose a reason for hiding this comment

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

Thank you @smattheis @AHeise @dawidwys! The changes definitely fill a gap in the source framework. There are a lot of changes here which are not always directly related to FLIP-217 like the refactoring of the threading and locking logic. Ideally, this could have done more incremental but I understand that was difficult due to the multiple authors.

I've left some comments and suggestions. All in all, the changes look good.

I wonder about the way the SourceOperator calls through the stack via pauseOrResumeSplits while also being called back with watermarks. My intuition would have been to do the pausing directly at the splits based on the current max watermark lag, e.g. by putting splits into a suspended mode where no more output is accepted from a split. I guess this could be tricky because the implementation of the source doesn't necessarily know it's paused and could timeout or otherwise misbehave. So it looks like the current implementation is simpler.

Collection<PulsarPartitionSplit> splitsToPause,
Collection<PulsarPartitionSplit> splitsToResume) {
if (splitsToPause.size() > 1 || splitsToResume.size() > 1) {
throw new IllegalStateException("This pulsar split reader only support one split.");
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why we can't pause single splits. Even if so, I don't know why that should leak to the Pulsar reader.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question...

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you found an answer for that @mxm ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, Pulsar splits are always started in a separate fetcher thread. We still want to be able to pause these split threads. So the code makes sense.

@mxm
Copy link
Contributor

mxm commented Aug 29, 2022

Any thoughts on how and when to proceed with this PR? We'd like to help to bring this over the finish line.

@pnowojski
Copy link
Contributor

I wonder about the way the SourceOperator calls through the stack via pauseOrResumeSplits while also being called back with watermarks. My intuition would have been to do the pausing directly at the splits based on the current max watermark lag, e.g. by putting splits into a suspended mode where no more output is accepted from a split. I guess this could be tricky because the implementation of the source doesn't necessarily know it's paused and could timeout or otherwise misbehave. So it looks like the current implementation is simpler.

Currently Splits are just pojos, data carriers, without much logic. If I understand you correctly, what you are suggesting would require us to push some availability logic down to the splits and it would still require handling of this availability in the SourceReader - basically the same logic that we have in the current proposal. The difference would be only that SourceReader would be informed about (un)availability change of a split, from the split, instead of from the pauseOrResume call.

Given that most of the users are expected to just use SourceReaderBase, the current proposal gives them watermark alignment for free. While adding availability logic to the splits would increase exposure of this feature in the public API, without much benefit?

Any thoughts on how and when to proceed with this PR? We'd like to help to bring this over the finish line.

Indeed there is an issue now, that I think @smattheis doesn't work on Flink anymore, so he can not finish this PR. I will go through the PR myself and do a quick pass/respond to the inlined questions from you @mxm and @mas-chen , but it would be great if someone could take over applying the actual changes after the review. Would you be up to do that @mxm ?

Collection<PulsarPartitionSplit> splitsToPause,
Collection<PulsarPartitionSplit> splitsToResume) {
if (splitsToPause.size() > 1 || splitsToResume.size() > 1) {
throw new IllegalStateException("This pulsar split reader only support one split.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Good question...

Copy link
Contributor

@mxm mxm left a comment

Choose a reason for hiding this comment

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

@pnowojski Thank you for the comments. If nobody of the authors currently has time to work on this, I can take over the PR for now. I'd be glad to get another review from @mas-chen and you once I've addressed the comments.

Copy link
Contributor

@pnowojski pnowojski left a comment

Choose a reason for hiding this comment

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

If nobody of the authors currently has time to work on this, I can take over the PR for now.

That would be great :)

@mxm mxm force-pushed the flip-217-split-wm-alignment branch from f9b2e3b to a9246bd Compare September 7, 2022 15:02
Copy link
Contributor

@pnowojski pnowojski 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 update @mxm , I've left a couple of minor comments.

The next question would be how to squash the commits? If you want to preserve authorship of your changes @mxm, without overwriting authors of the base commits, we would need either a single fixup commit from you, all one your fixup per original commit.

@mxm
Copy link
Contributor

mxm commented Sep 8, 2022

The next question would be how to squash the commits? If you want to preserve authorship of your changes @mxm, without overwriting authors of the base commits, we would need either a single fixup commit from you, all one your fixup per original commit.

I'd prefer this to be a single suqashed commit with the use of Co-Authored-By. IMHO there is no benefit in merging the individual commits because they are very much tight to each other. This keeps the history clean while retaining authorship. What do you think?

@pnowojski
Copy link
Contributor

I'd prefer this to be a single suqashed commit with the use of Co-Authored-By. IMHO there is no benefit in merging the individual commits because they are very much tight to each other. This keeps the history clean while retaining authorship. What do you think?

I wouldn't squash all commits into one. The original commits authored by Sebastian, Dawid and Arvid I think are nicely separated. But sure, squashing your fixups to those commits and co-authoring them is also perfectly fine.

@mxm
Copy link
Contributor

mxm commented Sep 8, 2022

I wouldn't squash all commits into one. The original commits authored by Sebastian, Dawid and Arvid I think are nicely separated. But sure, squashing your fixups to those commits and co-authoring them is also perfectly fine.

If the commits are nicely separated, why were they not handled in separate PRs? Anyhow, I'm ok with just putting my changes in a single commit on top of those.

@mxm mxm force-pushed the flip-217-split-wm-alignment branch from cd9ce51 to c2408e3 Compare September 8, 2022 13:51
@mxm
Copy link
Contributor

mxm commented Sep 8, 2022

@flinkbot run azure

Copy link
Contributor

@pnowojski pnowojski left a comment

Choose a reason for hiding this comment

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

We are often splitting larger features into smaller commits for the sake of easier reviewing. As long as commits are independently working, and coherent (one need to find a sensible division) that's fine.

https://flink.apache.org/contributing/code-style-and-quality-pull-requests.html#separate-refactoring-cleanup-and-independent-changes

It gets more complicated in those rare cases where there are various authors, especially if someone takes over an orphaned PR. 🤷

LGTM assuming green azure.

Thanks a lot @mxm for driving this forward! Much appreciated. Thank you @dawidwys, @AHeise , @smattheis for your contributions as well!

@smattheis
Copy link
Contributor Author

@mxm Thanks a lot also from my side for you contributions. However, @pnowojski this PR was not orphaned! (I wrote to you that I'm on vacations.)

@mxm
Copy link
Contributor

mxm commented Sep 8, 2022

Thank you @pnowojski for your thoughtful comments and guidance. And of course thanks to the original authors @AHeise @dawidwys @smattheis.

Whoops @smattheis I had assumed you wouldn't continue on this PR but I think no harm has been done. Let me know if anything is open on your side. It still need to revise the code with respect to a test failure.

@pnowojski
Copy link
Contributor

@mxm Thanks a lot also from my side for you contributions. However, @pnowojski this PR was not orphaned! (I wrote to you that I'm on vacations.)

Yes, sorry for the mental shortcut. There was a delay in the communication between first my vacations and then yours. Around the time @mxm was asking how to continue with this PR, you @smattheis were not responding, and I got a message from you that you can work on it only after @mxm has already volunteered to take it over. After that I didn't want to create more confusion. But sorry for my inaccurate statement that it was "orphaned" :)

@smattheis
Copy link
Contributor Author

@mxm @pnowojski All good. Thanks for driving it.

@mxm mxm force-pushed the flip-217-split-wm-alignment branch 2 times, most recently from ff462cd to 22db9b0 Compare September 9, 2022 13:17
@mxm
Copy link
Contributor

mxm commented Sep 9, 2022

(Rebased)

@mxm
Copy link
Contributor

mxm commented Sep 9, 2022

@flinkbot run azure

@pnowojski
Copy link
Contributor

There are still some related test failures:

Documented option pipeline.watermark-alignment.allow-unaligned-source-splits does not exist.

and

Sep 09 15:10:03 [ERROR] Errors:
Sep 09 15:10:03 [ERROR] PulsarUnorderedSourceReaderTest.supportsPausingOrResumingSplits(PulsarSourceReaderBase, Boundedness, String)[1] » Timeout
Sep 09 15:10:03 [ERROR] PulsarUnorderedSourceReaderTest.supportsPausingOrResumingSplits(PulsarSourceReaderBase, Boundedness, String)[2] » Timeout

@mxm
Copy link
Contributor

mxm commented Sep 12, 2022

Thanks @pnowojski. Will fix those.

On another note, do you think it makes sense to add a configuration option to disable using split alignment entirely? I'm a bit worried this feature might cause issues with the already integrated Kafka/Pulsar sources that we are not foreseeing right now. The added configuration option only allows to disable split alignments for non-compatible connectors. We could add another option to disable it entirely to retain the old behavior (disabled by default).

@mxm mxm force-pushed the flip-217-split-wm-alignment branch from 22db9b0 to d6aed81 Compare September 12, 2022 10:58
@mxm
Copy link
Contributor

mxm commented Sep 12, 2022

There are still some related test failures:

Documented option pipeline.watermark-alignment.allow-unaligned-source-splits does not exist.

I had to remove the @Deprecated flag from the configuration option. Otherwise, it will be undocumented.

@mxm mxm force-pushed the flip-217-split-wm-alignment branch from d6aed81 to 546fc79 Compare September 12, 2022 10:59
@mxm
Copy link
Contributor

mxm commented Sep 12, 2022

@flinkbot run azure

@pnowojski
Copy link
Contributor

On another note, do you think it makes sense to add a configuration option to disable using split alignment entirely? I'm a bit worried this feature might cause issues with the already integrated Kafka/Pulsar sources that we are not foreseeing right now. The added configuration option only allows to disable split alignments for non-compatible connectors. We could add another option to disable it entirely to retain the old behavior (disabled by default).

Does it make sense to use and enable watermark alignment via DataStream API to only disable it via config value? Keep in mind that user has to manually enable via WatermarkStrategy#withWatermarkAlignment call [1].

[1] https://nightlies.apache.org/flink/flink-docs-master/docs/dev/datastream/event-time/generating_watermarks/#watermark-alignment-_beta_

Arvid Heise and others added 8 commits September 13, 2022 13:00
Instead of mixing 4 different concepts of synchronization, this commit aims to have one lock for everything and go through with it.
When there is only one SplitFetcher per split, the split advanced too much, and aligned event time is enabled, then the complete SplitFetcher can be paused by SplitFetcherManager#alignSplits, such that temporarily no more records are read from the respective split.
…dual splits

This provides support for pausing and resuming individual splits in SourceReaderBase. This is used to align individual splits based on emitted watermarks in SourceOperator.
@mxm mxm force-pushed the flip-217-split-wm-alignment branch from 546fc79 to 991230a Compare September 13, 2022 11:21
@mxm
Copy link
Contributor

mxm commented Sep 13, 2022

Fair point, users may modify the job to disable alignment. It doesn't make sense to override the watermark alignment settings from the config. But the same argument applies to the other configuration option to disable split alignment for not-ready sources. I think it would make sense to provide a transitory option to disable split alignment altogether until this feature has proven to be stable.

@mxm
Copy link
Contributor

mxm commented Sep 13, 2022

@flinkbot run azure

@mxm
Copy link
Contributor

mxm commented Sep 13, 2022

Tests are passing now.

@mxm mxm merged commit 0612a99 into apache:master Sep 14, 2022
@mxm
Copy link
Contributor

mxm commented Sep 14, 2022

Thank you everyone!

@dawidwys
Copy link
Contributor

dawidwys commented Sep 14, 2022

Thank you for helping getting it over the line! @mxm

@tweise
Copy link
Contributor

tweise commented Sep 14, 2022

Exciting to see this make the finish line! This was a long awaited feature (we implemented alignment for the Kinesis source ~4 years ago). Let's see how it holds up in production use cases!

Thanks @mxm @pnowojski @smattheis @dawidwys, @AHeise for your contributions!

@pnowojski
Copy link
Contributor

Yes, it took longer than it should have. Good that it's finally been merged 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants