-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[feat][admin] PIP-415: Support getting message ID by index #24222
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
base: master
Are you sure you want to change the base?
Conversation
035132b
to
75194f7
Compare
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
Outdated
Show resolved
Hide resolved
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.
#24220 PIP has a lot of adjustments.
@liangyepianzhou please ping me after you modify the code and I will review it again.
Good jobs |
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
Outdated
Show resolved
Hide resolved
@ApiResponse(code = 406, message = "The topic is not a persistent topic"), | ||
@ApiResponse(code = 412, message = "The broker is not enable broker entry metadata"), | ||
}) | ||
public void getMessageIDByIndexAndPartitionID(@Suspended final AsyncResponse asyncResponse, |
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.
The AndPartitionID
suffix in the method seems meaningless (and confusing)?
} else { | ||
indexFuture.complete(index); | ||
} | ||
} |
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.
You must release entry
here.
I think you can add a common method for both asyncReadEntry
and asyncFindPosition
to use. Here is an example:
private static Optional<Long> getIndexAndRelease(Entry entry) throws IOException {
try {
final var brokerEntryMetadata = Commands.parseBrokerEntryMetadataIfExist(entry.getDataBuffer());
if (brokerEntryMetadata != null && brokerEntryMetadata.hasIndex()) {
return Optional.of(brokerEntryMetadata.getIndex());
} else {
return Optional.empty();
}
} catch (Throwable throwable) {
throw new IOException(throwable);
}
}
The implementation above forces the caller side to handle the two exceptional cases:
Optional.empty()
is returned, which indicates the broker entry metadata does not exist or the index does not exist (your code does not take it into consideration)- The buffer is corrupted, where
IOException
will be thrown
But you can implement your own method if you care much about the overhead of Optional
or don't want to use checked exception.
} | ||
ManagedLedger managedLedger = persistentTopic.getManagedLedger(); | ||
return findMessageIndexByPosition( | ||
PositionFactory.create(managedLedger.getFirstPosition().getLedgerId(), 0), |
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.
Why not just pass managedLedger.getFirstPosition()
here?
Out of the scope of this PR, I think it would be better to add a method to |
PIP:#24220
Motivation
we can now obtain the offset of a message by its message id:
get-message-by-id
cmdMessage.getIndex()
But we cannot obtain the message id by offset. Then we need to add a new API to get the message id by offset.
Modifications
Add a new http API to retrieve the message ID by offset.
We propose to add a new API to retrieve the message ID by offset, enabling us to cache the mapping between message ID and offset.
This will allow us to use offsets for seek and acknowledgment operations when consuming messages through the standardized API.
Verifying this change
(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:)
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: