Skip to content

Commit 3669d6e

Browse files
committed
Add quick path: return quickly if recently refreshed
1 parent 6777826 commit 3669d6e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import static com.alipay.oceanbase.rpc.location.model.partition.ObPartitionKey.MAX_PARTITION_ELEMENT;
4848
import static com.alipay.oceanbase.rpc.location.model.partition.ObPartitionKey.MIN_PARTITION_ELEMENT;
49+
import static com.alipay.oceanbase.rpc.property.Property.TABLE_ENTRY_REFRESH_INTERVAL_CEILING;
4950
import static com.alipay.oceanbase.rpc.util.RandomUtil.getRandomNum;
5051
import static com.alipay.oceanbase.rpc.util.TableClientLoggerFactory.*;
5152
import static java.lang.String.format;
@@ -861,12 +862,19 @@ private static String genLocationSQLByOffset(TableEntry tableEntry, int offset,
861862

862863
public static TableEntry getTableEntryLocationFromRemote(Connection connection,
863864
TableEntryKey key,
864-
TableEntry tableEntry, Long tabletId)
865-
throws ObTablePartitionLocationRefreshException {
865+
TableEntry tableEntry,
866+
Long tabletId)
867+
throws ObTablePartitionLocationRefreshException {
866868
PreparedStatement ps = null;
867869
ResultSet rs = null;
868870
ObPartitionEntry partitionEntry = tableEntry.getPartitionEntry();
869871
String sql = genLocationSQLByTabletId();
872+
ObPartitionLocationInfo partitionLocationInfo = partitionEntry.getPartitionInfo(tabletId);
873+
// return quickly if recently refreshed
874+
if (System.currentTimeMillis() - partitionLocationInfo.getLastUpdateTime()
875+
< TABLE_ENTRY_REFRESH_INTERVAL_CEILING.getDefaultLong()) {
876+
return tableEntry;
877+
}
870878
try {
871879
ps = connection.prepareStatement(sql);
872880
ps.setString(1, key.getTenantName());

0 commit comments

Comments
 (0)