@azure/eventhubs-checkpointstore-table 1.0.0-alpha.20240112.1 → 1.0.0-alpha.20240126.2
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/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var tslib = require('tslib');
|
|
5
6
|
var dataTables = require('@azure/data-tables');
|
|
6
7
|
var logger$1 = require('@azure/logger');
|
|
7
8
|
|
|
@@ -54,33 +55,46 @@ class TableCheckpointStore {
|
|
|
54
55
|
* @returns Partition ownership details of all the partitions that have had an owner.
|
|
55
56
|
*/
|
|
56
57
|
async listOwnership(fullyQualifiedNamespace, eventHubName, consumerGroup) {
|
|
58
|
+
var _a, e_1, _b, _c;
|
|
57
59
|
const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`;
|
|
58
60
|
const partitionOwnershipArray = [];
|
|
59
61
|
const entitiesIter = this._tableClient.listEntities({
|
|
60
62
|
queryOptions: { filter: dataTables.odata `PartitionKey eq ${partitionKey}` },
|
|
61
63
|
});
|
|
62
64
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
try {
|
|
66
|
+
for (var _d = true, entitiesIter_1 = tslib.__asyncValues(entitiesIter), entitiesIter_1_1; entitiesIter_1_1 = await entitiesIter_1.next(), _a = entitiesIter_1_1.done, !_a; _d = true) {
|
|
67
|
+
_c = entitiesIter_1_1.value;
|
|
68
|
+
_d = false;
|
|
69
|
+
const entity = _c;
|
|
70
|
+
if (!entity.timestamp) {
|
|
71
|
+
throw new Error(`Unable to retrieve timestamp from partitionKey "${partitionKey}", rowKey "${entity.rowKey}"`);
|
|
72
|
+
}
|
|
73
|
+
const partitionOwnership = {
|
|
74
|
+
fullyQualifiedNamespace,
|
|
75
|
+
eventHubName,
|
|
76
|
+
consumerGroup,
|
|
77
|
+
ownerId: entity.ownerid,
|
|
78
|
+
partitionId: entity.rowKey,
|
|
79
|
+
lastModifiedTimeInMs: new Date(entity.timestamp).getTime(),
|
|
80
|
+
etag: entity.etag,
|
|
81
|
+
};
|
|
82
|
+
partitionOwnershipArray.push(partitionOwnership);
|
|
66
83
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
etag: entity.etag,
|
|
75
|
-
};
|
|
76
|
-
partitionOwnershipArray.push(partitionOwnership);
|
|
84
|
+
}
|
|
85
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
86
|
+
finally {
|
|
87
|
+
try {
|
|
88
|
+
if (!_d && !_a && (_b = entitiesIter_1.return)) await _b.call(entitiesIter_1);
|
|
89
|
+
}
|
|
90
|
+
finally { if (e_1) throw e_1.error; }
|
|
77
91
|
}
|
|
78
92
|
return partitionOwnershipArray;
|
|
79
93
|
}
|
|
80
94
|
catch (err) {
|
|
81
95
|
logger.warning(`Error occurred while fetching the list of entities`, err.message);
|
|
82
96
|
logErrorStackTrace(err);
|
|
83
|
-
if (err
|
|
97
|
+
if ((err === null || err === void 0 ? void 0 : err.name) === "AbortError")
|
|
84
98
|
throw err;
|
|
85
99
|
throw new Error(`Error occurred while fetching the list of entities. \n${err}`);
|
|
86
100
|
}
|
|
@@ -98,7 +112,7 @@ class TableCheckpointStore {
|
|
|
98
112
|
async claimOwnership(partitionOwnership) {
|
|
99
113
|
const partitionOwnershipArray = [];
|
|
100
114
|
for (const ownership of partitionOwnership) {
|
|
101
|
-
const updatedOwnership = {
|
|
115
|
+
const updatedOwnership = Object.assign({}, ownership);
|
|
102
116
|
const partitionKey = `${ownership.fullyQualifiedNamespace} ${ownership.eventHubName} ${ownership.consumerGroup} Ownership`;
|
|
103
117
|
const ownershipEntity = {
|
|
104
118
|
partitionKey: partitionKey,
|
|
@@ -163,20 +177,33 @@ class TableCheckpointStore {
|
|
|
163
177
|
* - `tracingOptions`: Options for configuring tracing.
|
|
164
178
|
*/
|
|
165
179
|
async listCheckpoints(fullyQualifiedNamespace, eventHubName, consumerGroup) {
|
|
180
|
+
var _a, e_2, _b, _c;
|
|
166
181
|
const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`;
|
|
167
182
|
const checkpoints = [];
|
|
168
183
|
const entitiesIter = this._tableClient.listEntities({
|
|
169
184
|
queryOptions: { filter: dataTables.odata `PartitionKey eq ${partitionKey}` },
|
|
170
185
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
186
|
+
try {
|
|
187
|
+
for (var _d = true, entitiesIter_2 = tslib.__asyncValues(entitiesIter), entitiesIter_2_1; entitiesIter_2_1 = await entitiesIter_2.next(), _a = entitiesIter_2_1.done, !_a; _d = true) {
|
|
188
|
+
_c = entitiesIter_2_1.value;
|
|
189
|
+
_d = false;
|
|
190
|
+
const entity = _c;
|
|
191
|
+
checkpoints.push({
|
|
192
|
+
consumerGroup,
|
|
193
|
+
eventHubName,
|
|
194
|
+
fullyQualifiedNamespace,
|
|
195
|
+
partitionId: entity.rowKey,
|
|
196
|
+
offset: parseInt(entity.offset, 10),
|
|
197
|
+
sequenceNumber: parseInt(entity.sequencenumber, 10),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
202
|
+
finally {
|
|
203
|
+
try {
|
|
204
|
+
if (!_d && !_a && (_b = entitiesIter_2.return)) await _b.call(entitiesIter_2);
|
|
205
|
+
}
|
|
206
|
+
finally { if (e_2) throw e_2.error; }
|
|
180
207
|
}
|
|
181
208
|
return checkpoints;
|
|
182
209
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/log.ts","../src/tableCheckpointStore.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The `@azure/logger` configuration for this package.\n * This will output logs using the `azure:eventhubs-checkpointstore-table` namespace prefix.\n */\nexport const logger = createClientLogger(\"eventhubs-checkpointstore-table\");\n\n/**\n * Logs the error's stack trace to \"verbose\" if a stack trace is available.\n * @param error - Error containing a stack trace.\n * @internal\n */\nexport function logErrorStackTrace(error: unknown): void {\n if (error && typeof error === \"object\" && \"stack\" in error) {\n logger.verbose((error as any).stack);\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Checkpoint, CheckpointStore, PartitionOwnership } from \"@azure/event-hubs\";\nimport { TableClient, TableInsertEntityHeaders, odata } from \"@azure/data-tables\";\nimport { logErrorStackTrace, logger } from \"./log\";\n\n/**\n *\n * Checks if the value contains a `Timestamp` field of type `string`.\n */\nfunction _hasTimestamp<T extends TableInsertEntityHeaders>(\n value: T,\n): value is T & { Timestamp: string } {\n return typeof (value as any).Timestamp === \"string\";\n}\n\n/**\n * A checkpoint entity of type CheckpointEntity to be stored in the table\n * @internal\n *\n */\nexport interface CheckpointEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n sequencenumber: string;\n offset: string;\n}\n\n/**\n * An ownership entity of type PartitionOwnership to be stored in the table\n * @internal\n */\nexport interface PartitionOwnershipEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n ownerid: string;\n}\n\n/**\n * An implementation of CheckpointStore that uses Azure Table Storage to persist checkpoint data.\n */\nexport class TableCheckpointStore implements CheckpointStore {\n private _tableClient: TableClient;\n\n constructor(tableClient: TableClient) {\n this._tableClient = tableClient;\n }\n\n /**\n * Get the list of all existing partition ownership from the underlying data store. May return empty\n * results if there are is no existing ownership information.\n * Partition Ownership contains the information on which `EventHubConsumerClient` subscribe call is currently processing the partition.\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 * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\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 partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`;\n const partitionOwnershipArray: PartitionOwnership[] = [];\n const entitiesIter = this._tableClient.listEntities<PartitionOwnershipEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n try {\n for await (const entity of entitiesIter) {\n if (!entity.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entity.rowKey}\"`,\n );\n }\n\n const partitionOwnership: PartitionOwnership = {\n fullyQualifiedNamespace,\n eventHubName,\n consumerGroup,\n ownerId: entity.ownerid,\n partitionId: entity.rowKey,\n lastModifiedTimeInMs: new Date(entity.timestamp).getTime(),\n etag: entity.etag,\n };\n partitionOwnershipArray.push(partitionOwnership);\n }\n return partitionOwnershipArray;\n } catch (err: any) {\n logger.warning(`Error occurred while fetching the list of entities`, err.message);\n logErrorStackTrace(err);\n if (err?.name === \"AbortError\") throw err;\n\n throw new Error(`Error occurred while fetching the list of entities. \\n${err}`);\n }\n }\n\n /**\n * Claim ownership of a list of partitions. This will return the list of partitions that were\n * successfully claimed.\n *\n * @param partitionOwnership - The list of partition ownership this instance is claiming to own.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A list partitions this instance successfully claimed ownership.\n */\n async claimOwnership(partitionOwnership: PartitionOwnership[]): Promise<PartitionOwnership[]> {\n const partitionOwnershipArray: PartitionOwnership[] = [];\n\n for (const ownership of partitionOwnership) {\n const updatedOwnership = { ...ownership };\n const partitionKey = `${ownership.fullyQualifiedNamespace} ${ownership.eventHubName} ${ownership.consumerGroup} Ownership`;\n const ownershipEntity: PartitionOwnershipEntity = {\n partitionKey: partitionKey,\n rowKey: ownership.partitionId,\n ownerid: ownership.ownerId,\n };\n\n // When we have an etag, we know the entity existed.\n // If we encounter an error we should fail.\n try {\n if (ownership.etag) {\n const updatedMetadata = await this._tableClient.updateEntity(ownershipEntity, \"Replace\", {\n etag: ownership.etag,\n });\n const entityRetrieved = await this._tableClient.getEntity(\n ownershipEntity.partitionKey,\n ownershipEntity.rowKey,\n );\n if (!entityRetrieved.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entityRetrieved.rowKey}\"`,\n );\n }\n updatedOwnership.lastModifiedTimeInMs = new Date(entityRetrieved.timestamp).getTime();\n updatedOwnership.etag = updatedMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n logger.info(\n `[${ownership.ownerId}] Claimed ownership successfully for partition: ${ownership.partitionId}`,\n `LastModifiedTime: ${ownership.lastModifiedTimeInMs}, ETag: ${ownership.etag}`,\n );\n } else {\n const newOwnershipMetadata = await this._tableClient.createEntity(ownershipEntity, {\n requestOptions: {\n customHeaders: {\n Prefer: \"return-content\",\n },\n },\n });\n\n if (!_hasTimestamp(newOwnershipMetadata)) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${ownershipEntity.rowKey}\"`,\n );\n }\n\n updatedOwnership.lastModifiedTimeInMs = new Date(\n newOwnershipMetadata.Timestamp,\n ).getTime();\n updatedOwnership.etag = newOwnershipMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n }\n } catch (err: any) {\n if (err.statusCode === 412) {\n // etag failures (precondition not met) aren't fatal errors. They happen\n // as multiple consumers attempt to claim the same partition (first one wins)\n // and losers get this error.\n logger.verbose(\n `[${ownership.ownerId}] Did not claim partition ${ownership.partitionId}. Another processor has already claimed it.`,\n );\n continue;\n }\n logger.warning(\n `Error occurred while claiming ownership for partition: ${ownership.partitionId}`,\n err.message,\n );\n logErrorStackTrace(err);\n }\n }\n return partitionOwnershipArray;\n }\n\n /**\n * Lists all the checkpoints in a data store for a given namespace, eventhub and consumer group.\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 * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n */\n async listCheckpoints(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n consumerGroup: string,\n ): Promise<Checkpoint[]> {\n const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`;\n const checkpoints: Checkpoint[] = [];\n const entitiesIter = this._tableClient.listEntities<CheckpointEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n for await (const entity of entitiesIter) {\n checkpoints.push({\n consumerGroup,\n eventHubName,\n fullyQualifiedNamespace,\n partitionId: entity.rowKey,\n offset: parseInt(entity.offset, 10),\n sequenceNumber: parseInt(entity.sequencenumber, 10),\n });\n }\n return checkpoints;\n }\n\n /**\n * Updates the checkpoint in the data store for a partition.\n *\n * @param checkpoint - The checkpoint.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A promise that resolves when the checkpoint has been updated.\n */\n async updateCheckpoint(checkpoint: Checkpoint): Promise<void> {\n const partitionKey = `${checkpoint.fullyQualifiedNamespace} ${checkpoint.eventHubName} ${checkpoint.consumerGroup} Checkpoint`;\n const checkpointEntity: CheckpointEntity = {\n partitionKey: partitionKey,\n rowKey: checkpoint.partitionId,\n sequencenumber: checkpoint.sequenceNumber.toString(),\n offset: checkpoint.offset.toString(),\n };\n try {\n await this._tableClient.upsertEntity(checkpointEntity);\n logger.verbose(`Updated checkpoint successfully for partition: ${checkpoint.partitionId}`);\n return;\n } catch (err: any) {\n logger.verbose(\n `Error occurred while upating the checkpoint for partition: ${checkpoint.partitionId}.`,\n err.message,\n );\n throw err;\n }\n }\n}\n"],"names":["createClientLogger","odata"],"mappings":";;;;;;;AAAA;AACA;AAIA;;;AAGG;MACU,MAAM,GAAGA,2BAAkB,CAAC,iCAAiC,EAAE;AAE5E;;;;AAIG;AACG,SAAU,kBAAkB,CAAC,KAAc,EAAA;IAC/C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,EAAE;AAC1D,QAAA,MAAM,CAAC,OAAO,CAAE,KAAa,CAAC,KAAK,CAAC,CAAC;AACtC,KAAA;AACH;;ACpBA;AACA;AAMA;;;AAGG;AACH,SAAS,aAAa,CACpB,KAAQ,EAAA;AAER,IAAA,OAAO,OAAQ,KAAa,CAAC,SAAS,KAAK,QAAQ,CAAC;AACtD,CAAC;AAwCD;;AAEG;MACU,oBAAoB,CAAA;AAG/B,IAAA,WAAA,CAAY,WAAwB,EAAA;AAClC,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;KACjC;AAED;;;;;;;;;;;;;AAaG;AACH,IAAA,MAAM,aAAa,CACjB,uBAA+B,EAC/B,YAAoB,EACpB,aAAqB,EAAA;QAErB,MAAM,YAAY,GAAG,CAAG,EAAA,uBAAuB,IAAI,YAAY,CAAA,CAAA,EAAI,aAAa,CAAA,UAAA,CAAY,CAAC;QAC7F,MA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,UAAU,CAAC,WAAW;AAC9B,YAAA,cAAc,EAAE,UAAU,CAAC,cAAc,CAAC,QAAQ,EAAE;AACpD,YAAA,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;SACrC,CAAC;QACF,IAAI;YACF,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO,CAAC,CAAA,+CAAA,EAAkD,UAAU,CAAC,WAAW,CAAE,CAAA,CAAC,CAAC;YAC3F,OAAO;AACR,SAAA;AAAC,QAAA,OAAO,GAAQ,EAAE;AACjB,YAAA,MAAM,CAAC,OAAO,CACZ,CAAA,2DAAA,EAA8D,UAAU,CAAC,WAAW,CAAA,CAAA,CAAG,EACvF,GAAG,CAAC,OAAO,CACZ,CAAC;AACF,YAAA,MAAM,GAAG,CAAC;AACX,SAAA;KACF;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/log.ts","../src/tableCheckpointStore.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The `@azure/logger` configuration for this package.\n * This will output logs using the `azure:eventhubs-checkpointstore-table` namespace prefix.\n */\nexport const logger = createClientLogger(\"eventhubs-checkpointstore-table\");\n\n/**\n * Logs the error's stack trace to \"verbose\" if a stack trace is available.\n * @param error - Error containing a stack trace.\n * @internal\n */\nexport function logErrorStackTrace(error: unknown): void {\n if (error && typeof error === \"object\" && \"stack\" in error) {\n logger.verbose((error as any).stack);\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Checkpoint, CheckpointStore, PartitionOwnership } from \"@azure/event-hubs\";\nimport { TableClient, TableInsertEntityHeaders, odata } from \"@azure/data-tables\";\nimport { logErrorStackTrace, logger } from \"./log\";\n\n/**\n *\n * Checks if the value contains a `Timestamp` field of type `string`.\n */\nfunction _hasTimestamp<T extends TableInsertEntityHeaders>(\n value: T,\n): value is T & { Timestamp: string } {\n return typeof (value as any).Timestamp === \"string\";\n}\n\n/**\n * A checkpoint entity of type CheckpointEntity to be stored in the table\n * @internal\n *\n */\nexport interface CheckpointEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n sequencenumber: string;\n offset: string;\n}\n\n/**\n * An ownership entity of type PartitionOwnership to be stored in the table\n * @internal\n */\nexport interface PartitionOwnershipEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n ownerid: string;\n}\n\n/**\n * An implementation of CheckpointStore that uses Azure Table Storage to persist checkpoint data.\n */\nexport class TableCheckpointStore implements CheckpointStore {\n private _tableClient: TableClient;\n\n constructor(tableClient: TableClient) {\n this._tableClient = tableClient;\n }\n\n /**\n * Get the list of all existing partition ownership from the underlying data store. May return empty\n * results if there are is no existing ownership information.\n * Partition Ownership contains the information on which `EventHubConsumerClient` subscribe call is currently processing the partition.\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 * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\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 partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`;\n const partitionOwnershipArray: PartitionOwnership[] = [];\n const entitiesIter = this._tableClient.listEntities<PartitionOwnershipEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n try {\n for await (const entity of entitiesIter) {\n if (!entity.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entity.rowKey}\"`,\n );\n }\n\n const partitionOwnership: PartitionOwnership = {\n fullyQualifiedNamespace,\n eventHubName,\n consumerGroup,\n ownerId: entity.ownerid,\n partitionId: entity.rowKey,\n lastModifiedTimeInMs: new Date(entity.timestamp).getTime(),\n etag: entity.etag,\n };\n partitionOwnershipArray.push(partitionOwnership);\n }\n return partitionOwnershipArray;\n } catch (err: any) {\n logger.warning(`Error occurred while fetching the list of entities`, err.message);\n logErrorStackTrace(err);\n if (err?.name === \"AbortError\") throw err;\n\n throw new Error(`Error occurred while fetching the list of entities. \\n${err}`);\n }\n }\n\n /**\n * Claim ownership of a list of partitions. This will return the list of partitions that were\n * successfully claimed.\n *\n * @param partitionOwnership - The list of partition ownership this instance is claiming to own.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A list partitions this instance successfully claimed ownership.\n */\n async claimOwnership(partitionOwnership: PartitionOwnership[]): Promise<PartitionOwnership[]> {\n const partitionOwnershipArray: PartitionOwnership[] = [];\n\n for (const ownership of partitionOwnership) {\n const updatedOwnership = { ...ownership };\n const partitionKey = `${ownership.fullyQualifiedNamespace} ${ownership.eventHubName} ${ownership.consumerGroup} Ownership`;\n const ownershipEntity: PartitionOwnershipEntity = {\n partitionKey: partitionKey,\n rowKey: ownership.partitionId,\n ownerid: ownership.ownerId,\n };\n\n // When we have an etag, we know the entity existed.\n // If we encounter an error we should fail.\n try {\n if (ownership.etag) {\n const updatedMetadata = await this._tableClient.updateEntity(ownershipEntity, \"Replace\", {\n etag: ownership.etag,\n });\n const entityRetrieved = await this._tableClient.getEntity(\n ownershipEntity.partitionKey,\n ownershipEntity.rowKey,\n );\n if (!entityRetrieved.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entityRetrieved.rowKey}\"`,\n );\n }\n updatedOwnership.lastModifiedTimeInMs = new Date(entityRetrieved.timestamp).getTime();\n updatedOwnership.etag = updatedMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n logger.info(\n `[${ownership.ownerId}] Claimed ownership successfully for partition: ${ownership.partitionId}`,\n `LastModifiedTime: ${ownership.lastModifiedTimeInMs}, ETag: ${ownership.etag}`,\n );\n } else {\n const newOwnershipMetadata = await this._tableClient.createEntity(ownershipEntity, {\n requestOptions: {\n customHeaders: {\n Prefer: \"return-content\",\n },\n },\n });\n\n if (!_hasTimestamp(newOwnershipMetadata)) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${ownershipEntity.rowKey}\"`,\n );\n }\n\n updatedOwnership.lastModifiedTimeInMs = new Date(\n newOwnershipMetadata.Timestamp,\n ).getTime();\n updatedOwnership.etag = newOwnershipMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n }\n } catch (err: any) {\n if (err.statusCode === 412) {\n // etag failures (precondition not met) aren't fatal errors. They happen\n // as multiple consumers attempt to claim the same partition (first one wins)\n // and losers get this error.\n logger.verbose(\n `[${ownership.ownerId}] Did not claim partition ${ownership.partitionId}. Another processor has already claimed it.`,\n );\n continue;\n }\n logger.warning(\n `Error occurred while claiming ownership for partition: ${ownership.partitionId}`,\n err.message,\n );\n logErrorStackTrace(err);\n }\n }\n return partitionOwnershipArray;\n }\n\n /**\n * Lists all the checkpoints in a data store for a given namespace, eventhub and consumer group.\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 * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n */\n async listCheckpoints(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n consumerGroup: string,\n ): Promise<Checkpoint[]> {\n const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`;\n const checkpoints: Checkpoint[] = [];\n const entitiesIter = this._tableClient.listEntities<CheckpointEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n for await (const entity of entitiesIter) {\n checkpoints.push({\n consumerGroup,\n eventHubName,\n fullyQualifiedNamespace,\n partitionId: entity.rowKey,\n offset: parseInt(entity.offset, 10),\n sequenceNumber: parseInt(entity.sequencenumber, 10),\n });\n }\n return checkpoints;\n }\n\n /**\n * Updates the checkpoint in the data store for a partition.\n *\n * @param checkpoint - The checkpoint.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A promise that resolves when the checkpoint has been updated.\n */\n async updateCheckpoint(checkpoint: Checkpoint): Promise<void> {\n const partitionKey = `${checkpoint.fullyQualifiedNamespace} ${checkpoint.eventHubName} ${checkpoint.consumerGroup} Checkpoint`;\n const checkpointEntity: CheckpointEntity = {\n partitionKey: partitionKey,\n rowKey: checkpoint.partitionId,\n sequencenumber: checkpoint.sequenceNumber.toString(),\n offset: checkpoint.offset.toString(),\n };\n try {\n await this._tableClient.upsertEntity(checkpointEntity);\n logger.verbose(`Updated checkpoint successfully for partition: ${checkpoint.partitionId}`);\n return;\n } catch (err: any) {\n logger.verbose(\n `Error occurred while upating the checkpoint for partition: ${checkpoint.partitionId}.`,\n err.message,\n );\n throw err;\n }\n }\n}\n"],"names":["createClientLogger","odata","__asyncValues"],"mappings":";;;;;;;;AAAA;AACA;AAIA;;;AAGG;MACU,MAAM,GAAGA,2BAAkB,CAAC,iCAAiC,EAAE;AAE5E;;;;AAIG;AACG,SAAU,kBAAkB,CAAC,KAAc,EAAA;IAC/C,IAAI,KAAK,IAAI,OAAO,KAA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;YAC3F,OAAO;SACR;QAAC,OAAO,GAAQ,EAAE;AACjB,YAAA,MAAM,CAAC,OAAO,CACZ,CAAA,2DAAA,EAA8D,UAAU,CAAC,WAAW,CAAA,CAAA,CAAG,EACvF,GAAG,CAAC,OAAO,CACZ,CAAC;AACF,YAAA,MAAM,GAAG,CAAC;SACX;KACF;AACF;;;;;"}
|
package/dist-esm/src/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,iCAAiC,CAAC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,EAAE;
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,iCAAiC,CAAC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;QAC3D,MAAM,CAAC,OAAO,CAAE,KAAa,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The `@azure/logger` configuration for this package.\n * This will output logs using the `azure:eventhubs-checkpointstore-table` namespace prefix.\n */\nexport const logger = createClientLogger(\"eventhubs-checkpointstore-table\");\n\n/**\n * Logs the error's stack trace to \"verbose\" if a stack trace is available.\n * @param error - Error containing a stack trace.\n * @internal\n */\nexport function logErrorStackTrace(error: unknown): void {\n if (error && typeof error === \"object\" && \"stack\" in error) {\n logger.verbose((error as any).stack);\n }\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
+
import { __asyncValues } from "tslib";
|
|
3
4
|
import { odata } from "@azure/data-tables";
|
|
4
5
|
import { logErrorStackTrace, logger } from "./log";
|
|
5
6
|
/**
|
|
@@ -31,33 +32,46 @@ export class TableCheckpointStore {
|
|
|
31
32
|
* @returns Partition ownership details of all the partitions that have had an owner.
|
|
32
33
|
*/
|
|
33
34
|
async listOwnership(fullyQualifiedNamespace, eventHubName, consumerGroup) {
|
|
35
|
+
var _a, e_1, _b, _c;
|
|
34
36
|
const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`;
|
|
35
37
|
const partitionOwnershipArray = [];
|
|
36
38
|
const entitiesIter = this._tableClient.listEntities({
|
|
37
39
|
queryOptions: { filter: odata `PartitionKey eq ${partitionKey}` },
|
|
38
40
|
});
|
|
39
41
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
try {
|
|
43
|
+
for (var _d = true, entitiesIter_1 = __asyncValues(entitiesIter), entitiesIter_1_1; entitiesIter_1_1 = await entitiesIter_1.next(), _a = entitiesIter_1_1.done, !_a; _d = true) {
|
|
44
|
+
_c = entitiesIter_1_1.value;
|
|
45
|
+
_d = false;
|
|
46
|
+
const entity = _c;
|
|
47
|
+
if (!entity.timestamp) {
|
|
48
|
+
throw new Error(`Unable to retrieve timestamp from partitionKey "${partitionKey}", rowKey "${entity.rowKey}"`);
|
|
49
|
+
}
|
|
50
|
+
const partitionOwnership = {
|
|
51
|
+
fullyQualifiedNamespace,
|
|
52
|
+
eventHubName,
|
|
53
|
+
consumerGroup,
|
|
54
|
+
ownerId: entity.ownerid,
|
|
55
|
+
partitionId: entity.rowKey,
|
|
56
|
+
lastModifiedTimeInMs: new Date(entity.timestamp).getTime(),
|
|
57
|
+
etag: entity.etag,
|
|
58
|
+
};
|
|
59
|
+
partitionOwnershipArray.push(partitionOwnership);
|
|
43
60
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
etag: entity.etag,
|
|
52
|
-
};
|
|
53
|
-
partitionOwnershipArray.push(partitionOwnership);
|
|
61
|
+
}
|
|
62
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
63
|
+
finally {
|
|
64
|
+
try {
|
|
65
|
+
if (!_d && !_a && (_b = entitiesIter_1.return)) await _b.call(entitiesIter_1);
|
|
66
|
+
}
|
|
67
|
+
finally { if (e_1) throw e_1.error; }
|
|
54
68
|
}
|
|
55
69
|
return partitionOwnershipArray;
|
|
56
70
|
}
|
|
57
71
|
catch (err) {
|
|
58
72
|
logger.warning(`Error occurred while fetching the list of entities`, err.message);
|
|
59
73
|
logErrorStackTrace(err);
|
|
60
|
-
if (err
|
|
74
|
+
if ((err === null || err === void 0 ? void 0 : err.name) === "AbortError")
|
|
61
75
|
throw err;
|
|
62
76
|
throw new Error(`Error occurred while fetching the list of entities. \n${err}`);
|
|
63
77
|
}
|
|
@@ -75,7 +89,7 @@ export class TableCheckpointStore {
|
|
|
75
89
|
async claimOwnership(partitionOwnership) {
|
|
76
90
|
const partitionOwnershipArray = [];
|
|
77
91
|
for (const ownership of partitionOwnership) {
|
|
78
|
-
const updatedOwnership = {
|
|
92
|
+
const updatedOwnership = Object.assign({}, ownership);
|
|
79
93
|
const partitionKey = `${ownership.fullyQualifiedNamespace} ${ownership.eventHubName} ${ownership.consumerGroup} Ownership`;
|
|
80
94
|
const ownershipEntity = {
|
|
81
95
|
partitionKey: partitionKey,
|
|
@@ -140,20 +154,33 @@ export class TableCheckpointStore {
|
|
|
140
154
|
* - `tracingOptions`: Options for configuring tracing.
|
|
141
155
|
*/
|
|
142
156
|
async listCheckpoints(fullyQualifiedNamespace, eventHubName, consumerGroup) {
|
|
157
|
+
var _a, e_2, _b, _c;
|
|
143
158
|
const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`;
|
|
144
159
|
const checkpoints = [];
|
|
145
160
|
const entitiesIter = this._tableClient.listEntities({
|
|
146
161
|
queryOptions: { filter: odata `PartitionKey eq ${partitionKey}` },
|
|
147
162
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
163
|
+
try {
|
|
164
|
+
for (var _d = true, entitiesIter_2 = __asyncValues(entitiesIter), entitiesIter_2_1; entitiesIter_2_1 = await entitiesIter_2.next(), _a = entitiesIter_2_1.done, !_a; _d = true) {
|
|
165
|
+
_c = entitiesIter_2_1.value;
|
|
166
|
+
_d = false;
|
|
167
|
+
const entity = _c;
|
|
168
|
+
checkpoints.push({
|
|
169
|
+
consumerGroup,
|
|
170
|
+
eventHubName,
|
|
171
|
+
fullyQualifiedNamespace,
|
|
172
|
+
partitionId: entity.rowKey,
|
|
173
|
+
offset: parseInt(entity.offset, 10),
|
|
174
|
+
sequenceNumber: parseInt(entity.sequencenumber, 10),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
179
|
+
finally {
|
|
180
|
+
try {
|
|
181
|
+
if (!_d && !_a && (_b = entitiesIter_2.return)) await _b.call(entitiesIter_2);
|
|
182
|
+
}
|
|
183
|
+
finally { if (e_2) throw e_2.error; }
|
|
157
184
|
}
|
|
158
185
|
return checkpoints;
|
|
159
186
|
}
|
|
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AAY,EAAE,YAAY;YAC1B,MAAM,EAAE,UAAU,CAAC,WAAW;YAC9B,cAAc,EAAE,UAAU,CAAC,cAAc,CAAC,QAAQ,EAAE;YACpD,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;SACrC,CAAC;QACF,IAAI;YACF,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO,CAAC,kDAAkD,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;YAC3F,OAAO;SACR;QAAC,OAAO,GAAQ,EAAE;YACjB,MAAM,CAAC,OAAO,CACZ,8DAA8D,UAAU,CAAC,WAAW,GAAG,EACvF,GAAG,CAAC,OAAO,CACZ,CAAC;YACF,MAAM,GAAG,CAAC;SACX;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Checkpoint, CheckpointStore, PartitionOwnership } from \"@azure/event-hubs\";\nimport { TableClient, TableInsertEntityHeaders, odata } from \"@azure/data-tables\";\nimport { logErrorStackTrace, logger } from \"./log\";\n\n/**\n *\n * Checks if the value contains a `Timestamp` field of type `string`.\n */\nfunction _hasTimestamp<T extends TableInsertEntityHeaders>(\n value: T,\n): value is T & { Timestamp: string } {\n return typeof (value as any).Timestamp === \"string\";\n}\n\n/**\n * A checkpoint entity of type CheckpointEntity to be stored in the table\n * @internal\n *\n */\nexport interface CheckpointEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n sequencenumber: string;\n offset: string;\n}\n\n/**\n * An ownership entity of type PartitionOwnership to be stored in the table\n * @internal\n */\nexport interface PartitionOwnershipEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n ownerid: string;\n}\n\n/**\n * An implementation of CheckpointStore that uses Azure Table Storage to persist checkpoint data.\n */\nexport class TableCheckpointStore implements CheckpointStore {\n private _tableClient: TableClient;\n\n constructor(tableClient: TableClient) {\n this._tableClient = tableClient;\n }\n\n /**\n * Get the list of all existing partition ownership from the underlying data store. May return empty\n * results if there are is no existing ownership information.\n * Partition Ownership contains the information on which `EventHubConsumerClient` subscribe call is currently processing the partition.\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 * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\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 partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`;\n const partitionOwnershipArray: PartitionOwnership[] = [];\n const entitiesIter = this._tableClient.listEntities<PartitionOwnershipEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n try {\n for await (const entity of entitiesIter) {\n if (!entity.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entity.rowKey}\"`,\n );\n }\n\n const partitionOwnership: PartitionOwnership = {\n fullyQualifiedNamespace,\n eventHubName,\n consumerGroup,\n ownerId: entity.ownerid,\n partitionId: entity.rowKey,\n lastModifiedTimeInMs: new Date(entity.timestamp).getTime(),\n etag: entity.etag,\n };\n partitionOwnershipArray.push(partitionOwnership);\n }\n return partitionOwnershipArray;\n } catch (err: any) {\n logger.warning(`Error occurred while fetching the list of entities`, err.message);\n logErrorStackTrace(err);\n if (err?.name === \"AbortError\") throw err;\n\n throw new Error(`Error occurred while fetching the list of entities. \\n${err}`);\n }\n }\n\n /**\n * Claim ownership of a list of partitions. This will return the list of partitions that were\n * successfully claimed.\n *\n * @param partitionOwnership - The list of partition ownership this instance is claiming to own.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A list partitions this instance successfully claimed ownership.\n */\n async claimOwnership(partitionOwnership: PartitionOwnership[]): Promise<PartitionOwnership[]> {\n const partitionOwnershipArray: PartitionOwnership[] = [];\n\n for (const ownership of partitionOwnership) {\n const updatedOwnership = { ...ownership };\n const partitionKey = `${ownership.fullyQualifiedNamespace} ${ownership.eventHubName} ${ownership.consumerGroup} Ownership`;\n const ownershipEntity: PartitionOwnershipEntity = {\n partitionKey: partitionKey,\n rowKey: ownership.partitionId,\n ownerid: ownership.ownerId,\n };\n\n // When we have an etag, we know the entity existed.\n // If we encounter an error we should fail.\n try {\n if (ownership.etag) {\n const updatedMetadata = await this._tableClient.updateEntity(ownershipEntity, \"Replace\", {\n etag: ownership.etag,\n });\n const entityRetrieved = await this._tableClient.getEntity(\n ownershipEntity.partitionKey,\n ownershipEntity.rowKey,\n );\n if (!entityRetrieved.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entityRetrieved.rowKey}\"`,\n );\n }\n updatedOwnership.lastModifiedTimeInMs = new Date(entityRetrieved.timestamp).getTime();\n updatedOwnership.etag = updatedMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n logger.info(\n `[${ownership.ownerId}] Claimed ownership successfully for partition: ${ownership.partitionId}`,\n `LastModifiedTime: ${ownership.lastModifiedTimeInMs}, ETag: ${ownership.etag}`,\n );\n } else {\n const newOwnershipMetadata = await this._tableClient.createEntity(ownershipEntity, {\n requestOptions: {\n customHeaders: {\n Prefer: \"return-content\",\n },\n },\n });\n\n if (!_hasTimestamp(newOwnershipMetadata)) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${ownershipEntity.rowKey}\"`,\n );\n }\n\n updatedOwnership.lastModifiedTimeInMs = new Date(\n newOwnershipMetadata.Timestamp,\n ).getTime();\n updatedOwnership.etag = newOwnershipMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n }\n } catch (err: any) {\n if (err.statusCode === 412) {\n // etag failures (precondition not met) aren't fatal errors. They happen\n // as multiple consumers attempt to claim the same partition (first one wins)\n // and losers get this error.\n logger.verbose(\n `[${ownership.ownerId}] Did not claim partition ${ownership.partitionId}. Another processor has already claimed it.`,\n );\n continue;\n }\n logger.warning(\n `Error occurred while claiming ownership for partition: ${ownership.partitionId}`,\n err.message,\n );\n logErrorStackTrace(err);\n }\n }\n return partitionOwnershipArray;\n }\n\n /**\n * Lists all the checkpoints in a data store for a given namespace, eventhub and consumer group.\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 * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n */\n async listCheckpoints(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n consumerGroup: string,\n ): Promise<Checkpoint[]> {\n const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`;\n const checkpoints: Checkpoint[] = [];\n const entitiesIter = this._tableClient.listEntities<CheckpointEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n for await (const entity of entitiesIter) {\n checkpoints.push({\n consumerGroup,\n eventHubName,\n fullyQualifiedNamespace,\n partitionId: entity.rowKey,\n offset: parseInt(entity.offset, 10),\n sequenceNumber: parseInt(entity.sequencenumber, 10),\n });\n }\n return checkpoints;\n }\n\n /**\n * Updates the checkpoint in the data store for a partition.\n *\n * @param checkpoint - The checkpoint.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A promise that resolves when the checkpoint has been updated.\n */\n async updateCheckpoint(checkpoint: Checkpoint): Promise<void> {\n const partitionKey = `${checkpoint.fullyQualifiedNamespace} ${checkpoint.eventHubName} ${checkpoint.consumerGroup} Checkpoint`;\n const checkpointEntity: CheckpointEntity = {\n partitionKey: partitionKey,\n rowKey: checkpoint.partitionId,\n sequencenumber: checkpoint.sequenceNumber.toString(),\n offset: checkpoint.offset.toString(),\n };\n try {\n await this._tableClient.upsertEntity(checkpointEntity);\n logger.verbose(`Updated checkpoint successfully for partition: ${checkpoint.partitionId}`);\n return;\n } catch (err: any) {\n logger.verbose(\n `Error occurred while upating the checkpoint for partition: ${checkpoint.partitionId}.`,\n err.message,\n );\n throw err;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tableCheckpointStore.js","sourceRoot":"","sources":["../../src/tableCheckpointStore.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAyC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEnD;;;GAGG;AACH,SAAS,aAAa,CACpB,KAAQ;IAER,OAAO,OAAQ,KAAa,CAAC,SAAS,KAAK,QAAQ,CAAC;AACtD,CAAC;AAwCD;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAG/B,YAAY,WAAwB;QAClC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,aAAa,CACjB,uBAA+B,EAC/B,YAAoB,EACpB,aAAqB;;QAErB,MAAM,YAAY,GAAG,GAAG,uBAAuB,IAAI,YAAY,IAAI,aAAa,YAAY,CAAC;QAC7F,MAAM,uBAAuB,GAAyB,EAAE,CAAC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C3F,OAAO;QACT,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,CAAC,OAAO,CACZ,8DAA8D,UAAU,CAAC,WAAW,GAAG,EACvF,GAAG,CAAC,OAAO,CACZ,CAAC;YACF,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Checkpoint, CheckpointStore, PartitionOwnership } from \"@azure/event-hubs\";\nimport { TableClient, TableInsertEntityHeaders, odata } from \"@azure/data-tables\";\nimport { logErrorStackTrace, logger } from \"./log\";\n\n/**\n *\n * Checks if the value contains a `Timestamp` field of type `string`.\n */\nfunction _hasTimestamp<T extends TableInsertEntityHeaders>(\n value: T,\n): value is T & { Timestamp: string } {\n return typeof (value as any).Timestamp === \"string\";\n}\n\n/**\n * A checkpoint entity of type CheckpointEntity to be stored in the table\n * @internal\n *\n */\nexport interface CheckpointEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n sequencenumber: string;\n offset: string;\n}\n\n/**\n * An ownership entity of type PartitionOwnership to be stored in the table\n * @internal\n */\nexport interface PartitionOwnershipEntity {\n /**\n * The partitionKey is a composite key assembled in the following format:\n * `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`\n */\n partitionKey: string;\n /**\n * The rowKey is the partitionId\n *\n */\n rowKey: string;\n ownerid: string;\n}\n\n/**\n * An implementation of CheckpointStore that uses Azure Table Storage to persist checkpoint data.\n */\nexport class TableCheckpointStore implements CheckpointStore {\n private _tableClient: TableClient;\n\n constructor(tableClient: TableClient) {\n this._tableClient = tableClient;\n }\n\n /**\n * Get the list of all existing partition ownership from the underlying data store. May return empty\n * results if there are is no existing ownership information.\n * Partition Ownership contains the information on which `EventHubConsumerClient` subscribe call is currently processing the partition.\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 * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\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 partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Ownership`;\n const partitionOwnershipArray: PartitionOwnership[] = [];\n const entitiesIter = this._tableClient.listEntities<PartitionOwnershipEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n try {\n for await (const entity of entitiesIter) {\n if (!entity.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entity.rowKey}\"`,\n );\n }\n\n const partitionOwnership: PartitionOwnership = {\n fullyQualifiedNamespace,\n eventHubName,\n consumerGroup,\n ownerId: entity.ownerid,\n partitionId: entity.rowKey,\n lastModifiedTimeInMs: new Date(entity.timestamp).getTime(),\n etag: entity.etag,\n };\n partitionOwnershipArray.push(partitionOwnership);\n }\n return partitionOwnershipArray;\n } catch (err: any) {\n logger.warning(`Error occurred while fetching the list of entities`, err.message);\n logErrorStackTrace(err);\n if (err?.name === \"AbortError\") throw err;\n\n throw new Error(`Error occurred while fetching the list of entities. \\n${err}`);\n }\n }\n\n /**\n * Claim ownership of a list of partitions. This will return the list of partitions that were\n * successfully claimed.\n *\n * @param partitionOwnership - The list of partition ownership this instance is claiming to own.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A list partitions this instance successfully claimed ownership.\n */\n async claimOwnership(partitionOwnership: PartitionOwnership[]): Promise<PartitionOwnership[]> {\n const partitionOwnershipArray: PartitionOwnership[] = [];\n\n for (const ownership of partitionOwnership) {\n const updatedOwnership = { ...ownership };\n const partitionKey = `${ownership.fullyQualifiedNamespace} ${ownership.eventHubName} ${ownership.consumerGroup} Ownership`;\n const ownershipEntity: PartitionOwnershipEntity = {\n partitionKey: partitionKey,\n rowKey: ownership.partitionId,\n ownerid: ownership.ownerId,\n };\n\n // When we have an etag, we know the entity existed.\n // If we encounter an error we should fail.\n try {\n if (ownership.etag) {\n const updatedMetadata = await this._tableClient.updateEntity(ownershipEntity, \"Replace\", {\n etag: ownership.etag,\n });\n const entityRetrieved = await this._tableClient.getEntity(\n ownershipEntity.partitionKey,\n ownershipEntity.rowKey,\n );\n if (!entityRetrieved.timestamp) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${entityRetrieved.rowKey}\"`,\n );\n }\n updatedOwnership.lastModifiedTimeInMs = new Date(entityRetrieved.timestamp).getTime();\n updatedOwnership.etag = updatedMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n logger.info(\n `[${ownership.ownerId}] Claimed ownership successfully for partition: ${ownership.partitionId}`,\n `LastModifiedTime: ${ownership.lastModifiedTimeInMs}, ETag: ${ownership.etag}`,\n );\n } else {\n const newOwnershipMetadata = await this._tableClient.createEntity(ownershipEntity, {\n requestOptions: {\n customHeaders: {\n Prefer: \"return-content\",\n },\n },\n });\n\n if (!_hasTimestamp(newOwnershipMetadata)) {\n throw new Error(\n `Unable to retrieve timestamp from partitionKey \"${partitionKey}\", rowKey \"${ownershipEntity.rowKey}\"`,\n );\n }\n\n updatedOwnership.lastModifiedTimeInMs = new Date(\n newOwnershipMetadata.Timestamp,\n ).getTime();\n updatedOwnership.etag = newOwnershipMetadata.etag;\n partitionOwnershipArray.push(updatedOwnership);\n }\n } catch (err: any) {\n if (err.statusCode === 412) {\n // etag failures (precondition not met) aren't fatal errors. They happen\n // as multiple consumers attempt to claim the same partition (first one wins)\n // and losers get this error.\n logger.verbose(\n `[${ownership.ownerId}] Did not claim partition ${ownership.partitionId}. Another processor has already claimed it.`,\n );\n continue;\n }\n logger.warning(\n `Error occurred while claiming ownership for partition: ${ownership.partitionId}`,\n err.message,\n );\n logErrorStackTrace(err);\n }\n }\n return partitionOwnershipArray;\n }\n\n /**\n * Lists all the checkpoints in a data store for a given namespace, eventhub and consumer group.\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 * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n */\n async listCheckpoints(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n consumerGroup: string,\n ): Promise<Checkpoint[]> {\n const partitionKey = `${fullyQualifiedNamespace} ${eventHubName} ${consumerGroup} Checkpoint`;\n const checkpoints: Checkpoint[] = [];\n const entitiesIter = this._tableClient.listEntities<CheckpointEntity>({\n queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },\n });\n for await (const entity of entitiesIter) {\n checkpoints.push({\n consumerGroup,\n eventHubName,\n fullyQualifiedNamespace,\n partitionId: entity.rowKey,\n offset: parseInt(entity.offset, 10),\n sequenceNumber: parseInt(entity.sequencenumber, 10),\n });\n }\n return checkpoints;\n }\n\n /**\n * Updates the checkpoint in the data store for a partition.\n *\n * @param checkpoint - The checkpoint.\n * @param options - A set of options that can be specified to influence the behavior of this method.\n * - `abortSignal`: A signal used to request operation cancellation.\n * - `tracingOptions`: Options for configuring tracing.\n * @returns A promise that resolves when the checkpoint has been updated.\n */\n async updateCheckpoint(checkpoint: Checkpoint): Promise<void> {\n const partitionKey = `${checkpoint.fullyQualifiedNamespace} ${checkpoint.eventHubName} ${checkpoint.consumerGroup} Checkpoint`;\n const checkpointEntity: CheckpointEntity = {\n partitionKey: partitionKey,\n rowKey: checkpoint.partitionId,\n sequencenumber: checkpoint.sequenceNumber.toString(),\n offset: checkpoint.offset.toString(),\n };\n try {\n await this._tableClient.upsertEntity(checkpointEntity);\n logger.verbose(`Updated checkpoint successfully for partition: ${checkpoint.partitionId}`);\n return;\n } catch (err: any) {\n logger.verbose(\n `Error occurred while upating the checkpoint for partition: ${checkpoint.partitionId}.`,\n err.message,\n );\n throw err;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/util/error.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAC9C,UAAkB,EAClB,aAAqB,EACrB,cAAuB;IAEvB,IAAI,cAAc,KAAK,SAAS,IAAI,cAAc,KAAK,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/util/error.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAC9C,UAAkB,EAClB,aAAqB,EACrB,cAAuB;IAEvB,IAAI,cAAc,KAAK,SAAS,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;QAC5D,MAAM,KAAK,GAAG,IAAI,SAAS,CACzB,GAAG,UAAU,sCAAsC,aAAa,GAAG,CACpE,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { logErrorStackTrace, logger } from \"../log\";\n\n/**\n * @internal\n * Logs and Throws TypeError if given parameter is undefined or null\n * @param methodName - Name of the method that was passed the parameter\n * @param parameterName - Name of the parameter to check\n * @param parameterValue - Value of the parameter to check\n */\nexport function throwTypeErrorIfParameterMissing(\n methodName: string,\n parameterName: string,\n parameterValue: unknown,\n): void {\n if (parameterValue === undefined || parameterValue === null) {\n const error = new TypeError(\n `${methodName} called without required argument \"${parameterName}\"`,\n );\n logger.warning(error.message);\n logErrorStackTrace(error);\n throw error;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/eventhubs-checkpointstore-table",
|
|
3
3
|
"sdk-type": "client",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.20240126.2",
|
|
5
5
|
"description": "An Azure Storage Table solution to store checkpoints when using Event Hubs.",
|
|
6
6
|
"author": "Microsoft Corporation",
|
|
7
7
|
"license": "MIT",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"c8": "^8.0.0",
|
|
98
98
|
"rimraf": "^3.0.0",
|
|
99
99
|
"ts-node": "^10.0.0",
|
|
100
|
-
"typescript": "~5.
|
|
100
|
+
"typescript": "~5.3.3",
|
|
101
101
|
"util": "^0.12.1"
|
|
102
102
|
},
|
|
103
103
|
"//sampleConfiguration": {
|