2121import com .alipay .oceanbase .rpc .ObTableClient ;
2222import com .alipay .oceanbase .rpc .exception .FeatureNotSupportedException ;
2323import com .alipay .oceanbase .rpc .exception .ObTableException ;
24+ import com .alipay .oceanbase .rpc .exception .ObTableNotExistException ;
25+ import com .alipay .oceanbase .rpc .exception .ObTableUnexpectedException ;
2426import com .alipay .oceanbase .rpc .location .model .partition .ObPair ;
2527import com .alipay .oceanbase .rpc .mutation .Row ;
2628import com .alipay .oceanbase .rpc .protocol .payload .ObPayload ;
@@ -133,12 +135,13 @@ public void checkArgumentBeforeExec() throws Exception {
133135 throw new IllegalArgumentException ("table name is null" );
134136 } else if (tableQuery .isFTSQuery ()) {
135137 if (!ObGlobal .isFtsQuerySupport ()) {
136- throw new FeatureNotSupportedException ("full text query is not supported in " +ObGlobal .obVsnString ());
138+ throw new FeatureNotSupportedException ("full text query is not supported in "
139+ + ObGlobal .obVsnString ());
137140 }
138141 if (tableQuery .getIndexName () == null || tableQuery .getIndexName ().isEmpty ()
139- || tableQuery .getIndexName ().equalsIgnoreCase ("primary" )) {
142+ || tableQuery .getIndexName ().equalsIgnoreCase ("primary" )) {
140143 throw new IllegalArgumentException (
141- "use fulltext search but specified index name is not fulltext index" );
144+ "use fulltext search but specified index name is not fulltext index" );
142145 }
143146 }
144147 }
@@ -176,31 +179,27 @@ private AbstractQueryStreamResult commonExecute(InitQueryResultCallback<Abstract
176179 if (obTableClient .isOdpMode ()) {
177180 if (tableQuery .getScanRangeColumns ().isEmpty ()) {
178181 if (tableQuery .getIndexName () != null
179- && !tableQuery .getIndexName ().equalsIgnoreCase ("primary" ) && !tableQuery .isFTSQuery ()) {
182+ && !tableQuery .getIndexName ().equalsIgnoreCase ("primary" )
183+ && !tableQuery .isFTSQuery ()) {
180184 throw new ObTableException ("key range columns must be specified when use index" );
181185 }
182186 }
183- if (getPartId () != null && tableQuery . getIndexName () == null ) {
184- String realTableName = tableName ;
187+ if (entityType != ObTableEntityType . HKV && getPartId () != null
188+ && tableQuery . getIndexName () == null ) {
185189 try {
186- if (this .entityType == ObTableEntityType .HKV
187- && obTableClient .isTableGroupName (tableName )) {
188- indexTableName = obTableClient .tryGetTableNameFromTableGroupCache (tableName ,
189- false );
190- realTableName = indexTableName ;
191- }
192190 ObPair <Long , ObTableParam > odpTable = obTableClient .getODPTableWithPartId (
193- realTableName , getPartId (), false );
191+ tableName , getPartId (), false );
194192 partitionObTables .put (odpTable .getLeft (), odpTable );
195193 } catch (Exception e ) {
196194 if (e instanceof ObTableException ) {
197195 if (((ObTableException ) e ).getErrorCode () == ResultCodes .OB_NOT_SUPPORTED .errorCode ) {
198196 // current ODP version does not support get partition meta information
199- throw new FeatureNotSupportedException ("current ODP version does not support query with part id" , e );
197+ throw new FeatureNotSupportedException (
198+ "current ODP version does not support query with part id" , e );
200199 } else if (((ObTableException ) e ).getErrorCode () == ResultCodes .OB_ERR_KV_ROUTE_ENTRY_EXPIRE .errorCode ) {
201200 // retry one time with force-renew flag
202- ObPair <Long , ObTableParam > odpTable = obTableClient . getODPTableWithPartId (
203- realTableName , getPartId (), true );
201+ ObPair <Long , ObTableParam > odpTable = obTableClient
202+ . getODPTableWithPartId ( tableName , getPartId (), true );
204203 partitionObTables .put (odpTable .getLeft (), odpTable );
205204 } else {
206205 throw e ;
@@ -211,7 +210,7 @@ private AbstractQueryStreamResult commonExecute(InitQueryResultCallback<Abstract
211210 }
212211 } else {
213212 partitionObTables .put (0L , new ObPair <Long , ObTableParam >(0L , new ObTableParam (
214- obTableClient .getOdpTable ())));
213+ obTableClient .getOdpTable ())));
215214 }
216215 } else {
217216 if (getPartId () == null ) {
@@ -224,9 +223,26 @@ private AbstractQueryStreamResult commonExecute(InitQueryResultCallback<Abstract
224223 indexTableName = obTableClient .tryGetTableNameFromTableGroupCache (tableName ,
225224 false );
226225 }
227- ObPair <Long , ObTableParam > table = obTableClient .getTableWithPartId (indexTableName ,
228- getPartId (), false , false , false , obTableClient .getRoute (false ));
229- partitionObTables .put (table .getLeft (), table );
226+ try {
227+ ObPair <Long , ObTableParam > table = obTableClient .getTableWithPartId (
228+ indexTableName , getPartId (), false , false , false ,
229+ obTableClient .getRoute (false ));
230+ partitionObTables .put (table .getLeft (), table );
231+ } catch (ObTableNotExistException e ) {
232+ if (this .entityType == ObTableEntityType .HKV
233+ && obTableClient .isTableGroupName (tableName )
234+ && obTableClient .getTableGroupInverted ().get (indexTableName ) != null ) {
235+ obTableClient .eraseTableGroupFromCache (indexTableName );
236+ indexTableName = obTableClient .tryGetTableNameFromTableGroupCache (
237+ tableName , true );
238+ ObPair <Long , ObTableParam > table = obTableClient .getTableWithPartId (
239+ indexTableName , getPartId (), false , false , false ,
240+ obTableClient .getRoute (false ));
241+ partitionObTables .put (table .getLeft (), table );
242+ } else {
243+ throw e ;
244+ }
245+ }
230246 }
231247 }
232248
@@ -318,8 +334,22 @@ public Map<Long, ObPair<Long, ObTableParam>> initPartitions(ObTableQuery tableQu
318334 }
319335 ObBorderFlag borderFlag = range .getBorderFlag ();
320336 // pairs -> List<Pair<logicId, param>>
321- List <ObPair <Long , ObTableParam >> pairs = this .obTableClient .getTables (indexTableName , tableQuery , start ,
322- borderFlag .isInclusiveStart (), end , borderFlag .isInclusiveEnd (), false , false );
337+ List <ObPair <Long , ObTableParam >> pairs = null ;
338+ try {
339+ pairs = this .obTableClient .getTables (indexTableName , tableQuery , start ,
340+ borderFlag .isInclusiveStart (), end , borderFlag .isInclusiveEnd (), false , false );
341+ } catch (ObTableNotExistException e ) {
342+ if (this .entityType == ObTableEntityType .HKV
343+ && obTableClient .isTableGroupName (tableName )
344+ && obTableClient .getTableGroupInverted ().get (indexTableName ) != null ) {
345+ obTableClient .eraseTableGroupFromCache (indexTableName );
346+ indexTableName = obTableClient .tryGetTableNameFromTableGroupCache (tableName , true );
347+ pairs = this .obTableClient .getTables (indexTableName , tableQuery , start ,
348+ borderFlag .isInclusiveStart (), end , borderFlag .isInclusiveEnd (), false , false );
349+ } else {
350+ throw e ;
351+ }
352+ }
323353 if (tableQuery .getScanOrder () == ObScanOrder .Reverse ) {
324354 for (int i = pairs .size () - 1 ; i >= 0 ; i --) {
325355 partitionObTables .put (pairs .get (i ).getLeft (), pairs .get (i ));
0 commit comments