-
Notifications
You must be signed in to change notification settings - Fork 0
feat: resume retained materialization predecessors #771
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
de39cb7
feat: resume retained materialization predecessors
flyingrobots 716b075
docs: explain retained materialization resume
flyingrobots 66db6c3
test: complete materialization regression fixture
flyingrobots ef0f104
test: model retained replay basis
flyingrobots 29dc30d
fix: harden retained predecessor recovery
flyingrobots File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/domain/services/controllers/MaterializationRetention.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import MaterializationCoordinate from '../../materialization/MaterializationCoordinate.ts'; | ||
| import type MaterializationHandle from '../../materialization/MaterializationHandle.ts'; | ||
| import WarpError from '../../errors/WarpError.ts'; | ||
| import { | ||
| materializationSessionOpen, | ||
| } from './MaterializeSessionBridge.ts'; | ||
| import type { | ||
| MaterializeReduceOutput, | ||
| } from './MaterializeController.ts'; | ||
| import type { MaterializeDeps } from './MaterializeDeps.ts'; | ||
| import type { | ||
| MaterializeResultBuildInput, | ||
| } from './MaterializeStrategyRuntime.ts'; | ||
|
|
||
| /** Publishes session roots through their git-cas workspace retention scope. */ | ||
| export async function resolveMaterializationRetention(input: { | ||
| readonly deps: MaterializeDeps; | ||
| readonly params: MaterializeResultBuildInput; | ||
| readonly stateHash: string; | ||
| }): Promise<MaterializationHandle | undefined> { | ||
| const retained = resolveExistingMaterialization(input.params, input.stateHash); | ||
| return retained ?? await publishMaterialization(input); | ||
| } | ||
|
|
||
| function resolveExistingMaterialization( | ||
| params: MaterializeResultBuildInput, | ||
| stateHash: string, | ||
| ): MaterializationHandle | undefined { | ||
| const retained = params.materialization; | ||
| if (retained === undefined) { | ||
| return undefined; | ||
| } | ||
| if (retained.stateHash !== stateHash) { | ||
| throw retentionError('retained handle state hash does not match resumed state'); | ||
| } | ||
| if (!rootsMatch(params, retained)) { | ||
| return undefined; | ||
| } | ||
| params.reduced.acceptMaterialization?.(retained.retention); | ||
| return retained; | ||
| } | ||
|
|
||
| function rootsMatch( | ||
| params: MaterializeResultBuildInput, | ||
| retained: MaterializationHandle, | ||
| ): boolean { | ||
| return params.reduced.roots === undefined | ||
| || retained.roots.equals(params.reduced.roots); | ||
| } | ||
|
|
||
| async function publishMaterialization(input: { | ||
| readonly deps: MaterializeDeps; | ||
| readonly params: MaterializeResultBuildInput; | ||
| readonly stateHash: string; | ||
| }): Promise<MaterializationHandle | undefined> { | ||
| const { params } = input; | ||
| if (params.reduced.roots === undefined || params.frontier === null) { | ||
| await acceptSessionWithoutMaterialization(params.reduced); | ||
| return undefined; | ||
| } | ||
| const request = { | ||
| coordinate: new MaterializationCoordinate({ | ||
| frontier: params.frontier, | ||
| ceiling: params.ceiling, | ||
| }), | ||
| roots: params.reduced.roots, | ||
| stateHash: input.stateHash, | ||
| replayBasis: params.reduced.state, | ||
| }; | ||
| const materialization = params.reduced.workspace === undefined | ||
| ? await input.deps.materializations.retain(request) | ||
| : await params.reduced.workspace.promote(request); | ||
| params.reduced.acceptMaterialization?.(materialization.retention); | ||
| return materialization; | ||
| } | ||
|
|
||
| async function acceptSessionWithoutMaterialization( | ||
| reduced: MaterializeReduceOutput, | ||
| ): Promise<void> { | ||
| if (reduced.acceptMaterialization === undefined) { | ||
| return; | ||
| } | ||
| if (reduced.roots === undefined || reduced.workspace === undefined) { | ||
| throw retentionError('prepared session is missing roots or workspace retention'); | ||
| } | ||
| const roots = materializationSessionOpen(reduced.roots); | ||
| if (roots === null) { | ||
| throw retentionError('prepared session roots cannot be checkpointed'); | ||
| } | ||
| const witness = await reduced.workspace.checkpoint({ | ||
| nodeAliveRoot: roots.nodeAliveRootOid, | ||
| edgeAliveRoot: roots.edgeAliveRootOid, | ||
| }); | ||
| reduced.acceptMaterialization(witness); | ||
| } | ||
|
|
||
| function retentionError(message: string): WarpError { | ||
| return new WarpError(message, 'E_MATERIALIZATION_RESUME'); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.