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

Support time travel #52

Open
hackerwins opened this issue May 8, 2020 · 1 comment
Open

Support time travel #52

hackerwins opened this issue May 8, 2020 · 1 comment
Labels
enhancement 🌟 New feature or request hard 🧑‍🔬 Difficult to deal with or require research sdk ⚒️

Comments

@hackerwins
Copy link
Member

hackerwins commented May 8, 2020

Yorkie internally saves a history of all changes in documents. This enables time travel which is looking at the document state at past points in time.

The current state of the Yorkie system is as follows:

Past to Present
For now, we have not introduced inverse operations yet, we can only apply operations from the past to the present.

Screen Shot 2021-06-13 at 3 24 56 PM

Changes and Snapshots

Currently, Client only has a snapshot of the current state and changes that have not been sent to Agent. Since client data is not enough, we need to use Snapshots and Changes stored on Agent for time travel.

For example, if Client A wants to go back to S7, it needs S5, C6, and C7.

Screen Shot 2021-06-13 at 3 40 50 PM

Proposal

We can think of a document as a pointer to a specific location in a Change. Using this, we can create two features, fork and peek.

Screen Shot 2021-06-15 at 3 20 12 AM

const doc1 = client.createDocument('docs', 'doc1');

...

// serverSeq is the position in the order of the last change stored in Agent.
const serverSeq = doc1.getCheckpoint().getServerSeqAsString(); // for example: 4

// peek returns a snapshot of the change at a specific location from Agent.
const snapshot = await client.peek(doc1, serverSeq.divide(2));

// Create a new document that forked from a specific location in doc1.
const doc2 = await client.fork('docs', 'doc2', doc1, serverSeq.divide(2)); // for example: 2
doc2.update((root) => {
  root.hello = 'world';
});
@hackerwins hackerwins added the enhancement 🌟 New feature or request label May 23, 2020
@hackerwins hackerwins self-assigned this Jun 13, 2021
@hackerwins hackerwins changed the title Support version history Support time travel Jun 14, 2021
@hackerwins hackerwins removed their assignment Aug 14, 2021
@hackerwins hackerwins self-assigned this Oct 29, 2021
@hackerwins hackerwins removed their assignment Nov 20, 2021
@hackerwins hackerwins self-assigned this Feb 5, 2022
@hackerwins hackerwins mentioned this issue Feb 5, 2022
2 tasks
@hackerwins
Copy link
Member Author

Conflict can arise when Client A is restoring the document to a point in changes while Client B makes new changes from an earlier point in time.

Google Docs exposes the following dialog with the message with a red banner.

Document cannot be saved!

An error prevented this document from being saved. Please copy your changes and paste them elsewhere. Then tap on the red banner below to remove the problematic changes and continue editing.

We also have to deal with exposing an error when there are changes created at the same time as restoring.

Screen Shot 2022-02-18 at 4 08 51 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🌟 New feature or request hard 🧑‍🔬 Difficult to deal with or require research sdk ⚒️
Projects
Status: Backlog
Status: Todo
Development

No branches or pull requests

1 participant