UNPKG

azurite

Version:

An open source Azure Storage API compatible server

87 lines 3.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const Logger_1 = require("../../common/Logger"); const NoLoggerStrategy_1 = tslib_1.__importDefault(require("../../common/NoLoggerStrategy")); var State; (function (State) { State[State["LISTING_EXTENTS_IN_BLOBS"] = 0] = "LISTING_EXTENTS_IN_BLOBS"; State[State["LISTING_EXTENTS_IN_BLOCKS"] = 1] = "LISTING_EXTENTS_IN_BLOCKS"; State[State["DONE"] = 2] = "DONE"; })(State || (State = {})); /** * An async iterator which enumerates all extents being used. * * @export * @class BlobReferredExtentsAsyncIterator * @implements {AsyncIterator<string[]>} */ class BlobReferredExtentsAsyncIterator { constructor(blobMetadataStore, logger = new Logger_1.Logger(new NoLoggerStrategy_1.default())) { this.blobMetadataStore = blobMetadataStore; this.logger = logger; this.state = State.LISTING_EXTENTS_IN_BLOBS; } async next() { if (this.state === State.LISTING_EXTENTS_IN_BLOBS) { const [blobs, marker] = await this.blobMetadataStore.listAllBlobs(undefined, this.blobListingMarker, true, // includeSnapshots true // includeUncommitedBlobs ); this.blobListingMarker = marker; if (marker === undefined) { this.state = State.LISTING_EXTENTS_IN_BLOCKS; } const extents = []; for (const blob of blobs) { this.logger.debug(`BlobReferredExtentsAsyncIterator:next() Handle blob ${blob.accountName} ${blob.containerName} ${blob.name} ${blob.snapshot} Blocks: ${(blob.committedBlocksInOrder || []).length} PageRanges: ${(blob.pageRangesInOrder || []).length} Persistency: ${blob.persistency ? blob.persistency.id : ""}`); // this._logger.debug( // `BlobReferredExtentsAsyncIterator:next() committedBlocksInOrder:${JSON.stringify( // blob.committedBlocksInOrder // )}` // ); // this._logger.debug( // `BlobReferredExtentsAsyncIterator:next() pageRangesInOrder:${JSON.stringify( // blob.pageRangesInOrder // )}` // ); for (const block of blob.committedBlocksInOrder || []) { extents.push(block.persistency.id); } for (const range of blob.pageRangesInOrder || []) { extents.push(range.persistency.id); } if (blob.persistency) { extents.push(blob.persistency.id); } } return { done: false, value: extents }; } else if (this.state === State.LISTING_EXTENTS_IN_BLOCKS) { const [blocks, marker] = await this.blobMetadataStore.listUncommittedBlockPersistencyChunks(this.blockListingMarker); this.blockListingMarker = marker; if (marker === undefined) { this.state = State.DONE; } // this._logger.debug( // `BlobReferredExtentsAsyncIterator:next() Handle uncommitted blocks ${ // blocks.length // } ${JSON.stringify(blocks)}` // ); return { done: false, value: blocks.map(block => block.id) }; } else { return { done: true, value: [] }; } } } exports.default = BlobReferredExtentsAsyncIterator; //# sourceMappingURL=BlobReferredExtentsAsyncIterator.js.map