You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "aloyszhang (via GitHub)" <gi...@apache.org> on 2024/09/11 10:13:52 UTC
[PR] [improve][broker] reducing the parse of MessageMetadata in compaction [pulsar]
aloyszhang opened a new pull request, #23285:
URL: https://github.com/apache/pulsar/pull/23285
### Motivation
There are many redundant parses of MessageMetadata in topic compaction, including phase one and phase two
### Modifications
reuse the MessageMetadata object when do topic compaction
### Verifying this change
- [ ] Make sure that the change passes the CI checks.
*(Please pick either of the following options)*
This change is a trivial rework / code cleanup without any test coverage.
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
### Matching PR in forked repository
PR in forked repository: <!-- ENTER URL HERE -->
<!--
After opening this PR, the build in apache/pulsar will fail and instructions will
be provided for opening a PR in the PR author's forked repository.
apache/pulsar pull requests should be first tested in your own fork since the
apache/pulsar CI based on GitHub Actions has constrained resources and quota.
GitHub Actions provides separate quota for pull requests that are executed in
a forked repository.
The tests will be run in the forked repository until all PR review comments have
been handled, the tests pass and the PR is approved by a reviewer.
-->
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#discussion_r1756308136
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawBatchConverter.java:
##########
@@ -52,12 +52,16 @@ public static boolean isReadableBatch(MessageMetadata metadata) {
return metadata.hasNumMessagesInBatch() && metadata.getEncryptionKeysCount() == 0;
}
- public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg)
+ public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg, MessageMetadata metadata)
throws IOException {
checkArgument(msg.getMessageIdData().getBatchIndex() == -1);
ByteBuf payload = msg.getHeadersAndPayload();
- MessageMetadata metadata = Commands.parseMessageMetadata(payload);
+ if (metadata == null) {
+ metadata = Commands.parseMessageMetadata(payload);
Review Comment:
One more concern. `Commands.parseMessageMetadata(payload)` will use a shared thread local instance. Is that a problem here?
`Commands.parseMessageMetadata(payload, new MessageMetadata())` would be a way to resolve it if there's a need to have multiple instances in flight.
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#discussion_r1756221353
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawBatchConverter.java:
##########
@@ -123,7 +135,9 @@ public static Optional<RawMessage> rebatchMessage(RawMessage msg,
payload.readerIndex(readerIndex);
brokerMeta = payload.readSlice(brokerEntryMetadataSize + Short.BYTES + Integer.BYTES);
}
- MessageMetadata metadata = Commands.parseMessageMetadata(payload);
+ if (metadata == null) {
+ metadata = Commands.parseMessageMetadata(payload);
Review Comment:
is there a need to skip the message metadata if it's not parsed?
Doesn't `parseMessageMetadata` move the read position of the ByteBuf forward?
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#discussion_r1756220527
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawBatchConverter.java:
##########
@@ -52,12 +52,14 @@ public static boolean isReadableBatch(MessageMetadata metadata) {
return metadata.hasNumMessagesInBatch() && metadata.getEncryptionKeysCount() == 0;
}
- public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg)
+ public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg, MessageMetadata metadata)
throws IOException {
checkArgument(msg.getMessageIdData().getBatchIndex() == -1);
ByteBuf payload = msg.getHeadersAndPayload();
- MessageMetadata metadata = Commands.parseMessageMetadata(payload);
+ if (metadata == null) {
+ metadata = Commands.parseMessageMetadata(payload);
Review Comment:
is there a need to skip the message metadata if it's not parsed?
Doesn't `parseMessageMetadata` move the read position of the ByteBuf forward?
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "lordcheng10 (via GitHub)" <gi...@apache.org>.
lordcheng10 commented on PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#issuecomment-2350954925
LGTM
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#issuecomment-2346124375
## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/23285?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `85.18519%` with `4 lines` in your changes missing coverage. Please review.
> Project coverage is 74.51%. Comparing base [(`bbc6224`)](https://app.codecov.io/gh/apache/pulsar/commit/bbc62245c5ddba1de4b1e7cee4ab49334bc36277?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`3f3efad`)](https://app.codecov.io/gh/apache/pulsar/commit/3f3efad51126b6a9cb18d348a4754a17d940ee52?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
> Report is 576 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/pulsar/pull/23285?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...che/pulsar/compaction/EventTimeOrderCompactor.java](https://app.codecov.io/gh/apache/pulsar/pull/23285?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fcompaction%2FEventTimeOrderCompactor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NvbXBhY3Rpb24vRXZlbnRUaW1lT3JkZXJDb21wYWN0b3IuamF2YQ==) | 50.00% | [2 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/pulsar/pull/23285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/pulsar/pull/23285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #23285 +/- ##
============================================
+ Coverage 73.57% 74.51% +0.93%
+ Complexity 32624 2758 -29866
============================================
Files 1877 1927 +50
Lines 139502 145065 +5563
Branches 15299 15862 +563
============================================
+ Hits 102638 108088 +5450
+ Misses 28908 28704 -204
- Partials 7956 8273 +317
```
| [Flag](https://app.codecov.io/gh/apache/pulsar/pull/23285/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [inttests](https://app.codecov.io/gh/apache/pulsar/pull/23285/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `27.85% <11.11%> (+3.27%)` | :arrow_up: |
| [systests](https://app.codecov.io/gh/apache/pulsar/pull/23285/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `24.72% <11.11%> (+0.39%)` | :arrow_up: |
| [unittests](https://app.codecov.io/gh/apache/pulsar/pull/23285/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.85% <85.18%> (+1.00%)` | :arrow_up: |
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=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Files with missing lines](https://app.codecov.io/gh/apache/pulsar/pull/23285?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...g/apache/pulsar/client/impl/RawBatchConverter.java](https://app.codecov.io/gh/apache/pulsar/pull/23285?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fclient%2Fimpl%2FRawBatchConverter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NsaWVudC9pbXBsL1Jhd0JhdGNoQ29udmVydGVyLmphdmE=) | `94.79% <100.00%> (+0.88%)` | :arrow_up: |
| [...e/pulsar/compaction/AbstractTwoPhaseCompactor.java](https://app.codecov.io/gh/apache/pulsar/pull/23285?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fcompaction%2FAbstractTwoPhaseCompactor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NvbXBhY3Rpb24vQWJzdHJhY3RUd29QaGFzZUNvbXBhY3Rvci5qYXZh) | `76.77% <100.00%> (ø)` | |
| [...he/pulsar/compaction/PublishingOrderCompactor.java](https://app.codecov.io/gh/apache/pulsar/pull/23285?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fcompaction%2FPublishingOrderCompactor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NvbXBhY3Rpb24vUHVibGlzaGluZ09yZGVyQ29tcGFjdG9yLmphdmE=) | `93.18% <100.00%> (ø)` | |
| [...che/pulsar/compaction/EventTimeOrderCompactor.java](https://app.codecov.io/gh/apache/pulsar/pull/23285?src=pr&el=tree&filepath=pulsar-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fcompaction%2FEventTimeOrderCompactor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NvbXBhY3Rpb24vRXZlbnRUaW1lT3JkZXJDb21wYWN0b3IuamF2YQ==) | `35.82% <50.00%> (ø)` | |
... and [557 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/23285/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#discussion_r1756339286
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawBatchConverter.java:
##########
@@ -52,12 +52,16 @@ public static boolean isReadableBatch(MessageMetadata metadata) {
return metadata.hasNumMessagesInBatch() && metadata.getEncryptionKeysCount() == 0;
}
- public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg)
+ public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg, MessageMetadata metadata)
throws IOException {
checkArgument(msg.getMessageIdData().getBatchIndex() == -1);
ByteBuf payload = msg.getHeadersAndPayload();
- MessageMetadata metadata = Commands.parseMessageMetadata(payload);
+ if (metadata == null) {
+ metadata = Commands.parseMessageMetadata(payload);
Review Comment:
I think it's not a problem.
Metadata is parsed previously when doing compaction in both phase one and phase two.
The null value for metadata only happens in unit tests.
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#discussion_r1756291206
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawBatchConverter.java:
##########
@@ -123,7 +135,9 @@ public static Optional<RawMessage> rebatchMessage(RawMessage msg,
payload.readerIndex(readerIndex);
brokerMeta = payload.readSlice(brokerEntryMetadataSize + Short.BYTES + Integer.BYTES);
}
- MessageMetadata metadata = Commands.parseMessageMetadata(payload);
+ if (metadata == null) {
+ metadata = Commands.parseMessageMetadata(payload);
Review Comment:
fixed
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#discussion_r1756283866
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawBatchConverter.java:
##########
@@ -52,12 +52,14 @@ public static boolean isReadableBatch(MessageMetadata metadata) {
return metadata.hasNumMessagesInBatch() && metadata.getEncryptionKeysCount() == 0;
}
- public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg)
+ public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg, MessageMetadata metadata)
throws IOException {
checkArgument(msg.getMessageIdData().getBatchIndex() == -1);
ByteBuf payload = msg.getHeadersAndPayload();
- MessageMetadata metadata = Commands.parseMessageMetadata(payload);
+ if (metadata == null) {
+ metadata = Commands.parseMessageMetadata(payload);
Review Comment:
Yes, you're right. I missed it before.
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "lordcheng10 (via GitHub)" <gi...@apache.org>.
lordcheng10 merged PR #23285:
URL: https://github.com/apache/pulsar/pull/23285
--
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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#issuecomment-2343224519
@aloyszhang Please add the following content to your PR description and select a checkbox:
```
- [ ] `doc` <!-- Your PR contains doc changes -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [ ] `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
Re: [PR] [improve][broker] Reducing the parse of MessageMetadata in compaction [pulsar]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #23285:
URL: https://github.com/apache/pulsar/pull/23285#discussion_r1756290780
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawBatchConverter.java:
##########
@@ -52,12 +52,14 @@ public static boolean isReadableBatch(MessageMetadata metadata) {
return metadata.hasNumMessagesInBatch() && metadata.getEncryptionKeysCount() == 0;
}
- public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg)
+ public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg, MessageMetadata metadata)
throws IOException {
checkArgument(msg.getMessageIdData().getBatchIndex() == -1);
ByteBuf payload = msg.getHeadersAndPayload();
- MessageMetadata metadata = Commands.parseMessageMetadata(payload);
+ if (metadata == null) {
+ metadata = Commands.parseMessageMetadata(payload);
Review Comment:
fixed
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawBatchConverter.java:
##########
@@ -52,12 +52,14 @@ public static boolean isReadableBatch(MessageMetadata metadata) {
return metadata.hasNumMessagesInBatch() && metadata.getEncryptionKeysCount() == 0;
}
- public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg)
+ public static List<MessageCompactionData> extractMessageCompactionData(RawMessage msg, MessageMetadata metadata)
throws IOException {
checkArgument(msg.getMessageIdData().getBatchIndex() == -1);
ByteBuf payload = msg.getHeadersAndPayload();
- MessageMetadata metadata = Commands.parseMessageMetadata(payload);
+ if (metadata == null) {
+ metadata = Commands.parseMessageMetadata(payload);
Review Comment:
fixed, PTAL again.
--
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