Skip to content

Conversation

bts
Copy link
Contributor

@bts bts commented Oct 20, 2025

Hi everyone!

I'm not planning to submit this PR as is. I'm posting this to get some thoughts on this line of work, which converts most methods on Index, MutableIndex, ReadonlyIndex, and ChangeIdIndex to have fallible (i.e. Result) return values. The motivation here is supporting distributed implementations of these index traits which might perform I/O during most operations. This way, implementers would not be forced to keep entire indices in memory. The Backend, OpStore, and OpHeadsStore storage traits already support distributed/network implementations, so these changes bring the *Index traits in line with those three.

If you look at the changes, note that I purposefully did not include a similar conversion of ReadonlyIndex::start_modification() -- that's because the consequences are quite a bit more involved than the other methods, due to causing WorkspaceCommandHelper::start_transaction() to become fallible. From what I can tell, I think most distributed/network implementations of the storage traits would probably be able to get by without making this one fallible by using an interior mutability pattern. (I could go into more detail if that's helpful).

FWIW:

  • if we decide to move forward with something like these changes, I'd submit only a few related changes at a time to keep the reviews manageable.
  • in a few places, rather than introduce more sweeping changes to unify errors (e.g. where we now produce IndexError in addition to BackendError), I erred toward sprinkling in a few more instances of the existing // TODO: indexing error shouldn't be a "BackendError"

Thanks!
Brian

@google-cla
Copy link

google-cla bot commented Oct 20, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@bts bts force-pushed the bts/fallible-traits branch 4 times, most recently from 629eb95 to b0a9250 Compare October 21, 2025 01:29
Copy link
Contributor

@PhilipMetzger PhilipMetzger left a comment

Choose a reason for hiding this comment

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

All in all this looks great. I do think there are some minor codestyle issues and some helpers missing for all the tests which unwrap by default now.

I also think Yuya should take a look at it since he's the expert of that part of the codebase.

@bts
Copy link
Contributor Author

bts commented Oct 21, 2025

Thank you @PhilipMetzger! I'll fix up these items in their respective changes.

@bts bts force-pushed the bts/fallible-traits branch 2 times, most recently from fc935d9 to 4f53071 Compare October 21, 2025 16:23
Copy link
Contributor

@PhilipMetzger PhilipMetzger left a comment

Choose a reason for hiding this comment

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

With some last minor nits this looks good enough to split into 2/3 smaller PRs because this is large and it reduces reviewer time. I'll also let Yuya be the judge of your more functional rewrites of some filter(...).map(...) calls into filter_map.

bts added 4 commits October 22, 2025 15:22
This way we match how errors are organized for the other storage traits,
and we allow for networked implementations of `Index::all_heads_for_gc`
to return I/O errors.
This way we match how the errors are organized for other storage traits.
By using a type alias, we match how `Backend` and `OpStore` traits
organize their errors. This will be useful as we progressively convert
more methods on `Index`, `MutableIndex`, `ReadonlyIndex`, and
`ChangeIdIndex` traits to return `Result<T, IndexError>` in order to
support networked implementations which can produce I/O failures.
By introducing `IndexStoreResult`, we follow the pattern used by other
storage traits: `BackendResult`, `OpStoreResult`, and `IndexResult`.
@bts bts force-pushed the bts/fallible-traits branch from 4f53071 to 36383b1 Compare October 22, 2025 19:27
@bts bts force-pushed the bts/fallible-traits branch from 36383b1 to 1081d57 Compare October 22, 2025 21:17
@bts
Copy link
Contributor Author

bts commented Oct 22, 2025

@yuja @martinvonz @PhilipMetzger Thanks for your help everyone! I believe I've applied all of the suggestions above. I think we can probably start shifting to PRs at this point -- going to close out this draft. I put the first few changes are in #7799.

@bts bts closed this Oct 22, 2025
bts added a commit to bts/jj that referenced this pull request Oct 23, 2025
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which can produce I/O errors during operation. See
jj-vcs#7790 for more information.
bts added a commit to bts/jj that referenced this pull request Oct 23, 2025
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which can produce I/O errors during operation. See
jj-vcs#7790 for more information.
bts added a commit to bts/jj that referenced this pull request Oct 23, 2025
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which can produce I/O errors during operation. See
jj-vcs#7790 for more information.
bts added a commit to bts/jj that referenced this pull request Oct 23, 2025
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which can produce I/O errors during operation. See
jj-vcs#7790 for more information.
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.

4 participants