Add Support for Getting Live Brokers for a Table (without type suffix)#8188
Add Support for Getting Live Brokers for a Table (without type suffix)#8188chenboat merged 8 commits intoapache:masterfrom
Conversation
|
Adding more APIs makes us pay more tech debt in terms of backward compatibility, etc. We do have a list tables by type API, can u consider using that? We shoul not be adding new APIs to resolve a minor inconvenience, IMO. |
|
@mcvsubbu : Our main use case is to get live brokers of a table. For upstream callers like say Presto, users and the caller aren't aware of the different table-types associated with a given table, and hence the only way to get live brokers for a table in that case would be to try the current API with both table types. Lmk if there's another way to do this. I looked around and it seems this is the only I agree adding APIs isn't tenable and prone to adding more tech debt, but I think in this case this is also cleaning up older tech debt (this was also a comment on the original PR: e2e3aeb#r738959901). I think there are a couple other options worth considering:
|
|
Let's change the existing API to take table name (with or without type suffix).
|
|
@Jackie-Jiang : Thanks. I have updated the PR. Note: At present the API doesn't return a 404 in case the table doesn't exist. It instead returns an empty list and hence I am also returning the same. Should we update the docs too accordingly? (remove |
dceb3ca to
31f17a6
Compare
|
Thanks @chenboat for the review. @Jackie-Jiang can you also take a look? |
Jackie-Jiang
left a comment
There was a problem hiding this comment.
I'd suggest checking the table existence and throw exception if table does not exist to be consistent with other APIs. Within PinotHelixResourceManager, you may throw TableNotFoundException to pass this information
There was a problem hiding this comment.
Please set up the Pinot Style and re-format the code
There was a problem hiding this comment.
Ah good catch.. didn't know about this. Fixed
...-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableInstances.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #8188 +/- ##
============================================
+ Coverage 64.28% 69.66% +5.37%
+ Complexity 4312 4239 -73
============================================
Files 1581 1629 +48
Lines 83122 85159 +2037
Branches 12587 12820 +233
============================================
+ Hits 53436 59326 +5890
+ Misses 25852 21698 -4154
- Partials 3834 4135 +301
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
9104dbe to
f29feed
Compare
Jackie-Jiang
left a comment
There was a problem hiding this comment.
The overall logic looks good
| @ApiResponses(value = { | ||
| @ApiResponse(code = 200, message = "Success"), | ||
| @ApiResponse(code = 404, message = "Table not found"), | ||
| @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 404, message = "Table not found"), |
| try { | ||
| return _pinotHelixResourceManager.getLiveBrokersForTable(tableName); | ||
| } catch (TableNotFoundException tableNotFoundException) { | ||
| throw new WebApplicationException(String.format("Table=%s not found", tableName), 404); |
There was a problem hiding this comment.
We have some example of returning table not found in PinotTableRestletResource
| throw new WebApplicationException(String.format("Table=%s not found", tableName), 404); | |
| throw new ControllerApplicationException(LOGGER, String.format("Table '%s' does not exist", tableName), | |
| Response.Status.NOT_FOUND); |
| } | ||
| } | ||
|
|
||
| public void setPinotHelixResourceManager(PinotHelixResourceManager pinotHelixResourceManager) { |
There was a problem hiding this comment.
Suggest removing this function and PinotTableInstancesTest. The test in PinotHelixResourceManagerTest is good enough, no need to mock a PinotHelixResourceManager for one line of code
| * Broker_hostname_port | ||
| */ | ||
| public List<String> getLiveBrokersForTable(String tableNameWithType) { | ||
| public List<String> getLiveBrokersForTable(String tableName, TableType tableType) { |
There was a problem hiding this comment.
Suggest merging the logic of this method into the main method to avoid looking up BROKER_RESOURCE twice. Also (not introduced in this PR), when BROKER_RESOURCE cannot be found, we should probably throw an exception instead of returning empty result
...ntroller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
Show resolved
Hide resolved
| } | ||
| return getLiveBrokersForTable(tableName, inputTableType); | ||
| } | ||
| boolean hasOfflineTable = hasOfflineTable(tableName); |
There was a problem hiding this comment.
(minor) Generate offlineTableName and realtimeTableName using TableNameBuilder.OFFLINE.tableNameWithType(tableName) and TableNameBuilder.REALTIME.tableNameWithType(tableName) which can be used to check table existence and lookup the external view to avoid generating them multiple times.
...ller/src/test/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManagerTest.java
Show resolved
Hide resolved
| ExternalView ev = _helixDataAccessor.getProperty(_keyBuilder.externalView(Helix.BROKER_RESOURCE_INSTANCE)); | ||
| if (ev == null) { | ||
| return Collections.EMPTY_LIST; | ||
| return new ArrayList<>(); |
There was a problem hiding this comment.
@Jackie-Jiang : Can you specify which exception should we return when ExternalView is null?
There was a problem hiding this comment.
We can throw new IllegalStateException("Failed to find external view for " + Helix.BROKER_RESOURCE_INSTANCE), and the rest API should return 500
Jackie-Jiang
left a comment
There was a problem hiding this comment.
LGTM with minor comments
| ExternalView ev = _helixDataAccessor.getProperty(_keyBuilder.externalView(Helix.BROKER_RESOURCE_INSTANCE)); | ||
| if (ev == null) { | ||
| return Collections.EMPTY_LIST; | ||
| return new ArrayList<>(); |
There was a problem hiding this comment.
We can throw new IllegalStateException("Failed to find external view for " + Helix.BROKER_RESOURCE_INSTANCE), and the rest API should return 500
...ntroller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
Outdated
Show resolved
Hide resolved
...ller/src/test/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManagerTest.java
Outdated
Show resolved
Hide resolved
| * 3. If the tableName doesn't have a type-suffix and there are both REALTIME | ||
| * and OFFLINE tables, then the intersection of the brokers for the two table-types | ||
| * would be returned. Intersection is taken since the method guarantees to return | ||
| * brokers which can serve the given table. In case of no type provided, it returns |
There was a problem hiding this comment.
"In case of no type provided..." -- isn't this sentence a repeat of what is stated right before it?
Description
fixes #8187
At present the /tables/{tableNameWithType}/livebrokers API doesn't support table names without the type suffix. Upstream callers that are not aware of the available types for a given table will have to try the API for both the table-types to determine the available brokers.
We can either update the existing API to handle tables names without type or add a new API. Updating the existing API would inevitably change the behavior of the API so it can cause compatibility issues.
This was also discussed in the PR for adding the livebrokers API as a follow-up: e2e3aeb#r738959901
Test Plan: I have added a UT. Also tested on a local Pinot instance. Output below:
Upgrade Notes
Does this PR prevent a zero down-time upgrade? (Assume upgrade order: Controller, Broker, Server, Minion)
Does this PR fix a zero-downtime upgrade introduced earlier?
Does this PR otherwise need attention when creating release notes? Things to consider:
release-notesand complete the section on Release Notes)Release Notes
Documentation