Skip to content

Commit 07c37aa

Browse files
authored
fix 3.x null exception (#214)
* fix * fix regress
1 parent 6d00f65 commit 07c37aa

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

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

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.alipay.oceanbase.rpc.mutation.*;
2828
import com.alipay.oceanbase.rpc.protocol.payload.ObPayload;
2929
import com.alipay.oceanbase.rpc.protocol.payload.Pcodes;
30+
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
3031
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObRowKey;
3132
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.*;
3233
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.aggregation.ObTableAggregation;
@@ -1829,14 +1830,20 @@ public ObPair<Long, ObTableParam> getTableInternal(String tableName, TableEntry
18291830
ObServerRoute route) throws Exception {
18301831
ReplicaLocation replica = null;
18311832
long tabletId = getTabletIdByPartId(tableEntry, partId);
1833+
long partitionId = partId;
18321834
ObPartitionLocationInfo obPartitionLocationInfo = null;
18331835
if (ObGlobal.obVsnMajor() >= 4) {
18341836

18351837
obPartitionLocationInfo = getOrRefreshPartitionInfo(tableEntry, tableName, tabletId);
18361838

18371839
replica = getPartitionLocation(obPartitionLocationInfo, route);
18381840
} else {
1839-
ObPair<Long, ReplicaLocation> partitionReplica = getPartitionReplica(tableEntry, partId,
1841+
if (tableEntry.isPartitionTable()
1842+
&& null != tableEntry.getPartitionInfo().getSubPartDesc()) {
1843+
partitionId = ObPartIdCalculator.getPartIdx(partId, tableEntry
1844+
.getPartitionInfo().getSubPartDesc().getPartNum());
1845+
}
1846+
ObPair<Long, ReplicaLocation> partitionReplica = getPartitionReplica(tableEntry, partitionId,
18401847
route);
18411848
replica = partitionReplica.getRight();
18421849
}
@@ -1861,7 +1868,7 @@ public ObPair<Long, ObTableParam> getTableInternal(String tableName, TableEntry
18611868
replica = getPartitionLocation(obPartitionLocationInfo, route);
18621869
} else {
18631870
tableEntry = getOrRefreshTableEntry(tableName, true, waitForRefresh, false);
1864-
replica = getPartitionReplica(tableEntry, partId, route).getRight();
1871+
replica = getPartitionReplica(tableEntry, partitionId, route).getRight();
18651872
}
18661873

18671874
addr = replica.getAddr();
@@ -1872,9 +1879,8 @@ public ObPair<Long, ObTableParam> getTableInternal(String tableName, TableEntry
18721879
throw new ObTableGetException("Cannot get table by addr: " + addr);
18731880
}
18741881
}
1875-
ObTableParam param = null;
1882+
ObTableParam param = createTableParam(obTable, tableEntry, obPartitionLocationInfo, partId, tabletId);
18761883
if (ObGlobal.obVsnMajor() >= 4) {
1877-
param = createTableParam(obTable, tableEntry, obPartitionLocationInfo, partId, tabletId);
18781884
} else {
18791885
param.setPartId(partId);
18801886
param.setTableId(tableEntry.getTableId());
@@ -1890,7 +1896,9 @@ private ObPartitionLocationInfo getOrRefreshPartitionInfo(TableEntry tableEntry,
18901896
ObPartitionLocationInfo obPartitionLocationInfo = tableEntry.getPartitionEntry()
18911897
.getPartitionInfo(tabletId);
18921898
if (!obPartitionLocationInfo.initialized.get()) {
1893-
tableEntry = refreshTableLocationByTabletId(tableEntry, tableName, tabletId);
1899+
if (ObGlobal.obVsnMajor() >= 4) {
1900+
tableEntry = refreshTableLocationByTabletId(tableEntry, tableName, tabletId);
1901+
}
18941902
obPartitionLocationInfo = tableEntry.getPartitionEntry().getPartitionInfo(tabletId);
18951903
obPartitionLocationInfo.initializationLatch.await();
18961904
}
@@ -1940,10 +1948,19 @@ private List<ObPair<Long, ReplicaLocation>> getPartitionReplica(TableEntry table
19401948
ObPartitionLevel partitionLevel = tableEntry.getPartitionInfo().getLevel();
19411949
List<Long> partIds = getPartitionTablePartitionIds(tableEntry, startRow, startIncluded, endRow, endIncluded, partitionLevel);
19421950

1943-
for (Long partId : partIds) {
1944-
long tabletId = getTabletIdByPartId(tableEntry, partId);
1945-
ObPartitionLocationInfo locationInfo = getOrRefreshPartitionInfo(tableEntry, tableName, tabletId);
1946-
replicas.add(new ObPair<>(tabletId, getPartitionLocation(locationInfo, route)));
1951+
if (ObGlobal.obVsnMajor() >= 4) {
1952+
for (Long partId : partIds) {
1953+
long tabletId = getTabletIdByPartId(tableEntry, partId);
1954+
ObPartitionLocationInfo locationInfo = getOrRefreshPartitionInfo(tableEntry, tableName, tabletId);
1955+
replicas.add(new ObPair<>(tabletId, getPartitionLocation(locationInfo, route)));
1956+
}
1957+
} else {
1958+
for (Long partId : partIds) {
1959+
long partitionId = ObPartIdCalculator.getPartIdx(partId, tableEntry
1960+
.getPartitionInfo().getSubPartDesc().getPartNum());
1961+
replicas.add(new ObPair<Long, ReplicaLocation>(partId, getPartitionLocation(
1962+
tableEntry, partitionId, route)));
1963+
}
19471964
}
19481965

19491966
return replicas;
@@ -3136,7 +3153,7 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
31363153
request.setTimeout(getOdpTable().getObTableOperationTimeout());
31373154
return getOdpTable().execute(request);
31383155
} else {
3139-
int maxRetries = getRuntimeRetryTimes(); // Define the maximum number of retries
3156+
int maxRetries = getRuntimeRetryTimes(); // Define the maximum number of retries
31403157
int tryTimes = 0;
31413158
long startExecute = System.currentTimeMillis();
31423159
boolean needRefreshTableEntry = false;
@@ -3158,7 +3175,7 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
31583175
try {
31593176
// Recalculate partIdMapObTable
31603177
// Clear the map before recalculating
3161-
partIdMapObTable.clear();
3178+
partIdMapObTable.clear();
31623179
for (ObNewRange rang : tableQuery.getKeyRanges()) {
31633180
ObRowKey startKey = rang.getStartKey();
31643181
int startKeySize = startKey.getObjs().size();
@@ -3167,11 +3184,21 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
31673184
Object[] start = new Object[startKeySize];
31683185
Object[] end = new Object[endKeySize];
31693186
for (int i = 0; i < startKeySize; i++) {
3170-
start[i] = startKey.getObj(i).getValue();
3187+
ObObj curStart = startKey.getObj(i);
3188+
if (curStart.isMinObj()) {
3189+
start[i] = curStart;
3190+
} else {
3191+
start[i] = curStart.getValue();
3192+
}
31713193
}
31723194

31733195
for (int i = 0; i < endKeySize; i++) {
3174-
end[i] = endKey.getObj(i).getValue();
3196+
ObObj curEnd = endKey.getObj(i);
3197+
if (curEnd.isMaxObj()) {
3198+
end[i] = curEnd;
3199+
} else {
3200+
end[i] = curEnd.getValue();
3201+
}
31753202
}
31763203
ObBorderFlag borderFlag = rang.getBorderFlag();
31773204
List<ObPair<Long, ObTableParam>> pairList = getTables(request.getTableName(),
@@ -3182,7 +3209,7 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
31823209
}
31833210
}
31843211

3185-
// Check if partIdMapObTable size is greater than 1
3212+
// Check if partIdMapObTable size is greater than 1
31863213
if (partIdMapObTable.size() > 1) {
31873214
throw new ObTablePartitionConsistentException(
31883215
"query and mutate must be a atomic operation");
@@ -3195,7 +3222,7 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
31953222
request.setTimeout(tableParam.getObTable().getObTableOperationTimeout());
31963223
ObTable obTable = tableParam.getObTable();
31973224

3198-
// Attempt to execute the operation
3225+
// Attempt to execute the operation
31993226
return executeWithRetry(obTable, request, request.getTableName());
32003227
} catch (Exception ex) {
32013228
tryTimes++;
@@ -3212,7 +3239,7 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
32123239
tryTimes, ex);
32133240

32143241
if (ex instanceof ObTableNeedFetchAllException) {
3215-
// Refresh table info
3242+
// Refresh table info
32163243
getOrRefreshTableEntry(request.getTableName(), needRefreshTableEntry, isTableEntryRefreshIntervalWait(), true);
32173244
}
32183245
} else {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ protected ObPayload commonExecute(ObTableClient client, Logger logger,
232232
} else if (e instanceof ObTableException) {
233233
if ((((ObTableException) e).getErrorCode() == ResultCodes.OB_TABLE_NOT_EXIST.errorCode || ((ObTableException) e)
234234
.getErrorCode() == ResultCodes.OB_NOT_SUPPORTED.errorCode)
235-
&& ((ObTableQueryAsyncRequest) request).getObTableQueryRequest().getTableQuery().isHbaseQuery()
235+
&& ((request instanceof ObTableQueryAsyncRequest && ((ObTableQueryAsyncRequest) request).getObTableQueryRequest().getTableQuery().isHbaseQuery())
236+
|| (request instanceof ObTableQueryRequest && ((ObTableQueryRequest) request).getTableQuery().isHbaseQuery()))
236237
&& client.getTableGroupInverted().get(indexTableName) != null) {
237238
// table not exists && hbase mode && table group exists , three condition both
238239
client.eraseTableGroupFromCache(tableName);

0 commit comments

Comments
 (0)