Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 53 additions & 20 deletions src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ public class LocationUtil {
private static final int TEMPLATE_PART_ID = -1;

// limit the size of get tableEntry location from remote each time
private static final int MAX_TABLET_NUMS_EPOCH = 300;
private static final int MAX_TABLET_NUMS_EPOCH = 300;
private static final int TABLE_ENTRY_LOCATION_REFRESH_THRESHOLD = 100;

private abstract static class TableEntryRefreshWithPriorityCallback<T> {
abstract T execute(ObServerAddr obServerAddr) throws ObTableEntryRefreshException;
Expand Down Expand Up @@ -745,10 +746,14 @@ private static TableEntry getTableEntryFromRemote(Connection connection, TableEn
}

if (ObGlobal.obVsnMajor() >= 4) {
// only set empty partitionEntry
ObPartitionEntry partitionEntry = new ObPartitionEntry();
tableEntry.setPartitionEntry(partitionEntry);
tableEntry.setRefreshTimeMills(System.currentTimeMillis());
// only set empty partitionEntry
if (tableEntry.getPartitionNum() <= TABLE_ENTRY_LOCATION_REFRESH_THRESHOLD) {
getTableEntryLocationFromRemote(connection, key, tableEntry);
} else {
ObPartitionEntry partitionEntry = new ObPartitionEntry();
tableEntry.setPartitionEntry(partitionEntry);
tableEntry.setRefreshTimeMills(System.currentTimeMillis());
}
} else {
// get location info
getTableEntryLocationFromRemote(connection, key, tableEntry);
Expand Down Expand Up @@ -915,6 +920,7 @@ public static TableEntry getTableEntryLocationFromRemote(Connection connection,
ps.setString(1, key.getTenantName());
ps.setString(2, key.getDatabaseName());
ps.setString(3, key.getTableName());
ps.setString(4, key.getTenantName());
rs = ps.executeQuery();
partitionEntry = getPartitionLocationFromResultSet(tableEntry, rs, partitionEntry);
} catch (Exception e) {
Expand Down Expand Up @@ -1279,28 +1285,55 @@ private static ObPartitionEntry getPartitionLocationFromResultSet(TableEntry tab
} else {
tabletLsIdMap.put(partitionId, INVALID_LS_ID); // non-partitioned table
}
ObPartitionLocationInfo partitionLocationInfo = partitionEntry
.getPartitionInfo(partitionId);
ObPartitionLocation location = partitionLocationInfo.getPartitionLocation();
if (location == null) {
partitionLocationInfo.rwLock.writeLock().lock();
try {
location = partitionLocationInfo.getPartitionLocation();
if (location == null) {
location = new ObPartitionLocation();
partitionLocationInfo.updateLocation(location, lsId);
}
} finally {
partitionLocationInfo.rwLock.writeLock().unlock();
}
}
if (!replica.isValid()) {
RUNTIME
.warn(format(
"Replica is invalid; continuing. Replica=%s, PartitionId/TabletId=%d, TableId=%d",
replica, partitionId, tableEntry.getTableId()));
continue;
}
location.addReplicaLocation(replica);

if (partitionLocationInfo.initialized.compareAndSet(false, true)) {
partitionLocationInfo.initializationLatch.countDown();
}
} else {
partitionId = rs.getLong("partition_id");
if (tableEntry.isPartitionTable()
&& null != tableEntry.getPartitionInfo().getSubPartDesc()) {
&& null != tableEntry.getPartitionInfo().getSubPartDesc()) {
partitionId = ObPartIdCalculator.getPartIdx(partitionId, tableEntry
.getPartitionInfo().getSubPartDesc().getPartNum());
.getPartitionInfo().getSubPartDesc().getPartNum());
}
}
if (!replica.isValid()) {
RUNTIME
.warn(format(
"replica is invalid, continue, replica=%s, partitionId/tabletId=%d, tableId=%d",
replica, partitionId, tableEntry.getTableId()));
continue;
}
ObPartitionLocation location = partitionLocation.get(partitionId);
if (!replica.isValid()) {
RUNTIME
.warn(format(
"replica is invalid, continue, replica=%s, partitionId/tabletId=%d, tableId=%d",
replica, partitionId, tableEntry.getTableId()));
continue;
}
ObPartitionLocation location = partitionLocation.get(partitionId);

if (location == null) {
location = new ObPartitionLocation();
partitionLocation.put(partitionId, location);
if (location == null) {
location = new ObPartitionLocation();
partitionLocation.put(partitionId, location);
}
location.addReplicaLocation(replica);
}
location.addReplicaLocation(replica);
}

if (ObGlobal.obVsnMajor() < 4) {
Expand Down