Skip to content
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

packages/core: Proof of concept tests for CRDT #429

Open
raykyri opened this issue Jan 13, 2025 · 0 comments
Open

packages/core: Proof of concept tests for CRDT #429

raykyri opened this issue Jan 13, 2025 · 0 comments
Assignees

Comments

@raykyri
Copy link
Member

raykyri commented Jan 13, 2025

At some point this year we will want to add CRDTs to the core db API, at the runtime/core level, or possibly at the ModelDB level:

  • Adding a CRDT type to the Models schema type
    • It should be possible to declare a model field with the yjs.document model type.
  • Adding CRDT support to the db API in runtime, e.g.
    • When this.#context is set up, reconstruct an in-memory representation of the CRDT
    • At the end of a runtime call, collect CRDT deltas and update the in-memory representation of the CRDT
    • Serialize and save the CRDT to ModelDB
  • Adding a db API for CRDTs. Change the types for db.set to accept reducers for CRDTs, or create a new CRDT update API, and making it so db.set and db.get don't interact with CRDTs, by filtering out the CRDT field, etc.

However, there are changes in progress on the runtime database APIs. Instead, before making any CRDT changes we can set up tests using a helper that emulates the syntax of a CRDT db API:

const cr = (db, ...) => {
  return { 
    update: async (docid, mut) => {
        const doc = db.get(...)
        mut(doc)
        db.set(...)
    }
  }
}
const models = {
  document: { id: "primary", document: "json" }
}

const actions = {
  updateDocument: (db, docid, ...) => {
    cr(db).update(docid, (doc) => {
        doc.getMap('one').set('foo', new Y.Text())
        // ... more CRDT writes
    })
  }
}

const app = await Canvas.initialize({ contract: { models, actions } })
app.updateDocument(...)

Using this model, we can set up a few single-threaded tests for different Y.js shared types. We can also plan out tests for concurrent updates to CRDTs (without implementing them); just mark each block of updates that needs to be split into being done by concurrent actors with a comment inside cr().update().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants