-
Notifications
You must be signed in to change notification settings - Fork 0
Read retained node liveness without whole-state materialization #757
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
4 commits
Select commit
Hold shift + click to select a range
56ed3ce
feat(runtime): read retained node liveness
flyingrobots 3cdd71a
fix(runtime): preserve custom session root ownership
flyingrobots 6315884
fix(materialization): validate retained root reader
flyingrobots 4a1ae43
docs(materialization): qualify retained reader availability
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import type CodecPort from '../../ports/CodecPort.ts'; | ||
| import MaterializationReadPort from '../../ports/MaterializationReadPort.ts'; | ||
| import BundleHandle from '../storage/BundleHandle.ts'; | ||
| import WarpError from '../errors/WarpError.ts'; | ||
| import PageCache from '../orset/trie/PageCache.ts'; | ||
| import TrieCursor from '../orset/trie/TrieCursor.ts'; | ||
| import TrieGeometry from '../orset/trie/TrieGeometry.ts'; | ||
| import type TrieStorePort from '../orset/trie/TrieStorePort.ts'; | ||
|
|
||
| const MAX_RESIDENT_READ_PAGES = 256; | ||
|
|
||
| /** Reads retained liveness roots without reconstructing a complete WarpState. */ | ||
| export default class TrieMaterializationReader extends MaterializationReadPort { | ||
| readonly #store: TrieStorePort; | ||
| readonly #codec: CodecPort; | ||
| readonly #geometry: TrieGeometry; | ||
|
|
||
| constructor(options: { | ||
| readonly store: TrieStorePort; | ||
| readonly codec: CodecPort; | ||
| readonly geometry?: TrieGeometry; | ||
| }) { | ||
| super(); | ||
| requireOptions(options); | ||
| this.#store = requireStore(options.store); | ||
| this.#codec = requireCodec(options.codec); | ||
| this.#geometry = options.geometry === undefined | ||
| ? TrieGeometry.default16way() | ||
| : requireGeometry(options.geometry); | ||
| Object.freeze(this); | ||
| } | ||
|
|
||
| override async hasNode(nodeAliveRoot: BundleHandle, nodeId: string): Promise<boolean> { | ||
| if (!(nodeAliveRoot instanceof BundleHandle)) { | ||
| throw new WarpError( | ||
| 'Materialization node-liveness root must be a BundleHandle', | ||
| 'E_MATERIALIZATION_RESUME' | ||
| ); | ||
| } | ||
| const cursor = new TrieCursor({ | ||
| rootOid: nodeAliveRoot.toString(), | ||
| store: this.#store, | ||
| geometry: this.#geometry, | ||
| codec: this.#codec, | ||
| pageCache: new PageCache({ maxResident: MAX_RESIDENT_READ_PAGES }), | ||
| }); | ||
| return await cursor.contains(nodeId); | ||
| } | ||
| } | ||
|
|
||
| function requireOptions(options: object): void { | ||
| if (options === null || typeof options !== 'object' || Array.isArray(options)) { | ||
| throw readerError('options must be an object'); | ||
| } | ||
| } | ||
|
|
||
| function requireStore(store: TrieStorePort): TrieStorePort { | ||
| if ( | ||
| store === null | ||
| || typeof store !== 'object' | ||
| || !hasTrieOperations(store) | ||
| ) { | ||
| throw readerError('store must provide trie read/write operations'); | ||
| } | ||
| return store; | ||
| } | ||
|
|
||
| function hasTrieOperations(store: TrieStorePort): boolean { | ||
| return typeof store.readLeaf === 'function' | ||
| && typeof store.readBranch === 'function' | ||
| && typeof store.writeLeaf === 'function' | ||
| && typeof store.writeBranch === 'function'; | ||
| } | ||
|
|
||
| function requireCodec(codec: CodecPort): CodecPort { | ||
| if ( | ||
| codec === null | ||
| || typeof codec !== 'object' | ||
| || typeof codec.encode !== 'function' | ||
| || typeof codec.decode !== 'function' | ||
| ) { | ||
| throw readerError('codec must provide encode/decode operations'); | ||
| } | ||
| return codec; | ||
| } | ||
|
|
||
| function requireGeometry(geometry: TrieGeometry): TrieGeometry { | ||
| if (!(geometry instanceof TrieGeometry)) { | ||
| throw readerError('geometry must be a TrieGeometry instance'); | ||
| } | ||
| return geometry; | ||
| } | ||
|
|
||
| function readerError(message: string): WarpError { | ||
| return new WarpError(`Materialization reader ${message}`, 'E_MATERIALIZATION_RESUME'); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import type CheckpointStorePort from '../../../ports/CheckpointStorePort.ts'; | ||
| import type CodecPort from '../../../ports/CodecPort.ts'; | ||
| import type CryptoPort from '../../../ports/CryptoPort.ts'; | ||
| import type LoggerPort from '../../../ports/LoggerPort.ts'; | ||
| import type MaterializationReadPort from '../../../ports/MaterializationReadPort.ts'; | ||
| import type MaterializationStorePort from '../../../ports/MaterializationStorePort.ts'; | ||
| import type WarpStateCachePort from '../../../ports/WarpStateCachePort.ts'; | ||
| import type DetachedGraphFactory from '../../capabilities/DetachedGraphFactory.ts'; | ||
| import type PatchCollector from '../../capabilities/PatchCollector.ts'; | ||
| import type { MaterializeSessionOpener } from './MaterializeSessionBridge.ts'; | ||
|
|
||
| export type MaterializePersistence = { | ||
| readRef(ref: string): Promise<string | null>; | ||
| }; | ||
|
|
||
| /** Constructor dependencies for retained-handle materialization operations. */ | ||
| export type MaterializeDeps = { | ||
| logger: LoggerPort; | ||
| codec: CodecPort; | ||
| crypto: CryptoPort; | ||
| persistence: MaterializePersistence; | ||
| checkpointStore: CheckpointStorePort; | ||
| materializations: MaterializationStorePort; | ||
| materializationRead?: MaterializationReadPort; | ||
| getStateCache?: () => WarpStateCachePort | null; | ||
| openStateSession?: MaterializeSessionOpener; | ||
| patches: PatchCollector; | ||
| graphCloner: DetachedGraphFactory; | ||
| graphName: string; | ||
| }; |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import type BundleHandle from '../domain/storage/BundleHandle.ts'; | ||
|
|
||
| /** Bounded reads over independently retained materialization roots. */ | ||
| export default abstract class MaterializationReadPort { | ||
| abstract hasNode(_nodeAliveRoot: BundleHandle, _nodeId: string): Promise<boolean>; | ||
| } |
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.