You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/05/09 08:42:01 UTC
[GitHub] [pulsar] eolivelli opened a new pull request, #15503: Issue 15455: [enh] Pulsar Admin: create subscripion with Properties (PIP-105)
eolivelli opened a new pull request, #15503:
URL: https://github.com/apache/pulsar/pull/15503
Fixes #15455
### Motivation
We are missing tools to manage Subscription properties introduces in PIP-105.
### Modifications
Add initial support to "create subscription" in PulsarAdmin API (Java and CLI) to pass subscription properties.
The properties are passed as a query string parameter in order to keep compatibility with the old API and do not require a new API.
### Verifying this change
TODO: add tests
### Documentation
The documentation of pulsar-admin and PulsarAdmin is automatically generated, no need to do anything more
--
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
[GitHub] [pulsar] eolivelli commented on pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#issuecomment-1126255563
@nicoloboschi @mattisonchao
I have to rework this patch, actually there is no way to pass values containing the "comma" (,) or the equals (=) characters, so you are very limited.
I will update it early next week
--
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
[GitHub] [pulsar] eolivelli commented on pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#issuecomment-1123955477
> Overall LGTM, Could we add a test for REST API with properties? Looks like we just have a test for cli.
good point @mattisonchao
I added a test case
--
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
[GitHub] [pulsar] eolivelli commented on a diff in pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#discussion_r872229162
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/nonpersistent/NonPersistentSubscription.java:
##########
@@ -518,4 +521,8 @@ public long getLastActive() {
public void updateLastActive() {
this.lastActive = System.currentTimeMillis();
}
+
+ public Map<String, String> getSubscriptionProperties() {
+ return subscriptionProperties;
Review Comment:
I have wrapped the properties with unmodifiabledMap
--
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
[GitHub] [pulsar] mattisonchao commented on a diff in pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
mattisonchao commented on code in PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#discussion_r871430350
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java:
##########
@@ -1317,7 +1317,7 @@ protected void handleProducer(final CommandProducer cmdProducer) {
}
createInitSubFuture =
topic.createSubscription(initialSubscriptionName, InitialPosition.Earliest,
- false);
+ false, null);
Review Comment:
Could we add a new method or use the empty map to avoid putting the `NULL` value directly.
--
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
[GitHub] [pulsar] eolivelli commented on pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#issuecomment-1126259769
actually the comma character is not a problem
https://www.baeldung.com/jcommander-parsing-command-line-parameters
I misunderstood how "List<String>" behaves
the command will be `pulsar-admin topics create-subscription -p a=b -p c=d -s sub topicname`
but we have to deal with the equals symbol, using split("=") doesn't work well
--
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
[GitHub] [pulsar] 315157973 commented on a diff in pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
315157973 commented on code in PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#discussion_r873138817
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java:
##########
@@ -1456,7 +1460,9 @@ public void createSubscription(
)
ResetCursorData resetCursorData,
@ApiParam(value = "Is replicated required to perform this operation")
- @QueryParam("replicated") boolean replicated
+ @QueryParam("replicated") boolean replicated,
+ @ApiParam(value = "JSON encoded list of properties for the Subscription")
+ @QueryParam("properties") String properties
Review Comment:
Should we put it in the body? The url is too long and prone to truncation
--
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
[GitHub] [pulsar] eolivelli commented on pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#issuecomment-1131684612
/pulsarbot rerun-failure-checks
--
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
[GitHub] [pulsar] eolivelli commented on pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#issuecomment-1127507576
There is something bad with space characters:
```
pulsar-admin topics create test
pulsar-admin topics create-subscription -p 'query=SELECT * FROM aaa where a = {some sql value}' -p foo=bar -s sub test pulsar-admin topics stats test
```
Result:
```
...
"subscriptionProperties" : {
"query" : "SELECT+*+FROM+aaa+where+a+=+{some+sql+value}",
"foo" : "bar"
},
```
so the space character is replaced by the '+' symbol. This is not good. I am working on a fix
--
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
[GitHub] [pulsar] eolivelli commented on pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#issuecomment-1127551332
@mattisonchao @315157973 @nicoloboschi finally I had to put the properties inside the payload of the message.
This is because the query string cannot deal well with some characters.
I am still working on backward compatibility, current still has one problem, if a new version client sets the properties, an old broker will think that we are passing a "null" message id.
--
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
[GitHub] [pulsar] eolivelli commented on pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#issuecomment-1127599744
I have solved the compatibility issue.
the code is pretty ugly, but it works
--
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
[GitHub] [pulsar] eolivelli merged pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli merged PR #15503:
URL: https://github.com/apache/pulsar/pull/15503
--
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
[GitHub] [pulsar] eolivelli commented on pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#issuecomment-1131599808
/pulsarbot rerun-failure-checks
--
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
[GitHub] [pulsar] eolivelli commented on a diff in pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#discussion_r872133220
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/nonpersistent/NonPersistentSubscription.java:
##########
@@ -518,4 +521,8 @@ public long getLastActive() {
public void updateLastActive() {
this.lastActive = System.currentTimeMillis();
}
+
+ public Map<String, String> getSubscriptionProperties() {
+ return subscriptionProperties;
Review Comment:
there is no need to wrap it. it is an internal method and it should be already immutable.
this method is supposed to be called in hotpaths and we have to reduce allocations as much as possible
--
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
[GitHub] [pulsar] eolivelli commented on a diff in pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#discussion_r872132499
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java:
##########
@@ -1317,7 +1317,7 @@ protected void handleProducer(final CommandProducer cmdProducer) {
}
createInitSubFuture =
topic.createSubscription(initialSubscriptionName, InitialPosition.Earliest,
- false);
+ false, null);
Review Comment:
I think that adding a new method will make it more messy than it already looks like.
--
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
[GitHub] [pulsar] nicoloboschi commented on a diff in pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
nicoloboschi commented on code in PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#discussion_r874486117
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java:
##########
@@ -1464,10 +1466,28 @@ public void createSubscription(
throw new RestException(Response.Status.BAD_REQUEST, "Create subscription on non-persistent topic "
+ "can only be done through client");
}
- MessageIdImpl messageId = resetCursorData == null ? null :
- new MessageIdImpl(resetCursorData.getLedgerId(), resetCursorData.getEntryId(),
- resetCursorData.getPartitionIndex());
- internalCreateSubscription(asyncResponse, decode(encodedSubName), messageId, authoritative, replicated);
+ MessageIdImpl messageId = null;
+ Map<String, String> subscriptionProperties = null;
+ if (payload != null) {
+ if (payload.containsKey("properties")) {
Review Comment:
what about creating a class that extends ResetCursorData which contains the properties field?
the code will look like this:
```
class CreateSubscriptionPayload extends ResetCursorData {
Map<String, String> properties;
}
if (payload.containsKey("properties")) {
ObjectMapperFactory.getThreadLocal()
.convertValue(messageIdEncoded, CreateSubscriptionPayload.class);
} else {
ObjectMapperFactory.getThreadLocal()
.convertValue(messageIdEncoded, ResetCursorData.class);
}
```
--
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
[GitHub] [pulsar] nicoloboschi commented on a diff in pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
nicoloboschi commented on code in PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#discussion_r871438000
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/nonpersistent/NonPersistentSubscription.java:
##########
@@ -518,4 +521,8 @@ public long getLastActive() {
public void updateLastActive() {
this.lastActive = System.currentTimeMillis();
}
+
+ public Map<String, String> getSubscriptionProperties() {
+ return subscriptionProperties;
Review Comment:
better to return an immutable map here
##########
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdPersistentTopics.java:
##########
@@ -507,8 +512,23 @@ void run() throws PulsarAdminException {
} else {
messageId = validateMessageIdString(messageIdStr);
}
-
- getPersistentTopics().createSubscription(persistentTopic, subscriptionName, messageId);
+ Map<String, String> map = new HashMap<>();
+ if (properties != null) {
+ for (String property : properties) {
+ if (!property.contains("=")) {
Review Comment:
this condition is useless since if `=` is absent, the keyValue length will be 1
##########
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java:
##########
@@ -959,8 +962,23 @@ void run() throws PulsarAdminException {
} else {
messageId = validateMessageIdString(messageIdStr);
}
-
- getTopics().createSubscription(topic, subscriptionName, messageId, replicated);
+ Map<String, String> map = new HashMap<>();
+ if (properties != null) {
+ for (String property : properties) {
+ if (!property.contains("=")) {
Review Comment:
this condition is useless since if = is absent, the keyValue length will be 1
--
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
[GitHub] [pulsar] eolivelli commented on a diff in pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#discussion_r872229670
##########
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdPersistentTopics.java:
##########
@@ -507,8 +512,23 @@ void run() throws PulsarAdminException {
} else {
messageId = validateMessageIdString(messageIdStr);
}
-
- getPersistentTopics().createSubscription(persistentTopic, subscriptionName, messageId);
+ Map<String, String> map = new HashMap<>();
+ if (properties != null) {
+ for (String property : properties) {
+ if (!property.contains("=")) {
Review Comment:
this was copy/paste code, I have consolidated all duplicate code in one single method and addressed your comment
--
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
[GitHub] [pulsar] eolivelli commented on a diff in pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#discussion_r873209782
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java:
##########
@@ -1456,7 +1460,9 @@ public void createSubscription(
)
ResetCursorData resetCursorData,
@ApiParam(value = "Is replicated required to perform this operation")
- @QueryParam("replicated") boolean replicated
+ @QueryParam("replicated") boolean replicated,
+ @ApiParam(value = "JSON encoded list of properties for the Subscription")
+ @QueryParam("properties") String properties
Review Comment:
If we put this into the body then we will have more problems about compatibility, because unfortunately the body is already in use
--
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
[GitHub] [pulsar] eolivelli commented on pull request #15503: [enh] Issue 15455: Pulsar Admin: create subscripion with Properties (PIP-105)
Posted by GitBox <gi...@apache.org>.
eolivelli commented on PR #15503:
URL: https://github.com/apache/pulsar/pull/15503#issuecomment-1131638037
/pulsarbot rerun-failure-checks
--
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