-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(4981): incorrect error wrapping in OnceFut
#4983
Conversation
52d0eae
to
15886a8
Compare
15886a8
to
c434859
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, I think the string hack was a clear shortcut, and removing it LGTM.
If it is possible to remove the double-arc, I'd like to do that before merging.
@@ -438,7 +438,7 @@ impl<T: 'static> OnceAsync<T> { | |||
} | |||
|
|||
/// The shared future type used internally within [`OnceAsync`] | |||
type OnceFutPending<T> = Shared<BoxFuture<'static, Arc<Result<T>>>>; | |||
type OnceFutPending<T> = Shared<BoxFuture<'static, Arc<SharedResult<T>>>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that SharedResult
has an Arc
, can we avoid the double-arc here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OnceFut
is cloneable, while SharedResult
wraps only Err
into Arc
to allow cloning the error itself 🤔
I decided to declare it as SharedResult<Arc<T>>
instead, so it won't be Arc
inside Arc
. It will be either content of Ok
or Error
wrapped into Arc
.
48aab75
to
3cfdec6
Compare
@@ -36,6 +36,9 @@ use sqlparser::parser::ParserError; | |||
/// Result type for operations that could result in an [DataFusionError] | |||
pub type Result<T> = result::Result<T, DataFusionError>; | |||
|
|||
/// Result type for operations that could result in an [DataFusionError] and needs to be shared (wrapped into `Arc`). | |||
pub type SharedResult<T> = result::Result<T, Arc<DataFusionError>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this PR never actually returns this type, do we need to declare it here? Or could we just move it into utils?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I observed that Result<T, Arc<Error>
is quite common approach to allow clonning errors in datafustion & arrow.
And not to miss such kind of errors, I think it would be nice to have it as general type.
Take a look at #4992 and even current find_root
impl, it's easy to forget that error could be wrapped into Arc
actually (IMO)
I believe this type should be used when it's needed to explicitly declare that error is wrapped into Arc
. And could be used in other places later.
And this PR doesn't return this type, however it will be inside ArrowError::ExternalError(..)
, so actually it's way of explicit usage to be able to check all usages of this pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow clonning errors in datafustion & arrow.
I don't see any other examples of this pattern?
so actually it's way of explicit usage to be able to check all usages of this pattern
I'd hope that any codepath that cares about these variants would walk the source
tree and effectively blindly skip over the Arc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #4992 for the code (that does indeed walk over Arcs). It was non ideal however. Figuring out some way to avoid Arc'ing errors would be better in my opinion (not for this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I would suggest keeping SharedResult as an implementation detail, i.e. within utils have something like
type SharedResult<T> = std::result::Result<Arc<T>,Arc<DataFusionError>>;
Thanks @DDtKey |
Benchmark runs are scheduled for baseline = 6dce728 and contender = 22d106a. 22d106a is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Which issue does this PR close?
Closes #4981
Rationale for this change
I used approach with errors wrapped to
Arc
(I see it's common pattern in arrow & datafusion), because it should be shareable.I also created separate type alias for that
What changes are included in this PR?
Are these changes tested?
I've added test which failed before these changes.
Are there any user-facing changes?