Repository navigation
computer: Let several Workspaces share one durable object's storage - #246
Draft
mattzcarey wants to merge 1 commit into
Draft
mattzcarey wants to merge 1 commit into
mattzcarey wants to merge 1 commit into
Conversation
A durable object's storage held exactly one Workspace, because every table it creates has a fixed name. An agent that wanted a scratch area next to a durable project, or one Workspace per sub-task, needed a durable object for each. WorkspaceOptions now takes a `namespace`. A namespaced Workspace gets its own copy of every table and index, named with a `ws_<namespace>_` prefix, so `vfs_nodes` becomes `ws_scratch_vfs_nodes`. Without a namespace a Workspace keeps the existing names, so stored data stays where it is. The table names are spread across the filesystem, sync, mount, and runtime code, so rather than thread a prefix through all of it, the Workspace wraps its storage handle and renames its own identifiers in the SQL on the way to SQLite. Values always travel as bindings, so file names and contents are never touched. Namespaces are lowercase letters and digits only, which keeps two namespaces from ever mapping to the same table names. A test checks that a namespaced Workspace creates no table or index outside its prefix, so a new table that the rename misses fails the build. A durable object still has one container, so only one Workspace in it should have a container backend. The README and the schema doc say so. Fixes #219.
馃 Changeset detectedLatest commit: 4487be9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A durable object's storage can hold only one Workspace, because every table a Workspace creates has a fixed name (#219). An agent that wants a scratch area next to a durable project, or one Workspace per sub-task, needs a separate durable object for each.
WorkspaceOptionsnow takes anamespace:A namespaced Workspace gets its own copy of every table and index, named with a
ws_<namespace>_prefix. Sovfs_nodesbecomesws_scratch_vfs_nodes. Without a namespace a Workspace keeps the existing names, so stored data stays where it is.The table names are spread across the filesystem, sync, mount and runtime code, roughly 50 files of SQL. Rather than thread a prefix through all of it, the Workspace wraps its storage handle and renames its own identifiers in the SQL on the way to SQLite. I picked this because it's the smallest change, but it's the main thing to review. The trade-offs:
vfs_nodes.sqlcontaining SQL and reads it back unchanged.vfs_*,_vfs_*,workspace_runtime_*andcomputer_execution_runtime. A test checks that a namespaced Workspace creates no table or index outside its prefix, so a new table that the pattern misses fails the build._means two namespaces can never map to the same table names.A durable object still has one container. Two Workspaces with container backends in the same object would fight over it, so the README says to give a container backend to only one of them. Container-backend state such as the client secret and launch record also lives in key-value storage under fixed keys, which is one more reason to keep it to one Workspace.
The new
namespace.test.tscovers:npm test --workspace @cloudflare/computerpasses. The README has a new "Several workspaces in one durable object" section,docs/03_filesystem_schema.mdexplains the prefix, and a minor changeset is included.