This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 7b4cc830a6 fallback if no broker found for the specified table name
(#9914)
7b4cc830a6 is described below
commit 7b4cc830a695b399ba5915e63841fd451b3f19d2
Author: Xiaobing <[email protected]>
AuthorDate: Mon Dec 5 18:59:09 2022 -0800
fallback if no broker found for the specified table name (#9914)
---
.../apache/pinot/client/DynamicBrokerSelector.java | 22 +++++++++++++++-------
.../pinot/client/DynamicBrokerSelectorTest.java | 22 +++++++++++++++++++---
2 files changed, 34 insertions(+), 10 deletions(-)
diff --git
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/DynamicBrokerSelector.java
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/DynamicBrokerSelector.java
index 44f97ac079..7c7fcfc8b6 100644
---
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/DynamicBrokerSelector.java
+++
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/DynamicBrokerSelector.java
@@ -87,17 +87,25 @@ public class DynamicBrokerSelector implements
BrokerSelector, IZkDataListener {
@Nullable
@Override
public String selectBroker(String table) {
- if (table == null) {
- List<String> list = _allBrokerListRef.get();
+ if (table != null) {
+ String tableName =
+ table.replace(ExternalViewReader.OFFLINE_SUFFIX,
"").replace(ExternalViewReader.REALTIME_SUFFIX, "");
+ List<String> list = _tableToBrokerListMapRef.get().get(tableName);
+ if (list != null && !list.isEmpty()) {
+ return list.get(RANDOM.nextInt(list.size()));
+ }
+ // In case tableName is formatted as <db>.<table>
+ int idx = tableName.indexOf('.');
+ if (idx > 0) {
+ tableName = tableName.substring(idx + 1);
+ }
+ list = _tableToBrokerListMapRef.get().get(tableName);
if (list != null && !list.isEmpty()) {
return list.get(RANDOM.nextInt(list.size()));
- } else {
- return null;
}
}
- String tableName = table.replace(ExternalViewReader.OFFLINE_SUFFIX, "")
- .replace(ExternalViewReader.REALTIME_SUFFIX, "");
- List<String> list = _tableToBrokerListMapRef.get().get(tableName);
+ // Return a broker randomly if table is null or no broker is found for the
specified table.
+ List<String> list = _allBrokerListRef.get();
if (list != null && !list.isEmpty()) {
return list.get(RANDOM.nextInt(list.size()));
}
diff --git
a/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/DynamicBrokerSelectorTest.java
b/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/DynamicBrokerSelectorTest.java
index 733aaa06f3..dd3ee3bbbf 100644
---
a/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/DynamicBrokerSelectorTest.java
+++
b/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/DynamicBrokerSelectorTest.java
@@ -50,7 +50,8 @@ public class DynamicBrokerSelectorTest {
private static final String ZK_SERVER = "zkServers";
@BeforeMethod
- public void setUp() throws Exception {
+ public void setUp()
+ throws Exception {
openMocks(this);
Map<String, List<String>> tableToBrokerListMap = new HashMap<>();
tableToBrokerListMap.put("table1", Collections.singletonList("broker1"));
@@ -88,14 +89,29 @@ public class DynamicBrokerSelectorTest {
}
@Test
- public void testSelectBroker() {
+ public void testSelectBrokerWithTableName() {
_dynamicBrokerSelectorUnderTest.handleDataChange("dataPath", "data");
- String result = _dynamicBrokerSelectorUnderTest.selectBroker("table1");
+ String result = _dynamicBrokerSelectorUnderTest.selectBroker("table1");
assertEquals("broker1", result);
}
+ @Test
+ public void testSelectBrokerWithDBAndTableName() {
+ _dynamicBrokerSelectorUnderTest.handleDataChange("dataPath", "data");
+ String result = _dynamicBrokerSelectorUnderTest.selectBroker("db1.table1");
+ assertEquals("broker1", result);
+
+ Map<String, List<String>> tableToBrokerListMap = new HashMap<>();
+ tableToBrokerListMap.put("table1", Collections.singletonList("broker1"));
+ tableToBrokerListMap.put("db1.table1",
Collections.singletonList("broker2"));
+
when(_mockExternalViewReader.getTableToBrokersMap()).thenReturn(tableToBrokerListMap);
+ _dynamicBrokerSelectorUnderTest.handleDataChange("dataPath", "data");
+ result = _dynamicBrokerSelectorUnderTest.selectBroker("db1.table1");
+ assertEquals("broker2", result);
+ }
+
@Test
public void testSelectBrokerForNullTable() {
_dynamicBrokerSelectorUnderTest.handleDataChange("dataPath", "data");
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]