-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Consistency in API response for live broker #12201
Conversation
d85285f
to
5bd97a6
Compare
5bd97a6
to
95ce4fd
Compare
@Jackie-Jiang comments on linked PR #11850 -
done
done
the default value for optional query params is "", and setting a custom default value also only takes a string
done
done |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12201 +/- ##
=============================================
- Coverage 61.75% 34.52% -27.24%
+ Complexity 207 6 -201
=============================================
Files 2436 2385 -51
Lines 133233 130968 -2265
Branches 20636 20292 -344
=============================================
- Hits 82274 45212 -37062
- Misses 44911 82432 +37521
+ Partials 6048 3324 -2724
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
try { | ||
return _pinotHelixResourceManager.getTableToLiveBrokersMapping(); | ||
return _pinotHelixResourceManager.getTableToLiveBrokersMapping(Optional.of(tableName)); |
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.
This might not give Optional.empty()
when tableName is empty which should be the desired behaviour here. You can modify it to - tableName.equals("") ? Optional.empty() : Optional.of(tableName)
?
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 check if (optionalTableName.isPresent() && !optionalTableName.get().isEmpty())
in getTableToLiveBrokersMapping
checks if the tableName string is empty.
Added a test case for the same.
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.
looks good to me overall. comment on the API changes. PTAL
...oller/src/main/java/org/apache/pinot/controller/api/resources/PinotRunningQueryResource.java
Outdated
Show resolved
Hide resolved
...ntroller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
Outdated
Show resolved
Hide resolved
e52a65b
to
28309a6
Compare
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.
looks good to me; tagging @Jackie-Jiang to take another look since he originally commented on previous PR
if (nullableTableName != null && !nullableTableName.toString().isEmpty()) { | ||
List<String> tableNameWithType = getExistingTableNamesWithType(nullableTableName.toString(), null); | ||
if (tableNameWithType.isEmpty()) { | ||
throw new TableNotFoundException(String.format("Table=%s not found", nullableTableName)); |
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.
should we make it consistent?
throw new TableNotFoundException(String.format("Table=%s not found", nullableTableName)); | |
throw new ControllerApplicationException(LOGGER, String.format("Table=%s not found", nullableTableName), Response.Status.NOT_FOUND); |
3d39785
to
37130a1
Compare
ed7a4e8
to
000ba11
Compare
@Jackie-Jiang @walterddr please take a look |
@@ -3921,7 +3921,16 @@ public TableStats getTableStats(String tableNameWithType) { | |||
* Returns map of tableName to list of live brokers | |||
* @return Map of tableName to list of ONLINE brokers serving the table | |||
*/ | |||
public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping() { | |||
public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping() throws TableNotFoundException { |
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.
(minor) reformat this change
* Returns map of arg tableName to list of live brokers | ||
* @return Map of arg tableName to list of ONLINE brokers serving the table | ||
*/ | ||
public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping(@Nullable Object nullableTableName) |
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.
public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping(@Nullable Object nullableTableName) | |
public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping(@Nullable String tableName) |
@@ -3933,6 +3942,29 @@ public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping() { | |||
|
|||
Map<String, List<InstanceInfo>> result = new HashMap<>(); | |||
ZNRecord znRecord = ev.getRecord(); | |||
|
|||
if (nullableTableName != null && !nullableTableName.toString().isEmpty()) { |
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.
if (nullableTableName != null && !nullableTableName.toString().isEmpty()) { | |
if (StringUtils.isEmpty(tableName)) { |
Map<String, String> brokersToState = znRecord.getMapField(tableName); | ||
List<InstanceInfo> hosts = new ArrayList<>(); | ||
for (Map.Entry<String, String> brokerEntry : brokersToState.entrySet()) { | ||
if ("ONLINE".equalsIgnoreCase(brokerEntry.getValue()) | ||
&& instanceConfigMap.containsKey(brokerEntry.getKey())) { | ||
InstanceConfig instanceConfig = instanceConfigMap.get(brokerEntry.getKey()); | ||
hosts.add(new InstanceInfo(instanceConfig.getInstanceName(), instanceConfig.getHostName(), | ||
Integer.parseInt(instanceConfig.getPort()))); | ||
} | ||
} |
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.
Consider extracting a common method
@@ -165,9 +166,11 @@ public List<String> getLiveBrokersForTable( | |||
@ApiResponses(value = { | |||
@ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Internal server error") | |||
}) | |||
public Map<String, List<InstanceInfo>> getLiveBrokers() { | |||
public Map<String, List<InstanceInfo>> getLiveBrokers( | |||
@ApiParam(value = "Table name (with or without type)", required = false) @DefaultValue("") |
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.
Are we going to ask for liver brokers on multiple tables (e.g. for JOIN queries)? If so, suggest taking tableName
as a list. Search for allowMultiple = true
to find examples of using list as api param
d283e25
to
781e290
Compare
public Map<String, List<InstanceInfo>> getLiveBrokers(@Context HttpHeaders headers) { | ||
public Map<String, List<InstanceInfo>> getLiveBrokers(@Context HttpHeaders headers, | ||
@ApiParam(value = "Table name list(with or without type)", allowMultiple = true) | ||
@QueryParam("tableNameList") List<String> tableNameList) { |
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.
Suggest naming the parameter "tables"
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.
@Jackie-Jiang addressed
b587d9a
to
b2e661c
Compare
b2e661c
to
3b6bfd2
Compare
Resolves #11841