@@ -1373,26 +1373,68 @@ public TableEntry refreshTableLocationByTabletId(TableEntry tableEntry, String t
13731373 if (tableEntry == null ) {
13741374 throw new ObTableEntryRefreshException ("Table entry is null, tableName=" + tableName );
13751375 }
1376- long lastRefreshTime = tableEntry .getPartitionEntry ().getPartitionInfo (tabletId ).getLastUpdateTime ();
1376+
1377+ ObPartitionLocationInfo info = tableEntry .getPartitionEntry ().getPartitionInfo (tabletId );
1378+ if (info == null ) {
1379+ throw new ObTableEntryRefreshException ("Partition info is null for tabletId=" + tabletId );
1380+ }
1381+
1382+ long lastRefreshTime = info .getLastUpdateTime ();
13771383 long currentTime = System .currentTimeMillis ();
13781384 if (currentTime - lastRefreshTime < tableEntryRefreshIntervalCeiling ) {
13791385 return tableEntry ;
13801386 }
1381- tableEntry = loadTableEntryLocationWithPriority (serverRoster , tableEntryKey , tableEntry , tabletId ,
1382- tableEntryAcquireConnectTimeout , tableEntryAcquireSocketTimeout ,
1383- serverAddressPriorityTimeout , serverAddressCachingTimeout , sysUA );
1387+
1388+ Lock lock = info .refreshLock ;
1389+ boolean acquired = false ;
1390+ try {
1391+ acquired = lock .tryLock (tableEntryRefreshLockTimeout , TimeUnit .MILLISECONDS );
1392+
1393+ if (!acquired ) {
1394+ String errMsg = String .format (
1395+ "Try to lock table location refreshing timeout. DataSource: %s, TableName: %s, Timeout: %dms." ,
1396+ dataSourceName , tableName , tableEntryRefreshLockTimeout );
1397+ RUNTIME .error (errMsg );
1398+ throw new ObTableEntryRefreshException (errMsg );
1399+ }
13841400
1385- tableEntry .prepareForWeakRead (serverRoster .getServerLdcLocation ());
1401+ // Double-check
1402+ lastRefreshTime = info .getLastUpdateTime ();
1403+ currentTime = System .currentTimeMillis ();
1404+ if (currentTime - lastRefreshTime < tableEntryRefreshIntervalCeiling ) {
1405+ return tableEntry ;
1406+ }
1407+
1408+ tableEntry = loadTableEntryLocationWithPriority (
1409+ serverRoster ,
1410+ tableEntryKey ,
1411+ tableEntry ,
1412+ tabletId ,
1413+ tableEntryAcquireConnectTimeout ,
1414+ tableEntryAcquireSocketTimeout ,
1415+ serverAddressPriorityTimeout ,
1416+ serverAddressCachingTimeout ,
1417+ sysUA
1418+ );
1419+
1420+ tableEntry .prepareForWeakRead (serverRoster .getServerLdcLocation ());
1421+
1422+ } finally {
1423+ if (acquired ) {
1424+ lock .unlock ();
1425+ }
1426+ }
13861427
13871428 } catch (ObTableNotExistException | ObTableServerCacheExpiredException e ) {
13881429 RUNTIME .error ("RefreshTableEntry encountered an exception" , e );
13891430 throw e ;
13901431 } catch (Exception e ) {
1391- String errorMsg = String .format ("Failed to get table entry. Key=%s, TabletId=%d, message=%s" , tableEntryKey , tabletId , e .getMessage ());
1432+ String errorMsg = String .format ("Failed to get table entry. Key=%s, TabletId=%d, message=%s" ,
1433+ tableEntryKey , tabletId , e .getMessage ());
13921434 RUNTIME .error (LCD .convert ("01-00020" ), tableEntryKey , tableEntry , e );
13931435 throw new ObTableEntryRefreshException (errorMsg , e );
13941436 }
1395-
1437+
13961438 tableLocations .put (tableName , tableEntry );
13971439 tableEntryRefreshContinuousFailureCount .set (0 );
13981440
0 commit comments