Skip to content

Commit 5e09cc3

Browse files
authored
Merge pull request #218 from oceanbase/region_metrics
Implement Admin Region metrics
2 parents 4b563a8 + 7fbe894 commit 5e09cc3

15 files changed

+1899
-18
lines changed

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ public OHTable(Configuration configuration, String tableName) throws IOException
220220
DEFAULT_HBASE_HTABLE_THREAD_KEEP_ALIVE_TIME);
221221
this.executePool = createDefaultThreadPoolExecutor(1, maxThreads, keepAliveTime);
222222
OHConnectionConfiguration ohConnectionConf = new OHConnectionConfiguration(configuration);
223-
int numRetries = configuration.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
224-
HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
223+
int numRetries = ohConnectionConf.getNumRetries();
225224
this.obTableClient = ObTableClientManager.getOrCreateObTableClient(setUserDefinedNamespace(
226225
this.tableNameString, ohConnectionConf));
227226
this.obTableClient.setRpcExecuteTimeout(ohConnectionConf.getRpcTimeout());
@@ -273,8 +272,7 @@ public OHTable(Configuration configuration, final byte[] tableName,
273272
this.executePool = executePool;
274273
this.cleanupPoolOnClose = false;
275274
OHConnectionConfiguration ohConnectionConf = new OHConnectionConfiguration(configuration);
276-
int numRetries = configuration.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
277-
HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
275+
int numRetries = ohConnectionConf.getNumRetries();
278276
this.obTableClient = ObTableClientManager.getOrCreateObTableClient(setUserDefinedNamespace(
279277
this.tableNameString, ohConnectionConf));
280278
this.obTableClient.setRpcExecuteTimeout(ohConnectionConf.getRpcTimeout());
@@ -345,8 +343,7 @@ public OHTable(TableName tableName, Connection connection,
345343
DEFAULT_HBASE_HTABLE_PUT_WRITE_BUFFER_CHECK);
346344
this.writeBufferSize = connectionConfig.getWriteBufferSize();
347345
this.tableName = tableName.getName();
348-
int numRetries = configuration.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
349-
HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
346+
int numRetries = connectionConfig.getNumRetries();
350347
this.obTableClient = ObTableClientManager.getOrCreateObTableClient(setUserDefinedNamespace(
351348
this.tableNameString, connectionConfig));
352349
this.obTableClient.setRpcExecuteTimeout(rpcTimeout);
@@ -389,8 +386,7 @@ public OHTable(Connection connection, ObTableBuilderBase builder,
389386
this.putWriteBufferCheck = this.configuration.getInt(HBASE_HTABLE_PUT_WRITE_BUFFER_CHECK,
390387
DEFAULT_HBASE_HTABLE_PUT_WRITE_BUFFER_CHECK);
391388
this.writeBufferSize = connectionConfig.getWriteBufferSize();
392-
int numRetries = configuration.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
393-
HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
389+
int numRetries = connectionConfig.getNumRetries();
394390
this.obTableClient = ObTableClientManager.getOrCreateObTableClient(setUserDefinedNamespace(
395391
this.tableNameString, connectionConfig));
396392
this.obTableClient.setRpcExecuteTimeout(rpcTimeout);
@@ -462,7 +458,7 @@ private void finishSetUp() {
462458
WRITE_BUFFER_SIZE_DEFAULT);
463459
}
464460

465-
private OHConnectionConfiguration setUserDefinedNamespace(String tableNameString,
461+
public static OHConnectionConfiguration setUserDefinedNamespace(String tableNameString,
466462
OHConnectionConfiguration ohConnectionConf)
467463
throws IllegalArgumentException {
468464
if (tableNameString.indexOf(':') != -1) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.alipay.oceanbase.hbase.execute;
2+
3+
import com.alipay.oceanbase.rpc.ObTableClient;
4+
import com.alipay.oceanbase.rpc.exception.ObTableException;
5+
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
6+
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
7+
import com.alipay.oceanbase.rpc.table.ObTable;
8+
9+
import java.io.IOException;
10+
11+
public abstract class AbstractObTableMetaExecutor<T> implements ObTableMetaExecutor<T> {
12+
13+
@Override
14+
public T execute(ObTableClient client, ObTableMetaRequest request) throws IOException {
15+
if (request.getMetaType() != getMetaType()) {
16+
throw new IOException("Invalid meta type, expected " + getMetaType());
17+
}
18+
ObTable table = client.getRandomTable();
19+
ObTableMetaResponse response;
20+
try {
21+
response = (ObTableMetaResponse) client.executeWithRetry(
22+
table,
23+
request,
24+
null /*tableName*/
25+
);
26+
} catch (Exception e) {
27+
throw new IOException("Failed to execute request", e);
28+
}
29+
return parse(response);
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.alipay.oceanbase.hbase.execute;
2+
3+
import com.alipay.oceanbase.rpc.ObTableClient;
4+
import com.alipay.oceanbase.rpc.meta.ObTableMetaRequest;
5+
import com.alipay.oceanbase.rpc.meta.ObTableMetaResponse;
6+
import com.alipay.oceanbase.rpc.meta.ObTableRpcMetaType;
7+
8+
import java.io.IOException;
9+
10+
public interface ObTableMetaExecutor<T> {
11+
/**
12+
* 执行元数据请求
13+
* @param request 元数据请求
14+
* @return 解析后的元数据对象
15+
* @throws IOException 如果执行失败或解析失败
16+
*/
17+
T execute(ObTableClient client, ObTableMetaRequest request) throws IOException;
18+
19+
/**
20+
* 解析元数据响应, 用户需要重写
21+
* @param response 元数据响应
22+
* @return 解析后的元数据对象
23+
* @throws IOException 如果解析失败
24+
*/
25+
T parse(ObTableMetaResponse response) throws IOException;
26+
27+
/**
28+
* 获取元信息类型, 用户需要重写
29+
* @return 元信息类型
30+
*/
31+
ObTableRpcMetaType getMetaType() throws IOException;
32+
}

0 commit comments

Comments
 (0)