@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
219 lines • 9.63 kB
TypeScript
import type { FeedOptions, Response } from "../request/index.js";
import type { PartitionedQueryExecutionInfo } from "../request/ErrorResponse.js";
import type { ExecutionContext } from "./ExecutionContext.js";
import type { SqlQuerySpec } from "./SqlQuerySpec.js";
import { DocumentProducer } from "./documentProducer.js";
import { TargetPartitionRangeManager } from "./queryFilteringStrategy/TargetPartitionRangeManager.js";
import type { QueryProcessingStrategy } from "./queryProcessingStrategy/QueryProcessingStrategy.js";
import { DiagnosticNodeInternal } from "../diagnostics/DiagnosticNodeInternal.js";
import type { ClientContext } from "../ClientContext.js";
/** @hidden */
export declare enum ParallelQueryExecutionContextBaseStates {
started = "started",
inProgress = "inProgress",
ended = "ended"
}
/** @hidden */
export declare abstract class ParallelQueryExecutionContextBase implements ExecutionContext {
private readonly clientContext;
private readonly collectionLink;
private readonly query;
private readonly options;
private readonly partitionedQueryExecutionInfo;
private readonly correlatedActivityId;
private readonly rangeManager;
private readonly queryProcessingStrategy;
private readonly documentProducerComparator;
private err;
private state;
private static readonly STATES;
private routingProvider;
private readonly requestContinuation;
private respHeaders;
private readonly unfilledDocumentProducersQueue;
private readonly bufferedDocumentProducersQueue;
private buffer;
private partitionDataPatchMap;
private patchCounter;
private readonly updatedContinuationRanges;
private readonly sem;
private readonly diagnosticNodeWrapper;
/**
* Provides the ParallelQueryExecutionContextBase.
* This is the base class that ParallelQueryExecutionContext and OrderByQueryExecutionContext will derive from.
*
* When handling a parallelized query, it instantiates one instance of
* DocumentProcuder per target partition key range and aggregates the result of each.
*
* @param clientContext - The service endpoint to use to create the client.
* @param collectionLink - The Collection Link
* @param options - Represents the feed options.
* @param partitionedQueryExecutionInfo - PartitionedQueryExecutionInfo
* @hidden
*/
constructor(clientContext: ClientContext, collectionLink: string, query: string | SqlQuerySpec, options: FeedOptions, partitionedQueryExecutionInfo: PartitionedQueryExecutionInfo, correlatedActivityId: string, rangeManager: TargetPartitionRangeManager, queryProcessingStrategy: QueryProcessingStrategy, documentProducerComparator: (dp1: DocumentProducer, dp2: DocumentProducer) => number);
/**
* Determine if there are still remaining resources to processs based on the value of the continuation
* token or the elements remaining on the current batch in the QueryIterator.
* @returns true if there is other elements to process in the ParallelQueryExecutionContextBase.
*/
hasMoreResults(): boolean;
/**
* Fetches more results from the query execution context.
* @param diagnosticNode - Optional diagnostic node for tracing.
* @returns A promise that resolves to the fetched results.
* @hidden
*/
fetchMore(diagnosticNode?: DiagnosticNodeInternal): Promise<Response<any>>;
/**
* Processes buffered document producers
* @returns A promise that resolves when processing is complete.
*/
private processBufferedDocumentProducers;
/**
* Processes a single document producer using template method pattern.
* Common structure with query-specific processing delegated to subclasses.
*/
private processDocumentProducer;
/**
* Fetches data from a document producer - implemented by subclasses.
*/
protected abstract fetchFromProducer(producer: DocumentProducer): Promise<Response<any>>;
/**
* Handles partition mapping updates - implemented in base class using template method pattern.
* Child classes provide query-specific parameters through abstract methods.
*/
private handlePartitionMapping;
/**
* Gets the continuation token to use - implemented by subclasses.
*/
private getContinuationToken;
/**
* Determines if buffered producers should continue to be processed based on query-specific rules.
* @param isUnfilledQueueEmpty - Whether the unfilled queue is empty
*/
protected abstract shouldProcessBufferedProducers(isUnfilledQueueEmpty: boolean): boolean;
/**
* Updates partition mapping - creates new entry or merges with existing for ORDER BY queries.
*/
private updatePartitionMapping;
/**
* Checks if the unfilled queue is empty (used by ORDER BY for processing control).
*/
protected isUnfilledQueueEmpty(): boolean;
/**
* Initializes document producers and fills the priority queue.
* Handles both continuation token and fresh query scenarios.
*/
private _initializeDocumentProducers;
/**
* Creates document producers from continuation token scenario.
*/
private _createDocumentProducersFromContinuation;
/**
* Creates document producers from fresh query scenario (no continuation token).
*/
private _createDocumentProducersFromFresh;
/**
* Creates a document producer from a range token pair (continuation token scenario).
*/
private _createDocumentProducerFromRangeTokenPair;
/**
* Enqueues document producers into the unfilled queue.
*/
private _enqueueDocumentProducers;
/**
* Checks if there are buffered document producers ready for processing.
* Encapsulates queue size checking.
*/
private hasBufferedProducers;
/**
* Gets the next buffered document producer for processing.
* Encapsulates queue dequeuing logic.
*/
private getNextBufferedProducer;
/**
* Adds items to the result buffer. Handles both single items and arrays.
*/
private addToBuffer;
/**
* Moves a producer to the unfilled queue for later processing.
*/
private moveToUnfilledQueue;
/**
* Re-queues a producer to the buffered queue for further processing.
*/
private requeueProducer;
/**
* Compares two document producers based on their partition key ranges and EPK values.
* Primary comparison: minInclusive values for left-to-right range traversal
* Secondary comparison: EPK ranges when minInclusive values are identical
* @param a - First document producer
* @param b - Second document producer
* @returns Comparison result for priority queue ordering
* @hidden
*/
private compareDocumentProducersByRange;
/**
* Detects partition splits/merges by analyzing parsed continuation token ranges and comparing with current topology
* @param parsed - The continuation token containing range mappings to analyze
* @returns Array of processed ranges with EPK info
*/
private _handlePartitionRangeChanges;
/**
* Parses the continuation token based on query type
* @param continuationToken - The continuation token string to parse
* @returns Parsed continuation token object (ORDER BY or Parallel query token)
* @throws ErrorResponse when continuation token is malformed or cannot be parsed
*/
private _parseContinuationToken;
/**
* Handles partition merge scenario for continuation token ranges
*/
private _handleContinuationTokenMerge;
/**
* Handles partition split scenario for continuation token ranges
*/
private _handleContinuationTokenSplit;
/**
* Handles partition merge scenario for continuation token ranges
*/
private _mergeWithActiveResponseHeaders;
private _getAndResetActiveResponseHeaders;
private getDiagnosticNode;
private _onTargetPartitionRanges;
/**
* Gets the replacement ranges for a partitionkeyrange that has been split
*/
private _getReplacementPartitionKeyRanges;
private _enqueueReplacementDocumentProducers;
private _updateContinuationTokenOnPartitionChange;
/**
* Creates a QueryRangeWithContinuationToken object from a DocumentProducer.
* Uses the DocumentProducer's target partition key range and continuation token.
* @param documentProducer - The DocumentProducer to convert
* @returns QueryRangeWithContinuationToken object for token operations
*/
private _createQueryRangeWithContinuationToken;
private static _needPartitionKeyRangeCacheRefresh;
/**
* Creates target partition range Query Execution Context
*/
private _createTargetPartitionQueryExecutionContext;
private drainBufferedItems;
/**
* Buffers document producers based on the maximum degree of parallelism.
* Moves document producers from the unfilled queue to the buffered queue.
* @param diagnosticNode - The diagnostic node for logging and tracing.
* @returns A promise that resolves when buffering is complete.
*/
private bufferDocumentProducers;
/**
* Drains the buffer of filled document producers and appends their items to the main buffer.
* Uses template method pattern - delegates actual processing to subclasses.
* @returns A promise that resolves when the buffer is filled.
*/
private fillBufferFromBufferQueue;
private updateStates;
}
//# sourceMappingURL=parallelQueryExecutionContextBase.d.ts.map