Skip to content

Commit 7e2d35c

Browse files
committed
Add quick path: return quickly if recently refreshed
1 parent 1723dc7 commit 7e2d35c

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
@@ -47,6 +47,7 @@
4747

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

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

0 commit comments

Comments
 (0)