@@ -669,7 +669,9 @@ private <T> T execute(String tableName, OperationExecuteCallback<T> callback,
669669 throw new IllegalArgumentException ("table name is null" );
670670 }
671671 int tryTimes = 0 ;
672+ long routeQueryTabletId = INVALID_TABLET_ID ;
672673 boolean needRefreshPartitionLocation = false ;
674+ boolean refreshedTableMeta = false ;
673675 long startExecute = System .currentTimeMillis ();
674676 while (true ) {
675677 checkStatus ();
@@ -705,13 +707,19 @@ private <T> T execute(String tableName, OperationExecuteCallback<T> callback,
705707 } else if (null != callback .getQuery ()) {
706708 if (tryTimes > 1 && needRefreshPartitionLocation ) {
707709 needRefreshPartitionLocation = false ;
708- boolean isHKV = callback .getQuery ().getEntityType () == ObTableEntityType .HKV ;
709- tableRoute .refreshTabletLocationForAtomicQuery (tableName , callback .getQuery ().getObTableQuery (), isHKV );
710+ if (refreshedTableMeta ) {
711+ refreshedTableMeta = false ;
712+ boolean isHKV = callback .getQuery ().getEntityType () == ObTableEntityType .HKV ;
713+ tableRoute .refreshTabletLocationForAtomicQuery (tableName , callback .getQuery ().getObTableQuery (), isHKV );
714+ } else {
715+ tableRoute .refreshPartitionLocation (tableName , routeQueryTabletId , null );
716+ }
710717 }
711718 ObTableQuery tableQuery = callback .getQuery ().getObTableQuery ();
712719 // using scan range
713720 tableParam = tableRoute .getTableParam (tableName , tableQuery .getScanRangeColumns (),
714721 tableQuery .getKeyRanges ());
722+ routeQueryTabletId = tableParam .getPartitionId ();
715723 } else {
716724 throw new ObTableException ("RowKey or scan range is null" );
717725 }
@@ -770,6 +778,7 @@ private <T> T execute(String tableName, OperationExecuteCallback<T> callback,
770778 ((ObTableException ) ex ).getErrorCode (), ex .getMessage (),
771779 tryTimes );
772780 tableRoute .refreshMeta (tableName );
781+ refreshedTableMeta = true ;
773782 // reset failure count while fetch all route info
774783 this .resetExecuteContinuousFailureCount (tableName );
775784 } else if (((ObTableException ) ex ).isNeedRetryError ()) {
@@ -2286,6 +2295,8 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
22862295 }
22872296 int tryTimes = 0 ;
22882297 boolean needRefreshTabletLocation = false ;
2298+ boolean refreshedTableMeta = false ;
2299+ long routeTabletId = INVALID_TABLET_ID ;
22892300 long startExecute = System .currentTimeMillis ();
22902301 while (true ) {
22912302 long currentExecute = System .currentTimeMillis ();
@@ -2309,8 +2320,14 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
23092320 // Recalculate partIdMapObTable
23102321 if (needRefreshTabletLocation ) {
23112322 needRefreshTabletLocation = false ;
2312- boolean isHKV = request .getEntityType () == ObTableEntityType .HKV ;
2313- tableRoute .refreshTabletLocationForAtomicQuery (request .getTableName (), tableQuery , isHKV );
2323+ if (refreshedTableMeta ) {
2324+ refreshedTableMeta = false ;
2325+ // need to recalculate routing tablet_id and refresh location
2326+ boolean isHKV = request .getEntityType () == ObTableEntityType .HKV ;
2327+ tableRoute .refreshTabletLocationForAtomicQuery (request .getTableName (), tableQuery , isHKV );
2328+ } else {
2329+ tableRoute .refreshPartitionLocation (request .getTableName (), routeTabletId , null );
2330+ }
23142331 }
23152332 Map <Long , ObTableParam > partIdMapObTable = tableRoute .getPartIdParamMapForQuery (
23162333 request .getTableName (), tableQuery .getScanRangeColumns (),
@@ -2327,6 +2344,7 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
23272344 ObTableParam tableParam = entry .getValue ();
23282345 request .setTableId (tableParam .getTableId ());
23292346 long partitionId = isDistributedExecuteSupported ? INVALID_TABLET_ID : tableParam .getPartitionId ();
2347+ routeTabletId = tableParam .getPartitionId ();
23302348 request .setPartitionId (partitionId );
23312349 request .setTimeout (tableParam .getObTable ().getObTableOperationTimeout ());
23322350 ObTable obTable = tableParam .getObTable ();
@@ -2360,19 +2378,20 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E
23602378 (((ObTableException ) ex ).isNeedRefreshTableEntry () || ((ObTableException ) ex ).isNeedRetryError ())) {
23612379 logger .warn (
23622380 "tablename:{} partition id:{} batch ops refresh table while meet ObTableMasterChangeException, errorCode: {}" ,
2363- request .getTableName (), request . getPartitionId () , ((ObTableException ) ex ).getErrorCode (), ex );
2381+ request .getTableName (), routeTabletId , ((ObTableException ) ex ).getErrorCode (), ex );
23642382
23652383 if (isRetryOnChangeMasterTimes ()) {
23662384 logger .warn (
23672385 "tablename:{} partition id:{} batch ops retry while meet ObTableMasterChangeException, errorCode: {} , retry times {}" ,
2368- request .getTableName (), request . getPartitionId () , ((ObTableException ) ex ).getErrorCode (),
2386+ request .getTableName (), routeTabletId , ((ObTableException ) ex ).getErrorCode (),
23692387 tryTimes , ex );
23702388
23712389 if (((ObTableException ) ex ).isNeedRefreshTableEntry ()) {
23722390 needRefreshTabletLocation = true ;
23732391 if (ex instanceof ObTableNeedFetchMetaException ) {
23742392 // Refresh table info
23752393 tableRoute .refreshMeta (request .getTableName ());
2394+ refreshedTableMeta = true ;
23762395 }
23772396 }
23782397 } else {
0 commit comments