@fluidframework/ordered-collection 0.59.4001 → 1.0.0
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 +1 -1
- package/dist/consensusOrderedCollection.js +1 -1
- package/dist/consensusOrderedCollection.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/consensusOrderedCollection.js +1 -1
- package/lib/consensusOrderedCollection.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +12 -25
- package/src/consensusOrderedCollection.ts +1 -1
- package/src/packageVersion.ts +1 -1
package/.eslintrc.js
CHANGED
|
@@ -29,7 +29,7 @@ class ConsensusOrderedCollection extends shared_object_base_1.SharedObject {
|
|
|
29
29
|
* be provided
|
|
30
30
|
*/
|
|
31
31
|
constructor(id, runtime, attributes, data) {
|
|
32
|
-
super(id, runtime, attributes);
|
|
32
|
+
super(id, runtime, attributes, "fluid_consensusOrderedCollection_");
|
|
33
33
|
this.data = data;
|
|
34
34
|
/**
|
|
35
35
|
* The set of values that have been acquired but not yet completed or released
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAuF;AACvF,+EAA8F;AAM9F,2EAAoF;AAEpF,iEAAmE;AACnE,+BAAkC;AAClC,6CAMsB;AAEtB,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,wBAAwB,GAAG,aAAa,CAAC;AAwD/C,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAa,0BACT,SAAQ,iCAAkD;IAM1D;;;O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CAAC;IACvC,CAAC;CACJ;AA9RD,gEA8RC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ConsensusCallback,\n ConsensusResult,\n IConsensusOrderedCollection,\n IOrderedCollection,\n IConsensusOrderedCollectionEvents,\n} from \"./interfaces\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n readonly acquireId: string;\n\n // The actual value\n readonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation {\n opName: \"add\";\n // serialized value\n value: string;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n opName: \"acquire\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n opName: \"complete\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n opName: \"release\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation =\n IConsensusOrderedCollectionAddOperation |\n IConsensusOrderedCollectionAcquireOperation |\n IConsensusOrderedCollectionCompleteOperation |\n IConsensusOrderedCollectionReleaseOperation;\n\n/** The type of the resolve function to call after the local operation is ack'd */\ntype PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;\n\n/**\n * For job tracking, we need to keep track of which client \"owns\" a given value.\n * Key is the acquireId from when it was acquired\n * Value is the acquired value, and the id of the client who acquired it, or undefined for unattached client\n */\ntype JobTrackingInfo<T> = Map<string, { value: T; clientId: string | undefined; }>;\nconst idForLocalUnattachedClient = undefined;\n\n/**\n * Implementation of a consensus collection shared object\n *\n * Implements the shared object's communication, and the semantics around the\n * release/complete mechanism following acquire.\n *\n * Generally not used directly. A derived type will pass in a backing data type\n * IOrderedCollection that will define the deterministic add/acquire order and snapshot ability.\n */\nexport class ConsensusOrderedCollection<T = any>\n extends SharedObject<IConsensusOrderedCollectionEvents<T>> implements IConsensusOrderedCollection<T> {\n /**\n * The set of values that have been acquired but not yet completed or released\n */\n private jobTracking: JobTrackingInfo<T> = new Map();\n\n /**\n * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n protected constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly data: IOrderedCollection<T>,\n ) {\n super(id, runtime, attributes);\n\n // We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n // because other clients may disconnect concurrently.\n // Disconnect order matters because it defines the order items go back to the queue.\n // So we put items back to queue only when we process our own removeMember event.\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n assert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n this.removeClient(clientId);\n });\n }\n\n /**\n * Add a value to the consensus collection.\n */\n public async add(value: T): Promise<void> {\n const valueSer = this.serializeValue(value, this.serializer);\n\n if (!this.isAttached()) {\n // For the case where this is not attached yet, explicitly JSON\n // clone the value to match the behavior of going thru the wire.\n const addValue = this.deserializeValue(valueSer, this.serializer) as T;\n this.addCore(addValue);\n return;\n }\n\n await this.submit<IConsensusOrderedCollectionAddOperation>({\n opName: \"add\",\n value: valueSer,\n });\n }\n\n /**\n * Remove a value from the consensus collection. If the collection is empty, returns false.\n * Otherwise calls callback with the value\n */\n public async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n const result = await this.acquireInternal();\n if (result === undefined) {\n return false;\n }\n\n const res = await callback(result.value);\n\n switch (res) {\n case ConsensusResult.Complete:\n await this.complete(result.acquireId);\n break;\n case ConsensusResult.Release:\n this.release(result.acquireId);\n this.emit(\"localRelease\", result.value, true /* intentional */);\n break;\n default: unreachableCase(res);\n }\n\n return true;\n }\n\n /**\n * Wait for a value to be available and acquire it from the consensus collection\n */\n public async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n do {\n if (this.data.size() === 0) {\n // Wait for new entry before trying to acquire again\n await this.newAckBasedPromise<T>((resolve) => {\n this.once(\"add\", resolve);\n });\n }\n } while (!(await this.acquire(callback)));\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n // If we are transitioning from unattached to attached mode,\n // then we are losing all checked out work!\n this.removeClient(idForLocalUnattachedClient);\n\n const builder = new SummaryTreeBuilder();\n let blobContent = this.serializeValue(this.data.asArray(), serializer);\n builder.addBlob(snapshotFileNameData, blobContent);\n blobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n builder.addBlob(snapshotFileNameTracking, blobContent);\n return builder.getSummaryTree();\n }\n\n protected isActive() {\n return this.runtime.connected && this.runtime.deltaManager.active;\n }\n\n protected async complete(acquireId: string) {\n if (!this.isAttached()) {\n this.completeCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n await this.submit<IConsensusOrderedCollectionCompleteOperation>({\n opName: \"complete\",\n acquireId,\n });\n }\n }\n\n protected completeCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.emit(\"complete\", rec.value);\n }\n }\n\n protected release(acquireId: string) {\n if (!this.isAttached()) {\n this.releaseCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n this.submit<IConsensusOrderedCollectionReleaseOperation>({\n opName: \"release\",\n acquireId,\n }).catch((error) => {\n this.runtime.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n });\n }\n }\n\n protected releaseCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.data.add(rec.value);\n this.emit(\"add\", rec.value, false /* newlyAdded */);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n assert(this.jobTracking.size === 0, 0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */);\n const blob = await storage.readBlob(snapshotFileNameTracking);\n const rawContentTracking = bufferToString(blob, \"utf8\");\n const content = this.deserializeValue(rawContentTracking, this.serializer);\n this.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n assert(this.data.size() === 0, 0x069 /* \"On consensusOrderedCollection load, data size > 0\" */);\n const blob2 = await storage.readBlob(snapshotFileNameData);\n const rawContentData = bufferToString(blob2, \"utf8\");\n const content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n this.data.loadFrom(content2);\n }\n\n protected onDisconnect() {\n for (const [, { value, clientId }] of this.jobTracking) {\n if (clientId === this.runtime.clientId) {\n this.emit(\"localRelease\", value, false /* intentional */);\n }\n }\n }\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IConsensusOrderedCollectionOperation = message.contents;\n let value: IConsensusOrderedCollectionValue<T> | undefined;\n switch (op.opName) {\n case \"add\":\n this.addCore(this.deserializeValue(op.value, this.serializer) as T);\n break;\n\n case \"acquire\":\n value = this.acquireCore(op.acquireId, message.clientId);\n break;\n\n case \"complete\":\n this.completeCore(op.acquireId);\n break;\n\n case \"release\":\n this.releaseCore(op.acquireId);\n break;\n\n default: unreachableCase(op);\n }\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve<T>;\n resolve(value);\n }\n }\n }\n\n private async submit<TMessage extends IConsensusOrderedCollectionOperation>(\n message: TMessage,\n ): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n assert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n return this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n }).catch((error) => undefined);\n }\n\n private addCore(value: T) {\n this.data.add(value);\n this.emit(\"add\", value, true /* newlyAdded */);\n }\n\n private acquireCore(acquireId: string, clientId?: string): IConsensusOrderedCollectionValue<T> | undefined {\n if (this.data.size() === 0) {\n return undefined;\n }\n const value = this.data.remove();\n\n const value2: IConsensusOrderedCollectionValue<T> = {\n acquireId,\n value,\n };\n this.jobTracking.set(value2.acquireId, { value, clientId });\n\n this.emit(\"acquire\", value, clientId);\n return value2;\n }\n\n private async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n if (!this.isAttached()) {\n // can be undefined if queue is empty\n return this.acquireCore(uuid(), idForLocalUnattachedClient);\n }\n\n return this.submit<IConsensusOrderedCollectionAcquireOperation>({\n opName: \"acquire\",\n acquireId: uuid(),\n });\n }\n\n private removeClient(clientIdToRemove?: string) {\n const added: T[] = [];\n for (const [acquireId, { value, clientId }] of this.jobTracking) {\n if (clientId === clientIdToRemove) {\n this.jobTracking.delete(acquireId);\n this.data.add(value);\n added.push(value);\n }\n }\n\n // Raise all events only after all state changes are completed,\n // to guarantee same ordering of operations if collection is manipulated from events.\n added.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n }\n\n private serializeValue(value, serializer: IFluidSerializer) {\n return serializer.stringify(value, this.handle);\n }\n\n private deserializeValue(content: string, serializer: IFluidSerializer) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAuF;AACvF,+EAA8F;AAM9F,2EAAoF;AAEpF,iEAAmE;AACnE,+BAAkC;AAClC,6CAMsB;AAEtB,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,wBAAwB,GAAG,aAAa,CAAC;AAwD/C,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAa,0BACT,SAAQ,iCAAkD;IAM1D;;;OAGG;IACH,YACI,EAAU,EACV,OAA+B,EAC/B,UAA8B,EACb,IAA2B;QAE5C,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,mCAAmC,CAAC,CAAC;QAFnD,SAAI,GAAJ,IAAI,CAAuB;QAbhD;;WAEG;QACK,gBAAW,GAAuB,IAAI,GAAG,EAAE,CAAC;QAchD,4FAA4F;QAC5F,qDAAqD;QACrD,oFAAoF;QACpF,iFAAiF;QACjF,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,QAAgB,EAAE,EAAE;YACxD,IAAA,qBAAM,EAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,qCAAqC,CAAC,CAAC;YAChE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,GAAG,CAAC,KAAQ;QACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,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AC,KAAK,CAAC,CAAC;gBACrB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACrB;SACJ;QAED,+DAA+D;QAC/D,qFAAqF;QACrF,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC1E,CAAC;IAEO,cAAc,CAAC,KAAK,EAAE,UAA4B;QACtD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QAClE,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAES,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AA9RD,gEA8RC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ConsensusCallback,\n ConsensusResult,\n IConsensusOrderedCollection,\n IOrderedCollection,\n IConsensusOrderedCollectionEvents,\n} from \"./interfaces\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n readonly acquireId: string;\n\n // The actual value\n readonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation {\n opName: \"add\";\n // serialized value\n value: string;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n opName: \"acquire\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n opName: \"complete\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n opName: \"release\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation =\n IConsensusOrderedCollectionAddOperation |\n IConsensusOrderedCollectionAcquireOperation |\n IConsensusOrderedCollectionCompleteOperation |\n IConsensusOrderedCollectionReleaseOperation;\n\n/** The type of the resolve function to call after the local operation is ack'd */\ntype PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;\n\n/**\n * For job tracking, we need to keep track of which client \"owns\" a given value.\n * Key is the acquireId from when it was acquired\n * Value is the acquired value, and the id of the client who acquired it, or undefined for unattached client\n */\ntype JobTrackingInfo<T> = Map<string, { value: T; clientId: string | undefined; }>;\nconst idForLocalUnattachedClient = undefined;\n\n/**\n * Implementation of a consensus collection shared object\n *\n * Implements the shared object's communication, and the semantics around the\n * release/complete mechanism following acquire.\n *\n * Generally not used directly. A derived type will pass in a backing data type\n * IOrderedCollection that will define the deterministic add/acquire order and snapshot ability.\n */\nexport class ConsensusOrderedCollection<T = any>\n extends SharedObject<IConsensusOrderedCollectionEvents<T>> implements IConsensusOrderedCollection<T> {\n /**\n * The set of values that have been acquired but not yet completed or released\n */\n private jobTracking: JobTrackingInfo<T> = new Map();\n\n /**\n * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n protected constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly data: IOrderedCollection<T>,\n ) {\n super(id, runtime, attributes, \"fluid_consensusOrderedCollection_\");\n\n // We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n // because other clients may disconnect concurrently.\n // Disconnect order matters because it defines the order items go back to the queue.\n // So we put items back to queue only when we process our own removeMember event.\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n assert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n this.removeClient(clientId);\n });\n }\n\n /**\n * Add a value to the consensus collection.\n */\n public async add(value: T): Promise<void> {\n const valueSer = this.serializeValue(value, this.serializer);\n\n if (!this.isAttached()) {\n // For the case where this is not attached yet, explicitly JSON\n // clone the value to match the behavior of going thru the wire.\n const addValue = this.deserializeValue(valueSer, this.serializer) as T;\n this.addCore(addValue);\n return;\n }\n\n await this.submit<IConsensusOrderedCollectionAddOperation>({\n opName: \"add\",\n value: valueSer,\n });\n }\n\n /**\n * Remove a value from the consensus collection. If the collection is empty, returns false.\n * Otherwise calls callback with the value\n */\n public async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n const result = await this.acquireInternal();\n if (result === undefined) {\n return false;\n }\n\n const res = await callback(result.value);\n\n switch (res) {\n case ConsensusResult.Complete:\n await this.complete(result.acquireId);\n break;\n case ConsensusResult.Release:\n this.release(result.acquireId);\n this.emit(\"localRelease\", result.value, true /* intentional */);\n break;\n default: unreachableCase(res);\n }\n\n return true;\n }\n\n /**\n * Wait for a value to be available and acquire it from the consensus collection\n */\n public async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n do {\n if (this.data.size() === 0) {\n // Wait for new entry before trying to acquire again\n await this.newAckBasedPromise<T>((resolve) => {\n this.once(\"add\", resolve);\n });\n }\n } while (!(await this.acquire(callback)));\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n // If we are transitioning from unattached to attached mode,\n // then we are losing all checked out work!\n this.removeClient(idForLocalUnattachedClient);\n\n const builder = new SummaryTreeBuilder();\n let blobContent = this.serializeValue(this.data.asArray(), serializer);\n builder.addBlob(snapshotFileNameData, blobContent);\n blobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n builder.addBlob(snapshotFileNameTracking, blobContent);\n return builder.getSummaryTree();\n }\n\n protected isActive() {\n return this.runtime.connected && this.runtime.deltaManager.active;\n }\n\n protected async complete(acquireId: string) {\n if (!this.isAttached()) {\n this.completeCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n await this.submit<IConsensusOrderedCollectionCompleteOperation>({\n opName: \"complete\",\n acquireId,\n });\n }\n }\n\n protected completeCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.emit(\"complete\", rec.value);\n }\n }\n\n protected release(acquireId: string) {\n if (!this.isAttached()) {\n this.releaseCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n this.submit<IConsensusOrderedCollectionReleaseOperation>({\n opName: \"release\",\n acquireId,\n }).catch((error) => {\n this.runtime.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n });\n }\n }\n\n protected releaseCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.data.add(rec.value);\n this.emit(\"add\", rec.value, false /* newlyAdded */);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n assert(this.jobTracking.size === 0, 0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */);\n const blob = await storage.readBlob(snapshotFileNameTracking);\n const rawContentTracking = bufferToString(blob, \"utf8\");\n const content = this.deserializeValue(rawContentTracking, this.serializer);\n this.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n assert(this.data.size() === 0, 0x069 /* \"On consensusOrderedCollection load, data size > 0\" */);\n const blob2 = await storage.readBlob(snapshotFileNameData);\n const rawContentData = bufferToString(blob2, \"utf8\");\n const content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n this.data.loadFrom(content2);\n }\n\n protected onDisconnect() {\n for (const [, { value, clientId }] of this.jobTracking) {\n if (clientId === this.runtime.clientId) {\n this.emit(\"localRelease\", value, false /* intentional */);\n }\n }\n }\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IConsensusOrderedCollectionOperation = message.contents;\n let value: IConsensusOrderedCollectionValue<T> | undefined;\n switch (op.opName) {\n case \"add\":\n this.addCore(this.deserializeValue(op.value, this.serializer) as T);\n break;\n\n case \"acquire\":\n value = this.acquireCore(op.acquireId, message.clientId);\n break;\n\n case \"complete\":\n this.completeCore(op.acquireId);\n break;\n\n case \"release\":\n this.releaseCore(op.acquireId);\n break;\n\n default: unreachableCase(op);\n }\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve<T>;\n resolve(value);\n }\n }\n }\n\n private async submit<TMessage extends IConsensusOrderedCollectionOperation>(\n message: TMessage,\n ): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n assert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n return this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n }).catch((error) => undefined);\n }\n\n private addCore(value: T) {\n this.data.add(value);\n this.emit(\"add\", value, true /* newlyAdded */);\n }\n\n private acquireCore(acquireId: string, clientId?: string): IConsensusOrderedCollectionValue<T> | undefined {\n if (this.data.size() === 0) {\n return undefined;\n }\n const value = this.data.remove();\n\n const value2: IConsensusOrderedCollectionValue<T> = {\n acquireId,\n value,\n };\n this.jobTracking.set(value2.acquireId, { value, clientId });\n\n this.emit(\"acquire\", value, clientId);\n return value2;\n }\n\n private async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n if (!this.isAttached()) {\n // can be undefined if queue is empty\n return this.acquireCore(uuid(), idForLocalUnattachedClient);\n }\n\n return this.submit<IConsensusOrderedCollectionAcquireOperation>({\n opName: \"acquire\",\n acquireId: uuid(),\n });\n }\n\n private removeClient(clientIdToRemove?: string) {\n const added: T[] = [];\n for (const [acquireId, { value, clientId }] of this.jobTracking) {\n if (clientId === clientIdToRemove) {\n this.jobTracking.delete(acquireId);\n this.data.add(value);\n added.push(value);\n }\n }\n\n // Raise all events only after all state changes are completed,\n // to guarantee same ordering of operations if collection is manipulated from events.\n added.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n }\n\n private serializeValue(value, serializer: IFluidSerializer) {\n return serializer.stringify(value, this.handle);\n }\n\n private deserializeValue(content: string, serializer: IFluidSerializer) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
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/ordered-collection";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "1.0.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,UAAU,CAAC"}
|
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/ordered-collection";
|
|
11
|
-
exports.pkgVersion = "0.
|
|
11
|
+
exports.pkgVersion = "1.0.0";
|
|
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,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,OAAO,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/ordered-collection\";\nexport const pkgVersion = \"1.0.0\";\n"]}
|
|
@@ -26,7 +26,7 @@ export class ConsensusOrderedCollection extends SharedObject {
|
|
|
26
26
|
* be provided
|
|
27
27
|
*/
|
|
28
28
|
constructor(id, runtime, attributes, data) {
|
|
29
|
-
super(id, runtime, attributes);
|
|
29
|
+
super(id, runtime, attributes, "fluid_consensusOrderedCollection_");
|
|
30
30
|
this.data = data;
|
|
31
31
|
/**
|
|
32
32
|
* The set of values that have been acquired but not yet completed or released
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,EAA6B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAM9F,OAAO,EAAoB,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAEH,eAAe,GAIlB,MAAM,cAAc,CAAC;AAEtB,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,wBAAwB,GAAG,aAAa,CAAC;AAwD/C,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,OAAO,0BACT,SAAQ,YAAkD;IAM1D;;;OAGG;IACH,YACI,EAAU,EACV,OAA+B,EAC/B,UAA8B,EACb,IAA2B;QAE5C,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAFd,SAAI,GAAJ,IAAI,CAAuB;QAbhD;;WAEG;QACK,gBAAW,GAAuB,IAAI,GAAG,EAAE,CAAC;QAchD,4FAA4F;QAC5F,qDAAqD;QACrD,oFAAoF;QACpF,iFAAiF;QACjF,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,QAAgB,EAAE,EAAE;YACxD,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,qCAAqC,CAAC,CAAC;YAChE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;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AC,SAAS,CAAC,CAAC;gBACnC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACrB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACrB;SACJ;QAED,+DAA+D;QAC/D,qFAAqF;QACrF,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC1E,CAAC;IAEO,cAAc,CAAC,KAAK,EAAE,UAA4B;QACtD,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAEO,gBAAgB,CAAC,OAAe,EAAE,UAA4B;QAClE,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAES,cAAc;QACpB,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 { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ConsensusCallback,\n ConsensusResult,\n IConsensusOrderedCollection,\n IOrderedCollection,\n IConsensusOrderedCollectionEvents,\n} from \"./interfaces\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n readonly acquireId: string;\n\n // The actual value\n readonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation {\n opName: \"add\";\n // serialized value\n value: string;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n opName: \"acquire\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n opName: \"complete\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n opName: \"release\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation =\n IConsensusOrderedCollectionAddOperation |\n IConsensusOrderedCollectionAcquireOperation |\n IConsensusOrderedCollectionCompleteOperation |\n IConsensusOrderedCollectionReleaseOperation;\n\n/** The type of the resolve function to call after the local operation is ack'd */\ntype PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;\n\n/**\n * For job tracking, we need to keep track of which client \"owns\" a given value.\n * Key is the acquireId from when it was acquired\n * Value is the acquired value, and the id of the client who acquired it, or undefined for unattached client\n */\ntype JobTrackingInfo<T> = Map<string, { value: T; clientId: string | undefined; }>;\nconst idForLocalUnattachedClient = undefined;\n\n/**\n * Implementation of a consensus collection shared object\n *\n * Implements the shared object's communication, and the semantics around the\n * release/complete mechanism following acquire.\n *\n * Generally not used directly. A derived type will pass in a backing data type\n * IOrderedCollection that will define the deterministic add/acquire order and snapshot ability.\n */\nexport class ConsensusOrderedCollection<T = any>\n extends SharedObject<IConsensusOrderedCollectionEvents<T>> implements IConsensusOrderedCollection<T> {\n /**\n * The set of values that have been acquired but not yet completed or released\n */\n private jobTracking: JobTrackingInfo<T> = new Map();\n\n /**\n * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n protected constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly data: IOrderedCollection<T>,\n ) {\n super(id, runtime, attributes);\n\n // We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n // because other clients may disconnect concurrently.\n // Disconnect order matters because it defines the order items go back to the queue.\n // So we put items back to queue only when we process our own removeMember event.\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n assert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n this.removeClient(clientId);\n });\n }\n\n /**\n * Add a value to the consensus collection.\n */\n public async add(value: T): Promise<void> {\n const valueSer = this.serializeValue(value, this.serializer);\n\n if (!this.isAttached()) {\n // For the case where this is not attached yet, explicitly JSON\n // clone the value to match the behavior of going thru the wire.\n const addValue = this.deserializeValue(valueSer, this.serializer) as T;\n this.addCore(addValue);\n return;\n }\n\n await this.submit<IConsensusOrderedCollectionAddOperation>({\n opName: \"add\",\n value: valueSer,\n });\n }\n\n /**\n * Remove a value from the consensus collection. If the collection is empty, returns false.\n * Otherwise calls callback with the value\n */\n public async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n const result = await this.acquireInternal();\n if (result === undefined) {\n return false;\n }\n\n const res = await callback(result.value);\n\n switch (res) {\n case ConsensusResult.Complete:\n await this.complete(result.acquireId);\n break;\n case ConsensusResult.Release:\n this.release(result.acquireId);\n this.emit(\"localRelease\", result.value, true /* intentional */);\n break;\n default: unreachableCase(res);\n }\n\n return true;\n }\n\n /**\n * Wait for a value to be available and acquire it from the consensus collection\n */\n public async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n do {\n if (this.data.size() === 0) {\n // Wait for new entry before trying to acquire again\n await this.newAckBasedPromise<T>((resolve) => {\n this.once(\"add\", resolve);\n });\n }\n } while (!(await this.acquire(callback)));\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n // If we are transitioning from unattached to attached mode,\n // then we are losing all checked out work!\n this.removeClient(idForLocalUnattachedClient);\n\n const builder = new SummaryTreeBuilder();\n let blobContent = this.serializeValue(this.data.asArray(), serializer);\n builder.addBlob(snapshotFileNameData, blobContent);\n blobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n builder.addBlob(snapshotFileNameTracking, blobContent);\n return builder.getSummaryTree();\n }\n\n protected isActive() {\n return this.runtime.connected && this.runtime.deltaManager.active;\n }\n\n protected async complete(acquireId: string) {\n if (!this.isAttached()) {\n this.completeCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n await this.submit<IConsensusOrderedCollectionCompleteOperation>({\n opName: \"complete\",\n acquireId,\n });\n }\n }\n\n protected completeCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.emit(\"complete\", rec.value);\n }\n }\n\n protected release(acquireId: string) {\n if (!this.isAttached()) {\n this.releaseCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n this.submit<IConsensusOrderedCollectionReleaseOperation>({\n opName: \"release\",\n acquireId,\n }).catch((error) => {\n this.runtime.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n });\n }\n }\n\n protected releaseCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.data.add(rec.value);\n this.emit(\"add\", rec.value, false /* newlyAdded */);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n assert(this.jobTracking.size === 0, 0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */);\n const blob = await storage.readBlob(snapshotFileNameTracking);\n const rawContentTracking = bufferToString(blob, \"utf8\");\n const content = this.deserializeValue(rawContentTracking, this.serializer);\n this.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n assert(this.data.size() === 0, 0x069 /* \"On consensusOrderedCollection load, data size > 0\" */);\n const blob2 = await storage.readBlob(snapshotFileNameData);\n const rawContentData = bufferToString(blob2, \"utf8\");\n const content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n this.data.loadFrom(content2);\n }\n\n protected onDisconnect() {\n for (const [, { value, clientId }] of this.jobTracking) {\n if (clientId === this.runtime.clientId) {\n this.emit(\"localRelease\", value, false /* intentional */);\n }\n }\n }\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IConsensusOrderedCollectionOperation = message.contents;\n let value: IConsensusOrderedCollectionValue<T> | undefined;\n switch (op.opName) {\n case \"add\":\n this.addCore(this.deserializeValue(op.value, this.serializer) as T);\n break;\n\n case \"acquire\":\n value = this.acquireCore(op.acquireId, message.clientId);\n break;\n\n case \"complete\":\n this.completeCore(op.acquireId);\n break;\n\n case \"release\":\n this.releaseCore(op.acquireId);\n break;\n\n default: unreachableCase(op);\n }\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve<T>;\n resolve(value);\n }\n }\n }\n\n private async submit<TMessage extends IConsensusOrderedCollectionOperation>(\n message: TMessage,\n ): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n assert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n return this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n }).catch((error) => undefined);\n }\n\n private addCore(value: T) {\n this.data.add(value);\n this.emit(\"add\", value, true /* newlyAdded */);\n }\n\n private acquireCore(acquireId: string, clientId?: string): IConsensusOrderedCollectionValue<T> | undefined {\n if (this.data.size() === 0) {\n return undefined;\n }\n const value = this.data.remove();\n\n const value2: IConsensusOrderedCollectionValue<T> = {\n acquireId,\n value,\n };\n this.jobTracking.set(value2.acquireId, { value, clientId });\n\n this.emit(\"acquire\", value, clientId);\n return value2;\n }\n\n private async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n if (!this.isAttached()) {\n // can be undefined if queue is empty\n return this.acquireCore(uuid(), idForLocalUnattachedClient);\n }\n\n return this.submit<IConsensusOrderedCollectionAcquireOperation>({\n opName: \"acquire\",\n acquireId: uuid(),\n });\n }\n\n private removeClient(clientIdToRemove?: string) {\n const added: T[] = [];\n for (const [acquireId, { value, clientId }] of this.jobTracking) {\n if (clientId === clientIdToRemove) {\n this.jobTracking.delete(acquireId);\n this.data.add(value);\n added.push(value);\n }\n }\n\n // Raise all events only after all state changes are completed,\n // to guarantee same ordering of operations if collection is manipulated from events.\n added.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n }\n\n private serializeValue(value, serializer: IFluidSerializer) {\n return serializer.stringify(value, this.handle);\n }\n\n private deserializeValue(content: string, serializer: IFluidSerializer) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"consensusOrderedCollection.js","sourceRoot":"","sources":["../src/consensusOrderedCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,EAA6B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAM9F,OAAO,EAAoB,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAEH,eAAe,GAIlB,M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AAE,UAA4B;QAClE,+DAA+D;QAC/D,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAES,cAAc;QACpB,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 { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n} from \"@fluidframework/datastore-definitions\";\nimport { IFluidSerializer, SharedObject } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ConsensusCallback,\n ConsensusResult,\n IConsensusOrderedCollection,\n IOrderedCollection,\n IConsensusOrderedCollectionEvents,\n} from \"./interfaces\";\n\nconst snapshotFileNameData = \"header\";\nconst snapshotFileNameTracking = \"jobTracking\";\n\ninterface IConsensusOrderedCollectionValue<T> {\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n readonly acquireId: string;\n\n // The actual value\n readonly value: T;\n}\n\n/**\n * An operation for consensus ordered collection\n */\ninterface IConsensusOrderedCollectionAddOperation {\n opName: \"add\";\n // serialized value\n value: string;\n}\n\ninterface IConsensusOrderedCollectionAcquireOperation {\n opName: \"acquire\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionCompleteOperation {\n opName: \"complete\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ninterface IConsensusOrderedCollectionReleaseOperation {\n opName: \"release\";\n // an ID used to indicate acquired item.\n // Used in acquire/release/complete ops.\n acquireId: string;\n}\n\ntype IConsensusOrderedCollectionOperation =\n IConsensusOrderedCollectionAddOperation |\n IConsensusOrderedCollectionAcquireOperation |\n IConsensusOrderedCollectionCompleteOperation |\n IConsensusOrderedCollectionReleaseOperation;\n\n/** The type of the resolve function to call after the local operation is ack'd */\ntype PendingResolve<T> = (value: IConsensusOrderedCollectionValue<T> | undefined) => void;\n\n/**\n * For job tracking, we need to keep track of which client \"owns\" a given value.\n * Key is the acquireId from when it was acquired\n * Value is the acquired value, and the id of the client who acquired it, or undefined for unattached client\n */\ntype JobTrackingInfo<T> = Map<string, { value: T; clientId: string | undefined; }>;\nconst idForLocalUnattachedClient = undefined;\n\n/**\n * Implementation of a consensus collection shared object\n *\n * Implements the shared object's communication, and the semantics around the\n * release/complete mechanism following acquire.\n *\n * Generally not used directly. A derived type will pass in a backing data type\n * IOrderedCollection that will define the deterministic add/acquire order and snapshot ability.\n */\nexport class ConsensusOrderedCollection<T = any>\n extends SharedObject<IConsensusOrderedCollectionEvents<T>> implements IConsensusOrderedCollection<T> {\n /**\n * The set of values that have been acquired but not yet completed or released\n */\n private jobTracking: JobTrackingInfo<T> = new Map();\n\n /**\n * Constructs a new consensus collection. If the object is non-local an id and service interfaces will\n * be provided\n */\n protected constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly data: IOrderedCollection<T>,\n ) {\n super(id, runtime, attributes, \"fluid_consensusOrderedCollection_\");\n\n // We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,\n // because other clients may disconnect concurrently.\n // Disconnect order matters because it defines the order items go back to the queue.\n // So we put items back to queue only when we process our own removeMember event.\n runtime.getQuorum().on(\"removeMember\", (clientId: string) => {\n assert(!!clientId, 0x067 /* \"Missing clientId for removal!\" */);\n this.removeClient(clientId);\n });\n }\n\n /**\n * Add a value to the consensus collection.\n */\n public async add(value: T): Promise<void> {\n const valueSer = this.serializeValue(value, this.serializer);\n\n if (!this.isAttached()) {\n // For the case where this is not attached yet, explicitly JSON\n // clone the value to match the behavior of going thru the wire.\n const addValue = this.deserializeValue(valueSer, this.serializer) as T;\n this.addCore(addValue);\n return;\n }\n\n await this.submit<IConsensusOrderedCollectionAddOperation>({\n opName: \"add\",\n value: valueSer,\n });\n }\n\n /**\n * Remove a value from the consensus collection. If the collection is empty, returns false.\n * Otherwise calls callback with the value\n */\n public async acquire(callback: ConsensusCallback<T>): Promise<boolean> {\n const result = await this.acquireInternal();\n if (result === undefined) {\n return false;\n }\n\n const res = await callback(result.value);\n\n switch (res) {\n case ConsensusResult.Complete:\n await this.complete(result.acquireId);\n break;\n case ConsensusResult.Release:\n this.release(result.acquireId);\n this.emit(\"localRelease\", result.value, true /* intentional */);\n break;\n default: unreachableCase(res);\n }\n\n return true;\n }\n\n /**\n * Wait for a value to be available and acquire it from the consensus collection\n */\n public async waitAndAcquire(callback: ConsensusCallback<T>): Promise<void> {\n do {\n if (this.data.size() === 0) {\n // Wait for new entry before trying to acquire again\n await this.newAckBasedPromise<T>((resolve) => {\n this.once(\"add\", resolve);\n });\n }\n } while (!(await this.acquire(callback)));\n }\n\n protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n // If we are transitioning from unattached to attached mode,\n // then we are losing all checked out work!\n this.removeClient(idForLocalUnattachedClient);\n\n const builder = new SummaryTreeBuilder();\n let blobContent = this.serializeValue(this.data.asArray(), serializer);\n builder.addBlob(snapshotFileNameData, blobContent);\n blobContent = this.serializeValue(Array.from(this.jobTracking.entries()), serializer);\n builder.addBlob(snapshotFileNameTracking, blobContent);\n return builder.getSummaryTree();\n }\n\n protected isActive() {\n return this.runtime.connected && this.runtime.deltaManager.active;\n }\n\n protected async complete(acquireId: string) {\n if (!this.isAttached()) {\n this.completeCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n await this.submit<IConsensusOrderedCollectionCompleteOperation>({\n opName: \"complete\",\n acquireId,\n });\n }\n }\n\n protected completeCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.emit(\"complete\", rec.value);\n }\n }\n\n protected release(acquireId: string) {\n if (!this.isAttached()) {\n this.releaseCore(acquireId);\n return;\n }\n\n // if not active, this item already was released to queue (as observed by other clients)\n if (this.isActive()) {\n this.submit<IConsensusOrderedCollectionReleaseOperation>({\n opName: \"release\",\n acquireId,\n }).catch((error) => {\n this.runtime.logger.sendErrorEvent({ eventName: \"ConsensusQueue_release\" }, error);\n });\n }\n }\n\n protected releaseCore(acquireId: string) {\n // Note: item may be no longer in jobTracking and returned back to queue!\n const rec = this.jobTracking.get(acquireId);\n if (rec !== undefined) {\n this.jobTracking.delete(acquireId);\n this.data.add(rec.value);\n this.emit(\"add\", rec.value, false /* newlyAdded */);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n assert(this.jobTracking.size === 0, 0x068 /* \"On consensusOrderedCollection load, job tracking size > 0\" */);\n const blob = await storage.readBlob(snapshotFileNameTracking);\n const rawContentTracking = bufferToString(blob, \"utf8\");\n const content = this.deserializeValue(rawContentTracking, this.serializer);\n this.jobTracking = new Map(content) as JobTrackingInfo<T>;\n\n assert(this.data.size() === 0, 0x069 /* \"On consensusOrderedCollection load, data size > 0\" */);\n const blob2 = await storage.readBlob(snapshotFileNameData);\n const rawContentData = bufferToString(blob2, \"utf8\");\n const content2 = this.deserializeValue(rawContentData, this.serializer) as T[];\n this.data.loadFrom(content2);\n }\n\n protected onDisconnect() {\n for (const [, { value, clientId }] of this.jobTracking) {\n if (clientId === this.runtime.clientId) {\n this.emit(\"localRelease\", value, false /* intentional */);\n }\n }\n }\n\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation) {\n const op: IConsensusOrderedCollectionOperation = message.contents;\n let value: IConsensusOrderedCollectionValue<T> | undefined;\n switch (op.opName) {\n case \"add\":\n this.addCore(this.deserializeValue(op.value, this.serializer) as T);\n break;\n\n case \"acquire\":\n value = this.acquireCore(op.acquireId, message.clientId);\n break;\n\n case \"complete\":\n this.completeCore(op.acquireId);\n break;\n\n case \"release\":\n this.releaseCore(op.acquireId);\n break;\n\n default: unreachableCase(op);\n }\n if (local) {\n // Resolve the pending promise for this operation now that we have received an ack for it.\n const resolve = localOpMetadata as PendingResolve<T>;\n resolve(value);\n }\n }\n }\n\n private async submit<TMessage extends IConsensusOrderedCollectionOperation>(\n message: TMessage,\n ): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n assert(this.isAttached(), 0x06a /* \"Trying to submit message while detached!\" */);\n\n return this.newAckBasedPromise<IConsensusOrderedCollectionValue<T> | undefined>((resolve) => {\n // Send the resolve function as the localOpMetadata. This will be provided back to us when the\n // op is ack'd.\n this.submitLocalMessage(message, resolve);\n // If we fail due to runtime being disposed, it's better to return undefined then unhandled exception.\n }).catch((error) => undefined);\n }\n\n private addCore(value: T) {\n this.data.add(value);\n this.emit(\"add\", value, true /* newlyAdded */);\n }\n\n private acquireCore(acquireId: string, clientId?: string): IConsensusOrderedCollectionValue<T> | undefined {\n if (this.data.size() === 0) {\n return undefined;\n }\n const value = this.data.remove();\n\n const value2: IConsensusOrderedCollectionValue<T> = {\n acquireId,\n value,\n };\n this.jobTracking.set(value2.acquireId, { value, clientId });\n\n this.emit(\"acquire\", value, clientId);\n return value2;\n }\n\n private async acquireInternal(): Promise<IConsensusOrderedCollectionValue<T> | undefined> {\n if (!this.isAttached()) {\n // can be undefined if queue is empty\n return this.acquireCore(uuid(), idForLocalUnattachedClient);\n }\n\n return this.submit<IConsensusOrderedCollectionAcquireOperation>({\n opName: \"acquire\",\n acquireId: uuid(),\n });\n }\n\n private removeClient(clientIdToRemove?: string) {\n const added: T[] = [];\n for (const [acquireId, { value, clientId }] of this.jobTracking) {\n if (clientId === clientIdToRemove) {\n this.jobTracking.delete(acquireId);\n this.data.add(value);\n added.push(value);\n }\n }\n\n // Raise all events only after all state changes are completed,\n // to guarantee same ordering of operations if collection is manipulated from events.\n added.map((value) => this.emit(\"add\", value, false /* newlyAdded */));\n }\n\n private serializeValue(value, serializer: IFluidSerializer) {\n return serializer.stringify(value, this.handle);\n }\n\n private deserializeValue(content: string, serializer: IFluidSerializer) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return serializer.parse(content);\n }\n\n protected 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/ordered-collection";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "1.0.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,UAAU,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,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/ordered-collection\";\nexport const pkgVersion = \"1.0.0\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/ordered-collection",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Consensus Collection",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -61,43 +61,30 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@fluidframework/common-utils": "^0.32.1",
|
|
64
|
-
"@fluidframework/core-interfaces": "^0.
|
|
65
|
-
"@fluidframework/datastore-definitions": "^0.
|
|
64
|
+
"@fluidframework/core-interfaces": "^1.0.0",
|
|
65
|
+
"@fluidframework/datastore-definitions": "^1.0.0",
|
|
66
66
|
"@fluidframework/protocol-definitions": "^0.1028.2000",
|
|
67
|
-
"@fluidframework/runtime-definitions": "^0.
|
|
68
|
-
"@fluidframework/runtime-utils": "^0.
|
|
69
|
-
"@fluidframework/shared-object-base": "^0.
|
|
67
|
+
"@fluidframework/runtime-definitions": "^1.0.0",
|
|
68
|
+
"@fluidframework/runtime-utils": "^1.0.0",
|
|
69
|
+
"@fluidframework/shared-object-base": "^1.0.0",
|
|
70
70
|
"uuid": "^8.3.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@fluid-internal/test-dds-utils": "^0.
|
|
73
|
+
"@fluid-internal/test-dds-utils": "^1.0.0",
|
|
74
74
|
"@fluidframework/build-common": "^0.23.0",
|
|
75
|
-
"@fluidframework/build-tools": "^0.2.
|
|
75
|
+
"@fluidframework/build-tools": "^0.2.71273",
|
|
76
76
|
"@fluidframework/eslint-config-fluid": "^0.28.2000",
|
|
77
|
-
"@fluidframework/mocha-test-setup": "^0.
|
|
78
|
-
"@fluidframework/ordered-collection-previous": "npm:@fluidframework/ordered-collection
|
|
79
|
-
"@fluidframework/test-runtime-utils": "^0.
|
|
77
|
+
"@fluidframework/mocha-test-setup": "^1.0.0",
|
|
78
|
+
"@fluidframework/ordered-collection-previous": "npm:@fluidframework/ordered-collection@^0.59.0",
|
|
79
|
+
"@fluidframework/test-runtime-utils": "^1.0.0",
|
|
80
80
|
"@microsoft/api-extractor": "^7.22.2",
|
|
81
81
|
"@rushstack/eslint-config": "^2.5.1",
|
|
82
82
|
"@types/mocha": "^9.1.1",
|
|
83
83
|
"@types/node": "^14.18.0",
|
|
84
|
-
"@typescript-eslint/eslint-plugin": "~5.9.0",
|
|
85
|
-
"@typescript-eslint/parser": "~5.9.0",
|
|
86
84
|
"concurrently": "^6.2.0",
|
|
87
85
|
"copyfiles": "^2.1.0",
|
|
88
86
|
"cross-env": "^7.0.2",
|
|
89
87
|
"eslint": "~8.6.0",
|
|
90
|
-
"eslint-plugin-editorconfig": "~3.2.0",
|
|
91
|
-
"eslint-plugin-eslint-comments": "~3.2.0",
|
|
92
|
-
"eslint-plugin-import": "~2.25.4",
|
|
93
|
-
"eslint-plugin-jest": "~26.1.3",
|
|
94
|
-
"eslint-plugin-jsdoc": "~39.3.0",
|
|
95
|
-
"eslint-plugin-mocha": "~10.0.3",
|
|
96
|
-
"eslint-plugin-promise": "~6.0.0",
|
|
97
|
-
"eslint-plugin-react": "~7.28.0",
|
|
98
|
-
"eslint-plugin-tsdoc": "~0.2.14",
|
|
99
|
-
"eslint-plugin-unicorn": "~40.0.0",
|
|
100
|
-
"eslint-plugin-unused-imports": "~2.0.0",
|
|
101
88
|
"mocha": "^10.0.0",
|
|
102
89
|
"nyc": "^15.0.0",
|
|
103
90
|
"rimraf": "^2.6.2",
|
|
@@ -105,7 +92,7 @@
|
|
|
105
92
|
"typescript-formatter": "7.1.0"
|
|
106
93
|
},
|
|
107
94
|
"typeValidation": {
|
|
108
|
-
"version": "0.
|
|
95
|
+
"version": "1.0.0",
|
|
109
96
|
"broken": {}
|
|
110
97
|
}
|
|
111
98
|
}
|
|
@@ -107,7 +107,7 @@ export class ConsensusOrderedCollection<T = any>
|
|
|
107
107
|
attributes: IChannelAttributes,
|
|
108
108
|
private readonly data: IOrderedCollection<T>,
|
|
109
109
|
) {
|
|
110
|
-
super(id, runtime, attributes);
|
|
110
|
+
super(id, runtime, attributes, "fluid_consensusOrderedCollection_");
|
|
111
111
|
|
|
112
112
|
// We can't simply call this.removeClient(this.runtime.clientId) in on runtime disconnected,
|
|
113
113
|
// because other clients may disconnect concurrently.
|
package/src/packageVersion.ts
CHANGED