Skip to content

Allow for three way merges to automatically resolve concurrent changes to a JSON object when the changes affect different keys.#7230

Merged
nicktobey merged 24 commits intomainfrom
nicktobey/json
Jan 8, 2024
Merged

Allow for three way merges to automatically resolve concurrent changes to a JSON object when the changes affect different keys.#7230
nicktobey merged 24 commits intomainfrom
nicktobey/json

Conversation

@nicktobey
Copy link
Copy Markdown
Contributor

@nicktobey nicktobey commented Jan 2, 2024

I recommend looking at one commit at a time.

This PR implemented the "Primary Goal" outlined in this doc.

Basically, when two branches in a merge both modify the same JSON value, but touch different keys, dolt should be able to automatically resolve the merge by doing a Three Way Merge that compares the value on both branches to the value at a common ancestor.

This implementation deviates from the strategy outlined in the doc in one major way: when a branch contains an edit to a nested object, we don't run the diff or merge algorithms recursively. Instead, we generate a diff that contains a JSON path to the modified object. Doing this allows us to generate all the diffs in a single linear pass, and is still easy to reason about what changes are conflicts.

We discussed only performing this merge on JSON objects below a certain size for performance reasons, but the size of the object isn't actually visible to the merge algorithm. Given that this algorithm only runs for rows that would otherwise have a merge conflict, all dolt merges that succeed before this PR should see zero performance impact from this change, so I'm not worried about performance.

@nicktobey nicktobey force-pushed the nicktobey/json branch 2 times, most recently from 0f09ae3 to 92f2a56 Compare January 2, 2024 01:23
@nicktobey nicktobey force-pushed the nicktobey/json branch 3 times, most recently from ef17d46 to 735bca1 Compare January 2, 2024 08:08
Copy link
Copy Markdown
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a few minor comments. Overall, very clean.

Copy link
Copy Markdown
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flag/var to opt-out of json merging looks good!

@nicktobey nicktobey merged commit 2c58d53 into main Jan 8, 2024
@nicktobey nicktobey deleted the nicktobey/json branch January 8, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants