Skip to content

[STRMHELP-197] Update Global Watermark When Idle#61

Merged
sethsaperstein-lyft merged 8 commits into
release-1.13-lyftfrom
STRMHELP-197_update_idle_global_watermark
Sep 1, 2022
Merged

[STRMHELP-197] Update Global Watermark When Idle#61
sethsaperstein-lyft merged 8 commits into
release-1.13-lyftfrom
STRMHELP-197_update_idle_global_watermark

Conversation

@sethsaperstein-lyft
Copy link
Copy Markdown

@sethsaperstein-lyft sethsaperstein-lyft commented Aug 18, 2022

overview

Update the global watermark for idle subtasks. This will avoid a deadlock state by enabling the RecordEmitter to emit records that were previously stuck in the emitQueue due to the lookahead. Emitting a record from the source will enable us to no longer be marked idle in the PeriodicWatermarkEmitter.

additional info

To get the global watermark, we need to communicate with the JM. The JobManagerWatermarkTracker is a WatermarkTracker that uses a GlobalAggregateManager to do so. This interface has 1 method updateGlobalAggregate. In order to get the global watermark without updating with the local watermark, and thus holding other subtasks back, we've modified the WatermarkAggregateFunction used by the GlobalAggregateManager to avoid updating the watermark value and lastUpdated value for the subtask by indicating a noOp field. Thus, when calculating the global watermark, the accumulator has not been modified.

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. 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 Travis CI to do that following this guide.

  • 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

(For example: This pull request makes task deployment go through the blob server, rather than through RPC. That way we avoid re-transferring them on each deployment (during recovery).)

Brief change log

(for example:)

  • The TaskInfo is stored in the blob store on job creation time as a persistent artifact
  • Deployments RPC transmits only the blob storage reference
  • TaskManagers retrieve the TaskInfo from the blob cache

Verifying this change

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (100MB)
  • Extended integration test for recovery after master (JobManager) failure
  • Added test that validates that TaskInfo is transferred only once across recoveries
  • Manually verified the change by running a 4 node cluser with 2 JobManagers and 4 TaskManagers, a stateful streaming program, and killing one JobManager and two TaskManagers during the execution, verifying that recovery happens correctly.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (yes / no)
  • The serializers: (yes / no / don't know)
  • The runtime per-record code paths (performance sensitive): (yes / no / don't know)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (yes / no / don't know)
  • The S3 file system connector: (yes / no / don't know)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

}
WatermarkState ws = accumulator.get(value.id);
if (ws == null) {
accumulator.put(value.id, ws = new WatermarkState());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should we also reset the WatermarkState for the idle subtask (inside if (value.noOp) )?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This would reset the state for the local watermark of the subtask to WatermarkState's default watermark which is Long.MIN_VALUE. I think it's best to leave its local watermark as is, especially since the local watermark does not change when idle.

@premsantosh
Copy link
Copy Markdown

@sethsaperstein-lyft thanks for this amazing contribution. Can you just setup sometime with the reviews to go over the PR (since this seems very involved)? And make sure to ask everyone to review the PR before the meeting.

public abstract long updateWatermark(final long localWatermark);

public abstract long getWatermark();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nice !

globalWatermark = watermarkTracker.getWatermark();
LOG.info(
"WatermarkSyncCallback subtask: {} is idle",
indexOfThisConsumerSubtask);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can you log lastGlobalWatermark, globalWatermark and isIdle values here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also, how about we add more logs at [1] ? Primarily, important state values of lastEmittedRecordWatermark and lastWatermark

Also, would be great if we can publish a metric at [1] the first time we set isIdle to True

for (Map.Entry<Integer, ShardWatermarkState> e : shardWatermarks.entrySet()) {
            Watermark w = e.getValue().lastEmittedRecordWatermark;
            // consider only active shards, or those that would advance the watermark
            if (w != null
                    && (e.getValue().lastUpdated >= idleTime
                            || e.getValue().emitQueue.getSize() > 0
                            || w.getTimestamp() > lastWatermark)) {

[1]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

can you log lastGlobalWatermark, globalWatermark and isIdle values here.
Check out ln 1279. That logs local, global, delta, timeouts, queues, and queue sizes. Logging here would be redundant I believe. I will add isIdle to that log though.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Also, how about we add more logs at [1] ? Primarily, important state values of lastEmittedRecordWatermark and lastWatermark

Also, would be great if we can publish a metric at [1] the first time we set isIdle to True

for (Map.Entry<Integer, ShardWatermarkState> e : shardWatermarks.entrySet()) {
            Watermark w = e.getValue().lastEmittedRecordWatermark;
            // consider only active shards, or those that would advance the watermark
            if (w != null
                    && (e.getValue().lastUpdated >= idleTime
                            || e.getValue().emitQueue.getSize() > 0
                            || w.getTimestamp() > lastWatermark)) {

[1]

love the idea of logging the state. Would have been very useful.

With regards to the metric for the first time isIdle is true, it seems like this happens too infrequently to warrant a metric. Seems more fitting for the existing log. That being said, I do think there is an issue with the logger here as even with my test with FlinkPerf and EventPersister had issues. I slept the thread that polls from kinesis and I knew the subtask was marked idle due to the WatermarkSyncCallback log "WatermarkSyncCallback: subtask 0 is idle", but never saw the log from the PeriodicWatermarkEmitter "No active shard for subtask 0, marking the source idle.". I'll have to run it by you but there's something going on here with the PeriodicWatermarkEmitter being on a timer and referencing the KinesisDataFetcher, who owns the emitWatermark function which is supposed to log the idle subtask.

Copy link
Copy Markdown

@maghamravi maghamravi Aug 23, 2022

Choose a reason for hiding this comment

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

My idea is to add an alert based on the metric. TTD and TTR is critical and metrics are a great way to notify us quicker.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

agreed. I've added an isIdle metric in the PeriodicWatermarkEmitter and we can write the prom query to detect a 0 to 1 change

globalWatermark = watermarkTracker.updateWatermark(nextWatermark);
propagatedLocalWatermark = nextWatermark;
} else {
globalWatermark = watermarkTracker.getWatermark();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[suggest] For a faster rollback strategy, how about we wrap this code based on a ConsumerConfig, say, flink.watermark.sync.global ? To begin, we can have it set to True for zippy jobs.

@maghamravi
Copy link
Copy Markdown

The changes LGTM! Left few comments on adding more logs and syncing the global watermark based on user provided config.

@sethsaperstein-lyft
Copy link
Copy Markdown
Author

@sethsaperstein-lyft thanks for this amazing contribution. Can you just setup sometime with the reviews to go over the PR (since this seems very involved)? And make sure to ask everyone to review the PR before the meeting.

Absolutely! I'll try to set it up for early next week, post brownbag, since the brownbag will discuss the inner workings of the FlinkKinesisConsumer. We'll record so you don't miss it

@sethsaperstein-lyft
Copy link
Copy Markdown
Author

/PTAL @maghamravi

@maghamravi
Copy link
Copy Markdown

LGTM!

@sethsaperstein-lyft sethsaperstein-lyft merged commit 8733b7b into release-1.13-lyft Sep 1, 2022
@sethsaperstein-lyft sethsaperstein-lyft deleted the STRMHELP-197_update_idle_global_watermark branch September 1, 2022 03:45
@sethsaperstein-lyft sethsaperstein-lyft restored the STRMHELP-197_update_idle_global_watermark branch September 1, 2022 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants