Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Upgrade Resiliency: Adds Code to Enable Replica Validation Feature Through CosmosClientOptions #3967

Conversation

kundadebdatta
Copy link
Member

@kundadebdatta kundadebdatta commented Jul 7, 2023

Pull Request Template

Description

In reference to a recent conversation with the compute gateway team, we agreed to add an internal Boolean flag in CosmosClientOptions to dynamically enable the feature. This PR adds the flag in CosmosClientOptions to enable or disable the replica validation using the client options.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Closing issues

To automatically close an issue: closes #3922

@kundadebdatta kundadebdatta force-pushed the users/kundadebdatta/3922_make_replica_validation_dynamic branch from 23490fe to 7a0bbcf Compare July 7, 2023 21:30
@kundadebdatta kundadebdatta marked this pull request as ready for review July 7, 2023 21:30
/// timeouts. The default value for this parameter is false.
/// </summary>
/// <returns>The <see cref="CosmosClientBuilder"/> object</returns>
internal CosmosClientBuilder WithAdvancedReplicaSelectionEnabledForTcp()
Copy link
Member

Choose a reason for hiding this comment

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

Compute doesn't use builder API's is not needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Removed the method in the latest commit.

/// <remarks>
/// <para>This is optimal for latency-sensitive workloads. Does not apply if <see cref="ConnectionMode.Gateway"/> is used.</para>
/// </remarks>
internal bool EnableAdvancedReplicaSelectionForTcp { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Is explicit differentiation about opted/not vs default behavior for compute?
If so one option is to model it as nullable. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Similar to EnableContentResponseOnWrite

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, not setting this flag EnableAdvancedReplicaSelectionForTcp will automatically make the SDK to opt out from replica validation. In order to opt the feature, Compute doesn't need to specify any value for this field and the default value for this flag is always false.

I think this brings more simplicity, since we are anyhow not going to make this flag to public.

Copy link
Member

Choose a reason for hiding this comment

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

You can make the SDK default to disabled if the bool? has not value by just capturing:

bool isEnabled = EnableAdvancedReplicaSelectionForTcp.HasValue && EnableAdvancedReplicaSelectionForTcp.Value;

I think Kiran's point is that semantically it's always better to make settings bool? like EnableContentResponseOnWrite because it allows us (for whatever reason) to tell apart the scenario where the property's setter was not touched (use default) and when the user did set some preference (either true or false). In this particular case there might not be a special case for not touched, but for consistency's sake, if we are using bool? for other settings, might as well use it here.

Copy link
Member

Choose a reason for hiding this comment

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

Its an optional property and hence the conversation.

If compute if always set it explicitly (true/false) then for current requirements its makes sense.

@@ -233,7 +232,6 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider

this.Initialize(serviceEndpoint, connectionPolicy, desiredConsistencyLevel);
this.initTaskCache = new AsyncCacheNonBlocking<string, bool>(cancellationToken: this.cancellationTokenSource.Token);
this.isReplicaAddressValidationEnabled = ConfigurationManager.IsReplicaAddressValidationEnabled();
Copy link
Member

Choose a reason for hiding this comment

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

Is CosmosCLientOptions needs to default to ConfigurationManager.IsReplicaAddressValidationEnabled()?

Copy link
Member

Choose a reason for hiding this comment

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

Did we ship a version that supported setting the environment variable and is anyone using it? If yes, we might want to have backward compatibility?

Copy link
Member Author

Choose a reason for hiding this comment

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

CosmosClientOptions does not need to default to ConfigurationManager.IsReplicaAddressValidationEnabled(). This was an earlier implementation, which was reading the environment variable to set the replica validation flag. Since we never shipped this feature with any version of the SDK, we can safely remove this and rely on the CosmosClientOptions.

Copy link
Member

Choose a reason for hiding this comment

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

Since we never shipped this feature with any version of the SDK, we can safely remove this

Then yeah, no issues from my side.

Copy link
Member

Choose a reason for hiding this comment

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

How do external CX enable/disable this feature?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you suggesting to have both the environment variable and CosmosClientOptions way of enabling and disabling the feature ? My understanding was we will flight it with Compute first, and thereafter we will enable it by default for the external Cx ? That way, there is no need to have any env variables/ client options.

@kundadebdatta kundadebdatta marked this pull request as draft July 10, 2023 18:56
@kundadebdatta
Copy link
Member Author

This PR is no longer required as an alternate PR has been merged to master to address the issue.

@kundadebdatta kundadebdatta deleted the users/kundadebdatta/3922_make_replica_validation_dynamic branch July 11, 2023 02:21
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.

[Cosmos Service Upgrade - .NET] Replica Validation - Expose Replica Validation Feature as a Public Contract
3 participants