@fluidframework/task-manager 2.0.0-internal.2.2.1 → 2.0.0-internal.2.3.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/.eslintrc.js +19 -7
- package/README.md +23 -4
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/taskManager.js +8 -8
- package/dist/taskManager.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/taskManager.js +8 -8
- package/lib/taskManager.js.map +1 -1
- package/package.json +17 -18
- package/src/packageVersion.ts +1 -1
- package/src/taskManager.ts +8 -8
package/.eslintrc.js
CHANGED
|
@@ -4,11 +4,23 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"parserOptions": {
|
|
12
|
-
"project": ["./tsconfig.json", "./src/test/tsconfig.json"]
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid/minimal"), "prettier"],
|
|
8
|
+
|
|
9
|
+
parserOptions: {
|
|
10
|
+
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
13
11
|
},
|
|
14
|
-
|
|
12
|
+
rules: {
|
|
13
|
+
// This library is used in the browser, so we don't want dependencies on most node libraries.
|
|
14
|
+
"import/no-nodejs-modules": ["error", { allow: ["events"] }],
|
|
15
|
+
},
|
|
16
|
+
overrides: [
|
|
17
|
+
{
|
|
18
|
+
// Rules only for test files
|
|
19
|
+
files: ["*.spec.ts", "src/test/**"],
|
|
20
|
+
rules: {
|
|
21
|
+
// Test files are run in node only so additional node libraries can be used.
|
|
22
|
+
"import/no-nodejs-modules": ["error", { allow: ["assert", "events", "fs", "path"] }],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# @fluidframework/task-manager
|
|
2
2
|
|
|
3
3
|
<!-- AUTO-GENERATED-CONTENT:START (README_SIMPLE:scripts=FALSE) -->
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
<!-- prettier-ignore-start -->
|
|
6
|
+
|
|
7
|
+
<!-- This section is automatically generated. To update it, make the appropriate changes to docs/md-magic.config.js or the embedded content, then run 'npm run build:md-magic' in the docs folder. -->
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
@@ -18,12 +20,26 @@ API documentation for **@fluidframework/task-manager** is available at <https://
|
|
|
18
20
|
|
|
19
21
|
## Contribution Guidelines
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
There are many ways to [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid.
|
|
24
|
+
|
|
25
|
+
- Participate in Q&A in our [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
|
|
26
|
+
- [Submit bugs](https://github.com/microsoft/FluidFramework/issues) and help us verify fixes as they are checked in.
|
|
27
|
+
- Review the [source code changes](https://github.com/microsoft/FluidFramework/pulls).
|
|
28
|
+
- [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
|
|
29
|
+
|
|
30
|
+
Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/wiki).
|
|
31
|
+
|
|
32
|
+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
33
|
+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
34
|
+
|
|
35
|
+
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
36
|
+
Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
|
|
37
|
+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
22
38
|
|
|
23
39
|
## Help
|
|
24
40
|
|
|
25
41
|
Not finding what you're looking for in this README?
|
|
26
|
-
Check out our [
|
|
42
|
+
Check out our [GitHub Wiki](https://github.com/microsoft/FluidFramework/wiki) or [fluidframework.com](https://fluidframework.com/docs/).
|
|
27
43
|
|
|
28
44
|
Still not finding what you're looking for? Please [file an issue](https://github.com/microsoft/FluidFramework/wiki/Submitting-Bugs-and-Feature-Requests).
|
|
29
45
|
Thank you!
|
|
@@ -33,4 +49,7 @@ Thank you!
|
|
|
33
49
|
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
34
50
|
Use of these trademarks or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
|
35
51
|
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
52
|
+
|
|
53
|
+
<!-- prettier-ignore-end -->
|
|
54
|
+
|
|
36
55
|
<!-- AUTO-GENERATED-CONTENT:END -->
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/task-manager";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-internal.2.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.2.3.1";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/task-manager";
|
|
11
|
-
exports.pkgVersion = "2.0.0-internal.2.
|
|
11
|
+
exports.pkgVersion = "2.0.0-internal.2.3.1";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/task-manager\";\nexport const pkgVersion = \"2.0.0-internal.2.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/task-manager\";\nexport const pkgVersion = \"2.0.0-internal.2.3.1\";\n"]}
|
package/dist/taskManager.js
CHANGED
|
@@ -313,8 +313,8 @@ class TaskManager extends shared_object_base_1.SharedObject {
|
|
|
313
313
|
}
|
|
314
314
|
if (this.readOnlyInfo.readonly === true) {
|
|
315
315
|
const error = this.readOnlyInfo.permissions === true ?
|
|
316
|
-
new Error(
|
|
317
|
-
new Error(
|
|
316
|
+
new Error("Attempted to volunteer with read-only permissions") :
|
|
317
|
+
new Error("Attempted to volunteer in read-only state");
|
|
318
318
|
throw error;
|
|
319
319
|
}
|
|
320
320
|
if (!this.isAttached()) {
|
|
@@ -324,7 +324,7 @@ class TaskManager extends shared_object_base_1.SharedObject {
|
|
|
324
324
|
return true;
|
|
325
325
|
}
|
|
326
326
|
if (!this.connected) {
|
|
327
|
-
throw new Error(
|
|
327
|
+
throw new Error("Attempted to volunteer in disconnected state");
|
|
328
328
|
}
|
|
329
329
|
// This promise works even if we already have an outstanding volunteer op.
|
|
330
330
|
const lockAcquireP = new Promise((resolve, reject) => {
|
|
@@ -351,14 +351,14 @@ class TaskManager extends shared_object_base_1.SharedObject {
|
|
|
351
351
|
this.abandonWatcher.off("abandon", checkIfAbandoned);
|
|
352
352
|
this.connectionWatcher.off("disconnect", rejectOnDisconnect);
|
|
353
353
|
this.completedWatcher.off("completed", checkIfCompleted);
|
|
354
|
-
reject(new Error(
|
|
354
|
+
reject(new Error("Abandoned before acquiring task assignment"));
|
|
355
355
|
};
|
|
356
356
|
const rejectOnDisconnect = () => {
|
|
357
357
|
this.queueWatcher.off("queueChange", checkIfAcquiredLock);
|
|
358
358
|
this.abandonWatcher.off("abandon", checkIfAbandoned);
|
|
359
359
|
this.connectionWatcher.off("disconnect", rejectOnDisconnect);
|
|
360
360
|
this.completedWatcher.off("completed", checkIfCompleted);
|
|
361
|
-
reject(new Error(
|
|
361
|
+
reject(new Error("Disconnected before acquiring task assignment"));
|
|
362
362
|
};
|
|
363
363
|
const checkIfCompleted = (eventTaskId) => {
|
|
364
364
|
if (eventTaskId !== taskId) {
|
|
@@ -388,7 +388,7 @@ class TaskManager extends shared_object_base_1.SharedObject {
|
|
|
388
388
|
return;
|
|
389
389
|
}
|
|
390
390
|
if (this.readOnlyInfo.readonly === true && this.readOnlyInfo.permissions === true) {
|
|
391
|
-
throw new Error(
|
|
391
|
+
throw new Error("Attempted to subscribe with read-only permissions");
|
|
392
392
|
}
|
|
393
393
|
const submitVolunteerOp = () => {
|
|
394
394
|
this.submitVolunteerOp(taskId);
|
|
@@ -515,13 +515,13 @@ class TaskManager extends shared_object_base_1.SharedObject {
|
|
|
515
515
|
*/
|
|
516
516
|
complete(taskId) {
|
|
517
517
|
if (!this.assigned(taskId)) {
|
|
518
|
-
throw new Error(
|
|
518
|
+
throw new Error("Attempted to mark task as complete while not being assigned");
|
|
519
519
|
}
|
|
520
520
|
// If we are detached we will simulate auto-ack for the complete op. Therefore we only need to send the op if
|
|
521
521
|
// we are attached. Additionally, we don't need to check if we are connected while detached.
|
|
522
522
|
if (this.isAttached()) {
|
|
523
523
|
if (!this.connected) {
|
|
524
|
-
throw new Error(
|
|
524
|
+
throw new Error("Attempted to complete task in disconnected state");
|
|
525
525
|
}
|
|
526
526
|
this.submitCompleteOp(taskId);
|
|
527
527
|
}
|
package/dist/taskManager.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taskManager.js","sourceRoot":"","sources":["../src/taskManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,mCAAsC;AAEtC,+DAAsD;AACtD,+EAA8F;AAQ9F,+DAA4D;AAC5D,2EAA6G;AAE7G,6DAA0D;AA+B1D,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AACH,MAAa,WAAY,SAAQ,iCAAgC;IAoE7D;;;;;;OAMG;IACH,YAAY,EAAU,EAAE,OAA+B,EAAE,UAA8B;QACnF,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,oBAAoB,CAAC,CAAC;QAvDzD;;;WAGG;QACc,eAAU,GAA0B,IAAI,GAAG,EAAE,CAAC;QAE/D,2GAA2G;QAC1F,cAAS,GAAiB,IAAI,qBAAY,EAAE,CAAC;QAC9D,sFAAsF;QACrE,iBAAY,GAAiB,IAAI,qBAAY,EAAE,CAAC;QACjE,qFAAqF;QACpE,mBAAc,GAAiB,IAAI,qBAAY,EAAE,CAAC;QACnE,8EAA8E;QAC7D,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,SAAS,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE;YACjD,MAAM,mBAAmB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAC,CAAC;YACvG,IAAI,WAAW,CAAC,MAAM,KAAK,mBAAmB,CAAC,MAAM,EAAE;gBACnD,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC,EAAE;oBAClC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;iBAClC;qBAAM;oBACH,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;iBACpD;gBACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;aACjD;SACJ;IACL,CAAC;IAEM,cAAc;QACjB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AA3qBD,kCA2qBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ReadOnlyInfo } from \"@fluidframework/container-definitions\";\nimport { TaskManagerFactory } from \"./taskManagerFactory\";\nimport { ITaskManager, ITaskManagerEvents } from \"./interfaces\";\n\n/**\n * Description of a task manager operation\n */\ntype ITaskManagerOperation =\n ITaskManagerVolunteerOperation |\n ITaskManagerAbandonOperation |\n ITaskManagerCompletedOperation;\n\ninterface ITaskManagerVolunteerOperation {\n type: \"volunteer\";\n taskId: string;\n}\n\ninterface ITaskManagerAbandonOperation {\n type: \"abandon\";\n taskId: string;\n}\n\ninterface ITaskManagerCompletedOperation {\n type: \"complete\";\n taskId: string;\n}\n\ninterface IPendingOp {\n type: \"volunteer\" | \"abandon\" | \"complete\";\n messageId: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * Placeholder clientId for detached scenarios.\n */\nconst placeholderClientId = \"placeholder\";\n\n\n/**\n * The TaskManager distributed data structure tracks queues of clients that want to exclusively run a task.\n *\n * @remarks\n *\n * For an in-depth overview, see [TaskManager](https://fluidframework.com/docs/data-structures/task-manager/).\n *\n * ### Creation\n *\n * To create a `TaskManager`, call the static create method:\n *\n * ```typescript\n * const taskManager = TaskManager.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * To volunteer for a task, use the `volunteerForTask()` method. This returns a Promise that will resolve once the\n * client has acquired exclusive rights to run the task, or reject if the client is removed from the queue without\n * acquiring the rights.\n *\n * ```typescript\n * taskManager.volunteerForTask(\"NameOfTask\")\n * .then(() => { doTheTask(); })\n * .catch((err) => { console.error(err); });\n * ```\n *\n * Alternatively, you can indefinitely volunteer for a task with the synchronous `subscribeToTask()` method. This\n * method does not return a value, therefore you need to rely on eventing to know when you have acquired the rights\n * to run the task (see below).\n *\n * ```typescript\n * taskManager.subscribeToTask(\"NameOfTask\");\n * ```\n *\n * To check if the local client is currently subscribed to a task, use the `subscribed()` method.\n * ```typescript\n * if (taskManager.subscribed(\"NameOfTask\")) {\n * console.log(\"This client is currently subscribed to the task.\");\n * }\n * ```\n *\n * To release the rights to the task, use the `abandon()` method. The next client in the queue will then get the\n * rights to run the task.\n *\n * ```typescript\n * taskManager.abandon(\"NameOfTask\");\n * ```\n *\n * To inspect your state in the queue, you can use the `queued()` and `assigned()` methods.\n *\n * ```typescript\n * if (taskManager.queued(\"NameOfTask\")) {\n * console.log(\"This client is somewhere in the queue, potentially even having the task assignment.\");\n * }\n *\n * if (taskManager.assigned(\"NameOfTask\")) {\n * console.log(\"This client currently has the rights to run the task\");\n * }\n * ```\n *\n * To signal to other connected clients that a task is completed, use the `complete()` method. This will release all\n * clients from the queue and emit the \"completed\" event.\n *\n * ```typescript\n * taskManager.complete(\"NameOfTask\");\n * ```\n *\n * ### Eventing\n *\n * `TaskManager` is an `EventEmitter`, and will emit events when a task is assigned to the client, when the task\n * assignment is lost, and when a task was completed by another client.\n *\n * ```typescript\n * taskManager.on(\"assigned\", (taskId: string) => {\n * console.log(`Client was assigned task: ${taskId}`);\n * });\n *\n * taskManager.on(\"lost\", (taskId: string) => {\n * console.log(`Client released task: ${taskId}`);\n * });\n *\n * taskManager.on(\"completed\", (taskId: string) => {\n * console.log(`Another client completed task: ${taskId}`);\n * });\n * ```\n *\n * These can be useful if the logic to volunteer for a task is separated from the logic to perform the task, such as\n * when using the `subscribeToTask()` method.\n */\nexport class TaskManager extends SharedObject<ITaskManagerEvents> implements ITaskManager {\n /**\n * Create a new TaskManager\n *\n * @param runtime - data store runtime the new task queue belongs to\n * @param id - optional name of the task queue\n * @returns newly create task queue (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, TaskManagerFactory.Type) as TaskManager;\n }\n\n /**\n * Get a factory for TaskManager to register with the data store.\n *\n * @returns a factory that creates and load TaskManager\n */\n public static getFactory(): IChannelFactory {\n return new TaskManagerFactory();\n }\n\n /**\n * Mapping of taskId to a queue of clientIds that are waiting on the task. Maintains the consensus state of the\n * queue, even if we know we've submitted an op that should eventually modify the queue.\n */\n private readonly taskQueues: Map<string, string[]> = new Map();\n\n // opWatcher emits for every op on this data store. This is just a repackaging of processCore into events.\n private readonly opWatcher: EventEmitter = new EventEmitter();\n // queueWatcher emits an event whenever the consensus state of the task queues changes\n private readonly queueWatcher: EventEmitter = new EventEmitter();\n // abandonWatcher emits an event whenever the local client calls abandon() on a task.\n private readonly abandonWatcher: EventEmitter = new EventEmitter();\n // connectionWatcher emits an event whenever we get connected or disconnected.\n private readonly connectionWatcher: EventEmitter = new EventEmitter();\n // completedWatcher emits an event whenever the local client receives a completed op.\n private readonly completedWatcher: EventEmitter = new EventEmitter();\n\n private messageId: number = -1;\n /**\n * Tracks the most recent pending op for a given task\n */\n private readonly latestPendingOps: Map<string, IPendingOp> = new Map();\n\n /**\n * Tracks tasks that are this client is currently subscribed to.\n */\n private readonly subscribedTasks: Set<string> = new Set();\n\n /**\n * Map to track tasks that have pending complete ops.\n */\n private readonly pendingCompletedTasks: Map<string, number[]> = new Map();\n\n /**\n * Returns the clientId. Will return a placeholder if the runtime is detached and not yet assigned a clientId.\n */\n private get clientId(): string | undefined {\n return this.isAttached() ? this.runtime.clientId : placeholderClientId;\n }\n\n /**\n * Returns a ReadOnlyInfo object to determine current read/write permissions.\n */\n private get readOnlyInfo(): ReadOnlyInfo {\n return this.runtime.deltaManager.readOnlyInfo;\n }\n\n /**\n * Constructs a new task manager. If the object is non-local an id and service interfaces will\n * be provided\n *\n * @param runtime - data store runtime the task queue belongs to\n * @param id - optional name of the task queue\n */\n constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, \"fluid_taskManager_\");\n\n this.opWatcher.on(\"volunteer\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n // We're tracking local ops from this connection. Filter out local ops during \"connecting\"\n // state since these were sent on the prior connection and were already cleared from the latestPendingOps.\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x07b /* \"Unexpected op\" */);\n // Need to check the id, since it's possible to volunteer and abandon multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"volunteer\", 0x07c /* \"Unexpected op type\" */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n }\n\n this.addClientToQueue(taskId, clientId);\n });\n\n this.opWatcher.on(\"abandon\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x07d /* \"Unexpected op\" */);\n // Need to check the id, since it's possible to abandon and volunteer multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"abandon\", 0x07e /* \"Unexpected op type\" */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n }\n\n this.removeClientFromQueue(taskId, clientId);\n });\n\n this.opWatcher.on(\"complete\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x400 /* Unexpected op */);\n // Need to check the id, since it's possible to complete multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"complete\", 0x401 /* Unexpected op type */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n\n // Remove complete op from this.pendingCompletedTasks\n const pendingIds = this.pendingCompletedTasks.get(taskId);\n assert(pendingIds !== undefined && pendingIds.length > 0, 0x402 /* pendingIds is empty */);\n const removed = pendingIds.shift();\n assert(removed === messageId, 0x403 /* Removed complete op id does not match */);\n }\n\n // For clients in queue, we need to remove them from the queue and raise the proper events.\n if (!local) {\n this.taskQueues.delete(taskId);\n this.completedWatcher.emit(\"completed\", taskId);\n this.emit(\"completed\", taskId);\n }\n });\n\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n this.removeClientFromAllQueues(clientId);\n });\n\n this.queueWatcher.on(\"queueChange\", (taskId: string, oldLockHolder: string, newLockHolder: string) => {\n // If oldLockHolder is placeholderClientId we need to emit the task was lost during the attach process\n if (oldLockHolder === placeholderClientId) {\n this.emit(\"lost\", taskId);\n return;\n }\n\n // Exit early if we are still catching up on reconnect -- we can't be the leader yet anyway.\n if (this.clientId === undefined) {\n return;\n }\n\n if (oldLockHolder !== this.clientId && newLockHolder === this.clientId) {\n this.emit(\"assigned\", taskId);\n } else if (oldLockHolder === this.clientId && newLockHolder !== this.clientId) {\n this.emit(\"lost\", taskId);\n }\n });\n\n this.connectionWatcher.on(\"disconnect\", () => {\n assert(this.clientId !== undefined, 0x1d3 /* \"Missing client id on disconnect\" */);\n\n // We don't modify the taskQueues on disconnect (they still reflect the latest known consensus state).\n // After reconnect these will get cleaned up by observing the clientLeaves.\n // However we do need to recognize that we lost the lock if we had it. Calls to .queued() and\n // .assigned() are also connection-state-aware to be consistent.\n for (const [taskId, clientQueue] of this.taskQueues.entries()) {\n if (this.isAttached() && clientQueue[0] === this.clientId) {\n this.emit(\"lost\", taskId);\n }\n }\n\n // All of our outstanding ops will be for the old clientId even if they get ack'd\n this.latestPendingOps.clear();\n });\n }\n\n private submitVolunteerOp(taskId: string) {\n const op: ITaskManagerVolunteerOperation = {\n type: \"volunteer\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"volunteer\",\n messageId: ++this.messageId,\n };\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n private submitAbandonOp(taskId: string) {\n const op: ITaskManagerAbandonOperation = {\n type: \"abandon\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"abandon\",\n messageId: ++this.messageId,\n };\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n private submitCompleteOp(taskId: string) {\n const op: ITaskManagerCompletedOperation = {\n type: \"complete\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"complete\",\n messageId: ++this.messageId,\n };\n\n if (this.pendingCompletedTasks.has(taskId)) {\n this.pendingCompletedTasks.get(taskId)?.push(pendingOp.messageId);\n } else {\n this.pendingCompletedTasks.set(taskId, [pendingOp.messageId]);\n }\n\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n /**\n * {@inheritDoc ITaskManager.volunteerForTask}\n */\n public async volunteerForTask(taskId: string) {\n // If we have the lock, resolve immediately\n if (this.assigned(taskId)) {\n return true;\n }\n\n if (this.readOnlyInfo.readonly === true) {\n const error = this.readOnlyInfo.permissions === true ?\n new Error(`Attempted to volunteer with read-only permissions: ${taskId}`) :\n new Error(`Attempted to volunteer in read-only state: ${taskId}`);\n throw error;\n }\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x472 /* clientId should not be undefined */);\n this.addClientToQueue(taskId, this.clientId);\n return true;\n }\n\n if (!this.connected) {\n throw new Error(`Attempted to volunteer in disconnected state: ${taskId}`);\n }\n\n // This promise works even if we already have an outstanding volunteer op.\n const lockAcquireP = new Promise<boolean>((resolve, reject) => {\n const checkIfAcquiredLock = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n // Also check pending ops here because it's possible we are currently in the queue from a previous\n // lock attempt, but have an outstanding abandon AND the outstanding volunteer for this lock attempt.\n // If we reach the head of the queue based on the previous lock attempt, we don't want to resolve.\n if (this.assigned(taskId) && !this.latestPendingOps.has(taskId)) {\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n resolve(true);\n }\n };\n\n const checkIfAbandoned = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n reject(new Error(`Abandoned before acquiring task assignment: ${taskId}`));\n };\n\n const rejectOnDisconnect = () => {\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n reject(new Error(`Disconnected before acquiring task assignment: ${taskId}`));\n };\n\n const checkIfCompleted = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n resolve(false);\n };\n\n this.queueWatcher.on(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.on(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.on(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.on(\"completed\", checkIfCompleted);\n });\n\n if (!this.queued(taskId)) {\n this.submitVolunteerOp(taskId);\n }\n return lockAcquireP;\n }\n\n /**\n * {@inheritDoc ITaskManager.subscribeToTask}\n */\n public subscribeToTask(taskId: string) {\n if (this.subscribed(taskId)) {\n return;\n }\n\n if (this.readOnlyInfo.readonly === true && this.readOnlyInfo.permissions === true) {\n throw new Error(`Attempted to subscribe with read-only permissions: ${taskId}`);\n }\n\n const submitVolunteerOp = () => {\n this.submitVolunteerOp(taskId);\n };\n\n const disconnectHandler = () => {\n // Wait to be connected again and then re-submit volunteer op\n this.connectionWatcher.once(\"connect\", submitVolunteerOp);\n };\n\n const checkIfAbandoned = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", disconnectHandler);\n this.connectionWatcher.off(\"connect\", submitVolunteerOp);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n\n this.subscribedTasks.delete(taskId);\n };\n\n const checkIfCompleted = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", disconnectHandler);\n this.connectionWatcher.off(\"connect\", submitVolunteerOp);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n\n this.subscribedTasks.delete(taskId);\n };\n\n this.abandonWatcher.on(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.on(\"disconnect\", disconnectHandler);\n this.completedWatcher.on(\"completed\", checkIfCompleted);\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x473 /* clientId should not be undefined */);\n this.addClientToQueue(taskId, this.clientId);\n // Because we volunteered with placeholderClientId, we need to wait for when we attach and are assigned\n // a real clientId. At that point we should re-enter the queue with a real volunteer op (assuming we are\n // connected).\n this.runtime.once(\"attached\", () => {\n if (this.queued(taskId)) {\n // If we are already queued, then we were able to replace the placeholderClientId with our real\n // clientId and no action is required.\n return;\n } else if (this.connected) {\n submitVolunteerOp();\n } else {\n this.connectionWatcher.once(\"connect\", () => {\n submitVolunteerOp();\n });\n }\n });\n } else if (!this.connected) {\n // If we are disconnected (and attached), wait to be connected and submit volunteer op\n disconnectHandler();\n } else if (!this.assigned(taskId) && !this.queued(taskId)) {\n submitVolunteerOp();\n }\n this.subscribedTasks.add(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.abandon}\n */\n public abandon(taskId: string) {\n // Always allow abandon if the client is subscribed to allow clients to unsubscribe while disconnected.\n // Otherwise, we should check to make sure the client is both connected queued for the task before sending an\n // abandon op.\n if (!this.subscribed(taskId) && !this.queued(taskId)) {\n // Nothing to do\n return;\n }\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x474 /* clientId is undefined */);\n this.removeClientFromQueue(taskId, this.clientId);\n this.abandonWatcher.emit(\"abandon\", taskId);\n return;\n }\n\n // If we're subscribed but not queued, we don't need to submit an abandon op (probably offline)\n if (this.queued(taskId)) {\n this.submitAbandonOp(taskId);\n }\n this.abandonWatcher.emit(\"abandon\", taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.assigned}\n */\n public assigned(taskId: string) {\n if (this.isAttached() && !this.connected) {\n return false;\n }\n\n const currentAssignee = this.taskQueues.get(taskId)?.[0];\n return currentAssignee !== undefined\n && currentAssignee === this.clientId\n && !this.latestPendingOps.has(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.queued}\n */\n public queued(taskId: string) {\n if (this.isAttached() && !this.connected) {\n return false;\n }\n\n assert(this.clientId !== undefined, 0x07f /* \"clientId undefined\" */);\n\n const clientQueue = this.taskQueues.get(taskId);\n // If we have no queue for the taskId, then no one has signed up for it.\n return (\n (clientQueue?.includes(this.clientId) ?? false)\n && !this.latestPendingOps.has(taskId)\n )\n || this.latestPendingOps.get(taskId)?.type === \"volunteer\";\n }\n\n /**\n * {@inheritDoc ITaskManager.subscribed}\n */\n public subscribed(taskId: string): boolean {\n return this.subscribedTasks.has(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.complete}\n */\n public complete(taskId: string): void {\n if (!this.assigned(taskId)) {\n throw new Error(`Attempted to mark task as complete while not being assigned: ${taskId}`);\n }\n\n // If we are detached we will simulate auto-ack for the complete op. Therefore we only need to send the op if\n // we are attached. Additionally, we don't need to check if we are connected while detached.\n if (this.isAttached()) {\n if (!this.connected) {\n throw new Error(`Attempted to complete task in disconnected state: ${taskId}`);\n }\n this.submitCompleteOp(taskId);\n }\n\n this.taskQueues.delete(taskId);\n this.completedWatcher.emit(\"completed\", taskId);\n this.emit(\"completed\", taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.canVolunteer}\n */\n public canVolunteer(): boolean {\n // A client can volunteer for a task if it's both connected to the delta stream and in write mode.\n // this.connected reflects that condition, but is unintuitive and may be changed in the future. This API allows\n // us to make changes to this.connected without affecting our guidance on how to check if a client is eligible\n // to volunteer for a task.\n return this.connected;\n }\n\n /**\n * Create a summary for the task manager\n *\n * @returns the summary of the current state of the task manager\n * @internal\n */\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n if (this.runtime.clientId !== undefined) {\n // If the runtime has been assigned an actual clientId by now, we can replace the placeholder clientIds\n // and maintain the task assignment.\n this.replacePlaceholderInAllQueues();\n } else {\n // If the runtime has still not been assigned a clientId, we should not summarize with the placeholder\n // clientIds and instead remove them from the queues and require the client to re-volunteer when assigned\n // a new clientId.\n this.removeClientFromAllQueues(placeholderClientId);\n }\n\n // Only include tasks if there are clients in the queue.\n const filteredMap = new Map<string, string[]>();\n this.taskQueues.forEach((queue: string[], taskId: string) => {\n if (queue.length > 0) {\n filteredMap.set(taskId, queue);\n }\n });\n const content = [...filteredMap.entries()];\n return createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<[string, string[]][]>(storage, snapshotFileName);\n content.forEach(([taskId, clientIdQueue]) => {\n this.taskQueues.set(taskId, clientIdQueue);\n });\n this.scrubClientsNotInQuorum();\n }\n\n /**\n * @internal\n */\n protected initializeLocalCore() { }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n * @internal\n */\n protected onDisconnect() {\n this.connectionWatcher.emit(\"disconnect\");\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n * @internal\n */\n protected onConnect() {\n this.connectionWatcher.emit(\"connect\");\n }\n\n //\n /**\n * Override resubmit core to avoid resubmission on reconnect. On disconnect we accept our removal from the\n * queues, and leave it up to the user to decide whether they want to attempt to re-enter a queue on reconnect.\n * @internal\n */\n protected reSubmitCore() { }\n\n /**\n * Process a task manager operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n * @internal\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op = message.contents as ITaskManagerOperation;\n const messageId = localOpMetadata as number;\n\n switch (op.type) {\n case \"volunteer\":\n this.opWatcher.emit(\"volunteer\", op.taskId, message.clientId, local, messageId);\n break;\n\n case \"abandon\":\n this.opWatcher.emit(\"abandon\", op.taskId, message.clientId, local, messageId);\n break;\n\n case \"complete\":\n this.opWatcher.emit(\"complete\", op.taskId, message.clientId, local, messageId);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n private addClientToQueue(taskId: string, clientId: string) {\n const pendingIds = this.pendingCompletedTasks.get(taskId);\n if (pendingIds !== undefined && pendingIds.length > 0) {\n // Ignore the volunteer op if we know this task is about to be completed\n return;\n }\n\n // Ensure that the clientId exists in the quorum, or it is placeholderClientId (detached scenario)\n if (this.runtime.getQuorum().getMembers().has(clientId) || this.clientId === placeholderClientId) {\n // Create the queue if it doesn't exist, and push the client on the back.\n let clientQueue = this.taskQueues.get(taskId);\n if (clientQueue === undefined) {\n clientQueue = [];\n this.taskQueues.set(taskId, clientQueue);\n }\n\n const oldLockHolder = clientQueue[0];\n clientQueue.push(clientId);\n const newLockHolder = clientQueue[0];\n if (newLockHolder !== oldLockHolder) {\n this.queueWatcher.emit(\"queueChange\", taskId, oldLockHolder, newLockHolder);\n }\n\n }\n }\n\n private removeClientFromQueue(taskId: string, clientId: string) {\n const clientQueue = this.taskQueues.get(taskId);\n if (clientQueue === undefined) {\n return;\n }\n\n const oldLockHolder = clientId === placeholderClientId ? placeholderClientId : clientQueue[0];\n const clientIdIndex = clientQueue.indexOf(clientId);\n if (clientIdIndex !== -1) {\n clientQueue.splice(clientIdIndex, 1);\n // Clean up the queue if there are no more clients in it.\n if (clientQueue.length === 0) {\n this.taskQueues.delete(taskId);\n }\n }\n const newLockHolder = clientQueue[0];\n if (newLockHolder !== oldLockHolder) {\n this.queueWatcher.emit(\"queueChange\", taskId, oldLockHolder, newLockHolder);\n }\n }\n\n private removeClientFromAllQueues(clientId: string) {\n for (const taskId of this.taskQueues.keys()) {\n this.removeClientFromQueue(taskId, clientId);\n }\n }\n\n /**\n * Will replace all instances of the placeholderClientId with the current clientId. This should only be called when\n * transitioning from detached to attached and this.runtime.clientId is defined.\n */\n private replacePlaceholderInAllQueues() {\n assert(this.runtime.clientId !== undefined, 0x475 /* this.runtime.clientId should be defined */);\n for (const clientQueue of this.taskQueues.values()) {\n const clientIdIndex = clientQueue.indexOf(placeholderClientId);\n if (clientIdIndex !== -1) {\n clientQueue[clientIdIndex] = this.runtime.clientId;\n }\n }\n }\n\n // This seems like it should be unnecessary if we can trust to receive the join/leave messages and\n // also have an accurate snapshot.\n private scrubClientsNotInQuorum() {\n const quorum = this.runtime.getQuorum();\n for (const [taskId, clientQueue] of this.taskQueues) {\n const filteredClientQueue = clientQueue.filter((clientId) => quorum.getMember(clientId) !== undefined);\n if (clientQueue.length !== filteredClientQueue.length) {\n if (filteredClientQueue.length === 0) {\n this.taskQueues.delete(taskId);\n } else {\n this.taskQueues.set(taskId, filteredClientQueue);\n }\n this.queueWatcher.emit(\"queueChange\", taskId);\n }\n }\n }\n\n public applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"taskManager.js","sourceRoot":"","sources":["../src/taskManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,mCAAsC;AAEtC,+DAAsD;AACtD,+EAA8F;AAQ9F,+DAA4D;AAC5D,2EAA6G;AAE7G,6DAA0D;AA+B1D,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AACH,MAAa,WAAY,SAAQ,iCAAgC;IAoE7D;;;;;;OAMG;IACH,YAAY,EAAU,EAAE,OAA+B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mBAAmB,CAAC,CAAC;YAC/D,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE;gBACtB,WAAW,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;aACtD;SACJ;IACL,CAAC;IAED,kGAAkG;IAClG,kCAAkC;IAC1B,uBAAuB;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE;YACjD,MAAM,mBAAmB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAC,CAAC;YACvG,IAAI,WAAW,CAAC,MAAM,KAAK,mBAAmB,CAAC,MAAM,EAAE;gBACnD,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC,EAAE;oBAClC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;iBAClC;qBAAM;oBACH,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;iBACpD;gBACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;aACjD;SACJ;IACL,CAAC;IAEM,cAAc;QACjB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AA3qBD,kCA2qBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ReadOnlyInfo } from \"@fluidframework/container-definitions\";\nimport { TaskManagerFactory } from \"./taskManagerFactory\";\nimport { ITaskManager, ITaskManagerEvents } from \"./interfaces\";\n\n/**\n * Description of a task manager operation\n */\ntype ITaskManagerOperation =\n ITaskManagerVolunteerOperation |\n ITaskManagerAbandonOperation |\n ITaskManagerCompletedOperation;\n\ninterface ITaskManagerVolunteerOperation {\n type: \"volunteer\";\n taskId: string;\n}\n\ninterface ITaskManagerAbandonOperation {\n type: \"abandon\";\n taskId: string;\n}\n\ninterface ITaskManagerCompletedOperation {\n type: \"complete\";\n taskId: string;\n}\n\ninterface IPendingOp {\n type: \"volunteer\" | \"abandon\" | \"complete\";\n messageId: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * Placeholder clientId for detached scenarios.\n */\nconst placeholderClientId = \"placeholder\";\n\n\n/**\n * The TaskManager distributed data structure tracks queues of clients that want to exclusively run a task.\n *\n * @remarks\n *\n * For an in-depth overview, see [TaskManager](https://fluidframework.com/docs/data-structures/task-manager/).\n *\n * ### Creation\n *\n * To create a `TaskManager`, call the static create method:\n *\n * ```typescript\n * const taskManager = TaskManager.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * To volunteer for a task, use the `volunteerForTask()` method. This returns a Promise that will resolve once the\n * client has acquired exclusive rights to run the task, or reject if the client is removed from the queue without\n * acquiring the rights.\n *\n * ```typescript\n * taskManager.volunteerForTask(\"NameOfTask\")\n * .then(() => { doTheTask(); })\n * .catch((err) => { console.error(err); });\n * ```\n *\n * Alternatively, you can indefinitely volunteer for a task with the synchronous `subscribeToTask()` method. This\n * method does not return a value, therefore you need to rely on eventing to know when you have acquired the rights\n * to run the task (see below).\n *\n * ```typescript\n * taskManager.subscribeToTask(\"NameOfTask\");\n * ```\n *\n * To check if the local client is currently subscribed to a task, use the `subscribed()` method.\n * ```typescript\n * if (taskManager.subscribed(\"NameOfTask\")) {\n * console.log(\"This client is currently subscribed to the task.\");\n * }\n * ```\n *\n * To release the rights to the task, use the `abandon()` method. The next client in the queue will then get the\n * rights to run the task.\n *\n * ```typescript\n * taskManager.abandon(\"NameOfTask\");\n * ```\n *\n * To inspect your state in the queue, you can use the `queued()` and `assigned()` methods.\n *\n * ```typescript\n * if (taskManager.queued(\"NameOfTask\")) {\n * console.log(\"This client is somewhere in the queue, potentially even having the task assignment.\");\n * }\n *\n * if (taskManager.assigned(\"NameOfTask\")) {\n * console.log(\"This client currently has the rights to run the task\");\n * }\n * ```\n *\n * To signal to other connected clients that a task is completed, use the `complete()` method. This will release all\n * clients from the queue and emit the \"completed\" event.\n *\n * ```typescript\n * taskManager.complete(\"NameOfTask\");\n * ```\n *\n * ### Eventing\n *\n * `TaskManager` is an `EventEmitter`, and will emit events when a task is assigned to the client, when the task\n * assignment is lost, and when a task was completed by another client.\n *\n * ```typescript\n * taskManager.on(\"assigned\", (taskId: string) => {\n * console.log(`Client was assigned task: ${taskId}`);\n * });\n *\n * taskManager.on(\"lost\", (taskId: string) => {\n * console.log(`Client released task: ${taskId}`);\n * });\n *\n * taskManager.on(\"completed\", (taskId: string) => {\n * console.log(`Another client completed task: ${taskId}`);\n * });\n * ```\n *\n * These can be useful if the logic to volunteer for a task is separated from the logic to perform the task, such as\n * when using the `subscribeToTask()` method.\n */\nexport class TaskManager extends SharedObject<ITaskManagerEvents> implements ITaskManager {\n /**\n * Create a new TaskManager\n *\n * @param runtime - data store runtime the new task queue belongs to\n * @param id - optional name of the task queue\n * @returns newly create task queue (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, TaskManagerFactory.Type) as TaskManager;\n }\n\n /**\n * Get a factory for TaskManager to register with the data store.\n *\n * @returns a factory that creates and load TaskManager\n */\n public static getFactory(): IChannelFactory {\n return new TaskManagerFactory();\n }\n\n /**\n * Mapping of taskId to a queue of clientIds that are waiting on the task. Maintains the consensus state of the\n * queue, even if we know we've submitted an op that should eventually modify the queue.\n */\n private readonly taskQueues: Map<string, string[]> = new Map();\n\n // opWatcher emits for every op on this data store. This is just a repackaging of processCore into events.\n private readonly opWatcher: EventEmitter = new EventEmitter();\n // queueWatcher emits an event whenever the consensus state of the task queues changes\n private readonly queueWatcher: EventEmitter = new EventEmitter();\n // abandonWatcher emits an event whenever the local client calls abandon() on a task.\n private readonly abandonWatcher: EventEmitter = new EventEmitter();\n // connectionWatcher emits an event whenever we get connected or disconnected.\n private readonly connectionWatcher: EventEmitter = new EventEmitter();\n // completedWatcher emits an event whenever the local client receives a completed op.\n private readonly completedWatcher: EventEmitter = new EventEmitter();\n\n private messageId: number = -1;\n /**\n * Tracks the most recent pending op for a given task\n */\n private readonly latestPendingOps: Map<string, IPendingOp> = new Map();\n\n /**\n * Tracks tasks that are this client is currently subscribed to.\n */\n private readonly subscribedTasks: Set<string> = new Set();\n\n /**\n * Map to track tasks that have pending complete ops.\n */\n private readonly pendingCompletedTasks: Map<string, number[]> = new Map();\n\n /**\n * Returns the clientId. Will return a placeholder if the runtime is detached and not yet assigned a clientId.\n */\n private get clientId(): string | undefined {\n return this.isAttached() ? this.runtime.clientId : placeholderClientId;\n }\n\n /**\n * Returns a ReadOnlyInfo object to determine current read/write permissions.\n */\n private get readOnlyInfo(): ReadOnlyInfo {\n return this.runtime.deltaManager.readOnlyInfo;\n }\n\n /**\n * Constructs a new task manager. If the object is non-local an id and service interfaces will\n * be provided\n *\n * @param runtime - data store runtime the task queue belongs to\n * @param id - optional name of the task queue\n */\n constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, \"fluid_taskManager_\");\n\n this.opWatcher.on(\"volunteer\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n // We're tracking local ops from this connection. Filter out local ops during \"connecting\"\n // state since these were sent on the prior connection and were already cleared from the latestPendingOps.\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x07b /* \"Unexpected op\" */);\n // Need to check the id, since it's possible to volunteer and abandon multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"volunteer\", 0x07c /* \"Unexpected op type\" */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n }\n\n this.addClientToQueue(taskId, clientId);\n });\n\n this.opWatcher.on(\"abandon\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x07d /* \"Unexpected op\" */);\n // Need to check the id, since it's possible to abandon and volunteer multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"abandon\", 0x07e /* \"Unexpected op type\" */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n }\n\n this.removeClientFromQueue(taskId, clientId);\n });\n\n this.opWatcher.on(\"complete\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x400 /* Unexpected op */);\n // Need to check the id, since it's possible to complete multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"complete\", 0x401 /* Unexpected op type */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n\n // Remove complete op from this.pendingCompletedTasks\n const pendingIds = this.pendingCompletedTasks.get(taskId);\n assert(pendingIds !== undefined && pendingIds.length > 0, 0x402 /* pendingIds is empty */);\n const removed = pendingIds.shift();\n assert(removed === messageId, 0x403 /* Removed complete op id does not match */);\n }\n\n // For clients in queue, we need to remove them from the queue and raise the proper events.\n if (!local) {\n this.taskQueues.delete(taskId);\n this.completedWatcher.emit(\"completed\", taskId);\n this.emit(\"completed\", taskId);\n }\n });\n\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n this.removeClientFromAllQueues(clientId);\n });\n\n this.queueWatcher.on(\"queueChange\", (taskId: string, oldLockHolder: string, newLockHolder: string) => {\n // If oldLockHolder is placeholderClientId we need to emit the task was lost during the attach process\n if (oldLockHolder === placeholderClientId) {\n this.emit(\"lost\", taskId);\n return;\n }\n\n // Exit early if we are still catching up on reconnect -- we can't be the leader yet anyway.\n if (this.clientId === undefined) {\n return;\n }\n\n if (oldLockHolder !== this.clientId && newLockHolder === this.clientId) {\n this.emit(\"assigned\", taskId);\n } else if (oldLockHolder === this.clientId && newLockHolder !== this.clientId) {\n this.emit(\"lost\", taskId);\n }\n });\n\n this.connectionWatcher.on(\"disconnect\", () => {\n assert(this.clientId !== undefined, 0x1d3 /* \"Missing client id on disconnect\" */);\n\n // We don't modify the taskQueues on disconnect (they still reflect the latest known consensus state).\n // After reconnect these will get cleaned up by observing the clientLeaves.\n // However we do need to recognize that we lost the lock if we had it. Calls to .queued() and\n // .assigned() are also connection-state-aware to be consistent.\n for (const [taskId, clientQueue] of this.taskQueues.entries()) {\n if (this.isAttached() && clientQueue[0] === this.clientId) {\n this.emit(\"lost\", taskId);\n }\n }\n\n // All of our outstanding ops will be for the old clientId even if they get ack'd\n this.latestPendingOps.clear();\n });\n }\n\n private submitVolunteerOp(taskId: string) {\n const op: ITaskManagerVolunteerOperation = {\n type: \"volunteer\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"volunteer\",\n messageId: ++this.messageId,\n };\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n private submitAbandonOp(taskId: string) {\n const op: ITaskManagerAbandonOperation = {\n type: \"abandon\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"abandon\",\n messageId: ++this.messageId,\n };\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n private submitCompleteOp(taskId: string) {\n const op: ITaskManagerCompletedOperation = {\n type: \"complete\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"complete\",\n messageId: ++this.messageId,\n };\n\n if (this.pendingCompletedTasks.has(taskId)) {\n this.pendingCompletedTasks.get(taskId)?.push(pendingOp.messageId);\n } else {\n this.pendingCompletedTasks.set(taskId, [pendingOp.messageId]);\n }\n\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n /**\n * {@inheritDoc ITaskManager.volunteerForTask}\n */\n public async volunteerForTask(taskId: string) {\n // If we have the lock, resolve immediately\n if (this.assigned(taskId)) {\n return true;\n }\n\n if (this.readOnlyInfo.readonly === true) {\n const error = this.readOnlyInfo.permissions === true ?\n new Error(\"Attempted to volunteer with read-only permissions\") :\n new Error(\"Attempted to volunteer in read-only state\");\n throw error;\n }\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x472 /* clientId should not be undefined */);\n this.addClientToQueue(taskId, this.clientId);\n return true;\n }\n\n if (!this.connected) {\n throw new Error(\"Attempted to volunteer in disconnected state\");\n }\n\n // This promise works even if we already have an outstanding volunteer op.\n const lockAcquireP = new Promise<boolean>((resolve, reject) => {\n const checkIfAcquiredLock = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n // Also check pending ops here because it's possible we are currently in the queue from a previous\n // lock attempt, but have an outstanding abandon AND the outstanding volunteer for this lock attempt.\n // If we reach the head of the queue based on the previous lock attempt, we don't want to resolve.\n if (this.assigned(taskId) && !this.latestPendingOps.has(taskId)) {\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n resolve(true);\n }\n };\n\n const checkIfAbandoned = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n reject(new Error(\"Abandoned before acquiring task assignment\"));\n };\n\n const rejectOnDisconnect = () => {\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n reject(new Error(\"Disconnected before acquiring task assignment\"));\n };\n\n const checkIfCompleted = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n resolve(false);\n };\n\n this.queueWatcher.on(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.on(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.on(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.on(\"completed\", checkIfCompleted);\n });\n\n if (!this.queued(taskId)) {\n this.submitVolunteerOp(taskId);\n }\n return lockAcquireP;\n }\n\n /**\n * {@inheritDoc ITaskManager.subscribeToTask}\n */\n public subscribeToTask(taskId: string) {\n if (this.subscribed(taskId)) {\n return;\n }\n\n if (this.readOnlyInfo.readonly === true && this.readOnlyInfo.permissions === true) {\n throw new Error(\"Attempted to subscribe with read-only permissions\");\n }\n\n const submitVolunteerOp = () => {\n this.submitVolunteerOp(taskId);\n };\n\n const disconnectHandler = () => {\n // Wait to be connected again and then re-submit volunteer op\n this.connectionWatcher.once(\"connect\", submitVolunteerOp);\n };\n\n const checkIfAbandoned = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", disconnectHandler);\n this.connectionWatcher.off(\"connect\", submitVolunteerOp);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n\n this.subscribedTasks.delete(taskId);\n };\n\n const checkIfCompleted = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", disconnectHandler);\n this.connectionWatcher.off(\"connect\", submitVolunteerOp);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n\n this.subscribedTasks.delete(taskId);\n };\n\n this.abandonWatcher.on(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.on(\"disconnect\", disconnectHandler);\n this.completedWatcher.on(\"completed\", checkIfCompleted);\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x473 /* clientId should not be undefined */);\n this.addClientToQueue(taskId, this.clientId);\n // Because we volunteered with placeholderClientId, we need to wait for when we attach and are assigned\n // a real clientId. At that point we should re-enter the queue with a real volunteer op (assuming we are\n // connected).\n this.runtime.once(\"attached\", () => {\n if (this.queued(taskId)) {\n // If we are already queued, then we were able to replace the placeholderClientId with our real\n // clientId and no action is required.\n return;\n } else if (this.connected) {\n submitVolunteerOp();\n } else {\n this.connectionWatcher.once(\"connect\", () => {\n submitVolunteerOp();\n });\n }\n });\n } else if (!this.connected) {\n // If we are disconnected (and attached), wait to be connected and submit volunteer op\n disconnectHandler();\n } else if (!this.assigned(taskId) && !this.queued(taskId)) {\n submitVolunteerOp();\n }\n this.subscribedTasks.add(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.abandon}\n */\n public abandon(taskId: string) {\n // Always allow abandon if the client is subscribed to allow clients to unsubscribe while disconnected.\n // Otherwise, we should check to make sure the client is both connected queued for the task before sending an\n // abandon op.\n if (!this.subscribed(taskId) && !this.queued(taskId)) {\n // Nothing to do\n return;\n }\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x474 /* clientId is undefined */);\n this.removeClientFromQueue(taskId, this.clientId);\n this.abandonWatcher.emit(\"abandon\", taskId);\n return;\n }\n\n // If we're subscribed but not queued, we don't need to submit an abandon op (probably offline)\n if (this.queued(taskId)) {\n this.submitAbandonOp(taskId);\n }\n this.abandonWatcher.emit(\"abandon\", taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.assigned}\n */\n public assigned(taskId: string) {\n if (this.isAttached() && !this.connected) {\n return false;\n }\n\n const currentAssignee = this.taskQueues.get(taskId)?.[0];\n return currentAssignee !== undefined\n && currentAssignee === this.clientId\n && !this.latestPendingOps.has(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.queued}\n */\n public queued(taskId: string) {\n if (this.isAttached() && !this.connected) {\n return false;\n }\n\n assert(this.clientId !== undefined, 0x07f /* \"clientId undefined\" */);\n\n const clientQueue = this.taskQueues.get(taskId);\n // If we have no queue for the taskId, then no one has signed up for it.\n return (\n (clientQueue?.includes(this.clientId) ?? false)\n && !this.latestPendingOps.has(taskId)\n )\n || this.latestPendingOps.get(taskId)?.type === \"volunteer\";\n }\n\n /**\n * {@inheritDoc ITaskManager.subscribed}\n */\n public subscribed(taskId: string): boolean {\n return this.subscribedTasks.has(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.complete}\n */\n public complete(taskId: string): void {\n if (!this.assigned(taskId)) {\n throw new Error(\"Attempted to mark task as complete while not being assigned\");\n }\n\n // If we are detached we will simulate auto-ack for the complete op. Therefore we only need to send the op if\n // we are attached. Additionally, we don't need to check if we are connected while detached.\n if (this.isAttached()) {\n if (!this.connected) {\n throw new Error(\"Attempted to complete task in disconnected state\");\n }\n this.submitCompleteOp(taskId);\n }\n\n this.taskQueues.delete(taskId);\n this.completedWatcher.emit(\"completed\", taskId);\n this.emit(\"completed\", taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.canVolunteer}\n */\n public canVolunteer(): boolean {\n // A client can volunteer for a task if it's both connected to the delta stream and in write mode.\n // this.connected reflects that condition, but is unintuitive and may be changed in the future. This API allows\n // us to make changes to this.connected without affecting our guidance on how to check if a client is eligible\n // to volunteer for a task.\n return this.connected;\n }\n\n /**\n * Create a summary for the task manager\n *\n * @returns the summary of the current state of the task manager\n * @internal\n */\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n if (this.runtime.clientId !== undefined) {\n // If the runtime has been assigned an actual clientId by now, we can replace the placeholder clientIds\n // and maintain the task assignment.\n this.replacePlaceholderInAllQueues();\n } else {\n // If the runtime has still not been assigned a clientId, we should not summarize with the placeholder\n // clientIds and instead remove them from the queues and require the client to re-volunteer when assigned\n // a new clientId.\n this.removeClientFromAllQueues(placeholderClientId);\n }\n\n // Only include tasks if there are clients in the queue.\n const filteredMap = new Map<string, string[]>();\n this.taskQueues.forEach((queue: string[], taskId: string) => {\n if (queue.length > 0) {\n filteredMap.set(taskId, queue);\n }\n });\n const content = [...filteredMap.entries()];\n return createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<[string, string[]][]>(storage, snapshotFileName);\n content.forEach(([taskId, clientIdQueue]) => {\n this.taskQueues.set(taskId, clientIdQueue);\n });\n this.scrubClientsNotInQuorum();\n }\n\n /**\n * @internal\n */\n protected initializeLocalCore() { }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n * @internal\n */\n protected onDisconnect() {\n this.connectionWatcher.emit(\"disconnect\");\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n * @internal\n */\n protected onConnect() {\n this.connectionWatcher.emit(\"connect\");\n }\n\n //\n /**\n * Override resubmit core to avoid resubmission on reconnect. On disconnect we accept our removal from the\n * queues, and leave it up to the user to decide whether they want to attempt to re-enter a queue on reconnect.\n * @internal\n */\n protected reSubmitCore() { }\n\n /**\n * Process a task manager operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n * @internal\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op = message.contents as ITaskManagerOperation;\n const messageId = localOpMetadata as number;\n\n switch (op.type) {\n case \"volunteer\":\n this.opWatcher.emit(\"volunteer\", op.taskId, message.clientId, local, messageId);\n break;\n\n case \"abandon\":\n this.opWatcher.emit(\"abandon\", op.taskId, message.clientId, local, messageId);\n break;\n\n case \"complete\":\n this.opWatcher.emit(\"complete\", op.taskId, message.clientId, local, messageId);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n private addClientToQueue(taskId: string, clientId: string) {\n const pendingIds = this.pendingCompletedTasks.get(taskId);\n if (pendingIds !== undefined && pendingIds.length > 0) {\n // Ignore the volunteer op if we know this task is about to be completed\n return;\n }\n\n // Ensure that the clientId exists in the quorum, or it is placeholderClientId (detached scenario)\n if (this.runtime.getQuorum().getMembers().has(clientId) || this.clientId === placeholderClientId) {\n // Create the queue if it doesn't exist, and push the client on the back.\n let clientQueue = this.taskQueues.get(taskId);\n if (clientQueue === undefined) {\n clientQueue = [];\n this.taskQueues.set(taskId, clientQueue);\n }\n\n const oldLockHolder = clientQueue[0];\n clientQueue.push(clientId);\n const newLockHolder = clientQueue[0];\n if (newLockHolder !== oldLockHolder) {\n this.queueWatcher.emit(\"queueChange\", taskId, oldLockHolder, newLockHolder);\n }\n\n }\n }\n\n private removeClientFromQueue(taskId: string, clientId: string) {\n const clientQueue = this.taskQueues.get(taskId);\n if (clientQueue === undefined) {\n return;\n }\n\n const oldLockHolder = clientId === placeholderClientId ? placeholderClientId : clientQueue[0];\n const clientIdIndex = clientQueue.indexOf(clientId);\n if (clientIdIndex !== -1) {\n clientQueue.splice(clientIdIndex, 1);\n // Clean up the queue if there are no more clients in it.\n if (clientQueue.length === 0) {\n this.taskQueues.delete(taskId);\n }\n }\n const newLockHolder = clientQueue[0];\n if (newLockHolder !== oldLockHolder) {\n this.queueWatcher.emit(\"queueChange\", taskId, oldLockHolder, newLockHolder);\n }\n }\n\n private removeClientFromAllQueues(clientId: string) {\n for (const taskId of this.taskQueues.keys()) {\n this.removeClientFromQueue(taskId, clientId);\n }\n }\n\n /**\n * Will replace all instances of the placeholderClientId with the current clientId. This should only be called when\n * transitioning from detached to attached and this.runtime.clientId is defined.\n */\n private replacePlaceholderInAllQueues() {\n assert(this.runtime.clientId !== undefined, 0x475 /* this.runtime.clientId should be defined */);\n for (const clientQueue of this.taskQueues.values()) {\n const clientIdIndex = clientQueue.indexOf(placeholderClientId);\n if (clientIdIndex !== -1) {\n clientQueue[clientIdIndex] = this.runtime.clientId;\n }\n }\n }\n\n // This seems like it should be unnecessary if we can trust to receive the join/leave messages and\n // also have an accurate snapshot.\n private scrubClientsNotInQuorum() {\n const quorum = this.runtime.getQuorum();\n for (const [taskId, clientQueue] of this.taskQueues) {\n const filteredClientQueue = clientQueue.filter((clientId) => quorum.getMember(clientId) !== undefined);\n if (clientQueue.length !== filteredClientQueue.length) {\n if (filteredClientQueue.length === 0) {\n this.taskQueues.delete(taskId);\n } else {\n this.taskQueues.set(taskId, filteredClientQueue);\n }\n this.queueWatcher.emit(\"queueChange\", taskId);\n }\n }\n }\n\n public applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/task-manager";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-internal.2.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.2.3.1";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export const pkgName = "@fluidframework/task-manager";
|
|
8
|
-
export const pkgVersion = "2.0.0-internal.2.
|
|
8
|
+
export const pkgVersion = "2.0.0-internal.2.3.1";
|
|
9
9
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/task-manager\";\nexport const pkgVersion = \"2.0.0-internal.2.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/task-manager\";\nexport const pkgVersion = \"2.0.0-internal.2.3.1\";\n"]}
|
package/lib/taskManager.js
CHANGED
|
@@ -310,8 +310,8 @@ export class TaskManager extends SharedObject {
|
|
|
310
310
|
}
|
|
311
311
|
if (this.readOnlyInfo.readonly === true) {
|
|
312
312
|
const error = this.readOnlyInfo.permissions === true ?
|
|
313
|
-
new Error(
|
|
314
|
-
new Error(
|
|
313
|
+
new Error("Attempted to volunteer with read-only permissions") :
|
|
314
|
+
new Error("Attempted to volunteer in read-only state");
|
|
315
315
|
throw error;
|
|
316
316
|
}
|
|
317
317
|
if (!this.isAttached()) {
|
|
@@ -321,7 +321,7 @@ export class TaskManager extends SharedObject {
|
|
|
321
321
|
return true;
|
|
322
322
|
}
|
|
323
323
|
if (!this.connected) {
|
|
324
|
-
throw new Error(
|
|
324
|
+
throw new Error("Attempted to volunteer in disconnected state");
|
|
325
325
|
}
|
|
326
326
|
// This promise works even if we already have an outstanding volunteer op.
|
|
327
327
|
const lockAcquireP = new Promise((resolve, reject) => {
|
|
@@ -348,14 +348,14 @@ export class TaskManager extends SharedObject {
|
|
|
348
348
|
this.abandonWatcher.off("abandon", checkIfAbandoned);
|
|
349
349
|
this.connectionWatcher.off("disconnect", rejectOnDisconnect);
|
|
350
350
|
this.completedWatcher.off("completed", checkIfCompleted);
|
|
351
|
-
reject(new Error(
|
|
351
|
+
reject(new Error("Abandoned before acquiring task assignment"));
|
|
352
352
|
};
|
|
353
353
|
const rejectOnDisconnect = () => {
|
|
354
354
|
this.queueWatcher.off("queueChange", checkIfAcquiredLock);
|
|
355
355
|
this.abandonWatcher.off("abandon", checkIfAbandoned);
|
|
356
356
|
this.connectionWatcher.off("disconnect", rejectOnDisconnect);
|
|
357
357
|
this.completedWatcher.off("completed", checkIfCompleted);
|
|
358
|
-
reject(new Error(
|
|
358
|
+
reject(new Error("Disconnected before acquiring task assignment"));
|
|
359
359
|
};
|
|
360
360
|
const checkIfCompleted = (eventTaskId) => {
|
|
361
361
|
if (eventTaskId !== taskId) {
|
|
@@ -385,7 +385,7 @@ export class TaskManager extends SharedObject {
|
|
|
385
385
|
return;
|
|
386
386
|
}
|
|
387
387
|
if (this.readOnlyInfo.readonly === true && this.readOnlyInfo.permissions === true) {
|
|
388
|
-
throw new Error(
|
|
388
|
+
throw new Error("Attempted to subscribe with read-only permissions");
|
|
389
389
|
}
|
|
390
390
|
const submitVolunteerOp = () => {
|
|
391
391
|
this.submitVolunteerOp(taskId);
|
|
@@ -512,13 +512,13 @@ export class TaskManager extends SharedObject {
|
|
|
512
512
|
*/
|
|
513
513
|
complete(taskId) {
|
|
514
514
|
if (!this.assigned(taskId)) {
|
|
515
|
-
throw new Error(
|
|
515
|
+
throw new Error("Attempted to mark task as complete while not being assigned");
|
|
516
516
|
}
|
|
517
517
|
// If we are detached we will simulate auto-ack for the complete op. Therefore we only need to send the op if
|
|
518
518
|
// we are attached. Additionally, we don't need to check if we are connected while detached.
|
|
519
519
|
if (this.isAttached()) {
|
|
520
520
|
if (!this.connected) {
|
|
521
|
-
throw new Error(
|
|
521
|
+
throw new Error("Attempted to complete task in disconnected state");
|
|
522
522
|
}
|
|
523
523
|
this.submitCompleteOp(taskId);
|
|
524
524
|
}
|
package/lib/taskManager.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taskManager.js","sourceRoot":"","sources":["../src/taskManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAA6B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAQ9F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAoB,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAE7G,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA+B1D,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE;YAChD,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;YAC/D,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE;gBACtB,WAAW,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;aACtD;SACJ;IACL,CAAC;IAED,kGAAkG;IAClG,kCAAkC;IAC1B,uBAAuB;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE;YACjD,MAAM,mBAAmB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAC,CAAC;YACvG,IAAI,WAAW,CAAC,MAAM,KAAK,mBAAmB,CAAC,MAAM,EAAE;gBACnD,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC,EAAE;oBAClC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;iBAClC;qBAAM;oBACH,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;iBACpD;gBACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;aACjD;SACJ;IACL,CAAC;IAEM,cAAc;QACjB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ReadOnlyInfo } from \"@fluidframework/container-definitions\";\nimport { TaskManagerFactory } from \"./taskManagerFactory\";\nimport { ITaskManager, ITaskManagerEvents } from \"./interfaces\";\n\n/**\n * Description of a task manager operation\n */\ntype ITaskManagerOperation =\n ITaskManagerVolunteerOperation |\n ITaskManagerAbandonOperation |\n ITaskManagerCompletedOperation;\n\ninterface ITaskManagerVolunteerOperation {\n type: \"volunteer\";\n taskId: string;\n}\n\ninterface ITaskManagerAbandonOperation {\n type: \"abandon\";\n taskId: string;\n}\n\ninterface ITaskManagerCompletedOperation {\n type: \"complete\";\n taskId: string;\n}\n\ninterface IPendingOp {\n type: \"volunteer\" | \"abandon\" | \"complete\";\n messageId: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * Placeholder clientId for detached scenarios.\n */\nconst placeholderClientId = \"placeholder\";\n\n\n/**\n * The TaskManager distributed data structure tracks queues of clients that want to exclusively run a task.\n *\n * @remarks\n *\n * For an in-depth overview, see [TaskManager](https://fluidframework.com/docs/data-structures/task-manager/).\n *\n * ### Creation\n *\n * To create a `TaskManager`, call the static create method:\n *\n * ```typescript\n * const taskManager = TaskManager.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * To volunteer for a task, use the `volunteerForTask()` method. This returns a Promise that will resolve once the\n * client has acquired exclusive rights to run the task, or reject if the client is removed from the queue without\n * acquiring the rights.\n *\n * ```typescript\n * taskManager.volunteerForTask(\"NameOfTask\")\n * .then(() => { doTheTask(); })\n * .catch((err) => { console.error(err); });\n * ```\n *\n * Alternatively, you can indefinitely volunteer for a task with the synchronous `subscribeToTask()` method. This\n * method does not return a value, therefore you need to rely on eventing to know when you have acquired the rights\n * to run the task (see below).\n *\n * ```typescript\n * taskManager.subscribeToTask(\"NameOfTask\");\n * ```\n *\n * To check if the local client is currently subscribed to a task, use the `subscribed()` method.\n * ```typescript\n * if (taskManager.subscribed(\"NameOfTask\")) {\n * console.log(\"This client is currently subscribed to the task.\");\n * }\n * ```\n *\n * To release the rights to the task, use the `abandon()` method. The next client in the queue will then get the\n * rights to run the task.\n *\n * ```typescript\n * taskManager.abandon(\"NameOfTask\");\n * ```\n *\n * To inspect your state in the queue, you can use the `queued()` and `assigned()` methods.\n *\n * ```typescript\n * if (taskManager.queued(\"NameOfTask\")) {\n * console.log(\"This client is somewhere in the queue, potentially even having the task assignment.\");\n * }\n *\n * if (taskManager.assigned(\"NameOfTask\")) {\n * console.log(\"This client currently has the rights to run the task\");\n * }\n * ```\n *\n * To signal to other connected clients that a task is completed, use the `complete()` method. This will release all\n * clients from the queue and emit the \"completed\" event.\n *\n * ```typescript\n * taskManager.complete(\"NameOfTask\");\n * ```\n *\n * ### Eventing\n *\n * `TaskManager` is an `EventEmitter`, and will emit events when a task is assigned to the client, when the task\n * assignment is lost, and when a task was completed by another client.\n *\n * ```typescript\n * taskManager.on(\"assigned\", (taskId: string) => {\n * console.log(`Client was assigned task: ${taskId}`);\n * });\n *\n * taskManager.on(\"lost\", (taskId: string) => {\n * console.log(`Client released task: ${taskId}`);\n * });\n *\n * taskManager.on(\"completed\", (taskId: string) => {\n * console.log(`Another client completed task: ${taskId}`);\n * });\n * ```\n *\n * These can be useful if the logic to volunteer for a task is separated from the logic to perform the task, such as\n * when using the `subscribeToTask()` method.\n */\nexport class TaskManager extends SharedObject<ITaskManagerEvents> implements ITaskManager {\n /**\n * Create a new TaskManager\n *\n * @param runtime - data store runtime the new task queue belongs to\n * @param id - optional name of the task queue\n * @returns newly create task queue (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, TaskManagerFactory.Type) as TaskManager;\n }\n\n /**\n * Get a factory for TaskManager to register with the data store.\n *\n * @returns a factory that creates and load TaskManager\n */\n public static getFactory(): IChannelFactory {\n return new TaskManagerFactory();\n }\n\n /**\n * Mapping of taskId to a queue of clientIds that are waiting on the task. Maintains the consensus state of the\n * queue, even if we know we've submitted an op that should eventually modify the queue.\n */\n private readonly taskQueues: Map<string, string[]> = new Map();\n\n // opWatcher emits for every op on this data store. This is just a repackaging of processCore into events.\n private readonly opWatcher: EventEmitter = new EventEmitter();\n // queueWatcher emits an event whenever the consensus state of the task queues changes\n private readonly queueWatcher: EventEmitter = new EventEmitter();\n // abandonWatcher emits an event whenever the local client calls abandon() on a task.\n private readonly abandonWatcher: EventEmitter = new EventEmitter();\n // connectionWatcher emits an event whenever we get connected or disconnected.\n private readonly connectionWatcher: EventEmitter = new EventEmitter();\n // completedWatcher emits an event whenever the local client receives a completed op.\n private readonly completedWatcher: EventEmitter = new EventEmitter();\n\n private messageId: number = -1;\n /**\n * Tracks the most recent pending op for a given task\n */\n private readonly latestPendingOps: Map<string, IPendingOp> = new Map();\n\n /**\n * Tracks tasks that are this client is currently subscribed to.\n */\n private readonly subscribedTasks: Set<string> = new Set();\n\n /**\n * Map to track tasks that have pending complete ops.\n */\n private readonly pendingCompletedTasks: Map<string, number[]> = new Map();\n\n /**\n * Returns the clientId. Will return a placeholder if the runtime is detached and not yet assigned a clientId.\n */\n private get clientId(): string | undefined {\n return this.isAttached() ? this.runtime.clientId : placeholderClientId;\n }\n\n /**\n * Returns a ReadOnlyInfo object to determine current read/write permissions.\n */\n private get readOnlyInfo(): ReadOnlyInfo {\n return this.runtime.deltaManager.readOnlyInfo;\n }\n\n /**\n * Constructs a new task manager. If the object is non-local an id and service interfaces will\n * be provided\n *\n * @param runtime - data store runtime the task queue belongs to\n * @param id - optional name of the task queue\n */\n constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, \"fluid_taskManager_\");\n\n this.opWatcher.on(\"volunteer\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n // We're tracking local ops from this connection. Filter out local ops during \"connecting\"\n // state since these were sent on the prior connection and were already cleared from the latestPendingOps.\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x07b /* \"Unexpected op\" */);\n // Need to check the id, since it's possible to volunteer and abandon multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"volunteer\", 0x07c /* \"Unexpected op type\" */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n }\n\n this.addClientToQueue(taskId, clientId);\n });\n\n this.opWatcher.on(\"abandon\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x07d /* \"Unexpected op\" */);\n // Need to check the id, since it's possible to abandon and volunteer multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"abandon\", 0x07e /* \"Unexpected op type\" */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n }\n\n this.removeClientFromQueue(taskId, clientId);\n });\n\n this.opWatcher.on(\"complete\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x400 /* Unexpected op */);\n // Need to check the id, since it's possible to complete multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"complete\", 0x401 /* Unexpected op type */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n\n // Remove complete op from this.pendingCompletedTasks\n const pendingIds = this.pendingCompletedTasks.get(taskId);\n assert(pendingIds !== undefined && pendingIds.length > 0, 0x402 /* pendingIds is empty */);\n const removed = pendingIds.shift();\n assert(removed === messageId, 0x403 /* Removed complete op id does not match */);\n }\n\n // For clients in queue, we need to remove them from the queue and raise the proper events.\n if (!local) {\n this.taskQueues.delete(taskId);\n this.completedWatcher.emit(\"completed\", taskId);\n this.emit(\"completed\", taskId);\n }\n });\n\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n this.removeClientFromAllQueues(clientId);\n });\n\n this.queueWatcher.on(\"queueChange\", (taskId: string, oldLockHolder: string, newLockHolder: string) => {\n // If oldLockHolder is placeholderClientId we need to emit the task was lost during the attach process\n if (oldLockHolder === placeholderClientId) {\n this.emit(\"lost\", taskId);\n return;\n }\n\n // Exit early if we are still catching up on reconnect -- we can't be the leader yet anyway.\n if (this.clientId === undefined) {\n return;\n }\n\n if (oldLockHolder !== this.clientId && newLockHolder === this.clientId) {\n this.emit(\"assigned\", taskId);\n } else if (oldLockHolder === this.clientId && newLockHolder !== this.clientId) {\n this.emit(\"lost\", taskId);\n }\n });\n\n this.connectionWatcher.on(\"disconnect\", () => {\n assert(this.clientId !== undefined, 0x1d3 /* \"Missing client id on disconnect\" */);\n\n // We don't modify the taskQueues on disconnect (they still reflect the latest known consensus state).\n // After reconnect these will get cleaned up by observing the clientLeaves.\n // However we do need to recognize that we lost the lock if we had it. Calls to .queued() and\n // .assigned() are also connection-state-aware to be consistent.\n for (const [taskId, clientQueue] of this.taskQueues.entries()) {\n if (this.isAttached() && clientQueue[0] === this.clientId) {\n this.emit(\"lost\", taskId);\n }\n }\n\n // All of our outstanding ops will be for the old clientId even if they get ack'd\n this.latestPendingOps.clear();\n });\n }\n\n private submitVolunteerOp(taskId: string) {\n const op: ITaskManagerVolunteerOperation = {\n type: \"volunteer\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"volunteer\",\n messageId: ++this.messageId,\n };\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n private submitAbandonOp(taskId: string) {\n const op: ITaskManagerAbandonOperation = {\n type: \"abandon\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"abandon\",\n messageId: ++this.messageId,\n };\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n private submitCompleteOp(taskId: string) {\n const op: ITaskManagerCompletedOperation = {\n type: \"complete\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"complete\",\n messageId: ++this.messageId,\n };\n\n if (this.pendingCompletedTasks.has(taskId)) {\n this.pendingCompletedTasks.get(taskId)?.push(pendingOp.messageId);\n } else {\n this.pendingCompletedTasks.set(taskId, [pendingOp.messageId]);\n }\n\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n /**\n * {@inheritDoc ITaskManager.volunteerForTask}\n */\n public async volunteerForTask(taskId: string) {\n // If we have the lock, resolve immediately\n if (this.assigned(taskId)) {\n return true;\n }\n\n if (this.readOnlyInfo.readonly === true) {\n const error = this.readOnlyInfo.permissions === true ?\n new Error(`Attempted to volunteer with read-only permissions: ${taskId}`) :\n new Error(`Attempted to volunteer in read-only state: ${taskId}`);\n throw error;\n }\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x472 /* clientId should not be undefined */);\n this.addClientToQueue(taskId, this.clientId);\n return true;\n }\n\n if (!this.connected) {\n throw new Error(`Attempted to volunteer in disconnected state: ${taskId}`);\n }\n\n // This promise works even if we already have an outstanding volunteer op.\n const lockAcquireP = new Promise<boolean>((resolve, reject) => {\n const checkIfAcquiredLock = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n // Also check pending ops here because it's possible we are currently in the queue from a previous\n // lock attempt, but have an outstanding abandon AND the outstanding volunteer for this lock attempt.\n // If we reach the head of the queue based on the previous lock attempt, we don't want to resolve.\n if (this.assigned(taskId) && !this.latestPendingOps.has(taskId)) {\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n resolve(true);\n }\n };\n\n const checkIfAbandoned = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n reject(new Error(`Abandoned before acquiring task assignment: ${taskId}`));\n };\n\n const rejectOnDisconnect = () => {\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n reject(new Error(`Disconnected before acquiring task assignment: ${taskId}`));\n };\n\n const checkIfCompleted = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n resolve(false);\n };\n\n this.queueWatcher.on(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.on(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.on(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.on(\"completed\", checkIfCompleted);\n });\n\n if (!this.queued(taskId)) {\n this.submitVolunteerOp(taskId);\n }\n return lockAcquireP;\n }\n\n /**\n * {@inheritDoc ITaskManager.subscribeToTask}\n */\n public subscribeToTask(taskId: string) {\n if (this.subscribed(taskId)) {\n return;\n }\n\n if (this.readOnlyInfo.readonly === true && this.readOnlyInfo.permissions === true) {\n throw new Error(`Attempted to subscribe with read-only permissions: ${taskId}`);\n }\n\n const submitVolunteerOp = () => {\n this.submitVolunteerOp(taskId);\n };\n\n const disconnectHandler = () => {\n // Wait to be connected again and then re-submit volunteer op\n this.connectionWatcher.once(\"connect\", submitVolunteerOp);\n };\n\n const checkIfAbandoned = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", disconnectHandler);\n this.connectionWatcher.off(\"connect\", submitVolunteerOp);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n\n this.subscribedTasks.delete(taskId);\n };\n\n const checkIfCompleted = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", disconnectHandler);\n this.connectionWatcher.off(\"connect\", submitVolunteerOp);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n\n this.subscribedTasks.delete(taskId);\n };\n\n this.abandonWatcher.on(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.on(\"disconnect\", disconnectHandler);\n this.completedWatcher.on(\"completed\", checkIfCompleted);\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x473 /* clientId should not be undefined */);\n this.addClientToQueue(taskId, this.clientId);\n // Because we volunteered with placeholderClientId, we need to wait for when we attach and are assigned\n // a real clientId. At that point we should re-enter the queue with a real volunteer op (assuming we are\n // connected).\n this.runtime.once(\"attached\", () => {\n if (this.queued(taskId)) {\n // If we are already queued, then we were able to replace the placeholderClientId with our real\n // clientId and no action is required.\n return;\n } else if (this.connected) {\n submitVolunteerOp();\n } else {\n this.connectionWatcher.once(\"connect\", () => {\n submitVolunteerOp();\n });\n }\n });\n } else if (!this.connected) {\n // If we are disconnected (and attached), wait to be connected and submit volunteer op\n disconnectHandler();\n } else if (!this.assigned(taskId) && !this.queued(taskId)) {\n submitVolunteerOp();\n }\n this.subscribedTasks.add(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.abandon}\n */\n public abandon(taskId: string) {\n // Always allow abandon if the client is subscribed to allow clients to unsubscribe while disconnected.\n // Otherwise, we should check to make sure the client is both connected queued for the task before sending an\n // abandon op.\n if (!this.subscribed(taskId) && !this.queued(taskId)) {\n // Nothing to do\n return;\n }\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x474 /* clientId is undefined */);\n this.removeClientFromQueue(taskId, this.clientId);\n this.abandonWatcher.emit(\"abandon\", taskId);\n return;\n }\n\n // If we're subscribed but not queued, we don't need to submit an abandon op (probably offline)\n if (this.queued(taskId)) {\n this.submitAbandonOp(taskId);\n }\n this.abandonWatcher.emit(\"abandon\", taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.assigned}\n */\n public assigned(taskId: string) {\n if (this.isAttached() && !this.connected) {\n return false;\n }\n\n const currentAssignee = this.taskQueues.get(taskId)?.[0];\n return currentAssignee !== undefined\n && currentAssignee === this.clientId\n && !this.latestPendingOps.has(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.queued}\n */\n public queued(taskId: string) {\n if (this.isAttached() && !this.connected) {\n return false;\n }\n\n assert(this.clientId !== undefined, 0x07f /* \"clientId undefined\" */);\n\n const clientQueue = this.taskQueues.get(taskId);\n // If we have no queue for the taskId, then no one has signed up for it.\n return (\n (clientQueue?.includes(this.clientId) ?? false)\n && !this.latestPendingOps.has(taskId)\n )\n || this.latestPendingOps.get(taskId)?.type === \"volunteer\";\n }\n\n /**\n * {@inheritDoc ITaskManager.subscribed}\n */\n public subscribed(taskId: string): boolean {\n return this.subscribedTasks.has(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.complete}\n */\n public complete(taskId: string): void {\n if (!this.assigned(taskId)) {\n throw new Error(`Attempted to mark task as complete while not being assigned: ${taskId}`);\n }\n\n // If we are detached we will simulate auto-ack for the complete op. Therefore we only need to send the op if\n // we are attached. Additionally, we don't need to check if we are connected while detached.\n if (this.isAttached()) {\n if (!this.connected) {\n throw new Error(`Attempted to complete task in disconnected state: ${taskId}`);\n }\n this.submitCompleteOp(taskId);\n }\n\n this.taskQueues.delete(taskId);\n this.completedWatcher.emit(\"completed\", taskId);\n this.emit(\"completed\", taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.canVolunteer}\n */\n public canVolunteer(): boolean {\n // A client can volunteer for a task if it's both connected to the delta stream and in write mode.\n // this.connected reflects that condition, but is unintuitive and may be changed in the future. This API allows\n // us to make changes to this.connected without affecting our guidance on how to check if a client is eligible\n // to volunteer for a task.\n return this.connected;\n }\n\n /**\n * Create a summary for the task manager\n *\n * @returns the summary of the current state of the task manager\n * @internal\n */\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n if (this.runtime.clientId !== undefined) {\n // If the runtime has been assigned an actual clientId by now, we can replace the placeholder clientIds\n // and maintain the task assignment.\n this.replacePlaceholderInAllQueues();\n } else {\n // If the runtime has still not been assigned a clientId, we should not summarize with the placeholder\n // clientIds and instead remove them from the queues and require the client to re-volunteer when assigned\n // a new clientId.\n this.removeClientFromAllQueues(placeholderClientId);\n }\n\n // Only include tasks if there are clients in the queue.\n const filteredMap = new Map<string, string[]>();\n this.taskQueues.forEach((queue: string[], taskId: string) => {\n if (queue.length > 0) {\n filteredMap.set(taskId, queue);\n }\n });\n const content = [...filteredMap.entries()];\n return createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<[string, string[]][]>(storage, snapshotFileName);\n content.forEach(([taskId, clientIdQueue]) => {\n this.taskQueues.set(taskId, clientIdQueue);\n });\n this.scrubClientsNotInQuorum();\n }\n\n /**\n * @internal\n */\n protected initializeLocalCore() { }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n * @internal\n */\n protected onDisconnect() {\n this.connectionWatcher.emit(\"disconnect\");\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n * @internal\n */\n protected onConnect() {\n this.connectionWatcher.emit(\"connect\");\n }\n\n //\n /**\n * Override resubmit core to avoid resubmission on reconnect. On disconnect we accept our removal from the\n * queues, and leave it up to the user to decide whether they want to attempt to re-enter a queue on reconnect.\n * @internal\n */\n protected reSubmitCore() { }\n\n /**\n * Process a task manager operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n * @internal\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op = message.contents as ITaskManagerOperation;\n const messageId = localOpMetadata as number;\n\n switch (op.type) {\n case \"volunteer\":\n this.opWatcher.emit(\"volunteer\", op.taskId, message.clientId, local, messageId);\n break;\n\n case \"abandon\":\n this.opWatcher.emit(\"abandon\", op.taskId, message.clientId, local, messageId);\n break;\n\n case \"complete\":\n this.opWatcher.emit(\"complete\", op.taskId, message.clientId, local, messageId);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n private addClientToQueue(taskId: string, clientId: string) {\n const pendingIds = this.pendingCompletedTasks.get(taskId);\n if (pendingIds !== undefined && pendingIds.length > 0) {\n // Ignore the volunteer op if we know this task is about to be completed\n return;\n }\n\n // Ensure that the clientId exists in the quorum, or it is placeholderClientId (detached scenario)\n if (this.runtime.getQuorum().getMembers().has(clientId) || this.clientId === placeholderClientId) {\n // Create the queue if it doesn't exist, and push the client on the back.\n let clientQueue = this.taskQueues.get(taskId);\n if (clientQueue === undefined) {\n clientQueue = [];\n this.taskQueues.set(taskId, clientQueue);\n }\n\n const oldLockHolder = clientQueue[0];\n clientQueue.push(clientId);\n const newLockHolder = clientQueue[0];\n if (newLockHolder !== oldLockHolder) {\n this.queueWatcher.emit(\"queueChange\", taskId, oldLockHolder, newLockHolder);\n }\n\n }\n }\n\n private removeClientFromQueue(taskId: string, clientId: string) {\n const clientQueue = this.taskQueues.get(taskId);\n if (clientQueue === undefined) {\n return;\n }\n\n const oldLockHolder = clientId === placeholderClientId ? placeholderClientId : clientQueue[0];\n const clientIdIndex = clientQueue.indexOf(clientId);\n if (clientIdIndex !== -1) {\n clientQueue.splice(clientIdIndex, 1);\n // Clean up the queue if there are no more clients in it.\n if (clientQueue.length === 0) {\n this.taskQueues.delete(taskId);\n }\n }\n const newLockHolder = clientQueue[0];\n if (newLockHolder !== oldLockHolder) {\n this.queueWatcher.emit(\"queueChange\", taskId, oldLockHolder, newLockHolder);\n }\n }\n\n private removeClientFromAllQueues(clientId: string) {\n for (const taskId of this.taskQueues.keys()) {\n this.removeClientFromQueue(taskId, clientId);\n }\n }\n\n /**\n * Will replace all instances of the placeholderClientId with the current clientId. This should only be called when\n * transitioning from detached to attached and this.runtime.clientId is defined.\n */\n private replacePlaceholderInAllQueues() {\n assert(this.runtime.clientId !== undefined, 0x475 /* this.runtime.clientId should be defined */);\n for (const clientQueue of this.taskQueues.values()) {\n const clientIdIndex = clientQueue.indexOf(placeholderClientId);\n if (clientIdIndex !== -1) {\n clientQueue[clientIdIndex] = this.runtime.clientId;\n }\n }\n }\n\n // This seems like it should be unnecessary if we can trust to receive the join/leave messages and\n // also have an accurate snapshot.\n private scrubClientsNotInQuorum() {\n const quorum = this.runtime.getQuorum();\n for (const [taskId, clientQueue] of this.taskQueues) {\n const filteredClientQueue = clientQueue.filter((clientId) => quorum.getMember(clientId) !== undefined);\n if (clientQueue.length !== filteredClientQueue.length) {\n if (filteredClientQueue.length === 0) {\n this.taskQueues.delete(taskId);\n } else {\n this.taskQueues.set(taskId, filteredClientQueue);\n }\n this.queueWatcher.emit(\"queueChange\", taskId);\n }\n }\n }\n\n public applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"taskManager.js","sourceRoot":"","sources":["../src/taskManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAA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C,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;aACjD;SACJ;IACL,CAAC;IAEM,cAAc;QACjB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { createSingleBlobSummary, IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ReadOnlyInfo } from \"@fluidframework/container-definitions\";\nimport { TaskManagerFactory } from \"./taskManagerFactory\";\nimport { ITaskManager, ITaskManagerEvents } from \"./interfaces\";\n\n/**\n * Description of a task manager operation\n */\ntype ITaskManagerOperation =\n ITaskManagerVolunteerOperation |\n ITaskManagerAbandonOperation |\n ITaskManagerCompletedOperation;\n\ninterface ITaskManagerVolunteerOperation {\n type: \"volunteer\";\n taskId: string;\n}\n\ninterface ITaskManagerAbandonOperation {\n type: \"abandon\";\n taskId: string;\n}\n\ninterface ITaskManagerCompletedOperation {\n type: \"complete\";\n taskId: string;\n}\n\ninterface IPendingOp {\n type: \"volunteer\" | \"abandon\" | \"complete\";\n messageId: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * Placeholder clientId for detached scenarios.\n */\nconst placeholderClientId = \"placeholder\";\n\n\n/**\n * The TaskManager distributed data structure tracks queues of clients that want to exclusively run a task.\n *\n * @remarks\n *\n * For an in-depth overview, see [TaskManager](https://fluidframework.com/docs/data-structures/task-manager/).\n *\n * ### Creation\n *\n * To create a `TaskManager`, call the static create method:\n *\n * ```typescript\n * const taskManager = TaskManager.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * To volunteer for a task, use the `volunteerForTask()` method. This returns a Promise that will resolve once the\n * client has acquired exclusive rights to run the task, or reject if the client is removed from the queue without\n * acquiring the rights.\n *\n * ```typescript\n * taskManager.volunteerForTask(\"NameOfTask\")\n * .then(() => { doTheTask(); })\n * .catch((err) => { console.error(err); });\n * ```\n *\n * Alternatively, you can indefinitely volunteer for a task with the synchronous `subscribeToTask()` method. This\n * method does not return a value, therefore you need to rely on eventing to know when you have acquired the rights\n * to run the task (see below).\n *\n * ```typescript\n * taskManager.subscribeToTask(\"NameOfTask\");\n * ```\n *\n * To check if the local client is currently subscribed to a task, use the `subscribed()` method.\n * ```typescript\n * if (taskManager.subscribed(\"NameOfTask\")) {\n * console.log(\"This client is currently subscribed to the task.\");\n * }\n * ```\n *\n * To release the rights to the task, use the `abandon()` method. The next client in the queue will then get the\n * rights to run the task.\n *\n * ```typescript\n * taskManager.abandon(\"NameOfTask\");\n * ```\n *\n * To inspect your state in the queue, you can use the `queued()` and `assigned()` methods.\n *\n * ```typescript\n * if (taskManager.queued(\"NameOfTask\")) {\n * console.log(\"This client is somewhere in the queue, potentially even having the task assignment.\");\n * }\n *\n * if (taskManager.assigned(\"NameOfTask\")) {\n * console.log(\"This client currently has the rights to run the task\");\n * }\n * ```\n *\n * To signal to other connected clients that a task is completed, use the `complete()` method. This will release all\n * clients from the queue and emit the \"completed\" event.\n *\n * ```typescript\n * taskManager.complete(\"NameOfTask\");\n * ```\n *\n * ### Eventing\n *\n * `TaskManager` is an `EventEmitter`, and will emit events when a task is assigned to the client, when the task\n * assignment is lost, and when a task was completed by another client.\n *\n * ```typescript\n * taskManager.on(\"assigned\", (taskId: string) => {\n * console.log(`Client was assigned task: ${taskId}`);\n * });\n *\n * taskManager.on(\"lost\", (taskId: string) => {\n * console.log(`Client released task: ${taskId}`);\n * });\n *\n * taskManager.on(\"completed\", (taskId: string) => {\n * console.log(`Another client completed task: ${taskId}`);\n * });\n * ```\n *\n * These can be useful if the logic to volunteer for a task is separated from the logic to perform the task, such as\n * when using the `subscribeToTask()` method.\n */\nexport class TaskManager extends SharedObject<ITaskManagerEvents> implements ITaskManager {\n /**\n * Create a new TaskManager\n *\n * @param runtime - data store runtime the new task queue belongs to\n * @param id - optional name of the task queue\n * @returns newly create task queue (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, TaskManagerFactory.Type) as TaskManager;\n }\n\n /**\n * Get a factory for TaskManager to register with the data store.\n *\n * @returns a factory that creates and load TaskManager\n */\n public static getFactory(): IChannelFactory {\n return new TaskManagerFactory();\n }\n\n /**\n * Mapping of taskId to a queue of clientIds that are waiting on the task. Maintains the consensus state of the\n * queue, even if we know we've submitted an op that should eventually modify the queue.\n */\n private readonly taskQueues: Map<string, string[]> = new Map();\n\n // opWatcher emits for every op on this data store. This is just a repackaging of processCore into events.\n private readonly opWatcher: EventEmitter = new EventEmitter();\n // queueWatcher emits an event whenever the consensus state of the task queues changes\n private readonly queueWatcher: EventEmitter = new EventEmitter();\n // abandonWatcher emits an event whenever the local client calls abandon() on a task.\n private readonly abandonWatcher: EventEmitter = new EventEmitter();\n // connectionWatcher emits an event whenever we get connected or disconnected.\n private readonly connectionWatcher: EventEmitter = new EventEmitter();\n // completedWatcher emits an event whenever the local client receives a completed op.\n private readonly completedWatcher: EventEmitter = new EventEmitter();\n\n private messageId: number = -1;\n /**\n * Tracks the most recent pending op for a given task\n */\n private readonly latestPendingOps: Map<string, IPendingOp> = new Map();\n\n /**\n * Tracks tasks that are this client is currently subscribed to.\n */\n private readonly subscribedTasks: Set<string> = new Set();\n\n /**\n * Map to track tasks that have pending complete ops.\n */\n private readonly pendingCompletedTasks: Map<string, number[]> = new Map();\n\n /**\n * Returns the clientId. Will return a placeholder if the runtime is detached and not yet assigned a clientId.\n */\n private get clientId(): string | undefined {\n return this.isAttached() ? this.runtime.clientId : placeholderClientId;\n }\n\n /**\n * Returns a ReadOnlyInfo object to determine current read/write permissions.\n */\n private get readOnlyInfo(): ReadOnlyInfo {\n return this.runtime.deltaManager.readOnlyInfo;\n }\n\n /**\n * Constructs a new task manager. If the object is non-local an id and service interfaces will\n * be provided\n *\n * @param runtime - data store runtime the task queue belongs to\n * @param id - optional name of the task queue\n */\n constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes) {\n super(id, runtime, attributes, \"fluid_taskManager_\");\n\n this.opWatcher.on(\"volunteer\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n // We're tracking local ops from this connection. Filter out local ops during \"connecting\"\n // state since these were sent on the prior connection and were already cleared from the latestPendingOps.\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x07b /* \"Unexpected op\" */);\n // Need to check the id, since it's possible to volunteer and abandon multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"volunteer\", 0x07c /* \"Unexpected op type\" */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n }\n\n this.addClientToQueue(taskId, clientId);\n });\n\n this.opWatcher.on(\"abandon\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x07d /* \"Unexpected op\" */);\n // Need to check the id, since it's possible to abandon and volunteer multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"abandon\", 0x07e /* \"Unexpected op type\" */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n }\n\n this.removeClientFromQueue(taskId, clientId);\n });\n\n this.opWatcher.on(\"complete\", (taskId: string, clientId: string, local: boolean, messageId: number) => {\n if (runtime.connected && local) {\n const pendingOp = this.latestPendingOps.get(taskId);\n assert(pendingOp !== undefined, 0x400 /* Unexpected op */);\n // Need to check the id, since it's possible to complete multiple times before the acks\n if (messageId === pendingOp.messageId) {\n assert(pendingOp.type === \"complete\", 0x401 /* Unexpected op type */);\n // Delete the pending, because we no longer have an outstanding op\n this.latestPendingOps.delete(taskId);\n }\n\n // Remove complete op from this.pendingCompletedTasks\n const pendingIds = this.pendingCompletedTasks.get(taskId);\n assert(pendingIds !== undefined && pendingIds.length > 0, 0x402 /* pendingIds is empty */);\n const removed = pendingIds.shift();\n assert(removed === messageId, 0x403 /* Removed complete op id does not match */);\n }\n\n // For clients in queue, we need to remove them from the queue and raise the proper events.\n if (!local) {\n this.taskQueues.delete(taskId);\n this.completedWatcher.emit(\"completed\", taskId);\n this.emit(\"completed\", taskId);\n }\n });\n\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n this.removeClientFromAllQueues(clientId);\n });\n\n this.queueWatcher.on(\"queueChange\", (taskId: string, oldLockHolder: string, newLockHolder: string) => {\n // If oldLockHolder is placeholderClientId we need to emit the task was lost during the attach process\n if (oldLockHolder === placeholderClientId) {\n this.emit(\"lost\", taskId);\n return;\n }\n\n // Exit early if we are still catching up on reconnect -- we can't be the leader yet anyway.\n if (this.clientId === undefined) {\n return;\n }\n\n if (oldLockHolder !== this.clientId && newLockHolder === this.clientId) {\n this.emit(\"assigned\", taskId);\n } else if (oldLockHolder === this.clientId && newLockHolder !== this.clientId) {\n this.emit(\"lost\", taskId);\n }\n });\n\n this.connectionWatcher.on(\"disconnect\", () => {\n assert(this.clientId !== undefined, 0x1d3 /* \"Missing client id on disconnect\" */);\n\n // We don't modify the taskQueues on disconnect (they still reflect the latest known consensus state).\n // After reconnect these will get cleaned up by observing the clientLeaves.\n // However we do need to recognize that we lost the lock if we had it. Calls to .queued() and\n // .assigned() are also connection-state-aware to be consistent.\n for (const [taskId, clientQueue] of this.taskQueues.entries()) {\n if (this.isAttached() && clientQueue[0] === this.clientId) {\n this.emit(\"lost\", taskId);\n }\n }\n\n // All of our outstanding ops will be for the old clientId even if they get ack'd\n this.latestPendingOps.clear();\n });\n }\n\n private submitVolunteerOp(taskId: string) {\n const op: ITaskManagerVolunteerOperation = {\n type: \"volunteer\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"volunteer\",\n messageId: ++this.messageId,\n };\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n private submitAbandonOp(taskId: string) {\n const op: ITaskManagerAbandonOperation = {\n type: \"abandon\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"abandon\",\n messageId: ++this.messageId,\n };\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n private submitCompleteOp(taskId: string) {\n const op: ITaskManagerCompletedOperation = {\n type: \"complete\",\n taskId,\n };\n const pendingOp: IPendingOp = {\n type: \"complete\",\n messageId: ++this.messageId,\n };\n\n if (this.pendingCompletedTasks.has(taskId)) {\n this.pendingCompletedTasks.get(taskId)?.push(pendingOp.messageId);\n } else {\n this.pendingCompletedTasks.set(taskId, [pendingOp.messageId]);\n }\n\n this.submitLocalMessage(op, pendingOp.messageId);\n this.latestPendingOps.set(taskId, pendingOp);\n }\n\n /**\n * {@inheritDoc ITaskManager.volunteerForTask}\n */\n public async volunteerForTask(taskId: string) {\n // If we have the lock, resolve immediately\n if (this.assigned(taskId)) {\n return true;\n }\n\n if (this.readOnlyInfo.readonly === true) {\n const error = this.readOnlyInfo.permissions === true ?\n new Error(\"Attempted to volunteer with read-only permissions\") :\n new Error(\"Attempted to volunteer in read-only state\");\n throw error;\n }\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x472 /* clientId should not be undefined */);\n this.addClientToQueue(taskId, this.clientId);\n return true;\n }\n\n if (!this.connected) {\n throw new Error(\"Attempted to volunteer in disconnected state\");\n }\n\n // This promise works even if we already have an outstanding volunteer op.\n const lockAcquireP = new Promise<boolean>((resolve, reject) => {\n const checkIfAcquiredLock = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n // Also check pending ops here because it's possible we are currently in the queue from a previous\n // lock attempt, but have an outstanding abandon AND the outstanding volunteer for this lock attempt.\n // If we reach the head of the queue based on the previous lock attempt, we don't want to resolve.\n if (this.assigned(taskId) && !this.latestPendingOps.has(taskId)) {\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n resolve(true);\n }\n };\n\n const checkIfAbandoned = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n reject(new Error(\"Abandoned before acquiring task assignment\"));\n };\n\n const rejectOnDisconnect = () => {\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n reject(new Error(\"Disconnected before acquiring task assignment\"));\n };\n\n const checkIfCompleted = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.queueWatcher.off(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n resolve(false);\n };\n\n this.queueWatcher.on(\"queueChange\", checkIfAcquiredLock);\n this.abandonWatcher.on(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.on(\"disconnect\", rejectOnDisconnect);\n this.completedWatcher.on(\"completed\", checkIfCompleted);\n });\n\n if (!this.queued(taskId)) {\n this.submitVolunteerOp(taskId);\n }\n return lockAcquireP;\n }\n\n /**\n * {@inheritDoc ITaskManager.subscribeToTask}\n */\n public subscribeToTask(taskId: string) {\n if (this.subscribed(taskId)) {\n return;\n }\n\n if (this.readOnlyInfo.readonly === true && this.readOnlyInfo.permissions === true) {\n throw new Error(\"Attempted to subscribe with read-only permissions\");\n }\n\n const submitVolunteerOp = () => {\n this.submitVolunteerOp(taskId);\n };\n\n const disconnectHandler = () => {\n // Wait to be connected again and then re-submit volunteer op\n this.connectionWatcher.once(\"connect\", submitVolunteerOp);\n };\n\n const checkIfAbandoned = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", disconnectHandler);\n this.connectionWatcher.off(\"connect\", submitVolunteerOp);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n\n this.subscribedTasks.delete(taskId);\n };\n\n const checkIfCompleted = (eventTaskId: string) => {\n if (eventTaskId !== taskId) {\n return;\n }\n\n this.abandonWatcher.off(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.off(\"disconnect\", disconnectHandler);\n this.connectionWatcher.off(\"connect\", submitVolunteerOp);\n this.completedWatcher.off(\"completed\", checkIfCompleted);\n\n this.subscribedTasks.delete(taskId);\n };\n\n this.abandonWatcher.on(\"abandon\", checkIfAbandoned);\n this.connectionWatcher.on(\"disconnect\", disconnectHandler);\n this.completedWatcher.on(\"completed\", checkIfCompleted);\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x473 /* clientId should not be undefined */);\n this.addClientToQueue(taskId, this.clientId);\n // Because we volunteered with placeholderClientId, we need to wait for when we attach and are assigned\n // a real clientId. At that point we should re-enter the queue with a real volunteer op (assuming we are\n // connected).\n this.runtime.once(\"attached\", () => {\n if (this.queued(taskId)) {\n // If we are already queued, then we were able to replace the placeholderClientId with our real\n // clientId and no action is required.\n return;\n } else if (this.connected) {\n submitVolunteerOp();\n } else {\n this.connectionWatcher.once(\"connect\", () => {\n submitVolunteerOp();\n });\n }\n });\n } else if (!this.connected) {\n // If we are disconnected (and attached), wait to be connected and submit volunteer op\n disconnectHandler();\n } else if (!this.assigned(taskId) && !this.queued(taskId)) {\n submitVolunteerOp();\n }\n this.subscribedTasks.add(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.abandon}\n */\n public abandon(taskId: string) {\n // Always allow abandon if the client is subscribed to allow clients to unsubscribe while disconnected.\n // Otherwise, we should check to make sure the client is both connected queued for the task before sending an\n // abandon op.\n if (!this.subscribed(taskId) && !this.queued(taskId)) {\n // Nothing to do\n return;\n }\n\n if (!this.isAttached()) {\n // Simulate auto-ack in detached scenario\n assert(this.clientId !== undefined, 0x474 /* clientId is undefined */);\n this.removeClientFromQueue(taskId, this.clientId);\n this.abandonWatcher.emit(\"abandon\", taskId);\n return;\n }\n\n // If we're subscribed but not queued, we don't need to submit an abandon op (probably offline)\n if (this.queued(taskId)) {\n this.submitAbandonOp(taskId);\n }\n this.abandonWatcher.emit(\"abandon\", taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.assigned}\n */\n public assigned(taskId: string) {\n if (this.isAttached() && !this.connected) {\n return false;\n }\n\n const currentAssignee = this.taskQueues.get(taskId)?.[0];\n return currentAssignee !== undefined\n && currentAssignee === this.clientId\n && !this.latestPendingOps.has(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.queued}\n */\n public queued(taskId: string) {\n if (this.isAttached() && !this.connected) {\n return false;\n }\n\n assert(this.clientId !== undefined, 0x07f /* \"clientId undefined\" */);\n\n const clientQueue = this.taskQueues.get(taskId);\n // If we have no queue for the taskId, then no one has signed up for it.\n return (\n (clientQueue?.includes(this.clientId) ?? false)\n && !this.latestPendingOps.has(taskId)\n )\n || this.latestPendingOps.get(taskId)?.type === \"volunteer\";\n }\n\n /**\n * {@inheritDoc ITaskManager.subscribed}\n */\n public subscribed(taskId: string): boolean {\n return this.subscribedTasks.has(taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.complete}\n */\n public complete(taskId: string): void {\n if (!this.assigned(taskId)) {\n throw new Error(\"Attempted to mark task as complete while not being assigned\");\n }\n\n // If we are detached we will simulate auto-ack for the complete op. Therefore we only need to send the op if\n // we are attached. Additionally, we don't need to check if we are connected while detached.\n if (this.isAttached()) {\n if (!this.connected) {\n throw new Error(\"Attempted to complete task in disconnected state\");\n }\n this.submitCompleteOp(taskId);\n }\n\n this.taskQueues.delete(taskId);\n this.completedWatcher.emit(\"completed\", taskId);\n this.emit(\"completed\", taskId);\n }\n\n /**\n * {@inheritDoc ITaskManager.canVolunteer}\n */\n public canVolunteer(): boolean {\n // A client can volunteer for a task if it's both connected to the delta stream and in write mode.\n // this.connected reflects that condition, but is unintuitive and may be changed in the future. This API allows\n // us to make changes to this.connected without affecting our guidance on how to check if a client is eligible\n // to volunteer for a task.\n return this.connected;\n }\n\n /**\n * Create a summary for the task manager\n *\n * @returns the summary of the current state of the task manager\n * @internal\n */\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n if (this.runtime.clientId !== undefined) {\n // If the runtime has been assigned an actual clientId by now, we can replace the placeholder clientIds\n // and maintain the task assignment.\n this.replacePlaceholderInAllQueues();\n } else {\n // If the runtime has still not been assigned a clientId, we should not summarize with the placeholder\n // clientIds and instead remove them from the queues and require the client to re-volunteer when assigned\n // a new clientId.\n this.removeClientFromAllQueues(placeholderClientId);\n }\n\n // Only include tasks if there are clients in the queue.\n const filteredMap = new Map<string, string[]>();\n this.taskQueues.forEach((queue: string[], taskId: string) => {\n if (queue.length > 0) {\n filteredMap.set(taskId, queue);\n }\n });\n const content = [...filteredMap.entries()];\n return createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<[string, string[]][]>(storage, snapshotFileName);\n content.forEach(([taskId, clientIdQueue]) => {\n this.taskQueues.set(taskId, clientIdQueue);\n });\n this.scrubClientsNotInQuorum();\n }\n\n /**\n * @internal\n */\n protected initializeLocalCore() { }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}\n * @internal\n */\n protected onDisconnect() {\n this.connectionWatcher.emit(\"disconnect\");\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onConnect}\n * @internal\n */\n protected onConnect() {\n this.connectionWatcher.emit(\"connect\");\n }\n\n //\n /**\n * Override resubmit core to avoid resubmission on reconnect. On disconnect we accept our removal from the\n * queues, and leave it up to the user to decide whether they want to attempt to re-enter a queue on reconnect.\n * @internal\n */\n protected reSubmitCore() { }\n\n /**\n * Process a task manager operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n * @internal\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op = message.contents as ITaskManagerOperation;\n const messageId = localOpMetadata as number;\n\n switch (op.type) {\n case \"volunteer\":\n this.opWatcher.emit(\"volunteer\", op.taskId, message.clientId, local, messageId);\n break;\n\n case \"abandon\":\n this.opWatcher.emit(\"abandon\", op.taskId, message.clientId, local, messageId);\n break;\n\n case \"complete\":\n this.opWatcher.emit(\"complete\", op.taskId, message.clientId, local, messageId);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n private addClientToQueue(taskId: string, clientId: string) {\n const pendingIds = this.pendingCompletedTasks.get(taskId);\n if (pendingIds !== undefined && pendingIds.length > 0) {\n // Ignore the volunteer op if we know this task is about to be completed\n return;\n }\n\n // Ensure that the clientId exists in the quorum, or it is placeholderClientId (detached scenario)\n if (this.runtime.getQuorum().getMembers().has(clientId) || this.clientId === placeholderClientId) {\n // Create the queue if it doesn't exist, and push the client on the back.\n let clientQueue = this.taskQueues.get(taskId);\n if (clientQueue === undefined) {\n clientQueue = [];\n this.taskQueues.set(taskId, clientQueue);\n }\n\n const oldLockHolder = clientQueue[0];\n clientQueue.push(clientId);\n const newLockHolder = clientQueue[0];\n if (newLockHolder !== oldLockHolder) {\n this.queueWatcher.emit(\"queueChange\", taskId, oldLockHolder, newLockHolder);\n }\n\n }\n }\n\n private removeClientFromQueue(taskId: string, clientId: string) {\n const clientQueue = this.taskQueues.get(taskId);\n if (clientQueue === undefined) {\n return;\n }\n\n const oldLockHolder = clientId === placeholderClientId ? placeholderClientId : clientQueue[0];\n const clientIdIndex = clientQueue.indexOf(clientId);\n if (clientIdIndex !== -1) {\n clientQueue.splice(clientIdIndex, 1);\n // Clean up the queue if there are no more clients in it.\n if (clientQueue.length === 0) {\n this.taskQueues.delete(taskId);\n }\n }\n const newLockHolder = clientQueue[0];\n if (newLockHolder !== oldLockHolder) {\n this.queueWatcher.emit(\"queueChange\", taskId, oldLockHolder, newLockHolder);\n }\n }\n\n private removeClientFromAllQueues(clientId: string) {\n for (const taskId of this.taskQueues.keys()) {\n this.removeClientFromQueue(taskId, clientId);\n }\n }\n\n /**\n * Will replace all instances of the placeholderClientId with the current clientId. This should only be called when\n * transitioning from detached to attached and this.runtime.clientId is defined.\n */\n private replacePlaceholderInAllQueues() {\n assert(this.runtime.clientId !== undefined, 0x475 /* this.runtime.clientId should be defined */);\n for (const clientQueue of this.taskQueues.values()) {\n const clientIdIndex = clientQueue.indexOf(placeholderClientId);\n if (clientIdIndex !== -1) {\n clientQueue[clientIdIndex] = this.runtime.clientId;\n }\n }\n }\n\n // This seems like it should be unnecessary if we can trust to receive the join/leave messages and\n // also have an accurate snapshot.\n private scrubClientsNotInQuorum() {\n const quorum = this.runtime.getQuorum();\n for (const [taskId, clientQueue] of this.taskQueues) {\n const filteredClientQueue = clientQueue.filter((clientId) => quorum.getMember(clientId) !== undefined);\n if (clientQueue.length !== filteredClientQueue.length) {\n if (filteredClientQueue.length === 0) {\n this.taskQueues.delete(taskId);\n } else {\n this.taskQueues.set(taskId, filteredClientQueue);\n }\n this.queueWatcher.emit(\"queueChange\", taskId);\n }\n }\n }\n\n public applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/task-manager",
|
|
3
|
-
"version": "2.0.0-internal.2.
|
|
3
|
+
"version": "2.0.0-internal.2.3.1",
|
|
4
4
|
"description": "Distributed data structure for queueing exclusive tasks",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -64,25 +64,26 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
66
66
|
"@fluidframework/common-utils": "^1.0.0",
|
|
67
|
-
"@fluidframework/container-definitions": ">=2.0.0-internal.2.
|
|
68
|
-
"@fluidframework/container-runtime-definitions": ">=2.0.0-internal.2.
|
|
69
|
-
"@fluidframework/core-interfaces": ">=2.0.0-internal.2.
|
|
70
|
-
"@fluidframework/datastore-definitions": ">=2.0.0-internal.2.
|
|
71
|
-
"@fluidframework/driver-utils": ">=2.0.0-internal.2.
|
|
67
|
+
"@fluidframework/container-definitions": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
68
|
+
"@fluidframework/container-runtime-definitions": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
69
|
+
"@fluidframework/core-interfaces": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
70
|
+
"@fluidframework/datastore-definitions": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
71
|
+
"@fluidframework/driver-utils": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
72
72
|
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
73
|
-
"@fluidframework/runtime-definitions": ">=2.0.0-internal.2.
|
|
74
|
-
"@fluidframework/shared-object-base": ">=2.0.0-internal.2.
|
|
73
|
+
"@fluidframework/runtime-definitions": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
74
|
+
"@fluidframework/shared-object-base": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
75
|
+
"events": "^3.1.0"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
|
-
"@fluid-
|
|
78
|
-
"@fluid-internal/
|
|
79
|
-
"@fluid-internal/test-dds-utils": ">=2.0.0-internal.2.2.1 <2.0.0-internal.3.0.0",
|
|
78
|
+
"@fluid-internal/stochastic-test-utils": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
79
|
+
"@fluid-internal/test-dds-utils": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
80
80
|
"@fluid-tools/build-cli": "^0.7.0",
|
|
81
81
|
"@fluidframework/build-common": "^1.1.0",
|
|
82
82
|
"@fluidframework/build-tools": "^0.7.0",
|
|
83
|
-
"@fluidframework/eslint-config-fluid": "^
|
|
84
|
-
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.2.
|
|
85
|
-
"@fluidframework/
|
|
83
|
+
"@fluidframework/eslint-config-fluid": "^2.0.0",
|
|
84
|
+
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
85
|
+
"@fluidframework/task-manager-previous": "npm:@fluidframework/task-manager@2.0.0-internal.2.3.0",
|
|
86
|
+
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
|
|
86
87
|
"@microsoft/api-extractor": "^7.22.2",
|
|
87
88
|
"@rushstack/eslint-config": "^2.5.1",
|
|
88
89
|
"@types/mocha": "^9.1.1",
|
|
@@ -99,10 +100,8 @@
|
|
|
99
100
|
"typescript": "~4.5.5"
|
|
100
101
|
},
|
|
101
102
|
"typeValidation": {
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"baselineRange": ">=2.0.0-internal.2.1.0 <2.0.0-internal.2.2.0",
|
|
105
|
-
"baselineVersion": "2.0.0-internal.2.1.0",
|
|
103
|
+
"version": "2.0.0-internal.2.3.1",
|
|
104
|
+
"baselineRange": "2.0.0-internal.2.3.0",
|
|
106
105
|
"broken": {}
|
|
107
106
|
}
|
|
108
107
|
}
|
package/src/packageVersion.ts
CHANGED
package/src/taskManager.ts
CHANGED
|
@@ -380,8 +380,8 @@ export class TaskManager extends SharedObject<ITaskManagerEvents> implements ITa
|
|
|
380
380
|
|
|
381
381
|
if (this.readOnlyInfo.readonly === true) {
|
|
382
382
|
const error = this.readOnlyInfo.permissions === true ?
|
|
383
|
-
new Error(
|
|
384
|
-
new Error(
|
|
383
|
+
new Error("Attempted to volunteer with read-only permissions") :
|
|
384
|
+
new Error("Attempted to volunteer in read-only state");
|
|
385
385
|
throw error;
|
|
386
386
|
}
|
|
387
387
|
|
|
@@ -393,7 +393,7 @@ export class TaskManager extends SharedObject<ITaskManagerEvents> implements ITa
|
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
if (!this.connected) {
|
|
396
|
-
throw new Error(
|
|
396
|
+
throw new Error("Attempted to volunteer in disconnected state");
|
|
397
397
|
}
|
|
398
398
|
|
|
399
399
|
// This promise works even if we already have an outstanding volunteer op.
|
|
@@ -424,7 +424,7 @@ export class TaskManager extends SharedObject<ITaskManagerEvents> implements ITa
|
|
|
424
424
|
this.abandonWatcher.off("abandon", checkIfAbandoned);
|
|
425
425
|
this.connectionWatcher.off("disconnect", rejectOnDisconnect);
|
|
426
426
|
this.completedWatcher.off("completed", checkIfCompleted);
|
|
427
|
-
reject(new Error(
|
|
427
|
+
reject(new Error("Abandoned before acquiring task assignment"));
|
|
428
428
|
};
|
|
429
429
|
|
|
430
430
|
const rejectOnDisconnect = () => {
|
|
@@ -432,7 +432,7 @@ export class TaskManager extends SharedObject<ITaskManagerEvents> implements ITa
|
|
|
432
432
|
this.abandonWatcher.off("abandon", checkIfAbandoned);
|
|
433
433
|
this.connectionWatcher.off("disconnect", rejectOnDisconnect);
|
|
434
434
|
this.completedWatcher.off("completed", checkIfCompleted);
|
|
435
|
-
reject(new Error(
|
|
435
|
+
reject(new Error("Disconnected before acquiring task assignment"));
|
|
436
436
|
};
|
|
437
437
|
|
|
438
438
|
const checkIfCompleted = (eventTaskId: string) => {
|
|
@@ -468,7 +468,7 @@ export class TaskManager extends SharedObject<ITaskManagerEvents> implements ITa
|
|
|
468
468
|
}
|
|
469
469
|
|
|
470
470
|
if (this.readOnlyInfo.readonly === true && this.readOnlyInfo.permissions === true) {
|
|
471
|
-
throw new Error(
|
|
471
|
+
throw new Error("Attempted to subscribe with read-only permissions");
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
const submitVolunteerOp = () => {
|
|
@@ -611,14 +611,14 @@ export class TaskManager extends SharedObject<ITaskManagerEvents> implements ITa
|
|
|
611
611
|
*/
|
|
612
612
|
public complete(taskId: string): void {
|
|
613
613
|
if (!this.assigned(taskId)) {
|
|
614
|
-
throw new Error(
|
|
614
|
+
throw new Error("Attempted to mark task as complete while not being assigned");
|
|
615
615
|
}
|
|
616
616
|
|
|
617
617
|
// If we are detached we will simulate auto-ack for the complete op. Therefore we only need to send the op if
|
|
618
618
|
// we are attached. Additionally, we don't need to check if we are connected while detached.
|
|
619
619
|
if (this.isAttached()) {
|
|
620
620
|
if (!this.connected) {
|
|
621
|
-
throw new Error(
|
|
621
|
+
throw new Error("Attempted to complete task in disconnected state");
|
|
622
622
|
}
|
|
623
623
|
this.submitCompleteOp(taskId);
|
|
624
624
|
}
|