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

[Cosmos] Refactor endpoint discovery and failover #6283

Merged
merged 11 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sdk/cosmosdb/cosmos/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 3.4.3
## 3.5.0

- FEATURE: Endpoint discovery and multi-region failover improvements. See https://github.com/Azure/azure-sdk-for-js/pull/6283 for more information on this change. (#6283)
- Makes changeFeed and query options optional. Fix #6232 Fix #6277 (#6273)

## 3.4.2
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/cosmos",
"version": "3.4.2",
"version": "3.5.0",
"description": "Microsoft Azure Cosmos DB Service Node.js SDK for SQL API",
"sdk-type": "client",
"keywords": [
Expand Down
6 changes: 2 additions & 4 deletions sdk/cosmosdb/cosmos/review/cosmos.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ export interface Location {
databaseAccountEndpoint: string;
// (undocumented)
name: string;
// (undocumented)
unavailable?: boolean;
}

// @public
Expand Down Expand Up @@ -888,10 +890,6 @@ export interface RequestContext {
globalEndpointManager: GlobalEndpointManager;
// (undocumented)
headers?: CosmosHeaders_2;
// Warning: (ae-forgotten-export) The symbol "LocationRouting" needs to be exported by the entry point index.d.ts
//
// (undocumented)
locationRouting?: LocationRouting;
// Warning: (ae-forgotten-export) The symbol "HTTPMethod" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down
40 changes: 32 additions & 8 deletions sdk/cosmosdb/cosmos/src/ClientContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export class ClientContext {
this.applySessionToken(request);

// read will use ReadEndpoint since it uses GET operation
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request);
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(
request.resourceType,
request.operationType
);
const response = await executePlugins(request, executeRequest, PluginOn.operation);
this.captureSessionToken(undefined, path, OperationType.Read, response.headers);
return response;
Expand Down Expand Up @@ -131,7 +134,10 @@ export class ClientContext {
if (query !== undefined) {
request.method = HTTPMethod.post;
}
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request);
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(
request.resourceType,
request.operationType
);
request.headers = await this.buildHeaders(request);
if (query !== undefined) {
request.headers[Constants.HttpHeaders.IsQuery] = "true";
Expand Down Expand Up @@ -177,7 +183,10 @@ export class ClientContext {
plugins: this.cosmosClientOptions.plugins
};

request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request);
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(
request.resourceType,
request.operationType
);
request.headers = await this.buildHeaders(request);
request.headers[Constants.HttpHeaders.IsQueryPlan] = "True";
request.headers[Constants.HttpHeaders.QueryVersion] = "1.4";
Expand Down Expand Up @@ -246,7 +255,10 @@ export class ClientContext {
request.headers = await this.buildHeaders(request);
this.applySessionToken(request);
// deleteResource will use WriteEndpoint since it uses DELETE operation
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request);
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(
request.resourceType,
request.operationType
);
const response = await executePlugins(request, executeRequest, PluginOn.operation);
if (parseLink(path).type !== "colls") {
this.captureSessionToken(undefined, path, OperationType.Delete, response.headers);
Expand Down Expand Up @@ -296,7 +308,10 @@ export class ClientContext {
// create will use WriteEndpoint since it uses POST operation
this.applySessionToken(request);

request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request);
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(
request.resourceType,
request.operationType
);
const response = await executePlugins(request, executeRequest, PluginOn.operation);
this.captureSessionToken(undefined, path, OperationType.Create, response.headers);
return response;
Expand Down Expand Up @@ -381,7 +396,10 @@ export class ClientContext {
this.applySessionToken(request);

// replace will use WriteEndpoint since it uses PUT operation
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request);
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(
request.resourceType,
request.operationType
);
const response = await executePlugins(request, executeRequest, PluginOn.operation);
this.captureSessionToken(undefined, path, OperationType.Replace, response.headers);
return response;
Expand Down Expand Up @@ -428,7 +446,10 @@ export class ClientContext {
this.applySessionToken(request);

// upsert will use WriteEndpoint since it uses POST operation
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request);
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(
request.resourceType,
request.operationType
);
const response = await executePlugins(request, executeRequest, PluginOn.operation);
this.captureSessionToken(undefined, path, OperationType.Upsert, response.headers);
return response;
Expand Down Expand Up @@ -475,7 +496,10 @@ export class ClientContext {

request.headers = await this.buildHeaders(request);
// executeStoredProcedure will use WriteEndpoint since it uses POST operation
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(request);
request.endpoint = await this.globalEndpointManager.resolveServiceEndpoint(
request.resourceType,
request.operationType
);
return executePlugins(request, executeRequest, PluginOn.operation);
}

Expand Down
Loading