|
47 | 47 |
|
48 | 48 | import static com.alipay.oceanbase.rpc.location.model.partition.ObPartitionKey.MAX_PARTITION_ELEMENT; |
49 | 49 | import static com.alipay.oceanbase.rpc.location.model.partition.ObPartitionKey.MIN_PARTITION_ELEMENT; |
| 50 | +import static com.alipay.oceanbase.rpc.property.Property.TABLE_ENTRY_LOCATION_REFRESH_THRESHOLD; |
50 | 51 | import static com.alipay.oceanbase.rpc.util.RandomUtil.getRandomNum; |
51 | 52 | import static com.alipay.oceanbase.rpc.util.TableClientLoggerFactory.*; |
52 | 53 | import static java.lang.String.format; |
@@ -745,10 +746,14 @@ private static TableEntry getTableEntryFromRemote(Connection connection, TableEn |
745 | 746 | } |
746 | 747 |
|
747 | 748 | 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.getDefaultLong()) { |
| 751 | + getTableEntryLocationFromRemote(connection, key, tableEntry); |
| 752 | + } else { |
| 753 | + ObPartitionEntry partitionEntry = new ObPartitionEntry(); |
| 754 | + tableEntry.setPartitionEntry(partitionEntry); |
| 755 | + tableEntry.setRefreshTimeMills(System.currentTimeMillis()); |
| 756 | + } |
752 | 757 | } else { |
753 | 758 | // get location info |
754 | 759 | getTableEntryLocationFromRemote(connection, key, tableEntry); |
@@ -915,6 +920,7 @@ public static TableEntry getTableEntryLocationFromRemote(Connection connection, |
915 | 920 | ps.setString(1, key.getTenantName()); |
916 | 921 | ps.setString(2, key.getDatabaseName()); |
917 | 922 | ps.setString(3, key.getTableName()); |
| 923 | + ps.setString(4, key.getTenantName()); |
918 | 924 | rs = ps.executeQuery(); |
919 | 925 | partitionEntry = getPartitionLocationFromResultSet(tableEntry, rs, partitionEntry); |
920 | 926 | } catch (Exception e) { |
@@ -1279,28 +1285,55 @@ private static ObPartitionEntry getPartitionLocationFromResultSet(TableEntry tab |
1279 | 1285 | } else { |
1280 | 1286 | tabletLsIdMap.put(partitionId, INVALID_LS_ID); // non-partitioned table |
1281 | 1287 | } |
| 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 | + } |
1282 | 1315 | } else { |
1283 | 1316 | partitionId = rs.getLong("partition_id"); |
1284 | 1317 | if (tableEntry.isPartitionTable() |
1285 | | - && null != tableEntry.getPartitionInfo().getSubPartDesc()) { |
| 1318 | + && null != tableEntry.getPartitionInfo().getSubPartDesc()) { |
1286 | 1319 | partitionId = ObPartIdCalculator.getPartIdx(partitionId, tableEntry |
1287 | | - .getPartitionInfo().getSubPartDesc().getPartNum()); |
| 1320 | + .getPartitionInfo().getSubPartDesc().getPartNum()); |
1288 | 1321 | } |
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); |
1298 | 1330 |
|
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); |
1302 | 1336 | } |
1303 | | - location.addReplicaLocation(replica); |
1304 | 1337 | } |
1305 | 1338 |
|
1306 | 1339 | if (ObGlobal.obVsnMajor() < 4) { |
|
0 commit comments