Skip to content

Commit 7e8f9ea

Browse files
committed
fix
1 parent 1eae5a4 commit 7e8f9ea

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObPartitionLocationInfo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.concurrent.CountDownLatch;
2121
import java.util.concurrent.atomic.AtomicBoolean;
22+
import java.util.concurrent.locks.ReentrantLock;
2223
import java.util.concurrent.locks.ReentrantReadWriteLock;
2324

2425
import static com.alipay.oceanbase.rpc.protocol.payload.Constants.OB_INVALID_ID;
@@ -31,7 +32,8 @@ public class ObPartitionLocationInfo {
3132
public AtomicBoolean initialized = new AtomicBoolean(false);
3233
public final CountDownLatch initializationLatch = new CountDownLatch(1);
3334

34-
35+
public ReentrantLock refreshLock = new ReentrantLock();
36+
3537
public ObPartitionLocation getPartitionLocation() {
3638
rwLock.readLock().lock();
3739
try {

0 commit comments

Comments
 (0)