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

CosmosClientBuilder: Add preferred regions and public internal func WithConnectionModeDirect() #1397

Conversation

lingdaLi
Copy link
Contributor

Description

When we migrate our app from sdk v2 to sdk v3, we need a way to set the EnableTcpConnectionEndpointRediscovery and ApplicationPreferredRegions on CosmosClientOptions by CosmosClientBuilder.

The reason we need create CosmosClientBuilder is due to we need utilize the internal encryption feature.

Type of change

  • Allow CosmosClientBuilder to build the CosmosClient by preferred regions.
  • Public the internal function of WithConnectionModeDirect() which take customize connection configs.

1395

Put closes #1395 .

lingdaLi

2. Make the function to build CosmosClient by customize connection configs from internal to public
@msftclas
Copy link

msftclas commented Apr 17, 2020

CLA assistant check
All CLA requirements met.

/// <seealso cref="CosmosClientOptions.ApplicationPreferredRegions"/>
public CosmosClientBuilder WithApplicationPreferredRegions(IReadOnlyList<string> applicationPreferredRegions)
{
this.clientOptions.ApplicationPreferredRegions = applicationPreferredRegions;
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to make a deep copy of the list, since the list itself is mutable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Either that or use ImmutableList.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since @bchong95 brought this topic, do you guys think it's necessary to force the input type as ImmutableList? Since it will ensure the thread safe. I might over thinking but it's possible the list will change during add process?

Copy link
Member

Choose a reason for hiding this comment

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

Internally the list that is passed is iterated when you build the Client instance and not referenced, so modifying the variable after bulding the client has no effect.

Copy link
Member

Choose a reason for hiding this comment

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

What's the contract on ClientOptions. If its IReadOnly then won't it also have the same issue?

Copy link
Member

Choose a reason for hiding this comment

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

CosmosClientOptions's contract is public IReadOnlyList<string> ApplicationPreferredRegions { get; set; }. Like I mentioned, once the Client is built, we don't maintain a reference to the variable, so modifying the variable does not alter the Client configuration.

Copy link
Member

Choose a reason for hiding this comment

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

@ealsur lets please track this feedback for V4.

Copy link
Member

@ealsur ealsur left a comment

Choose a reason for hiding this comment

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

You need to run the unit tests locally and update the public API file.

@ealsur
Copy link
Member

ealsur commented Apr 20, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@j82w
Copy link
Contributor

j82w commented Apr 29, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@j82w j82w merged commit c83d6a8 into Azure:master May 7, 2020
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.

CosmosClientBuilder need support the options allowed on CosmosClientOptions
6 participants