Skip to content

Conversation

@tdas
Copy link
Contributor

@tdas tdas commented Sep 9, 2020

What changes were proposed in this pull request?

Make MicroBatchExecution explicitly call getBatch when the start and end offsets are the same.

Why are the changes needed?

Structured Streaming micro-batch engine has the contract with V1 data sources that, after a restart, it will call source.getBatch() on the last batch attempted before the restart. However, a very rare combination of sequences violates this contract. It occurs only when

  • The streaming query has specific types of stateful operations with watermarks (e.g., aggregation in append, mapGroupsWithState with timeouts).
    • These queries can execute a batch even without new data when the previous updates the watermark and the stateful ops are such that the new watermark can cause new output/cleanup. Such batches are called no-data-batches.
  • The last batch before termination was an incomplete no-data-batch. Upon restart, the micro-batch engine fails to call source.getBatch when attempting to re-execute the incomplete no-data-batch.

This occurs because no-data-batches has the same and end offsets, and when a batch is executed, if the start and end offset is same then calling source.getBatch is skipped as it is assumed the generated plan will be empty. This only affects V1 data sources which rely on this invariant to detect in the source whether the query is being started from scratch or restarted.

Does this PR introduce any user-facing change?

No

How was this patch tested?

New unit test with a mock v1 source that fails without the fix.

…with some stateful queries + no-data-batches + V1 sources

Make MicroBatchExecution explicitly call `getBatch` when the start and end offsets are the same.

Structured Streaming micro-batch engine has the contract with V1 data sources that, after a restart, it will call `source.getBatch()` on the last batch attempted before the restart. However, a very rare combination of sequences violates this contract. It occurs only when
- The streaming query has specific types of stateful operations with watermarks (e.g., aggregation in append, mapGroupsWithState with timeouts).
    - These queries can execute a batch even without new data when the previous updates the watermark and the stateful ops are such that the new watermark can cause new output/cleanup. Such batches are called no-data-batches.
- The last batch before termination was an incomplete no-data-batch. Upon restart, the micro-batch engine fails to call `source.getBatch` when attempting to re-execute the incomplete no-data-batch.

This occurs because no-data-batches has the same and end offsets, and when a batch is executed, if the start and end offset is same then calling `source.getBatch` is skipped as it is assumed the generated plan will be empty. This only affects V1 data sources which rely on this invariant to detect in the source whether the query is being started from scratch or restarted.

No

New unit test with a mock v1 source that fails without the fix.

Closes apache#29696 from tdas/SPARK-32794-3.0.

Authored-by: Tathagata Das <[email protected]>
Signed-off-by: Tathagata Das <[email protected]>
@SparkQA
Copy link

SparkQA commented Sep 10, 2020

Test build #128472 has finished for PR 29700 at commit 01f16e6.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@tdas tdas closed this Sep 10, 2020
@tdas tdas reopened this Sep 10, 2020
Copy link
Member

@zsxwing zsxwing left a comment

Choose a reason for hiding this comment

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

LGTM

asfgit pushed a commit that referenced this pull request Sep 11, 2020
…with some stateful queries + no-data-batches + V1 sources

### What changes were proposed in this pull request?

Make MicroBatchExecution explicitly call `getBatch` when the start and end offsets are the same.

### Why are the changes needed?

Structured Streaming micro-batch engine has the contract with V1 data sources that, after a restart, it will call `source.getBatch()` on the last batch attempted before the restart. However, a very rare combination of sequences violates this contract. It occurs only when
- The streaming query has specific types of stateful operations with watermarks (e.g., aggregation in append, mapGroupsWithState with timeouts).
    - These queries can execute a batch even without new data when the previous updates the watermark and the stateful ops are such that the new watermark can cause new output/cleanup. Such batches are called no-data-batches.
- The last batch before termination was an incomplete no-data-batch. Upon restart, the micro-batch engine fails to call `source.getBatch` when attempting to re-execute the incomplete no-data-batch.

This occurs because no-data-batches has the same and end offsets, and when a batch is executed, if the start and end offset is same then calling `source.getBatch` is skipped as it is assumed the generated plan will be empty. This only affects V1 data sources which rely on this invariant to detect in the source whether the query is being started from scratch or restarted.
### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

New unit test with a mock v1 source that fails without the fix.

Closes #29700 from tdas/SPARK-32794-2.4.

Authored-by: Tathagata Das <[email protected]>
Signed-off-by: Tathagata Das <[email protected]>
@tdas tdas closed this Sep 11, 2020
@dongjoon-hyun
Copy link
Member

Thank you, @tdas and @zsxwing .
cc @HeartSaVioR

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.

4 participants