You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "mattisonchao (via GitHub)" <gi...@apache.org> on 2023/02/01 07:18:44 UTC
[GitHub] [pulsar] mattisonchao opened a new pull request, #19381: [improve][ml] Avoid to wrap `CompletionException` in other exception
mattisonchao opened a new pull request, #19381:
URL: https://github.com/apache/pulsar/pull/19381
### Motivation
When I was investigating a problem, I found a bad exception stack trace. It's ugly and made the code harder to handle and to do `instanceOf`.
<img width="700" alt="image" src="https://user-images.githubusercontent.com/74767115/215976411-b45ba2e8-fb90-41b3-8a9c-654db52301f3.png">
### Modifications
- Using the static method to help create `ManagedLedgerException` and `MetaStoreException`.
### Verifying this change
- [x] Make sure that the change passes the CI checks.
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. Please attach the local preview screenshots (run `sh start.sh` at `pulsar/site2/website`) to your PR description, or else your PR might not get merged. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] mattisonchao closed pull request #19381: [improve][ml] Avoid to wrap `CompletionException` in `ManagedLedgerException`
Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao closed pull request #19381: [improve][ml] Avoid to wrap `CompletionException` in `ManagedLedgerException`
URL: https://github.com/apache/pulsar/pull/19381
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] eolivelli commented on a diff in pull request #19381: [improve][ml] Avoid to wrap `CompletionException` in `ManagedLedgerException`
Posted by "eolivelli (via GitHub)" <gi...@apache.org>.
eolivelli commented on code in PR #19381:
URL: https://github.com/apache/pulsar/pull/19381#discussion_r1093283423
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerException.java:
##########
@@ -29,46 +32,61 @@ public ManagedLedgerException(String msg) {
super(msg);
}
- public ManagedLedgerException(Throwable e) {
+ protected ManagedLedgerException(Throwable e) {
super(e);
}
public ManagedLedgerException(String msg, Throwable e) {
super(msg, e);
}
- public static ManagedLedgerException getManagedLedgerException(Throwable e) {
- if (e instanceof ManagedLedgerException) {
- return (ManagedLedgerException) e;
+ /**
+ * Returns the encoding of the given (non-null) exception as a wrapped ManagedLedgerException
+ * unless it is one already. Since we use a lot of CompletableFuture, it will unwrap the completion
+ * exception to help get to the original exception.
+ */
+ public static ManagedLedgerException getManagedLedgerException(@Nonnull Throwable ex) {
Review Comment:
`return toClass.getConstructor(Throwable.class).newInstance(rc);`
This implies that it works only with Exception types that has that constructor.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] mattisonchao closed pull request #19381: [improve][ml] Avoid to wrap `CompletionException` in `ManagedLedgerException`
Posted by "mattisonchao (via GitHub)" <gi...@apache.org>.
mattisonchao closed pull request #19381: [improve][ml] Avoid to wrap `CompletionException` in `ManagedLedgerException`
URL: https://github.com/apache/pulsar/pull/19381
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nicoloboschi commented on a diff in pull request #19381: [improve][ml] Avoid to wrap `CompletionException` in `ManagedLedgerException`
Posted by "nicoloboschi (via GitHub)" <gi...@apache.org>.
nicoloboschi commented on code in PR #19381:
URL: https://github.com/apache/pulsar/pull/19381#discussion_r1093255854
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerException.java:
##########
@@ -29,46 +32,61 @@ public ManagedLedgerException(String msg) {
super(msg);
}
- public ManagedLedgerException(Throwable e) {
+ protected ManagedLedgerException(Throwable e) {
super(e);
}
public ManagedLedgerException(String msg, Throwable e) {
super(msg, e);
}
- public static ManagedLedgerException getManagedLedgerException(Throwable e) {
- if (e instanceof ManagedLedgerException) {
- return (ManagedLedgerException) e;
+ /**
+ * Returns the encoding of the given (non-null) exception as a wrapped ManagedLedgerException
+ * unless it is one already. Since we use a lot of CompletableFuture, it will unwrap the completion
+ * exception to help get to the original exception.
+ */
+ public static ManagedLedgerException getManagedLedgerException(@Nonnull Throwable ex) {
+ final Throwable rc = FutureUtil.unwrapCompletionException(ex);
+ if (rc instanceof ManagedLedgerException) {
+ return (ManagedLedgerException) rc;
}
- return new ManagedLedgerException(e);
+ return new ManagedLedgerException(rc);
}
public static class MetaStoreException extends ManagedLedgerException {
- public MetaStoreException(Throwable t) {
+ protected MetaStoreException(Throwable t) {
super(t);
}
public MetaStoreException(String msg) {
super(msg);
}
+
+ /**
+ * Returns the encoding of the given (non-null) exception as a wrapped MetaStoreException
+ * unless it is one already. Since we use a lot of CompletableFuture, it will unwrap the completion
+ * exception to help get to the original exception.
+ */
+ public static MetaStoreException getException(Throwable ex) {
+ final Throwable rc = FutureUtil.unwrapCompletionException(ex);
+ if (rc instanceof MetadataStoreException.BadVersionException
+ || rc.getCause() instanceof MetadataStoreException.BadVersionException) {
Review Comment:
we should traverse all the exception chain instead of only checking the cause
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerException.java:
##########
@@ -29,46 +32,61 @@ public ManagedLedgerException(String msg) {
super(msg);
}
- public ManagedLedgerException(Throwable e) {
+ protected ManagedLedgerException(Throwable e) {
super(e);
}
public ManagedLedgerException(String msg, Throwable e) {
super(msg, e);
}
- public static ManagedLedgerException getManagedLedgerException(Throwable e) {
- if (e instanceof ManagedLedgerException) {
- return (ManagedLedgerException) e;
+ /**
+ * Returns the encoding of the given (non-null) exception as a wrapped ManagedLedgerException
+ * unless it is one already. Since we use a lot of CompletableFuture, it will unwrap the completion
+ * exception to help get to the original exception.
+ */
+ public static ManagedLedgerException getManagedLedgerException(@Nonnull Throwable ex) {
Review Comment:
what about making this method generic in `FutureUtil` ?
maybe something like
```
@SneakyThrows
public static <T extends Throwable> T wrapException(Class<T> toClass, Throwable ex) {
final Throwable rc = FutureUtil.unwrapCompletionException(ex);
if (rc.getClass().isAssignableFrom(toClass)) {
return (T) rc;
}
return toClass.getConstructor(Throwable.class).newInstance(rc);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] eolivelli commented on a diff in pull request #19381: [improve][ml] Avoid to wrap `CompletionException` in `ManagedLedgerException`
Posted by "eolivelli (via GitHub)" <gi...@apache.org>.
eolivelli commented on code in PR #19381:
URL: https://github.com/apache/pulsar/pull/19381#discussion_r1093284039
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerException.java:
##########
@@ -29,46 +32,61 @@ public ManagedLedgerException(String msg) {
super(msg);
}
- public ManagedLedgerException(Throwable e) {
+ protected ManagedLedgerException(Throwable e) {
super(e);
}
public ManagedLedgerException(String msg, Throwable e) {
super(msg, e);
}
- public static ManagedLedgerException getManagedLedgerException(Throwable e) {
- if (e instanceof ManagedLedgerException) {
- return (ManagedLedgerException) e;
+ /**
+ * Returns the encoding of the given (non-null) exception as a wrapped ManagedLedgerException
+ * unless it is one already. Since we use a lot of CompletableFuture, it will unwrap the completion
+ * exception to help get to the original exception.
+ */
+ public static ManagedLedgerException getManagedLedgerException(@Nonnull Throwable ex) {
+ final Throwable rc = FutureUtil.unwrapCompletionException(ex);
+ if (rc instanceof ManagedLedgerException) {
+ return (ManagedLedgerException) rc;
}
- return new ManagedLedgerException(e);
+ return new ManagedLedgerException(rc);
}
public static class MetaStoreException extends ManagedLedgerException {
- public MetaStoreException(Throwable t) {
+ protected MetaStoreException(Throwable t) {
Review Comment:
this is a public API change
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] eolivelli commented on pull request #19381: [improve][ml] Avoid to wrap `CompletionException` in `ManagedLedgerException`
Posted by "eolivelli (via GitHub)" <gi...@apache.org>.
eolivelli commented on PR #19381:
URL: https://github.com/apache/pulsar/pull/19381#issuecomment-1412135513
please note that even if this kind or refactoring reduce the tech debt, we are adding many risks.
because due to the nature of how CompletableFuture works it is possible that in many points of the pulsar code (and in Protocol handler and other plugins) the code expects a CompletionException and if we drop one level of exceptions the code may misbehave (from unhandled exceptions to NPEs)
I wouldn't go this way.
We cannot risk the stability of the system.
If you found a case in which we didn't handle correctly a completion exception then we should take a look to the specific point
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codecov-commenter commented on pull request #19381: [improve][ml] Avoid to wrap `CompletionException` in `ManagedLedgerException`
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #19381:
URL: https://github.com/apache/pulsar/pull/19381#issuecomment-1412090830
# [Codecov](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#19381](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2c94e25) into [master](https://codecov.io/gh/apache/pulsar/commit/246c2701e5c43e02e9783c82d4d107d06b019951?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (246c270) will **decrease** coverage by `17.34%`.
> The diff coverage is `0.00%`.
[](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #19381 +/- ##
=============================================
- Coverage 43.01% 25.67% -17.34%
+ Complexity 10167 6362 -3805
=============================================
Files 747 1648 +901
Lines 72255 125461 +53206
Branches 7786 13684 +5898
=============================================
+ Hits 31080 32216 +1136
- Misses 37577 88626 +51049
- Partials 3598 4619 +1021
```
| Flag | Coverage Δ | |
|---|---|---|
| inttests | `24.04% <0.00%> (?)` | |
| unittests | `17.54% <0.00%> (-25.47%)` | :arrow_down: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...che/bookkeeper/mledger/ManagedLedgerException.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9NYW5hZ2VkTGVkZ2VyRXhjZXB0aW9uLmphdmE=) | `21.42% <0.00%> (-19.75%)` | :arrow_down: |
| [...che/bookkeeper/mledger/impl/ManagedCursorImpl.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL01hbmFnZWRDdXJzb3JJbXBsLmphdmE=) | `38.78% <0.00%> (+2.01%)` | :arrow_up: |
| [...kkeeper/mledger/impl/ManagedLedgerFactoryImpl.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL01hbmFnZWRMZWRnZXJGYWN0b3J5SW1wbC5qYXZh) | `40.76% <0.00%> (-9.34%)` | :arrow_down: |
| [...che/bookkeeper/mledger/impl/ManagedLedgerImpl.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL01hbmFnZWRMZWRnZXJJbXBsLmphdmE=) | `32.17% <0.00%> (-21.55%)` | :arrow_down: |
| [.../apache/bookkeeper/mledger/impl/MetaStoreImpl.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL01ldGFTdG9yZUltcGwuamF2YQ==) | `42.02% <0.00%> (-6.18%)` | :arrow_down: |
| [...keeper/mledger/impl/ReadOnlyManagedLedgerImpl.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL1JlYWRPbmx5TWFuYWdlZExlZGdlckltcGwuamF2YQ==) | `0.00% <0.00%> (ø)` | |
| [...okkeeper/mledger/impl/ShadowManagedLedgerImpl.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bWFuYWdlZC1sZWRnZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2Jvb2trZWVwZXIvbWxlZGdlci9pbXBsL1NoYWRvd01hbmFnZWRMZWRnZXJJbXBsLmphdmE=) | `0.00% <0.00%> (ø)` | |
| [...sar/broker/service/persistent/PersistentTopic.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9zZXJ2aWNlL3BlcnNpc3RlbnQvUGVyc2lzdGVudFRvcGljLmphdmE=) | `48.60% <0.00%> (-10.47%)` | :arrow_down: |
| [...g/apache/pulsar/compaction/CompactedTopicImpl.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NvbXBhY3Rpb24vQ29tcGFjdGVkVG9waWNJbXBsLmphdmE=) | `72.14% <0.00%> (+2.85%)` | :arrow_up: |
| [...ava/org/apache/pulsar/broker/admin/v1/Brokers.java](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9hZG1pbi92MS9Ccm9rZXJzLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| ... and [1371 more](https://codecov.io/gh/apache/pulsar/pull/19381?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org