@azure/event-hubs 6.0.2-alpha.20251014.1 → 6.0.2-alpha.20251021.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/browser/batchingPartitionChannel.js +2 -1
- package/dist/browser/batchingPartitionChannel.js.map +1 -1
- package/dist/browser/connectionContext.d.ts.map +1 -1
- package/dist/browser/connectionContext.js +10 -4
- package/dist/browser/connectionContext.js.map +1 -1
- package/dist/browser/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/browser/eventHubBufferedProducerClient.js +2 -1
- package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/browser/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/browser/eventHubConsumerClient.js +3 -6
- package/dist/browser/eventHubConsumerClient.js.map +1 -1
- package/dist/browser/eventHubProducerClient.d.ts.map +1 -1
- package/dist/browser/eventHubProducerClient.js +3 -6
- package/dist/browser/eventHubProducerClient.js.map +1 -1
- package/dist/browser/eventHubSender.d.ts.map +1 -1
- package/dist/browser/eventHubSender.js +6 -4
- package/dist/browser/eventHubSender.js.map +1 -1
- package/dist/browser/partitionReceiver.js +4 -4
- package/dist/browser/partitionReceiver.js.map +1 -1
- package/dist/browser/util/timerLoop.d.ts.map +1 -1
- package/dist/browser/util/timerLoop.js +12 -5
- package/dist/browser/util/timerLoop.js.map +1 -1
- package/dist/commonjs/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/commonjs/batchingPartitionChannel.js +2 -1
- package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
- package/dist/commonjs/connectionContext.d.ts.map +1 -1
- package/dist/commonjs/connectionContext.js +10 -4
- package/dist/commonjs/connectionContext.js.map +1 -1
- package/dist/commonjs/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubBufferedProducerClient.js +2 -1
- package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubConsumerClient.js +3 -6
- package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
- package/dist/commonjs/eventHubProducerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubProducerClient.js +3 -6
- package/dist/commonjs/eventHubProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubSender.d.ts.map +1 -1
- package/dist/commonjs/eventHubSender.js +6 -4
- package/dist/commonjs/eventHubSender.js.map +1 -1
- package/dist/commonjs/partitionReceiver.js +4 -4
- package/dist/commonjs/partitionReceiver.js.map +1 -1
- package/dist/commonjs/util/timerLoop.d.ts.map +1 -1
- package/dist/commonjs/util/timerLoop.js +12 -5
- package/dist/commonjs/util/timerLoop.js.map +1 -1
- package/dist/esm/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/esm/batchingPartitionChannel.js +2 -1
- package/dist/esm/batchingPartitionChannel.js.map +1 -1
- package/dist/esm/connectionContext.d.ts.map +1 -1
- package/dist/esm/connectionContext.js +10 -4
- package/dist/esm/connectionContext.js.map +1 -1
- package/dist/esm/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/esm/eventHubBufferedProducerClient.js +2 -1
- package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/esm/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/esm/eventHubConsumerClient.js +3 -6
- package/dist/esm/eventHubConsumerClient.js.map +1 -1
- package/dist/esm/eventHubProducerClient.d.ts.map +1 -1
- package/dist/esm/eventHubProducerClient.js +3 -6
- package/dist/esm/eventHubProducerClient.js.map +1 -1
- package/dist/esm/eventHubSender.d.ts.map +1 -1
- package/dist/esm/eventHubSender.js +6 -4
- package/dist/esm/eventHubSender.js.map +1 -1
- package/dist/esm/partitionReceiver.js +4 -4
- package/dist/esm/partitionReceiver.js.map +1 -1
- package/dist/esm/util/timerLoop.d.ts.map +1 -1
- package/dist/esm/util/timerLoop.js +12 -5
- package/dist/esm/util/timerLoop.js.map +1 -1
- package/dist/react-native/batchingPartitionChannel.d.ts +94 -0
- package/dist/react-native/batchingPartitionChannel.d.ts.map +1 -0
- package/dist/react-native/batchingPartitionChannel.js +255 -0
- package/dist/react-native/batchingPartitionChannel.js.map +1 -0
- package/dist/react-native/connectionContext.d.ts +108 -0
- package/dist/react-native/connectionContext.d.ts.map +1 -0
- package/dist/react-native/connectionContext.js +310 -0
- package/dist/react-native/connectionContext.js.map +1 -0
- package/dist/react-native/dataTransformer.d.ts +53 -0
- package/dist/react-native/dataTransformer.d.ts.map +1 -0
- package/dist/react-native/dataTransformer.js +133 -0
- package/dist/react-native/dataTransformer.js.map +1 -0
- package/dist/react-native/diagnostics/instrumentEventData.d.ts +28 -0
- package/dist/react-native/diagnostics/instrumentEventData.d.ts.map +1 -0
- package/dist/react-native/diagnostics/instrumentEventData.js +67 -0
- package/dist/react-native/diagnostics/instrumentEventData.js.map +1 -0
- package/dist/react-native/diagnostics/tracing.d.ts +19 -0
- package/dist/react-native/diagnostics/tracing.d.ts.map +1 -0
- package/dist/react-native/diagnostics/tracing.js +40 -0
- package/dist/react-native/diagnostics/tracing.js.map +1 -0
- package/dist/react-native/eventData.d.ts +295 -0
- package/dist/react-native/eventData.d.ts.map +1 -0
- package/dist/react-native/eventData.js +247 -0
- package/dist/react-native/eventData.js.map +1 -0
- package/dist/react-native/eventDataAdapter.d.ts +69 -0
- package/dist/react-native/eventDataAdapter.d.ts.map +1 -0
- package/dist/react-native/eventDataAdapter.js +38 -0
- package/dist/react-native/eventDataAdapter.js.map +1 -0
- package/dist/react-native/eventDataBatch.d.ts +225 -0
- package/dist/react-native/eventDataBatch.d.ts.map +1 -0
- package/dist/react-native/eventDataBatch.js +301 -0
- package/dist/react-native/eventDataBatch.js.map +1 -0
- package/dist/react-native/eventHubBufferedProducerClient.d.ts +323 -0
- package/dist/react-native/eventHubBufferedProducerClient.d.ts.map +1 -0
- package/dist/react-native/eventHubBufferedProducerClient.js +301 -0
- package/dist/react-native/eventHubBufferedProducerClient.js.map +1 -0
- package/dist/react-native/eventHubConsumerClient.d.ts +293 -0
- package/dist/react-native/eventHubConsumerClient.d.ts.map +1 -0
- package/dist/react-native/eventHubConsumerClient.js +336 -0
- package/dist/react-native/eventHubConsumerClient.js.map +1 -0
- package/dist/react-native/eventHubConsumerClientModels.d.ts +218 -0
- package/dist/react-native/eventHubConsumerClientModels.d.ts.map +1 -0
- package/dist/react-native/eventHubConsumerClientModels.js +4 -0
- package/dist/react-native/eventHubConsumerClientModels.js.map +1 -0
- package/dist/react-native/eventHubProducerClient.d.ts +299 -0
- package/dist/react-native/eventHubProducerClient.d.ts.map +1 -0
- package/dist/react-native/eventHubProducerClient.js +366 -0
- package/dist/react-native/eventHubProducerClient.js.map +1 -0
- package/dist/react-native/eventHubSender.d.ts +227 -0
- package/dist/react-native/eventHubSender.d.ts.map +1 -0
- package/dist/react-native/eventHubSender.js +626 -0
- package/dist/react-native/eventHubSender.js.map +1 -0
- package/dist/react-native/eventPosition.d.ts +73 -0
- package/dist/react-native/eventPosition.d.ts.map +1 -0
- package/dist/react-native/eventPosition.js +121 -0
- package/dist/react-native/eventPosition.js.map +1 -0
- package/dist/react-native/eventProcessor.d.ts +232 -0
- package/dist/react-native/eventProcessor.d.ts.map +1 -0
- package/dist/react-native/eventProcessor.js +389 -0
- package/dist/react-native/eventProcessor.js.map +1 -0
- package/dist/react-native/eventhubConnectionConfig.d.ts +96 -0
- package/dist/react-native/eventhubConnectionConfig.d.ts.map +1 -0
- package/dist/react-native/eventhubConnectionConfig.js +98 -0
- package/dist/react-native/eventhubConnectionConfig.js.map +1 -0
- package/dist/react-native/impl/awaitableQueue.d.ts +25 -0
- package/dist/react-native/impl/awaitableQueue.d.ts.map +1 -0
- package/dist/react-native/impl/awaitableQueue.js +51 -0
- package/dist/react-native/impl/awaitableQueue.js.map +1 -0
- package/dist/react-native/impl/partitionAssigner.d.ts +29 -0
- package/dist/react-native/impl/partitionAssigner.d.ts.map +1 -0
- package/dist/react-native/impl/partitionAssigner.js +52 -0
- package/dist/react-native/impl/partitionAssigner.js.map +1 -0
- package/dist/react-native/impl/partitionGate.d.ts +27 -0
- package/dist/react-native/impl/partitionGate.d.ts.map +1 -0
- package/dist/react-native/impl/partitionGate.js +38 -0
- package/dist/react-native/impl/partitionGate.js.map +1 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.d.ts +6 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.d.ts.map +1 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.js +111 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.js.map +1 -0
- package/dist/react-native/inMemoryCheckpointStore.d.ts +44 -0
- package/dist/react-native/inMemoryCheckpointStore.d.ts.map +1 -0
- package/dist/react-native/inMemoryCheckpointStore.js +94 -0
- package/dist/react-native/inMemoryCheckpointStore.js.map +1 -0
- package/dist/react-native/index.d.ts +21 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +12 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts +30 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.js +40 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts +24 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.js +29 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts +28 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js +245 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts +20 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js +22 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js.map +1 -0
- package/dist/react-native/logger.d.ts +37 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +56 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/managementClient.d.ts +145 -0
- package/dist/react-native/managementClient.d.ts.map +1 -0
- package/dist/react-native/managementClient.js +305 -0
- package/dist/react-native/managementClient.js.map +1 -0
- package/dist/react-native/models/private.d.ts +185 -0
- package/dist/react-native/models/private.d.ts.map +1 -0
- package/dist/react-native/models/private.js +4 -0
- package/dist/react-native/models/private.js.map +1 -0
- package/dist/react-native/models/public.d.ts +240 -0
- package/dist/react-native/models/public.d.ts.map +1 -0
- package/dist/react-native/models/public.js +18 -0
- package/dist/react-native/models/public.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/partitionProcessor.d.ts +134 -0
- package/dist/react-native/partitionProcessor.d.ts.map +1 -0
- package/dist/react-native/partitionProcessor.js +137 -0
- package/dist/react-native/partitionProcessor.js.map +1 -0
- package/dist/react-native/partitionPump.d.ts +38 -0
- package/dist/react-native/partitionPump.d.ts.map +1 -0
- package/dist/react-native/partitionPump.js +175 -0
- package/dist/react-native/partitionPump.js.map +1 -0
- package/dist/react-native/partitionReceiver.d.ts +82 -0
- package/dist/react-native/partitionReceiver.d.ts.map +1 -0
- package/dist/react-native/partitionReceiver.js +335 -0
- package/dist/react-native/partitionReceiver.js.map +1 -0
- package/dist/react-native/pumpManager.d.ts +72 -0
- package/dist/react-native/pumpManager.d.ts.map +1 -0
- package/dist/react-native/pumpManager.js +120 -0
- package/dist/react-native/pumpManager.js.map +1 -0
- package/dist/react-native/util/connectionStringUtils.d.ts +52 -0
- package/dist/react-native/util/connectionStringUtils.d.ts.map +1 -0
- package/dist/react-native/util/connectionStringUtils.js +48 -0
- package/dist/react-native/util/connectionStringUtils.js.map +1 -0
- package/dist/react-native/util/constants.d.ts +25 -0
- package/dist/react-native/util/constants.d.ts.map +1 -0
- package/dist/react-native/util/constants.js +27 -0
- package/dist/react-native/util/constants.js.map +1 -0
- package/dist/react-native/util/delayWithoutThrow.d.ts +8 -0
- package/dist/react-native/util/delayWithoutThrow.d.ts.map +1 -0
- package/dist/react-native/util/delayWithoutThrow.js +17 -0
- package/dist/react-native/util/delayWithoutThrow.js.map +1 -0
- package/dist/react-native/util/error.d.ts +39 -0
- package/dist/react-native/util/error.d.ts.map +1 -0
- package/dist/react-native/util/error.js +103 -0
- package/dist/react-native/util/error.js.map +1 -0
- package/dist/react-native/util/getPromiseParts.d.ts +10 -0
- package/dist/react-native/util/getPromiseParts.d.ts.map +1 -0
- package/dist/react-native/util/getPromiseParts.js +20 -0
- package/dist/react-native/util/getPromiseParts.js.map +1 -0
- package/dist/react-native/util/operationOptions.d.ts +16 -0
- package/dist/react-native/util/operationOptions.d.ts.map +1 -0
- package/dist/react-native/util/operationOptions.js +4 -0
- package/dist/react-native/util/operationOptions.js.map +1 -0
- package/dist/react-native/util/parseEndpoint.d.ts +11 -0
- package/dist/react-native/util/parseEndpoint.d.ts.map +1 -0
- package/dist/react-native/util/parseEndpoint.js +17 -0
- package/dist/react-native/util/parseEndpoint.js.map +1 -0
- package/dist/react-native/util/retries.d.ts +6 -0
- package/dist/react-native/util/retries.d.ts.map +1 -0
- package/dist/react-native/util/retries.js +13 -0
- package/dist/react-native/util/retries.js.map +1 -0
- package/dist/react-native/util/runtimeInfo-react-native.d.mts.map +1 -0
- package/dist/react-native/util/runtimeInfo-react-native.mjs.map +1 -0
- package/dist/react-native/util/runtimeInfo.d.ts +6 -0
- package/dist/react-native/util/runtimeInfo.js +20 -0
- package/dist/react-native/util/timerLoop.d.ts +26 -0
- package/dist/react-native/util/timerLoop.d.ts.map +1 -0
- package/dist/react-native/util/timerLoop.js +34 -0
- package/dist/react-native/util/timerLoop.js.map +1 -0
- package/dist/react-native/util/typeGuards.d.ts +8 -0
- package/dist/react-native/util/typeGuards.d.ts.map +1 -0
- package/dist/react-native/util/typeGuards.js +12 -0
- package/dist/react-native/util/typeGuards.js.map +1 -0
- package/dist/react-native/util/utils.d.ts +7 -0
- package/dist/react-native/util/utils.d.ts.map +1 -0
- package/dist/react-native/util/utils.js +13 -0
- package/dist/react-native/util/utils.js.map +1 -0
- package/dist/react-native/withAuth.d.ts +25 -0
- package/dist/react-native/withAuth.d.ts.map +1 -0
- package/dist/react-native/withAuth.js +84 -0
- package/dist/react-native/withAuth.js.map +1 -0
- package/package.json +16 -11
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { throwTypeErrorIfParameterMissing } from "./util/error.js";
|
|
4
|
+
import { getRandomName } from "./util/utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* The `EventProcessor` relies on a `CheckpointStore` to store checkpoints and handle partition
|
|
7
|
+
* ownerships. `InMemoryCheckpointStore` is simple partition manager that stores checkpoints and
|
|
8
|
+
* partition ownerships in memory of your program.
|
|
9
|
+
*
|
|
10
|
+
* You can use the `InMemoryCheckpointStore` to get started with using the `EventProcessor`.
|
|
11
|
+
* But in production, you should choose an implementation of the `CheckpointStore` interface that will
|
|
12
|
+
* store the checkpoints and partition ownerships to a durable store instead.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export class InMemoryCheckpointStore {
|
|
17
|
+
_partitionOwnershipMap = new Map();
|
|
18
|
+
_committedCheckpoints = new Map();
|
|
19
|
+
/**
|
|
20
|
+
* Get the list of all existing partition ownership from the underlying data store. Could return empty
|
|
21
|
+
* results if there are is no existing ownership information.
|
|
22
|
+
*
|
|
23
|
+
* @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to
|
|
24
|
+
* <yournamespace>.servicebus.windows.net.
|
|
25
|
+
* @param eventHubName - The event hub name.
|
|
26
|
+
* @param consumerGroup - The consumer group name.
|
|
27
|
+
* @returns Partition ownership details of all the partitions that have/had an owner..
|
|
28
|
+
*/
|
|
29
|
+
async listOwnership(_fullyQualifiedNamespace, _eventHubName, _consumerGroup) {
|
|
30
|
+
const ownerships = [];
|
|
31
|
+
for (const value of this._partitionOwnershipMap.values()) {
|
|
32
|
+
ownerships.push({ ...value });
|
|
33
|
+
}
|
|
34
|
+
return ownerships;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Claim ownership of a list of partitions. This will return the list of partitions that were owned
|
|
38
|
+
* successfully.
|
|
39
|
+
*
|
|
40
|
+
* @param partitionOwnership - The list of partition ownership this instance is claiming to own.
|
|
41
|
+
* @returns A list partitions this instance successfully claimed ownership.
|
|
42
|
+
*/
|
|
43
|
+
async claimOwnership(partitionOwnership) {
|
|
44
|
+
const claimedOwnerships = [];
|
|
45
|
+
for (const ownership of partitionOwnership) {
|
|
46
|
+
if (!this._partitionOwnershipMap.has(ownership.partitionId) ||
|
|
47
|
+
this._partitionOwnershipMap.get(ownership.partitionId).etag === ownership.etag) {
|
|
48
|
+
const date = new Date();
|
|
49
|
+
const newOwnership = {
|
|
50
|
+
...ownership,
|
|
51
|
+
etag: getRandomName(),
|
|
52
|
+
lastModifiedTimeInMs: date.getTime(),
|
|
53
|
+
};
|
|
54
|
+
this._partitionOwnershipMap.set(newOwnership.partitionId, newOwnership);
|
|
55
|
+
claimedOwnerships.push(newOwnership);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return claimedOwnerships;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Updates the checkpoint in the data store for a partition.
|
|
62
|
+
*
|
|
63
|
+
* @param checkpoint - The checkpoint.
|
|
64
|
+
*/
|
|
65
|
+
async updateCheckpoint(checkpoint) {
|
|
66
|
+
throwTypeErrorIfParameterMissing("", "updateCheckpoint", "sequenceNumber", checkpoint.sequenceNumber);
|
|
67
|
+
throwTypeErrorIfParameterMissing("", "updateCheckpoint", "offset", checkpoint.offset);
|
|
68
|
+
checkpoint = { ...checkpoint };
|
|
69
|
+
const partitionOwnership = this._partitionOwnershipMap.get(checkpoint.partitionId);
|
|
70
|
+
if (partitionOwnership) {
|
|
71
|
+
partitionOwnership.etag = getRandomName();
|
|
72
|
+
const key = `${checkpoint.fullyQualifiedNamespace}:${checkpoint.eventHubName}:${checkpoint.consumerGroup}`;
|
|
73
|
+
let partitionMap = this._committedCheckpoints.get(key);
|
|
74
|
+
if (partitionMap == null) {
|
|
75
|
+
partitionMap = new Map();
|
|
76
|
+
this._committedCheckpoints.set(key, partitionMap);
|
|
77
|
+
}
|
|
78
|
+
partitionMap.set(checkpoint.partitionId, checkpoint);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async listCheckpoints(fullyQualifiedNamespace, eventHubName, consumerGroup) {
|
|
82
|
+
const key = `${fullyQualifiedNamespace}:${eventHubName}:${consumerGroup}`;
|
|
83
|
+
const partitionMap = this._committedCheckpoints.get(key);
|
|
84
|
+
if (partitionMap == null) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
const checkpoints = [];
|
|
88
|
+
for (const value of partitionMap.values()) {
|
|
89
|
+
checkpoints.push({ ...value });
|
|
90
|
+
}
|
|
91
|
+
return checkpoints;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=inMemoryCheckpointStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inMemoryCheckpointStore.js","sourceRoot":"","sources":["../../src/inMemoryCheckpointStore.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,gCAAgC,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,uBAAuB;IAC1B,sBAAsB,GAAoC,IAAI,GAAG,EAAE,CAAC;IACpE,qBAAqB,GAAyC,IAAI,GAAG,EAAE,CAAC;IAEhF;;;;;;;;;OASG;IACH,KAAK,CAAC,aAAa,CACjB,wBAAgC,EAChC,aAAqB,EACrB,cAAsB;QAEtB,MAAM,UAAU,GAAG,EAAE,CAAC;QAEtB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,EAAE,CAAC;YACzD,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc,CAAC,kBAAwC;QAC3D,MAAM,iBAAiB,GAAG,EAAE,CAAC;QAE7B,KAAK,MAAM,SAAS,IAAI,kBAAkB,EAAE,CAAC;YAC3C,IACE,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC;gBACvD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,CAAE,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,EAC/E,CAAC;gBACD,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;gBAExB,MAAM,YAAY,GAAG;oBACnB,GAAG,SAAS;oBACZ,IAAI,EAAE,aAAa,EAAE;oBACrB,oBAAoB,EAAE,IAAI,CAAC,OAAO,EAAE;iBACrC,CAAC;gBAEF,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,YAAY,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;gBACxE,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QACD,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,gBAAgB,CAAC,UAAsB;QAC3C,gCAAgC,CAC9B,EAAE,EACF,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,CAAC,cAAc,CAC1B,CAAC;QACF,gCAAgC,CAAC,EAAE,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QAEtF,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC;QAE/B,MAAM,kBAAkB,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnF,IAAI,kBAAkB,EAAE,CAAC;YACvB,kBAAkB,CAAC,IAAI,GAAG,aAAa,EAAE,CAAC;YAE1C,MAAM,GAAG,GAAG,GAAG,UAAU,CAAC,uBAAuB,IAAI,UAAU,CAAC,YAAY,IAAI,UAAU,CAAC,aAAa,EAAE,CAAC;YAC3G,IAAI,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEvD,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;gBACzB,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;gBACzB,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YACpD,CAAC;YAED,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,uBAA+B,EAC/B,YAAoB,EACpB,aAAqB;QAErB,MAAM,GAAG,GAAG,GAAG,uBAAuB,IAAI,YAAY,IAAI,aAAa,EAAE,CAAC;QAE1E,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEzD,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;YACzB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,WAAW,GAAG,EAAE,CAAC;QAEvB,KAAK,MAAM,KAAK,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { CheckpointStore, PartitionOwnership } from \"./eventProcessor.js\";\nimport type { Checkpoint } from \"./partitionProcessor.js\";\nimport { throwTypeErrorIfParameterMissing } from \"./util/error.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\n/**\n * The `EventProcessor` relies on a `CheckpointStore` to store checkpoints and handle partition\n * ownerships. `InMemoryCheckpointStore` is simple partition manager that stores checkpoints and\n * partition ownerships in memory of your program.\n *\n * You can use the `InMemoryCheckpointStore` to get started with using the `EventProcessor`.\n * But in production, you should choose an implementation of the `CheckpointStore` interface that will\n * store the checkpoints and partition ownerships to a durable store instead.\n *\n * @internal\n */\nexport class InMemoryCheckpointStore implements CheckpointStore {\n private _partitionOwnershipMap: Map<string, PartitionOwnership> = new Map();\n private _committedCheckpoints: Map<string, Map<string, Checkpoint>> = new Map();\n\n /**\n * Get the list of all existing partition ownership from the underlying data store. Could return empty\n * results if there are is no existing ownership information.\n *\n * @param fullyQualifiedNamespace - The fully qualified Event Hubs namespace. This is likely to be similar to\n * <yournamespace>.servicebus.windows.net.\n * @param eventHubName - The event hub name.\n * @param consumerGroup - The consumer group name.\n * @returns Partition ownership details of all the partitions that have/had an owner..\n */\n async listOwnership(\n _fullyQualifiedNamespace: string,\n _eventHubName: string,\n _consumerGroup: string,\n ): Promise<PartitionOwnership[]> {\n const ownerships = [];\n\n for (const value of this._partitionOwnershipMap.values()) {\n ownerships.push({ ...value });\n }\n\n return ownerships;\n }\n\n /**\n * Claim ownership of a list of partitions. This will return the list of partitions that were owned\n * successfully.\n *\n * @param partitionOwnership - The list of partition ownership this instance is claiming to own.\n * @returns A list partitions this instance successfully claimed ownership.\n */\n async claimOwnership(partitionOwnership: PartitionOwnership[]): Promise<PartitionOwnership[]> {\n const claimedOwnerships = [];\n\n for (const ownership of partitionOwnership) {\n if (\n !this._partitionOwnershipMap.has(ownership.partitionId) ||\n this._partitionOwnershipMap.get(ownership.partitionId)!.etag === ownership.etag\n ) {\n const date = new Date();\n\n const newOwnership = {\n ...ownership,\n etag: getRandomName(),\n lastModifiedTimeInMs: date.getTime(),\n };\n\n this._partitionOwnershipMap.set(newOwnership.partitionId, newOwnership);\n claimedOwnerships.push(newOwnership);\n }\n }\n return claimedOwnerships;\n }\n\n /**\n * Updates the checkpoint in the data store for a partition.\n *\n * @param checkpoint - The checkpoint.\n */\n async updateCheckpoint(checkpoint: Checkpoint): Promise<void> {\n throwTypeErrorIfParameterMissing(\n \"\",\n \"updateCheckpoint\",\n \"sequenceNumber\",\n checkpoint.sequenceNumber,\n );\n throwTypeErrorIfParameterMissing(\"\", \"updateCheckpoint\", \"offset\", checkpoint.offset);\n\n checkpoint = { ...checkpoint };\n\n const partitionOwnership = this._partitionOwnershipMap.get(checkpoint.partitionId);\n if (partitionOwnership) {\n partitionOwnership.etag = getRandomName();\n\n const key = `${checkpoint.fullyQualifiedNamespace}:${checkpoint.eventHubName}:${checkpoint.consumerGroup}`;\n let partitionMap = this._committedCheckpoints.get(key);\n\n if (partitionMap == null) {\n partitionMap = new Map();\n this._committedCheckpoints.set(key, partitionMap);\n }\n\n partitionMap.set(checkpoint.partitionId, checkpoint);\n }\n }\n\n async listCheckpoints(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n consumerGroup: string,\n ): Promise<Checkpoint[]> {\n const key = `${fullyQualifiedNamespace}:${eventHubName}:${consumerGroup}`;\n\n const partitionMap = this._committedCheckpoints.get(key);\n\n if (partitionMap == null) {\n return [];\n }\n\n const checkpoints = [];\n\n for (const value of partitionMap.values()) {\n checkpoints.push({ ...value });\n }\n\n return checkpoints;\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { EventData, ReceivedEventData } from "./eventData.js";
|
|
2
|
+
export { WebSocketImpl } from "rhea-promise";
|
|
3
|
+
export { LastEnqueuedEventProperties } from "./partitionReceiver.js";
|
|
4
|
+
export { OperationOptions } from "./util/operationOptions.js";
|
|
5
|
+
export { EventHubClientOptions, EventHubConsumerClientOptions, LoadBalancingOptions, SendBatchOptions, CreateBatchOptions, GetPartitionIdsOptions, GetPartitionPropertiesOptions, GetEventHubPropertiesOptions, } from "./models/public.js";
|
|
6
|
+
export { EventHubConsumerClient } from "./eventHubConsumerClient.js";
|
|
7
|
+
export { EventHubProducerClient } from "./eventHubProducerClient.js";
|
|
8
|
+
export { BufferedCloseOptions, EventHubBufferedProducerClient, EventHubBufferedProducerClientOptions, EnqueueEventOptions, BufferedFlushOptions, OnSendEventsErrorContext, OnSendEventsSuccessContext, } from "./eventHubBufferedProducerClient.js";
|
|
9
|
+
export { SubscribeOptions, Subscription, SubscriptionEventHandlers, PartitionContext, ProcessErrorHandler, ProcessInitializeHandler, ProcessCloseHandler, ProcessEventsHandler, } from "./eventHubConsumerClientModels.js";
|
|
10
|
+
export { EventPosition, latestEventPosition, earliestEventPosition } from "./eventPosition.js";
|
|
11
|
+
export { PartitionProperties, EventHubProperties } from "./managementClient.js";
|
|
12
|
+
export { EventDataBatch, TryAddOptions } from "./eventDataBatch.js";
|
|
13
|
+
export { Checkpoint } from "./partitionProcessor.js";
|
|
14
|
+
export { CheckpointStore, PartitionOwnership } from "./eventProcessor.js";
|
|
15
|
+
export { CloseReason } from "./models/public.js";
|
|
16
|
+
export { MessagingError, RetryOptions, RetryMode, WebSocketOptions } from "@azure/core-amqp";
|
|
17
|
+
export { TokenCredential } from "@azure/core-auth";
|
|
18
|
+
export { logger } from "./logger.js";
|
|
19
|
+
export { parseEventHubConnectionString, EventHubConnectionStringProperties, } from "./util/connectionStringUtils.js";
|
|
20
|
+
export * from "./eventDataAdapter.js";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,8BAA8B,EAC9B,qCAAqC,EACrC,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,yBAAyB,EACzB,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,GACnC,MAAM,iCAAiC,CAAC;AAEzC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
export { EventHubConsumerClient } from "./eventHubConsumerClient.js";
|
|
4
|
+
export { EventHubProducerClient } from "./eventHubProducerClient.js";
|
|
5
|
+
export { EventHubBufferedProducerClient, } from "./eventHubBufferedProducerClient.js";
|
|
6
|
+
export { latestEventPosition, earliestEventPosition } from "./eventPosition.js";
|
|
7
|
+
export { CloseReason } from "./models/public.js";
|
|
8
|
+
export { MessagingError, RetryMode } from "@azure/core-amqp";
|
|
9
|
+
export { logger } from "./logger.js";
|
|
10
|
+
export { parseEventHubConnectionString, } from "./util/connectionStringUtils.js";
|
|
11
|
+
export * from "./eventDataAdapter.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAgBlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAEL,8BAA8B,GAM/B,MAAM,qCAAqC,CAAC;AAW7C,OAAO,EAAiB,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAK/F,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAgB,SAAS,EAAoB,MAAM,kBAAkB,CAAC;AAE7F,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,6BAA6B,GAE9B,MAAM,iCAAiC,CAAC;AAEzC,cAAc,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport { EventData, ReceivedEventData } from \"./eventData.js\";\nexport { WebSocketImpl } from \"rhea-promise\";\nexport { LastEnqueuedEventProperties } from \"./partitionReceiver.js\";\nexport { OperationOptions } from \"./util/operationOptions.js\";\nexport {\n EventHubClientOptions,\n EventHubConsumerClientOptions,\n LoadBalancingOptions,\n SendBatchOptions,\n CreateBatchOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n GetEventHubPropertiesOptions,\n} from \"./models/public.js\";\nexport { EventHubConsumerClient } from \"./eventHubConsumerClient.js\";\nexport { EventHubProducerClient } from \"./eventHubProducerClient.js\";\nexport {\n BufferedCloseOptions,\n EventHubBufferedProducerClient,\n EventHubBufferedProducerClientOptions,\n EnqueueEventOptions,\n BufferedFlushOptions,\n OnSendEventsErrorContext,\n OnSendEventsSuccessContext,\n} from \"./eventHubBufferedProducerClient.js\";\nexport {\n SubscribeOptions,\n Subscription,\n SubscriptionEventHandlers,\n PartitionContext,\n ProcessErrorHandler,\n ProcessInitializeHandler,\n ProcessCloseHandler,\n ProcessEventsHandler,\n} from \"./eventHubConsumerClientModels.js\";\nexport { EventPosition, latestEventPosition, earliestEventPosition } from \"./eventPosition.js\";\nexport { PartitionProperties, EventHubProperties } from \"./managementClient.js\";\nexport { EventDataBatch, TryAddOptions } from \"./eventDataBatch.js\";\nexport { Checkpoint } from \"./partitionProcessor.js\";\nexport { CheckpointStore, PartitionOwnership } from \"./eventProcessor.js\";\nexport { CloseReason } from \"./models/public.js\";\nexport { MessagingError, RetryOptions, RetryMode, WebSocketOptions } from \"@azure/core-amqp\";\nexport { TokenCredential } from \"@azure/core-auth\";\nexport { logger } from \"./logger.js\";\nexport {\n parseEventHubConnectionString,\n EventHubConnectionStringProperties,\n} from \"./util/connectionStringUtils.js\";\n\nexport * from \"./eventDataAdapter.js\";\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { LoadBalancingStrategy } from "./loadBalancingStrategy.js";
|
|
2
|
+
import type { PartitionOwnership } from "../eventProcessor.js";
|
|
3
|
+
/**
|
|
4
|
+
* The BalancedLoadBalancerStrategy is meant to be used when the user
|
|
5
|
+
* wants to reach a load balanced state with less partition 'thrashing'.
|
|
6
|
+
*
|
|
7
|
+
* Partition thrashing - where a partition changes owners - is minimized
|
|
8
|
+
* by only returning a single partition to claim at a time.
|
|
9
|
+
* This minimizes the number of times a partition should need to be stolen.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare class BalancedLoadBalancingStrategy implements LoadBalancingStrategy {
|
|
13
|
+
private readonly _partitionOwnershipExpirationIntervalInMs;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of BalancedLoadBalancingStrategy.
|
|
16
|
+
*
|
|
17
|
+
* @param _partitionOwnershipExpirationIntervalInMs - The length of time a partition claim is valid.
|
|
18
|
+
*/
|
|
19
|
+
constructor(_partitionOwnershipExpirationIntervalInMs: number);
|
|
20
|
+
/**
|
|
21
|
+
* Implements load balancing by taking into account current ownership and
|
|
22
|
+
* the full set of partitions in the Event Hub.
|
|
23
|
+
* @param ourOwnerId - The id we should assume is _our_ id when checking for ownership.
|
|
24
|
+
* @param claimedPartitionOwnershipMap - The current claimed ownerships for partitions.
|
|
25
|
+
* @param partitionIds - Partitions to assign owners to.
|
|
26
|
+
* @returns Partition ids to claim.
|
|
27
|
+
*/
|
|
28
|
+
getPartitionsToClaim(ourOwnerId: string, claimedPartitionOwnershipMap: Map<string, PartitionOwnership>, partitionIds: string[]): string[];
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=balancedStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balancedStrategy.d.ts","sourceRoot":"","sources":["../../../src/loadBalancerStrategies/balancedStrategy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;;;;;;;GAQG;AACH,qBAAa,6BAA8B,YAAW,qBAAqB;IAM7D,OAAO,CAAC,QAAQ,CAAC,yCAAyC;IALtE;;;;OAIG;gBAC0B,yCAAyC,EAAE,MAAM;IAE9E;;;;;;;OAOG;IACI,oBAAoB,CACzB,UAAU,EAAE,MAAM,EAClB,4BAA4B,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAC7D,YAAY,EAAE,MAAM,EAAE,GACrB,MAAM,EAAE;CAeZ"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { listAvailablePartitions } from "./loadBalancingStrategy.js";
|
|
4
|
+
/**
|
|
5
|
+
* The BalancedLoadBalancerStrategy is meant to be used when the user
|
|
6
|
+
* wants to reach a load balanced state with less partition 'thrashing'.
|
|
7
|
+
*
|
|
8
|
+
* Partition thrashing - where a partition changes owners - is minimized
|
|
9
|
+
* by only returning a single partition to claim at a time.
|
|
10
|
+
* This minimizes the number of times a partition should need to be stolen.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export class BalancedLoadBalancingStrategy {
|
|
14
|
+
_partitionOwnershipExpirationIntervalInMs;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of BalancedLoadBalancingStrategy.
|
|
17
|
+
*
|
|
18
|
+
* @param _partitionOwnershipExpirationIntervalInMs - The length of time a partition claim is valid.
|
|
19
|
+
*/
|
|
20
|
+
constructor(_partitionOwnershipExpirationIntervalInMs) {
|
|
21
|
+
this._partitionOwnershipExpirationIntervalInMs = _partitionOwnershipExpirationIntervalInMs;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Implements load balancing by taking into account current ownership and
|
|
25
|
+
* the full set of partitions in the Event Hub.
|
|
26
|
+
* @param ourOwnerId - The id we should assume is _our_ id when checking for ownership.
|
|
27
|
+
* @param claimedPartitionOwnershipMap - The current claimed ownerships for partitions.
|
|
28
|
+
* @param partitionIds - Partitions to assign owners to.
|
|
29
|
+
* @returns Partition ids to claim.
|
|
30
|
+
*/
|
|
31
|
+
getPartitionsToClaim(ourOwnerId, claimedPartitionOwnershipMap, partitionIds) {
|
|
32
|
+
const claimablePartitions = listAvailablePartitions(ourOwnerId, claimedPartitionOwnershipMap, partitionIds, this._partitionOwnershipExpirationIntervalInMs);
|
|
33
|
+
if (!claimablePartitions.length) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const randomIndex = Math.floor(Math.random() * claimablePartitions.length);
|
|
37
|
+
return [claimablePartitions[randomIndex]];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=balancedStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balancedStrategy.js","sourceRoot":"","sources":["../../../src/loadBalancerStrategies/balancedStrategy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAGrE;;;;;;;;GAQG;AACH,MAAM,OAAO,6BAA6B;IAMX;IAL7B;;;;OAIG;IACH,YAA6B,yCAAiD;QAAjD,8CAAyC,GAAzC,yCAAyC,CAAQ;IAAG,CAAC;IAElF;;;;;;;OAOG;IACI,oBAAoB,CACzB,UAAkB,EAClB,4BAA6D,EAC7D,YAAsB;QAEtB,MAAM,mBAAmB,GAAG,uBAAuB,CACjD,UAAU,EACV,4BAA4B,EAC5B,YAAY,EACZ,IAAI,CAAC,yCAAyC,CAC/C,CAAC;QAEF,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,CAAC;YAChC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAC3E,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { LoadBalancingStrategy } from \"./loadBalancingStrategy.js\";\nimport { listAvailablePartitions } from \"./loadBalancingStrategy.js\";\nimport type { PartitionOwnership } from \"../eventProcessor.js\";\n\n/**\n * The BalancedLoadBalancerStrategy is meant to be used when the user\n * wants to reach a load balanced state with less partition 'thrashing'.\n *\n * Partition thrashing - where a partition changes owners - is minimized\n * by only returning a single partition to claim at a time.\n * This minimizes the number of times a partition should need to be stolen.\n * @internal\n */\nexport class BalancedLoadBalancingStrategy implements LoadBalancingStrategy {\n /**\n * Creates an instance of BalancedLoadBalancingStrategy.\n *\n * @param _partitionOwnershipExpirationIntervalInMs - The length of time a partition claim is valid.\n */\n constructor(private readonly _partitionOwnershipExpirationIntervalInMs: number) {}\n\n /**\n * Implements load balancing by taking into account current ownership and\n * the full set of partitions in the Event Hub.\n * @param ourOwnerId - The id we should assume is _our_ id when checking for ownership.\n * @param claimedPartitionOwnershipMap - The current claimed ownerships for partitions.\n * @param partitionIds - Partitions to assign owners to.\n * @returns Partition ids to claim.\n */\n public getPartitionsToClaim(\n ourOwnerId: string,\n claimedPartitionOwnershipMap: Map<string, PartitionOwnership>,\n partitionIds: string[],\n ): string[] {\n const claimablePartitions = listAvailablePartitions(\n ourOwnerId,\n claimedPartitionOwnershipMap,\n partitionIds,\n this._partitionOwnershipExpirationIntervalInMs,\n );\n\n if (!claimablePartitions.length) {\n return [];\n }\n\n const randomIndex = Math.floor(Math.random() * claimablePartitions.length);\n return [claimablePartitions[randomIndex]];\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LoadBalancingStrategy } from "./loadBalancingStrategy.js";
|
|
2
|
+
import type { PartitionOwnership } from "../eventProcessor.js";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare class GreedyLoadBalancingStrategy implements LoadBalancingStrategy {
|
|
7
|
+
private readonly _partitionOwnershipExpirationIntervalInMs;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of GreedyLoadBalancingStrategy.
|
|
10
|
+
*
|
|
11
|
+
* @param _partitionOwnershipExpirationIntervalInMs - The length of time a partition claim is valid.
|
|
12
|
+
*/
|
|
13
|
+
constructor(_partitionOwnershipExpirationIntervalInMs: number);
|
|
14
|
+
/**
|
|
15
|
+
* Implements load balancing by taking into account current ownership and
|
|
16
|
+
* the new set of partitions to add.
|
|
17
|
+
* @param ourOwnerId - The id we should assume is _our_ id when checking for ownership.
|
|
18
|
+
* @param claimedPartitionOwnershipMap - The current claimed ownerships for partitions.
|
|
19
|
+
* @param partitionIds - Partitions to assign owners to.
|
|
20
|
+
* @returns Partition ids to claim.
|
|
21
|
+
*/
|
|
22
|
+
getPartitionsToClaim(ourOwnerId: string, claimedPartitionOwnershipMap: Map<string, PartitionOwnership>, partitionIds: string[]): string[];
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=greedyStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greedyStrategy.d.ts","sourceRoot":"","sources":["../../../src/loadBalancerStrategies/greedyStrategy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;GAEG;AACH,qBAAa,2BAA4B,YAAW,qBAAqB;IAM3D,OAAO,CAAC,QAAQ,CAAC,yCAAyC;IALtE;;;;OAIG;gBAC0B,yCAAyC,EAAE,MAAM;IAE9E;;;;;;;OAOG;IACI,oBAAoB,CACzB,UAAU,EAAE,MAAM,EAClB,4BAA4B,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAC7D,YAAY,EAAE,MAAM,EAAE,GACrB,MAAM,EAAE;CAQZ"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { listAvailablePartitions } from "./loadBalancingStrategy.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export class GreedyLoadBalancingStrategy {
|
|
8
|
+
_partitionOwnershipExpirationIntervalInMs;
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of GreedyLoadBalancingStrategy.
|
|
11
|
+
*
|
|
12
|
+
* @param _partitionOwnershipExpirationIntervalInMs - The length of time a partition claim is valid.
|
|
13
|
+
*/
|
|
14
|
+
constructor(_partitionOwnershipExpirationIntervalInMs) {
|
|
15
|
+
this._partitionOwnershipExpirationIntervalInMs = _partitionOwnershipExpirationIntervalInMs;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Implements load balancing by taking into account current ownership and
|
|
19
|
+
* the new set of partitions to add.
|
|
20
|
+
* @param ourOwnerId - The id we should assume is _our_ id when checking for ownership.
|
|
21
|
+
* @param claimedPartitionOwnershipMap - The current claimed ownerships for partitions.
|
|
22
|
+
* @param partitionIds - Partitions to assign owners to.
|
|
23
|
+
* @returns Partition ids to claim.
|
|
24
|
+
*/
|
|
25
|
+
getPartitionsToClaim(ourOwnerId, claimedPartitionOwnershipMap, partitionIds) {
|
|
26
|
+
return listAvailablePartitions(ourOwnerId, claimedPartitionOwnershipMap, partitionIds, this._partitionOwnershipExpirationIntervalInMs);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=greedyStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greedyStrategy.js","sourceRoot":"","sources":["../../../src/loadBalancerStrategies/greedyStrategy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAGrE;;GAEG;AACH,MAAM,OAAO,2BAA2B;IAMT;IAL7B;;;;OAIG;IACH,YAA6B,yCAAiD;QAAjD,8CAAyC,GAAzC,yCAAyC,CAAQ;IAAG,CAAC;IAElF;;;;;;;OAOG;IACI,oBAAoB,CACzB,UAAkB,EAClB,4BAA6D,EAC7D,YAAsB;QAEtB,OAAO,uBAAuB,CAC5B,UAAU,EACV,4BAA4B,EAC5B,YAAY,EACZ,IAAI,CAAC,yCAAyC,CAC/C,CAAC;IACJ,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { LoadBalancingStrategy } from \"./loadBalancingStrategy.js\";\nimport { listAvailablePartitions } from \"./loadBalancingStrategy.js\";\nimport type { PartitionOwnership } from \"../eventProcessor.js\";\n\n/**\n * @internal\n */\nexport class GreedyLoadBalancingStrategy implements LoadBalancingStrategy {\n /**\n * Creates an instance of GreedyLoadBalancingStrategy.\n *\n * @param _partitionOwnershipExpirationIntervalInMs - The length of time a partition claim is valid.\n */\n constructor(private readonly _partitionOwnershipExpirationIntervalInMs: number) {}\n\n /**\n * Implements load balancing by taking into account current ownership and\n * the new set of partitions to add.\n * @param ourOwnerId - The id we should assume is _our_ id when checking for ownership.\n * @param claimedPartitionOwnershipMap - The current claimed ownerships for partitions.\n * @param partitionIds - Partitions to assign owners to.\n * @returns Partition ids to claim.\n */\n public getPartitionsToClaim(\n ourOwnerId: string,\n claimedPartitionOwnershipMap: Map<string, PartitionOwnership>,\n partitionIds: string[],\n ): string[] {\n return listAvailablePartitions(\n ourOwnerId,\n claimedPartitionOwnershipMap,\n partitionIds,\n this._partitionOwnershipExpirationIntervalInMs,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PartitionOwnership } from "../eventProcessor.js";
|
|
2
|
+
/**
|
|
3
|
+
* Determines which partitions to claim as part of load balancing.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export interface LoadBalancingStrategy {
|
|
7
|
+
/**
|
|
8
|
+
* Implements load balancing by taking into account current ownership and
|
|
9
|
+
* the full set of partitions in the Event Hub.
|
|
10
|
+
* @param ourOwnerId - The id we should assume is _our_ id when checking for ownership.
|
|
11
|
+
* @param claimedPartitionOwnershipMap - The current claimed ownerships for partitions.
|
|
12
|
+
* @param partitionIds - Partitions to assign owners to.
|
|
13
|
+
* @returns Partition ids to claim.
|
|
14
|
+
*/
|
|
15
|
+
getPartitionsToClaim(ownerId: string, claimedPartitionOwnershipMap: Map<string, PartitionOwnership>, partitionIds: string[]): string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Identifies all of the partitions that can be claimed by the specified owner for
|
|
19
|
+
* that owner to reach a balanced state.
|
|
20
|
+
* @param OwnerId - The id we should assume is _our_ id when checking for ownership.
|
|
21
|
+
* @param claimedPartitionOwnershipMap - The current claimed ownerships for partitions.
|
|
22
|
+
* @param partitionIds - Partitions to assign owners to.
|
|
23
|
+
* @param expirationIntervalInMs - The length of time a partition claim is valid.
|
|
24
|
+
* @returns Partition ids that may be claimed.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export declare function listAvailablePartitions(ownerId: string, claimedPartitionOwnershipMap: Map<string, PartitionOwnership>, partitionIds: string[], expirationIntervalInMs: number): string[];
|
|
28
|
+
//# sourceMappingURL=loadBalancingStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadBalancingStrategy.d.ts","sourceRoot":"","sources":["../../../src/loadBalancerStrategies/loadBalancingStrategy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;;OAOG;IACH,oBAAoB,CAClB,OAAO,EAAE,MAAM,EACf,4BAA4B,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAC7D,YAAY,EAAE,MAAM,EAAE,GACrB,MAAM,EAAE,CAAC;CACb;AA2PD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,4BAA4B,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAC7D,YAAY,EAAE,MAAM,EAAE,EACtB,sBAAsB,EAAE,MAAM,GAC7B,MAAM,EAAE,CA8FV"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { logger } from "../logger.js";
|
|
4
|
+
/**
|
|
5
|
+
* This method will create a new map of partition id and PartitionOwnership containing only those partitions
|
|
6
|
+
* that are actively owned.
|
|
7
|
+
* All entries in the original map that haven't been modified for a duration of time greater than the allowed
|
|
8
|
+
* inactivity time limit are assumed to be owned by dead event processors.
|
|
9
|
+
* These will not be included in the map returned by this method.
|
|
10
|
+
*
|
|
11
|
+
* @param partitionOwnershipMap - The existing PartitionOwnerships mapped by partition.
|
|
12
|
+
* @param expirationIntervalInMs - The length of time a PartitionOwnership claim is valid.
|
|
13
|
+
*/
|
|
14
|
+
function getActivePartitionOwnerships(partitionOwnershipMap, expirationIntervalInMs) {
|
|
15
|
+
const activePartitionOwnershipMap = new Map();
|
|
16
|
+
partitionOwnershipMap.forEach((partitionOwnership, partitionId) => {
|
|
17
|
+
// If lastModifiedtimeInMs is missing, assume it is inactive.
|
|
18
|
+
if (typeof partitionOwnership.lastModifiedTimeInMs === "undefined" ||
|
|
19
|
+
partitionOwnership.lastModifiedTimeInMs === null) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const timeSincePartitionClaimed = Date.now() - partitionOwnership.lastModifiedTimeInMs;
|
|
23
|
+
if (timeSincePartitionClaimed < expirationIntervalInMs && partitionOwnership.ownerId) {
|
|
24
|
+
activePartitionOwnershipMap.set(partitionId, partitionOwnership);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return activePartitionOwnershipMap;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Calculates the minimum number of partitions each EventProcessor should own,
|
|
31
|
+
* and the number of EventProcessors that should have an extra partition assigned.
|
|
32
|
+
* @param ownerToOwnershipMap - The current ownerships for partitions.
|
|
33
|
+
* @param partitionIds - The full list of the Event Hub's partition ids.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
function calculateBalancedLoadCounts(ownerToOwnershipMap, partitionIds) {
|
|
37
|
+
// Calculate the minimum number of partitions every EventProcessor should own when the load
|
|
38
|
+
// is evenly distributed.
|
|
39
|
+
const minPartitionsPerOwner = Math.floor(partitionIds.length / ownerToOwnershipMap.size);
|
|
40
|
+
// If the number of partitions in the Event Hub is not evenly divisible by the number of active
|
|
41
|
+
// EventProcesrrors, some EventProcessors may own 1 partition in addition to the minimum when the
|
|
42
|
+
// load is balanced.
|
|
43
|
+
// Calculate the number of EventProcessors that can own an additional partition.
|
|
44
|
+
const requiredNumberOfOwnersWithExtraPartition = partitionIds.length % ownerToOwnershipMap.size;
|
|
45
|
+
return {
|
|
46
|
+
minPartitionsPerOwner,
|
|
47
|
+
requiredNumberOfOwnersWithExtraPartition,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Counts the EventProcessors and tallies them by type.
|
|
52
|
+
*
|
|
53
|
+
* To be in balance we need to make sure that each EventProcessor is only consuming
|
|
54
|
+
* their fair share.
|
|
55
|
+
*
|
|
56
|
+
* When the partitions are divvied up we will sometimes end up with some EventProcessors
|
|
57
|
+
* that will have 1 more partition than others.
|
|
58
|
+
* This can happen if the number of partitions is not evenly divisible by the number of EventProcessors.
|
|
59
|
+
*
|
|
60
|
+
* So this function largely exists to support isLoadBalanced() and
|
|
61
|
+
* shouldOwnMorePartitions(), both of which depend on knowing if our current list
|
|
62
|
+
* of EventProcessors is actually in the proper state.
|
|
63
|
+
*
|
|
64
|
+
* @param minPartitionsPerOwner - The number of required partitions per EventProcessor.
|
|
65
|
+
* @param ownerToOwnershipMap - The current ownerships for partitions.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
function getEventProcessorCounts(minPartitionsPerOwner, ownerToOwnershipMap) {
|
|
69
|
+
const counts = {
|
|
70
|
+
haveRequiredPartitions: 0,
|
|
71
|
+
haveAdditionalPartition: 0,
|
|
72
|
+
haveTooManyPartitions: 0,
|
|
73
|
+
};
|
|
74
|
+
for (const ownershipList of ownerToOwnershipMap.values()) {
|
|
75
|
+
const numberOfPartitions = ownershipList.length;
|
|
76
|
+
// there are basically three kinds of partition counts
|
|
77
|
+
// for a processor:
|
|
78
|
+
if (numberOfPartitions === minPartitionsPerOwner) {
|
|
79
|
+
// 1. Has _exactly_ the required number of partitions
|
|
80
|
+
counts.haveRequiredPartitions++;
|
|
81
|
+
}
|
|
82
|
+
else if (numberOfPartitions === minPartitionsPerOwner + 1) {
|
|
83
|
+
// 2. Has the required number plus one extra (correct in cases)
|
|
84
|
+
// where the # of partitions is not evenly divisible by the
|
|
85
|
+
// number of processors.
|
|
86
|
+
counts.haveAdditionalPartition++;
|
|
87
|
+
}
|
|
88
|
+
else if (numberOfPartitions > minPartitionsPerOwner + 1) {
|
|
89
|
+
// 3. has more than the possible # of partitions required
|
|
90
|
+
counts.haveTooManyPartitions++;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return counts;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Validates that we are currently in a balanced state - all EventProcessors own the
|
|
97
|
+
* minimum required number of partitions (and additional partitions, if the # of partitions
|
|
98
|
+
* is not evenly divisible by the # of EventProcessors).
|
|
99
|
+
*
|
|
100
|
+
* @param requiredNumberOfOwnersWithExtraPartition - The # of EventProcessors that process an additional partition, in addition to the required minimum.
|
|
101
|
+
* @param totalExpectedProcessors - The total # of EventProcessors we expect.
|
|
102
|
+
* @param eventProcessorCounts - EventProcessor counts, grouped by criteria.
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
function isLoadBalanced(requiredNumberOfOwnersWithExtraPartition, totalExpectedEventProcessors, { haveAdditionalPartition, haveRequiredPartitions }) {
|
|
106
|
+
return (haveAdditionalPartition === requiredNumberOfOwnersWithExtraPartition &&
|
|
107
|
+
haveRequiredPartitions + haveAdditionalPartition === totalExpectedEventProcessors);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Determines the number of new partitions to claim for this particular processor.
|
|
111
|
+
*
|
|
112
|
+
* @param minRequired - The minimum required number of partitions.
|
|
113
|
+
* @param requiredNumberOfOwnersWithExtraPartition - The current number of processors that should have an additional partition.
|
|
114
|
+
* @param numPartitionsOwnedByUs - The number of partitions we currently own.
|
|
115
|
+
* @param eventProcessorCounts - Processors, grouped by criteria.
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
function getNumberOfPartitionsToClaim(minRequiredPartitionCount, requiredNumberOfOwnersWithExtraPartition, numPartitionsOwnedByUs, { haveAdditionalPartition, haveTooManyPartitions }) {
|
|
119
|
+
let actualRequiredPartitionCount = minRequiredPartitionCount;
|
|
120
|
+
if (requiredNumberOfOwnersWithExtraPartition > 0 &&
|
|
121
|
+
// Eventually the `haveTooManyPartitions` will decay into `haveAdditionalPartition`
|
|
122
|
+
// EventProcessors as partitions are balanced to consumers that aren't at par.
|
|
123
|
+
// We can consider them to be `haveAdditionalPartition` EventProcessors for our purposes.
|
|
124
|
+
haveAdditionalPartition + haveTooManyPartitions < requiredNumberOfOwnersWithExtraPartition) {
|
|
125
|
+
// Overall we don't have enough EventProcessors that are taking on an additional partition
|
|
126
|
+
// so we should attempt to.
|
|
127
|
+
actualRequiredPartitionCount = minRequiredPartitionCount + 1;
|
|
128
|
+
}
|
|
129
|
+
return actualRequiredPartitionCount - numPartitionsOwnedByUs;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Determines which partitions can be stolen from other owners while maintaining
|
|
133
|
+
* a balanced state.
|
|
134
|
+
* @param numberOfPartitionsToClaim - The number of partitions the owner needs to claim to reach a balanced state.
|
|
135
|
+
* @param minPartitionsPerOwner - The minimum number of partitions each owner needs for the partition load to be balanced.
|
|
136
|
+
* @param requiredNumberOfOwnersWithExtraPartition - The number of owners that should have 1 extra partition.
|
|
137
|
+
* @param ourOwnerId - The id of _our_ owner.
|
|
138
|
+
* @param ownerToOwnershipMap - The current ownerships for partitions.
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
function findPartitionsToSteal(numberOfPartitionsToClaim, minPartitionsPerOwner, requiredNumberOfOwnersWithExtraPartition, ourOwnerId, ownerToOwnershipMap) {
|
|
142
|
+
const partitionsToSteal = [];
|
|
143
|
+
// Create a list of PartitionOwnership lists that we can steal from.
|
|
144
|
+
const listOfPartitionOwnerships = [];
|
|
145
|
+
ownerToOwnershipMap.forEach((partitionOwnerships, ownerId) => {
|
|
146
|
+
if (ownerId === ourOwnerId || partitionOwnerships.length <= minPartitionsPerOwner)
|
|
147
|
+
return;
|
|
148
|
+
listOfPartitionOwnerships.push(partitionOwnerships);
|
|
149
|
+
});
|
|
150
|
+
// Sort the list in descending order based on the length of each element.
|
|
151
|
+
listOfPartitionOwnerships.sort((a, b) => {
|
|
152
|
+
if (a.length > b.length)
|
|
153
|
+
return -1;
|
|
154
|
+
if (a.length < b.length)
|
|
155
|
+
return 1;
|
|
156
|
+
return 0;
|
|
157
|
+
});
|
|
158
|
+
// Attempt to steal partitions from EventProcessors that have the most partitions 1st,
|
|
159
|
+
// then work our way down.
|
|
160
|
+
let ownersEncounteredWithExtraPartitions = 0;
|
|
161
|
+
let currentPartitionOwnershipList = listOfPartitionOwnerships.shift();
|
|
162
|
+
while (numberOfPartitionsToClaim > 0 && currentPartitionOwnershipList) {
|
|
163
|
+
let ownersExpectedPartitionCount = minPartitionsPerOwner;
|
|
164
|
+
// Determine if the current owner should be allowed to have an extra partition.
|
|
165
|
+
if (ownersEncounteredWithExtraPartitions < requiredNumberOfOwnersWithExtraPartition) {
|
|
166
|
+
ownersExpectedPartitionCount++;
|
|
167
|
+
}
|
|
168
|
+
ownersEncounteredWithExtraPartitions++;
|
|
169
|
+
let numberAvailableToSteal = currentPartitionOwnershipList.length - ownersExpectedPartitionCount;
|
|
170
|
+
// Claim as many random partitions as possible.
|
|
171
|
+
while (Math.min(numberOfPartitionsToClaim, numberAvailableToSteal)) {
|
|
172
|
+
const indexToClaim = Math.floor(Math.random() * currentPartitionOwnershipList.length);
|
|
173
|
+
partitionsToSteal.push(currentPartitionOwnershipList.splice(indexToClaim, 1)[0].partitionId);
|
|
174
|
+
numberOfPartitionsToClaim--;
|
|
175
|
+
numberAvailableToSteal--;
|
|
176
|
+
}
|
|
177
|
+
// Move on to the next list of PartitionOwnership.
|
|
178
|
+
currentPartitionOwnershipList = listOfPartitionOwnerships.shift();
|
|
179
|
+
}
|
|
180
|
+
return partitionsToSteal;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Identifies all of the partitions that can be claimed by the specified owner for
|
|
184
|
+
* that owner to reach a balanced state.
|
|
185
|
+
* @param OwnerId - The id we should assume is _our_ id when checking for ownership.
|
|
186
|
+
* @param claimedPartitionOwnershipMap - The current claimed ownerships for partitions.
|
|
187
|
+
* @param partitionIds - Partitions to assign owners to.
|
|
188
|
+
* @param expirationIntervalInMs - The length of time a partition claim is valid.
|
|
189
|
+
* @returns Partition ids that may be claimed.
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
export function listAvailablePartitions(ownerId, claimedPartitionOwnershipMap, partitionIds, expirationIntervalInMs) {
|
|
193
|
+
if (!partitionIds.length) {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
// Collect only the PartitionOwnership that have been updated within the expiration interval.
|
|
197
|
+
// Any PartitionOwnership that has been updated outside the expiration interval can be claimed.
|
|
198
|
+
const activePartitionOwnershipMap = getActivePartitionOwnerships(claimedPartitionOwnershipMap, expirationIntervalInMs);
|
|
199
|
+
logger.verbose(`[${ownerId}] Number of active ownership records: ${activePartitionOwnershipMap.size}.`);
|
|
200
|
+
if (activePartitionOwnershipMap.size === 0) {
|
|
201
|
+
// All partitions in this Event Hub are available to claim.
|
|
202
|
+
return partitionIds;
|
|
203
|
+
}
|
|
204
|
+
// Map ownerIds to the partitions they own so that we can determine how many each owner has.
|
|
205
|
+
const ownerToOwnershipMap = new Map();
|
|
206
|
+
for (const activeOwnership of activePartitionOwnershipMap.values()) {
|
|
207
|
+
const partitionOwnershipList = ownerToOwnershipMap.get(activeOwnership.ownerId) || [];
|
|
208
|
+
partitionOwnershipList.push(activeOwnership);
|
|
209
|
+
ownerToOwnershipMap.set(activeOwnership.ownerId, partitionOwnershipList);
|
|
210
|
+
}
|
|
211
|
+
// Add the current EventProcessor to the map of owners to ownerships if it doesn't exist.
|
|
212
|
+
if (!ownerToOwnershipMap.has(ownerId)) {
|
|
213
|
+
ownerToOwnershipMap.set(ownerId, []);
|
|
214
|
+
}
|
|
215
|
+
logger.info(`[${ownerId}] Number of active event processors: ${ownerToOwnershipMap.size}.`);
|
|
216
|
+
const { minPartitionsPerOwner, requiredNumberOfOwnersWithExtraPartition } = calculateBalancedLoadCounts(ownerToOwnershipMap, partitionIds);
|
|
217
|
+
logger.verbose(`[${ownerId}] Expected minimum number of partitions per event processor: ${minPartitionsPerOwner},` +
|
|
218
|
+
`expected number of event processors with additional partition: ${requiredNumberOfOwnersWithExtraPartition}.`);
|
|
219
|
+
// Get some stats representing the current state the world with regards to how balanced the
|
|
220
|
+
// partitions are across EventProcessors.
|
|
221
|
+
const eventProcessorCounts = getEventProcessorCounts(minPartitionsPerOwner, ownerToOwnershipMap);
|
|
222
|
+
if (isLoadBalanced(requiredNumberOfOwnersWithExtraPartition, ownerToOwnershipMap.size, eventProcessorCounts)) {
|
|
223
|
+
// When the partitions are evenly distributed, no change required.
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
let numberOfPartitionsToClaim = getNumberOfPartitionsToClaim(minPartitionsPerOwner, requiredNumberOfOwnersWithExtraPartition, ownerToOwnershipMap.get(ownerId).length, eventProcessorCounts);
|
|
227
|
+
if (numberOfPartitionsToClaim <= 0) {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
const partitionsToClaim = [];
|
|
231
|
+
const unclaimedPartitionIds = partitionIds.filter((id) => !activePartitionOwnershipMap.has(id));
|
|
232
|
+
// Prioritize getting unclaimed partitions first.
|
|
233
|
+
while (Math.min(numberOfPartitionsToClaim, unclaimedPartitionIds.length)) {
|
|
234
|
+
const indexToClaim = Math.floor(Math.random() * unclaimedPartitionIds.length);
|
|
235
|
+
partitionsToClaim.push(unclaimedPartitionIds.splice(indexToClaim, 1)[0]);
|
|
236
|
+
numberOfPartitionsToClaim--;
|
|
237
|
+
}
|
|
238
|
+
if (numberOfPartitionsToClaim === 0) {
|
|
239
|
+
return partitionsToClaim;
|
|
240
|
+
}
|
|
241
|
+
// Find partitions that can be stolen from other EventProcessors.
|
|
242
|
+
const partitionsToSteal = findPartitionsToSteal(numberOfPartitionsToClaim, minPartitionsPerOwner, requiredNumberOfOwnersWithExtraPartition, ownerId, ownerToOwnershipMap);
|
|
243
|
+
return partitionsToClaim.concat(partitionsToSteal);
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=loadBalancingStrategy.js.map
|