Fix Spark change feed hang after partition splits - #49883
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf290159-a5da-42bd-ac20-662075b01169
|
Azure Pipelines: Successfully started running 2 pipeline(s). 33 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf290159-a5da-42bd-ac20-662075b01169
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf290159-a5da-42bd-ac20-662075b01169
|
/azp run java - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run java - spark - tests |
|
No pipelines are associated with this pull request. |
|
/azp run java - cosmos - spark |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf290159-a5da-42bd-ac20-662075b01169
|
Azure Pipelines: Successfully started running 2 pipeline(s). 32 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run java - cosmos - spark |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
No pipelines are associated with this pull request. |
|
/azp run java - cosmos - tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR fixes a Spark Cosmos change-feed hang that can occur after partition splits when cached parent feed-range metadata is stale and the service returns a composite FromNow continuation with child ranges at different LSNs. The planner now preserves and expands the composite continuation into child-specific metadata so each child is bounded independently, while keeping the persisted ChangeFeedOffset v1 model unchanged.
Changes:
- Preserve the full service-issued
FromNowcontinuation and split composite continuation state into per-effective-rangePartitionMetadata. - Update the partition planner to expand composite latest metadata only for change-feed planning and to filter out-of-scope split children before planning.
- Add unit + live regression coverage for divergent child continuations and stale metadata after splits; update Spark connector changelogs across supported Spark variants.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos-spark_4-1_2-13/CHANGELOG.md | Document the bug fix for Spark 4.1 connector variant. |
| sdk/cosmos/azure-cosmos-spark_4-0_2-13/CHANGELOG.md | Document the bug fix for Spark 4.0 connector variant. |
| sdk/cosmos/azure-cosmos-spark_3-5_2-13/CHANGELOG.md | Document the bug fix for Spark 3.5 (Scala 2.13) connector variant. |
| sdk/cosmos/azure-cosmos-spark_3-5_2-12/CHANGELOG.md | Document the bug fix for Spark 3.5 (Scala 2.12) connector variant. |
| sdk/cosmos/azure-cosmos-spark_3-4_2-12/CHANGELOG.md | Document the bug fix for Spark 3.4 connector variant. |
| sdk/cosmos/azure-cosmos-spark_3-3_2-12/CHANGELOG.md | Document the bug fix for Spark 3.3 connector variant. |
| sdk/cosmos/azure-cosmos-spark_3/src/main/scala/com/azure/cosmos/spark/PartitionMetadata.scala | Add composite continuation expansion (splitByLatestLsn) and propagate per-range continuation state. |
| sdk/cosmos/azure-cosmos-spark_3/src/main/scala/com/azure/cosmos/spark/CosmosPartitionPlanner.scala | Expand composite metadata only for change feed, and filter expanded children by feed-range scope before planning. |
| sdk/cosmos/azure-cosmos-spark_3/src/main/scala/com/azure/cosmos/implementation/SparkBridgeImplementationInternal.scala | Add an overload to extract continuation tokens from a parsed ChangeFeedState. |
| sdk/cosmos/azure-cosmos-spark_3/src/test/scala/com/azure/cosmos/spark/SparkE2EChangeFeedSplitITest.scala | Add a live split regression with stale metadata and time-bounded collection to catch hangs. |
| sdk/cosmos/azure-cosmos-spark_3/src/test/scala/com/azure/cosmos/spark/PartitionMetadataSpec.scala | Add unit coverage for composite FromNow continuation preservation and per-range planning. |
| sdk/cosmos/azure-cosmos-spark_3/src/test/scala/com/azure/cosmos/spark/CosmosPartitionPlannerSpec.scala | Add planner regressions validating expansion behavior, filtering, reconciliation, and v1 offset preservation. |
Comments suppressed due to low confidence (1)
sdk/cosmos/azure-cosmos-spark_3/src/test/scala/com/azure/cosmos/spark/SparkE2EChangeFeedSplitITest.scala:327
- The
isPartitionKeyInRangemethod body is missing indentation, which makes the boolean expression harder to scan and is inconsistent with the rest of the file's formatting.
private def isPartitionKeyInRange(
effectiveRange: NormalizedRange,
targetRange: NormalizedRange
): Boolean = {
effectiveRange.min.compareTo(targetRange.min) >= 0 &&
effectiveRange.min.compareTo(targetRange.max) < 0
}
|
@sdkReviewAgent |
|
✅ Review complete (31:39) Posted 3 inline comment(s). Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf290159-a5da-42bd-ac20-662075b01169
|
/azp run java - cosmos - spark |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
…ts (#49943) * Release Cosmos Spark Connectors: 4.49.2 (hotfix) Updates all azure-cosmos-spark_* packages (3.3, 3.4, 3.5 for Scala 2.12, 3.5/4.0/4.1 for Scala 2.13) to 4.49.2 as a hotfix release. Promotes the bounded change feed hang fix (PR #49883) from the Unreleased 4.50.0-beta.1 section into the 4.49.2 (2026-07-27) hotfix release across all CHANGELOGs, and updates the compatibility matrix and download coordinates in each README plus the shared quick-start doc. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Fix stale dependency version pins in fabric-auth/sample poms Comparing against the prior Spark hotfix release (commit 808435c), these three poms depend on the released azure-cosmos-spark connector version via x-version-update/x-include-update tags and were missed in the initial hotfix commit: - fabric-cosmos-spark-auth_3/pom.xml (azure-cosmos-spark_3-5_2-12) - fabric-cosmos-spark-auth_4-0_2-13/pom.xml (azure-cosmos-spark_4-0_2-13) - azure-cosmos-spark-account-data-resolver-sample/pom.xml (azure-cosmos-spark_3-5_2-12) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Description
Fixes a Spark change-feed hang that can occur when cached feed-range metadata still references a parent range after it splits. A stale-parent
FromNowresponse can contain child continuations at different LSNs; collapsing that composite state to one scalar bound can make the lower-LSN child wait indefinitely for an unreachable end LSN.The planner now retains the full service-issued
FromNowcontinuation internally, expands composite state into child-specific partition metadata, and computes each child bound independently. The persistedChangeFeedOffsetv1 checkpoint model and serialization remain unchanged.Coverage includes a unit regression for divergent child continuations and a live split regression using a deliberately stale metadata refresh interval with writes advancing only one child.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines