Skip to content

Runtime: Expose readonly directly off the datastore runtime #24410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1147ba3
Runtime: Expose readonly directly off the datastore runtime
anthony-murphy Apr 21, 2025
d69491f
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
anthony-murphy Apr 21, 2025
a47722c
update type tests
anthony-murphy Apr 21, 2025
f05624c
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
anthony-murphy Apr 21, 2025
3f54418
revert whitespace
anthony-murphy Apr 21, 2025
6f22dec
update tests
anthony-murphy Apr 22, 2025
780ab0e
fixes
anthony-murphy Apr 22, 2025
b11bf64
regen docs
anthony-murphy Apr 22, 2025
948c6a4
Merge branch 'main' into ro/datastore-readonly
anthony-murphy Apr 22, 2025
413dce5
update feature name
anthony-murphy Apr 22, 2025
5691bb5
Update packages/runtime/container-runtime/src/dataStoreContext.ts
anthony-murphy Apr 22, 2025
0a7fe4d
Update packages/runtime/container-runtime/src/dataStoreContext.ts
anthony-murphy Apr 22, 2025
1f12146
Update packages/runtime/container-runtime/src/dataStoreContext.ts
anthony-murphy Apr 22, 2025
c155032
Update packages/runtime/container-runtime/src/dataStoreContext.ts
anthony-murphy Apr 22, 2025
57a7351
small fixes
anthony-murphy Apr 22, 2025
c8cddcd
Merge branch 'ro/datastore-readonly' of https://github.com/anthony-mu…
anthony-murphy Apr 22, 2025
e465ca4
add some comments
anthony-murphy Apr 22, 2025
e1c1788
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
anthony-murphy Apr 22, 2025
1e6bead
more comments
anthony-murphy Apr 22, 2025
c5ba247
PR feedback
anthony-murphy Apr 23, 2025
c7ccef3
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
anthony-murphy Apr 23, 2025
988ab66
update name to notifyReadOnlyState
anthony-murphy Apr 23, 2025
c71914d
fix delta manager proxy disposal
anthony-murphy Apr 23, 2025
58522b6
remove tri-state
anthony-murphy Apr 23, 2025
c27695d
move readonly to method
anthony-murphy Apr 23, 2025
e045be5
fix test
anthony-murphy Apr 23, 2025
880b14e
Update packages/runtime/datastore-definitions/src/dataStoreRuntime.ts
anthony-murphy Apr 23, 2025
7fb62fe
update comments
anthony-murphy Apr 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/framework/aqueduct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@
"typescript": "~5.4.5"
},
"typeValidation": {
"broken": {},
"broken": {
"Interface_IDataObjectProps": {
"forwardCompat": false
}
},
"entrypoint": "legacy"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ declare type current_as_old_for_Interface_DataObjectTypes = requireAssignableTo<
* typeValidation.broken:
* "Interface_IDataObjectProps": {"forwardCompat": false}
*/
// @ts-expect-error compatibility expected to be broken
declare type old_as_current_for_Interface_IDataObjectProps = requireAssignableTo<TypeOnly<old.IDataObjectProps>, TypeOnly<current.IDataObjectProps>>

/*
Expand Down
25 changes: 25 additions & 0 deletions packages/runtime/container-runtime/src/channelCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ export function wrapContext(context: IFluidParentContext): IFluidParentContext {
get attachState() {
return context.attachState;
},
get readonly() {
return context.readonly;
},
containerRuntime: context.containerRuntime,
scope: context.scope,
gcThrowOnTombstoneUsage: context.gcThrowOnTombstoneUsage,
Expand Down Expand Up @@ -1116,6 +1119,28 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable {
}
}

public setReadOnlyState(readonly: boolean): void {
for (const [fluidDataStoreId, context] of this.contexts) {
try {
context.setReadOnlyState(readonly);
} catch (error) {
this.mc.logger.sendErrorEvent(
{
eventName: "SetReadOnlyStateError",
...tagCodeArtifacts({
fluidDataStoreId,
}),
details: {
runtimeReadonly: this.parentContext.readonly,
readonly,
},
},
error,
);
}
}
}

public setAttachState(attachState: AttachState.Attaching | AttachState.Attached): void {
for (const [, context] of this.contexts) {
// Fire only for bounded stores.
Expand Down
11 changes: 10 additions & 1 deletion packages/runtime/container-runtime/src/containerRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ import {
idCompressorBlobName,
metadataBlobName,
rootHasIsolatedChannels,
summarizerClientType,
wrapSummaryInChannelsTree,
formCreateSummarizerFn,
summarizerRequestUrl,
Expand All @@ -267,6 +266,7 @@ import {
ISummaryConfiguration,
DefaultSummaryConfiguration,
isSummariesDisabled,
summarizerClientType,
} from "./summary/index.js";
import { Throttler, formExponentialFn } from "./throttler.js";

Expand Down Expand Up @@ -1119,6 +1119,10 @@ export class ContainerRuntime
return this._getAttachState();
}

public get readonly(): boolean {
return this.deltaManager.readOnlyInfo.readonly === true;
}

/**
* Current session schema - defines what options are on & off.
* It's overlap of document schema (controlled by summary & ops) and options controlling this session.
Expand Down Expand Up @@ -1733,6 +1737,7 @@ export class ContainerRuntime
new Map<string, string>(dataStoreAliasMap),
async (runtime: ChannelCollection) => provideEntryPoint,
);
this._deltaManager.on("readonly", (readonly) => this.setReadOnlyState(readonly));

this.blobManager = new BlobManager({
routeContext: this.handleContext,
Expand Down Expand Up @@ -2574,6 +2579,10 @@ export class ContainerRuntime
return this._loadIdCompressor;
}

public setReadOnlyState(readonly: boolean): void {
this.channelCollection.setReadOnlyState(readonly);
}

public setConnectionState(connected: boolean, clientId?: string): void {
// Validate we have consistent state
const currentClientId = this._audience.getSelf()?.clientId;
Expand Down
71 changes: 69 additions & 2 deletions packages/runtime/container-runtime/src/dataStoreContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@

import { TypedEventEmitter, type ILayerCompatDetails } from "@fluid-internal/client-utils";
import { AttachState, IAudience } from "@fluidframework/container-definitions";
import { IDeltaManager } from "@fluidframework/container-definitions/internal";
import {
IDeltaManager,
isIDeltaManagerFull,
type IDeltaManagerFull,
type ReadOnlyInfo,
} from "@fluidframework/container-definitions/internal";
import {
FluidObject,
IDisposable,
ITelemetryBaseProperties,
type IErrorBase,
type IEvent,
} from "@fluidframework/core-interfaces";
import {
Expand Down Expand Up @@ -75,6 +81,7 @@ import {
tagCodeArtifacts,
} from "@fluidframework/telemetry-utils/internal";

import { BaseDeltaManagerProxy } from "./deltaManagerProxies.js";
import {
runtimeCompatDetailsForDataStore,
validateDatastoreCompatibility,
Expand Down Expand Up @@ -188,6 +195,50 @@ export interface IFluidDataStoreContextEvents extends IEvent {
(event: "attaching" | "attached", listener: () => void);
}

/**
* Eventually we should remove the delta manger from being exposed to Datastore runtimes via the context. However to remove that exposure we need to add new
* features, and those features themselves need forward and back compat. This proxy is here to enable that back compat. Each feature this proxy is used to
* support should be listed below, and as layer compat support goes away for those feature, we should also remove them from this proxy, with the eventual goal
* of completely remove this proxy.
*
* - Everything regarding readonly is to support older datastore runtimes which do not have the setReadonly function, so must get their readonly state via the delta manager.
*
*/
class ContextDeltaManagerProxy extends BaseDeltaManagerProxy {
constructor(base: IDeltaManagerFull) {
super(base, {
onReadonly: (readonly, reason): void => this.setReadonly(readonly, reason),
});
this._readonly = base.readOnlyInfo.readonly;
}

public get readOnlyInfo(): ReadOnlyInfo {
if (this._readonly === this.deltaManager.readOnlyInfo.readonly) {
return this.deltaManager.readOnlyInfo;
} else {
return this._readonly === true
? {
readonly: true,
forced: false,
permissions: undefined,
storageOnly: false,
}
: { readonly: this._readonly };
}
}

private _readonly: boolean | undefined;
public setReadonly(
readonly: boolean,
readonlyConnectionReason?: { reason: string; error?: IErrorBase },
): void {
if (this._readonly !== readonly) {
this._readonly = readonly;
this.emit("readonly", readonly, readonlyConnectionReason);
}
}
}

/**
* Represents the context for the store. This context is passed to the store runtime.
* @internal
Expand Down Expand Up @@ -217,8 +268,13 @@ export abstract class FluidDataStoreContext
return this.parentContext.baseLogger;
}

private readonly _deltaManager: ContextDeltaManagerProxy;
public get deltaManager(): IDeltaManager<ISequencedDocumentMessage, IDocumentMessage> {
return this.parentContext.deltaManager;
return this._deltaManager;
}

public get readonly(): boolean | undefined {
return this.parentContext.readonly;
}

public get connected(): boolean {
Expand Down Expand Up @@ -420,6 +476,10 @@ export abstract class FluidDataStoreContext
// By default, a data store can log maximum 10 local changes telemetry in summarizer.
this.localChangesTelemetryCount =
this.mc.config.getNumber("Fluid.Telemetry.LocalChangesTelemetryCount") ?? 10;

assert(isIDeltaManagerFull(this.parentContext.deltaManager), "Invalid delta manager");

this._deltaManager = new ContextDeltaManagerProxy(this.parentContext.deltaManager);
}

public dispose(): void {
Expand Down Expand Up @@ -615,6 +675,13 @@ export abstract class FluidDataStoreContext
this.channel!.setConnectionState(connected, clientId);
}

public setReadOnlyState(readonly: boolean): void {
this.verifyNotClosed("setReadOnlyState", false /* checkTombstone */);

