Skip to content
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

[improve][broker] Add getLastMessagePosition method to TopicCompactionService for flexible customization #38

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.pulsar.common.util.collections.BitSetRecyclable;
import org.apache.pulsar.compaction.Compactor;
import org.apache.pulsar.compaction.TopicCompactionService;
import org.apache.pulsar.metadata.api.MetadataStoreException;
import org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID;
import org.slf4j.Logger;
Expand Down Expand Up @@ -2809,30 +2810,17 @@ protected CompletableFuture<MessageId> internalGetMessageIdByTimestampAsync(long
}
final PersistentTopic persistentTopic = (PersistentTopic) topic;

return persistentTopic.getTopicCompactionService().readLastCompactedEntry().thenCompose(lastEntry -> {
if (lastEntry == null) {
return persistentTopic.getTopicCompactionService().getLastMessagePosition().thenCompose(position -> {
if (position == TopicCompactionService.MessagePosition.EARLIEST) {
return findMessageIdByPublishTime(timestamp, persistentTopic.getManagedLedger());
}
MessageMetadata metadata;
Position position = lastEntry.getPosition();
try {
metadata = Commands.parseMessageMetadata(lastEntry.getDataBuffer());
} finally {
lastEntry.release();
}
if (timestamp == metadata.getPublishTime()) {
return CompletableFuture.completedFuture(new MessageIdImpl(position.getLedgerId(),
position.getEntryId(), topicName.getPartitionIndex()));
} else if (timestamp < metadata.getPublishTime()) {
return persistentTopic.getTopicCompactionService().findEntryByPublishTime(timestamp)
.thenApply(compactedEntry -> {
try {
return new MessageIdImpl(compactedEntry.getLedgerId(),
compactedEntry.getEntryId(), topicName.getPartitionIndex());
} finally {
compactedEntry.release();
}
});
if (timestamp == position.publishTime()) {
return CompletableFuture.completedFuture(new MessageIdImpl(position.ledgerId(),
position.entryId(), topicName.getPartitionIndex()));
} else if (timestamp < position.publishTime()) {
return persistentTopic.getTopicCompactionService().findPositionByPublishTime(timestamp)
.thenApply(__ -> new MessageIdImpl(__.getLedgerId(), __.getEntryId(),
topicName.getPartitionIndex()));
} else {
return findMessageIdByPublishTime(timestamp, persistentTopic.getManagedLedger());
}
Expand Down
Loading
Loading