Skip to content

Commit

Permalink
Update names in cosmos for consistency
Browse files Browse the repository at this point in the history
Fixes Azure#5263 by updating names to align better with other packages.
  • Loading branch information
xirzec committed Nov 8, 2019
1 parent 6dfaac6 commit 1a23fa9
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 72 deletions.
16 changes: 8 additions & 8 deletions sdk/cosmosdb/cosmos/review/cosmos.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const Constants: {
XDate: string;
CollectionPartitionInfo: string;
CollectionServiceInfo: string;
RetryAfterInMilliseconds: string;
RetryAfterInMs: string;
IsFeedUnfiltered: string;
ResourceTokenExpiry: string;
EnableScanInQuery: string;
Expand Down Expand Up @@ -257,7 +257,6 @@ export class Container {
// (undocumented)
readonly database: Database;
delete(options?: RequestOptions): Promise<ContainerResponse>;
getPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>>;
// Warning: (ae-forgotten-export) The symbol "PartitionedQueryExecutionInfo" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand All @@ -267,6 +266,7 @@ export class Container {
item(id: string, partitionKey: any): Item;
readonly items: Items;
read(options?: RequestOptions): Promise<ContainerResponse>;
readPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>>;
// (undocumented)
readPartitionKeyRanges(feedOptions?: FeedOptions): QueryIterator<PartitionKeyRange>;
replace(body: ContainerDefinition, options?: RequestOptions): Promise<ContainerResponse>;
Expand Down Expand Up @@ -427,7 +427,7 @@ export interface ErrorResponse extends Error {
// (undocumented)
headers?: CosmosHeaders;
// (undocumented)
retryAfterInMilliseconds?: number;
retryAfterInMs?: number;
// (undocumented)
substatus?: number;
}
Expand All @@ -444,7 +444,7 @@ export interface FeedOptions extends SharedOptions {
condition: string;
};
bufferItems?: boolean;
continuation?: string;
continuationToken?: string;
continuationTokenLimitInKB?: number;
enableScanInQuery?: boolean;
forceQueryPlan?: boolean;
Expand All @@ -460,7 +460,7 @@ export class FeedResponse<TResource> {
// (undocumented)
readonly activityId: string;
// (undocumented)
readonly continuation: string;
readonly continuationToken: string;
// (undocumented)
readonly hasMoreResults: boolean;
// (undocumented)
Expand Down Expand Up @@ -970,9 +970,9 @@ export interface Response<T> {

// @public
export interface RetryOptions {
fixedRetryIntervalInMilliseconds: number;
maxRetryAttemptCount: number;
maxWaitTimeInSeconds: number;
fixedRetryIntervalInMs: number;
maxTries: number;
timeoutInSeconds: number;
}

// @public (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/src/client/Container/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class Container {
* @param {function} callback - \
* The arguments to the callback are(in order): error, partitionKeyDefinition, response object and response headers
*/
public async getPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>> {
public async readPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>> {
// $ISSUE-felixfan-2016-03-17: Make name based path and link based path use the same key
// $ISSUE-felixfan-2016-03-17: Refresh partitionKeyDefinitionCache when necessary
if (this.url in this.clientContext.partitionKeyDefinitionCache) {
Expand Down
12 changes: 9 additions & 3 deletions sdk/cosmosdb/cosmos/src/client/Item/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class Item {
options: RequestOptions = {}
): Promise<ItemResponse<T>> {
if (this.partitionKey === undefined) {
const { resource: partitionKeyDefinition } = await this.container.getPartitionKeyDefinition();
const {
resource: partitionKeyDefinition
} = await this.container.readPartitionKeyDefinition();
this.partitionKey = undefinedPartitionKey(partitionKeyDefinition);
}
const path = getPathFromLink(this.url);
Expand Down Expand Up @@ -137,7 +139,9 @@ export class Item {
options: RequestOptions = {}
): Promise<ItemResponse<T>> {
if (this.partitionKey === undefined) {
const { resource: partitionKeyDefinition } = await this.container.getPartitionKeyDefinition();
const {
resource: partitionKeyDefinition
} = await this.container.readPartitionKeyDefinition();
this.partitionKey = extractPartitionKey(body, partitionKeyDefinition);
}

Expand Down Expand Up @@ -178,7 +182,9 @@ export class Item {
options: RequestOptions = {}
): Promise<ItemResponse<T>> {
if (this.partitionKey === undefined) {
const { resource: partitionKeyDefinition } = await this.container.getPartitionKeyDefinition();
const {
resource: partitionKeyDefinition
} = await this.container.readPartitionKeyDefinition();
this.partitionKey = undefinedPartitionKey(partitionKeyDefinition);
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmosdb/cosmos/src/client/Item/Items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class Items {
body: T,
options: RequestOptions = {}
): Promise<ItemResponse<T>> {
const { resource: partitionKeyDefinition } = await this.container.getPartitionKeyDefinition();
const { resource: partitionKeyDefinition } = await this.container.readPartitionKeyDefinition();
const partitionKey = extractPartitionKey(body, partitionKeyDefinition);

// Generate random document id if the id is missing in the payload and
Expand Down Expand Up @@ -277,7 +277,7 @@ export class Items {
body: T,
options: RequestOptions = {}
): Promise<ItemResponse<T>> {
const { resource: partitionKeyDefinition } = await this.container.getPartitionKeyDefinition();
const { resource: partitionKeyDefinition } = await this.container.readPartitionKeyDefinition();
const partitionKey = extractPartitionKey(body, partitionKeyDefinition);

// Generate random document id if the id is missing in the payload and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ export class StoredProcedure {
options?: RequestOptions
): Promise<ResourceResponse<T>> {
if (partitionKey === undefined) {
const { resource: partitionKeyDefinition } = await this.container.getPartitionKeyDefinition();
const {
resource: partitionKeyDefinition
} = await this.container.readPartitionKeyDefinition();
partitionKey = undefinedPartitionKey(partitionKeyDefinition);
}
const response = await this.clientContext.execute<T>({
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const Constants = {
XDate: "x-ms-date",
CollectionPartitionInfo: "x-ms-collection-partition-info",
CollectionServiceInfo: "x-ms-collection-service-info",
RetryAfterInMilliseconds: "x-ms-retry-after-ms",
RetryAfterInMs: "x-ms-retry-after-ms",
IsFeedUnfiltered: "x-ms-is-feed-unfiltered",
ResourceTokenExpiry: "x-ms-documentdb-expiry-seconds",
EnableScanInQuery: "x-ms-documentdb-query-enable-scan",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class DefaultQueryExecutionContext implements ExecutionContext {
this.currentPartitionIndex = 0;
this.fetchFunctions = Array.isArray(fetchFunctions) ? fetchFunctions : [fetchFunctions];
this.options = options || {};
this.continuation = this.options.continuation || null;
this.continuation = this.options.continuationToken || null;
this.state = DefaultQueryExecutionContext.STATES.start;
}

Expand Down Expand Up @@ -127,8 +127,8 @@ export class DefaultQueryExecutionContext implements ExecutionContext {
}

// Keep to the original continuation and to restore the value after fetchFunction call
const originalContinuation = this.options.continuation;
this.options.continuation = this.continuation;
const originalContinuation = this.options.continuationToken;
this.options.continuationToken = this.continuation;

// Return undefined if there is no more results
if (this.currentPartitionIndex >= this.fetchFunctions.length) {
Expand Down Expand Up @@ -159,7 +159,7 @@ export class DefaultQueryExecutionContext implements ExecutionContext {
if (this.options && this.options.bufferItems === true) {
const fetchFunction = this.fetchFunctions[this.currentPartitionIndex];
this.nextFetchFunction = fetchFunction
? fetchFunction({ ...this.options, continuation: this.continuation })
? fetchFunction({ ...this.options, continuationToken: this.continuation })
: undefined;
}
} catch (err) {
Expand All @@ -171,7 +171,7 @@ export class DefaultQueryExecutionContext implements ExecutionContext {

this.state = DefaultQueryExecutionContext.STATES.inProgress;
this.currentIndex = 0;
this.options.continuation = originalContinuation;
this.options.continuationToken = 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export abstract class ParallelQueryExecutionContextBase implements ExecutionCont
this.pageSize = options["maxItemCount"];
}

this.requestContinuation = options ? options.continuation : null;
this.requestContinuation = options ? options.continuationToken : null;
// response headers of undergoing operation
this.respHeaders = getInitialHeader();

Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/src/request/ErrorResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export interface ErrorResponse extends Error {
body?: ErrorBody;
headers?: CosmosHeaders;
activityId?: string;
retryAfterInMilliseconds?: number;
retryAfterInMs?: number;
[key: string]: any;
}
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/src/request/FeedOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SharedOptions } from "./SharedOptions";
*/
export interface FeedOptions extends SharedOptions {
/** Opaque token for continuing the enumeration. Default: undefined */
continuation?: string;
continuationToken?: string;
/**
* Limits the size of the continuation token in the response. Default: undefined
*
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/src/request/FeedResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class FeedResponse<TResource> {
private readonly headers: CosmosHeaders,
public readonly hasMoreResults: boolean
) {}
public get continuation(): string {
public get continuationToken(): string {
return this.headers[Constants.HttpHeaders.Continuation];
}
public get queryMetrics(): string {
Expand Down
6 changes: 3 additions & 3 deletions sdk/cosmosdb/cosmos/src/request/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ async function httpRequest(requestContext: RequestContext) {
errorResponse.substatus = substatus;
}

if (Constants.HttpHeaders.RetryAfterInMilliseconds in headers) {
errorResponse.retryAfterInMilliseconds = parseInt(
headers[Constants.HttpHeaders.RetryAfterInMilliseconds],
if (Constants.HttpHeaders.RetryAfterInMs in headers) {
errorResponse.retryAfterInMs = parseInt(
headers[Constants.HttpHeaders.RetryAfterInMs],
10
);
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmosdb/cosmos/src/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export async function getHeaders({
headers[Constants.HttpHeaders.ResponseContinuationTokenLimitInKB] =
options.continuationTokenLimitInKB;
}
if (options.continuation) {
headers[Constants.HttpHeaders.Continuation] = options.continuation;
if (options.continuationToken) {
headers[Constants.HttpHeaders.Continuation] = options.continuationToken;
}

if (options.preTriggerInclude) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/src/retry/RetryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RetryContext } from "./RetryContext";
* @ignore
*/
export interface RetryPolicy {
retryAfterInMilliseconds: number;
retryAfterInMs: number;
shouldRetry: (
errorResponse: ErrorResponse,
retryContext?: RetryContext,
Expand Down
6 changes: 3 additions & 3 deletions sdk/cosmosdb/cosmos/src/retry/defaultRetryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ function needsRetry(operationType: OperationType, code: number | string) {
* @ignore
*/
export class DefaultRetryPolicy implements RetryPolicy {
private maxRetryAttemptCount: number = 10;
private maxTries: number = 10;
private currentRetryAttemptCount: number = 0;
public retryAfterInMilliseconds: number = 1000;
public retryAfterInMs: number = 1000;

constructor(private operationType: OperationType) {}
/**
Expand All @@ -139,7 +139,7 @@ export class DefaultRetryPolicy implements RetryPolicy {
public async shouldRetry(err: ErrorResponse): Promise<boolean> {
if (err) {
if (
this.currentRetryAttemptCount < this.maxRetryAttemptCount &&
this.currentRetryAttemptCount < this.maxTries &&
needsRetry(this.operationType, err.code)
) {
this.currentRetryAttemptCount++;
Expand Down
14 changes: 7 additions & 7 deletions sdk/cosmosdb/cosmos/src/retry/endpointDiscoveryRetryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export class EndpointDiscoveryRetryPolicy implements RetryPolicy {
/** Current retry attempt count. */
public currentRetryAttemptCount: number;
/** Retry interval in milliseconds. */
public retryAfterInMilliseconds: number;
public retryAfterInMs: number;

/** Max number of retry attempts to perform. */
private maxRetryAttemptCount: number;
private static readonly maxRetryAttemptCount = 120; // TODO: Constant?
private static readonly retryAfterInMilliseconds = 1000;
private maxTries: number;
private static readonly maxTries = 120; // TODO: Constant?
private static readonly retryAfterInMs = 1000;

/**
* @constructor EndpointDiscoveryRetryPolicy
Expand All @@ -30,9 +30,9 @@ export class EndpointDiscoveryRetryPolicy implements RetryPolicy {
private globalEndpointManager: GlobalEndpointManager,
private operationType: OperationType
) {
this.maxRetryAttemptCount = EndpointDiscoveryRetryPolicy.maxRetryAttemptCount;
this.maxTries = EndpointDiscoveryRetryPolicy.maxTries;
this.currentRetryAttemptCount = 0;
this.retryAfterInMilliseconds = EndpointDiscoveryRetryPolicy.retryAfterInMilliseconds;
this.retryAfterInMs = EndpointDiscoveryRetryPolicy.retryAfterInMs;
}

/**
Expand All @@ -56,7 +56,7 @@ export class EndpointDiscoveryRetryPolicy implements RetryPolicy {
return false;
}

if (this.currentRetryAttemptCount >= this.maxRetryAttemptCount) {
if (this.currentRetryAttemptCount >= this.maxTries) {
return false;
}

Expand Down
38 changes: 19 additions & 19 deletions sdk/cosmosdb/cosmos/src/retry/resourceThrottleRetryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ export class ResourceThrottleRetryPolicy {
/** Current retry attempt count. */
public currentRetryAttemptCount: number = 0;
/** Cummulative wait time in milliseconds for a request while the retries are happening. */
public cummulativeWaitTimeinMilliseconds: number = 0;
public cummulativeWaitTimeinMs: number = 0;
/** Max wait time in milliseconds to wait for a request while the retries are happening. */
public retryAfterInMilliseconds: number = 0;
public retryAfterInMs: number = 0;

/** Max number of retries to be performed for a request. */
private maxWaitTimeInMilliseconds: number;
private timeoutInMs: number;
/**
* @constructor ResourceThrottleRetryPolicy
* @param {int} maxRetryAttemptCount - Max number of retries to be performed for a request.
* @param {int} fixedRetryIntervalInMilliseconds - Fixed retry interval in milliseconds to wait between each \
* @param {int} maxTries - Max number of retries to be performed for a request.
* @param {int} fixedRetryIntervalInMs - Fixed retry interval in milliseconds to wait between each \
* retry ignoring the retryAfter returned as part of the response.
* @param {int} maxWaitTimeInSeconds - Max wait time in seconds to wait for a request while the \
* @param {int} timeoutInSeconds - Max wait time in seconds to wait for a request while the \
* retries are happening.
*/
constructor(
private maxRetryAttemptCount: number = 9,
private fixedRetryIntervalInMilliseconds: number = 0,
maxWaitTimeInSeconds: number = 30
private maxTries: number = 9,
private fixedRetryIntervalInMs: number = 0,
timeoutInSeconds: number = 30
) {
this.maxWaitTimeInMilliseconds = maxWaitTimeInSeconds * 1000;
this.timeoutInMs = timeoutInSeconds * 1000;
this.currentRetryAttemptCount = 0;
this.cummulativeWaitTimeinMilliseconds = 0;
this.cummulativeWaitTimeinMs = 0;
}
/**
* Determines whether the request should be retried or not.
Expand All @@ -40,18 +40,18 @@ export class ResourceThrottleRetryPolicy {
public async shouldRetry(err: ErrorResponse): Promise<boolean> {
// TODO: any custom error object
if (err) {
if (this.currentRetryAttemptCount < this.maxRetryAttemptCount) {
if (this.currentRetryAttemptCount < this.maxTries) {
this.currentRetryAttemptCount++;
this.retryAfterInMilliseconds = 0;
this.retryAfterInMs = 0;

if (this.fixedRetryIntervalInMilliseconds) {
this.retryAfterInMilliseconds = this.fixedRetryIntervalInMilliseconds;
} else if (err.retryAfterInMilliseconds) {
this.retryAfterInMilliseconds = err.retryAfterInMilliseconds;
if (this.fixedRetryIntervalInMs) {
this.retryAfterInMs = this.fixedRetryIntervalInMs;
} else if (err.retryAfterInMs) {
this.retryAfterInMs = err.retryAfterInMs;
}

if (this.cummulativeWaitTimeinMilliseconds < this.maxWaitTimeInMilliseconds) {
this.cummulativeWaitTimeinMilliseconds += this.retryAfterInMilliseconds;
if (this.cummulativeWaitTimeinMs < this.timeoutInMs) {
this.cummulativeWaitTimeinMs += this.retryAfterInMs;
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/cosmosdb/cosmos/src/retry/retryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/
export interface RetryOptions {
/** Max number of retries to be performed for a request. Default value 9. */
maxRetryAttemptCount: number;
maxTries: number;
/** Fixed retry interval in milliseconds to wait between each retry ignoring the retryAfter returned as part of the response. */
fixedRetryIntervalInMilliseconds: number;
fixedRetryIntervalInMs: number;
/** Max wait time in seconds to wait for a request while the retries are happening. Default value 30 seconds. */
maxWaitTimeInSeconds: number;
timeoutInSeconds: number;
}
Loading

0 comments on commit 1a23fa9

Please sign in to comment.