Skip to content

Enable calling serialize while container is in the attaching state#19893

Merged
anthony-murphy merged 17 commits into
microsoft:mainfrom
anthony-murphy:stash-attaching-serialize
Mar 1, 2024
Merged

Enable calling serialize while container is in the attaching state#19893
anthony-murphy merged 17 commits into
microsoft:mainfrom
anthony-murphy:stash-attaching-serialize

Conversation

@anthony-murphy
Copy link
Copy Markdown
Contributor

Background

This change is the final change for allowing consumers of fluid to call serialize on a container while a container is in an attaching state, which will include a failed attach where the failure didn't cause the container to close. This will aid in the case of offline, network, or server outage by allowing the application to capture the un-attached state of the container, preserve it locally, and later create a new file from it.

AB#5502

Overview

This change enables calling container.serialize while a container is in the attaching state. It is the culmination of many smaller changes that have gone in to enable this change.

@github-actions github-actions Bot added area: loader Loader related issues area: tests Tests to add, test infrastructure improvements, etc public api change Changes to a public API base: main PRs targeted against main branch labels Feb 29, 2024
Comment thread packages/common/container-definitions/src/loader.ts Outdated
Co-authored-by: Daniel Madrid <105010181+dannimad@users.noreply.github.com>
* Extract a snapshot of the container as long as it is in detached state. Calling this on an attached container
* is an error.
* This function will capture the state of a container this is not Attached or closed.
* This is useful in draft-like scenarios. For example, think of an email draft, where a user can make changes over time,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure this comment is that related to serialize, it sounds more like detached to me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

granted, serialize is only used in detached, attaching scenarios but in the phrase "This is useful" not sure if "this" is detached/attaching state or serialize. I guess it makes sense both ways but it was a bit confusing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I have a comment above re: attach() where I think this sort of explanation would fit better.

Copy link
Copy Markdown
Contributor Author

@anthony-murphy anthony-murphy Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all containers start detached, and all container needs to be attached. serialize is what allows preserving unattached container, for draft like scenarios. i don't see why this wouldn't belong here

Comment thread packages/common/container-definitions/src/loader.ts Outdated
* @internal
*/
export interface IPendingContainerState {
attached: true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know you can set values at the interface definition. Is it safe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not setting a value. its saying the only valid value is true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it allows union types like IPendingContainerState | IPendingDetachedContainerState to be discriminated via the attached property, such that typescript know that if it is true, it is IPendingContainerState and if it is false it is IPendingDetachedContainerState

Comment thread packages/common/container-definitions/src/loader.ts Outdated
const appSummary: ISummaryTree = this.runtime.createSummary();
const protocolSummary = this.captureProtocolSummary();
const combinedSummary = combineAppAndProtocolSummary(appSummary, protocolSummary);
const attachingData =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the two potential options for the state of the container at this point attaching or detached? And if it's detached, the attachingData should be undefined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. two possibilities. only an attaching has already created it base summary, so this is handling that, a detached container has no base summary, so we generate it on each call.

Comment thread packages/loader/container-loader/src/test/loader.spec.ts
anthony-murphy and others added 3 commits February 29, 2024 10:50
Co-authored-by: jzaffiro <110866475+jzaffiro@users.noreply.github.com>
Co-authored-by: Daniel Madrid <105010181+dannimad@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@ChumpChief ChumpChief left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ignoring the code changes, just reviewing the docs here.

Love the additions! Most comments are just language suggestions. I call it out in one of the comments, but being pedantic with RFC 2119 keywords can help clarify correct usage to customers.

Comment thread packages/common/container-definitions/src/loader.ts Outdated
Comment thread packages/common/container-definitions/src/loader.ts Outdated
/**
* Attaches the Container to the Container specified by the given Request.
* When a container is created in Fluid it starts in what we call a detached state,
* which means it is detached from server storage and unavailable for other users to open or collaborate with.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here would be a good spot to explain why, e.g. "The detached state can be useful for drafting content in the container before the initial upload."

Comment thread packages/common/container-definitions/src/loader.ts Outdated
Comment thread packages/common/container-definitions/src/loader.ts Outdated
Comment thread packages/common/container-definitions/src/loader.ts Outdated
Comment thread packages/common/container-definitions/src/loader.ts Outdated
Comment thread packages/common/container-definitions/src/loader.ts Outdated
Comment thread packages/common/container-definitions/src/loader.ts Outdated
Comment thread packages/common/container-definitions/src/loader.ts Outdated
Co-authored-by: Matt Rakow <ChumpChief@users.noreply.github.com>
@msfluid-bot
Copy link
Copy Markdown
Collaborator

msfluid-bot commented Feb 29, 2024

@fluid-example/bundle-size-tests: +470 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 514.17 KB 514.2 KB +33 Bytes
connectionState.js 680 Bytes 680 Bytes No change
containerRuntime.js 247.99 KB 248 KB +11 Bytes
loader.js 171.31 KB 171.69 KB +382 Bytes
map.js 46.69 KB 46.7 KB +11 Bytes
matrix.js 148.74 KB 148.74 KB No change
odspDriver.js 97.36 KB 97.37 KB +11 Bytes
odspPrefetchSnapshot.js 42.28 KB 42.29 KB +11 Bytes
sharedString.js 167.32 KB 167.33 KB +11 Bytes
sharedTree.js 334.63 KB 334.63 KB No change
Total Size 1.87 MB 1.87 MB +470 Bytes

Baseline commit: 6dea020

Generated by 🚫 dangerJS against 3a0d45d

Copy link
Copy Markdown
Contributor

@jzaffiro jzaffiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes make sense to me, you may want another opinion though :)

@anthony-murphy anthony-murphy merged commit 3b860e8 into microsoft:main Mar 1, 2024
@anthony-murphy anthony-murphy deleted the stash-attaching-serialize branch March 1, 2024 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: loader Loader related issues area: tests Tests to add, test infrastructure improvements, etc base: main PRs targeted against main branch public api change Changes to a public API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants