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

[Issue 2912][pulsar-admin] add get-message-by-id cmd into pulsar-admin #6331

Merged
merged 12 commits into from
Apr 22, 2020

Conversation

nlu90
Copy link
Member

@nlu90 nlu90 commented Feb 15, 2020

Fixes #2912

Motivation

Adding a new command get-message-by-id to the pulsar-admin which allows user to look at a single message by providing ledger id and entry id.

Modifications

  • pulsar-admin includes the new command get-message-by-id
  • pulsar-broker v1/v2 apis to handle the get-message-by-id request from pulsar-admin
  • managedCursor to read from ledgers with given ledger id and entry id

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.

(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

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: no
  • The rest endpoints: yes
  • The admin cli options: yes
  • Anything that affects deployment: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

@nlu90 nlu90 requested review from sijie and codelipenghui and removed request for sijie February 15, 2020 00:54
@nlu90
Copy link
Member Author

nlu90 commented Feb 15, 2020

Test result on my local laptop:

$ ./bin/pulsar-admin topics get-message-by-id persistent://public/default/my-topic -s "first-subscription" -l 10 -e 0
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 68 65 6c 6c 6f 2d 70 75 6c 73 61 72             |hello-pulsar    |
+--------+-------------------------------------------------+----------------+```

@codelipenghui
Copy link
Contributor

@nlu90 I noticed that to get the message content by ID needs to specify a subscription name. Sorry I didn't clarify this matter in the issue.

Is it better to not require the user to specify the message ID? No matter which subscription name is specified, the returned message content is the same. It's different with peek messages, users can peek one or more messages by peeking messages. So we don’t need to consider whether the message is acknowledged or not.

Future more, the entry may represent a batch message. If I understand correctly, if it is a batch message, the format of the information received by the user may not be easy to read. And the message can encoded by different schema, we need to leverage by pulsar schema. This part can also be solved by a separate PR. At present, the peek message is not handled.

@nlu90
Copy link
Member Author

nlu90 commented Feb 15, 2020

@codelipenghui

For your first suggestion about removing subscription, I actually considered it when I was first implementing this functionality. But later I kept it there due to implementation simplicity. Now I removed it and will create a one-time subscription when fetching the message internally. Please take a look and let me know if you have any other suggestions.

For your second suggestion -- handling batch message, I thins we can handle it it in a separate issue and PR.

@nlu90
Copy link
Member Author

nlu90 commented Feb 15, 2020

Now the command works as following:

$ ./bin/pulsar-admin topics get-message-by-id persistent://public/default/my-topic -l 10 -e 0
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 68 65 6c 6c 6f 2d 70 75 6c 73 61 72             |hello-pulsar    |
+--------+-------------------------------------------------+----------------+```

Copy link
Contributor

@codelipenghui codelipenghui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment related to using ManagedLedger to get a message directly. And please also update the documentation for the new admin method.

* @param callback
* @param ctx
*/
void asyncGetMessageById(long ledgerId, long entryId, IndividualDeletedEntries deletedEntries,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to what we discussed before, We don't need to specify a subscription name for getting a message by ID. So I think we can get a message from ManagedLedger directly by https://github.com/apache/pulsar/blob/master/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java#L1494. So that we don't need to create a one-time subscription.

Entry entry = null;
try {
PersistentSubscription subscription =
(PersistentSubscription) topic.createSubscription(subName, InitialPosition.Earliest, false).get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comments above

@@ -79,6 +80,8 @@ default long getNumberOfEntriesDelayed() {

CompletableFuture<Entry> peekNthMessage(int messagePosition);

CompletableFuture<Entry> getMessageById(long ledgerId, long entryId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can use ManagedLedger directly, this method also can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. Fixed them in the following update.

@sijie sijie added this to the 2.6.0 milestone Feb 16, 2020
@codelipenghui
Copy link
Contributor

@nlu90 Thanks for achieving it. The change looks good to me.
I think the asyncGetMessageById method should remove from ManagedCursor.java right?

@nlu90
Copy link
Member Author

nlu90 commented Feb 17, 2020

@codelipenghui Thanks for all the suggestions. I removed the asyncGetMessageById .

@sijie I think this feature should not be labelled with component/functions.

@sijie
Copy link
Member

sijie commented Feb 17, 2020

@nlu90 my bad. fixed it.

}
}, null);

entry = future.get(1000, TimeUnit.MILLISECONDS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being late in reviewing this pull request. I would suggest implementing this using AsyncResponse. We have tried to move away from using sync methods.

You can check internalCreateSubscription on how to use AsyncResponse.

protected void internalCreateSubscription(AsyncResponse asyncResponse, String subscriptionName,

@codelipenghui codelipenghui added the doc-required Your PR changes impact docs and you will update later. label Feb 17, 2020
@codelipenghui
Copy link
Contributor

@sijie @nlu90 I added doc-required tag since this is a new feature for pulsar-admin. It's better to add a new paragraph in https://github.com/apache/pulsar/blob/master/site2/docs/reference-pulsar-admin.md.

@nlu90
Copy link
Member Author

nlu90 commented Feb 18, 2020

@sijie updated with the asyncResponse to construct the result

@codelipenghui added the doc into the following two md file: reference-pulsar-admin.md and admin-api-persistent-topics.md

Copy link
Member

@sijie sijie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nlu90 overall looks good. one small comment regarding releasing the entry.


PersistentTopic topic = (PersistentTopic) getTopicReference(topicName);
ManagedLedgerImpl ledger = (ManagedLedgerImpl) topic.getManagedLedger();
Entry entry = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed any more.

clientAppId(), ledgerId, entryId, topicName, exception);
asyncResponse.resume(new RestException(exception));
} finally {
if (entry != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this finally block to line 1520

@sijie
Copy link
Member

sijie commented Feb 18, 2020

@nlu90

It seems the code can not be compiled.

[ERROR] /home/runner/work/pulsar/pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:[1540,24] method internalPeekNthMessage(java.lang.String,int,boolean) is already defined in class org.apache.pulsar.broker.admin.impl.PersistentTopicsBase

@Override
public void readEntryComplete(Entry entry, Object ctx) {
try {
asyncResponse.resume(generateResponseWithEntry(entry));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to release the Entry it after using it.

@nlu90
Copy link
Member Author

nlu90 commented Feb 18, 2020

@sijie The problem is caused by some conflicting commit. I've fixed them now. Also added the entry.release() logic to the proper place.

Copy link
Member

@sijie sijie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nlu90 awesome contribution!

@sijie
Copy link
Member

sijie commented Apr 21, 2020

/pulsarbot run-failure-checks

@codelipenghui codelipenghui merged commit d3ac61f into apache:master Apr 22, 2020
@Anonymitaet Anonymitaet removed the doc-required Your PR changes impact docs and you will update later. label Jun 10, 2020
@Anonymitaet Anonymitaet deleted the neng/add-get-message-by-id branch June 10, 2020 08:23
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Aug 24, 2020
apache#6331)

Fixes apache#2912 

### Motivation
Adding a new command `get-message-by-id` to the pulsar-admin which allows user to look at a single message by providing ledger id and entry id.

### Modifications
- pulsar-admin includes the new command `get-message-by-id`
- pulsar-broker v1/v2 apis to handle the get-message-by-id request from pulsar-admin
- managedCursor to read from ledgers with given ledger id and entry id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get message by messageId
4 participants