documentdb
Advanced tools
Comparing version 1.14.2 to 1.14.3
@@ -221,2 +221,6 @@ /* | ||
} | ||
if (options.a_im) { | ||
headers[Constants.HttpHeaders.A_IM] = options.a_im; | ||
} | ||
@@ -254,5 +258,9 @@ if (options.indexingDirective) { | ||
if (options.populateQuotaInfo) { | ||
headers[Constants.HttpHeaders.PopulateQuotaInfo] = true; | ||
headers[Constants.HttpHeaders.PopulateQuotaInfo] = options.populateQuotaInfo; | ||
} | ||
if (options.populateQueryMetrics) { | ||
headers[Constants.HttpHeaders.PopulateQueryMetrics] = options.populateQueryMetrics; | ||
} | ||
// If the user is not using partition resolver, we add options.partitonKey to the header for elastic collections | ||
@@ -259,0 +267,0 @@ if (documentClient.partitionResolver === undefined || documentClient.partitionResolver === null) { |
@@ -98,3 +98,4 @@ /* | ||
Referer: "referer", | ||
A_IM: "A-IM", | ||
// Query | ||
@@ -127,2 +128,6 @@ Query: "x-ms-documentdb-query", | ||
ParallelizeCrossPartitionQuery: "x-ms-documentdb-query-parallelizecrosspartitionquery", | ||
// QueryMetrics | ||
PopulateQueryMetrics: "x-ms-documentdb-populatequerymetrics", // Request header to tell backend to give you query metrics. | ||
QueryMetrics: "x-ms-documentdb-query-metrics", // Response header that holds the serialized version of query metrics. | ||
@@ -190,3 +195,3 @@ // Version headers and values | ||
SDKName: "documentdb-nodejs-sdk", | ||
SDKVersion: "1.14.2", | ||
SDKVersion: "1.14.3", | ||
@@ -226,3 +231,6 @@ DefaultPrecisions: { | ||
PartitionKeyRangesPathSegment: "pkranges", | ||
SchemasPathSegment: "schemas" | ||
SchemasPathSegment: "schemas", | ||
OffersPathSegment: "offers", | ||
TopologyPathSegment: "topology", | ||
DatabaseAccountPathSegment: "databaseaccount" | ||
}, | ||
@@ -229,0 +237,0 @@ |
@@ -72,5 +72,3 @@ /* | ||
maxRetryAttemptCount : 120, | ||
retryAfterInMilliseconds : 1000, | ||
FORBIDDEN_STATUS_CODE : 403, | ||
WRITE_FORBIDDEN_SUB_STATUS_CODE : 3 | ||
retryAfterInMilliseconds : 1000 | ||
} | ||
@@ -77,0 +75,0 @@ ); |
@@ -27,2 +27,4 @@ /* | ||
var Base = require("../base") | ||
, QueryMetrics = require("../queryMetrics/queryMetrics.js") | ||
, ClientSideMetrics = require("../queryMetrics/clientSideMetrics.js") | ||
, Constants = require("../constants"); | ||
@@ -148,2 +150,31 @@ | ||
that.options.continuation = originalContinuation; | ||
// deserializing query metrics so that we aren't working with delimited strings in the rest of the code base | ||
if (Constants.HttpHeaders.QueryMetrics in responseHeaders) { | ||
var delimitedString = responseHeaders[Constants.HttpHeaders.QueryMetrics]; | ||
var queryMetrics = QueryMetrics.createFromDelimitedString(delimitedString); | ||
// Add the request charge to the query metrics so that we can have per partition request charge. | ||
if (Constants.HttpHeaders.RequestCharge in responseHeaders) { | ||
queryMetrics = new QueryMetrics( | ||
queryMetrics._getRetrievedDocumentCount(), | ||
queryMetrics._getRetrievedDocumentSize(), | ||
queryMetrics._getOutputDocumentCount(), | ||
queryMetrics._getOutputDocumentSize(), | ||
queryMetrics._getIndexHitDocumentCount(), | ||
queryMetrics._getTotalQueryExecutionTime(), | ||
queryMetrics._getQueryPreparationTimes(), | ||
queryMetrics._getIndexLookupTime(), | ||
queryMetrics._getDocumentLoadTime(), | ||
queryMetrics._getVMExecutionTime(), | ||
queryMetrics._getRuntimeExecutionTimes(), | ||
queryMetrics._getDocumentWriteTime(), | ||
new ClientSideMetrics(responseHeaders[Constants.HttpHeaders.RequestCharge])); | ||
} | ||
// Wraping query metrics in a object where the key is '0' just so single partition and partition queries have the same response schema | ||
responseHeaders[Constants.HttpHeaders.QueryMetrics] = {}; | ||
responseHeaders[Constants.HttpHeaders.QueryMetrics]["0"] = queryMetrics; | ||
} | ||
callback(undefined, resources, responseHeaders); | ||
@@ -150,0 +181,0 @@ }); |
@@ -27,3 +27,6 @@ /* | ||
var Base = require("../base") | ||
, QueryMetrics = require("../queryMetrics/queryMetrics.js") | ||
, ClientSideMetrics = require("../queryMetrics/clientSideMetrics.js") | ||
, DefaultQueryExecutionContext = require("./defaultQueryExecutionContext") | ||
, Constants = require("../constants") | ||
, HttpHeaders = require("../constants").HttpHeaders | ||
@@ -200,2 +203,12 @@ , HeaderUtils = require("./headerUtils") | ||
} | ||
// need to modify the header response so that the query metrics are per partition | ||
if (headerResponse != null && Constants.HttpHeaders.QueryMetrics in headerResponse) { | ||
// "0" is the default partition before one is actually assigned. | ||
var queryMetrics = headerResponse[Constants.HttpHeaders.QueryMetrics]["0"]; | ||
// Wraping query metrics in a object where the keys are the partition key range. | ||
headerResponse[Constants.HttpHeaders.QueryMetrics] = {}; | ||
headerResponse[Constants.HttpHeaders.QueryMetrics][that.targetPartitionKeyRange.id] = queryMetrics; | ||
} | ||
@@ -202,0 +215,0 @@ return callback(undefined, resources, headerResponse); |
@@ -28,2 +28,3 @@ /* | ||
, Constants = require("../constants") | ||
, QueryMetrics = require("../queryMetrics/queryMetrics.js") | ||
, assert = require("assert") | ||
@@ -42,3 +43,3 @@ , util = require("util"); | ||
} | ||
if (headers) { | ||
@@ -55,9 +56,10 @@ var rc = headers[Constants.HttpHeaders.RequestCharge]; | ||
}, | ||
getInitialHeader: function () { | ||
var headers = {}; | ||
headers[Constants.HttpHeaders.RequestCharge] = 0; | ||
headers[Constants.HttpHeaders.QueryMetrics] = {}; | ||
return headers; | ||
}, | ||
mergeHeaders: function (headers, toBeMergedHeaders) { | ||
@@ -67,5 +69,11 @@ if (headers[Constants.HttpHeaders.RequestCharge] == undefined) { | ||
} | ||
if (headers[Constants.HttpHeaders.QueryMetrics] == undefined) { | ||
headers[Constants.HttpHeaders.QueryMetrics] = QueryMetrics.zero; | ||
} | ||
if (!toBeMergedHeaders) { | ||
return; | ||
} | ||
headers[Constants.HttpHeaders.RequestCharge] += this.getRequestChargeIfAny(toBeMergedHeaders); | ||
@@ -75,2 +83,17 @@ if (toBeMergedHeaders[Constants.HttpHeaders.IsRUPerMinuteUsed]) { | ||
} | ||
if (Constants.HttpHeaders.QueryMetrics in toBeMergedHeaders) { | ||
var headerQueryMetrics = headers[Constants.HttpHeaders.QueryMetrics]; | ||
var toBeMergedHeaderQueryMetrics = toBeMergedHeaders[Constants.HttpHeaders.QueryMetrics]; | ||
for (var partitionId in toBeMergedHeaderQueryMetrics) { | ||
if (partitionId in headerQueryMetrics) { | ||
var combinedQueryMetrics = headerQueryMetrics[partitionId].add(toBeMergedHeaderQueryMetrics[partitionId]); | ||
headerQueryMetrics[partitionId] = combinedQueryMetrics; | ||
} | ||
else { | ||
headerQueryMetrics[partitionId] = toBeMergedHeaderQueryMetrics[partitionId]; | ||
} | ||
} | ||
} | ||
} | ||
@@ -77,0 +100,0 @@ } |
@@ -156,3 +156,2 @@ /* | ||
rid.documentCollection = buffer.readIntBE(4, 4).toString(); | ||
var newBuff = new Buffer(4); | ||
@@ -159,0 +158,0 @@ if (buffer.length >= 16) { |
@@ -77,5 +77,2 @@ /* | ||
} | ||
}, | ||
{ | ||
THROTTLE_STATUS_CODE: 429 | ||
} | ||
@@ -82,0 +79,0 @@ ); |
@@ -30,3 +30,6 @@ /* | ||
ResourceThrottleRetryPolicy = require("./resourceThrottleRetryPolicy"), | ||
SessionReadRetryPolicy = require("./sessionReadRetryPolicy"); | ||
SessionReadRetryPolicy = require("./sessionReadRetryPolicy"), | ||
DefaultRetryPolicy = require("./defaultRetryPolicy"), | ||
StatusCodes = require("./statusCodes").StatusCodes, | ||
SubStatusCodes = require("./statusCodes").SubStatusCodes; | ||
@@ -52,4 +55,5 @@ //SCRIPT START | ||
var sessionReadRetryPolicy = new SessionReadRetryPolicy(globalEndpointManager, request) | ||
var defaultRetryPolicy = new DefaultRetryPolicy(request.operationType) | ||
this.apply(body, createRequestObjectFunc, connectionPolicy, requestOptions, endpointDiscoveryRetryPolicy, resourceThrottleRetryPolicy, sessionReadRetryPolicy, callback); | ||
this.apply(body, createRequestObjectFunc, connectionPolicy, requestOptions, endpointDiscoveryRetryPolicy, resourceThrottleRetryPolicy, sessionReadRetryPolicy, defaultRetryPolicy, callback); | ||
}, | ||
@@ -67,3 +71,3 @@ | ||
*/ | ||
apply: function (body, createRequestObjectFunc, connectionPolicy, requestOptions, endpointDiscoveryRetryPolicy, resourceThrottleRetryPolicy, sessionReadRetryPolicy, callback) { | ||
apply: function (body, createRequestObjectFunc, connectionPolicy, requestOptions, endpointDiscoveryRetryPolicy, resourceThrottleRetryPolicy, sessionReadRetryPolicy, defaultRetryPolicy, callback) { | ||
var that = this; | ||
@@ -74,26 +78,26 @@ var httpsRequest = createRequestObjectFunc(connectionPolicy, requestOptions, function (err, response, headers) { | ||
headers = headers || {}; | ||
if (err.code === EndpointDiscoveryRetryPolicy.FORBIDDEN_STATUS_CODE && err.substatus === EndpointDiscoveryRetryPolicy.WRITE_FORBIDDEN_SUB_STATUS_CODE) { | ||
if (err.code === StatusCodes.Forbidden && err.substatus === SubStatusCodes.WriteForbidden) { | ||
retryPolicy = endpointDiscoveryRetryPolicy; | ||
} else if (err.code === ResourceThrottleRetryPolicy.THROTTLE_STATUS_CODE) { | ||
} else if (err.code === StatusCodes.TooManyRequests) { | ||
retryPolicy = resourceThrottleRetryPolicy; | ||
} else if (err.code === SessionReadRetryPolicy.NOT_FOUND_STATUS_CODE && err.substatus === SessionReadRetryPolicy.READ_SESSION_NOT_AVAILABLE_SUB_STATUS_CODE) { | ||
} else if (err.code === StatusCodes.NotFound && err.substatus === SubStatusCodes.ReadSessionNotAvailable) { | ||
retryPolicy = sessionReadRetryPolicy; | ||
} else { | ||
retryPolicy = defaultRetryPolicy; | ||
} | ||
if (retryPolicy) { | ||
retryPolicy.shouldRetry(err, function (shouldRetry, newUrl) { | ||
if (!shouldRetry) { | ||
headers[Constants.ThrottleRetryCount] = resourceThrottleRetryPolicy.currentRetryAttemptCount; | ||
headers[Constants.ThrottleRetryWaitTimeInMs] = resourceThrottleRetryPolicy.cummulativeWaitTimeinMilliseconds; | ||
return callback(err, response, headers); | ||
} else { | ||
setTimeout(function () { | ||
if (typeof newUrl !== 'undefined') | ||
requestOptions = that.modifyRequestOptions(requestOptions, newUrl); | ||
that.apply(body, createRequestObjectFunc, connectionPolicy, requestOptions, endpointDiscoveryRetryPolicy, resourceThrottleRetryPolicy, sessionReadRetryPolicy, callback); | ||
}, retryPolicy.retryAfterInMilliseconds); | ||
return; | ||
} | ||
}); | ||
return; | ||
} | ||
retryPolicy.shouldRetry(err, function (shouldRetry, newUrl) { | ||
if (!shouldRetry) { | ||
headers[Constants.ThrottleRetryCount] = resourceThrottleRetryPolicy.currentRetryAttemptCount; | ||
headers[Constants.ThrottleRetryWaitTimeInMs] = resourceThrottleRetryPolicy.cummulativeWaitTimeinMilliseconds; | ||
return callback(err, response, headers); | ||
} else { | ||
setTimeout(function () { | ||
if (typeof newUrl !== 'undefined') | ||
requestOptions = that.modifyRequestOptions(requestOptions, newUrl); | ||
that.apply(body, createRequestObjectFunc, connectionPolicy, requestOptions, endpointDiscoveryRetryPolicy, resourceThrottleRetryPolicy, sessionReadRetryPolicy, defaultRetryPolicy, callback); | ||
}, retryPolicy.retryAfterInMilliseconds); | ||
return; | ||
} | ||
}); | ||
return | ||
} | ||
@@ -100,0 +104,0 @@ headers[Constants.ThrottleRetryCount] = resourceThrottleRetryPolicy.currentRetryAttemptCount; |
@@ -110,3 +110,3 @@ /* | ||
setSessionToken: function (request, reqHeaders, resHeaders) { | ||
setSessionToken: function (request, resHeaders) { | ||
if (resHeaders && !this.isReadingFromMaster(request['resourceType'], request['opearationType'])) { | ||
@@ -177,10 +177,10 @@ var sessionToken = resHeaders[Constants.HttpHeaders.SessionToken]; | ||
isReadingFromMaster: function (resourceType, operationType) { | ||
if (resourceType == "offers" || | ||
resourceType == "dbs" || | ||
resourceType == "users" || | ||
resourceType == "permissions" || | ||
resourceType == "topology" || | ||
resourceType == "databaseaccount" || | ||
resourceType == "pkranges" || | ||
(resourceType == "colls" | ||
if (resourceType == Constants.Path.OffersPathSegment || | ||
resourceType == Constants.Path.DatabasesPathSegment || | ||
resourceType == Constants.Path.UsersPathSegment || | ||
resourceType == Constants.Path.PermissionsPathSegment || | ||
resourceType == Constants.Path.TopologyPathSegment || | ||
resourceType == Constants.Path.DatabaseAccountPathSegment || | ||
resourceType == Constants.Path.PartitionKeyRangesPathSegment || | ||
(resourceType == Constants.Path.CollectionsPathSegment | ||
&& (operationType == Constants.OperationTypes.Query))) { | ||
@@ -187,0 +187,0 @@ return true; |
@@ -73,4 +73,7 @@ /* | ||
} else { | ||
console.log("Clear the the token for named base request"); | ||
that.request.client.clearSessionToken(that.request.path); | ||
console.log(Base.isLinkNameBased(that.request.path)); | ||
if (Base.isLinkNameBased(that.request.path)) { | ||
console.log("Clear the the token for named base request"); | ||
that.request.client.clearSessionToken(that.request.path); | ||
} | ||
return callback(false); | ||
@@ -88,5 +91,3 @@ } | ||
maxRetryAttemptCount: 1, | ||
retryAfterInMilliseconds: 0, | ||
NOT_FOUND_STATUS_CODE: 404, | ||
READ_SESSION_NOT_AVAILABLE_SUB_STATUS_CODE: 1002 | ||
retryAfterInMilliseconds: 0 | ||
} | ||
@@ -93,0 +94,0 @@ ); |
@@ -64,2 +64,8 @@ /* | ||
"PartitionKeyRangeGone": 1002, | ||
// 404: NotFound Substatus | ||
"ReadSessionNotAvailable": 1002, | ||
// 403: Forbidden Substatus | ||
"WriteForbidden": 3 | ||
} | ||
@@ -66,0 +72,0 @@ |
{ | ||
"name": "documentdb", | ||
"description": "Node.js SDK for DocumentDB API of Azure Cosmos DB Service", | ||
"description": "Azure Cosmos DB Service Node.js SDK for SQL API", | ||
"keywords": [ | ||
@@ -14,3 +14,3 @@ "cosmosdb", | ||
], | ||
"version": "1.14.2", | ||
"version": "1.14.3", | ||
"author": "Microsoft Corporation", | ||
@@ -50,2 +50,2 @@ "main": "./index.js", | ||
"license": "MIT" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
942887
59
20494
1
0