[STRMHELP-197] Update Global Watermark When Idle#61
Conversation
| } | ||
| WatermarkState ws = accumulator.get(value.id); | ||
| if (ws == null) { | ||
| accumulator.put(value.id, ws = new WatermarkState()); |
There was a problem hiding this comment.
Should we also reset the WatermarkState for the idle subtask (inside if (value.noOp) )?
There was a problem hiding this comment.
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.
|
@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(); | ||
|
|
| globalWatermark = watermarkTracker.getWatermark(); | ||
| LOG.info( | ||
| "WatermarkSyncCallback subtask: {} is idle", | ||
| indexOfThisConsumerSubtask); |
There was a problem hiding this comment.
can you log lastGlobalWatermark, globalWatermark and isIdle values here.
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
can you log
lastGlobalWatermark,globalWatermarkandisIdlevalues 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.
There was a problem hiding this comment.
Also, how about we add more logs at [1] ? Primarily, important state values of
lastEmittedRecordWatermarkandlastWatermarkAlso, would be great if we can publish a metric at [1] the first time we set
isIdleto Truefor (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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
[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.
|
The changes LGTM! Left few comments on adding more logs and syncing the global watermark based on user provided config. |
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 |
|
/PTAL @maghamravi |
|
LGTM! |
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 introductionor[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 verifypasses. 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:)
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:)
Does this pull request potentially affect one of the following parts:
@Public(Evolving): (yes / no)Documentation