@fluidframework/datastore 1.2.6 → 2.0.0-dev.1.3.0.96595

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.
@@ -1 +1 @@
1
- {"version":3,"file":"remoteChannelContext.js","sourceRoot":"","sources":["../src/remoteChannelContext.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAStE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAe5D,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,EACH,iBAAiB,EACjB,sBAAsB,EAEtB,qBAAqB,GACxB,MAAM,kBAAkB,CAAC;AAK1B,MAAM,OAAO,oBAAoB;IAc7B,YACqB,OAA+B,EAC/B,gBAAwC,EACzD,cAAuC,EACvC,QAA0D,EAC1D,OAAkC,EAClC,0BAA2F,EAC1E,EAAU,EAC3B,YAA2B,EACV,QAA+B,EAChD,UAAoD,EACpD,oBAAiD,EACjD,gBAA8D,EAC7C,iBAA0B;QAZ1B,YAAO,GAAP,OAAO,CAAwB;QAC/B,qBAAgB,GAAhB,gBAAgB,CAAwB;QAKxC,OAAE,GAAF,EAAE,CAAQ;QAEV,aAAQ,GAAR,QAAQ,CAAuB;QAI/B,sBAAiB,GAAjB,iBAAiB,CAAS;QA1BvC,aAAQ,GAAG,KAAK,CAAC;QACjB,YAAO,GAA4C,EAAE,CAAC;QA2B1D,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,+CAA+C,CAAC,CAAC;QAEtF,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC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,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,2GAA2G;QAC3G,wGAAwG;QACxG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAClF,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,SAAS,CAAC,SAAkB,KAAK;QAC1C,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,iBAAiB,CAAC,SAAkB,KAAK;QACnD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,OAAO,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;IAEM,gBAAgB,CAAC,UAAoB,EAAE,WAAoB;QAC9D;;;;;WAKG;QACH,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;;AAnQuB,6CAAwB,GAAG,IAAI,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { DataCorruptionError } from \"@fluidframework/container-utils\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannel,\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { IDocumentStorageService } from \"@fluidframework/driver-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport {\n ISequencedDocumentMessage,\n ISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n CreateChildSummarizerNodeFn,\n IFluidDataStoreContext,\n IGarbageCollectionData,\n IGarbageCollectionDetailsBase,\n ISummarizeInternalResult,\n ISummarizeResult,\n ISummarizerNodeWithGC,\n ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { ChildLogger, TelemetryDataTag, ThresholdCounter } from \"@fluidframework/telemetry-utils\";\nimport {\n attributesBlobKey,\n createServiceEndpoints,\n IChannelContext,\n summarizeChannelAsync,\n} from \"./channelContext\";\nimport { ChannelDeltaConnection } from \"./channelDeltaConnection\";\nimport { ChannelStorageService } from \"./channelStorageService\";\nimport { ISharedObjectRegistry } from \"./dataStoreRuntime\";\n\nexport class RemoteChannelContext implements IChannelContext {\n private isLoaded = false;\n private pending: ISequencedDocumentMessage[] | undefined = [];\n private channelP: Promise<IChannel> | undefined;\n private channel: IChannel | undefined;\n private readonly services: {\n readonly deltaConnection: ChannelDeltaConnection;\n readonly objectStorage: ChannelStorageService;\n };\n private readonly summarizerNode: ISummarizerNodeWithGC;\n private readonly subLogger: ITelemetryLogger;\n private readonly thresholdOpsCounter: ThresholdCounter;\n private static readonly pendingOpsCountThreshold = 1000;\n\n constructor(\n private readonly runtime: IFluidDataStoreRuntime,\n private readonly dataStoreContext: IFluidDataStoreContext,\n storageService: IDocumentStorageService,\n submitFn: (content: any, localOpMetadata: unknown) => void,\n dirtyFn: (address: string) => void,\n addedGCOutboundReferenceFn: (srcHandle: IFluidHandle, outboundHandle: IFluidHandle) => void,\n private readonly id: string,\n baseSnapshot: ISnapshotTree,\n private readonly registry: ISharedObjectRegistry,\n extraBlobs: Map<string, ArrayBufferLike> | undefined,\n createSummarizerNode: CreateChildSummarizerNodeFn,\n getBaseGCDetails: () => Promise<IGarbageCollectionDetailsBase>,\n private readonly attachMessageType?: string,\n ) {\n assert(!this.id.includes(\"/\"), 0x310 /* Channel context ID cannot contain slashes */);\n\n this.subLogger = ChildLogger.create(this.runtime.logger, \"RemoteChannelContext\");\n\n this.services = createServiceEndpoints(\n this.id,\n this.dataStoreContext.connected,\n submitFn,\n () => dirtyFn(this.id),\n addedGCOutboundReferenceFn,\n storageService,\n this.subLogger,\n baseSnapshot,\n extraBlobs);\n\n const thisSummarizeInternal =\n async (fullTree: boolean, trackState: boolean, telemetryContext?: ITelemetryContext) =>\n this.summarizeInternal(fullTree, trackState, telemetryContext);\n\n this.summarizerNode = createSummarizerNode(\n thisSummarizeInternal,\n async (fullGC?: boolean) => this.getGCDataInternal(fullGC),\n async () => getBaseGCDetails(),\n );\n\n this.thresholdOpsCounter = new ThresholdCounter(\n RemoteChannelContext.pendingOpsCountThreshold,\n this.subLogger,\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n public getChannel(): Promise<IChannel> {\n if (this.channelP === undefined) {\n this.channelP = this.loadChannel();\n }\n\n return this.channelP;\n }\n\n public setConnectionState(connected: boolean, clientId?: string) {\n // Connection events are ignored if the data store is not yet loaded\n if (!this.isLoaded) {\n return;\n }\n\n this.services.deltaConnection.setConnectionState(connected);\n }\n\n public applyStashedOp(message: ISequencedDocumentMessage): unknown {\n assert(this.isLoaded, 0x194 /* \"Remote channel must be loaded when rebasing op\" */);\n return this.services.deltaConnection.applyStashedOp(message);\n }\n\n public processOp(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void {\n this.summarizerNode.invalidate(message.sequenceNumber);\n\n if (this.isLoaded) {\n this.services.deltaConnection.process(message, local, localOpMetadata);\n } else {\n assert(!local, 0x195 /* \"Remote channel must not be local when processing op\" */);\n assert(this.pending !== undefined, 0x23e /* \"pending is undefined\" */);\n this.pending.push(message);\n this.thresholdOpsCounter.sendIfMultiple(\"StorePendingOps\", this.pending.length);\n }\n }\n\n public reSubmit(content: any, localOpMetadata: unknown) {\n assert(this.isLoaded, 0x196 /* \"Remote channel must be loaded when resubmitting op\" */);\n\n this.services.deltaConnection.reSubmit(content, localOpMetadata);\n }\n\n public rollback(content: any, localOpMetadata: unknown) {\n assert(this.isLoaded, 0x2f0 /* \"Remote channel must be loaded when rolling back op\" */);\n\n this.services.deltaConnection.rollback(content, localOpMetadata);\n }\n\n /**\n * Returns a summary at the current sequence number.\n * @param fullTree - true to bypass optimizations and force a full summary tree\n * @param trackState - This tells whether we should track state from this summary.\n * @param telemetryContext - summary data passed through the layers for telemetry purposes\n */\n public async summarize(\n fullTree: boolean = false,\n trackState: boolean = true,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummarizeResult> {\n return this.summarizerNode.summarize(fullTree, trackState, telemetryContext);\n }\n\n private async summarizeInternal(\n fullTree: boolean,\n trackState: boolean,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummarizeInternalResult> {\n const channel = await this.getChannel();\n const summarizeResult = await summarizeChannelAsync(channel, fullTree, trackState, telemetryContext);\n return { ...summarizeResult, id: this.id };\n }\n\n private async loadChannel(): Promise<IChannel> {\n assert(!this.isLoaded, 0x197 /* \"Remote channel must not already be loaded when loading\" */);\n\n let attributes: IChannelAttributes | undefined;\n if (await this.services.objectStorage.contains(attributesBlobKey)) {\n attributes = await readAndParse<IChannelAttributes | undefined>(\n this.services.objectStorage,\n attributesBlobKey);\n }\n\n let factory: IChannelFactory | undefined;\n // this is a backward compatibility case where\n // the attach message doesn't include\n // the attributes. Since old attach messages\n // will not have attributes we need to keep\n // this as long as we support old attach messages\n if (attributes === undefined) {\n if (this.attachMessageType === undefined) {\n // TODO: dataStoreId may require a different tag from PackageData #7488\n throw new DataCorruptionError(\"channelTypeNotAvailable\", {\n channelId: {\n value: this.id,\n tag: TelemetryDataTag.PackageData,\n },\n dataStoreId: {\n value: this.dataStoreContext.id,\n tag: TelemetryDataTag.PackageData,\n },\n dataStorePackagePath: this.dataStoreContext.packagePath.join(\"/\"),\n });\n }\n factory = this.registry.get(this.attachMessageType);\n if (factory === undefined) {\n // TODO: dataStoreId may require a different tag from PackageData #7488\n throw new DataCorruptionError(\"channelFactoryNotRegisteredForAttachMessageType\", {\n channelId: {\n value: this.id,\n tag: TelemetryDataTag.PackageData,\n },\n dataStoreId: {\n value: this.dataStoreContext.id,\n tag: TelemetryDataTag.PackageData,\n },\n dataStorePackagePath: this.dataStoreContext.packagePath.join(\"/\"),\n channelFactoryType: this.attachMessageType,\n });\n }\n attributes = factory.attributes;\n } else {\n factory = this.registry.get(attributes.type);\n if (factory === undefined) {\n // TODO: dataStoreId may require a different tag from PackageData #7488\n throw new DataCorruptionError(\"channelFactoryNotRegisteredForGivenType\", {\n channelId: {\n value: this.id,\n tag: TelemetryDataTag.PackageData,\n },\n dataStoreId: {\n value: this.dataStoreContext.id,\n tag: TelemetryDataTag.PackageData,\n },\n dataStorePackagePath: this.dataStoreContext.packagePath.join(\"/\"),\n channelFactoryType: attributes.type,\n });\n }\n }\n\n // Compare snapshot version to collaborative object version\n if (attributes.snapshotFormatVersion !== undefined\n && attributes.snapshotFormatVersion !== factory.attributes.snapshotFormatVersion) {\n this.subLogger.sendTelemetryEvent(\n {\n eventName: \"ChannelAttributesVersionMismatch\",\n channelType: { value: attributes.type, tag: TelemetryDataTag.PackageData },\n channelSnapshotVersion: {\n value: `${attributes.snapshotFormatVersion}@${attributes.packageVersion}`,\n tag: TelemetryDataTag.PackageData,\n },\n channelCodeVersion: {\n value: `${factory.attributes.snapshotFormatVersion}@${factory.attributes.packageVersion}`,\n tag: TelemetryDataTag.PackageData,\n },\n },\n );\n }\n\n const channel = await factory.load(\n this.runtime,\n this.id,\n this.services,\n attributes);\n\n // Send all pending messages to the channel\n assert(this.pending !== undefined, 0x23f /* \"pending undefined\" */);\n for (const message of this.pending) {\n this.services.deltaConnection.process(message, false, undefined /* localOpMetadata */);\n }\n this.thresholdOpsCounter.send(\"ProcessPendingOps\", this.pending.length);\n\n // Commit changes.\n this.channel = channel;\n this.pending = undefined;\n this.isLoaded = true;\n\n // Because have some await between we created the service and here, the connection state might have changed\n // and we don't propagate the connection state when we are not loaded. So we have to set it again here.\n this.services.deltaConnection.setConnectionState(this.dataStoreContext.connected);\n return this.channel;\n }\n\n /**\n * Returns the data used for garbage collection. This includes a list of GC nodes that represent this context.\n * Each node has a set of outbound routes to other GC nodes in the document.\n * If there is no new data in this context since the last summary, previous GC data is used.\n * If there is new data, the GC data is generated again (by calling getGCDataInternal).\n * @param fullGC - true to bypass optimizations and force full generation of GC data.\n */\n public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {\n return this.summarizerNode.getGCData(fullGC);\n }\n\n /**\n * Generates the data used for garbage collection. This is called when there is new data since last summary. It\n * loads the context and calls into the channel to get its GC data.\n * @param fullGC - true to bypass optimizations and force full generation of GC data.\n */\n private async getGCDataInternal(fullGC: boolean = false): Promise<IGarbageCollectionData> {\n const channel = await this.getChannel();\n return channel.getGCData(fullGC);\n }\n\n public updateUsedRoutes(usedRoutes: string[], gcTimestamp?: number) {\n /**\n * Currently, DDSes are always considered referenced and are not garbage collected. Update the summarizer node's\n * used routes to contain a route to this channel context.\n * Once we have GC at DDS level, this will be updated to use the passed usedRoutes. See -\n * https://github.com/microsoft/FluidFramework/issues/4611\n */\n this.summarizerNode.updateUsedRoutes([\"\"]);\n }\n}\n"]}
1
+ {"version":3,"file":"remoteChannelContext.js","sourceRoot":"","sources":["../src/remoteChannelContext.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAStE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAe5D,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,EACH,iBAAiB,EACjB,sBAAsB,EAEtB,qBAAqB,GACxB,MAAM,kBAAkB,CAAC;AAK1B,MAAM,OAAO,oBAAoB;IAc7B,YACqB,OAA+B,EAC/B,gBAAwC,EACzD,cAAuC,EACvC,QAA0D,EAC1D,OAAkC,EAClC,0BAA2F,EAC1E,EAAU,EAC3B,YAA2B,EACV,QAA+B,EAChD,UAAoD,E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,CAAC;;AAnQuB,6CAAwB,GAAG,IAAI,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { DataCorruptionError } from \"@fluidframework/container-utils\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannel,\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { IDocumentStorageService } from \"@fluidframework/driver-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport {\n ISequencedDocumentMessage,\n ISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n CreateChildSummarizerNodeFn,\n IFluidDataStoreContext,\n IGarbageCollectionData,\n IGarbageCollectionDetailsBase,\n ISummarizeInternalResult,\n ISummarizeResult,\n ISummarizerNodeWithGC,\n ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { ChildLogger, TelemetryDataTag, ThresholdCounter } from \"@fluidframework/telemetry-utils\";\nimport {\n attributesBlobKey,\n createServiceEndpoints,\n IChannelContext,\n summarizeChannelAsync,\n} from \"./channelContext\";\nimport { ChannelDeltaConnection } from \"./channelDeltaConnection\";\nimport { ChannelStorageService } from \"./channelStorageService\";\nimport { ISharedObjectRegistry } from \"./dataStoreRuntime\";\n\nexport class RemoteChannelContext implements IChannelContext {\n private isLoaded = false;\n private pending: ISequencedDocumentMessage[] | undefined = [];\n private channelP: Promise<IChannel> | undefined;\n private channel: IChannel | undefined;\n private readonly services: {\n readonly deltaConnection: ChannelDeltaConnection;\n readonly objectStorage: ChannelStorageService;\n };\n private readonly summarizerNode: ISummarizerNodeWithGC;\n private readonly subLogger: ITelemetryLogger;\n private readonly thresholdOpsCounter: ThresholdCounter;\n private static readonly pendingOpsCountThreshold = 1000;\n\n constructor(\n private readonly runtime: IFluidDataStoreRuntime,\n private readonly dataStoreContext: IFluidDataStoreContext,\n storageService: IDocumentStorageService,\n submitFn: (content: any, localOpMetadata: unknown) => void,\n dirtyFn: (address: string) => void,\n addedGCOutboundReferenceFn: (srcHandle: IFluidHandle, outboundHandle: IFluidHandle) => void,\n private readonly id: string,\n baseSnapshot: ISnapshotTree,\n private readonly registry: ISharedObjectRegistry,\n extraBlobs: Map<string, ArrayBufferLike> | undefined,\n createSummarizerNode: CreateChildSummarizerNodeFn,\n getBaseGCDetails: () => Promise<IGarbageCollectionDetailsBase>,\n private readonly attachMessageType?: string,\n ) {\n assert(!this.id.includes(\"/\"), 0x310 /* Channel context ID cannot contain slashes */);\n\n this.subLogger = ChildLogger.create(this.runtime.logger, \"RemoteChannelContext\");\n\n this.services = createServiceEndpoints(\n this.id,\n this.dataStoreContext.connected,\n submitFn,\n () => dirtyFn(this.id),\n addedGCOutboundReferenceFn,\n storageService,\n this.subLogger,\n baseSnapshot,\n extraBlobs);\n\n const thisSummarizeInternal =\n async (fullTree: boolean, trackState: boolean, telemetryContext?: ITelemetryContext) =>\n this.summarizeInternal(fullTree, trackState, telemetryContext);\n\n this.summarizerNode = createSummarizerNode(\n thisSummarizeInternal,\n async (fullGC?: boolean) => this.getGCDataInternal(fullGC),\n async () => getBaseGCDetails(),\n );\n\n this.thresholdOpsCounter = new ThresholdCounter(\n RemoteChannelContext.pendingOpsCountThreshold,\n this.subLogger,\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n public getChannel(): Promise<IChannel> {\n if (this.channelP === undefined) {\n this.channelP = this.loadChannel();\n }\n\n return this.channelP;\n }\n\n public setConnectionState(connected: boolean, clientId?: string) {\n // Connection events are ignored if the data store is not yet loaded\n if (!this.isLoaded) {\n return;\n }\n\n this.services.deltaConnection.setConnectionState(connected);\n }\n\n public applyStashedOp(message: ISequencedDocumentMessage): unknown {\n assert(this.isLoaded, 0x194 /* \"Remote channel must be loaded when rebasing op\" */);\n return this.services.deltaConnection.applyStashedOp(message);\n }\n\n public processOp(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void {\n this.summarizerNode.invalidate(message.sequenceNumber);\n\n if (this.isLoaded) {\n this.services.deltaConnection.process(message, local, localOpMetadata);\n } else {\n assert(!local, 0x195 /* \"Remote channel must not be local when processing op\" */);\n assert(this.pending !== undefined, 0x23e /* \"pending is undefined\" */);\n this.pending.push(message);\n this.thresholdOpsCounter.sendIfMultiple(\"StorePendingOps\", this.pending.length);\n }\n }\n\n public reSubmit(content: any, localOpMetadata: unknown) {\n assert(this.isLoaded, 0x196 /* \"Remote channel must be loaded when resubmitting op\" */);\n\n this.services.deltaConnection.reSubmit(content, localOpMetadata);\n }\n\n public rollback(content: any, localOpMetadata: unknown) {\n assert(this.isLoaded, 0x2f0 /* \"Remote channel must be loaded when rolling back op\" */);\n\n this.services.deltaConnection.rollback(content, localOpMetadata);\n }\n\n /**\n * Returns a summary at the current sequence number.\n * @param fullTree - true to bypass optimizations and force a full summary tree\n * @param trackState - This tells whether we should track state from this summary.\n * @param telemetryContext - summary data passed through the layers for telemetry purposes\n */\n public async summarize(\n fullTree: boolean = false,\n trackState: boolean = true,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummarizeResult> {\n return this.summarizerNode.summarize(fullTree, trackState, telemetryContext);\n }\n\n private async summarizeInternal(\n fullTree: boolean,\n trackState: boolean,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummarizeInternalResult> {\n const channel = await this.getChannel();\n const summarizeResult = await summarizeChannelAsync(channel, fullTree, trackState, telemetryContext);\n return { ...summarizeResult, id: this.id };\n }\n\n private async loadChannel(): Promise<IChannel> {\n assert(!this.isLoaded, 0x197 /* \"Remote channel must not already be loaded when loading\" */);\n\n let attributes: IChannelAttributes | undefined;\n if (await this.services.objectStorage.contains(attributesBlobKey)) {\n attributes = await readAndParse<IChannelAttributes | undefined>(\n this.services.objectStorage,\n attributesBlobKey);\n }\n\n let factory: IChannelFactory | undefined;\n // this is a backward compatibility case where\n // the attach message doesn't include\n // the attributes. Since old attach messages\n // will not have attributes we need to keep\n // this as long as we support old attach messages\n if (attributes === undefined) {\n if (this.attachMessageType === undefined) {\n // TODO: dataStoreId may require a different tag from PackageData #7488\n throw new DataCorruptionError(\"channelTypeNotAvailable\", {\n channelId: {\n value: this.id,\n tag: TelemetryDataTag.CodeArtifact,\n },\n dataStoreId: {\n value: this.dataStoreContext.id,\n tag: TelemetryDataTag.CodeArtifact,\n },\n dataStorePackagePath: this.dataStoreContext.packagePath.join(\"/\"),\n });\n }\n factory = this.registry.get(this.attachMessageType);\n if (factory === undefined) {\n // TODO: dataStoreId may require a different tag from PackageData #7488\n throw new DataCorruptionError(\"channelFactoryNotRegisteredForAttachMessageType\", {\n channelId: {\n value: this.id,\n tag: TelemetryDataTag.CodeArtifact,\n },\n dataStoreId: {\n value: this.dataStoreContext.id,\n tag: TelemetryDataTag.CodeArtifact,\n },\n dataStorePackagePath: this.dataStoreContext.packagePath.join(\"/\"),\n channelFactoryType: this.attachMessageType,\n });\n }\n attributes = factory.attributes;\n } else {\n factory = this.registry.get(attributes.type);\n if (factory === undefined) {\n // TODO: dataStoreId may require a different tag from PackageData #7488\n throw new DataCorruptionError(\"channelFactoryNotRegisteredForGivenType\", {\n channelId: {\n value: this.id,\n tag: TelemetryDataTag.CodeArtifact,\n },\n dataStoreId: {\n value: this.dataStoreContext.id,\n tag: TelemetryDataTag.CodeArtifact,\n },\n dataStorePackagePath: this.dataStoreContext.packagePath.join(\"/\"),\n channelFactoryType: attributes.type,\n });\n }\n }\n\n // Compare snapshot version to collaborative object version\n if (attributes.snapshotFormatVersion !== undefined\n && attributes.snapshotFormatVersion !== factory.attributes.snapshotFormatVersion) {\n this.subLogger.sendTelemetryEvent(\n {\n eventName: \"ChannelAttributesVersionMismatch\",\n channelType: { value: attributes.type, tag: TelemetryDataTag.CodeArtifact },\n channelSnapshotVersion: {\n value: `${attributes.snapshotFormatVersion}@${attributes.packageVersion}`,\n tag: TelemetryDataTag.CodeArtifact,\n },\n channelCodeVersion: {\n value: `${factory.attributes.snapshotFormatVersion}@${factory.attributes.packageVersion}`,\n tag: TelemetryDataTag.CodeArtifact,\n },\n },\n );\n }\n\n const channel = await factory.load(\n this.runtime,\n this.id,\n this.services,\n attributes);\n\n // Send all pending messages to the channel\n assert(this.pending !== undefined, 0x23f /* \"pending undefined\" */);\n for (const message of this.pending) {\n this.services.deltaConnection.process(message, false, undefined /* localOpMetadata */);\n }\n this.thresholdOpsCounter.send(\"ProcessPendingOps\", this.pending.length);\n\n // Commit changes.\n this.channel = channel;\n this.pending = undefined;\n this.isLoaded = true;\n\n // Because have some await between we created the service and here, the connection state might have changed\n // and we don't propagate the connection state when we are not loaded. So we have to set it again here.\n this.services.deltaConnection.setConnectionState(this.dataStoreContext.connected);\n return this.channel;\n }\n\n /**\n * Returns the data used for garbage collection. This includes a list of GC nodes that represent this context.\n * Each node has a set of outbound routes to other GC nodes in the document.\n * If there is no new data in this context since the last summary, previous GC data is used.\n * If there is new data, the GC data is generated again (by calling getGCDataInternal).\n * @param fullGC - true to bypass optimizations and force full generation of GC data.\n */\n public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {\n return this.summarizerNode.getGCData(fullGC);\n }\n\n /**\n * Generates the data used for garbage collection. This is called when there is new data since last summary. It\n * loads the context and calls into the channel to get its GC data.\n * @param fullGC - true to bypass optimizations and force full generation of GC data.\n */\n private async getGCDataInternal(fullGC: boolean = false): Promise<IGarbageCollectionData> {\n const channel = await this.getChannel();\n return channel.getGCData(fullGC);\n }\n\n public updateUsedRoutes(usedRoutes: string[], gcTimestamp?: number) {\n /**\n * Currently, DDSes are always considered referenced and are not garbage collected. Update the summarizer node's\n * used routes to contain a route to this channel context.\n * Once we have GC at DDS level, this will be updated to use the passed usedRoutes. See -\n * https://github.com/microsoft/FluidFramework/issues/4611\n */\n this.summarizerNode.updateUsedRoutes([\"\"]);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/datastore",
3
- "version": "1.2.6",
3
+ "version": "2.0.0-dev.1.3.0.96595",
4
4
  "description": "Fluid data store implementation",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -62,36 +62,36 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@fluidframework/common-definitions": "^0.20.1",
65
- "@fluidframework/common-utils": "^0.32.1",
66
- "@fluidframework/container-definitions": "^1.2.6",
67
- "@fluidframework/container-utils": "^1.2.6",
68
- "@fluidframework/core-interfaces": "^1.2.6",
69
- "@fluidframework/datastore-definitions": "^1.2.6",
70
- "@fluidframework/driver-definitions": "^1.2.6",
71
- "@fluidframework/driver-utils": "^1.2.6",
72
- "@fluidframework/garbage-collector": "^1.2.6",
73
- "@fluidframework/protocol-base": "^0.1036.5000",
74
- "@fluidframework/protocol-definitions": "^0.1028.2000",
75
- "@fluidframework/runtime-definitions": "^1.2.6",
76
- "@fluidframework/runtime-utils": "^1.2.6",
77
- "@fluidframework/telemetry-utils": "^1.2.6",
65
+ "@fluidframework/common-utils": "^1.0.0",
66
+ "@fluidframework/container-definitions": "2.0.0-dev.1.3.0.96595",
67
+ "@fluidframework/container-utils": "2.0.0-dev.1.3.0.96595",
68
+ "@fluidframework/core-interfaces": "2.0.0-dev.1.3.0.96595",
69
+ "@fluidframework/datastore-definitions": "2.0.0-dev.1.3.0.96595",
70
+ "@fluidframework/driver-definitions": "2.0.0-dev.1.3.0.96595",
71
+ "@fluidframework/driver-utils": "2.0.0-dev.1.3.0.96595",
72
+ "@fluidframework/garbage-collector": "2.0.0-dev.1.3.0.96595",
73
+ "@fluidframework/protocol-base": "^0.1037.2001",
74
+ "@fluidframework/protocol-definitions": "^1.0.0",
75
+ "@fluidframework/runtime-definitions": "2.0.0-dev.1.3.0.96595",
76
+ "@fluidframework/runtime-utils": "2.0.0-dev.1.3.0.96595",
77
+ "@fluidframework/telemetry-utils": "2.0.0-dev.1.3.0.96595",
78
78
  "lodash": "^4.17.21",
79
79
  "uuid": "^8.3.1"
80
80
  },
81
81
  "devDependencies": {
82
- "@fluidframework/build-common": "^0.24.0",
83
- "@fluidframework/build-tools": "^0.2.74327",
84
- "@fluidframework/datastore-previous": "npm:@fluidframework/datastore@1.2.1",
85
- "@fluidframework/eslint-config-fluid": "^0.28.2000",
86
- "@fluidframework/mocha-test-setup": "^1.2.6",
87
- "@fluidframework/test-runtime-utils": "^1.2.6",
82
+ "@fluidframework/build-common": "^1.0.0",
83
+ "@fluidframework/build-tools": "^0.4.6000",
84
+ "@fluidframework/datastore-previous": "npm:@fluidframework/datastore@^1.0.0",
85
+ "@fluidframework/eslint-config-fluid": "^1.0.0",
86
+ "@fluidframework/mocha-test-setup": "2.0.0-dev.1.3.0.96595",
87
+ "@fluidframework/test-runtime-utils": "2.0.0-dev.1.3.0.96595",
88
88
  "@microsoft/api-extractor": "^7.22.2",
89
89
  "@rushstack/eslint-config": "^2.5.1",
90
90
  "@types/mocha": "^9.1.1",
91
91
  "@types/node": "^14.18.0",
92
92
  "@types/uuid": "^8.3.0",
93
93
  "concurrently": "^6.2.0",
94
- "copyfiles": "^2.1.0",
94
+ "copyfiles": "^2.4.1",
95
95
  "cross-env": "^7.0.2",
96
96
  "eslint": "~8.6.0",
97
97
  "mocha": "^10.0.0",
@@ -101,7 +101,7 @@
101
101
  "typescript-formatter": "7.1.0"
102
102
  },
103
103
  "typeValidation": {
104
- "version": "1.2.2",
104
+ "version": "2.0.0",
105
105
  "broken": {}
106
106
  }
107
107
  }
