-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[pulsar-admin] Validate the size options in cmd for topic and namespace #13002
[pulsar-admin] Validate the size options in cmd for topic and namespace #13002
Conversation
try { | ||
sizeLimit = validateSizeString(limitStr); | ||
} catch (IllegalArgumentException e) { | ||
throw new ParameterException(String.format("Invalid retention policy type '%s'. Valid formats are: %s", |
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.
It would be better to specify the property with the invalid value, such as 'size limit'.
It's better to create a private method which build the error message, with property and valid values/examples as input
long threshold; | ||
try { | ||
threshold = validateSizeString(thresholdStr); | ||
} catch (IllegalArgumentException e) { |
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.
I think it's better to put the exception convert into validateSizeString
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.
Done, PTAL
@@ -1808,12 +1801,13 @@ void run() throws PulsarAdminException { | |||
description = "Maximum number of bytes in a topic backlog before compaction is triggered " | |||
+ "(eg: 10M, 16G, 3T). 0 disables automatic compaction", | |||
required = true) | |||
private String threshold = "0"; | |||
private String thresholdStr = "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.
These "xxxxStr" modifications seem not necessary? IMHO, the previous way is cleaner.
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.
I think the previous code is not easy to read, and it’s not a good way to pass the method in the method, I prefer to pass a variable. as below:
pulsar/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java
Lines 1517 to 1524 in cfda694
@Parameter(names = { "--size", "-s" }, description = "Retention size limit (eg: 10M, 16G, 3T). " | |
+ "0 or less than 1MB means no retention and -1 means infinite size retention", required = true) | |
private String limitStr; | |
@Override | |
void run() throws PulsarAdminException { | |
String persistentTopic = validatePersistentTopic(params); | |
long sizeLimit = validateSizeString(limitStr); |
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.
OK, it is only a matter of taste.
…pache#13002) * [pulsar-admin] Check the size options in cmd for topic and namespace * Modify validateSizeString method
Motivation
We should check the parameters releted to
size
and throwParameterException
when there is an exception, which can avoid displaying stack information on the client.Currently, the lack of verification about
size
will directly display the exception, as below:Documentation
no-need-doc