You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "coderzc (via GitHub)" <gi...@apache.org> on 2023/11/21 04:07:35 UTC
[PR] [fix][broker] Fix issue with GetMessageIdByTimestamp can't find match messageId from compacted ledger [pulsar]
coderzc opened a new pull request, #21600:
URL: https://github.com/apache/pulsar/pull/21600
<!-- Details of when a PIP is required and how the PIP process work, please see: https://github.com/apache/pulsar/blob/master/pip/README.md -->
### Motivation
Currently, if topic compaction is enabled and the original ledger is trimmed, we won't be able to get the correct messageID by `publishTime`, we should first try to find messageID from the compacted ledger. Since we introduced the findEntryByPublishTime method in [PIP-286](https://github.com/apache/pulsar/pull/20867), we can easily implement it.
### Modifications
Try to find messageID from the compacted ledger when getting messageID by publishTime.
Move `findFirstMatchEntry` and `findFirstMatchIndexLoop` methods to `CompactedTopicImpl` to cherry-pick this change into branches before 3.0.
### Verifying this change
- [x] 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.
*(or)*
This change is already covered by existing tests, such as *(please describe tests)*.
*(or)*
This change added tests and can be verified as follows:
*(example:)*
- *Added integration tests for end-to-end deployment with large payloads (10MB)*
- *Extended integration test for recovery after broker failure*
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `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 -->
### 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] [fix][broker] Fix issue with GetMessageIdByTimestamp can't find match messageId from compacted ledger [pulsar]
Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc commented on code in PR #21600:
URL: https://github.com/apache/pulsar/pull/21600#discussion_r1450044227
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -2882,28 +2882,47 @@ protected CompletableFuture<MessageId> internalGetMessageIdByTimestampAsync(long
throw new RestException(Status.METHOD_NOT_ALLOWED,
"Get message ID by timestamp on a non-persistent topic is not allowed");
}
- ManagedLedger ledger = ((PersistentTopic) topic).getManagedLedger();
- return ledger.asyncFindPosition(entry -> {
- try {
- long entryTimestamp = Commands.getEntryTimestamp(entry.getDataBuffer());
- return MessageImpl.isEntryPublishedEarlierThan(entryTimestamp, timestamp);
- } catch (Exception e) {
- log.error("[{}] Error deserializing message for message position find", topicName, e);
- } finally {
- entry.release();
- }
- return false;
- }).thenApply(position -> {
- if (position == null) {
- return null;
- } else {
- return new MessageIdImpl(position.getLedgerId(), position.getEntryId(),
- topicName.getPartitionIndex());
- }
- });
+ return ((PersistentTopic) topic).getTopicCompactionService().findEntryByPublishTime(timestamp)
Review Comment:
Good idea. I check publish time of the last compacted entry to determine whether to find the entry from compacted ledger. PTAL~
--
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] [fix][broker] Fix issue with GetMessageIdByTimestamp can't find match messageId from compacted ledger [pulsar]
Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on code in PR #21600:
URL: https://github.com/apache/pulsar/pull/21600#discussion_r1454530990
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java:
##########
@@ -1459,6 +1463,70 @@ public void onSendAcknowledgement(Producer producer, Message message, MessageId
.compareTo(id2) > 0);
}
+ @Test
+ public void testGetMessageIdByTimestampWithCompaction() throws Exception {
+ TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test"));
+ admin.tenants().createTenant("tenant-xyz", tenantInfo);
+ admin.namespaces().createNamespace("tenant-xyz/ns-abc", Set.of("test"));
+ admin.namespaces().setCompactionThreshold("tenant-xyz/ns-abc", 100*1024*1024L);
Review Comment:
Is it required for this test?
--
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] [fix][broker] Fix issue with GetMessageIdByTimestamp can't find match messageId from compacted ledger [pulsar]
Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc merged PR #21600:
URL: https://github.com/apache/pulsar/pull/21600
--
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] [fix][broker] Fix issue with GetMessageIdByTimestamp can't find match messageId from compacted ledger [pulsar]
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on code in PR #21600:
URL: https://github.com/apache/pulsar/pull/21600#discussion_r1449897315
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -2882,28 +2882,47 @@ protected CompletableFuture<MessageId> internalGetMessageIdByTimestampAsync(long
throw new RestException(Status.METHOD_NOT_ALLOWED,
"Get message ID by timestamp on a non-persistent topic is not allowed");
}
- ManagedLedger ledger = ((PersistentTopic) topic).getManagedLedger();
- return ledger.asyncFindPosition(entry -> {
- try {
- long entryTimestamp = Commands.getEntryTimestamp(entry.getDataBuffer());
- return MessageImpl.isEntryPublishedEarlierThan(entryTimestamp, timestamp);
- } catch (Exception e) {
- log.error("[{}] Error deserializing message for message position find", topicName, e);
- } finally {
- entry.release();
- }
- return false;
- }).thenApply(position -> {
- if (position == null) {
- return null;
- } else {
- return new MessageIdImpl(position.getLedgerId(), position.getEntryId(),
- topicName.getPartitionIndex());
- }
- });
+ return ((PersistentTopic) topic).getTopicCompactionService().findEntryByPublishTime(timestamp)
Review Comment:
Maybe use the `compactedTopicContext` to determine whether reading data from the original `ML` or the ledger containing the data compacted is better. Because if the `@param timestamp` is nearly, and there is considerable data in the ledger containing the data compacted, it costs too much.
--
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] [fix][broker] Fix issue with GetMessageIdByTimestamp can't find match messageId from compacted ledger [pulsar]
Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc commented on code in PR #21600:
URL: https://github.com/apache/pulsar/pull/21600#discussion_r1455110296
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java:
##########
@@ -1459,6 +1463,70 @@ public void onSendAcknowledgement(Producer producer, Message message, MessageId
.compareTo(id2) > 0);
}
+ @Test
+ public void testGetMessageIdByTimestampWithCompaction() throws Exception {
+ TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test"));
+ admin.tenants().createTenant("tenant-xyz", tenantInfo);
+ admin.namespaces().createNamespace("tenant-xyz/ns-abc", Set.of("test"));
+ admin.namespaces().setCompactionThreshold("tenant-xyz/ns-abc", 100*1024*1024L);
Review Comment:
Not necessary, remove it.
--
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