Skip to content

Commit 7a44795

Browse files
miyuan-ljrmaochongxin
authored andcommitted
fix 3.x null exception (#214)
* fix * fix regress
1 parent d51e6c6 commit 7a44795

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,14 +1839,20 @@ public ObPair<Long, ObTableParam> getTableInternal(String tableName, TableEntry
18391839
ObServerRoute route) throws Exception {
18401840
ReplicaLocation replica = null;
18411841
long tabletId = getTabletIdByPartId(tableEntry, partId);
1842+
long partitionId = partId;
18421843
ObPartitionLocationInfo obPartitionLocationInfo = null;
18431844
if (ObGlobal.obVsnMajor() >= 4) {
18441845

18451846
obPartitionLocationInfo = getOrRefreshPartitionInfo(tableEntry, tableName, tabletId);
18461847

18471848
replica = getPartitionLocation(obPartitionLocationInfo, route);
18481849
} else {
1849-
ObPair<Long, ReplicaLocation> partitionReplica = getPartitionReplica(tableEntry, partId,
1850+
if (tableEntry.isPartitionTable()
1851+
&& null != tableEntry.getPartitionInfo().getSubPartDesc()) {
1852+
partitionId = ObPartIdCalculator.getPartIdx(partId, tableEntry
1853+
.getPartitionInfo().getSubPartDesc().getPartNum());
1854+
}
1855+
ObPair<Long, ReplicaLocation> partitionReplica = getPartitionReplica(tableEntry, partitionId,
18501856
route);
18511857
replica = partitionReplica.getRight();
18521858
}
@@ -1871,7 +1877,7 @@ public ObPair<Long, ObTableParam> getTableInternal(String tableName, TableEntry
18711877
replica = getPartitionLocation(obPartitionLocationInfo, route);
18721878
} else {
18731879
tableEntry = getOrRefreshTableEntry(tableName, true, waitForRefresh, false);
1874-
replica = getPartitionReplica(tableEntry, partId, route).getRight();
1880+
replica = getPartitionReplica(tableEntry, partitionId, route).getRight();
18751881
}
18761882

18771883
addr = replica.getAddr();
@@ -1882,9 +1888,8 @@ public ObPair<Long, ObTableParam> getTableInternal(String tableName, TableEntry
18821888
throw new ObTableGetException("Cannot get table by addr: " + addr);
18831889
}
18841890
}
1885-
ObTableParam param = null;
1891+
ObTableParam param = createTableParam(obTable, tableEntry, obPartitionLocationInfo, partId, tabletId);
18861892
if (ObGlobal.obVsnMajor() >= 4) {
1887-
param = createTableParam(obTable, tableEntry, obPartitionLocationInfo, partId, tabletId);
18881893
} else {
18891894
param.setPartId(partId);
18901895
param.setTableId(tableEntry.getTableId());
@@ -1900,7 +1905,9 @@ private ObPartitionLocationInfo getOrRefreshPartitionInfo(TableEntry tableEntry,
19001905
ObPartitionLocationInfo obPartitionLocationInfo = tableEntry.getPartitionEntry()
19011906
.getPartitionInfo(tabletId);
19021907
if (!obPartitionLocationInfo.initialized.get()) {
1903-
tableEntry = refreshTableLocationByTabletId(tableEntry, tableName, tabletId);
1908+
if (ObGlobal.obVsnMajor() >= 4) {
1909+
tableEntry = refreshTableLocationByTabletId(tableEntry, tableName, tabletId);
1910+
}
19041911
obPartitionLocationInfo = tableEntry.getPartitionEntry().getPartitionInfo(tabletId);
19051912
obPartitionLocationInfo.initializationLatch.await();
19061913
}
@@ -1950,10 +1957,19 @@ private List<ObPair<Long, ReplicaLocation>> getPartitionReplica(TableEntry table
19501957
ObPartitionLevel partitionLevel = tableEntry.getPartitionInfo().getLevel();
19511958
List<Long> partIds = getPartitionTablePartitionIds(tableEntry, startRow, startIncluded, endRow, endIncluded, partitionLevel);
19521959

1953-
for (Long partId : partIds) {
1954-
long tabletId = getTabletIdByPartId(tableEntry, partId);
1955-
ObPartitionLocationInfo locationInfo = getOrRefreshPartitionInfo(tableEntry, tableName, tabletId);
1956-
replicas.add(new ObPair<>(tabletId, getPartitionLocation(locationInfo, route)));
1960+
if (ObGlobal.obVsnMajor() >= 4) {
1961+
for (Long partId : partIds) {
1962+
long tabletId = getTabletIdByPartId(tableEntry, partId);
1963+
ObPartitionLocationInfo locationInfo = getOrRefreshPartitionInfo(tableEntry, tableName, tabletId);
1964+
replicas.add(new ObPair<>(tabletId, getPartitionLocation(locationInfo, route)));
1965+
}
1966+
} else {
1967+
for (Long partId : partIds) {
1968+
long partitionId = ObPartIdCalculator.getPartIdx(partId, tableEntry
1969+
.getPartitionInfo().getSubPartDesc().getPartNum());
1970+
replicas.add(new ObPair<Long, ReplicaLocation>(partId, getPartitionLocation(
1971+
tableEntry, partitionId, route)));
1972+
}
19571973
}
19581974

19591975
return replicas;

src/main/java/com/alipay/oceanbase/rpc/protocol/payload/impl/execute/query/AbstractQueryStreamResult.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ protected ObPayload commonExecute(ObTableClient client, Logger logger,
235235
}
236236
} else if (e instanceof ObTableException) {
237237
if ((((ObTableException) e).getErrorCode() == ResultCodes.OB_TABLE_NOT_EXIST.errorCode || ((ObTableException) e)
238-
.getErrorCode() == ResultCodes.OB_NOT_SUPPORTED.errorCode)
239-
&& ((request instanceof ObTableQueryAsyncRequest && ((ObTableQueryAsyncRequest) request).getObTableQueryRequest().getTableQuery().isHbaseQuery())
240-
|| (request instanceof ObTableQueryRequest && ((ObTableQueryRequest) request).getTableQuery().isHbaseQuery()))
241-
&& client.getTableGroupInverted().get(indexTableName) != null) {
238+
.getErrorCode() == ResultCodes.OB_NOT_SUPPORTED.errorCode)
239+
&& ((request instanceof ObTableQueryAsyncRequest && ((ObTableQueryAsyncRequest) request).getObTableQueryRequest().getTableQuery().isHbaseQuery())
240+
|| (request instanceof ObTableQueryRequest && ((ObTableQueryRequest) request).getTableQuery().isHbaseQuery()))
241+
&& client.getTableGroupInverted().get(indexTableName) != null) {
242242
// table not exists && hbase mode && table group exists , three condition both
243243
client.eraseTableGroupFromCache(tableName);
244244
}

0 commit comments

Comments
 (0)