@@ -213,7 +213,8 @@ public class LocationUtil {
213213 private static final int TEMPLATE_PART_ID = -1 ;
214214
215215 // limit the size of get tableEntry location from remote each time
216- private static final int MAX_TABLET_NUMS_EPOCH = 300 ;
216+ private static final int MAX_TABLET_NUMS_EPOCH = 300 ;
217+ private static final int TABLE_ENTRY_LOCATION_REFRESH_THRESHOLD = 100 ;
217218
218219 private abstract static class TableEntryRefreshWithPriorityCallback <T > {
219220 abstract T execute (ObServerAddr obServerAddr ) throws ObTableEntryRefreshException ;
@@ -745,10 +746,14 @@ private static TableEntry getTableEntryFromRemote(Connection connection, TableEn
745746 }
746747
747748 if (ObGlobal .obVsnMajor () >= 4 ) {
748- // only set empty partitionEntry
749- ObPartitionEntry partitionEntry = new ObPartitionEntry ();
750- tableEntry .setPartitionEntry (partitionEntry );
751- tableEntry .setRefreshTimeMills (System .currentTimeMillis ());
749+ // only set empty partitionEntry
750+ if (tableEntry .getPartitionNum () <= TABLE_ENTRY_LOCATION_REFRESH_THRESHOLD ) {
751+ getTableEntryLocationFromRemote (connection , key , tableEntry );
752+ } else {
753+ ObPartitionEntry partitionEntry = new ObPartitionEntry ();
754+ tableEntry .setPartitionEntry (partitionEntry );
755+ tableEntry .setRefreshTimeMills (System .currentTimeMillis ());
756+ }
752757 } else {
753758 // get location info
754759 getTableEntryLocationFromRemote (connection , key , tableEntry );
@@ -915,6 +920,7 @@ public static TableEntry getTableEntryLocationFromRemote(Connection connection,
915920 ps .setString (1 , key .getTenantName ());
916921 ps .setString (2 , key .getDatabaseName ());
917922 ps .setString (3 , key .getTableName ());
923+ ps .setString (4 , key .getTenantName ());
918924 rs = ps .executeQuery ();
919925 partitionEntry = getPartitionLocationFromResultSet (tableEntry , rs , partitionEntry );
920926 } catch (Exception e ) {
@@ -1279,28 +1285,55 @@ private static ObPartitionEntry getPartitionLocationFromResultSet(TableEntry tab
12791285 } else {
12801286 tabletLsIdMap .put (partitionId , INVALID_LS_ID ); // non-partitioned table
12811287 }
1288+ ObPartitionLocationInfo partitionLocationInfo = partitionEntry
1289+ .getPartitionInfo (partitionId );
1290+ ObPartitionLocation location = partitionLocationInfo .getPartitionLocation ();
1291+ if (location == null ) {
1292+ partitionLocationInfo .rwLock .writeLock ().lock ();
1293+ try {
1294+ location = partitionLocationInfo .getPartitionLocation ();
1295+ if (location == null ) {
1296+ location = new ObPartitionLocation ();
1297+ partitionLocationInfo .updateLocation (location , lsId );
1298+ }
1299+ } finally {
1300+ partitionLocationInfo .rwLock .writeLock ().unlock ();
1301+ }
1302+ }
1303+ if (!replica .isValid ()) {
1304+ RUNTIME
1305+ .warn (format (
1306+ "Replica is invalid; continuing. Replica=%s, PartitionId/TabletId=%d, TableId=%d" ,
1307+ replica , partitionId , tableEntry .getTableId ()));
1308+ continue ;
1309+ }
1310+ location .addReplicaLocation (replica );
1311+
1312+ if (partitionLocationInfo .initialized .compareAndSet (false , true )) {
1313+ partitionLocationInfo .initializationLatch .countDown ();
1314+ }
12821315 } else {
12831316 partitionId = rs .getLong ("partition_id" );
12841317 if (tableEntry .isPartitionTable ()
1285- && null != tableEntry .getPartitionInfo ().getSubPartDesc ()) {
1318+ && null != tableEntry .getPartitionInfo ().getSubPartDesc ()) {
12861319 partitionId = ObPartIdCalculator .getPartIdx (partitionId , tableEntry
1287- .getPartitionInfo ().getSubPartDesc ().getPartNum ());
1320+ .getPartitionInfo ().getSubPartDesc ().getPartNum ());
12881321 }
1289- }
1290- if (!replica .isValid ()) {
1291- RUNTIME
1292- .warn (format (
1293- "replica is invalid, continue, replica=%s, partitionId/tabletId=%d, tableId=%d" ,
1294- replica , partitionId , tableEntry .getTableId ()));
1295- continue ;
1296- }
1297- ObPartitionLocation location = partitionLocation .get (partitionId );
1322+ if (!replica .isValid ()) {
1323+ RUNTIME
1324+ .warn (format (
1325+ "replica is invalid, continue, replica=%s, partitionId/tabletId=%d, tableId=%d" ,
1326+ replica , partitionId , tableEntry .getTableId ()));
1327+ continue ;
1328+ }
1329+ ObPartitionLocation location = partitionLocation .get (partitionId );
12981330
1299- if (location == null ) {
1300- location = new ObPartitionLocation ();
1301- partitionLocation .put (partitionId , location );
1331+ if (location == null ) {
1332+ location = new ObPartitionLocation ();
1333+ partitionLocation .put (partitionId , location );
1334+ }
1335+ location .addReplicaLocation (replica );
13021336 }
1303- location .addReplicaLocation (replica );
13041337 }
13051338
13061339 if (ObGlobal .obVsnMajor () < 4 ) {
0 commit comments