Skip to content

Commit 98fb07c

Browse files
authored
Fix 431 version of ODP use normal get and throw error NOT_SUPPORT (#336)
* use odp interfaces and seperate from ocp mode to refresh meta * format code and optimize by review
1 parent d7ee23b commit 98fb07c

File tree

4 files changed

+207
-143
lines changed

4 files changed

+207
-143
lines changed

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

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ private <T> T execute(String tableName, TableExecuteCallback<T> callback, ObServ
457457
int tryTimes = 0;
458458
boolean needRefreshPartitionLocation = false;
459459
long startExecute = System.currentTimeMillis();
460-
Row rowKey = transformToRow(tableName, callback.getRowKey());
460+
Row rowKey = odpMode ? null : transformToRow(tableName, callback.getRowKey());
461461
while (true) {
462462
checkStatus();
463463
long currentExecute = System.currentTimeMillis();
@@ -946,7 +946,6 @@ public void setRpcExecuteTimeout(int rpcExecuteTimeout) {
946946

947947
/**
948948
* Get or refresh table entry meta information.
949-
* work for both OcpMode and OdpMode
950949
* @param tableName table name
951950
* @return TableEntry
952951
* @throws Exception if fail
@@ -962,15 +961,19 @@ public TableEntry getOrRefreshTableEntry(final String tableName, boolean forceRe
962961

963962
/**
964963
* refresh table meta information except location
965-
* work for both OcpMode and OdpMode
966964
* @param tableName table name
967965
* */
968966
private TableEntry refreshMeta(String tableName) throws Exception {
969-
if (odpMode) {
970-
return tableRoute.refreshODPMeta(tableName, true);
971-
} else {
972-
return tableRoute.refreshMeta(tableName);
973-
}
967+
return tableRoute.refreshMeta(tableName);
968+
}
969+
970+
/**
971+
* refresh table meta information except location
972+
* only support by ODP version after 4.3.2
973+
* @param tableName table name
974+
* */
975+
public TableEntry refreshOdpMeta(String tableName) throws Exception {
976+
return tableRoute.refreshOdpMeta(tableName, true);
974977
}
975978

976979
/**
@@ -1076,6 +1079,19 @@ public ObTableParam getTableParamWithPartId(String tableName, long partId, ObSer
10761079
return tableRoute.getTableWithPartId(tableName, partId, route);
10771080
}
10781081

1082+
/**
1083+
* get addr by pardId in ODP mode
1084+
* only support by ODP version after 4.3.2
1085+
* @param tableName table want to get
1086+
* @param partId logic of table
1087+
* @return ObPair of partId and table
1088+
* @throws Exception exception
1089+
*/
1090+
public ObTableParam getOdpTableParamWithPartId(String tableName, long partId)
1091+
throws Exception {
1092+
return tableRoute.getOdpTableWithPartId(tableName, partId);
1093+
}
1094+
10791095
/**
10801096
*
10811097
* @param moveResponse reRoute response
@@ -1910,14 +1926,17 @@ private Partition getSinglePartitionInternal(String tableName, Row rowKey, boole
19101926
addRowKeyElement(tableName, rowKey.getColumns());
19111927
}
19121928
ObTableParam tableParam = null;
1913-
if (refresh) {
1914-
if (odpMode) {
1915-
tableRoute.refreshODPMeta(tableName, true);
1916-
} else {
1929+
if (odpMode) {
1930+
if (refresh) {
1931+
tableRoute.refreshOdpMeta(tableName, true);
1932+
}
1933+
tableParam = tableRoute.getOdpTableParam(tableName, rowKey);
1934+
} else {
1935+
if (refresh) {
19171936
tableRoute.refreshMeta(tableName);
19181937
}
1938+
tableParam = tableRoute.getTableParam(tableName, rowKey);
19191939
}
1920-
tableParam = tableRoute.getTableParam(tableName, rowKey);
19211940
return new Partition(tableParam.getPartitionId(), tableParam.getPartId(),
19221941
tableParam.getTableId(), tableParam.getObTable().getIp(), tableParam.getObTable()
19231942
.getPort(), tableParam.getLsId());
@@ -1941,15 +1960,20 @@ public List<Partition> getPartition(String tableName, boolean refresh) throws Ex
19411960
*/
19421961
private List<Partition> getAllPartitionInternal(String tableName, boolean refresh) throws Exception {
19431962
List<Partition> partitions = new ArrayList<>();
1944-
if (refresh) {
1945-
if (odpMode) {
1946-
tableRoute.refreshODPMeta(tableName, true);
1947-
} else {
1963+
List<ObTableParam> allTables;
1964+
if (odpMode) {
1965+
if (refresh) {
1966+
tableRoute.refreshOdpMeta(tableName, true);
1967+
}
1968+
allTables = tableRoute.getOdpTableParams(tableName, new ObTableQuery(), new Object[]{ ObObj.getMin() }, true,
1969+
new Object[]{ ObObj.getMax() }, true);
1970+
} else {
1971+
if (refresh) {
19481972
tableRoute.refreshMeta(tableName);
19491973
}
1974+
allTables = tableRoute.getTableParams(tableName, new ObTableQuery(), new Object[]{ ObObj.getMin() }, true,
1975+
new Object[]{ ObObj.getMax() }, true);
19501976
}
1951-
List<ObTableParam> allTables = tableRoute.getTableParams(tableName, new ObTableQuery(), new Object[]{ ObObj.getMin() }, true,
1952-
new Object[]{ ObObj.getMax() }, true);
19531977
for (ObTableParam tableParam : allTables) {
19541978
Partition partition = new Partition(tableParam.getPartitionId(), tableParam.getPartId(), tableParam.getTableId(),
19551979
tableParam.getObTable().getIp(), tableParam.getObTable().getPort(), tableParam.getLsId());

src/main/java/com/alipay/oceanbase/rpc/location/model/TableLocations.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,14 @@ private long getTableLevelRefreshInterval(ServerRoster serverRoster) {
533533

534534
/**
535535
* fetch ODP partition meta information
536+
* only support by ODP version after 4.3.2
536537
* @param tableName table name to query
537538
* @param forceRefresh flag to force ODP to fetch the latest partition meta information
538539
* @param odpTable odp table to execute refreshing
539540
* @return TableEntry ODPTableEntry
540541
* @throws Exception Exception
541542
*/
542-
public TableEntry refreshODPMeta(String tableName, boolean forceRefresh, ObTable odpTable)
543+
public TableEntry refreshOdpMeta(String tableName, boolean forceRefresh, ObTable odpTable)
543544
throws Exception {
544545
if (tableName == null || tableName.isEmpty()) {
545546
throw new IllegalArgumentException("table name is null");

0 commit comments

Comments
 (0)