Skip to content

[Internal] Msdata/Direct: Adds support for Nregion synchronous commit#5375

Closed
ananth7592 wants to merge 4 commits intomsdata/directfrom
ananth/nregion-msdata-direct-commits
Closed

[Internal] Msdata/Direct: Adds support for Nregion synchronous commit#5375
ananth7592 wants to merge 4 commits intomsdata/directfrom
ananth/nregion-msdata-direct-commits

Conversation

@ananth7592
Copy link
Copy Markdown
Member

@ananth7592 ananth7592 commented Aug 26, 2025

Description

NRegion commit changes

Commit #1:

-Adds support for including nregioncommit account feature while creating StoreClient within DocumentClient

Commit #2

NRegion barrier writes support for < Strong consistency

- Refactors ConsistencyWriter to support synchronous barrier commits in NRegion accounts (< Strong) when EnableNRegionSynchronousCommit is enabled.

- Ensures response is only returned once GlobalNRegionCommittedGLSN has caught up with the write LSN, preserving linearizability.

Commit #3

Emulator test for NregionCommit Write Barrier

  • Used Http interceptor to "mock" nregioncommit feature enabled in AccountProperties.
  • Used Transport interceptor to mock GLobalNRegionCommitLSN for testing scenario.
  • Tested success and failures cases.

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] This change requires a documentation update

Closing issues

To automatically close an issue: closes #IssueNumber

- Refactors ConsistencyWriter to support synchronous barrier commits in NRegion accounts (< Strong) when EnableNRegionSynchronousCommit is enabled.

- Ensures response is only returned once GlobalNRegionCommittedGLSN has caught up with the write LSN, preserving linearizability.

- Adds coverage in StoreReaderTest for NRegion commit path.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

All good!

@ananth7592 ananth7592 changed the title Ananth/nregion msdata direct commits [Internal] Msdata/Direct: Adds support for Nregion synchronous commit Aug 26, 2025
Comment thread Microsoft.Azure.Cosmos/src/direct/StatusCodes.cs
@ananth7592 ananth7592 force-pushed the ananth/nregion-msdata-direct-commits branch from c04dad0 to fbc3366 Compare September 3, 2025 23:57
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 adds support for NRegion synchronous commit functionality, enabling write consistency guarantees across multiple read regions for accounts with consistency levels below Strong.

  • Introduces NRegion synchronous commit feature that ensures write barriers are met across read regions
  • Extends ConsistencyWriter to handle both global strong writes and NRegion synchronous commits with barrier requests
  • Adds comprehensive testing including unit tests and emulator tests with transport/HTTP interceptors

Reviewed Changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
StoreReaderTest.cs Adds unit test for NRegion synchronous commit write barrier functionality
DocumentClientUnitTests.cs Adds test to verify EnableNRegionSynchronousCommit flag is passed to StoreClient
CosmosItemConsistencyTests.cs Adds emulator tests for NRegion commit with transport interceptors
StoreResult.cs Adds GlobalNRegionCommittedGLSN property and parsing logic
StatusCodes.cs Adds new sub-status code for NRegion commit write barrier failures
ServiceUnavailableException.cs Adds error message handling for NRegion barrier failures
QuorumReader.cs Updates BarrierRequestHelper calls to include new parameter
ConsistencyWriter.cs Major refactor to support both global strong and NRegion write barriers
BarrierRequestHelper.cs Extends to support GlobalNRegionCommittedLsn header
AccountProperties.cs Adds EnableNRegionSynchronousCommit property
RMResources.resx Adds error message resources for NRegion barriers
DocumentClient.cs Passes account configuration to StoreClient factory
Files not reviewed (1)
  • Microsoft.Azure.Cosmos/src/RMResources.Designer.cs: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread Microsoft.Azure.Cosmos/src/direct/StoreResult.cs
Comment thread Microsoft.Azure.Cosmos/src/direct/ConsistencyWriter.cs
Comment thread Microsoft.Azure.Cosmos/src/direct/ConsistencyWriter.cs
Comment thread Microsoft.Azure.Cosmos/src/direct/ConsistencyWriter.cs Outdated
Comment thread Microsoft.Azure.Cosmos/src/RMResources.resx Outdated
Comment thread Microsoft.Azure.Cosmos/src/RMResources.resx Outdated
- Used Http interceptor to "mock" nregioncommit feature enabled in AccountProperties.
- Used Transport interceptor to mock GLobalNRegionCommitLSN for testing scenario.
- Tested success and failures cases.
@ananth7592 ananth7592 force-pushed the ananth/nregion-msdata-direct-commits branch from fbc3366 to 8745aee Compare September 4, 2025 22:47
Comment thread Microsoft.Azure.Cosmos/src/direct/BarrierRequestHelper.cs Outdated
{
AccountProperties accountProperties = this.accountServiceConfiguration.AccountProperties;

bool enableNRegionSynchronousCommit = accountProperties.EnableNRegionSynchronousCommit;
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.

Shouldn't this be more than a boolean flag (instead an absolute number of regions that must have committed)?

<value>Global Strong write barrier has not been met for the request.</value>
</data>
<data name="NRegionCommitWriteBarrierNotMet" xml:space="preserve">
<value>NRegion Commit write barrier has not been met for the request.</value>
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.

Hint about how apps can deal with it? Should they retry? Is it useless?


if (storeResponse.TryGetHeaderValue(WFConstants.BackendHeaders.GlobalNRegionCommittedGLSN, out headerValue))
{
globalNRegionCommittedGLSN = long.Parse(headerValue, CultureInfo.InvariantCulture);
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.

Should we handle any parsing issues? Right now the exception thrown would probably be confusing? - so, maybe use TryParse and have dedicated error if it fails? (I admit this should never ever happen and would be a violation of service contract - but still a good safety net IMO.

Copy link
Copy Markdown
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

Few NITS - otherwise looks good to me.

@ananth7592
Copy link
Copy Markdown
Member Author

Used this PR as baseline for N region commit .

#5401

Feature has been released in 3.54.0

@ananth7592 ananth7592 closed this Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants