Skip to content

Commit 28b9dec

Browse files
authored
[Bugfix] fix bugs in getPartIds in Hash and Key (#194)
* merged all commits into one * correct reverse test * format code * check whether startRow and endRow contain the refColumn in Hash and Key part * keep the same format with ObHashPartDesc * bugfix getPartIds in HashPartDesc and KeyPartDesc * refactor getTable in ObTableClient * format code * remove useless params commments * uniform the interface about getting table meta information to getTable
1 parent 8b08b59 commit 28b9dec

File tree

7 files changed

+197
-66
lines changed

7 files changed

+197
-66
lines changed

src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,9 @@ private <T> T execute(String tableName, TableExecuteCallback<T> callback, ObServ
624624
if (odpMode) {
625625
obPair = new ObPair<Long, ObTableParam>(0L, new ObTableParam(odpTable));
626626
} else {
627-
obPair = getTable(tableName, callback.getRowKey(), needRefreshTableEntry,
628-
tableEntryRefreshIntervalWait, route);
627+
obPair = getTable(tableName, callback.getRowKey(),
628+
needRefreshTableEntry, tableEntryRefreshIntervalWait,
629+
needFetchAllRouteInfo, route);
629630
}
630631
T t = callback.execute(obPair);
631632
resetExecuteContinuousFailureCount(tableName);
@@ -787,12 +788,13 @@ private <T> T executeMutation(String tableName, MutationExecuteCallback<T> callb
787788
} else {
788789
if (null != callback.getRowKey()) {
789790
// using row key
790-
obPair = getTable(tableName, callback.getRowKey(), needRefreshTableEntry,
791-
tableEntryRefreshIntervalWait, route);
791+
obPair = getTable(tableName, callback.getRowKey(),
792+
needRefreshTableEntry, tableEntryRefreshIntervalWait,
793+
needFetchAllRouteInfo, route);
792794
} else if (null != callback.getKeyRanges()) {
793795
// using scan range
794-
obPair = getTable(tableName, new ObTableQuery(), callback.getKeyRanges(),
795-
needRefreshTableEntry, tableEntryRefreshIntervalWait, route);
796+
obPair = getTable(tableName, new ObTableQuery(),
797+
callback.getKeyRanges());
796798
} else {
797799
throw new ObTableException("rowkey and scan range are null in mutation");
798800
}
@@ -1548,8 +1550,9 @@ private ReplicaLocation getPartitionLocation(TableEntry tableEntry, long partId,
15481550
* @return ObPair of partId and table
15491551
* @throws Exception exception
15501552
*/
1551-
public ObPair<Long, ObTableParam> getTable(String tableName, Object[] rowKey, boolean refresh,
1552-
boolean waitForRefresh) throws Exception {
1553+
public ObPair<Long, ObTableParam> getTable(String tableName, Object[] rowKey,
1554+
boolean refresh, boolean waitForRefresh)
1555+
throws Exception {
15531556
ObServerRoute route = getRoute(false);
15541557
return getTable(tableName, rowKey, refresh, waitForRefresh, route);
15551558
}
@@ -1567,7 +1570,17 @@ public ObPair<Long, ObTableParam> getTable(String tableName, Object[] rowKey, bo
15671570
public ObPair<Long, ObTableParam> getTable(String tableName, Object[] rowKey, boolean refresh,
15681571
boolean waitForRefresh, ObServerRoute route)
15691572
throws Exception {
1570-
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh, false);
1573+
return getTable(tableName, rowKey, refresh, waitForRefresh, false, route);
1574+
}
1575+
1576+
private ObPair<Long, ObTableParam> getTable(String tableName, Object[] rowKey,
1577+
boolean refresh,
1578+
boolean waitForRefresh,
1579+
boolean needFetchAll,
1580+
ObServerRoute route)
1581+
throws Exception {
1582+
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh,
1583+
needFetchAll);
15711584
Row row = new Row();
15721585
if (tableEntry.isPartitionTable()
15731586
&& tableEntry.getPartitionInfo().getLevel() != ObPartitionLevel.LEVEL_ZERO) {
@@ -1599,14 +1612,10 @@ public ObPair<Long, ObTableParam> getTable(String tableName, Object[] rowKey, bo
15991612
* For mutation (queryWithFilter)
16001613
* @param tableName table want to get
16011614
* @param keyRanges key
1602-
* @param refresh whether to refresh
1603-
* @param waitForRefresh whether wait for refresh
1604-
* @param route ObServer route
16051615
* @return ObPair of partId and table
16061616
* @throws Exception exception
16071617
*/
1608-
public ObPair<Long, ObTableParam> getTable(String tableName, ObTableQuery query, List<ObNewRange> keyRanges, boolean refresh,
1609-
boolean waitForRefresh, ObServerRoute route)
1618+
public ObPair<Long, ObTableParam> getTable(String tableName, ObTableQuery query, List<ObNewRange> keyRanges)
16101619
throws Exception {
16111620
Map<Long, ObTableParam> partIdMapObTable = new HashMap<Long, ObTableParam>();
16121621
for (ObNewRange rang : keyRanges) {
@@ -1655,9 +1664,12 @@ public ObPair<Long, ObTableParam> getTable(String tableName, ObTableQuery query,
16551664
* @return ObPair of partId and table
16561665
* @throws Exception exception
16571666
*/
1658-
public ObPair<Long, ObTableParam> getTable(String tableName, Row rowKey, boolean refresh,
1659-
boolean waitForRefresh) throws Exception {
1660-
return getTable(tableName, rowKey, refresh, waitForRefresh, getRoute(false));
1667+
public ObPair<Long, ObTableParam> getTable(String tableName, Row rowKey,
1668+
boolean refresh,
1669+
boolean waitForRefresh)
1670+
throws Exception {
1671+
return getTable(tableName, rowKey, refresh, waitForRefresh, false,
1672+
getRoute(false));
16611673
}
16621674

16631675
/**
@@ -1666,16 +1678,21 @@ public ObPair<Long, ObTableParam> getTable(String tableName, Row rowKey, boolean
16661678
* @param rowKey row key with column names
16671679
* @param refresh whether to refresh
16681680
* @param waitForRefresh whether wait for refresh
1681+
* @param needFetchAll whether to fetch all
16691682
* @param route ObServer route
16701683
* @return ObPair of partId and table
16711684
* @throws Exception exception
16721685
*/
1673-
public ObPair<Long, ObTableParam> getTable(String tableName, Row rowKey, boolean refresh,
1674-
boolean waitForRefresh, ObServerRoute route)
1675-
throws Exception {
1676-
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh, false);
1677-
long partId;
1678-
partId = getPartition(tableEntry, rowKey); // partition id in 3.x, origin partId in 4.x, logicId
1686+
private ObPair<Long, ObTableParam> getTable(String tableName,
1687+
Row rowKey,
1688+
boolean refresh,
1689+
boolean waitForRefresh,
1690+
boolean needFetchAll,
1691+
ObServerRoute route)
1692+
throws Exception {
1693+
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh,
1694+
needFetchAll);
1695+
long partId = getPartition(tableEntry, rowKey); // partition id in 3.x, origin partId in 4.x, logicId
16791696

16801697
return getTableInternal(tableName, tableEntry, partId, waitForRefresh, route);
16811698
}

src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDesc.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
import org.apache.commons.lang.builder.ToStringBuilder;
3030
import org.slf4j.Logger;
3131

32-
import java.util.ArrayList;
33-
import java.util.Arrays;
34-
import java.util.Collections;
35-
import java.util.List;
32+
import java.util.*;
3633

3734
import static com.alipay.oceanbase.rpc.util.TableClientLoggerFactory.LCD;
3835

@@ -130,15 +127,28 @@ public List<Long> getPartIds(Object startRowObj, boolean startInclusive, Object
130127
throw new IllegalArgumentException("rowkey length is " + startRow.size()
131128
+ ", which is shortest than " + refIdx);
132129
}
133-
Object startValue = startRow.get(curObRefColumnName);
130+
Object startValue = null;
131+
for (Map.Entry<String, Object> entry : startRow.getMap().entrySet()) {
132+
if (entry.getKey().equalsIgnoreCase(curObRefColumnName)) {
133+
startValue = entry.getValue();
134+
break;
135+
}
136+
}
134137
if (startValue == null) {
135138
throw new IllegalArgumentException("Please include all partition key in start range. Currently missing key: { " + curObRefColumnName + " }");
136139
}
137140
if (startValue instanceof ObObj
138141
&& (((ObObj) startValue).isMinObj() || ((ObObj) startValue).isMaxObj())) {
139142
return completeWorks;
140143
}
141-
Object endValue = endRow.get(curObRefColumnName);
144+
145+
Object endValue = null;
146+
for (Map.Entry<String, Object> entry : endRow.getMap().entrySet()) {
147+
if (entry.getKey().equalsIgnoreCase(curObRefColumnName)) {
148+
endValue = entry.getValue();
149+
break;
150+
}
151+
}
142152
if (endValue == null) {
143153
throw new IllegalArgumentException("Please include all partition key in end range. Currently missing key: { " + curObRefColumnName + " }");
144154
}

src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObKeyPartDesc.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,28 @@ public List<Long> getPartIds(Object startRowObj, boolean startInclusive, Object
116116
throw new IllegalArgumentException("rowkey length is " + startRow.size()
117117
+ ", which is shortest than " + refIdx);
118118
}
119-
Object startValue = startRow.get(curObRefColumnName);
119+
Object startValue = null;
120+
for (Map.Entry<String, Object> entry : startRow.getMap().entrySet()) {
121+
if (entry.getKey().equalsIgnoreCase(curObRefColumnName)) {
122+
startValue = entry.getValue();
123+
break;
124+
}
125+
}
120126
if (startValue == null) {
121127
throw new IllegalArgumentException("Please include all partition key in start range. Currently missing key: { " + curObRefColumnName + " }");
122128
}
123129
if (startValue instanceof ObObj
124130
&& (((ObObj) startValue).isMinObj() || ((ObObj) startValue).isMaxObj())) {
125131
return completeWorks;
126132
}
127-
Object endValue = endRow.get(curObRefColumnName);
133+
134+
Object endValue = null;
135+
for (Map.Entry<String, Object> entry : endRow.getMap().entrySet()) {
136+
if (entry.getKey().equalsIgnoreCase(curObRefColumnName)) {
137+
endValue = entry.getValue();
138+
break;
139+
}
140+
}
128141
if (endValue == null) {
129142
throw new IllegalArgumentException("Please include all partition key in end range. Currently missing key: { " + curObRefColumnName + " }");
130143
}

src/test/java/com/alipay/oceanbase/rpc/bolt/ObTableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void setup() throws Exception {
4848
throw new ObTableException("ODP Mode does not support this test");
4949
} else {
5050
obTable = obTableClient
51-
.getTable("test_varchar_table", new Object[] { "abc" }, true, true).getRight()
51+
.getTable("test_varchar_table", new Object[] { "abc" }, true, true, obTableClient.getRoute(false)).getRight()
5252
.getObTable();
5353
client = obTable;
5454
}

src/test/java/com/alipay/oceanbase/rpc/hbase/ObHTableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void setup() throws Exception {
5555
throw new ObTableException("ODP Mode does not support this test");
5656
} else {
5757
client = obTableClient
58-
.getTable("test_varchar_table", new Object[] { "abc" }, true, true).getRight()
58+
.getTable("test_varchar_table", new Object[] { "abc" }, true, true, obTableClient.getRoute(false)).getRight()
5959
.getObTable();
6060
this.obTableClient = obTableClient;
6161
}

0 commit comments

Comments
 (0)