Skip to content

Checking for new changes uses _creationTime, which can have out-of-order inserts #2

@ianmacartney

Description

@ianmacartney

Currently the "check if there are new changes" uses the previous _creationTime as the cursor. Unfortunately, the previous query could have fetched results before an in-progress mutation commits, which could have started prior to what the latest document's _creationTime shows, meaning the next check will miss the commit.

You can use a monotonically increasing sequence number on inserts to keep the cursor, or have some fancier vector clock.
You may also be able to leverage a version number used by the main app's schemas.

In the prosemirror-sync component, I do this with the "version" field: https://github.com/get-convex/prosemirror-sync/blob/ian/thin-client/src/component/schema.ts#L14-L15

The risk is then that concurrent inserts need to be written serially, which generally will happen automatically in convex thanks to the MVCC / OCC w/ auto-retry. However, it can cause DB write conflicts during contentious writes scenarios.

We're thinking about other patterns where we could support a "give me the latest since the last row I queried" but for now _creationTime can be out of order (up to a theoretical max skew of 4 minutes, though usually not more than ~seconds)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions