Skip to content
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

Remove deprecated container connection APIs #10192

Merged
merged 23 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
da7ee68
bump container-definitions
scottn12 Apr 29, 2022
38eb51b
replace references to deprecated APIs
scottn12 Apr 29, 2022
8c0a30e
Merge branch 'next' into replaceDepConnectAPIs
scottn12 May 3, 2022
0d3e92d
Merge branch 'next' into replaceDepConnectAPIs
scottn12 May 6, 2022
613e4ce
remove reamining resume() use
scottn12 May 6, 2022
181cafb
remove deprecated connection APIs
scottn12 May 6, 2022
ee32abd
Merge branch 'next' into replaceDepConnectAPIs
scottn12 May 9, 2022
ae2e469
allow connect() if this.connected is true
scottn12 May 9, 2022
41f3902
Revert "allow connect() if this.connected is true"
scottn12 May 9, 2022
fe9166f
use resumeInternal when loading a container
scottn12 May 9, 2022
46b4a0a
use ensureSynchronized instead of waitContainerToCatchUp
scottn12 May 20, 2022
c09b0e8
Merge branch 'next' into replaceDepConnectAPIs
scottn12 May 20, 2022
fdb4235
update broken types
scottn12 May 20, 2022
2b2e6e1
port LTS compatiable version of waitContainerToCatchUp() for e2e tests
scottn12 May 24, 2022
ce7a361
Update packages/test/test-utils/src/loaderContainerTracker.ts
scottn12 May 25, 2022
ffb7dfd
Merge branch 'next' into replaceDepConnectAPIs
scottn12 May 25, 2022
d96d11b
feedback from PR
scottn12 May 25, 2022
6669079
fix build errors
scottn12 May 25, 2022
bcd9b25
PR feedback
scottn12 May 26, 2022
6cb3772
alternative waitContainerToCatchUp()
scottn12 May 26, 2022
3025551
update container-loader readme
scottn12 May 27, 2022
7e49d93
add comment explaining waitContainerCatchUp
scottn12 May 27, 2022
f6c791e
Merge branch 'next' into replaceDepConnectAPIs
scottn12 May 27, 2022
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
1 change: 0 additions & 1 deletion api-report/test-utils.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ export class LoaderContainerTracker implements IOpProcessingController {
processOutgoing(...containers: IContainer[]): Promise<void>;
reset(): void;
resumeProcessing(...containers: IContainer[]): IContainer[];
waitContainerToCatchUp(container: IContainer): Promise<boolean>;
}

// @public
Expand Down
5 changes: 4 additions & 1 deletion packages/loader/container-loader/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export enum ConnectionState {
* Useful when resolving URIs and hitting 404, due to container being loaded from (stale) snapshot and not being
* up to date. Host may chose to wait in such case and retry resolving URI.
* Warning: Will wait infinitely for connection to establish if there is no connection.
* May result in deadlock if Container.disconnect() is called and never switched back to auto-reconnect.
* May result in deadlock if Container.disconnect() is called and never followed by a call to Container.connect().
* @returns true: container is up to date, it processed all the ops that were know at the time of first connection
* false: storage does not provide indication of how far the client is. Container processed
* all the ops known to it, but it maybe still behind.
Expand Down Expand Up @@ -1208,6 +1208,9 @@ export class Container extends EventEmitterWithErrorHandling<IContainerEvents> i

switch (loadMode.deltaConnection) {
case undefined:
// Note: no need to fetch ops as we do it preemptively as part of DeltaManager.attachOpHandler().
// If there is gap, we will learn about it once connected, but the gap should be small (if any),
// assuming that resumeInternal() is called quickly after initial container boot.
this.resumeInternal({ reason: "DocumentLoad", fetchOpsFromStorage: false });
break;
case "delayed":
Expand Down
7 changes: 1 addition & 6 deletions packages/test/test-service-load/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ function scheduleFaultInjection(
const injectionTime = random.integer(faultInjectionMinMs, faultInjectionMaxMs)(runConfig.randEng);
printStatus(runConfig, `fault injection in ${(injectionTime / 60000).toString().substring(0, 4)} min`);
setTimeout(() => {
// TODO: Remove null check after next release #8523
if (container.connectionState === ConnectionState.Connected && container.resolvedUrl !== undefined) {
const deltaConn =
ds.documentServices.get(container.resolvedUrl)?.documentDeltaConnection;
Expand Down Expand Up @@ -298,11 +297,7 @@ function scheduleContainerClose(
new Promise<void>((resolve) => {
// wait for the container to connect write
container.once("closed", () => resolve);
// TODO: Remove null check after next release #8523
if (container.connectionState !== undefined
&& container.connectionState !== ConnectionState.Connected
&& !container.closed
) {
if (container.connectionState !== ConnectionState.Connected && !container.closed) {
container.once("connected", () => {
resolve();
container.off("closed", () => resolve);
Expand Down
1 change: 0 additions & 1 deletion packages/test/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
"typeValidation": {
"version": "0.60.1000",
"broken": {
"ClassDeclaration_LoaderContainerTracker": {"forwardCompat": false},
"ClassDeclaration_TestObjectProvider": {"forwardCompat": false}
}
}
Expand Down
67 changes: 1 addition & 66 deletions packages/test/test-utils/src/loaderContainerTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { assert } from "@fluidframework/common-utils";
import { IContainer, IDeltaQueue, IHostLoader } from "@fluidframework/container-definitions";
import { ConnectionState, Container } from "@fluidframework/container-loader";
import { Container } from "@fluidframework/container-loader";
import { IDocumentMessage, ISequencedDocumentMessage, MessageType } from "@fluidframework/protocol-definitions";
import { debug } from "./debug";
import { IOpProcessingController } from "./testObjectProvider";
Expand Down Expand Up @@ -209,71 +209,6 @@ export class LoaderContainerTracker implements IOpProcessingController {
debugWait("Synchronized");
}

/**
* Port of {@link @fluidframework/container-loader#waitContainerToCatchUp} for compatibility with old containers.
* Waits until container connects to delta storage and gets up-to-date
* Useful when resolving URIs and hitting 404, due to container being loaded from (stale) snapshot and not being
* up to date. Host may chose to wait in such case and retry resolving URI.
* Warning: Will wait infinitely for connection to establish if there is no connection.
* May result in deadlock if Container.disconnect() is called and never switched back to auto-reconnect.
* @returns true: container is up to date, it processed all the ops that were know at the time of first connection
* false: storage does not provide indication of how far the client is. Container processed
* all the ops known to it, but it maybe still behind.
* @throws an error if the container is closed before it catches up.
*/
public async waitContainerToCatchUp(container: IContainer): Promise<boolean> {
// Make sure we stop waiting if container is closed.
if (container.closed) {
throw new Error("waitContainerToCatchUp: Container closed");
}
return new Promise<boolean>((resolve, reject) => {
const deltaManager = container.deltaManager;
let callbackOps;

const closedCallback = () => {
container.off("closed", closedCallback);
if (callbackOps !== undefined) {
deltaManager.off("op", callbackOps);
}
reject(new Error("Container closed while waiting to catch up"));
};
container.on("closed", closedCallback);

const waitForOps = () => {
assert(container.connectionState !== ConnectionState.Disconnected,
"Container disconnected while waiting for ops!");
const hasCheckpointSequenceNumber = deltaManager.hasCheckpointSequenceNumber;

const connectionOpSeqNumber = deltaManager.lastKnownSeqNumber;
assert(deltaManager.lastSequenceNumber <= connectionOpSeqNumber,
"lastKnownSeqNumber should never be below last processed sequence number");
if (deltaManager.lastSequenceNumber === connectionOpSeqNumber) {
container.off("closed", closedCallback);
resolve(hasCheckpointSequenceNumber);
return;
}
callbackOps = (message: ISequencedDocumentMessage) => {
if (connectionOpSeqNumber <= message.sequenceNumber) {
container.off("closed", closedCallback);
resolve(hasCheckpointSequenceNumber);
deltaManager.off("op", callbackOps);
}
};
deltaManager.on("op", callbackOps);
};

// We can leverage DeltaManager's "connect" event here and test for ConnectionState.Disconnected
// But that works only if service provides us checkPointSequenceNumber
// Our internal testing is based on R11S that does not, but almost all tests connect as "write" and
// use this function to catch up, so leveraging our own join op as a fence/barrier
if (container.connectionState === ConnectionState.Connected) {
waitForOps();
} else {
container.once("connected", () => { waitForOps(); });
}
});
}

/**
* Utility to calculate the set of clientId per container in quorum that is NOT associated with
* any container we tracked, indicating there is a pending join or leave op that we need to wait.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ declare function get_old_ClassDeclaration_LoaderContainerTracker():
declare function use_current_ClassDeclaration_LoaderContainerTracker(
use: TypeOnly<current.LoaderContainerTracker>);
use_current_ClassDeclaration_LoaderContainerTracker(
// @ts-expect-error compatibility expected to be broken
get_old_ClassDeclaration_LoaderContainerTracker());

/*
Expand Down
12 changes: 10 additions & 2 deletions packages/test/test-utils/src/testObjectProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

import { IContainer, IHostLoader, IFluidCodeDetails } from "@fluidframework/container-definitions";
import { ITelemetryGenericEvent, ITelemetryBaseLogger, ITelemetryBaseEvent } from "@fluidframework/common-definitions";
import { ILoaderProps, Loader } from "@fluidframework/container-loader";
import {
ILoaderProps,
Loader,
waitContainerToCatchUp as waitContainerToCatchUp_original,
} from "@fluidframework/container-loader";
import { IContainerRuntimeOptions } from "@fluidframework/container-runtime";
import { IRequestHeader } from "@fluidframework/core-interfaces";
import { IDocumentServiceFactory, IResolvedUrl, IUrlResolver } from "@fluidframework/driver-definitions";
Expand Down Expand Up @@ -390,7 +394,11 @@ export class TestObjectProvider implements ITestObjectProvider {
}

public async waitContainerToCatchUp(container: IContainer) {
return this._loaderContainerTracker.waitContainerToCatchUp(container);
if ((container as any).connect === undefined) {
scottn12 marked this conversation as resolved.
Show resolved Hide resolved
(container as any).connect = (container as any).resume;
}

return waitContainerToCatchUp_original(container);
}

updateDocumentId(resolvedUrl: IResolvedUrl | undefined) {
Expand Down