@fluid-experimental/pact-map 2.0.0-internal.6.2.0 → 2.0.0-internal.6.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/CHANGELOG.md +4 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pactMap.js +3 -3
- package/dist/pactMap.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/pactMap.js +1 -1
- package/lib/pactMap.js.map +1 -1
- package/package.json +16 -18
- package/src/packageVersion.ts +1 -1
- package/src/pactMap.ts +1 -1
package/CHANGELOG.md
CHANGED
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 = "@fluid-experimental/pact-map";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-internal.6.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.6.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 = "@fluid-experimental/pact-map";
|
|
11
|
-
exports.pkgVersion = "2.0.0-internal.6.
|
|
11
|
+
exports.pkgVersion = "2.0.0-internal.6.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 = \"@fluid-experimental/pact-map\";\nexport const pkgVersion = \"2.0.0-internal.6.
|
|
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 = \"@fluid-experimental/pact-map\";\nexport const pkgVersion = \"2.0.0-internal.6.3.1\";\n"]}
|
package/dist/pactMap.js
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.PactMap = void 0;
|
|
8
8
|
/* eslint-disable unicorn/numeric-separators-style */
|
|
9
9
|
const events_1 = require("events");
|
|
10
|
-
const
|
|
10
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
11
11
|
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
12
12
|
const driver_utils_1 = require("@fluidframework/driver-utils");
|
|
13
13
|
const shared_object_base_1 = require("@fluidframework/shared-object-base");
|
|
@@ -128,8 +128,8 @@ class PactMap extends shared_object_base_1.SharedObject {
|
|
|
128
128
|
this.handleIncomingAccept = (key, clientId, sequenceNumber) => {
|
|
129
129
|
const pending = this.values.get(key)?.pending;
|
|
130
130
|
// We don't resubmit accepts on reconnect so this should only run for expected accepts.
|
|
131
|
-
(0,
|
|
132
|
-
(0,
|
|
131
|
+
(0, core_utils_1.assert)(pending !== undefined, 0x2f8 /* Unexpected accept op, nothing pending */);
|
|
132
|
+
(0, core_utils_1.assert)(pending.expectedSignoffs.includes(clientId), 0x2f9 /* Unexpected accept op, client not in expectedSignoffs */);
|
|
133
133
|
// Remove the client from the expected signoffs
|
|
134
134
|
pending.expectedSignoffs = pending.expectedSignoffs.filter((expectedClientId) => expectedClientId !== clientId);
|
|
135
135
|
if (pending.expectedSignoffs.length === 0) {
|
package/dist/pactMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pactMap.js","sourceRoot":"","sources":["../src/pactMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qDAAqD;AAErD,mCAAsC;AAEtC,+DAAsD;AACtD,+EAA8F;AAQ9F,+DAA4D;AAC5D,2EAI4C;AAC5C,qDAAkD;AAwElD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAa,OAAqB,SAAQ,iCAA4B;IAyBrE;;;;;;OAMG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAhBjC,WAAM,GAAyB,IAAI,GAAG,EAAE,CAAC;QAEzC,eAAU,GAAiB,IAAI,qBAAY,EAAE,CAAC;QAyH9C,sBAAiB,GAAG,CACpC,GAAW,EACX,KAAoB,EACpB,MAAc,EACd,iBAAyB,EAClB,EAAE;YACT,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC1C,wGAAwG;YACxG,yGAAyG;YACzG,2BAA2B;YAC3B,MAAM,aAAa,GAClB,YAAY,KAAK,SAAS;gBAC1B,CAAC,YAAY,CAAC,OAAO,KAAK,SAAS,IAAI,YAAY,CAAC,QAAQ,CAAC,cAAc,IAAI,MAAM,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,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACpD,IACC,YAAY,KAAK,SAAS;YAC1B,CAAC,YAAY,CAAC,OAAO,KAAK,SAAS;gBAClC,SAAS,CAAC,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,cAAc,CAAC,EACzD;YACD,OAAO;SACP;QAED,4BAA4B;QAC5B,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;;OAQG;IACO,WAAW,CACpB,OAAkC,EAClC,KAAc,EACd,eAAwB;QAExB,IAAI,OAAO,CAAC,IAAI,KAAK,kCAAW,CAAC,SAAS,EAAE;YAC3C,MAAM,EAAE,GAAG,OAAO,CAAC,QAAgC,CAAC;YAEpD,QAAQ,EAAE,CAAC,IAAI,EAAE;gBAChB,KAAK,KAAK;oBACT,IAAI,CAAC,UAAU,CAAC,IAAI,CACnB,KAAK,EACL,EAAE,CAAC,GAAG,EACN,EAAE,CAAC,KAAK,EACR,EAAE,CAAC,MAAM,EACT,OAAO,CAAC,cAAc,CACtB,CAAC;oBACF,MAAM;gBAEP,KAAK,QAAQ;oBACZ,IAAI,CAAC,UAAU,CAAC,IAAI,CACnB,QAAQ,EACR,EAAE,CAAC,GAAG,EACN,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,cAAc,CACtB,CAAC;oBACF,MAAM;gBAEP;oBACC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aACtC;SACD;IACF,CAAC;IAEM,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AAvWD,0BAuWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable unicorn/numeric-separators-style */\n\nimport { EventEmitter } from \"events\";\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport {\n\tcreateSingleBlobSummary,\n\tIFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base\";\nimport { PactMapFactory } from \"./pactMapFactory\";\nimport { IAcceptedPact, IPactMap, IPactMapEvents } from \"./interfaces\";\n\n/**\n * The accepted pact information, if any.\n */\ninterface IAcceptedPactInternal<T> {\n\t/**\n\t * The accepted value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\n\t/**\n\t * The sequence number when the value was accepted, which will normally coincide with one of two possibilities:\n\t * - The sequence number of the \"accept\" op from the final client we expected signoff from\n\t * - The sequence number of the ClientLeave of the final client we expected signoff from\n\t *\n\t * For values set in detached state, it will be 0.\n\t */\n\tsequenceNumber: number;\n}\n\n/**\n * The pending pact information, if any.\n */\ninterface IPendingPact<T> {\n\t/**\n\t * The pending value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\t/**\n\t * The list of clientIds that we expect \"accept\" ops from. Clients are also removed from this list if they\n\t * disconnect without accepting. When this list empties, the pending value transitions to accepted.\n\t */\n\texpectedSignoffs: string[];\n}\n\n/**\n * Internal format of the values stored in the PactMap.\n */\ntype Pact<T> =\n\t| { accepted: IAcceptedPactInternal<T>; pending: undefined }\n\t| { accepted: undefined; pending: IPendingPact<T> }\n\t| { accepted: IAcceptedPactInternal<T>; pending: IPendingPact<T> };\n\n/**\n * PactMap operation formats\n */\ninterface IPactMapSetOperation<T> {\n\ttype: \"set\";\n\tkey: string;\n\tvalue: T | undefined;\n\n\t/**\n\t * A \"set\" is only valid if it is made with knowledge of the most-recent accepted proposal - its reference\n\t * sequence number is greater than or equal to the sequence number when that prior value was accepted.\n\t *\n\t * However, we can't trust the built-in referenceSequenceNumber of the op because of resubmit on reconnect,\n\t * which will update the referenceSequenceNumber on our behalf.\n\t *\n\t * Instead we need to separately stamp the real reference sequence number on the op itself.\n\t */\n\trefSeq: number;\n}\n\ninterface IPactMapAcceptOperation {\n\ttype: \"accept\";\n\tkey: string;\n}\n\ntype IPactMapOperation<T> = IPactMapSetOperation<T> | IPactMapAcceptOperation;\n\nconst snapshotFileName = \"header\";\n\n/**\n * The PactMap distributed data structure provides key/value storage with a cautious conflict resolution strategy.\n * This strategy optimizes for all clients being aware of the change prior to considering the value as accepted.\n *\n * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.\n *\n * @remarks\n * ### Creation\n *\n * To create a `PactMap`, call the static create method:\n *\n * ```typescript\n * const pactMap = PactMap.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * Setting and reading values is somewhat similar to a `SharedMap`. However, because the acceptance strategy\n * cannot be resolved until other clients have witnessed the set, the new value will only be reflected in the data\n * after the consensus is reached.\n *\n * ```typescript\n * pactMap.on(\"pending\", (key: string) => {\n * console.log(pactMap.getPending(key));\n * });\n * pactMap.on(\"accepted\", (key: string) => {\n * console.log(pactMap.get(key));\n * });\n * pactMap.set(\"myKey\", \"myValue\");\n *\n * // Reading from the pact map prior to the async operation's completion will still return the old value.\n * console.log(pactMap.get(\"myKey\"));\n * ```\n *\n * The acceptance process has two stages. When an op indicating a client's attempt to set a value is sequenced,\n * we first verify that it was set with knowledge of the most recently accepted value (consensus-like FWW). If it\n * meets this bar, then the value is \"pending\". During this time, clients may observe the pending value and act\n * upon it, but should be aware that not all other clients may have witnessed the value yet. Once all clients\n * that were connected at the time of the value being set have explicitly acknowledged the new value, the value\n * becomes \"accepted\". Once the value is accepted, it once again becomes possible to set the value, again with\n * consensus-like FWW resolution.\n *\n * Since all connected clients must explicitly accept the new value, it is important that all connected clients\n * have the PactMap loaded, including e.g. the summarizing client. Otherwise, those clients who have not loaded\n * the PactMap will not be responding to proposals and delay their acceptance (until they disconnect, which implicitly\n * removes them from consideration). The easiest way to ensure all clients load the PactMap is to instantiate it\n * as part of instantiating the IRuntime for the container (containerHasInitialized if using Aqueduct).\n *\n * ### Eventing\n *\n * `PactMap` is an `EventEmitter`, and will emit events when a new value is accepted for a key.\n *\n * ```typescript\n * pactMap.on(\"accept\", (key: string) => {\n * console.log(`New value was accepted for key: ${ key }, value: ${ pactMap.get(key) }`);\n * });\n * ```\n */\nexport class PactMap<T = unknown> extends SharedObject<IPactMapEvents> implements IPactMap<T> {\n\t/**\n\t * Create a new PactMap\n\t *\n\t * @param runtime - data store runtime the new PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t * @returns newly created PactMap (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string): PactMap {\n\t\treturn runtime.createChannel(id, PactMapFactory.Type) as PactMap;\n\t}\n\n\t/**\n\t * Get a factory for PactMap to register with the data store.\n\t *\n\t * @returns a factory that creates and loads PactMaps\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new PactMapFactory();\n\t}\n\n\tprivate readonly values: Map<string, Pact<T>> = new Map();\n\n\tprivate readonly incomingOp: EventEmitter = new EventEmitter();\n\n\t/**\n\t * Constructs a new PactMap. If the object is non-local an id and service interfaces will\n\t * be provided\n\t *\n\t * @param runtime - data store runtime the PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_pactMap_\");\n\n\t\tthis.incomingOp.on(\"set\", this.handleIncomingSet);\n\t\tthis.incomingOp.on(\"accept\", this.handleIncomingAccept);\n\n\t\tthis.runtime.getQuorum().on(\"removeMember\", this.handleQuorumRemoveMember);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.get}\n\t */\n\tpublic get(key: string): T | undefined {\n\t\treturn this.values.get(key)?.accepted?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getWithDetails}\n\t */\n\tpublic getWithDetails(key: string): IAcceptedPact<T> | undefined {\n\t\t// Note: We return type `IAcceptedPact` instead of `IAcceptedPactInternal` since we may want to diverge\n\t\t// the interfaces in the future.\n\t\tconst acceptedPact = this.values.get(key)?.accepted;\n\t\tif (acceptedPact === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tvalue: acceptedPact.value,\n\t\t\tacceptedSequenceNumber: acceptedPact.sequenceNumber,\n\t\t};\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.isPending}\n\t */\n\tpublic isPending(key: string): boolean {\n\t\treturn this.values.get(key)?.pending !== undefined;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getPending}\n\t */\n\tpublic getPending(key: string): T | undefined {\n\t\treturn this.values.get(key)?.pending?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.set}\n\t */\n\tpublic set(key: string, value: T | undefined): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if we can't submit a valid proposal (there's already a pending proposal)\n\t\tif (currentValue?.pending !== undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If not attached, we basically pretend we got an ack immediately.\n\t\tif (!this.isAttached()) {\n\t\t\t// Queueing as a microtask to permit callers to complete their callstacks before the result of the set\n\t\t\t// takes effect. This more closely resembles the pattern in the attached state, where the ack will not\n\t\t\t// be received synchronously.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.handleIncomingSet(key, value, 0 /* refSeq */, 0 /* setSequenceNumber */);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst setOp: IPactMapSetOperation<T> = {\n\t\t\ttype: \"set\",\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\trefSeq: this.runtime.deltaManager.lastSequenceNumber,\n\t\t};\n\n\t\tthis.submitLocalMessage(setOp);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.delete}\n\t */\n\tpublic delete(key: string): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if:\n\t\tif (\n\t\t\t// there's nothing to delete\n\t\t\tcurrentValue === undefined ||\n\t\t\t// if something is pending (and so our proposal won't be valid)\n\t\t\tcurrentValue.pending !== undefined ||\n\t\t\t// or if the accepted value is undefined which is equivalent to already being deleted\n\t\t\tcurrentValue.accepted.value === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.set(key, undefined);\n\t}\n\n\t/**\n\t * Get a point-in-time list of clients who must sign off on values coming in for them to move from \"pending\" to\n\t * \"accepted\" state. This list is finalized for a value at the moment it goes pending (i.e. if more clients\n\t * join later, they are not added to the list of signoffs).\n\t * @returns The list of clientIds for clients who must sign off to accept the incoming pending value\n\t */\n\tprivate getSignoffClients(): string[] {\n\t\t// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.\n\t\treturn this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];\n\t}\n\n\tprivate readonly handleIncomingSet = (\n\t\tkey: string,\n\t\tvalue: T | undefined,\n\t\trefSeq: number,\n\t\tsetSequenceNumber: number,\n\t): void => {\n\t\tconst currentValue = this.values.get(key);\n\t\t// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no\n\t\t// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid\n\t\t// proposals on the ground.\n\t\tconst proposalValid =\n\t\t\tcurrentValue === undefined ||\n\t\t\t(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);\n\t\tif (!proposalValid) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst accepted = currentValue?.accepted;\n\n\t\t// We expect signoffs from all connected clients at the time the set was sequenced (including the client who\n\t\t// sent the set).\n\t\tconst expectedSignoffs = this.getSignoffClients();\n\n\t\tconst newPact: Pact<T> = {\n\t\t\taccepted,\n\t\t\tpending: {\n\t\t\t\tvalue,\n\t\t\t\texpectedSignoffs,\n\t\t\t},\n\t\t};\n\n\t\tthis.values.set(key, newPact);\n\n\t\tthis.emit(\"pending\", key);\n\n\t\tif (expectedSignoffs.length === 0) {\n\t\t\t// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around\n\t\t\t// as extra protection and in case we bring back the \"submitting client implicitly accepts\" optimization.\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value, sequenceNumber: setSequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t} else if (\n\t\t\tthis.runtime.clientId !== undefined &&\n\t\t\texpectedSignoffs.includes(this.runtime.clientId)\n\t\t) {\n\t\t\t// Emit an accept upon a new key entering pending state if our accept is expected.\n\t\t\tconst acceptOp: IPactMapAcceptOperation = {\n\t\t\t\ttype: \"accept\",\n\t\t\t\tkey,\n\t\t\t};\n\t\t\tthis.submitLocalMessage(acceptOp);\n\t\t}\n\t};\n\n\tprivate readonly handleIncomingAccept = (\n\t\tkey: string,\n\t\tclientId: string,\n\t\tsequenceNumber: number,\n\t): void => {\n\t\tconst pending = this.values.get(key)?.pending;\n\t\t// We don't resubmit accepts on reconnect so this should only run for expected accepts.\n\t\tassert(pending !== undefined, 0x2f8 /* Unexpected accept op, nothing pending */);\n\t\tassert(\n\t\t\tpending.expectedSignoffs.includes(clientId),\n\t\t\t0x2f9 /* Unexpected accept op, client not in expectedSignoffs */,\n\t\t);\n\n\t\t// Remove the client from the expected signoffs\n\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t);\n\n\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t// The pending value has settled\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value: pending.value, sequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t}\n\t};\n\n\tprivate readonly handleQuorumRemoveMember = (clientId: string): void => {\n\t\tfor (const [key, { pending }] of this.values) {\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t\t\t);\n\n\t\t\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t\t\t// The pending value has settled\n\t\t\t\t\tconst clientLeaveSequenceNumber = this.runtime.deltaManager.lastSequenceNumber;\n\t\t\t\t\tthis.values.set(key, {\n\t\t\t\t\t\taccepted: {\n\t\t\t\t\t\t\tvalue: pending.value,\n\t\t\t\t\t\t\t// The sequence number of the ClientLeave message.\n\t\t\t\t\t\t\tsequenceNumber: clientLeaveSequenceNumber,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpending: undefined,\n\t\t\t\t\t});\n\t\t\t\t\tthis.emit(\"accepted\", key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Create a summary for the PactMap\n\t *\n\t * @returns the summary of the current state of the PactMap\n\t * @internal\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst allEntries = [...this.values.entries()];\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(allEntries));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t * @internal\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<[string, Pact<T>][]>(storage, snapshotFileName);\n\t\tfor (const [key, value] of content) {\n\t\t\tthis.values.set(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.initializeLocalCore}\n\t * @internal\n\t */\n\tprotected initializeLocalCore(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.onDisconnect}\n\t * @internal\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.reSubmitCore}\n\t * @internal\n\t */\n\tprotected reSubmitCore(content: unknown, localOpMetadata: unknown): void {\n\t\tconst pactMapOp = content as IPactMapOperation<T>;\n\t\t// Filter out accept messages - if we're coming back from a disconnect, our acceptance is never required\n\t\t// because we're implicitly removed from the list of expected accepts.\n\t\tif (pactMapOp.type === \"accept\") {\n\t\t\treturn;\n\t\t}\n\n\t\t// Filter out set messages that have no chance of being accepted because there's another value pending\n\t\t// or another value was accepted while we were disconnected.\n\t\tconst currentValue = this.values.get(pactMapOp.key);\n\t\tif (\n\t\t\tcurrentValue !== undefined &&\n\t\t\t(currentValue.pending !== undefined ||\n\t\t\t\tpactMapOp.refSeq < currentValue.accepted?.sequenceNumber)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise we can resubmit\n\t\tthis.submitLocalMessage(pactMapOp, localOpMetadata);\n\t}\n\n\t/**\n\t * Process a PactMap operation\n\t *\n\t * @param message - the message to prepare\n\t * @param local - whether the message was sent by the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t * @internal\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\tif (message.type === MessageType.Operation) {\n\t\t\tconst op = message.contents as IPactMapOperation<T>;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"set\":\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"set\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\top.value,\n\t\t\t\t\t\top.refSeq,\n\t\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"accept\":\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"accept\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\tmessage.clientId,\n\t\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pactMap.js","sourceRoot":"","sources":["../src/pactMap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qDAAqD;AAErD,mCAAsC;AAEtC,2DAAoD;AACpD,+EAA8F;AAQ9F,+DAA4D;AAC5D,2EAI4C;AAC5C,qDAAkD;AAwElD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAa,OAAqB,SAAQ,iCAA4B;IAyBrE;;;;;;OAMG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAhBjC,WAAM,GAAyB,IAAI,GAAG,EAAE,CAAC;QAEzC,eAAU,GAAiB,IAAI,qBAAY,EAAE,CAAC;QAyH9C,sBAAiB,GAAG,CACpC,GAAW,EACX,KAAoB,EACpB,MAAc,EACd,iBAAyB,EAClB,EAAE;YACT,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC1C,wGAAwG;YACxG,yGAAyG;YACzG,2BAA2B;YAC3B,MAAM,aAAa,GAClB,YAAY,KAAK,SAAS;gBAC1B,CAAC,YAAY,CAAC,OAAO,KAAK,SAAS,IAAI,YAAY,CAAC,QAAQ,CAAC,cAAc,IAAI,MAAM,CAAC,CAAC;YACxF,IAAI,CAAC,aAAa,EAAE;gBACnB,OAAO;aACP;YAED,MAAM,QAAQ,GAAG,YAAY,EAAE,QAAQ,CAAC;YAExC,4GAA4G;YAC5G,iBAAiB;YACjB,MAAM,gBAAgB,GAAG,IAAI,CAAC,iB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AC,EACzD;YACD,OAAO;SACP;QAED,4BAA4B;QAC5B,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;;OAQG;IACO,WAAW,CACpB,OAAkC,EAClC,KAAc,EACd,eAAwB;QAExB,IAAI,OAAO,CAAC,IAAI,KAAK,kCAAW,CAAC,SAAS,EAAE;YAC3C,MAAM,EAAE,GAAG,OAAO,CAAC,QAAgC,CAAC;YAEpD,QAAQ,EAAE,CAAC,IAAI,EAAE;gBAChB,KAAK,KAAK;oBACT,IAAI,CAAC,UAAU,CAAC,IAAI,CACnB,KAAK,EACL,EAAE,CAAC,GAAG,EACN,EAAE,CAAC,KAAK,EACR,EAAE,CAAC,MAAM,EACT,OAAO,CAAC,cAAc,CACtB,CAAC;oBACF,MAAM;gBAEP,KAAK,QAAQ;oBACZ,IAAI,CAAC,UAAU,CAAC,IAAI,CACnB,QAAQ,EACR,EAAE,CAAC,GAAG,EACN,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,cAAc,CACtB,CAAC;oBACF,MAAM;gBAEP;oBACC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aACtC;SACD;IACF,CAAC;IAEM,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD;AAvWD,0BAuWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable unicorn/numeric-separators-style */\n\nimport { EventEmitter } from \"events\";\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport {\n\tcreateSingleBlobSummary,\n\tIFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base\";\nimport { PactMapFactory } from \"./pactMapFactory\";\nimport { IAcceptedPact, IPactMap, IPactMapEvents } from \"./interfaces\";\n\n/**\n * The accepted pact information, if any.\n */\ninterface IAcceptedPactInternal<T> {\n\t/**\n\t * The accepted value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\n\t/**\n\t * The sequence number when the value was accepted, which will normally coincide with one of two possibilities:\n\t * - The sequence number of the \"accept\" op from the final client we expected signoff from\n\t * - The sequence number of the ClientLeave of the final client we expected signoff from\n\t *\n\t * For values set in detached state, it will be 0.\n\t */\n\tsequenceNumber: number;\n}\n\n/**\n * The pending pact information, if any.\n */\ninterface IPendingPact<T> {\n\t/**\n\t * The pending value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\t/**\n\t * The list of clientIds that we expect \"accept\" ops from. Clients are also removed from this list if they\n\t * disconnect without accepting. When this list empties, the pending value transitions to accepted.\n\t */\n\texpectedSignoffs: string[];\n}\n\n/**\n * Internal format of the values stored in the PactMap.\n */\ntype Pact<T> =\n\t| { accepted: IAcceptedPactInternal<T>; pending: undefined }\n\t| { accepted: undefined; pending: IPendingPact<T> }\n\t| { accepted: IAcceptedPactInternal<T>; pending: IPendingPact<T> };\n\n/**\n * PactMap operation formats\n */\ninterface IPactMapSetOperation<T> {\n\ttype: \"set\";\n\tkey: string;\n\tvalue: T | undefined;\n\n\t/**\n\t * A \"set\" is only valid if it is made with knowledge of the most-recent accepted proposal - its reference\n\t * sequence number is greater than or equal to the sequence number when that prior value was accepted.\n\t *\n\t * However, we can't trust the built-in referenceSequenceNumber of the op because of resubmit on reconnect,\n\t * which will update the referenceSequenceNumber on our behalf.\n\t *\n\t * Instead we need to separately stamp the real reference sequence number on the op itself.\n\t */\n\trefSeq: number;\n}\n\ninterface IPactMapAcceptOperation {\n\ttype: \"accept\";\n\tkey: string;\n}\n\ntype IPactMapOperation<T> = IPactMapSetOperation<T> | IPactMapAcceptOperation;\n\nconst snapshotFileName = \"header\";\n\n/**\n * The PactMap distributed data structure provides key/value storage with a cautious conflict resolution strategy.\n * This strategy optimizes for all clients being aware of the change prior to considering the value as accepted.\n *\n * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.\n *\n * @remarks\n * ### Creation\n *\n * To create a `PactMap`, call the static create method:\n *\n * ```typescript\n * const pactMap = PactMap.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * Setting and reading values is somewhat similar to a `SharedMap`. However, because the acceptance strategy\n * cannot be resolved until other clients have witnessed the set, the new value will only be reflected in the data\n * after the consensus is reached.\n *\n * ```typescript\n * pactMap.on(\"pending\", (key: string) => {\n * console.log(pactMap.getPending(key));\n * });\n * pactMap.on(\"accepted\", (key: string) => {\n * console.log(pactMap.get(key));\n * });\n * pactMap.set(\"myKey\", \"myValue\");\n *\n * // Reading from the pact map prior to the async operation's completion will still return the old value.\n * console.log(pactMap.get(\"myKey\"));\n * ```\n *\n * The acceptance process has two stages. When an op indicating a client's attempt to set a value is sequenced,\n * we first verify that it was set with knowledge of the most recently accepted value (consensus-like FWW). If it\n * meets this bar, then the value is \"pending\". During this time, clients may observe the pending value and act\n * upon it, but should be aware that not all other clients may have witnessed the value yet. Once all clients\n * that were connected at the time of the value being set have explicitly acknowledged the new value, the value\n * becomes \"accepted\". Once the value is accepted, it once again becomes possible to set the value, again with\n * consensus-like FWW resolution.\n *\n * Since all connected clients must explicitly accept the new value, it is important that all connected clients\n * have the PactMap loaded, including e.g. the summarizing client. Otherwise, those clients who have not loaded\n * the PactMap will not be responding to proposals and delay their acceptance (until they disconnect, which implicitly\n * removes them from consideration). The easiest way to ensure all clients load the PactMap is to instantiate it\n * as part of instantiating the IRuntime for the container (containerHasInitialized if using Aqueduct).\n *\n * ### Eventing\n *\n * `PactMap` is an `EventEmitter`, and will emit events when a new value is accepted for a key.\n *\n * ```typescript\n * pactMap.on(\"accept\", (key: string) => {\n * console.log(`New value was accepted for key: ${ key }, value: ${ pactMap.get(key) }`);\n * });\n * ```\n */\nexport class PactMap<T = unknown> extends SharedObject<IPactMapEvents> implements IPactMap<T> {\n\t/**\n\t * Create a new PactMap\n\t *\n\t * @param runtime - data store runtime the new PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t * @returns newly created PactMap (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string): PactMap {\n\t\treturn runtime.createChannel(id, PactMapFactory.Type) as PactMap;\n\t}\n\n\t/**\n\t * Get a factory for PactMap to register with the data store.\n\t *\n\t * @returns a factory that creates and loads PactMaps\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new PactMapFactory();\n\t}\n\n\tprivate readonly values: Map<string, Pact<T>> = new Map();\n\n\tprivate readonly incomingOp: EventEmitter = new EventEmitter();\n\n\t/**\n\t * Constructs a new PactMap. If the object is non-local an id and service interfaces will\n\t * be provided\n\t *\n\t * @param runtime - data store runtime the PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_pactMap_\");\n\n\t\tthis.incomingOp.on(\"set\", this.handleIncomingSet);\n\t\tthis.incomingOp.on(\"accept\", this.handleIncomingAccept);\n\n\t\tthis.runtime.getQuorum().on(\"removeMember\", this.handleQuorumRemoveMember);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.get}\n\t */\n\tpublic get(key: string): T | undefined {\n\t\treturn this.values.get(key)?.accepted?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getWithDetails}\n\t */\n\tpublic getWithDetails(key: string): IAcceptedPact<T> | undefined {\n\t\t// Note: We return type `IAcceptedPact` instead of `IAcceptedPactInternal` since we may want to diverge\n\t\t// the interfaces in the future.\n\t\tconst acceptedPact = this.values.get(key)?.accepted;\n\t\tif (acceptedPact === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tvalue: acceptedPact.value,\n\t\t\tacceptedSequenceNumber: acceptedPact.sequenceNumber,\n\t\t};\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.isPending}\n\t */\n\tpublic isPending(key: string): boolean {\n\t\treturn this.values.get(key)?.pending !== undefined;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getPending}\n\t */\n\tpublic getPending(key: string): T | undefined {\n\t\treturn this.values.get(key)?.pending?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.set}\n\t */\n\tpublic set(key: string, value: T | undefined): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if we can't submit a valid proposal (there's already a pending proposal)\n\t\tif (currentValue?.pending !== undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If not attached, we basically pretend we got an ack immediately.\n\t\tif (!this.isAttached()) {\n\t\t\t// Queueing as a microtask to permit callers to complete their callstacks before the result of the set\n\t\t\t// takes effect. This more closely resembles the pattern in the attached state, where the ack will not\n\t\t\t// be received synchronously.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.handleIncomingSet(key, value, 0 /* refSeq */, 0 /* setSequenceNumber */);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst setOp: IPactMapSetOperation<T> = {\n\t\t\ttype: \"set\",\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\trefSeq: this.runtime.deltaManager.lastSequenceNumber,\n\t\t};\n\n\t\tthis.submitLocalMessage(setOp);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.delete}\n\t */\n\tpublic delete(key: string): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if:\n\t\tif (\n\t\t\t// there's nothing to delete\n\t\t\tcurrentValue === undefined ||\n\t\t\t// if something is pending (and so our proposal won't be valid)\n\t\t\tcurrentValue.pending !== undefined ||\n\t\t\t// or if the accepted value is undefined which is equivalent to already being deleted\n\t\t\tcurrentValue.accepted.value === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.set(key, undefined);\n\t}\n\n\t/**\n\t * Get a point-in-time list of clients who must sign off on values coming in for them to move from \"pending\" to\n\t * \"accepted\" state. This list is finalized for a value at the moment it goes pending (i.e. if more clients\n\t * join later, they are not added to the list of signoffs).\n\t * @returns The list of clientIds for clients who must sign off to accept the incoming pending value\n\t */\n\tprivate getSignoffClients(): string[] {\n\t\t// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.\n\t\treturn this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];\n\t}\n\n\tprivate readonly handleIncomingSet = (\n\t\tkey: string,\n\t\tvalue: T | undefined,\n\t\trefSeq: number,\n\t\tsetSequenceNumber: number,\n\t): void => {\n\t\tconst currentValue = this.values.get(key);\n\t\t// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no\n\t\t// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid\n\t\t// proposals on the ground.\n\t\tconst proposalValid =\n\t\t\tcurrentValue === undefined ||\n\t\t\t(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);\n\t\tif (!proposalValid) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst accepted = currentValue?.accepted;\n\n\t\t// We expect signoffs from all connected clients at the time the set was sequenced (including the client who\n\t\t// sent the set).\n\t\tconst expectedSignoffs = this.getSignoffClients();\n\n\t\tconst newPact: Pact<T> = {\n\t\t\taccepted,\n\t\t\tpending: {\n\t\t\t\tvalue,\n\t\t\t\texpectedSignoffs,\n\t\t\t},\n\t\t};\n\n\t\tthis.values.set(key, newPact);\n\n\t\tthis.emit(\"pending\", key);\n\n\t\tif (expectedSignoffs.length === 0) {\n\t\t\t// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around\n\t\t\t// as extra protection and in case we bring back the \"submitting client implicitly accepts\" optimization.\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value, sequenceNumber: setSequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t} else if (\n\t\t\tthis.runtime.clientId !== undefined &&\n\t\t\texpectedSignoffs.includes(this.runtime.clientId)\n\t\t) {\n\t\t\t// Emit an accept upon a new key entering pending state if our accept is expected.\n\t\t\tconst acceptOp: IPactMapAcceptOperation = {\n\t\t\t\ttype: \"accept\",\n\t\t\t\tkey,\n\t\t\t};\n\t\t\tthis.submitLocalMessage(acceptOp);\n\t\t}\n\t};\n\n\tprivate readonly handleIncomingAccept = (\n\t\tkey: string,\n\t\tclientId: string,\n\t\tsequenceNumber: number,\n\t): void => {\n\t\tconst pending = this.values.get(key)?.pending;\n\t\t// We don't resubmit accepts on reconnect so this should only run for expected accepts.\n\t\tassert(pending !== undefined, 0x2f8 /* Unexpected accept op, nothing pending */);\n\t\tassert(\n\t\t\tpending.expectedSignoffs.includes(clientId),\n\t\t\t0x2f9 /* Unexpected accept op, client not in expectedSignoffs */,\n\t\t);\n\n\t\t// Remove the client from the expected signoffs\n\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t);\n\n\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t// The pending value has settled\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value: pending.value, sequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t}\n\t};\n\n\tprivate readonly handleQuorumRemoveMember = (clientId: string): void => {\n\t\tfor (const [key, { pending }] of this.values) {\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t\t\t);\n\n\t\t\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t\t\t// The pending value has settled\n\t\t\t\t\tconst clientLeaveSequenceNumber = this.runtime.deltaManager.lastSequenceNumber;\n\t\t\t\t\tthis.values.set(key, {\n\t\t\t\t\t\taccepted: {\n\t\t\t\t\t\t\tvalue: pending.value,\n\t\t\t\t\t\t\t// The sequence number of the ClientLeave message.\n\t\t\t\t\t\t\tsequenceNumber: clientLeaveSequenceNumber,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpending: undefined,\n\t\t\t\t\t});\n\t\t\t\t\tthis.emit(\"accepted\", key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Create a summary for the PactMap\n\t *\n\t * @returns the summary of the current state of the PactMap\n\t * @internal\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst allEntries = [...this.values.entries()];\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(allEntries));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t * @internal\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<[string, Pact<T>][]>(storage, snapshotFileName);\n\t\tfor (const [key, value] of content) {\n\t\t\tthis.values.set(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.initializeLocalCore}\n\t * @internal\n\t */\n\tprotected initializeLocalCore(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.onDisconnect}\n\t * @internal\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.reSubmitCore}\n\t * @internal\n\t */\n\tprotected reSubmitCore(content: unknown, localOpMetadata: unknown): void {\n\t\tconst pactMapOp = content as IPactMapOperation<T>;\n\t\t// Filter out accept messages - if we're coming back from a disconnect, our acceptance is never required\n\t\t// because we're implicitly removed from the list of expected accepts.\n\t\tif (pactMapOp.type === \"accept\") {\n\t\t\treturn;\n\t\t}\n\n\t\t// Filter out set messages that have no chance of being accepted because there's another value pending\n\t\t// or another value was accepted while we were disconnected.\n\t\tconst currentValue = this.values.get(pactMapOp.key);\n\t\tif (\n\t\t\tcurrentValue !== undefined &&\n\t\t\t(currentValue.pending !== undefined ||\n\t\t\t\tpactMapOp.refSeq < currentValue.accepted?.sequenceNumber)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise we can resubmit\n\t\tthis.submitLocalMessage(pactMapOp, localOpMetadata);\n\t}\n\n\t/**\n\t * Process a PactMap operation\n\t *\n\t * @param message - the message to prepare\n\t * @param local - whether the message was sent by the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t * @internal\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\tif (message.type === MessageType.Operation) {\n\t\t\tconst op = message.contents as IPactMapOperation<T>;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"set\":\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"set\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\top.value,\n\t\t\t\t\t\top.refSeq,\n\t\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"accept\":\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"accept\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\tmessage.clientId,\n\t\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\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 = "@fluid-experimental/pact-map";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-internal.6.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.6.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 = "@fluid-experimental/pact-map";
|
|
8
|
-
export const pkgVersion = "2.0.0-internal.6.
|
|
8
|
+
export const pkgVersion = "2.0.0-internal.6.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 = \"@fluid-experimental/pact-map\";\nexport const pkgVersion = \"2.0.0-internal.6.
|
|
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 = \"@fluid-experimental/pact-map\";\nexport const pkgVersion = \"2.0.0-internal.6.3.1\";\n"]}
|
package/lib/pactMap.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/* eslint-disable unicorn/numeric-separators-style */
|
|
6
6
|
import { EventEmitter } from "events";
|
|
7
|
-
import { assert } from "@fluidframework/
|
|
7
|
+
import { assert } from "@fluidframework/core-utils";
|
|
8
8
|
import { MessageType } from "@fluidframework/protocol-definitions";
|
|
9
9
|
import { readAndParse } from "@fluidframework/driver-utils";
|
|
10
10
|
import { createSingleBlobSummary, SharedObject, } from "@fluidframework/shared-object-base";
|
package/lib/pactMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pactMap.js","sourceRoot":"","sources":["../src/pactMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qDAAqD;AAErD,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,EACN,uBAAuB,EAEvB,YAAY,GACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAwElD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAM,OAAO,OAAqB,SAAQ,YAA4B;IAyBrE;;;;;;OAMG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QA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AAc,CACtB,CAAC;oBACF,MAAM;gBAEP;oBACC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aACtC;SACD;IACF,CAAC;IAEM,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable unicorn/numeric-separators-style */\n\nimport { EventEmitter } from \"events\";\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport {\n\tcreateSingleBlobSummary,\n\tIFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base\";\nimport { PactMapFactory } from \"./pactMapFactory\";\nimport { IAcceptedPact, IPactMap, IPactMapEvents } from \"./interfaces\";\n\n/**\n * The accepted pact information, if any.\n */\ninterface IAcceptedPactInternal<T> {\n\t/**\n\t * The accepted value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\n\t/**\n\t * The sequence number when the value was accepted, which will normally coincide with one of two possibilities:\n\t * - The sequence number of the \"accept\" op from the final client we expected signoff from\n\t * - The sequence number of the ClientLeave of the final client we expected signoff from\n\t *\n\t * For values set in detached state, it will be 0.\n\t */\n\tsequenceNumber: number;\n}\n\n/**\n * The pending pact information, if any.\n */\ninterface IPendingPact<T> {\n\t/**\n\t * The pending value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\t/**\n\t * The list of clientIds that we expect \"accept\" ops from. Clients are also removed from this list if they\n\t * disconnect without accepting. When this list empties, the pending value transitions to accepted.\n\t */\n\texpectedSignoffs: string[];\n}\n\n/**\n * Internal format of the values stored in the PactMap.\n */\ntype Pact<T> =\n\t| { accepted: IAcceptedPactInternal<T>; pending: undefined }\n\t| { accepted: undefined; pending: IPendingPact<T> }\n\t| { accepted: IAcceptedPactInternal<T>; pending: IPendingPact<T> };\n\n/**\n * PactMap operation formats\n */\ninterface IPactMapSetOperation<T> {\n\ttype: \"set\";\n\tkey: string;\n\tvalue: T | undefined;\n\n\t/**\n\t * A \"set\" is only valid if it is made with knowledge of the most-recent accepted proposal - its reference\n\t * sequence number is greater than or equal to the sequence number when that prior value was accepted.\n\t *\n\t * However, we can't trust the built-in referenceSequenceNumber of the op because of resubmit on reconnect,\n\t * which will update the referenceSequenceNumber on our behalf.\n\t *\n\t * Instead we need to separately stamp the real reference sequence number on the op itself.\n\t */\n\trefSeq: number;\n}\n\ninterface IPactMapAcceptOperation {\n\ttype: \"accept\";\n\tkey: string;\n}\n\ntype IPactMapOperation<T> = IPactMapSetOperation<T> | IPactMapAcceptOperation;\n\nconst snapshotFileName = \"header\";\n\n/**\n * The PactMap distributed data structure provides key/value storage with a cautious conflict resolution strategy.\n * This strategy optimizes for all clients being aware of the change prior to considering the value as accepted.\n *\n * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.\n *\n * @remarks\n * ### Creation\n *\n * To create a `PactMap`, call the static create method:\n *\n * ```typescript\n * const pactMap = PactMap.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * Setting and reading values is somewhat similar to a `SharedMap`. However, because the acceptance strategy\n * cannot be resolved until other clients have witnessed the set, the new value will only be reflected in the data\n * after the consensus is reached.\n *\n * ```typescript\n * pactMap.on(\"pending\", (key: string) => {\n * console.log(pactMap.getPending(key));\n * });\n * pactMap.on(\"accepted\", (key: string) => {\n * console.log(pactMap.get(key));\n * });\n * pactMap.set(\"myKey\", \"myValue\");\n *\n * // Reading from the pact map prior to the async operation's completion will still return the old value.\n * console.log(pactMap.get(\"myKey\"));\n * ```\n *\n * The acceptance process has two stages. When an op indicating a client's attempt to set a value is sequenced,\n * we first verify that it was set with knowledge of the most recently accepted value (consensus-like FWW). If it\n * meets this bar, then the value is \"pending\". During this time, clients may observe the pending value and act\n * upon it, but should be aware that not all other clients may have witnessed the value yet. Once all clients\n * that were connected at the time of the value being set have explicitly acknowledged the new value, the value\n * becomes \"accepted\". Once the value is accepted, it once again becomes possible to set the value, again with\n * consensus-like FWW resolution.\n *\n * Since all connected clients must explicitly accept the new value, it is important that all connected clients\n * have the PactMap loaded, including e.g. the summarizing client. Otherwise, those clients who have not loaded\n * the PactMap will not be responding to proposals and delay their acceptance (until they disconnect, which implicitly\n * removes them from consideration). The easiest way to ensure all clients load the PactMap is to instantiate it\n * as part of instantiating the IRuntime for the container (containerHasInitialized if using Aqueduct).\n *\n * ### Eventing\n *\n * `PactMap` is an `EventEmitter`, and will emit events when a new value is accepted for a key.\n *\n * ```typescript\n * pactMap.on(\"accept\", (key: string) => {\n * console.log(`New value was accepted for key: ${ key }, value: ${ pactMap.get(key) }`);\n * });\n * ```\n */\nexport class PactMap<T = unknown> extends SharedObject<IPactMapEvents> implements IPactMap<T> {\n\t/**\n\t * Create a new PactMap\n\t *\n\t * @param runtime - data store runtime the new PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t * @returns newly created PactMap (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string): PactMap {\n\t\treturn runtime.createChannel(id, PactMapFactory.Type) as PactMap;\n\t}\n\n\t/**\n\t * Get a factory for PactMap to register with the data store.\n\t *\n\t * @returns a factory that creates and loads PactMaps\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new PactMapFactory();\n\t}\n\n\tprivate readonly values: Map<string, Pact<T>> = new Map();\n\n\tprivate readonly incomingOp: EventEmitter = new EventEmitter();\n\n\t/**\n\t * Constructs a new PactMap. If the object is non-local an id and service interfaces will\n\t * be provided\n\t *\n\t * @param runtime - data store runtime the PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_pactMap_\");\n\n\t\tthis.incomingOp.on(\"set\", this.handleIncomingSet);\n\t\tthis.incomingOp.on(\"accept\", this.handleIncomingAccept);\n\n\t\tthis.runtime.getQuorum().on(\"removeMember\", this.handleQuorumRemoveMember);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.get}\n\t */\n\tpublic get(key: string): T | undefined {\n\t\treturn this.values.get(key)?.accepted?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getWithDetails}\n\t */\n\tpublic getWithDetails(key: string): IAcceptedPact<T> | undefined {\n\t\t// Note: We return type `IAcceptedPact` instead of `IAcceptedPactInternal` since we may want to diverge\n\t\t// the interfaces in the future.\n\t\tconst acceptedPact = this.values.get(key)?.accepted;\n\t\tif (acceptedPact === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tvalue: acceptedPact.value,\n\t\t\tacceptedSequenceNumber: acceptedPact.sequenceNumber,\n\t\t};\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.isPending}\n\t */\n\tpublic isPending(key: string): boolean {\n\t\treturn this.values.get(key)?.pending !== undefined;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getPending}\n\t */\n\tpublic getPending(key: string): T | undefined {\n\t\treturn this.values.get(key)?.pending?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.set}\n\t */\n\tpublic set(key: string, value: T | undefined): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if we can't submit a valid proposal (there's already a pending proposal)\n\t\tif (currentValue?.pending !== undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If not attached, we basically pretend we got an ack immediately.\n\t\tif (!this.isAttached()) {\n\t\t\t// Queueing as a microtask to permit callers to complete their callstacks before the result of the set\n\t\t\t// takes effect. This more closely resembles the pattern in the attached state, where the ack will not\n\t\t\t// be received synchronously.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.handleIncomingSet(key, value, 0 /* refSeq */, 0 /* setSequenceNumber */);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst setOp: IPactMapSetOperation<T> = {\n\t\t\ttype: \"set\",\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\trefSeq: this.runtime.deltaManager.lastSequenceNumber,\n\t\t};\n\n\t\tthis.submitLocalMessage(setOp);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.delete}\n\t */\n\tpublic delete(key: string): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if:\n\t\tif (\n\t\t\t// there's nothing to delete\n\t\t\tcurrentValue === undefined ||\n\t\t\t// if something is pending (and so our proposal won't be valid)\n\t\t\tcurrentValue.pending !== undefined ||\n\t\t\t// or if the accepted value is undefined which is equivalent to already being deleted\n\t\t\tcurrentValue.accepted.value === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.set(key, undefined);\n\t}\n\n\t/**\n\t * Get a point-in-time list of clients who must sign off on values coming in for them to move from \"pending\" to\n\t * \"accepted\" state. This list is finalized for a value at the moment it goes pending (i.e. if more clients\n\t * join later, they are not added to the list of signoffs).\n\t * @returns The list of clientIds for clients who must sign off to accept the incoming pending value\n\t */\n\tprivate getSignoffClients(): string[] {\n\t\t// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.\n\t\treturn this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];\n\t}\n\n\tprivate readonly handleIncomingSet = (\n\t\tkey: string,\n\t\tvalue: T | undefined,\n\t\trefSeq: number,\n\t\tsetSequenceNumber: number,\n\t): void => {\n\t\tconst currentValue = this.values.get(key);\n\t\t// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no\n\t\t// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid\n\t\t// proposals on the ground.\n\t\tconst proposalValid =\n\t\t\tcurrentValue === undefined ||\n\t\t\t(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);\n\t\tif (!proposalValid) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst accepted = currentValue?.accepted;\n\n\t\t// We expect signoffs from all connected clients at the time the set was sequenced (including the client who\n\t\t// sent the set).\n\t\tconst expectedSignoffs = this.getSignoffClients();\n\n\t\tconst newPact: Pact<T> = {\n\t\t\taccepted,\n\t\t\tpending: {\n\t\t\t\tvalue,\n\t\t\t\texpectedSignoffs,\n\t\t\t},\n\t\t};\n\n\t\tthis.values.set(key, newPact);\n\n\t\tthis.emit(\"pending\", key);\n\n\t\tif (expectedSignoffs.length === 0) {\n\t\t\t// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around\n\t\t\t// as extra protection and in case we bring back the \"submitting client implicitly accepts\" optimization.\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value, sequenceNumber: setSequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t} else if (\n\t\t\tthis.runtime.clientId !== undefined &&\n\t\t\texpectedSignoffs.includes(this.runtime.clientId)\n\t\t) {\n\t\t\t// Emit an accept upon a new key entering pending state if our accept is expected.\n\t\t\tconst acceptOp: IPactMapAcceptOperation = {\n\t\t\t\ttype: \"accept\",\n\t\t\t\tkey,\n\t\t\t};\n\t\t\tthis.submitLocalMessage(acceptOp);\n\t\t}\n\t};\n\n\tprivate readonly handleIncomingAccept = (\n\t\tkey: string,\n\t\tclientId: string,\n\t\tsequenceNumber: number,\n\t): void => {\n\t\tconst pending = this.values.get(key)?.pending;\n\t\t// We don't resubmit accepts on reconnect so this should only run for expected accepts.\n\t\tassert(pending !== undefined, 0x2f8 /* Unexpected accept op, nothing pending */);\n\t\tassert(\n\t\t\tpending.expectedSignoffs.includes(clientId),\n\t\t\t0x2f9 /* Unexpected accept op, client not in expectedSignoffs */,\n\t\t);\n\n\t\t// Remove the client from the expected signoffs\n\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t);\n\n\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t// The pending value has settled\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value: pending.value, sequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t}\n\t};\n\n\tprivate readonly handleQuorumRemoveMember = (clientId: string): void => {\n\t\tfor (const [key, { pending }] of this.values) {\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t\t\t);\n\n\t\t\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t\t\t// The pending value has settled\n\t\t\t\t\tconst clientLeaveSequenceNumber = this.runtime.deltaManager.lastSequenceNumber;\n\t\t\t\t\tthis.values.set(key, {\n\t\t\t\t\t\taccepted: {\n\t\t\t\t\t\t\tvalue: pending.value,\n\t\t\t\t\t\t\t// The sequence number of the ClientLeave message.\n\t\t\t\t\t\t\tsequenceNumber: clientLeaveSequenceNumber,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpending: undefined,\n\t\t\t\t\t});\n\t\t\t\t\tthis.emit(\"accepted\", key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Create a summary for the PactMap\n\t *\n\t * @returns the summary of the current state of the PactMap\n\t * @internal\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst allEntries = [...this.values.entries()];\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(allEntries));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t * @internal\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<[string, Pact<T>][]>(storage, snapshotFileName);\n\t\tfor (const [key, value] of content) {\n\t\t\tthis.values.set(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.initializeLocalCore}\n\t * @internal\n\t */\n\tprotected initializeLocalCore(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.onDisconnect}\n\t * @internal\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.reSubmitCore}\n\t * @internal\n\t */\n\tprotected reSubmitCore(content: unknown, localOpMetadata: unknown): void {\n\t\tconst pactMapOp = content as IPactMapOperation<T>;\n\t\t// Filter out accept messages - if we're coming back from a disconnect, our acceptance is never required\n\t\t// because we're implicitly removed from the list of expected accepts.\n\t\tif (pactMapOp.type === \"accept\") {\n\t\t\treturn;\n\t\t}\n\n\t\t// Filter out set messages that have no chance of being accepted because there's another value pending\n\t\t// or another value was accepted while we were disconnected.\n\t\tconst currentValue = this.values.get(pactMapOp.key);\n\t\tif (\n\t\t\tcurrentValue !== undefined &&\n\t\t\t(currentValue.pending !== undefined ||\n\t\t\t\tpactMapOp.refSeq < currentValue.accepted?.sequenceNumber)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise we can resubmit\n\t\tthis.submitLocalMessage(pactMapOp, localOpMetadata);\n\t}\n\n\t/**\n\t * Process a PactMap operation\n\t *\n\t * @param message - the message to prepare\n\t * @param local - whether the message was sent by the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t * @internal\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\tif (message.type === MessageType.Operation) {\n\t\t\tconst op = message.contents as IPactMapOperation<T>;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"set\":\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"set\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\top.value,\n\t\t\t\t\t\top.refSeq,\n\t\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"accept\":\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"accept\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\tmessage.clientId,\n\t\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pactMap.js","sourceRoot":"","sources":["../src/pactMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qDAAqD;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAA6B,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAQ9F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACN,uBAAuB,EAEvB,YAAY,GACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAwElD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAM,OAAO,OAAqB,SAAQ,YAA4B;IAyBrE;;;;;;OAMG;IACH,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAA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AC,cAAc,CACtB,CAAC;oBACF,MAAM;gBAEP;oBACC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aACtC;SACD;IACF,CAAC;IAEM,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable unicorn/numeric-separators-style */\n\nimport { EventEmitter } from \"events\";\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport {\n\tcreateSingleBlobSummary,\n\tIFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base\";\nimport { PactMapFactory } from \"./pactMapFactory\";\nimport { IAcceptedPact, IPactMap, IPactMapEvents } from \"./interfaces\";\n\n/**\n * The accepted pact information, if any.\n */\ninterface IAcceptedPactInternal<T> {\n\t/**\n\t * The accepted value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\n\t/**\n\t * The sequence number when the value was accepted, which will normally coincide with one of two possibilities:\n\t * - The sequence number of the \"accept\" op from the final client we expected signoff from\n\t * - The sequence number of the ClientLeave of the final client we expected signoff from\n\t *\n\t * For values set in detached state, it will be 0.\n\t */\n\tsequenceNumber: number;\n}\n\n/**\n * The pending pact information, if any.\n */\ninterface IPendingPact<T> {\n\t/**\n\t * The pending value of the given type or undefined (typically in case of delete).\n\t */\n\tvalue: T | undefined;\n\t/**\n\t * The list of clientIds that we expect \"accept\" ops from. Clients are also removed from this list if they\n\t * disconnect without accepting. When this list empties, the pending value transitions to accepted.\n\t */\n\texpectedSignoffs: string[];\n}\n\n/**\n * Internal format of the values stored in the PactMap.\n */\ntype Pact<T> =\n\t| { accepted: IAcceptedPactInternal<T>; pending: undefined }\n\t| { accepted: undefined; pending: IPendingPact<T> }\n\t| { accepted: IAcceptedPactInternal<T>; pending: IPendingPact<T> };\n\n/**\n * PactMap operation formats\n */\ninterface IPactMapSetOperation<T> {\n\ttype: \"set\";\n\tkey: string;\n\tvalue: T | undefined;\n\n\t/**\n\t * A \"set\" is only valid if it is made with knowledge of the most-recent accepted proposal - its reference\n\t * sequence number is greater than or equal to the sequence number when that prior value was accepted.\n\t *\n\t * However, we can't trust the built-in referenceSequenceNumber of the op because of resubmit on reconnect,\n\t * which will update the referenceSequenceNumber on our behalf.\n\t *\n\t * Instead we need to separately stamp the real reference sequence number on the op itself.\n\t */\n\trefSeq: number;\n}\n\ninterface IPactMapAcceptOperation {\n\ttype: \"accept\";\n\tkey: string;\n}\n\ntype IPactMapOperation<T> = IPactMapSetOperation<T> | IPactMapAcceptOperation;\n\nconst snapshotFileName = \"header\";\n\n/**\n * The PactMap distributed data structure provides key/value storage with a cautious conflict resolution strategy.\n * This strategy optimizes for all clients being aware of the change prior to considering the value as accepted.\n *\n * It is still experimental and under development. Please do try it out, but expect breaking changes in the future.\n *\n * @remarks\n * ### Creation\n *\n * To create a `PactMap`, call the static create method:\n *\n * ```typescript\n * const pactMap = PactMap.create(this.runtime, id);\n * ```\n *\n * ### Usage\n *\n * Setting and reading values is somewhat similar to a `SharedMap`. However, because the acceptance strategy\n * cannot be resolved until other clients have witnessed the set, the new value will only be reflected in the data\n * after the consensus is reached.\n *\n * ```typescript\n * pactMap.on(\"pending\", (key: string) => {\n * console.log(pactMap.getPending(key));\n * });\n * pactMap.on(\"accepted\", (key: string) => {\n * console.log(pactMap.get(key));\n * });\n * pactMap.set(\"myKey\", \"myValue\");\n *\n * // Reading from the pact map prior to the async operation's completion will still return the old value.\n * console.log(pactMap.get(\"myKey\"));\n * ```\n *\n * The acceptance process has two stages. When an op indicating a client's attempt to set a value is sequenced,\n * we first verify that it was set with knowledge of the most recently accepted value (consensus-like FWW). If it\n * meets this bar, then the value is \"pending\". During this time, clients may observe the pending value and act\n * upon it, but should be aware that not all other clients may have witnessed the value yet. Once all clients\n * that were connected at the time of the value being set have explicitly acknowledged the new value, the value\n * becomes \"accepted\". Once the value is accepted, it once again becomes possible to set the value, again with\n * consensus-like FWW resolution.\n *\n * Since all connected clients must explicitly accept the new value, it is important that all connected clients\n * have the PactMap loaded, including e.g. the summarizing client. Otherwise, those clients who have not loaded\n * the PactMap will not be responding to proposals and delay their acceptance (until they disconnect, which implicitly\n * removes them from consideration). The easiest way to ensure all clients load the PactMap is to instantiate it\n * as part of instantiating the IRuntime for the container (containerHasInitialized if using Aqueduct).\n *\n * ### Eventing\n *\n * `PactMap` is an `EventEmitter`, and will emit events when a new value is accepted for a key.\n *\n * ```typescript\n * pactMap.on(\"accept\", (key: string) => {\n * console.log(`New value was accepted for key: ${ key }, value: ${ pactMap.get(key) }`);\n * });\n * ```\n */\nexport class PactMap<T = unknown> extends SharedObject<IPactMapEvents> implements IPactMap<T> {\n\t/**\n\t * Create a new PactMap\n\t *\n\t * @param runtime - data store runtime the new PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t * @returns newly created PactMap (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string): PactMap {\n\t\treturn runtime.createChannel(id, PactMapFactory.Type) as PactMap;\n\t}\n\n\t/**\n\t * Get a factory for PactMap to register with the data store.\n\t *\n\t * @returns a factory that creates and loads PactMaps\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new PactMapFactory();\n\t}\n\n\tprivate readonly values: Map<string, Pact<T>> = new Map();\n\n\tprivate readonly incomingOp: EventEmitter = new EventEmitter();\n\n\t/**\n\t * Constructs a new PactMap. If the object is non-local an id and service interfaces will\n\t * be provided\n\t *\n\t * @param runtime - data store runtime the PactMap belongs to\n\t * @param id - optional name of the PactMap\n\t */\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_pactMap_\");\n\n\t\tthis.incomingOp.on(\"set\", this.handleIncomingSet);\n\t\tthis.incomingOp.on(\"accept\", this.handleIncomingAccept);\n\n\t\tthis.runtime.getQuorum().on(\"removeMember\", this.handleQuorumRemoveMember);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.get}\n\t */\n\tpublic get(key: string): T | undefined {\n\t\treturn this.values.get(key)?.accepted?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getWithDetails}\n\t */\n\tpublic getWithDetails(key: string): IAcceptedPact<T> | undefined {\n\t\t// Note: We return type `IAcceptedPact` instead of `IAcceptedPactInternal` since we may want to diverge\n\t\t// the interfaces in the future.\n\t\tconst acceptedPact = this.values.get(key)?.accepted;\n\t\tif (acceptedPact === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tvalue: acceptedPact.value,\n\t\t\tacceptedSequenceNumber: acceptedPact.sequenceNumber,\n\t\t};\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.isPending}\n\t */\n\tpublic isPending(key: string): boolean {\n\t\treturn this.values.get(key)?.pending !== undefined;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.getPending}\n\t */\n\tpublic getPending(key: string): T | undefined {\n\t\treturn this.values.get(key)?.pending?.value;\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.set}\n\t */\n\tpublic set(key: string, value: T | undefined): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if we can't submit a valid proposal (there's already a pending proposal)\n\t\tif (currentValue?.pending !== undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If not attached, we basically pretend we got an ack immediately.\n\t\tif (!this.isAttached()) {\n\t\t\t// Queueing as a microtask to permit callers to complete their callstacks before the result of the set\n\t\t\t// takes effect. This more closely resembles the pattern in the attached state, where the ack will not\n\t\t\t// be received synchronously.\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.handleIncomingSet(key, value, 0 /* refSeq */, 0 /* setSequenceNumber */);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst setOp: IPactMapSetOperation<T> = {\n\t\t\ttype: \"set\",\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\trefSeq: this.runtime.deltaManager.lastSequenceNumber,\n\t\t};\n\n\t\tthis.submitLocalMessage(setOp);\n\t}\n\n\t/**\n\t * {@inheritDoc IPactMap.delete}\n\t */\n\tpublic delete(key: string): void {\n\t\tconst currentValue = this.values.get(key);\n\t\t// Early-exit if:\n\t\tif (\n\t\t\t// there's nothing to delete\n\t\t\tcurrentValue === undefined ||\n\t\t\t// if something is pending (and so our proposal won't be valid)\n\t\t\tcurrentValue.pending !== undefined ||\n\t\t\t// or if the accepted value is undefined which is equivalent to already being deleted\n\t\t\tcurrentValue.accepted.value === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.set(key, undefined);\n\t}\n\n\t/**\n\t * Get a point-in-time list of clients who must sign off on values coming in for them to move from \"pending\" to\n\t * \"accepted\" state. This list is finalized for a value at the moment it goes pending (i.e. if more clients\n\t * join later, they are not added to the list of signoffs).\n\t * @returns The list of clientIds for clients who must sign off to accept the incoming pending value\n\t */\n\tprivate getSignoffClients(): string[] {\n\t\t// If detached, we don't need anyone to sign off. Otherwise, we need all currently connected clients.\n\t\treturn this.isAttached() ? [...this.runtime.getQuorum().getMembers().keys()] : [];\n\t}\n\n\tprivate readonly handleIncomingSet = (\n\t\tkey: string,\n\t\tvalue: T | undefined,\n\t\trefSeq: number,\n\t\tsetSequenceNumber: number,\n\t): void => {\n\t\tconst currentValue = this.values.get(key);\n\t\t// We use a consensus-like approach here, so a proposal is valid if the value is unset or if there is no\n\t\t// pending change and it was made with knowledge of the most recently accepted value. We'll drop invalid\n\t\t// proposals on the ground.\n\t\tconst proposalValid =\n\t\t\tcurrentValue === undefined ||\n\t\t\t(currentValue.pending === undefined && currentValue.accepted.sequenceNumber <= refSeq);\n\t\tif (!proposalValid) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst accepted = currentValue?.accepted;\n\n\t\t// We expect signoffs from all connected clients at the time the set was sequenced (including the client who\n\t\t// sent the set).\n\t\tconst expectedSignoffs = this.getSignoffClients();\n\n\t\tconst newPact: Pact<T> = {\n\t\t\taccepted,\n\t\t\tpending: {\n\t\t\t\tvalue,\n\t\t\t\texpectedSignoffs,\n\t\t\t},\n\t\t};\n\n\t\tthis.values.set(key, newPact);\n\n\t\tthis.emit(\"pending\", key);\n\n\t\tif (expectedSignoffs.length === 0) {\n\t\t\t// At least the submitting client should be amongst the expectedSignoffs, but keeping this check around\n\t\t\t// as extra protection and in case we bring back the \"submitting client implicitly accepts\" optimization.\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value, sequenceNumber: setSequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t} else if (\n\t\t\tthis.runtime.clientId !== undefined &&\n\t\t\texpectedSignoffs.includes(this.runtime.clientId)\n\t\t) {\n\t\t\t// Emit an accept upon a new key entering pending state if our accept is expected.\n\t\t\tconst acceptOp: IPactMapAcceptOperation = {\n\t\t\t\ttype: \"accept\",\n\t\t\t\tkey,\n\t\t\t};\n\t\t\tthis.submitLocalMessage(acceptOp);\n\t\t}\n\t};\n\n\tprivate readonly handleIncomingAccept = (\n\t\tkey: string,\n\t\tclientId: string,\n\t\tsequenceNumber: number,\n\t): void => {\n\t\tconst pending = this.values.get(key)?.pending;\n\t\t// We don't resubmit accepts on reconnect so this should only run for expected accepts.\n\t\tassert(pending !== undefined, 0x2f8 /* Unexpected accept op, nothing pending */);\n\t\tassert(\n\t\t\tpending.expectedSignoffs.includes(clientId),\n\t\t\t0x2f9 /* Unexpected accept op, client not in expectedSignoffs */,\n\t\t);\n\n\t\t// Remove the client from the expected signoffs\n\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t);\n\n\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t// The pending value has settled\n\t\t\tthis.values.set(key, {\n\t\t\t\taccepted: { value: pending.value, sequenceNumber },\n\t\t\t\tpending: undefined,\n\t\t\t});\n\t\t\tthis.emit(\"accepted\", key);\n\t\t}\n\t};\n\n\tprivate readonly handleQuorumRemoveMember = (clientId: string): void => {\n\t\tfor (const [key, { pending }] of this.values) {\n\t\t\tif (pending !== undefined) {\n\t\t\t\tpending.expectedSignoffs = pending.expectedSignoffs.filter(\n\t\t\t\t\t(expectedClientId) => expectedClientId !== clientId,\n\t\t\t\t);\n\n\t\t\t\tif (pending.expectedSignoffs.length === 0) {\n\t\t\t\t\t// The pending value has settled\n\t\t\t\t\tconst clientLeaveSequenceNumber = this.runtime.deltaManager.lastSequenceNumber;\n\t\t\t\t\tthis.values.set(key, {\n\t\t\t\t\t\taccepted: {\n\t\t\t\t\t\t\tvalue: pending.value,\n\t\t\t\t\t\t\t// The sequence number of the ClientLeave message.\n\t\t\t\t\t\t\tsequenceNumber: clientLeaveSequenceNumber,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpending: undefined,\n\t\t\t\t\t});\n\t\t\t\t\tthis.emit(\"accepted\", key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t/**\n\t * Create a summary for the PactMap\n\t *\n\t * @returns the summary of the current state of the PactMap\n\t * @internal\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\tconst allEntries = [...this.values.entries()];\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(allEntries));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t * @internal\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<[string, Pact<T>][]>(storage, snapshotFileName);\n\t\tfor (const [key, value] of content) {\n\t\t\tthis.values.set(key, value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.initializeLocalCore}\n\t * @internal\n\t */\n\tprotected initializeLocalCore(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.onDisconnect}\n\t * @internal\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.reSubmitCore}\n\t * @internal\n\t */\n\tprotected reSubmitCore(content: unknown, localOpMetadata: unknown): void {\n\t\tconst pactMapOp = content as IPactMapOperation<T>;\n\t\t// Filter out accept messages - if we're coming back from a disconnect, our acceptance is never required\n\t\t// because we're implicitly removed from the list of expected accepts.\n\t\tif (pactMapOp.type === \"accept\") {\n\t\t\treturn;\n\t\t}\n\n\t\t// Filter out set messages that have no chance of being accepted because there's another value pending\n\t\t// or another value was accepted while we were disconnected.\n\t\tconst currentValue = this.values.get(pactMapOp.key);\n\t\tif (\n\t\t\tcurrentValue !== undefined &&\n\t\t\t(currentValue.pending !== undefined ||\n\t\t\t\tpactMapOp.refSeq < currentValue.accepted?.sequenceNumber)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Otherwise we can resubmit\n\t\tthis.submitLocalMessage(pactMapOp, localOpMetadata);\n\t}\n\n\t/**\n\t * Process a PactMap operation\n\t *\n\t * @param message - the message to prepare\n\t * @param local - whether the message was sent by the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t * @internal\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\tif (message.type === MessageType.Operation) {\n\t\t\tconst op = message.contents as IPactMapOperation<T>;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"set\":\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"set\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\top.value,\n\t\t\t\t\t\top.refSeq,\n\t\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase \"accept\":\n\t\t\t\t\tthis.incomingOp.emit(\n\t\t\t\t\t\t\"accept\",\n\t\t\t\t\t\top.key,\n\t\t\t\t\t\tmessage.clientId,\n\t\t\t\t\t\tmessage.sequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic applyStashedOp(): void {\n\t\tthrow new Error(\"not implemented\");\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-experimental/pact-map",
|
|
3
|
-
"version": "2.0.0-internal.6.
|
|
3
|
+
"version": "2.0.0-internal.6.3.1",
|
|
4
4
|
"description": "Distributed data structure for key-value pairs using pact consensus",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"module": "lib/index.js",
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
|
-
"
|
|
17
|
+
"c8": {
|
|
18
18
|
"all": true,
|
|
19
19
|
"cache-dir": "nyc/.cache",
|
|
20
20
|
"exclude": [
|
|
@@ -35,27 +35,27 @@
|
|
|
35
35
|
"temp-directory": "nyc/.nyc_output"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@fluidframework/
|
|
39
|
-
"@fluidframework/core-
|
|
40
|
-
"@fluidframework/datastore-definitions": ">=2.0.0-internal.6.
|
|
41
|
-
"@fluidframework/driver-utils": ">=2.0.0-internal.6.
|
|
38
|
+
"@fluidframework/core-interfaces": ">=2.0.0-internal.6.3.1 <2.0.0-internal.6.4.0",
|
|
39
|
+
"@fluidframework/core-utils": ">=2.0.0-internal.6.3.1 <2.0.0-internal.6.4.0",
|
|
40
|
+
"@fluidframework/datastore-definitions": ">=2.0.0-internal.6.3.1 <2.0.0-internal.6.4.0",
|
|
41
|
+
"@fluidframework/driver-utils": ">=2.0.0-internal.6.3.1 <2.0.0-internal.6.4.0",
|
|
42
42
|
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
43
|
-
"@fluidframework/runtime-definitions": ">=2.0.0-internal.6.
|
|
44
|
-
"@fluidframework/shared-object-base": ">=2.0.0-internal.6.
|
|
43
|
+
"@fluidframework/runtime-definitions": ">=2.0.0-internal.6.3.1 <2.0.0-internal.6.4.0",
|
|
44
|
+
"@fluidframework/shared-object-base": ">=2.0.0-internal.6.3.1 <2.0.0-internal.6.4.0",
|
|
45
45
|
"events": "^3.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@fluid-internal/test-dds-utils": ">=2.0.0-internal.6.
|
|
48
|
+
"@fluid-internal/test-dds-utils": ">=2.0.0-internal.6.3.1 <2.0.0-internal.6.4.0",
|
|
49
49
|
"@fluidframework/build-common": "^2.0.0",
|
|
50
|
-
"@fluidframework/build-tools": "^0.
|
|
50
|
+
"@fluidframework/build-tools": "^0.22.0",
|
|
51
51
|
"@fluidframework/eslint-config-fluid": "^2.1.0",
|
|
52
|
-
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.6.
|
|
53
|
-
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.6.
|
|
52
|
+
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.6.3.1 <2.0.0-internal.6.4.0",
|
|
53
|
+
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.6.3.1 <2.0.0-internal.6.4.0",
|
|
54
54
|
"@microsoft/api-extractor": "^7.34.4",
|
|
55
55
|
"@types/events": "^3.0.0",
|
|
56
56
|
"@types/mocha": "^9.1.1",
|
|
57
57
|
"@types/node": "^16.18.38",
|
|
58
|
-
"
|
|
58
|
+
"c8": "^7.7.1",
|
|
59
59
|
"copyfiles": "^2.4.1",
|
|
60
60
|
"cross-env": "^7.0.3",
|
|
61
61
|
"eslint": "~8.6.0",
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"mocha-junit-reporter": "^1.18.0",
|
|
65
65
|
"mocha-multi-reporters": "^1.5.1",
|
|
66
66
|
"moment": "^2.21.0",
|
|
67
|
-
"nyc": "^15.1.0",
|
|
68
67
|
"prettier": "~2.6.2",
|
|
69
68
|
"rimraf": "^4.4.0",
|
|
70
69
|
"typescript": "~4.5.5"
|
|
@@ -82,7 +81,7 @@
|
|
|
82
81
|
"build:genver": "gen-version",
|
|
83
82
|
"build:test": "tsc --project ./src/test/tsconfig.json",
|
|
84
83
|
"ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
|
|
85
|
-
"clean": "rimraf --glob
|
|
84
|
+
"clean": "rimraf --glob 'dist' 'lib' '*.tsbuildinfo' '*.build.log' '_api-extractor-temp' 'nyc'",
|
|
86
85
|
"eslint": "eslint --format stylish src",
|
|
87
86
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
88
87
|
"format": "npm run prettier:fix",
|
|
@@ -91,9 +90,8 @@
|
|
|
91
90
|
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
|
|
92
91
|
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
|
|
93
92
|
"test": "npm run test:mocha",
|
|
94
|
-
"test:coverage": "
|
|
95
|
-
"test:mocha": "mocha --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup
|
|
96
|
-
"test:mocha:multireport": "npm run test:mocha",
|
|
93
|
+
"test:coverage": "c8 npm test",
|
|
94
|
+
"test:mocha": "mocha --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup",
|
|
97
95
|
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
98
96
|
"tsc": "tsc"
|
|
99
97
|
}
|
package/src/packageVersion.ts
CHANGED
package/src/pactMap.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { EventEmitter } from "events";
|
|
9
9
|
|
|
10
|
-
import { assert } from "@fluidframework/
|
|
10
|
+
import { assert } from "@fluidframework/core-utils";
|
|
11
11
|
import { ISequencedDocumentMessage, MessageType } from "@fluidframework/protocol-definitions";
|
|
12
12
|
import {
|
|
13
13
|
IChannelAttributes,
|