this.channel?.setReadOnlyState?.(readonly);
this._deltaManager.setReadonly(readonly);
}

/**
* Process messages for this data store. The messages here are contiguous messages for this data store in a batch.
* @param messageCollection - The collection of messages to process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
type ILayerCompatSupportRequirements,
} from "@fluid-internal/client-utils";
import type { ICriticalContainerError } from "@fluidframework/container-definitions";
import { encodeHandlesInContainerRuntime } from "@fluidframework/runtime-definitions/internal";
import {
encodeHandlesInContainerRuntime,
setReadonly,
} from "@fluidframework/runtime-definitions/internal";
import { UsageError } from "@fluidframework/telemetry-utils/internal";

import { pkgVersion } from "./packageVersion.js";
Expand Down Expand Up @@ -66,7 +69,7 @@ export const runtimeCompatDetailsForDataStore: ILayerCompatDetails = {
/**
* The features supported by the Runtime layer across the Runtime / DataStore boundary.
*/
supportedFeatures: new Set<string>([encodeHandlesInContainerRuntime]),
supportedFeatures: new Set<string>([encodeHandlesInContainerRuntime, setReadonly]),
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
type ISummarizerNodeWithGC,
} from "@fluidframework/runtime-definitions/internal";
import { isFluidError } from "@fluidframework/telemetry-utils/internal";
import { MockFluidDataStoreRuntime } from "@fluidframework/test-runtime-utils/internal";
import {
MockDeltaManager,
MockFluidDataStoreRuntime,
} from "@fluidframework/test-runtime-utils/internal";

