[Runtime Epoch Split] (2/n) Narrow EpochManagerAdapter error type to EpochError wherever possible. #8767
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As a reminder of the overall goal, we want to split
RuntimeWithEpochManagerAdapter
, so that any code that needs the runtime will use anArc<RuntimeAdapter>
, and any code that uses the epoch manager will use theEpochManagerHandle
.We're doing this refactoring bottom-up, i.e. propagating
RuntimeWithEpochManagerAdapter
around at the top-level, but making some lower-level components useArc<RuntimeAdapter>
and/orEpochManagerHandle
.That means we need to be able to obtain an
Arc<RuntimeAdapter>
and anEpochManagerHandle
from aRuntimeWithEpochManagerAdapter
. However, this is not trivial at all:KeyValueRuntime
, the implementation ofRuntimeWithEpochManagerAdapter
for testing, does not contain anEpochManager
at all, so it's not possible to extract anEpochManagerHandle
from it (which is essentially an arc mutex ofEpochManager
). That means instead of usingEpochManagerHandle
, we need to useArc<EpochManagerAdapter>
in the meantime.Arc<EpochManagerAdapter>
from aArc<RuntimeWithEpochManagerAdapter>
is not trivial. Even thoughRuntimeWithEpochManagerAdapter
is a trait that extendsEpochManagerAdapter
, trait upcast is not allowed by Rust in general. So we need to resort to a workaround.This PR addresses an issue arising from (1), that current code that expects an
EpochManagerHandle
uses functions fromEpochManager
which mostly returnsEpochError
.EpochManagerAdapter
, on the other hand, returns mostlynear_chain_primitive::Error
, so changing to the adapter type breaks existing code. So, in this PR we are changing the error type returned from most of theEpochManagerAdapter
functions to also be EpochError. This is a pretty painless transition, except in some cases we need to do a two-hop conversion fromEpochError
to chainError
and then to some other error (and two-hop conversions cannot be supported by.into()
in general), so I've defined.into_chain_error()
to help with the two-hop conversion cases.