-
Notifications
You must be signed in to change notification settings - Fork 535
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
[GC] Make getAttachGCData required on IFluidDataStoreChannel and make implementation consistent #21347
Conversation
… the logic consistent
⯅ @fluid-example/bundle-size-tests: +1.79 KB
Baseline commit: 15a26ae |
.filter( | ||
([key, _]) => | ||
// Take GC data of bounded data stores only. | ||
!this.contexts.isNotBound(key), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tl;dr - I would strongly encourage you to use the visitor pattern (similar example) to share the structure of this do-while loop between both functions here.
Reasons/Thoughts:
- The logic should be the same, but people won't necessarily know to update both places
- To that point... you are already diverging the logic on this line. Shouldn't it check the same 3 conditions as above?
- Are there other places the logic differs, and can we keep it the same so we can share the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a change for this but it looks slightly risky. Let me do this in a follow-up PR.
} while (notBoundContextsLength !== this.contexts.notBoundLength()); | ||
|
||
// Get the outbound routes (aliased data stores) and add a GC node for this channel. | ||
builder.addNode("/", Array.from(this.aliasedDataStores)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're here, do we have a way to get the absolute path of this channel collection? For nested data stores, it won't be "/".
Fine to track as a follow-up, if someone would just tell us where!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best way would be to create a handle for this channel and use it's path. Agreed on a follow-up.
@@ -526,9 +528,14 @@ export class ChannelCollection implements IFluidDataStoreChannel, IDisposable { | |||
|
|||
/** Package up the context's attach summary etc into an IAttachMessage */ | |||
private generateAttachMessage(localContext: IFluidDataStoreContextInternal): IAttachMessage { | |||
const { attachSummary } = localContext.getAttachData(/* includeGCData: */ true); | |||
// Get the attach summary. | |||
const attachSummary = localContext.getAttachSummary(); | |||
const type = localContext.packagePath[localContext.packagePath.length - 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh funny, this code could have got it from the getAttachData
call but didn't.
Having callers do that instead of returning it is good, it frees up this change. I think I never considered that!
@@ -244,6 +241,8 @@ describe("Data Store Context Tests", () => { | |||
dataStoreAttributes.isRootDataStore, | |||
"Local DataStore root state does not match", | |||
); | |||
const type = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth adding a free function somewhere to do this, it's worth naming and codifying in one place IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One refactor suggestion, otherwise looks good :)
…sitor pattern (#21379) Follow up from this comment - #21347 (comment) During summarization or attachments, both GC and summarize runs and they iterate over data stores and channel contexts during summarization. The logic to filter and validate is duplicated for both which makes it prone to get diverged. This PR updates the following set of function to use the [visitor](https://en.wikipedia.org/wiki/Visitor_pattern) pattern to iterate over data stores / channel contexts: - `summarize` and `getGCData`. - `getAttachSummary` and `getAttachGCData`. One logic change in this PR: - It updates `ChannelCollection::getAttachSummary` to use a visisted set to ensure that a node is only summarized oncen similar to `FluidDataStoreRuntime::getAttachSummary`. It earlier used the summary tree to do this. #8257
getAttachGCData
was added toIFluidDataStoreChannel
in 2.0.0-rc.2.0 4 months ago via #19275. This PR does the following:getAttachGCData
required onIFluidDataStoreChannel
.getAttachGCData
logic consistent across channel collection, data store context, data store runtime and channel contexts. I found it confusing to follow the existing flow due to the implementation being different for various layers. This is how it works now:ChannelCollection
andFluidDataStoreRuntime
both implementsgetAttachGCData
which iterates through all it's children and gets their GC data by callinggetAttachGCData
.FluidDataStoreContext
andLocalChannelContext
both implementgetAttachGCData
which returns the GC data for this node.getAttachSummary
andgetAttachGCData
inChannelCollection:generateAttachMessage
.AB#8199