Skip to content

Commit

Permalink
Continuation Token wrapped with Error when Recursive Acl call is inte…
Browse files Browse the repository at this point in the history
…rrupted (#11716)
  • Loading branch information
XiaoningLiu authored Oct 8, 2020
1 parent beb900c commit 2ac4a95
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ export abstract class CredentialPolicy extends BaseRequestPolicy {
// @public
export type CredentialPolicyCreator = (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => CredentialPolicy;

// @public
export class DataLakeAclChangeFailedError extends Error {
constructor(error: RestError | Error, continuationToken?: string);
continuationToken?: string;
internalError: RestError | Error;
}

// @public
export class DataLakeDirectoryClient extends DataLakePathClient {
create(resourceType: PathResourceTypeModel, options?: PathCreateOptions): Promise<PathCreateResponse>;
Expand Down
38 changes: 22 additions & 16 deletions sdk/storage/storage-file-datalake/src/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BlobClient, BlockBlobClient } from "@azure/storage-blob";
import { CanonicalCode } from "@opentelemetry/api";
import { Readable } from "stream";

import { BufferScheduler } from "../../storage-common/src";
import { AnonymousCredential } from "./credentials/AnonymousCredential";
import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential";
import { DataLakeLeaseClient } from "./DataLakeLeaseClient";
Expand All @@ -21,12 +22,16 @@ import {
FileCreateIfNotExistsResponse,
FileCreateOptions,
FileCreateResponse,
FileExpiryMode,
FileFlushOptions,
FileFlushResponse,
FileParallelUploadOptions,
FileQueryOptions,
FileReadOptions,
FileReadResponse,
FileReadToBufferOptions,
FileSetExpiryOptions,
FileSetExpiryResponse,
FileUploadResponse,
Metadata,
PathAccessControlItem,
Expand Down Expand Up @@ -57,11 +62,7 @@ import {
PathSetMetadataResponse,
PathSetPermissionsOptions,
PathSetPermissionsResponse,
RemovePathAccessControlItem,
FileQueryOptions,
FileExpiryMode,
FileSetExpiryOptions,
FileSetExpiryResponse
RemovePathAccessControlItem
} from "./models";
import { PathSetAccessControlRecursiveMode } from "./models.internal";
import { newPipeline, Pipeline, StoragePipelineOptions } from "./Pipeline";
Expand All @@ -74,7 +75,6 @@ import {
toProperties
} from "./transforms";
import { Batch } from "./utils/Batch";

import {
BLOCK_BLOB_MAX_BLOCKS,
DEFAULT_HIGH_LEVEL_CONCURRENCY,
Expand All @@ -84,10 +84,10 @@ import {
FILE_UPLOAD_DEFAULT_CHUNK_SIZE,
FILE_UPLOAD_MAX_CHUNK_SIZE
} from "./utils/constants";
import { DataLakeAclChangeFailedError } from "./utils/DataLakeAclChangeFailedError";
import { createSpan } from "./utils/tracing";
import { appendToURLPath, setURLPath } from "./utils/utils.common";
import { fsStat, fsCreateReadStream } from "./utils/utils.node";
import { BufferScheduler } from "../../storage-common/src";
import { fsCreateReadStream, fsStat } from "./utils/utils.node";

/**
* A DataLakePathClient represents a URL to the Azure Storage path (directory or file).
Expand Down Expand Up @@ -159,14 +159,20 @@ export class DataLakePathClient extends StorageClient {
let batchCounter = 0;
let reachMaxBatches = false;
do {
const response = await this.pathContext.setAccessControlRecursive(mode, {
...options,
acl: toAclString(acl as PathAccessControlItem[]),
maxRecords: options.batchSize,
continuation: continuationToken,
forceFlag: options.continueOnFailure,
spanOptions
});
let response;
try {
response = await this.pathContext.setAccessControlRecursive(mode, {
...options,
acl: toAclString(acl as PathAccessControlItem[]),
maxRecords: options.batchSize,
continuation: continuationToken,
forceFlag: options.continueOnFailure,
spanOptions
});
} catch (e) {
throw new DataLakeAclChangeFailedError(e, continuationToken);
}

batchCounter++;
continuationToken = response.continuation;

Expand Down
1 change: 1 addition & 0 deletions sdk/storage/storage-file-datalake/src/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from "./policies/AnonymousCredentialPolicy";
export * from "./policies/CredentialPolicy";
export * from "./StorageRetryPolicyFactory";
export * from "./models";
export * from "./utils/DataLakeAclChangeFailedError";
export { CommonOptions } from "./StorageClient";
export { ToBlobEndpointHostMappings, ToDfsEndpointHostMappings } from "./utils/constants";
export { RestError } from "@azure/core-http";
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/storage-file-datalake/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export * from "./StorageRetryPolicyFactory";
export * from "./policies/StorageSharedKeyCredentialPolicy";
export * from "./sas/SASQueryParameters";
export * from "./models";
export * from "./utils/DataLakeAclChangeFailedError";
export { CommonOptions } from "./StorageClient";
export { SasIPRange } from "./sas/SasIPRange";
export { ToBlobEndpointHostMappings, ToDfsEndpointHostMappings } from "./utils/constants";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { RestError } from "@azure/core-http";

/**
* An error thrown when an operation is interrupted and can be continued later on.
*
* @export
* @class DataLakeAclChangeFailedError
* @extends {Error}
*/
export class DataLakeAclChangeFailedError extends Error {
/**
* Continuation token to continue next batch of operations.
*
* @type {string}
* @memberof DataLakeAclChangeFailedError
*/
public continuationToken?: string;

/**
* Internal error.
*
* @type {(RestError | Error)}
* @memberof DataLakeAclChangeFailedError
*/
public internalError: RestError | Error;

constructor(error: RestError | Error, continuationToken?: string) {
super(error.message);
this.name = "DataLakeAclChangeFailedError";
this.internalError = error;
this.continuationToken = continuationToken;
Object.setPrototypeOf(this, DataLakeAclChangeFailedError.prototype);
}
}

0 comments on commit 2ac4a95

Please sign in to comment.