Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,105 +32,13 @@ public class OHMetricsTracker {

public OHMetricsTracker(MetricsRegistry registry, String metricsName, OHOperationType opType) {
this.opType = opType;
// 使用通用占位类作为 type,表名作为 name,操作类型和指标名组合作为 scope
// 这样在 JMX 中路径会是:表名 -> 操作类型 -> 指标名
// newTimer(Class, name, scope) - name 是表名,scope 是 "操作类型.指标名"
// 生成的路径是: <class>.<表名>.<操作类型>.<指标名>
Class<?> metricsClass = getMetricsClassForOperation(opType);
String opTypeName = opType.name();
this.latencyHistogram = registry.newTimer(OHMetrics.class, opTypeName + ".latencyHistogram", metricsName);
// newMeter(Class, name, scope, TimeUnit) - name 是表名,scope 是 "操作类型.指标名"
this.failedOpCounter = registry.newMeter(OHMetrics.class, opTypeName + ".failedOpCounter", metricsName, "failedOpCounter", TimeUnit.MILLISECONDS);
// newCounter(Class, name, scope) - name 是表名,scope 是 "操作类型.指标名"
this.totalSingleOpCount = registry.newCounter(OHMetrics.class, opTypeName + ".totalSingleOpCount", metricsName);
this.failedOpCounter = registry.newMeter(OHMetrics.class,
opTypeName + ".failedOpCounter", metricsName, "failedOpCounter", TimeUnit.MILLISECONDS);
this.totalSingleOpCount = registry.newCounter(OHMetrics.class, opTypeName + ".totalSingleOpCount", metricsName);
this.totalRuntime = registry.newCounter(OHMetrics.class, opTypeName + ".totalRuntime", metricsName);
}


/**
* 为每个操作类型创建对应的内部类
* 这些类用于 JMX 注册,使路径为 com.alipay.oceanbase.hbase.metrics.<OPERATION_TYPE>
*/
public static class PUT {}
public static class DELETE {}
public static class GET {}
public static class GET_LIST {}
public static class SCAN {}
public static class APPEND {}
public static class INCREMENT {}
public static class INCREMENT_COLUMN_VALUE {}
public static class BATCH {}
public static class BATCH_CALLBACK {}
public static class PUT_LIST {}
public static class DELETE_LIST {}
public static class CHECK_AND_PUT {}
public static class CHECK_AND_DELETE {}
public static class CHECK_AND_MUTATE {}
public static class EXISTS {}
public static class EXISTS_LIST {}
public static class MUTATE_ROW {}

/**
* 通用占位类 - 用于未知的操作类型
*/
public static class OperationMetricsPlaceholder {}

/**
* 获取操作类型对应的类名(用于测试和调试)
* @param opType 操作类型
* @return 类名
*/
public static String getClassNameForOperation(OHOperationType opType) {
Class<?> clazz = getMetricsClassForOperation(opType);
return clazz.getName();
}

/**
* 获取操作类型对应的类(静态方法,供外部调用)
*/
private static Class<?> getMetricsClassForOperation(OHOperationType opType) {
switch (opType) {
case PUT:
return PUT.class;
case DELETE:
return DELETE.class;
case GET:
return GET.class;
case GET_LIST:
return GET_LIST.class;
case SCAN:
return SCAN.class;
case APPEND:
return APPEND.class;
case INCREMENT:
return INCREMENT.class;
case INCREMENT_COLUMN_VALUE:
return INCREMENT_COLUMN_VALUE.class;
case BATCH:
return BATCH.class;
case BATCH_CALLBACK:
return BATCH_CALLBACK.class;
case PUT_LIST:
return PUT_LIST.class;
case DELETE_LIST:
return DELETE_LIST.class;
case CHECK_AND_PUT:
return CHECK_AND_PUT.class;
case CHECK_AND_DELETE:
return CHECK_AND_DELETE.class;
case CHECK_AND_MUTATE:
return CHECK_AND_MUTATE.class;
case EXISTS:
return EXISTS.class;
case EXISTS_LIST:
return EXISTS_LIST.class;
case MUTATE_ROW:
return MUTATE_ROW.class;
default:
// 对于未知的操作类型,使用通用占位类
return OperationMetricsPlaceholder.class;
}
}

public OHOperationType getOpType() {
return this.opType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2903,7 +2903,7 @@ public void testGlobalConfigScan() throws Exception {
setZoneIdc(ZONE3, IDC3);
// 3. Scan不设置READ_CONSISTENCY属性,使用全局配置
Scan scan = new Scan();
scan.withStartRow(rowkey.getBytes());
scan.setStartRow(rowkey.getBytes());
// 不设置 READ_CONSISTENCY 属性
scan.addColumn(FAMILY_NAME.getBytes(), "c2".getBytes());
ResultScanner resultScanner = table.getScanner(scan);
Expand Down