@@ -13,7 +13,6 @@ import {
13
13
  import {
14
14
  IAudience,
15
15
  IDeltaManager,
16
- BindState,
17
16
  AttachState,
18
17
  ILoaderOptions,
19
18
  } from "@fluidframework/container-definitions";
@@ -41,6 +40,7 @@ import {
41
40
  IQuorumClients,
42
41
  } from "@fluidframework/protocol-definitions";
43
42
  import {
43
+ BindState,
44
44
  CreateSummarizerNodeSource,
45
45
  IAttachMessage,
46
46
  IEnvelope,
@@ -273,10 +273,12 @@ IFluidDataStoreChannel, IFluidDataStoreRuntime, IFluidHandleContext {
273
273
  /**
274
274
  * If existing flag is false, this is a new data store and is not visible. The existing flag can be true in two
275
275
  * conditions:
276
+ *
276
277
  * 1. It's a local data store that is created when a detached container is rehydrated. In this case, the data
277
- * store is locally visible because the snapshot it is loaded from contains locally visible data stores only.
278
+ * store is locally visible because the snapshot it is loaded from contains locally visible data stores only.
279
+ *
278
280
  * 2. It's a remote data store that is created when an attached container is loaded is loaded from snapshot or
279
- * when an attach op comes in. In both these cases, the data store is already globally visible.
281
+ * when an attach op comes in. In both these cases, the data store is already globally visible.
280
282
  */
281
283
  if (existing) {
282
284
  this.visibilityState = dataStoreContext.attachState === AttachState.Detached
@@ -422,11 +424,14 @@ IFluidDataStoreChannel, IFluidDataStoreRuntime, IFluidHandleContext {
422
424
 
423
425
  /**
424
426
  * This function is called when a data store becomes root. It does the following:
427
+ *
425
428
  * 1. Marks the data store locally visible in the container.
429
+ *
426
430
  * 2. Attaches the graph of all the handles bound to it.
431
+ *
427
432
  * 3. Calls into the data store context to mark it visible in the container too. If the container is globally
428
- * visible, it will mark us globally visible. Otherwise, it will mark us globally visible when it becomes
429
- * globally visible.
433
+ * visible, it will mark us globally visible. Otherwise, it will mark us globally visible when it becomes
434
+ * globally visible.
430
435
  */
431
436
  public makeVisibleAndAttachGraph() {
432
437
  if (this.visibilityState !== VisibilityState.NotVisible) {
@@ -449,6 +454,7 @@ IFluidDataStoreChannel, IFluidDataStoreRuntime, IFluidHandleContext {
449
454
  }
450
455
 
451
456
  /**
457
+ * @deprecated - Not necessary if consumers add a new dataStore to the container by storing its handle.
452
458
  * Binds this runtime to the container
453
459
  * This includes the following:
454
460
  * 1. Sending an Attach op that includes all existing state
@@ -618,11 +624,15 @@ IFluidDataStoreChannel, IFluidDataStoreRuntime, IFluidHandleContext {
618
624
  * Generates data used for garbage collection. This includes a list of GC nodes that represent this channel
619
625
  * including any of its child channel contexts. Each node has a set of outbound routes to other GC nodes in the
620
626
  * document. It does the following:
627
+ *
621
628
  * 1. Calls into each child context to get its GC data.
629
+ *
622
630
  * 2. Prefixes the child context's id to the GC nodes in the child's GC data. This makes sure that the node can be
623
- * identified as belonging to the child.
631
+ * identified as belonging to the child.
632
+ *
624
633
  * 3. Adds a GC node for this channel to the nodes received from the children. All these nodes together represent
625
- * the GC data of this channel.
634
+ * the GC data of this channel.
635
+ *
626
636
  * @param fullGC - true to bypass optimizations and force full generation of GC data.
627
637
  */
628
638
  public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
@@ -734,21 +744,21 @@ IFluidDataStoreChannel, IFluidDataStoreRuntime, IFluidHandleContext {
734
744
  * back-compat 0.59.1000 - getAttachSummary() is called when making a data store globally visible (previously
735
745
  * attaching state). Ideally, attachGraph() should have already be called making it locally visible. However,
736
746
  * before visibility state was added, this may not have been the case and getAttachSummary() could be called:
737
- * 1) Before attaching the data store - When a detached container is attached.
738
- * 2) After attaching the data store - When a data store is created and bound in an attached container.
747
+ *
748
+ * 1. Before attaching the data store - When a detached container is attached.
749
+ *
750
+ * 2. After attaching the data store - When a data store is created and bound in an attached container.
739
751
  *
740
752
  * The basic idea is that all local object should become locally visible before they are globally visible.
741
753
  */
742
754
  this.attachGraph();
743
755
 
744
- /**
745
- * This assert cannot be added now due to back-compat. To be uncommented when the following issue is fixed -
746
- * https://github.com/microsoft/FluidFramework/issues/9688.
747
- *
748
- * assert(this.visibilityState === VisibilityState.LocallyVisible,
749
- * "The data store should be locally visible when generating attach summary",
750
- * );
751
- */
756
+ // This assert cannot be added now due to back-compat. To be uncommented when the following issue is fixed -
757
+ // https://github.com/microsoft/FluidFramework/issues/9688.
758
+ //
759
+ // assert(this.visibilityState === VisibilityState.LocallyVisible,
760
+ // "The data store should be locally visible when generating attach summary",
761
+ // );
752
762
 
753
763
  const summaryBuilder = new SummaryTreeBuilder();
754
764
 
@@ -29,15 +29,19 @@ export class FluidObjectHandle<T extends FluidObject = FluidObject> implements I
29
29
  * should be enough for a handle. However, there are scenarios where the object becomes locally visible but the
30
30
  * handle does not know this - This will happen is attachGraph is never called on the handle. Couple of examples
31
31
  * where this can happen:
32
+ *
32
33
  * 1. Handles to DDS other than the default handle won't know if the DDS becomes visible after the handle was
33
- * created.
34
+ * created.
35
+ *
34
36
  * 2. Handles to root data stores will never know that it was visible because the handle will not be stores in
35
- * another DDS and so, attachGraph will never be called on it.
37
+ * another DDS and so, attachGraph will never be called on it.
36
38
  */
37
39
  return this.isAttached || this.locallyVisible;
38
40
  }
39
41
 
40
- // Tracks whether this handle is locally visible in the container.
42
+ /**
43
+ * Tracks whether this handle is locally visible in the container.
44
+ */
41
45
  private locallyVisible: boolean = false;
42
46
 
43
47
  /**
@@ -47,7 +51,7 @@ export class FluidObjectHandle<T extends FluidObject = FluidObject> implements I
47
51
  * @param routeContext - The parent IFluidHandleContext that has a route to this handle.
48
52
  */
49
53
  constructor(
50
- protected readonly value: T,
54
+ protected readonly value: T | Promise<T>,
51
55
  public readonly path: string,
52
56
  public readonly routeContext: IFluidHandleContext,
53
57
  ) {
@@ -55,6 +59,7 @@ export class FluidObjectHandle<T extends FluidObject = FluidObject> implements I
55
59
  }
56
60
 
57
61
  public async get(): Promise<any> {
62
+ // Note that this return works whether we received a T or a Promise<T> for this.value in the constructor.
58
63
  return this.value;
59
64
  }
60
65
 
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/datastore";
9
- export const pkgVersion = "1.2.6";
9
+ export const pkgVersion = "2.0.0-dev.1.3.0.96595";
@@ -194,11 +194,11 @@ export class RemoteChannelContext implements IChannelContext {
194
194
  throw new DataCorruptionError("channelTypeNotAvailable", {
195
195
  channelId: {
196
196
  value: this.id,
197
- tag: TelemetryDataTag.PackageData,
197
+ tag: TelemetryDataTag.CodeArtifact,
198
198
  },
199
199
  dataStoreId: {
200
200
  value: this.dataStoreContext.id,
201
- tag: TelemetryDataTag.PackageData,
201
+ tag: TelemetryDataTag.CodeArtifact,
202
202
  },
203
203
  dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
204
204
  });
@@ -209,11 +209,11 @@ export class RemoteChannelContext implements IChannelContext {
209
209
  throw new DataCorruptionError("channelFactoryNotRegisteredForAttachMessageType", {
210
210
  channelId: {
211
211
  value: this.id,
212
- tag: TelemetryDataTag.PackageData,
212
+ tag: TelemetryDataTag.CodeArtifact,
213
213
  },
214
214
  dataStoreId: {
215
215
  value: this.dataStoreContext.id,
216
- tag: TelemetryDataTag.PackageData,
216
+ tag: TelemetryDataTag.CodeArtifact,
217
217
  },
218
218
  dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
219
219
  channelFactoryType: this.attachMessageType,
@@ -227,11 +227,11 @@ export class RemoteChannelContext implements IChannelContext {
227
227
  throw new DataCorruptionError("channelFactoryNotRegisteredForGivenType", {
228
228
  channelId: {
229
229
  value: this.id,
230
- tag: TelemetryDataTag.PackageData,
230
+ tag: TelemetryDataTag.CodeArtifact,
231
231
  },
232
232
  dataStoreId: {
233
233
  value: this.dataStoreContext.id,
234
- tag: TelemetryDataTag.PackageData,
234
+ tag: TelemetryDataTag.CodeArtifact,
235
235
  },
236
236
  dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
237
237
  channelFactoryType: attributes.type,
@@ -245,14 +245,14 @@ export class RemoteChannelContext implements IChannelContext {
245
245
  this.subLogger.sendTelemetryEvent(
246
246
  {
247
247
  eventName: "ChannelAttributesVersionMismatch",
248
- channelType: { value: attributes.type, tag: TelemetryDataTag.PackageData },
248
+ channelType: { value: attributes.type, tag: TelemetryDataTag.CodeArtifact },
249
249
  channelSnapshotVersion: {
250
250
  value: `${attributes.snapshotFormatVersion}@${attributes.packageVersion}`,
251
- tag: TelemetryDataTag.PackageData,
251
+ tag: TelemetryDataTag.CodeArtifact,
252
252
  },
253
253
  channelCodeVersion: {
254
254
  value: `${factory.attributes.snapshotFormatVersion}@${factory.attributes.packageVersion}`,
255
- tag: TelemetryDataTag.PackageData,
255
+ tag: TelemetryDataTag.CodeArtifact,
256
256
  },
257
257
  },
258
258
  );