release-22.2: changefeedccl: flush to sink before initial_scan_only completion #90277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport 1/1 commits from #90241 on behalf of @samiskin.
/cc @cockroachdb/release
Resolves #90146
Previously if a changefeed was started with initial_scan_only, the job would be completed as soon as a resolved event was seen by the kv_feed even though we may not have flushed the messages to the sink yet. This could result in a huge difference where an initial_scan_only changefeed on a 100000 row table could complete successfully with a kafka topic only seeing <2000 messages. A similar issue of missing messages would also occur with schema_change_policy='stop', though the changefeed is marked failed in that case.
This change ensures the changefeed drains the eventProducer and sink upon a normal kvfeed exit.
This also uncovered a bug in the chunked_event_queue where empty() could return true even if there were many remaining messages due to the first chunk being empty but there still being future chunks.
Release note (bug fix): initial_scan_only changefeeds now ensure that all messages have successfully flushed to the sink prior to completion instead of potentially missing messages.
Release justification: high priority and very low risk bug fix