Skip to content

Commit 942aec5

Browse files
committed
reset cached result in sync query init if need to refresh table meta; refresh tablet location in sync query and normal batch if needed
1 parent aab0f4a commit 942aec5

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ private Long[] getTabletsFromTableEntry(TableEntry tableEntry) {
603603
tablets = tableEntry.getPartitionInfo().getPartTabletIdMap().values()
604604
.toArray(new Long[0]);
605605
} else {
606-
tablets = new Long[1];
606+
tablets = new Long[]{0L};
607607
}
608608
return tablets;
609609
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,9 @@ protected ObPayload commonExecute(ObTableClient client, Logger logger,
250250
// if the tableEntry is not cached in this client, tableEntry will refresh meta information and its tablet-ls information
251251
// if the server has the capacity to distribute ls request, no need to refresh ls_id and so tablet location
252252
if (e instanceof ObTableNeedFetchMetaException) {
253-
client.getOrRefreshTableEntry(indexTableName, true);
254-
if (((ObTableNeedFetchMetaException) e).isNeedRefreshMetaAndLocation()
255-
&& !client.getServerCapacity().isSupportDistributedExecute()) {
256-
long tabletId = partIdWithIndex.getRight().getTabletId();
253+
TableEntry tableEntry = client.getOrRefreshTableEntry(indexTableName, true);
254+
if (((ObTableNeedFetchMetaException) e).isNeedRefreshMetaAndLocation()) {
255+
long tabletId = client.getTabletIdByPartId(tableEntry, partIdWithIndex.getLeft());
257256
client.refreshTableLocationByTabletId(indexTableName,
258257
tabletId);
259258
}
@@ -369,6 +368,7 @@ public boolean next() throws Exception {
369368

370369
} catch (Exception e) {
371370
if (e instanceof ObTableNeedFetchMetaException) {
371+
// TODO: need to skip over the partitions that have been scanned
372372
setExpectant(refreshPartition(tableQuery, tableName));
373373
// Reset the iterator to start over
374374
it = expectant.entrySet().iterator();
@@ -536,6 +536,13 @@ protected abstract Map<Long, ObPair<Long, ObTableParam>> refreshPartition(ObTabl
536536
String tableName)
537537
throws Exception;
538538

539+
540+
private void resetCachedResult() {
541+
cacheRows.clear();
542+
cacheProperties.clear();
543+
partitionLastResult.clear();
544+
}
545+
539546
protected void cacheResultRows(ObTableQueryResult tableQueryResult) {
540547
cacheRows.addAll(tableQueryResult.getPropertiesRows());
541548
cacheProperties = tableQueryResult.getPropertiesNames();
@@ -604,6 +611,7 @@ public void init() throws Exception {
604611
referToNewPartition(entry.getValue());
605612
} catch (Exception e) {
606613
if (e instanceof ObTableNeedFetchMetaException) {
614+
resetCachedResult();
607615
setExpectant(refreshPartition(tableQuery, tableName));
608616
it = expectant.entrySet().iterator();
609617
retryTimes++;

src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientBatchOpsImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableOperation>>>>
267267
ObTableParam tableParam = obTableClient.getTableParamWithRoute(
268268
tableName, row, obTableClient.getRoute(batchOperation.isReadOnly()));
269269
ObPair<ObTableParam, List<ObPair<Integer, ObTableOperation>>> obTableOperations = partitionOperationsMap
270-
.computeIfAbsent(tableParam.getTabletId(), k -> new ObPair<>(
270+
.computeIfAbsent(tableParam.getPartId(), k -> new ObPair<>(
271271
tableParam, new ArrayList<>()));
272272
obTableOperations.getRight().add(new ObPair<>(i, operation));
273273
}
@@ -420,7 +420,11 @@ public void partitionExecute(ObTableOperationResult[] results,
420420
if (obTableClient.isRetryOnChangeMasterTimes()) {
421421
if (ex instanceof ObTableNeedFetchMetaException) {
422422
// refresh table info
423-
obTableClient.getOrRefreshTableEntry(tableName, true);
423+
TableEntry entry = obTableClient.getOrRefreshTableEntry(tableName, true);
424+
if (((ObTableNeedFetchMetaException) ex).isNeedRefreshMetaAndLocation()) {
425+
long tabletId = obTableClient.getTabletIdByPartId(entry, originPartId);
426+
obTableClient.refreshTableLocationByTabletId(tableName, tabletId);
427+
}
424428
throw ex;
425429
}
426430
} else {

0 commit comments

Comments
 (0)