Skip to content

Fixes UnsupportedOperationException when using readManyByPartitionKey for empty pages#49311

Merged
FabianMeiswinkel merged 8 commits into
Azure:mainfrom
FabianMeiswinkel:users/fabianm/ReadManyByPKFix
Jun 1, 2026
Merged

Fixes UnsupportedOperationException when using readManyByPartitionKey for empty pages#49311
FabianMeiswinkel merged 8 commits into
Azure:mainfrom
FabianMeiswinkel:users/fabianm/ReadManyByPKFix

Conversation

@FabianMeiswinkel
Copy link
Copy Markdown
Member

Description

The driver stack trace when it fails is the following
26/05/29 08:30:24 WARN TaskSetManager: Lost task 3.0 in stage 42.0 (TID 108773) (10.181.218.61 executor 44): java.lang.UnsupportedOperationException
      at java.util.Collections$UnmodifiableMap.put(Collections.java:1459)
      at azure_cosmos_spark.com.azure.cosmos.models.FeedResponse.setContinuationTokenInternal(FeedResponse.java:453)
      at azure_cosmos_spark.com.azure.cosmos.models.FeedResponse.setContinuationToken(FeedResponse.java:448)
      at azure_cosmos_spark.com.azure.cosmos.models.ModelBridgeInternal.setFeedResponseContinuationToken(ModelBridgeInternal.java:605)
      at azure_cosmos_spark.com.azure.cosmos.implementation.RxDocumentClientImpl.lambda$buildSequentialBatchFlux$132(RxDocumentClientImpl.java:4940)
      at azure_cosmos_spark.reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106)
      at azure_cosmos_spark.reactor.core.publisher.FluxFlatMap$FlatMapMain.tryEmit(FluxFlatMap.java:547)
      at azure_cosmos_spark.reactor.core.publisher.FluxFlatMap$FlatMapInner.onNext(FluxFlatMap.java:988)
      at azure_cosmos_spark.reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79)

This can happen when for a single physical partition the requested tuples don't have any matches - the empty page returned would have immutable headers.

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.

Copilot AI review requested due to automatic review settings May 29, 2026 14:41
@FabianMeiswinkel FabianMeiswinkel requested review from a team and kirankumarkolli as code owners May 29, 2026 14:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 Cosmos DB readManyByPartitionKey(s) failure where empty pages with immutable response headers could throw UnsupportedOperationException when stamping continuation tokens.

Changes:

  • Detects known immutable header map shapes and defensively copies before mutating continuation headers.
  • Adds unit tests for immutable-map detection and the customer-reported continuation-token stamping path.
  • Preserves the no-op fast path for empty headers when no continuation header needs to be changed.
Show a summary per file
File Description
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/FeedResponse.java Copies known immutable header maps before setting/removing continuation tokens.
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Utils.java Adds isImmutableMap helper for known immutable map implementations used by Cosmos internals.
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/UtilsImmutableMapTests.java Adds unit coverage for immutable-map detection.
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/ReadManyByPartitionKeyContinuationTokenTest.java Adds regression coverage for immutable non-empty headers in continuation-token stamping.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

@FabianMeiswinkel
Copy link
Copy Markdown
Member Author

/azp run java - cosmos - spark

@FabianMeiswinkel
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).

1 similar comment
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Comment thread sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/FeedResponse.java Outdated
Comment thread sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/FeedResponse.java Outdated
Copy link
Copy Markdown
Member

@ananth7592 ananth7592 left a comment

Choose a reason for hiding this comment

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

LGTM, Except for 2 minor comments

Copy link
Copy Markdown
Member

@tvaron3 tvaron3 left a comment

Choose a reason for hiding this comment

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

LGTM

xinlian12 and others added 2 commits May 29, 2026 17:38
…202605

Update JarStorageAccountName from oltpsparkcijarstore0326 to
oltpsparkcijarstore0529 to point to the new storage account provisioned
in the current ephemeral tenant rotation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@xinlian12
Copy link
Copy Markdown
Member

/azp run java - cosmos - spark

@xinlian12
Copy link
Copy Markdown
Member

/azp run java - cosmos - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@xinlian12
Copy link
Copy Markdown
Member

@sdkReviewAgent

Comment thread sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/FeedResponse.java Outdated
@xinlian12
Copy link
Copy Markdown
Member

Review complete (54:17)

Posted 1 inline comment(s).

Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage

@FabianMeiswinkel
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).

@FabianMeiswinkel
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).

@FabianMeiswinkel
Copy link
Copy Markdown
Member Author

/check-enforcer override

@FabianMeiswinkel FabianMeiswinkel merged commit 6c60dbc into Azure:main Jun 1, 2026
109 of 112 checks passed
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.

5 participants