Skip to content

Commit

Permalink
[Chore] format
Browse files Browse the repository at this point in the history
  • Loading branch information
IHEII committed Jan 8, 2024
1 parent 959f552 commit e71320a
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 136 deletions.
36 changes: 19 additions & 17 deletions src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,8 @@ public void syncRefreshMetadata() throws Exception {
* @param scanRangeColumns columns that need to be scaned
* @return the real table name
*/
public String getIndexTableName(final String dataTableName, final String indexName, List<String> scanRangeColumns)
throws Exception {
public String getIndexTableName(final String dataTableName, final String indexName,
List<String> scanRangeColumns) throws Exception {
String indexTableName = dataTableName;
if (indexName != null && !indexName.isEmpty() && !indexName.equalsIgnoreCase("PRIMARY")) {
String tmpTableName = constructIndexTableName(dataTableName, indexName);
Expand All @@ -925,27 +925,29 @@ public String getIndexTableName(final String dataTableName, final String indexNa
if (indexInfo.getIndexType().isGlobalIndex()) {
indexTableName = tmpTableName;
if (scanRangeColumns.isEmpty()) {
throw new ObTableException("query by global index need add all index keys in order");
throw new ObTableException(
"query by global index need add all index keys in order");
} else {
addRowKeyElement(indexTableName, scanRangeColumns.toArray(new String[scanRangeColumns.size()]));
addRowKeyElement(indexTableName,
scanRangeColumns.toArray(new String[scanRangeColumns.size()]));
}
}
}
return indexTableName;
}

public String constructIndexTableName(final String dataTableName, final String indexName)
throws Exception {
throws Exception {
// construct index table name
TableEntry entry = tableLocations.get(dataTableName);
Long dataTableId = null;
try {
if (entry == null) {
ObServerAddr addr = serverRoster.getServer(serverAddressPriorityTimeout,
serverAddressCachingTimeout);
serverAddressCachingTimeout);
dataTableId = LocationUtil.getTableIdFromRemote(addr, sysUA,
tableEntryAcquireConnectTimeout, tableEntryAcquireSocketTimeout, tenantName,
database, dataTableName);
tableEntryAcquireConnectTimeout, tableEntryAcquireSocketTimeout, tenantName,
database, dataTableName);
} else {
dataTableId = entry.getTableId();
}
Expand All @@ -957,7 +959,7 @@ public String constructIndexTableName(final String dataTableName, final String i
}

public ObIndexInfo getOrRefreshIndexInfo(final String indexName, final String indexTableName)
throws Exception {
throws Exception {
ObIndexInfo indexInfo = indexinfos.get(indexName);
if (indexInfo != null) {
return indexInfo;
Expand All @@ -968,8 +970,8 @@ public ObIndexInfo getOrRefreshIndexInfo(final String indexName, final String in
boolean acquired = lock.tryLock(tableEntryRefreshLockTimeout, TimeUnit.MILLISECONDS);
if (!acquired) {
String errMsg = "try to lock index infos refreshing timeout " + "dataSource:"
+ dataSourceName + " ,indexName:" + indexName + " , timeout:"
+ tableEntryRefreshLockTimeout + ".";
+ dataSourceName + " ,indexName:" + indexName + " , timeout:"
+ tableEntryRefreshLockTimeout + ".";
RUNTIME.error(errMsg);
throw new ObTableEntryRefreshException(errMsg);
}
Expand All @@ -979,21 +981,21 @@ public ObIndexInfo getOrRefreshIndexInfo(final String indexName, final String in
return indexInfo;
} else {
logger.info("index info is not exist, create new index info, indexName: {}",
indexName);
indexName);
int serverSize = serverRoster.getMembers().size();
int refreshTryTimes = tableEntryRefreshTryTimes > serverSize ? serverSize
: tableEntryRefreshTryTimes;
: tableEntryRefreshTryTimes;
for (int i = 0; i < refreshTryTimes; i++) {
ObServerAddr serverAddr = serverRoster.getServer(serverAddressPriorityTimeout,
serverAddressCachingTimeout);
serverAddressCachingTimeout);
indexInfo = getIndexInfoFromRemote(serverAddr, sysUA,
tableEntryAcquireConnectTimeout, tableEntryAcquireSocketTimeout,
indexTableName);
tableEntryAcquireConnectTimeout, tableEntryAcquireSocketTimeout,
indexTableName);
if (indexInfo != null) {
indexinfos.put(indexName, indexInfo);
} else {
RUNTIME.error("get index info from remote is null, index name: {}",
indexName);
indexName);
}
}
return indexInfo;
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public class LocationUtil {

private static final String OB_VERSION_SQL = "SELECT /*+READ_CONSISTENCY(WEAK)*/ OB_VERSION() AS CLUSTER_VERSION;";

private static final String PROXY_INDEX_INFO_SQL = "SELECT /*+READ_CONSISTENCY(WEAK)*/ data_table_id, table_id, index_type FROM oceanbase.__all_virtual_table " +
"where table_name = ?";
private static final String PROXY_INDEX_INFO_SQL = "SELECT /*+READ_CONSISTENCY(WEAK)*/ data_table_id, table_id, index_type FROM oceanbase.__all_virtual_table "
+ "where table_name = ?";

private static final String PROXY_TABLE_ID_SQL = "SELECT /*+READ_CONSISTENCY(WEAK)*/ table_id from oceanbase.__all_virtual_proxy_schema " +
"where tenant_name = ? and database_name = ? and table_name = ? limit 1";
private static final String PROXY_TABLE_ID_SQL = "SELECT /*+READ_CONSISTENCY(WEAK)*/ table_id from oceanbase.__all_virtual_proxy_schema "
+ "where tenant_name = ? and database_name = ? and table_name = ? limit 1";

private static final String OB_TENANT_EXIST_SQL = "SELECT /*+READ_CONSISTENCY(WEAK)*/ tenant_id from __all_tenant where tenant_name = ?;";

Expand Down Expand Up @@ -688,8 +688,9 @@ public static TableEntry getTableEntryLocationFromRemote(Connection connection,
}

public static Long getTableIdFromRemote(ObServerAddr obServerAddr, ObUserAuth sysUA,
long connectTimeout, long socketTimeout, String tenantName,
String databaseName, String tableName) throws ObTableEntryRefreshException {
long connectTimeout, long socketTimeout,
String tenantName, String databaseName, String tableName)
throws ObTableEntryRefreshException {
Long tableId = null;
Connection connection = null;
PreparedStatement ps = null;
Expand All @@ -706,11 +707,11 @@ public static Long getTableIdFromRemote(ObServerAddr obServerAddr, ObUserAuth sy
tableId = rs.getLong("table_id");
} else {
throw new ObTableEntryRefreshException("fail to get " + tableName
+ " table_id from remote");
+ " table_id from remote");
}
} catch (Exception e) {
throw new ObTableEntryRefreshException("fail to get " + tableName
+ " table_id from remote", e);
+ " table_id from remote", e);
} finally {
try {
if (null != rs) {
Expand All @@ -729,7 +730,7 @@ public static Long getTableIdFromRemote(ObServerAddr obServerAddr, ObUserAuth sy
public static ObIndexInfo getIndexInfoFromRemote(ObServerAddr obServerAddr, ObUserAuth sysUA,
long connectTimeout, long socketTimeout,
String indexTableName)
throws ObTableEntryRefreshException {
throws ObTableEntryRefreshException {
ObIndexInfo indexInfo = null;
Connection connection = null;
PreparedStatement ps = null;
Expand All @@ -746,10 +747,12 @@ public static ObIndexInfo getIndexInfoFromRemote(ObServerAddr obServerAddr, ObUs
indexInfo.setIndexTableId(rs.getLong("table_id"));
indexInfo.setIndexType(ObIndexType.valueOf(rs.getInt("index_type")));
} else {
throw new ObTableEntryRefreshException("fail to get index info from remote, result set is empty");
throw new ObTableEntryRefreshException(
"fail to get index info from remote, result set is empty");
}
} catch (Exception e) {
throw new ObTableEntryRefreshException(format("fail to get index info from remote, indexTableName: %s", indexTableName), e);
throw new ObTableEntryRefreshException(format(
"fail to get index info from remote, indexTableName: %s", indexTableName), e);
} finally {
try {
if (null != rs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public void setIndexType(ObIndexType indexType) {
@Override
public String toString() {
return "ObIndexInfo{" + "dataTableId=" + dataTableId + ", indexTableId=" + indexTableId
+ ", indexTableName=" + indexTableName + ", indexType=" + indexType + '}';
+ ", indexTableName=" + indexTableName + ", indexType=" + indexType + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@
import java.util.Map;

public enum ObIndexType {
IndexTypeIsNot(0), IndexTypeNormalLocal(1), IndexTypeUniqueLocal(2), IndexTypeNormalGlobal(3),
IndexTypeUniqueGlobal(4), IndexTypePrimary(5), IndexTypeDomainCtxcat(6), IndexTypeNormalGlobalLocalStorage(7),
IndexTypeUniqueGlobalLocalStorage(8), IndexTypeSpatialLocal(10), IndexTypeSpatialGlobal(11),
IndexTypeSpatialGlobalLocalStorage(12), IndexTypeMax(13);
IndexTypeIsNot(0), IndexTypeNormalLocal(1), IndexTypeUniqueLocal(2), IndexTypeNormalGlobal(3), IndexTypeUniqueGlobal(
4), IndexTypePrimary(
5), IndexTypeDomainCtxcat(
6), IndexTypeNormalGlobalLocalStorage(
7), IndexTypeUniqueGlobalLocalStorage(
8), IndexTypeSpatialLocal(
10), IndexTypeSpatialGlobal(
11), IndexTypeSpatialGlobalLocalStorage(
12), IndexTypeMax(
13);

private int value;
private static Map<Integer, ObIndexType> map = new HashMap<Integer, ObIndexType>();
Expand Down Expand Up @@ -62,7 +68,7 @@ public byte getByteValue() {

public boolean isGlobalIndex() {
return valueOf(value) == ObIndexType.IndexTypeNormalGlobal
|| valueOf(value) == ObIndexType.IndexTypeUniqueGlobal
|| valueOf(value) == ObIndexType.IndexTypeSpatialGlobal;
|| valueOf(value) == ObIndexType.IndexTypeUniqueGlobal
|| valueOf(value) == ObIndexType.IndexTypeSpatialGlobal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public Map<Long, ObPair<Long, ObTableParam>> getPartitions() throws Exception {
String indexName = tableQuery.getIndexName();
String indexTableName = tableName;
if (!this.obTableClient.isOdpMode()) {
indexTableName = obTableClient.getIndexTableName(tableName, indexName, tableQuery.getScanRangeColumns());
indexTableName = obTableClient.getIndexTableName(tableName, indexName,
tableQuery.getScanRangeColumns());
}

this.partitionObTables = new HashMap<Long, ObPair<Long, ObTableParam>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public ObTableClientQueryStreamResult executeInternal() throws Exception {
String indexName = tableQuery.getIndexName();
String indexTableName = tableName;
if (!this.obTableClient.isOdpMode()) {
indexTableName = obTableClient.getIndexTableName(tableName, indexName, tableQuery.getScanRangeColumns());
indexTableName = obTableClient.getIndexTableName(tableName, indexName,
tableQuery.getScanRangeColumns());
}

for (ObNewRange rang : tableQuery.getKeyRanges()) {
Expand All @@ -162,8 +163,8 @@ public ObTableClientQueryStreamResult executeInternal() throws Exception {
}
ObBorderFlag borderFlag = rang.getBorderFlag();
List<ObPair<Long, ObTableParam>> pairs = obTableClient.getTables(indexTableName,
start, borderFlag.isInclusiveStart(), end, borderFlag.isInclusiveEnd(), false,
false, obTableClient.getReadRoute());
start, borderFlag.isInclusiveStart(), end, borderFlag.isInclusiveEnd(), false,
false, obTableClient.getReadRoute());
for (ObPair<Long, ObTableParam> pair : pairs) {
partitionObTables.put(pair.getLeft(), pair);
}
Expand Down
Loading

0 comments on commit e71320a

Please sign in to comment.