@fluidframework/container-runtime 2.92.0 → 2.100.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/CHANGELOG.md +18 -0
- package/README.md +1 -1
- package/container-runtime.test-files.tar +0 -0
- package/dist/containerRuntime.d.ts +16 -4
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +80 -60
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStore.d.ts +1 -1
- package/dist/dataStore.d.ts.map +1 -1
- package/dist/dataStore.js +6 -7
- package/dist/dataStore.js.map +1 -1
- package/dist/opLifecycle/batchManager.d.ts +3 -9
- package/dist/opLifecycle/batchManager.d.ts.map +1 -1
- package/dist/opLifecycle/batchManager.js +3 -2
- package/dist/opLifecycle/batchManager.js.map +1 -1
- package/dist/opLifecycle/outbox.d.ts +8 -5
- package/dist/opLifecycle/outbox.d.ts.map +1 -1
- package/dist/opLifecycle/outbox.js +40 -57
- package/dist/opLifecycle/outbox.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/dist/pendingStateManager.d.ts +1 -6
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +6 -16
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/runtimeLayerCompatState.d.ts +2 -2
- package/eslint.config.mts +1 -1
- package/lib/containerRuntime.d.ts +16 -4
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +82 -62
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStore.d.ts +1 -1
- package/lib/dataStore.d.ts.map +1 -1
- package/lib/dataStore.js +1 -2
- package/lib/dataStore.js.map +1 -1
- package/lib/opLifecycle/batchManager.d.ts +3 -9
- package/lib/opLifecycle/batchManager.d.ts.map +1 -1
- package/lib/opLifecycle/batchManager.js +3 -2
- package/lib/opLifecycle/batchManager.js.map +1 -1
- package/lib/opLifecycle/outbox.d.ts +8 -5
- package/lib/opLifecycle/outbox.d.ts.map +1 -1
- package/lib/opLifecycle/outbox.js +41 -58
- package/lib/opLifecycle/outbox.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/lib/pendingStateManager.d.ts +1 -6
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +6 -16
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/runtimeLayerCompatState.d.ts +2 -2
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +26 -31
- package/src/containerRuntime.ts +91 -76
- package/src/dataStore.ts +5 -6
- package/src/opLifecycle/batchManager.ts +4 -12
- package/src/opLifecycle/outbox.ts +51 -69
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +5 -23
package/dist/dataStore.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import type { IDataStore, IFluidDataStoreChannel } from "@fluidframework/runtime-definitions/internal";
|
|
6
6
|
import { type ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
|
|
7
7
|
import type { ChannelCollection } from "./channelCollection.js";
|
|
8
8
|
/**
|
package/dist/dataStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataStore.d.ts","sourceRoot":"","sources":["../src/dataStore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,
|
|
1
|
+
{"version":3,"file":"dataStore.d.ts","sourceRoot":"","sources":["../src/dataStore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAEX,UAAU,EACV,sBAAsB,EACtB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACN,KAAK,mBAAmB,EAGxB,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAGhE;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,+BACP,OAAO,yDAOnC,CAAC;AAEF,eAAO,MAAM,kBAAkB,0BACP,sBAAsB,cACjC,MAAM,qBACC,iBAAiB,UAC5B,mBAAmB,KACzB,UAAyF,CAAC"}
|
package/dist/dataStore.js
CHANGED
|
@@ -7,8 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.channelToDataStore = exports.isDataStoreAliasMessage = void 0;
|
|
8
8
|
const container_definitions_1 = require("@fluidframework/container-definitions");
|
|
9
9
|
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
10
|
-
const internal_2 = require("@fluidframework/
|
|
11
|
-
const internal_3 = require("@fluidframework/telemetry-utils/internal");
|
|
10
|
+
const internal_2 = require("@fluidframework/telemetry-utils/internal");
|
|
12
11
|
const messageTypes_js_1 = require("./messageTypes.js");
|
|
13
12
|
/**
|
|
14
13
|
* Type guard that returns true if the given alias message is actually an instance of
|
|
@@ -36,10 +35,10 @@ class DataStore {
|
|
|
36
35
|
*/
|
|
37
36
|
async trySetAlias(alias) {
|
|
38
37
|
if (alias.includes("/")) {
|
|
39
|
-
throw new
|
|
38
|
+
throw new internal_2.UsageError(`The alias cannot contain slashes: '${alias}'`);
|
|
40
39
|
}
|
|
41
|
-
if (
|
|
42
|
-
throw new
|
|
40
|
+
if (this.parentContext.containerRuntime.inStagingMode === true) {
|
|
41
|
+
throw new internal_2.UsageError("Cannot set aliases while in staging mode");
|
|
43
42
|
}
|
|
44
43
|
switch (this.aliasState) {
|
|
45
44
|
// If we're already aliasing, check if it's for the same value and return
|
|
@@ -95,11 +94,11 @@ class DataStore {
|
|
|
95
94
|
eventName: "AliasingException",
|
|
96
95
|
alias: {
|
|
97
96
|
value: alias,
|
|
98
|
-
tag:
|
|
97
|
+
tag: internal_2.TelemetryDataTag.UserData,
|
|
99
98
|
},
|
|
100
99
|
internalId: {
|
|
101
100
|
value: this.internalId,
|
|
102
|
-
tag:
|
|
101
|
+
tag: internal_2.TelemetryDataTag.CodeArtifact,
|
|
103
102
|
},
|
|
104
103
|
}, error);
|
|
105
104
|
return false;
|
package/dist/dataStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataStore.js","sourceRoot":"","sources":["../src/dataStore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iFAAoE;AAGpE,kEAA8E;AAC9E,2EAKsD;AACtD,uEAIkD;AAGlD,uDAAyD;AAmBzD;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACtC,0BAAmC,EACoB,EAAE;IACzD,OAAO,CACN,OAAQ,0BAA8D,EAAE,UAAU;QACjF,QAAQ;QACT,OAAQ,0BAA8D,EAAE,KAAK,KAAK,QAAQ,CAC1F,CAAC;AACH,CAAC,CAAC;AARW,QAAA,uBAAuB,2BAQlC;AAEK,MAAM,kBAAkB,GAAG,CACjC,qBAA6C,EAC7C,UAAkB,EAClB,iBAAoC,EACpC,MAA2B,EACd,EAAE,CAAC,IAAI,SAAS,CAAC,qBAAqB,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;AALhF,QAAA,kBAAkB,sBAK8D;AAE7F,IAAK,UAIJ;AAJD,WAAK,UAAU;IACd,iCAAmB,CAAA;IACnB,mCAAqB,CAAA;IACrB,2BAAa,CAAA;AACd,CAAC,EAJI,UAAU,KAAV,UAAU,QAId;AAED,MAAM,SAAS;IAMd;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,K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GAAG,GAAG,EAAE,CAC3B,MAAM,CACL,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAC/E,CAAC;YAEH,IAAI,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;gBAClD,oBAAoB,EAAE,CAAC;gBACvB,OAAO;YACR,CAAC;YAED,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;YACxE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;YACf,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport type { FluidObject } from \"@fluidframework/core-interfaces\";\nimport type { IFluidHandleInternal } from \"@fluidframework/core-interfaces/internal\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype AliasResult,\n\ttype IDataStore,\n\ttype IFluidDataStoreChannel,\n\tasLegacyAlpha,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\ttype ITelemetryLoggerExt,\n\tTelemetryDataTag,\n\tUsageError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ChannelCollection } from \"./channelCollection.js\";\nimport { ContainerMessageType } from \"./messageTypes.js\";\n\n/**\n * Interface for an op to be used for assigning an\n * alias to a datastore\n * @internal\n * @privateRemarks exported per ContainerRuntime export for testing purposes\n */\nexport interface IDataStoreAliasMessage {\n\t/**\n\t * The internal id of the datastore\n\t */\n\treadonly internalId: string;\n\t/**\n\t * The alias name to be assigned to the datastore\n\t */\n\treadonly alias: string;\n}\n\n/**\n * Type guard that returns true if the given alias message is actually an instance of\n * a class which implements {@link IDataStoreAliasMessage}\n * @param maybeDataStoreAliasMessage - message object to be validated\n * @returns True if the {@link IDataStoreAliasMessage} is fully implemented, false otherwise\n */\nexport const isDataStoreAliasMessage = (\n\tmaybeDataStoreAliasMessage: unknown,\n): maybeDataStoreAliasMessage is IDataStoreAliasMessage => {\n\treturn (\n\t\ttypeof (maybeDataStoreAliasMessage as Partial<IDataStoreAliasMessage>)?.internalId ===\n\t\t\t\"string\" &&\n\t\ttypeof (maybeDataStoreAliasMessage as Partial<IDataStoreAliasMessage>)?.alias === \"string\"\n\t);\n};\n\nexport const channelToDataStore = (\n\tfluidDataStoreChannel: IFluidDataStoreChannel,\n\tinternalId: string,\n\tchannelCollection: ChannelCollection,\n\tlogger: ITelemetryLoggerExt,\n): IDataStore => new DataStore(fluidDataStoreChannel, internalId, channelCollection, logger);\n\nenum AliasState {\n\tAliased = \"Aliased\",\n\tAliasing = \"Aliasing\",\n\tNone = \"None\",\n}\n\nclass DataStore implements IDataStore {\n\tprivate aliasState: AliasState = AliasState.None;\n\tprivate alias: string | undefined;\n\tprivate readonly pendingAliases: Map<string, Promise<AliasResult>>;\n\tprivate aliasResult: Promise<AliasResult> | undefined;\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IDataStore.trySetAlias}\n\t */\n\tasync trySetAlias(alias: string): Promise<AliasResult> {\n\t\tif (alias.includes(\"/\")) {\n\t\t\tthrow new UsageError(`The alias cannot contain slashes: '${alias}'`);\n\t\t}\n\t\tif (asLegacyAlpha(this.parentContext.containerRuntime).inStagingMode === true) {\n\t\t\tthrow new UsageError(\"Cannot set aliases while in staging mode\");\n\t\t}\n\n\t\tswitch (this.aliasState) {\n\t\t\t// If we're already aliasing, check if it's for the same value and return\n\t\t\t// the stored promise, otherwise return 'AlreadyAliased'\n\t\t\tcase AliasState.Aliasing: {\n\t\t\t\tassert(\n\t\t\t\t\tthis.aliasResult !== undefined,\n\t\t\t\t\t0x316 /* There should be a cached promise of in-progress aliasing */,\n\t\t\t\t);\n\t\t\t\tawait this.aliasResult;\n\t\t\t\treturn this.alias === alias ? \"Success\" : \"AlreadyAliased\";\n\t\t\t}\n\n\t\t\t// If this datastore is already aliased, return true only if this\n\t\t\t// is a repeated call for the same alias\n\t\t\tcase AliasState.Aliased: {\n\t\t\t\treturn this.alias === alias ? \"Success\" : \"AlreadyAliased\";\n\t\t\t}\n\n\t\t\tcase AliasState.None: {\n\t\t\t\tconst existingAlias = this.pendingAliases.get(alias);\n\t\t\t\tif (existingAlias !== undefined) {\n\t\t\t\t\t// There is already another datastore which will be aliased\n\t\t\t\t\t// to the same name\n\t\t\t\t\treturn \"Conflict\";\n\t\t\t\t}\n\n\t\t\t\t// There is no current or past alias operation for this datastore,\n\t\t\t\t// or for this alias, so it is safe to continue execution\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tunreachableCase(this.aliasState);\n\t\t\t}\n\t\t}\n\n\t\tthis.aliasState = AliasState.Aliasing;\n\t\tthis.aliasResult = this.trySetAliasInternal(alias);\n\t\tthis.pendingAliases.set(alias, this.aliasResult);\n\t\treturn this.aliasResult;\n\t}\n\n\tasync trySetAliasInternal(alias: string): Promise<AliasResult> {\n\t\tconst message: IDataStoreAliasMessage = {\n\t\t\tinternalId: this.internalId,\n\t\t\talias,\n\t\t};\n\t\tthis.fluidDataStoreChannel.makeVisibleAndAttachGraph();\n\n\t\tif (this.parentContext.attachState === AttachState.Detached) {\n\t\t\tconst localResult = this.channelCollection.processAliasMessageCore(\n\t\t\t\tthis.internalId,\n\t\t\t\talias,\n\t\t\t);\n\t\t\t// Explicitly lock-out future attempts of aliasing,\n\t\t\t// regardless of result\n\t\t\tthis.aliasState = AliasState.Aliased;\n\t\t\treturn localResult ? \"Success\" : \"Conflict\";\n\t\t}\n\n\t\tconst aliased = await this.ackBasedPromise<boolean>((resolve) => {\n\t\t\tthis.parentContext.submitMessage(\n\t\t\t\t{ type: ContainerMessageType.Alias, contents: message },\n\t\t\t\tresolve,\n\t\t\t);\n\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"AliasingException\",\n\t\t\t\t\t\talias: {\n\t\t\t\t\t\t\tvalue: alias,\n\t\t\t\t\t\t\ttag: TelemetryDataTag.UserData,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinternalId: {\n\t\t\t\t\t\t\tvalue: this.internalId,\n\t\t\t\t\t\t\ttag: TelemetryDataTag.CodeArtifact,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\n\t\t\t\treturn false;\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tthis.pendingAliases.delete(alias);\n\t\t\t});\n\n\t\tif (!aliased) {\n\t\t\tthis.aliasState = AliasState.None;\n\t\t\tthis.aliasResult = undefined;\n\t\t\treturn \"Conflict\";\n\t\t}\n\n\t\tthis.alias = alias;\n\t\tthis.aliasState = AliasState.Aliased;\n\t\treturn \"Success\";\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IDataStore.entryPoint}\n\t */\n\tget entryPoint(): IFluidHandleInternal<FluidObject> {\n\t\treturn this.fluidDataStoreChannel.entryPoint;\n\t}\n\n\tconstructor(\n\t\tprivate readonly fluidDataStoreChannel: IFluidDataStoreChannel,\n\t\tprivate readonly internalId: string,\n\t\tprivate readonly channelCollection: ChannelCollection,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly parentContext = channelCollection.parentContext,\n\t) {\n\t\tthis.pendingAliases = channelCollection.pendingAliases;\n\t}\n\n\tprivate async ackBasedPromise<T>(\n\t\texecutor: (\n\t\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\t\treject: (reason?: unknown) => void,\n\t\t) => void,\n\t): Promise<T> {\n\t\tlet rejectBecauseDispose: () => void;\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\trejectBecauseDispose = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\"ContainerRuntime disposed while this ack-based Promise was pending\"),\n\t\t\t\t);\n\n\t\t\tif (this.parentContext.containerRuntime.disposed) {\n\t\t\t\trejectBecauseDispose();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.parentContext.containerRuntime.on(\"dispose\", rejectBecauseDispose);\n\t\t\texecutor(resolve, reject);\n\t\t}).finally(() => {\n\t\t\tthis.parentContext.containerRuntime.off(\"dispose\", rejectBecauseDispose);\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dataStore.js","sourceRoot":"","sources":["../src/dataStore.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iFAAoE;AAGpE,kEAA8E;AAM9E,uEAIkD;AAGlD,uDAAyD;AAmBzD;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACtC,0BAAmC,EACoB,EAAE;IACzD,OAAO,CACN,OAAQ,0BAA8D,EAAE,UAAU;QACjF,QAAQ;QACT,OAAQ,0BAA8D,EAAE,KAAK,KAAK,QAAQ,CAC1F,CAAC;AACH,CAAC,CAAC;AARW,QAAA,uBAAuB,2BAQlC;AAEK,MAAM,kBAAkB,GAAG,CACjC,qBAA6C,EAC7C,UAAkB,EAClB,iBAAoC,EACpC,MAA2B,EACd,EAAE,CAAC,IAAI,SAAS,CAAC,qBAAqB,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;AALhF,QAAA,kBAAkB,sBAK8D;AAE7F,IAAK,UAIJ;AAJD,WAAK,UAAU;IACd,iCAAmB,CAAA;IACnB,mCAAqB,CAAA;IACrB,2BAAa,CAAA;AACd,CAAC,EAJI,UAAU,KAAV,UAAU,QAId;AAED,MAAM,SAAS;IAMd;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,KAAa;QAC9B,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM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,aAAa,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;gBAClD,oBAAoB,EAAE,CAAC;gBACvB,OAAO;YACR,CAAC;YAED,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;YACxE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;YACf,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport type { FluidObject } from \"@fluidframework/core-interfaces\";\nimport type { IFluidHandleInternal } from \"@fluidframework/core-interfaces/internal\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tAliasResult,\n\tIDataStore,\n\tIFluidDataStoreChannel,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\ttype ITelemetryLoggerExt,\n\tTelemetryDataTag,\n\tUsageError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ChannelCollection } from \"./channelCollection.js\";\nimport { ContainerMessageType } from \"./messageTypes.js\";\n\n/**\n * Interface for an op to be used for assigning an\n * alias to a datastore\n * @internal\n * @privateRemarks exported per ContainerRuntime export for testing purposes\n */\nexport interface IDataStoreAliasMessage {\n\t/**\n\t * The internal id of the datastore\n\t */\n\treadonly internalId: string;\n\t/**\n\t * The alias name to be assigned to the datastore\n\t */\n\treadonly alias: string;\n}\n\n/**\n * Type guard that returns true if the given alias message is actually an instance of\n * a class which implements {@link IDataStoreAliasMessage}\n * @param maybeDataStoreAliasMessage - message object to be validated\n * @returns True if the {@link IDataStoreAliasMessage} is fully implemented, false otherwise\n */\nexport const isDataStoreAliasMessage = (\n\tmaybeDataStoreAliasMessage: unknown,\n): maybeDataStoreAliasMessage is IDataStoreAliasMessage => {\n\treturn (\n\t\ttypeof (maybeDataStoreAliasMessage as Partial<IDataStoreAliasMessage>)?.internalId ===\n\t\t\t\"string\" &&\n\t\ttypeof (maybeDataStoreAliasMessage as Partial<IDataStoreAliasMessage>)?.alias === \"string\"\n\t);\n};\n\nexport const channelToDataStore = (\n\tfluidDataStoreChannel: IFluidDataStoreChannel,\n\tinternalId: string,\n\tchannelCollection: ChannelCollection,\n\tlogger: ITelemetryLoggerExt,\n): IDataStore => new DataStore(fluidDataStoreChannel, internalId, channelCollection, logger);\n\nenum AliasState {\n\tAliased = \"Aliased\",\n\tAliasing = \"Aliasing\",\n\tNone = \"None\",\n}\n\nclass DataStore implements IDataStore {\n\tprivate aliasState: AliasState = AliasState.None;\n\tprivate alias: string | undefined;\n\tprivate readonly pendingAliases: Map<string, Promise<AliasResult>>;\n\tprivate aliasResult: Promise<AliasResult> | undefined;\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IDataStore.trySetAlias}\n\t */\n\tasync trySetAlias(alias: string): Promise<AliasResult> {\n\t\tif (alias.includes(\"/\")) {\n\t\t\tthrow new UsageError(`The alias cannot contain slashes: '${alias}'`);\n\t\t}\n\t\tif (this.parentContext.containerRuntime.inStagingMode === true) {\n\t\t\tthrow new UsageError(\"Cannot set aliases while in staging mode\");\n\t\t}\n\n\t\tswitch (this.aliasState) {\n\t\t\t// If we're already aliasing, check if it's for the same value and return\n\t\t\t// the stored promise, otherwise return 'AlreadyAliased'\n\t\t\tcase AliasState.Aliasing: {\n\t\t\t\tassert(\n\t\t\t\t\tthis.aliasResult !== undefined,\n\t\t\t\t\t0x316 /* There should be a cached promise of in-progress aliasing */,\n\t\t\t\t);\n\t\t\t\tawait this.aliasResult;\n\t\t\t\treturn this.alias === alias ? \"Success\" : \"AlreadyAliased\";\n\t\t\t}\n\n\t\t\t// If this datastore is already aliased, return true only if this\n\t\t\t// is a repeated call for the same alias\n\t\t\tcase AliasState.Aliased: {\n\t\t\t\treturn this.alias === alias ? \"Success\" : \"AlreadyAliased\";\n\t\t\t}\n\n\t\t\tcase AliasState.None: {\n\t\t\t\tconst existingAlias = this.pendingAliases.get(alias);\n\t\t\t\tif (existingAlias !== undefined) {\n\t\t\t\t\t// There is already another datastore which will be aliased\n\t\t\t\t\t// to the same name\n\t\t\t\t\treturn \"Conflict\";\n\t\t\t\t}\n\n\t\t\t\t// There is no current or past alias operation for this datastore,\n\t\t\t\t// or for this alias, so it is safe to continue execution\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tunreachableCase(this.aliasState);\n\t\t\t}\n\t\t}\n\n\t\tthis.aliasState = AliasState.Aliasing;\n\t\tthis.aliasResult = this.trySetAliasInternal(alias);\n\t\tthis.pendingAliases.set(alias, this.aliasResult);\n\t\treturn this.aliasResult;\n\t}\n\n\tasync trySetAliasInternal(alias: string): Promise<AliasResult> {\n\t\tconst message: IDataStoreAliasMessage = {\n\t\t\tinternalId: this.internalId,\n\t\t\talias,\n\t\t};\n\t\tthis.fluidDataStoreChannel.makeVisibleAndAttachGraph();\n\n\t\tif (this.parentContext.attachState === AttachState.Detached) {\n\t\t\tconst localResult = this.channelCollection.processAliasMessageCore(\n\t\t\t\tthis.internalId,\n\t\t\t\talias,\n\t\t\t);\n\t\t\t// Explicitly lock-out future attempts of aliasing,\n\t\t\t// regardless of result\n\t\t\tthis.aliasState = AliasState.Aliased;\n\t\t\treturn localResult ? \"Success\" : \"Conflict\";\n\t\t}\n\n\t\tconst aliased = await this.ackBasedPromise<boolean>((resolve) => {\n\t\t\tthis.parentContext.submitMessage(\n\t\t\t\t{ type: ContainerMessageType.Alias, contents: message },\n\t\t\t\tresolve,\n\t\t\t);\n\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.logger.sendErrorEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"AliasingException\",\n\t\t\t\t\t\talias: {\n\t\t\t\t\t\t\tvalue: alias,\n\t\t\t\t\t\t\ttag: TelemetryDataTag.UserData,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinternalId: {\n\t\t\t\t\t\t\tvalue: this.internalId,\n\t\t\t\t\t\t\ttag: TelemetryDataTag.CodeArtifact,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\n\t\t\t\treturn false;\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tthis.pendingAliases.delete(alias);\n\t\t\t});\n\n\t\tif (!aliased) {\n\t\t\tthis.aliasState = AliasState.None;\n\t\t\tthis.aliasResult = undefined;\n\t\t\treturn \"Conflict\";\n\t\t}\n\n\t\tthis.alias = alias;\n\t\tthis.aliasState = AliasState.Aliased;\n\t\treturn \"Success\";\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/runtime-definitions#IDataStore.entryPoint}\n\t */\n\tget entryPoint(): IFluidHandleInternal<FluidObject> {\n\t\treturn this.fluidDataStoreChannel.entryPoint;\n\t}\n\n\tconstructor(\n\t\tprivate readonly fluidDataStoreChannel: IFluidDataStoreChannel,\n\t\tprivate readonly internalId: string,\n\t\tprivate readonly channelCollection: ChannelCollection,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly parentContext = channelCollection.parentContext,\n\t) {\n\t\tthis.pendingAliases = channelCollection.pendingAliases;\n\t}\n\n\tprivate async ackBasedPromise<T>(\n\t\texecutor: (\n\t\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\t\treject: (reason?: unknown) => void,\n\t\t) => void,\n\t): Promise<T> {\n\t\tlet rejectBecauseDispose: () => void;\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\trejectBecauseDispose = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\"ContainerRuntime disposed while this ack-based Promise was pending\"),\n\t\t\t\t);\n\n\t\t\tif (this.parentContext.containerRuntime.disposed) {\n\t\t\t\trejectBecauseDispose();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.parentContext.containerRuntime.on(\"dispose\", rejectBecauseDispose);\n\t\t\texecutor(resolve, reject);\n\t\t}).finally(() => {\n\t\t\tthis.parentContext.containerRuntime.off(\"dispose\", rejectBecauseDispose);\n\t\t});\n\t}\n}\n"]}
|
|
@@ -7,15 +7,8 @@ import type { IPendingMessage } from "../pendingStateManager.js";
|
|
|
7
7
|
import type { LocalBatchMessage, IBatchCheckpoint, LocalBatch } from "./definitions.js";
|
|
8
8
|
import type { BatchStartInfo } from "./remoteMessageProcessor.js";
|
|
9
9
|
export interface IBatchManagerOptions {
|
|
10
|
+
readonly disableGroupedBatching: boolean;
|
|
10
11
|
readonly compressionOptions?: ICompressionRuntimeOptions;
|
|
11
|
-
/**
|
|
12
|
-
* If true, the outbox is allowed to rebase the batch during flushing.
|
|
13
|
-
*/
|
|
14
|
-
readonly canRebase: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* If true, don't compare batchID of incoming batches to this. e.g. ID Allocation Batch IDs should be ignored
|
|
17
|
-
*/
|
|
18
|
-
readonly ignoreBatchId?: boolean;
|
|
19
12
|
}
|
|
20
13
|
export interface BatchSequenceNumbers {
|
|
21
14
|
referenceSequenceNumber?: number;
|
|
@@ -56,8 +49,9 @@ export declare class BatchManager {
|
|
|
56
49
|
get empty(): boolean;
|
|
57
50
|
/**
|
|
58
51
|
* Gets the pending batch and clears state for the next batch.
|
|
52
|
+
* The caller is responsible for calling {@link addBatchMetadata} after any modifications (e.g. prepending messages).
|
|
59
53
|
*/
|
|
60
|
-
popBatch(
|
|
54
|
+
popBatch(): LocalBatch;
|
|
61
55
|
/**
|
|
62
56
|
* Capture the pending state at this point
|
|
63
57
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchManager.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/batchManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAA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AY,CAA2B;IAC/C,OAAO,CAAC,eAAe,CAAS;IAEhC,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,IAAW,eAAe,IAAI,oBAAoB,CAKjD;IAED,OAAO,KAAK,uBAAuB,GAKlC;IAED;;;OAGG;IACH,OAAO,CAAC,oBAAoB,CAAqB;gBAErB,OAAO,EAAE,oBAAoB;IAElD,IAAI,CACV,OAAO,EAAE,iBAAiB,EAC1B,SAAS,EAAE,OAAO,EAClB,2BAA2B,CAAC,EAAE,MAAM,GAClC,IAAI;IAUP,IAAW,KAAK,IAAI,OAAO,CAE1B;IAED;;;OAGG;IACI,QAAQ,IAAI,UAAU;IAgB7B;;OAEG;IACI,UAAU,IAAI,gBAAgB;IAwBrC;;OAEG;IACI,mBAAmB,IAAI,OAAO;CAGrC;AAED,eAAO,MAAM,gBAAgB,UAAW,UAAU,YAAY,OAAO,KAAG,UA4BvE,CAAC;AAEF,eAAO,MAAM,oBAAoB,YACvB,oBAAoB,gBACf,oBAAoB,KAChC,OASF,CAAC"}
|
|
@@ -69,8 +69,9 @@ class BatchManager {
|
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Gets the pending batch and clears state for the next batch.
|
|
72
|
+
* The caller is responsible for calling {@link addBatchMetadata} after any modifications (e.g. prepending messages).
|
|
72
73
|
*/
|
|
73
|
-
popBatch(
|
|
74
|
+
popBatch() {
|
|
74
75
|
(0, internal_1.assert)(this.pendingBatch[0] !== undefined, 0xb8a /* expected non-empty batch */);
|
|
75
76
|
const batch = {
|
|
76
77
|
messages: this.pendingBatch,
|
|
@@ -81,7 +82,7 @@ class BatchManager {
|
|
|
81
82
|
this.pendingBatch = [];
|
|
82
83
|
this.clientSequenceNumber = undefined;
|
|
83
84
|
this.hasReentrantOps = false;
|
|
84
|
-
return
|
|
85
|
+
return batch;
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
88
|
* Capture the pending state at this point
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tLoggingError,\n\ttagData,\n\tTelemetryDataTag,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ICompressionRuntimeOptions } from \"../compressionDefinitions.js\";\nimport { isContainerMessageDirtyable } from \"../containerRuntime.js\";\nimport { asBatchMetadata, type IBatchMetadata } from \"../metadata.js\";\nimport type { IPendingMessage } from \"../pendingStateManager.js\";\n\nimport type { LocalBatchMessage, IBatchCheckpoint, LocalBatch } from \"./definitions.js\";\nimport { serializeOp } from \"./opSerialization.js\";\nimport type { BatchStartInfo } from \"./remoteMessageProcessor.js\";\n\nexport interface IBatchManagerOptions {\n\treadonly compressionOptions?: ICompressionRuntimeOptions;\n\n\t/**\n\t * If true, the outbox is allowed to rebase the batch during flushing.\n\t */\n\treadonly canRebase: boolean;\n\n\t/**\n\t * If true, don't compare batchID of incoming batches to this. e.g. ID Allocation Batch IDs should be ignored\n\t */\n\treadonly ignoreBatchId?: boolean;\n}\n\nexport interface BatchSequenceNumbers {\n\treferenceSequenceNumber?: number;\n\tclientSequenceNumber?: number;\n}\n\n/**\n * Type alias for the batchId stored in batch metadata\n */\nexport type BatchId = string;\n\n/**\n * Compose original client ID and client sequence number into BatchId to stamp on the message during reconnect\n */\nexport function generateBatchId(originalClientId: string, batchStartCsn: number): BatchId {\n\treturn `${originalClientId}_[${batchStartCsn}]`;\n}\n\n/**\n * Get the effective batch ID for the input argument.\n * Supports either an IPendingMessage or BatchStartInfo.\n * If the batch ID is explicitly present, return it.\n * Otherwise, generate a new batch ID using the client ID and batch start CSN.\n */\nexport function getEffectiveBatchId(\n\tpendingMessageOrBatchStartInfo: IPendingMessage | BatchStartInfo,\n): string {\n\tif (\"localOpMetadata\" in pendingMessageOrBatchStartInfo) {\n\t\tconst pendingMessage: IPendingMessage = pendingMessageOrBatchStartInfo;\n\t\treturn (\n\t\t\tasBatchMetadata(pendingMessage.opMetadata)?.batchId ??\n\t\t\tgenerateBatchId(\n\t\t\t\tpendingMessage.batchInfo.clientId,\n\t\t\t\tpendingMessage.batchInfo.batchStartCsn,\n\t\t\t)\n\t\t);\n\t}\n\n\tconst batchStart: BatchStartInfo = pendingMessageOrBatchStartInfo;\n\treturn batchStart.batchId ?? generateBatchId(batchStart.clientId, batchStart.batchStartCsn);\n}\n\n/**\n * Helper class that manages partial batch & rollback.\n */\nexport class BatchManager {\n\tprivate pendingBatch: LocalBatchMessage[] = [];\n\tprivate hasReentrantOps = false;\n\n\tpublic get length(): number {\n\t\treturn this.pendingBatch.length;\n\t}\n\n\tpublic get sequenceNumbers(): BatchSequenceNumbers {\n\t\treturn {\n\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t\tclientSequenceNumber: this.clientSequenceNumber,\n\t\t};\n\t}\n\n\tprivate get referenceSequenceNumber(): number | undefined {\n\t\treturn this.pendingBatch.length === 0\n\t\t\t? undefined\n\t\t\t: // NOTE: In case of reentrant ops, there could be multiple reference sequence numbers, but we will rebase before submitting.\n\t\t\t\tthis.pendingBatch[this.pendingBatch.length - 1].referenceSequenceNumber;\n\t}\n\n\t/**\n\t * The last-processed CSN when this batch started.\n\t * This is used to ensure that while the batch is open, no incoming ops are processed.\n\t */\n\tprivate clientSequenceNumber: number | undefined;\n\n\tconstructor(public readonly options: IBatchManagerOptions) {}\n\n\tpublic push(\n\t\tmessage: LocalBatchMessage,\n\t\treentrant: boolean,\n\t\tcurrentClientSequenceNumber?: number,\n\t): void {\n\t\tthis.hasReentrantOps = this.hasReentrantOps || reentrant;\n\n\t\tif (this.pendingBatch.length === 0) {\n\t\t\tthis.clientSequenceNumber = currentClientSequenceNumber;\n\t\t}\n\n\t\tthis.pendingBatch.push(message);\n\t}\n\n\tpublic get empty(): boolean {\n\t\treturn this.pendingBatch.length === 0;\n\t}\n\n\t/**\n\t * Gets the pending batch and clears state for the next batch.\n\t */\n\tpublic popBatch(batchId?: BatchId): LocalBatch {\n\t\tassert(this.pendingBatch[0] !== undefined, 0xb8a /* expected non-empty batch */);\n\t\tconst batch: LocalBatch = {\n\t\t\tmessages: this.pendingBatch,\n\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t\thasReentrantOps: this.hasReentrantOps,\n\t\t\tstaged: this.pendingBatch[0].staged,\n\t\t};\n\n\t\tthis.pendingBatch = [];\n\t\tthis.clientSequenceNumber = undefined;\n\t\tthis.hasReentrantOps = false;\n\n\t\treturn addBatchMetadata(batch, batchId);\n\t}\n\n\t/**\n\t * Capture the pending state at this point\n\t */\n\tpublic checkpoint(): IBatchCheckpoint {\n\t\tconst startSequenceNumber = this.clientSequenceNumber;\n\t\tconst startPoint = this.pendingBatch.length;\n\t\treturn {\n\t\t\trollback: (process: (message: LocalBatchMessage) => void) => {\n\t\t\t\tthis.clientSequenceNumber = startSequenceNumber;\n\t\t\t\tconst rollbackOpsLifo = this.pendingBatch.splice(startPoint).reverse();\n\t\t\t\tfor (const message of rollbackOpsLifo) {\n\t\t\t\t\tprocess(message);\n\t\t\t\t}\n\t\t\t\tconst count = this.pendingBatch.length - startPoint;\n\t\t\t\tif (count !== 0) {\n\t\t\t\t\tthrow new LoggingError(\"Ops generated during rollback\", {\n\t\t\t\t\t\tcount,\n\t\t\t\t\t\t...tagData(TelemetryDataTag.UserData, {\n\t\t\t\t\t\t\tops: serializeOp(this.pendingBatch.slice(startPoint).map((b) => b.runtimeOp))\n\t\t\t\t\t\t\t\t.content,\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Does this batch current contain user changes (\"dirtyable\" ops)?\n\t */\n\tpublic containsUserChanges(): boolean {\n\t\treturn this.pendingBatch.some((message) => isContainerMessageDirtyable(message.runtimeOp));\n\t}\n}\n\nexport const addBatchMetadata = (batch: LocalBatch, batchId?: BatchId): LocalBatch => {\n\tconst batchEnd = batch.messages.length - 1;\n\n\tconst firstMsg = batch.messages[0];\n\tconst lastMsg = batch.messages[batchEnd];\n\tassert(\n\t\tfirstMsg !== undefined && lastMsg !== undefined,\n\t\t0x9d1 /* expected non-empty batch */,\n\t);\n\n\tconst firstMetadata: Partial<IBatchMetadata> = firstMsg.metadata ?? {};\n\tconst lastMetadata: Partial<IBatchMetadata> = lastMsg.metadata ?? {};\n\n\t// Multi-message batches: mark the first and last messages with the \"batch\" flag indicating batch start/end\n\tif (batch.messages.length > 1) {\n\t\tfirstMetadata.batch = true;\n\t\tlastMetadata.batch = false;\n\t\tfirstMsg.metadata = firstMetadata;\n\t\tlastMsg.metadata = lastMetadata;\n\t}\n\n\t// If batchId is provided (e.g. in case of resubmit): stamp it on the first message\n\tif (batchId !== undefined) {\n\t\tfirstMetadata.batchId = batchId;\n\t\tfirstMsg.metadata = firstMetadata;\n\t}\n\n\treturn batch;\n};\n\nexport const sequenceNumbersMatch = (\n\tseqNums: BatchSequenceNumbers,\n\totherSeqNums: BatchSequenceNumbers,\n): boolean => {\n\treturn (\n\t\t(seqNums.referenceSequenceNumber === undefined ||\n\t\t\totherSeqNums.referenceSequenceNumber === undefined ||\n\t\t\tseqNums.referenceSequenceNumber === otherSeqNums.referenceSequenceNumber) &&\n\t\t(seqNums.clientSequenceNumber === undefined ||\n\t\t\totherSeqNums.clientSequenceNumber === undefined ||\n\t\t\tseqNums.clientSequenceNumber === otherSeqNums.clientSequenceNumber)\n\t);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"batchManager.js","sourceRoot":"","sources":["../../src/opLifecycle/batchManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,uEAIkD;AAGlD,gEAAqE;AACrE,gDAAsE;AAItE,6DAAmD;AAkBnD;;GAEG;AACH,SAAgB,eAAe,CAAC,gBAAwB,EAAE,aAAqB;IAC9E,OAAO,GAAG,gBAAgB,KAAK,aAAa,GAAG,CAAC;AACjD,CAAC;AAFD,0CAE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AK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC;QAC3B,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;QAC3B,QAAQ,CAAC,QAAQ,GAAG,aAAa,CAAC;QAClC,OAAO,CAAC,QAAQ,GAAG,YAAY,CAAC;IACjC,CAAC;IAED,mFAAmF;IACnF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC;QAChC,QAAQ,CAAC,QAAQ,GAAG,aAAa,CAAC;IACnC,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AA5BW,QAAA,gBAAgB,oBA4B3B;AAEK,MAAM,oBAAoB,GAAG,CACnC,OAA6B,EAC7B,YAAkC,EACxB,EAAE;IACZ,OAAO,CACN,CAAC,OAAO,CAAC,uBAAuB,KAAK,SAAS;QAC7C,YAAY,CAAC,uBAAuB,KAAK,SAAS;QAClD,OAAO,CAAC,uBAAuB,KAAK,YAAY,CAAC,uBAAuB,CAAC;QAC1E,CAAC,OAAO,CAAC,oBAAoB,KAAK,SAAS;YAC1C,YAAY,CAAC,oBAAoB,KAAK,SAAS;YAC/C,OAAO,CAAC,oBAAoB,KAAK,YAAY,CAAC,oBAAoB,CAAC,CACpE,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,oBAAoB,wBAY/B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tLoggingError,\n\ttagData,\n\tTelemetryDataTag,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ICompressionRuntimeOptions } from \"../compressionDefinitions.js\";\nimport { isContainerMessageDirtyable } from \"../containerRuntime.js\";\nimport { asBatchMetadata, type IBatchMetadata } from \"../metadata.js\";\nimport type { IPendingMessage } from \"../pendingStateManager.js\";\n\nimport type { LocalBatchMessage, IBatchCheckpoint, LocalBatch } from \"./definitions.js\";\nimport { serializeOp } from \"./opSerialization.js\";\nimport type { BatchStartInfo } from \"./remoteMessageProcessor.js\";\n\nexport interface IBatchManagerOptions {\n\treadonly disableGroupedBatching: boolean;\n\treadonly compressionOptions?: ICompressionRuntimeOptions;\n}\n\nexport interface BatchSequenceNumbers {\n\treferenceSequenceNumber?: number;\n\tclientSequenceNumber?: number;\n}\n\n/**\n * Type alias for the batchId stored in batch metadata\n */\nexport type BatchId = string;\n\n/**\n * Compose original client ID and client sequence number into BatchId to stamp on the message during reconnect\n */\nexport function generateBatchId(originalClientId: string, batchStartCsn: number): BatchId {\n\treturn `${originalClientId}_[${batchStartCsn}]`;\n}\n\n/**\n * Get the effective batch ID for the input argument.\n * Supports either an IPendingMessage or BatchStartInfo.\n * If the batch ID is explicitly present, return it.\n * Otherwise, generate a new batch ID using the client ID and batch start CSN.\n */\nexport function getEffectiveBatchId(\n\tpendingMessageOrBatchStartInfo: IPendingMessage | BatchStartInfo,\n): string {\n\tif (\"localOpMetadata\" in pendingMessageOrBatchStartInfo) {\n\t\tconst pendingMessage: IPendingMessage = pendingMessageOrBatchStartInfo;\n\t\treturn (\n\t\t\tasBatchMetadata(pendingMessage.opMetadata)?.batchId ??\n\t\t\tgenerateBatchId(\n\t\t\t\tpendingMessage.batchInfo.clientId,\n\t\t\t\tpendingMessage.batchInfo.batchStartCsn,\n\t\t\t)\n\t\t);\n\t}\n\n\tconst batchStart: BatchStartInfo = pendingMessageOrBatchStartInfo;\n\treturn batchStart.batchId ?? generateBatchId(batchStart.clientId, batchStart.batchStartCsn);\n}\n\n/**\n * Helper class that manages partial batch & rollback.\n */\nexport class BatchManager {\n\tprivate pendingBatch: LocalBatchMessage[] = [];\n\tprivate hasReentrantOps = false;\n\n\tpublic get length(): number {\n\t\treturn this.pendingBatch.length;\n\t}\n\n\tpublic get sequenceNumbers(): BatchSequenceNumbers {\n\t\treturn {\n\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t\tclientSequenceNumber: this.clientSequenceNumber,\n\t\t};\n\t}\n\n\tprivate get referenceSequenceNumber(): number | undefined {\n\t\treturn this.pendingBatch.length === 0\n\t\t\t? undefined\n\t\t\t: // NOTE: In case of reentrant ops, there could be multiple reference sequence numbers, but we will rebase before submitting.\n\t\t\t\tthis.pendingBatch[this.pendingBatch.length - 1].referenceSequenceNumber;\n\t}\n\n\t/**\n\t * The last-processed CSN when this batch started.\n\t * This is used to ensure that while the batch is open, no incoming ops are processed.\n\t */\n\tprivate clientSequenceNumber: number | undefined;\n\n\tconstructor(public readonly options: IBatchManagerOptions) {}\n\n\tpublic push(\n\t\tmessage: LocalBatchMessage,\n\t\treentrant: boolean,\n\t\tcurrentClientSequenceNumber?: number,\n\t): void {\n\t\tthis.hasReentrantOps = this.hasReentrantOps || reentrant;\n\n\t\tif (this.pendingBatch.length === 0) {\n\t\t\tthis.clientSequenceNumber = currentClientSequenceNumber;\n\t\t}\n\n\t\tthis.pendingBatch.push(message);\n\t}\n\n\tpublic get empty(): boolean {\n\t\treturn this.pendingBatch.length === 0;\n\t}\n\n\t/**\n\t * Gets the pending batch and clears state for the next batch.\n\t * The caller is responsible for calling {@link addBatchMetadata} after any modifications (e.g. prepending messages).\n\t */\n\tpublic popBatch(): LocalBatch {\n\t\tassert(this.pendingBatch[0] !== undefined, 0xb8a /* expected non-empty batch */);\n\t\tconst batch: LocalBatch = {\n\t\t\tmessages: this.pendingBatch,\n\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t\thasReentrantOps: this.hasReentrantOps,\n\t\t\tstaged: this.pendingBatch[0].staged,\n\t\t};\n\n\t\tthis.pendingBatch = [];\n\t\tthis.clientSequenceNumber = undefined;\n\t\tthis.hasReentrantOps = false;\n\n\t\treturn batch;\n\t}\n\n\t/**\n\t * Capture the pending state at this point\n\t */\n\tpublic checkpoint(): IBatchCheckpoint {\n\t\tconst startSequenceNumber = this.clientSequenceNumber;\n\t\tconst startPoint = this.pendingBatch.length;\n\t\treturn {\n\t\t\trollback: (process: (message: LocalBatchMessage) => void) => {\n\t\t\t\tthis.clientSequenceNumber = startSequenceNumber;\n\t\t\t\tconst rollbackOpsLifo = this.pendingBatch.splice(startPoint).reverse();\n\t\t\t\tfor (const message of rollbackOpsLifo) {\n\t\t\t\t\tprocess(message);\n\t\t\t\t}\n\t\t\t\tconst count = this.pendingBatch.length - startPoint;\n\t\t\t\tif (count !== 0) {\n\t\t\t\t\tthrow new LoggingError(\"Ops generated during rollback\", {\n\t\t\t\t\t\tcount,\n\t\t\t\t\t\t...tagData(TelemetryDataTag.UserData, {\n\t\t\t\t\t\t\tops: serializeOp(this.pendingBatch.slice(startPoint).map((b) => b.runtimeOp))\n\t\t\t\t\t\t\t\t.content,\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Does this batch current contain user changes (\"dirtyable\" ops)?\n\t */\n\tpublic containsUserChanges(): boolean {\n\t\treturn this.pendingBatch.some((message) => isContainerMessageDirtyable(message.runtimeOp));\n\t}\n}\n\nexport const addBatchMetadata = (batch: LocalBatch, batchId?: BatchId): LocalBatch => {\n\tconst batchEnd = batch.messages.length - 1;\n\n\tconst firstMsg = batch.messages[0];\n\tconst lastMsg = batch.messages[batchEnd];\n\tassert(\n\t\tfirstMsg !== undefined && lastMsg !== undefined,\n\t\t0x9d1 /* expected non-empty batch */,\n\t);\n\n\tconst firstMetadata: Partial<IBatchMetadata> = firstMsg.metadata ?? {};\n\tconst lastMetadata: Partial<IBatchMetadata> = lastMsg.metadata ?? {};\n\n\t// Multi-message batches: mark the first and last messages with the \"batch\" flag indicating batch start/end\n\tif (batch.messages.length > 1) {\n\t\tfirstMetadata.batch = true;\n\t\tlastMetadata.batch = false;\n\t\tfirstMsg.metadata = firstMetadata;\n\t\tlastMsg.metadata = lastMetadata;\n\t}\n\n\t// If batchId is provided (e.g. in case of resubmit): stamp it on the first message\n\tif (batchId !== undefined) {\n\t\tfirstMetadata.batchId = batchId;\n\t\tfirstMsg.metadata = firstMetadata;\n\t}\n\n\treturn batch;\n};\n\nexport const sequenceNumbersMatch = (\n\tseqNums: BatchSequenceNumbers,\n\totherSeqNums: BatchSequenceNumbers,\n): boolean => {\n\treturn (\n\t\t(seqNums.referenceSequenceNumber === undefined ||\n\t\t\totherSeqNums.referenceSequenceNumber === undefined ||\n\t\t\tseqNums.referenceSequenceNumber === otherSeqNums.referenceSequenceNumber) &&\n\t\t(seqNums.clientSequenceNumber === undefined ||\n\t\t\totherSeqNums.clientSequenceNumber === undefined ||\n\t\t\tseqNums.clientSequenceNumber === otherSeqNums.clientSequenceNumber)\n\t);\n};\n"]}
|
|
@@ -31,6 +31,13 @@ export interface IOutboxParameters {
|
|
|
31
31
|
readonly getCurrentSequenceNumbers: () => BatchSequenceNumbers;
|
|
32
32
|
readonly reSubmit: (message: PendingMessageResubmitData, squash: boolean) => void;
|
|
33
33
|
readonly opReentrancy: () => boolean;
|
|
34
|
+
/**
|
|
35
|
+
* JIT callback to generate an ID allocation op at flush time.
|
|
36
|
+
* Called after rebase (if any), so the returned message has the correct refSeq.
|
|
37
|
+
*
|
|
38
|
+
* @returns A LocalBatchMessage for the ID allocation op, or undefined if no IDs need allocating.
|
|
39
|
+
*/
|
|
40
|
+
readonly generateIdAllocationOp: () => LocalBatchMessage | undefined;
|
|
34
41
|
}
|
|
35
42
|
/**
|
|
36
43
|
* Info needed to correctly resubmit a batch
|
|
@@ -91,7 +98,6 @@ export declare class Outbox {
|
|
|
91
98
|
private readonly logger;
|
|
92
99
|
private readonly mainBatch;
|
|
93
100
|
private readonly blobAttachBatch;
|
|
94
|
-
private readonly idAllocationBatch;
|
|
95
101
|
private batchRebasesToReport;
|
|
96
102
|
private rebasing;
|
|
97
103
|
/**
|
|
@@ -106,7 +112,6 @@ export declare class Outbox {
|
|
|
106
112
|
get messageCount(): number;
|
|
107
113
|
get mainBatchMessageCount(): number;
|
|
108
114
|
get blobAttachBatchMessageCount(): number;
|
|
109
|
-
get idAllocationBatchMessageCount(): number;
|
|
110
115
|
get isEmpty(): boolean;
|
|
111
116
|
containsUserChanges(): boolean;
|
|
112
117
|
/**
|
|
@@ -120,10 +125,9 @@ export declare class Outbox {
|
|
|
120
125
|
* last message processed by the ContainerRuntime. In the absence of op reentrancy, this
|
|
121
126
|
* pair will remain stable during a single JS turn during which the batch is being built up.
|
|
122
127
|
*/
|
|
123
|
-
private
|
|
128
|
+
private outboxSequenceNumberCoherencyCheck;
|
|
124
129
|
submit(message: LocalBatchMessage): void;
|
|
125
130
|
submitBlobAttach(message: LocalBatchMessage): void;
|
|
126
|
-
submitIdAllocation(message: LocalBatchMessage): void;
|
|
127
131
|
private addMessageToBatchManager;
|
|
128
132
|
/**
|
|
129
133
|
* Flush all the batches to the ordering service.
|
|
@@ -171,7 +175,6 @@ export declare class Outbox {
|
|
|
171
175
|
*/
|
|
172
176
|
getBatchCheckpoints(): {
|
|
173
177
|
mainBatch: IBatchCheckpoint;
|
|
174
|
-
idAllocationBatch: IBatchCheckpoint;
|
|
175
178
|
blobAttachBatch: IBatchCheckpoint;
|
|
176
179
|
};
|
|
177
180
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/outbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AACpF,OAAO,KAAK,EACX,oBAAoB,EAEpB,MAAM,iCAAiC,CAAC;AAUzC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,KAAK,EACX,0BAA0B,EAC1B,mBAAmB,EACnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAEN,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/outbox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MAAM,EAAE,iBAAiB;IAOtD,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED,IAAW,qBAAqB,IAAI,MAAM,CAEzC;IAED,IAAW,2BAA2B,IAAI,MAAM,CAE/C;IAED,IAAW,OAAO,IAAI,OAAO,CAE5B;IAEM,mBAAmB,IAAI,OAAO;IAIrC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,kCAAkC;IA2DnC,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAMxC,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAMzD,OAAO,CAAC,wBAAwB;IAWhC;;;;;;OAMG;IACI,KAAK,CAAC,YAAY,CAAC,EAAE,iBAAiB,GAAG,IAAI;IAmBpD,OAAO,CAAC,QAAQ;IAkBhB,OAAO,CAAC,eAAe;IA6BvB,OAAO,CAAC,aAAa;IAuErB;;;;;OAKG;IACH,OAAO,CAAC,MAAM;IAgCd,OAAO,CAAC,kBAAkB;IAI1B;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,eAAe;IA4CvB;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAwCjB,OAAO,CAAC,sBAAsB;IAyB9B;;OAEG;IACI,mBAAmB,IAAI;QAC7B,SAAS,EAAE,gBAAgB,CAAC;QAC5B,eAAe,EAAE,gBAAgB,CAAC;KAClC;CASD"}
|
|
@@ -111,15 +111,11 @@ class Outbox {
|
|
|
111
111
|
this.maxMismatchedOpsToReport = 3;
|
|
112
112
|
this.mismatchedOpsReported = 0;
|
|
113
113
|
this.logger = (0, internal_2.createChildLogger)({ logger: params.logger, namespace: "Outbox" });
|
|
114
|
-
this.mainBatch = new batchManager_js_1.BatchManager({
|
|
115
|
-
this.blobAttachBatch = new batchManager_js_1.BatchManager({
|
|
116
|
-
this.idAllocationBatch = new batchManager_js_1.BatchManager({
|
|
117
|
-
canRebase: false,
|
|
118
|
-
ignoreBatchId: true,
|
|
119
|
-
});
|
|
114
|
+
this.mainBatch = new batchManager_js_1.BatchManager({ disableGroupedBatching: false });
|
|
115
|
+
this.blobAttachBatch = new batchManager_js_1.BatchManager({ disableGroupedBatching: true });
|
|
120
116
|
}
|
|
121
117
|
get messageCount() {
|
|
122
|
-
return this.mainBatch.length + this.blobAttachBatch.length
|
|
118
|
+
return this.mainBatch.length + this.blobAttachBatch.length;
|
|
123
119
|
}
|
|
124
120
|
get mainBatchMessageCount() {
|
|
125
121
|
return this.mainBatch.length;
|
|
@@ -127,16 +123,11 @@ class Outbox {
|
|
|
127
123
|
get blobAttachBatchMessageCount() {
|
|
128
124
|
return this.blobAttachBatch.length;
|
|
129
125
|
}
|
|
130
|
-
get idAllocationBatchMessageCount() {
|
|
131
|
-
return this.idAllocationBatch.length;
|
|
132
|
-
}
|
|
133
126
|
get isEmpty() {
|
|
134
127
|
return this.messageCount === 0;
|
|
135
128
|
}
|
|
136
129
|
containsUserChanges() {
|
|
137
|
-
return
|
|
138
|
-
// ID Allocation ops are not user changes
|
|
139
|
-
);
|
|
130
|
+
return this.mainBatch.containsUserChanges() || this.blobAttachBatch.containsUserChanges();
|
|
140
131
|
}
|
|
141
132
|
/**
|
|
142
133
|
* Detect whether batching has been interrupted by an incoming message being processed. In this case,
|
|
@@ -149,16 +140,13 @@ class Outbox {
|
|
|
149
140
|
* last message processed by the ContainerRuntime. In the absence of op reentrancy, this
|
|
150
141
|
* pair will remain stable during a single JS turn during which the batch is being built up.
|
|
151
142
|
*/
|
|
152
|
-
|
|
143
|
+
outboxSequenceNumberCoherencyCheck() {
|
|
153
144
|
const mainBatchSeqNums = this.mainBatch.sequenceNumbers;
|
|
154
145
|
const blobAttachSeqNums = this.blobAttachBatch.sequenceNumbers;
|
|
155
|
-
|
|
156
|
-
(0, internal_1.assert)((0, batchManager_js_1.sequenceNumbersMatch)(mainBatchSeqNums, blobAttachSeqNums) &&
|
|
157
|
-
(0, batchManager_js_1.sequenceNumbersMatch)(mainBatchSeqNums, idAllocSeqNums), 0x58d /* Reference sequence numbers from both batches must be in sync */);
|
|
146
|
+
(0, internal_1.assert)((0, batchManager_js_1.sequenceNumbersMatch)(mainBatchSeqNums, blobAttachSeqNums), 0x58d /* Reference sequence numbers from both batches must be in sync */);
|
|
158
147
|
const currentSequenceNumbers = this.params.getCurrentSequenceNumbers();
|
|
159
148
|
if ((0, batchManager_js_1.sequenceNumbersMatch)(mainBatchSeqNums, currentSequenceNumbers) &&
|
|
160
|
-
(0, batchManager_js_1.sequenceNumbersMatch)(blobAttachSeqNums, currentSequenceNumbers)
|
|
161
|
-
(0, batchManager_js_1.sequenceNumbersMatch)(idAllocSeqNums, currentSequenceNumbers)) {
|
|
149
|
+
(0, batchManager_js_1.sequenceNumbersMatch)(blobAttachSeqNums, currentSequenceNumbers)) {
|
|
162
150
|
// The reference sequence numbers are stable, there is nothing to do
|
|
163
151
|
return;
|
|
164
152
|
}
|
|
@@ -190,17 +178,13 @@ class Outbox {
|
|
|
190
178
|
throw errorWrapper.value;
|
|
191
179
|
}
|
|
192
180
|
submit(message) {
|
|
193
|
-
this.
|
|
181
|
+
this.outboxSequenceNumberCoherencyCheck();
|
|
194
182
|
this.addMessageToBatchManager(this.mainBatch, message);
|
|
195
183
|
}
|
|
196
184
|
submitBlobAttach(message) {
|
|
197
|
-
this.
|
|
185
|
+
this.outboxSequenceNumberCoherencyCheck();
|
|
198
186
|
this.addMessageToBatchManager(this.blobAttachBatch, message);
|
|
199
187
|
}
|
|
200
|
-
submitIdAllocation(message) {
|
|
201
|
-
this.maybeFlushPartialBatch();
|
|
202
|
-
this.addMessageToBatchManager(this.idAllocationBatch, message);
|
|
203
|
-
}
|
|
204
188
|
addMessageToBatchManager(batchManager, message) {
|
|
205
189
|
batchManager.push(message, this.isContextReentrant(), this.params.getCurrentSequenceNumbers().clientSequenceNumber);
|
|
206
190
|
}
|
|
@@ -213,17 +197,18 @@ class Outbox {
|
|
|
213
197
|
*/
|
|
214
198
|
flush(resubmitInfo) {
|
|
215
199
|
// We have nothing to flush if all batchManagers are empty, and we we're not needing to resubmit an empty batch placeholder
|
|
216
|
-
if (this.
|
|
217
|
-
this.blobAttachBatch.empty &&
|
|
200
|
+
if (this.blobAttachBatch.empty &&
|
|
218
201
|
this.mainBatch.empty &&
|
|
219
202
|
resubmitInfo?.batchId === undefined) {
|
|
203
|
+
// Note that it's possible that there are unfinalized ranges in the ID Compressor,
|
|
204
|
+
// but there's no urgency to flush those if they're not referenced in any messages.
|
|
220
205
|
return;
|
|
221
206
|
}
|
|
222
207
|
(0, internal_1.assert)(!this.isContextReentrant(), 0xb7b /* Flushing must not happen while incoming changes are being processed */);
|
|
223
208
|
this.flushAll(resubmitInfo);
|
|
224
209
|
}
|
|
225
210
|
flushAll(resubmitInfo) {
|
|
226
|
-
const allBatchesEmpty = this.
|
|
211
|
+
const allBatchesEmpty = this.blobAttachBatch.empty && this.mainBatch.empty;
|
|
227
212
|
if (allBatchesEmpty) {
|
|
228
213
|
// If we're resubmitting with a batchId and all batches are empty, we need to flush an empty batch.
|
|
229
214
|
// Note that we currently resubmit one batch at a time, so on resubmit, 1 of the 2 batches will *always* be empty.
|
|
@@ -235,22 +220,8 @@ class Outbox {
|
|
|
235
220
|
}
|
|
236
221
|
return;
|
|
237
222
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
this.flushInternal({
|
|
241
|
-
batchManager: this.idAllocationBatch,
|
|
242
|
-
// Note: For now, we will never stage ID Allocation messages.
|
|
243
|
-
// They won't contain personal info and no harm in extra allocations in case of discarding the staged changes
|
|
244
|
-
});
|
|
245
|
-
this.flushInternal({
|
|
246
|
-
batchManager: this.blobAttachBatch,
|
|
247
|
-
disableGroupedBatching: true,
|
|
248
|
-
resubmitInfo,
|
|
249
|
-
});
|
|
250
|
-
this.flushInternal({
|
|
251
|
-
batchManager: this.mainBatch,
|
|
252
|
-
resubmitInfo,
|
|
253
|
-
});
|
|
223
|
+
this.flushInternal(this.blobAttachBatch, resubmitInfo);
|
|
224
|
+
this.flushInternal(this.mainBatch, resubmitInfo);
|
|
254
225
|
}
|
|
255
226
|
flushEmptyBatch(resubmittingBatchId, resubmittingStagedBatch) {
|
|
256
227
|
const referenceSequenceNumber = this.params.getCurrentSequenceNumbers().referenceSequenceNumber;
|
|
@@ -264,20 +235,20 @@ class Outbox {
|
|
|
264
235
|
this.params.pendingStateManager.onFlushEmptyBatch(placeholderMessage, clientSequenceNumber, resubmittingStagedBatch);
|
|
265
236
|
return;
|
|
266
237
|
}
|
|
267
|
-
flushInternal(
|
|
268
|
-
const { batchManager, disableGroupedBatching = false, resubmitInfo } = params;
|
|
238
|
+
flushInternal(batchManager, resubmitInfo) {
|
|
269
239
|
if (batchManager.empty) {
|
|
270
240
|
return;
|
|
271
241
|
}
|
|
272
|
-
|
|
242
|
+
let rawBatch = batchManager.popBatch();
|
|
273
243
|
// On resubmit we use the original batch's staged state, so these should match as well.
|
|
274
244
|
const staged = rawBatch.staged === true;
|
|
275
245
|
(0, internal_1.assert)(resubmitInfo === undefined || resubmitInfo.staged === staged, 0xba3 /* Mismatch in staged state tracking */);
|
|
276
|
-
const groupingEnabled = !disableGroupedBatching &&
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
246
|
+
const groupingEnabled = !batchManager.options.disableGroupedBatching &&
|
|
247
|
+
this.params.groupingManager.groupedBatchingEnabled();
|
|
248
|
+
if (rawBatch.hasReentrantOps === true) {
|
|
249
|
+
(0, internal_1.assert)(resubmitInfo === undefined, 0xcf2 /* Re-submitting a batch with reentrant ops is not supported */);
|
|
280
250
|
(0, internal_1.assert)(!this.rebasing, 0x6fa /* A rebased batch should never have reentrant ops */);
|
|
251
|
+
// Rebase the current batch (resubmit the ops one-by-one) and then reinvoke flushInternal.
|
|
281
252
|
// If a batch contains reentrant ops (ops created as a result from processing another op)
|
|
282
253
|
// it needs to be rebased so that we can ensure consistent reference sequence numbers
|
|
283
254
|
// and eventual consistency at the DDS level.
|
|
@@ -287,16 +258,30 @@ class Outbox {
|
|
|
287
258
|
this.rebase(rawBatch, batchManager);
|
|
288
259
|
return;
|
|
289
260
|
}
|
|
290
|
-
let clientSequenceNumber;
|
|
291
261
|
// Did we disconnect? (i.e. is shouldSend false?)
|
|
292
262
|
// If so, do nothing, as pending state manager will resubmit it correctly on reconnect.
|
|
293
263
|
// Because flush() is a task that executes async (on clean stack), we can get here in disconnected state.
|
|
294
|
-
|
|
264
|
+
const shouldSendNow = this.params.shouldSend() && !staged;
|
|
265
|
+
let clientSequenceNumber;
|
|
266
|
+
if (shouldSendNow) {
|
|
267
|
+
// Generate ID Allocation op just-in-time, after rebase (if any), and before addBatchMetadata,
|
|
268
|
+
// so that the prepended idAllocMsg is correctly marked as the first op in the batch.
|
|
269
|
+
// This ensures the refSeq is correct (matching the rest of the batch) and that
|
|
270
|
+
// ID ranges aren't lost during rebase (since reSubmit drops IdAllocation ops).
|
|
271
|
+
// Only generate for non-staged batches — ID alloc ops are always non-staged.
|
|
272
|
+
const idAllocMsg = this.params.generateIdAllocationOp();
|
|
273
|
+
if (idAllocMsg !== undefined) {
|
|
274
|
+
rawBatch = { ...rawBatch, messages: [idAllocMsg, ...rawBatch.messages] };
|
|
275
|
+
}
|
|
276
|
+
(0, batchManager_js_1.addBatchMetadata)(rawBatch, resubmitInfo?.batchId);
|
|
295
277
|
const virtualizedBatch = this.virtualizeBatch(rawBatch, groupingEnabled);
|
|
296
278
|
clientSequenceNumber = this.sendBatch(virtualizedBatch);
|
|
297
279
|
(0, internal_1.assert)(clientSequenceNumber === undefined || clientSequenceNumber >= 0, 0x9d2 /* unexpected negative clientSequenceNumber (empty batch should yield undefined) */);
|
|
298
280
|
}
|
|
299
|
-
|
|
281
|
+
else {
|
|
282
|
+
(0, batchManager_js_1.addBatchMetadata)(rawBatch, resubmitInfo?.batchId);
|
|
283
|
+
}
|
|
284
|
+
this.params.pendingStateManager.onFlushBatch(rawBatch.messages, clientSequenceNumber, staged);
|
|
300
285
|
}
|
|
301
286
|
/**
|
|
302
287
|
* Rebases a batch. All the ops in the batch are resubmitted to the runtime and
|
|
@@ -306,7 +291,6 @@ class Outbox {
|
|
|
306
291
|
*/
|
|
307
292
|
rebase(rawBatch, batchManager) {
|
|
308
293
|
(0, internal_1.assert)(!this.rebasing, 0x6fb /* Reentrancy */);
|
|
309
|
-
(0, internal_1.assert)(batchManager.options.canRebase, 0x9a7 /* BatchManager does not support rebase */);
|
|
310
294
|
this.rebasing = true;
|
|
311
295
|
const squash = false;
|
|
312
296
|
for (const message of rawBatch.messages) {
|
|
@@ -324,7 +308,7 @@ class Outbox {
|
|
|
324
308
|
}, new internal_2.UsageError("BatchRebase"));
|
|
325
309
|
this.batchRebasesToReport--;
|
|
326
310
|
}
|
|
327
|
-
this.flushInternal(
|
|
311
|
+
this.flushInternal(batchManager);
|
|
328
312
|
this.rebasing = false;
|
|
329
313
|
}
|
|
330
314
|
isContextReentrant() {
|
|
@@ -437,7 +421,6 @@ class Outbox {
|
|
|
437
421
|
const mainBatch = this.mainBatch.checkpoint();
|
|
438
422
|
return {
|
|
439
423
|
mainBatch,
|
|
440
|
-
idAllocationBatch: this.idAllocationBatch.checkpoint(),
|
|
441
424
|
blobAttachBatch: this.blobAttachBatch.checkpoint(),
|
|
442
425
|
};
|
|
443
426
|
}
|