Skip to content

Fix Spark change feed hang after partition splits - #49883

Merged
tvaron3 merged 5 commits into
Azure:mainfrom
tvaron3:tomasvaron-microsoft-fix-spark-change-feed-split-hang
Jul 24, 2026
Merged

Fix Spark change feed hang after partition splits#49883
tvaron3 merged 5 commits into
Azure:mainfrom
tvaron3:tomasvaron-microsoft-fix-spark-change-feed-split-hang

Conversation

@tvaron3

@tvaron3 tvaron3 commented Jul 22, 2026

Copy link
Copy Markdown
Member

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 FromNow response 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 FromNow continuation internally, expands composite state into child-specific partition metadata, and computes each child bound independently. The persisted ChangeFeedOffset v1 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:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bf290159-a5da-42bd-ac20-662075b01169
@azure-pipelines

Copy link
Copy Markdown
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.

tvaron3 added 2 commits July 21, 2026 17:07
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
@tvaron3

tvaron3 commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

/azp run java - cosmos - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@tvaron3

tvaron3 commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

/azp run java - spark - tests

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@tvaron3

tvaron3 commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

/azp run java - cosmos - spark

@azure-pipelines

Copy link
Copy Markdown
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
@tvaron3
tvaron3 marked this pull request as ready for review July 23, 2026 00:27
@tvaron3
tvaron3 requested review from a team and kirankumarkolli as code owners July 23, 2026 00:27
Copilot AI review requested due to automatic review settings July 23, 2026 00:27
@azure-pipelines

Copy link
Copy Markdown
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.

@tvaron3

tvaron3 commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

/azp run java - cosmos - spark

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@tvaron3

tvaron3 commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

/azp run java - cosmos - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 FromNow continuation and split composite continuation state into per-effective-range PartitionMetadata.
  • 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 isPartitionKeyInRange method 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
 }

@xinlian12

Copy link
Copy Markdown
Member

@sdkReviewAgent

@xinlian12 xinlian12 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks

@xinlian12

Copy link
Copy Markdown
Member

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
@tvaron3

tvaron3 commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

/azp run java - cosmos - spark

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@xinlian12 xinlian12 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM ,thanks

@tvaron3
tvaron3 merged commit e730f7f into Azure:main Jul 24, 2026
53 checks passed
tvaron3 added a commit that referenced this pull request Jul 28, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants