Skip to content

Add a dry_run mode to LockedWorkingCopy snapshot method. #6375

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

Closed
wants to merge 1 commit into from

Conversation

kevincliao
Copy link
Contributor

At Google, we are building a tool that needs to know the state of a jj repo constantly. Always snapshotting and updating .jj/working_copy/checkout increases the likelihood of write races and should be avoided.

I came across #2562 that encountered the same problem. From the post, the suggested solution is to add a --dry-run/--no-commit-transaction flag. This commit does a part of that by adding a dry_run mode to the WorkingCopy snapshot method. I don't intend to address the whole FR.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

At Google, we are building a tool that needs to know the state of a jj repo constantly. Always snapshotting and updating .jj/working_copy/checkout increases the likelihood of write races and should be avoided. 

I came across jj-vcs#2562 that encountered the same problem. From the post, the suggested solution is to add a --dry-run/--no-commit-transaction flag. This commit does a part of that by adding a `dry_run` mode to the WorkingCopy snapshot method. I don't intend to address the whole FR.
@kevincliao kevincliao requested a review from a team as a code owner April 18, 2025 23:29
});
if dry_run {
return Ok((false, stats));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Always snapshotting and updating .jj/working_copy/checkout increases the likelihood of write races and should be avoided.

Is it important to skip updates of in-memory data? If the write races are the problem, maybe we can just avoid calling .finish(). (We might have to restore the in-meory state, though.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it important to skip updates of in-memory data?

No, we're concerned about parallel updates to the .jj/working_copy/checkout file only. Since Google uses a network file system, races to the file system are far more common.

maybe we can just avoid calling .finish()

That's a great idea, not sure why I haven't thought of that. In our case, we need the trees to be written, but not the checkout file, and not calling finish() seems to do exactly that. I will put this PR on hold, and see if that works.

We might have to restore the in-memory state, though.

Because the snapshot method has updated the internal variables? Our usage pattern does not call other methods after the dry run snapshot, but maybe this can be a problem for others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yay it worked! I'll abandon this PR soon.

trace_span!("write tree").in_scope(|| {
let new_tree_id = tree_builder.write_tree(&self.store).unwrap();
if dry_run {
stats.dry_run_tree_id = Some(new_tree_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: It seems odd that we have dry_run_tree_id which is conditionally set. It might be better to add LockedWorkignCopy::snapshot_dry_run() -> (MergedTreeId, SnapshotStats). It might also make sense to add the function to WorkingCopy because dry-run snapshot() wouldn't need locking.

@kevincliao kevincliao closed this Apr 22, 2025
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

Successfully merging this pull request may close these issues.

2 participants