import {
FluidDataStoreContext,
Expand Down Expand Up @@ -89,6 +92,7 @@ describe("createChildDataStore", () => {
});
},
} satisfies Partial<IContainerRuntimeBase> as unknown as IContainerRuntimeBase,
deltaManager: new MockDeltaManager(),
} satisfies Partial<IFluidParentContext> as unknown as IFluidParentContext;

const context = new testContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
isFluidError,
} from "@fluidframework/telemetry-utils/internal";
import {
MockDeltaManager,
MockFluidDataStoreRuntime,
validateAssertionError,
} from "@fluidframework/test-runtime-utils/internal";
Expand Down Expand Up @@ -245,6 +246,7 @@ describe("Data Store Context Tests", () => {
parentContext = {
IFluidDataStoreRegistry: registryWithSubRegistries,
clientDetails: {} as unknown as IFluidParentContext["clientDetails"],
deltaManager: new MockDeltaManager(),
} satisfies Partial<IFluidParentContext> as unknown as IFluidParentContext;
localDataStoreContext = new LocalFluidDataStoreContext({
id: dataStoreId,
Expand Down Expand Up @@ -541,6 +543,7 @@ describe("Data Store Context Tests", () => {
IFluidDataStoreRegistry: registry,
clientDetails: {} as unknown as IFluidParentContext["clientDetails"],
containerRuntime: parentContext as unknown as IContainerRuntimeBase,
deltaManager: new MockDeltaManager(),
} satisfies Partial<IFluidParentContext> as unknown as IFluidParentContext;
});

Expand Down Expand Up @@ -1036,6 +1039,7 @@ describe("Data Store Context Tests", () => {
IFluidDataStoreRegistry: registry,
baseLogger: createChildLogger(),
clientDetails: {} as unknown as IFluidParentContext["clientDetails"],
deltaManager: new MockDeltaManager(),
} satisfies Partial<IFluidParentContext> as unknown as IFluidParentContext;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {
SummarizeInternalFn,
} from "@fluidframework/runtime-definitions/internal";
import { createChildLogger } from "@fluidframework/telemetry-utils/internal";
import { MockFluidDataStoreRuntime } from "@fluidframework/test-runtime-utils/internal";
import {
MockDeltaManager,
MockFluidDataStoreRuntime,
} from "@fluidframework/test-runtime-utils/internal";

import { LocalFluidDataStoreContext } from "../dataStoreContext.js";
import { createRootSummarizerNodeWithGC } from "../summary/index.js";
Expand Down Expand Up @@ -111,6 +114,7 @@ describe("Data Store Creation Tests", () => {
IFluidDataStoreRegistry: globalRegistry,
baseLogger: createChildLogger(),
clientDetails: {} as unknown as IFluidParentContext["clientDetails"],
deltaManager: new MockDeltaManager(),
} satisfies Partial<IFluidParentContext> as unknown as IFluidParentContext;
const summarizerNode = createRootSummarizerNodeWithGC(
createChildLogger(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
type SummarizeInternalFn,
} from "@fluidframework/runtime-definitions/internal";
import { createChildLogger } from "@fluidframework/telemetry-utils/internal";
import { MockFluidDataStoreRuntime } from "@fluidframework/test-runtime-utils/internal";
import {
MockDeltaManager,
MockFluidDataStoreRuntime,
} from "@fluidframework/test-runtime-utils/internal";

import {
LocalFluidDataStoreContext,
Expand Down Expand Up @@ -58,6 +61,7 @@ export function createParentContext(
baseLogger: logger,
clientDetails,
submitMessage: () => {},
deltaManager: new MockDeltaManager(),
} satisfies Partial<IFluidParentContext> as unknown as IFluidParentContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export interface IFluidDataStoreRuntime extends IEventProvider<IFluidDataStoreRu
// (undocumented)
readonly options: Record<string | number, any>;
// (undocumented)
readonly readonly: boolean;
// (undocumented)
readonly rootRoutingContext: IFluidHandleContext;
submitSignal: (type: string, content: unknown, targetClientId?: string) => void;
uploadBlob(blob: ArrayBufferLike, signal?: AbortSignal): Promise<IFluidHandle<ArrayBufferLike>>;
Expand All @@ -120,6 +122,8 @@ export interface IFluidDataStoreRuntimeEvents extends IEvent {
(event: "signal", listener: (message: IInboundSignalMessage, local: boolean) => void): any;
// (undocumented)
(event: "connected", listener: (clientId: string) => void): any;
// (undocumented)
(event: "readonly", listener: (isReadOnly: boolean) => void): any;
}

// @alpha (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface IFluidDataStoreRuntimeEvents extends IEvent {
(event: "op", listener: (message: ISequencedDocumentMessage) => void);
(event: "signal", listener: (message: IInboundSignalMessage, local: boolean) => void);
(event: "connected", listener: (clientId: string) => void);
(event: "readonly", listener: (isReadOnly: boolean) => void);
}

/**
Expand Down Expand Up @@ -69,6 +70,8 @@ export interface IFluidDataStoreRuntime

readonly connected: boolean;

readonly readonly: boolean;

readonly logger: ITelemetryBaseLogger;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class FluidDataStoreRuntime extends TypedEventEmitter<IFluidDataStoreRunt
// (undocumented)
processSignal(message: IInboundSignalMessage, local: boolean): void;
// (undocumented)
get readonly(): boolean;
// (undocumented)
request(request: IRequest): Promise<IResponse>;
// (undocumented)
resolveHandle(request: IRequest): Promise<IResponse>;
Expand All @@ -89,6 +91,8 @@ export class FluidDataStoreRuntime extends TypedEventEmitter<IFluidDataStoreRunt
// (undocumented)
setConnectionState(connected: boolean, clientId?: string): void;
// (undocumented)
setReadOnlyState(readonly: boolean): void;
// (undocumented)
submitMessage(type: DataStoreMessageType, content: any, localOpMetadata: unknown): void;
submitSignal(type: string, content: unknown, targetClientId?: string): void;
summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummaryTreeWithStats>;
Expand Down
Loading
Loading