Fix TODO about making enforce_view_invariants() return an error#9797
Fix TODO about making enforce_view_invariants() return an error#9797kevincliao wants to merge 1 commit into
enforce_view_invariants() return an error#9797Conversation
There was a problem hiding this comment.
The following commits do not follow our format for subject lines:
- 71b819e: Fix TODO about making
enforce_view_invariants()return an error instead of panicking
Commits should have a subject line following the format <topic>: <description>. Please review the commit guidelines for more information.
71b819e to
5db3376
Compare
All commits are now correctly formatted. Thank you for your contribution!
|
imo, this is a |
5db3376 to
3651ccb
Compare
Ah I assumed |
ab2b329 to
31f0299
Compare
…or instead of panicking At Google, we run jj lib on our servers. If jj lib panics, it causes the servers to crash, so we are trying to fix those. In this case, a network issue causes self.index.heads() to return an error, and unwrapping it crashed our servers. As part of the fix I also had to change several functions like view() to also return a Result<>, so this PR modifies many files.
31f0299 to
41281cc
Compare
|
For reference, here's @yuja's opinion from when the TODO was introduced: #5360 (comment) |
@yuja Can you please take a look at this PR? |
|
Btw, note that GitHub's UI seems to open the PR itself if you click the link, but if you choose "open in a new tab", it will take you to the comment I linked to. But let me just copy that comment to here:
I'm not sure what alternative design Yuya had in mind. |
Thanks. I have the habit of always opening in a new tab, so I didn't even realize of the bizarre github behavior. Just to clarify where I'm standing, I consider myself a Rust rookie, and I'm happy to change the code to whatever the best pattern is for Rust. But first I'd need someone (@yuja) to share which direction I should move forwards to. |
Perhaps we can allow duplicates in |
|
I suppose another option is to have |
That makes sense if redundant heads cause problems. Since we often calculate |
|
I don't like the idea of writing duplicate heads or non-heads to the operation at least. If it's just incorrect in memory, then we can at least fix it after we get a bug report. If it's incorrect on disk, then it becomes much more annoying. |
Agreed. The immutable view heads should be canonical at least. If we add something like |
Sorry for the delay, was out yesterday. I think I'm not following how this works. Is this saying that we should add a resolve_heads() function and update existing callers of MutableRepo to call it whenever view can have duplicates? Also,
Sidetracking a bit - Do you think it's a good idea to make jj lib not panic at all, even for human program errors? The crash Google had this time was caused by a neighboring team's servers (Piper) overloaded and rejecting requests. The painful thing about this is, the unwrap() apparently existed for over a year, but only triggered recently when it met the circumstances. And when this happened, our servers repeatedly crashes, and there's no way for us to mitigate the issue immediately since creating a fix can take hours or days. If we can make jj lib not panic at all, it would be much more friendly to use on the server. |
Exactly (well, I didn't write it, but I assume that's what Yuya meant).
If we make it the updater's responsibility to call it, then I think we should just panic if the dirty bit is set in those places.
Strictly speaking no, but I think this particular example is a good one. The reason I think we shouldn't strictly disallow panics even when there are programming errors is that programming errors can be nonobvious but they can also be obvious. Things like Btw, perhaps |
My idea is that, if the caller expects resolved/normalized heads, it should call The latter doesn't have to mutate If we make dirty
+1 |
|
Thanks for the explanations, I will give this a shot. |
|
I was able to update One answer that I believe is wrong is to update as soon as the cell is dirty. I think the existing code tries to avoid that, probably because it wants to reduce the number of calls to the indexer? Let me know whether this is right. My guess to the answer is to call Another question is even if we make |
So IMHO, it seems better to let the callers decide, and allow duplicates in the in-memory mutable // Use normalize/normalized_heads() because the caller expects non-head
// revisions don't exist in the set. ReadonlyRepo just forwards view.heads.
repo.view().normalize_heads()?.contains(working_commit_id)
// Redundant heads are okay here.
let old_heads = RevsetExpression::commits(old_view.heads().iter().cloned().collect());
let new_heads = RevsetExpression::commits(new_view.heads().iter().cloned().collect());
new_heads.range(&old_heads)
// consume() should return normalized view because the view data will be saved to disk.
view.store_view_mut().heads = ...; // copy normalized heads back to view
... |
Did you mean
Do you mean that the caller should remember the results from Also, since it's now entirely the caller's responsibility to do the right thing, should MutableRepo.view now be just a View object, and the |
Yes.
No.
I just assumed it would be easier to implement if repo.view().heads() // returns normalized heads
mut_repo.view().heads() // potentially contains duplicates
mut_repo.normalize_heads()?; mut_repo.view().heads() // normalized heads
// revset.rs
RevsetExpression::VisibleHeads => {
if is_head_normalized { // add flag to Repo trait?
visible_heads
} else {
Heads(visible_heads)
}
}EDIT: The pub struct View {
data: op_store::View,
head_normalized: bool,
}
impl View {
pub fn normalize_heads(&mut self, index, root_commit_id) -> Result<(), _>
} |
Repo: Fix TODO about making enforce_view_invariants() return an error instead of panicking
At Google, we run jj lib on our servers. If jj lib panics, it causes the servers to crash, so we are trying to fix those. In this case, a network issue causes self.index.heads() to return an error, and unwrapping it crashed our servers. As part of the fix I also had to change several functions like view() to also return a Result<>, so this PR modifies many files.
Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,demos/)cli/src/config-schema.json)how it works, how it's organized), including any code drafted by an LLM.
an eye towards deleting anything that is irrelevant, clarifying anything
that is confusing, and adding details that are relevant. This includes,
for example, commit descriptions, PR descriptions, and code comments.