feat(scheduler): 使用简化的table_meta加速查询
This commit is contained in:
@@ -6,7 +6,13 @@ import com.lanyuanxiaoyao.service.common.entity.TableMeta;
|
|||||||
import com.lanyuanxiaoyao.service.common.exception.ConfigException;
|
import com.lanyuanxiaoyao.service.common.exception.ConfigException;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +23,7 @@ import java.util.stream.Collectors;
|
|||||||
* @date 2021-12-01
|
* @date 2021-12-01
|
||||||
*/
|
*/
|
||||||
public class TableMetaHelper {
|
public class TableMetaHelper {
|
||||||
//private static final AES AES = new AES(Mode.CBC, Padding.NoPadding, "6fa22c779ec14b98".getBytes(), "6fa22c779ec14b98".getBytes());
|
// private static final AES AES = new AES(Mode.CBC, Padding.NoPadding, "6fa22c779ec14b98".getBytes(), "6fa22c779ec14b98".getBytes());
|
||||||
|
|
||||||
public static String tableMetaSql(String database) {
|
public static String tableMetaSql(String database) {
|
||||||
return tableMetaSql(database, true, false);
|
return tableMetaSql(database, true, false);
|
||||||
@@ -227,7 +233,7 @@ public class TableMetaHelper {
|
|||||||
public static List<TableMeta> from(ResultSet rs) throws SQLException {
|
public static List<TableMeta> from(ResultSet rs) throws SQLException {
|
||||||
List<TableMeta> results = new ArrayList<>();
|
List<TableMeta> results = new ArrayList<>();
|
||||||
List<TableMeta.RowMeta> metaList = new ArrayList<>();
|
List<TableMeta.RowMeta> metaList = new ArrayList<>();
|
||||||
while (rs.next( )) {
|
while (rs.next()) {
|
||||||
metaList.add(
|
metaList.add(
|
||||||
TableMeta.RowMeta.builder()
|
TableMeta.RowMeta.builder()
|
||||||
.dsName(rs.getString(1))
|
.dsName(rs.getString(1))
|
||||||
@@ -571,6 +577,14 @@ public class TableMetaHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean existsTag(TableMeta meta, String tag) {
|
public static boolean existsTag(TableMeta meta, String tag) {
|
||||||
return meta.getTags() != null && meta.getTags().contains(tag);
|
return existsTag(meta.getTags(), tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean existsTag(String sourceTags, String tag) {
|
||||||
|
return existsTag(Arrays.asList(sourceTags.split(",")), tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean existsTag(List<String> sourceTags, String tag) {
|
||||||
|
return sourceTags != null && sourceTags.contains(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,22 +12,30 @@ public class SimpleTableMeta {
|
|||||||
private String alias;
|
private String alias;
|
||||||
private String schema;
|
private String schema;
|
||||||
private String table;
|
private String table;
|
||||||
|
private Integer priority;
|
||||||
|
private String targetTableType;
|
||||||
private String targetDb;
|
private String targetDb;
|
||||||
private String targetTable;
|
private String targetTable;
|
||||||
private String targetHdfs;
|
private String targetHdfs;
|
||||||
|
private String tags;
|
||||||
|
private Integer bucketNumber;
|
||||||
|
|
||||||
public SimpleTableMeta() {
|
public SimpleTableMeta() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleTableMeta(Long flinkJobId, String flinkJobName, String alias, String schema, String table, String targetDb, String targetTable, String targetHdfs) {
|
public SimpleTableMeta(Long flinkJobId, String flinkJobName, String alias, String schema, String table, Integer priority, String targetTableType, String targetDb, String targetTable, String targetHdfs, String tags, Integer bucketNumber) {
|
||||||
this.flinkJobId = flinkJobId;
|
this.flinkJobId = flinkJobId;
|
||||||
this.flinkJobName = flinkJobName;
|
this.flinkJobName = flinkJobName;
|
||||||
this.alias = alias;
|
this.alias = alias;
|
||||||
this.schema = schema;
|
this.schema = schema;
|
||||||
this.table = table;
|
this.table = table;
|
||||||
|
this.priority = priority;
|
||||||
|
this.targetTableType = targetTableType;
|
||||||
this.targetDb = targetDb;
|
this.targetDb = targetDb;
|
||||||
this.targetTable = targetTable;
|
this.targetTable = targetTable;
|
||||||
this.targetHdfs = targetHdfs;
|
this.targetHdfs = targetHdfs;
|
||||||
|
this.tags = tags;
|
||||||
|
this.bucketNumber = bucketNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getFlinkJobId() {
|
public Long getFlinkJobId() {
|
||||||
@@ -50,6 +58,14 @@ public class SimpleTableMeta {
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getPriority() {
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetTableType() {
|
||||||
|
return targetTableType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTargetDb() {
|
public String getTargetDb() {
|
||||||
return targetDb;
|
return targetDb;
|
||||||
}
|
}
|
||||||
@@ -62,6 +78,14 @@ public class SimpleTableMeta {
|
|||||||
return targetHdfs;
|
return targetHdfs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTags() {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBucketNumber() {
|
||||||
|
return bucketNumber;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SimpleTableMeta{" +
|
return "SimpleTableMeta{" +
|
||||||
@@ -70,9 +94,13 @@ public class SimpleTableMeta {
|
|||||||
", alias='" + alias + '\'' +
|
", alias='" + alias + '\'' +
|
||||||
", schema='" + schema + '\'' +
|
", schema='" + schema + '\'' +
|
||||||
", table='" + table + '\'' +
|
", table='" + table + '\'' +
|
||||||
|
", priority=" + priority +
|
||||||
|
", targetTableType='" + targetTableType + '\'' +
|
||||||
", targetDb='" + targetDb + '\'' +
|
", targetDb='" + targetDb + '\'' +
|
||||||
", targetTable='" + targetTable + '\'' +
|
", targetTable='" + targetTable + '\'' +
|
||||||
", targetHdfs='" + targetHdfs + '\'' +
|
", targetHdfs='" + targetHdfs + '\'' +
|
||||||
|
", tags='" + tags + '\'' +
|
||||||
|
", bucketNumber=" + bucketNumber +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -593,9 +593,13 @@ public class TableMetaService extends BaseService {
|
|||||||
TbAppCollectTableInfo.ALIAS_A,
|
TbAppCollectTableInfo.ALIAS_A,
|
||||||
TbAppCollectTableInfo.SRC_SCHEMA_A,
|
TbAppCollectTableInfo.SRC_SCHEMA_A,
|
||||||
TbAppCollectTableInfo.SRC_TABLE_A,
|
TbAppCollectTableInfo.SRC_TABLE_A,
|
||||||
|
TbAppCollectTableInfo.PRIORITY_A,
|
||||||
|
TbAppCollectTableInfo.TGT_TABLE_TYPE_A,
|
||||||
TbAppCollectTableInfo.TGT_DB_A,
|
TbAppCollectTableInfo.TGT_DB_A,
|
||||||
TbAppCollectTableInfo.TGT_TABLE_A,
|
TbAppCollectTableInfo.TGT_TABLE_A,
|
||||||
TbAppCollectTableInfo.TGT_HDFS_PATH_A
|
TbAppCollectTableInfo.TGT_HDFS_PATH_A,
|
||||||
|
TbAppCollectTableInfo.TAGS_A,
|
||||||
|
TbAppCollectTableInfo.BUCKET_NUMBER_A
|
||||||
),
|
),
|
||||||
flinkJobId,
|
flinkJobId,
|
||||||
alias
|
alias
|
||||||
@@ -606,9 +610,13 @@ public class TableMetaService extends BaseService {
|
|||||||
rs.getString(3),
|
rs.getString(3),
|
||||||
rs.getString(4),
|
rs.getString(4),
|
||||||
rs.getString(5),
|
rs.getString(5),
|
||||||
rs.getString(6),
|
rs.getInt(6),
|
||||||
rs.getString(7),
|
rs.getString(7),
|
||||||
rs.getString(8)
|
rs.getString(8),
|
||||||
|
rs.getString(9),
|
||||||
|
rs.getString(10),
|
||||||
|
rs.getString(11),
|
||||||
|
rs.getInt(12)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public class ScheduleController {
|
|||||||
infoService,
|
infoService,
|
||||||
hudiService,
|
hudiService,
|
||||||
mapper,
|
mapper,
|
||||||
meta -> StrUtil.equals(meta.getAlias(), alias) && NumberUtil.equals(meta.getJob().getId(), flinkJobId),
|
meta -> StrUtil.equals(meta.getAlias(), alias) && NumberUtil.equals(meta.getFlinkJobId(), flinkJobId),
|
||||||
"Schedule manually",
|
"Schedule manually",
|
||||||
metadata.toImmutable()
|
metadata.toImmutable()
|
||||||
);
|
);
|
||||||
@@ -155,7 +155,7 @@ public class ScheduleController {
|
|||||||
infoService,
|
infoService,
|
||||||
hudiService,
|
hudiService,
|
||||||
mapper,
|
mapper,
|
||||||
meta -> keys.contains(StrUtil.format("{}-{}", meta.getJob().getId(), meta.getAlias())),
|
meta -> keys.contains(StrUtil.format("{}-{}", meta.getFlinkJobId(), meta.getAlias())),
|
||||||
"Schedule manually"
|
"Schedule manually"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class FocusUnVersionUpdateScheduleJob extends BaseScheduleJob {
|
|||||||
hudiService,
|
hudiService,
|
||||||
mapper,
|
mapper,
|
||||||
meta -> meta.getPriority() >= 10000
|
meta -> meta.getPriority() >= 10000
|
||||||
&& unUpdateVersionTableIds.contains(StrUtil.format("{}-{}", meta.getJob().getId(), meta.getAlias())),
|
&& unUpdateVersionTableIds.contains(StrUtil.format("{}-{}", meta.getFlinkJobId(), meta.getAlias())),
|
||||||
comment
|
comment
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class OdsFocusScheduleJob extends BaseScheduleJob {
|
|||||||
infoService,
|
infoService,
|
||||||
hudiService,
|
hudiService,
|
||||||
mapper,
|
mapper,
|
||||||
meta -> TableMetaHelper.existsTag(meta, Constants.TAGS_ODS_FOCUS),
|
meta -> TableMetaHelper.existsTag(meta.getTags(), Constants.TAGS_ODS_FOCUS),
|
||||||
comment
|
comment
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.github.loki4j.slf4j.marker.LabelMarker;
|
import com.github.loki4j.slf4j.marker.LabelMarker;
|
||||||
import com.lanyuanxiaoyao.service.common.Constants;
|
import com.lanyuanxiaoyao.service.common.Constants;
|
||||||
import com.lanyuanxiaoyao.service.common.entity.SyncState;
|
import com.lanyuanxiaoyao.service.common.entity.SyncState;
|
||||||
import com.lanyuanxiaoyao.service.common.entity.TableMeta;
|
|
||||||
import com.lanyuanxiaoyao.service.common.entity.compaction.ScheduleJob;
|
import com.lanyuanxiaoyao.service.common.entity.compaction.ScheduleJob;
|
||||||
import com.lanyuanxiaoyao.service.common.utils.TableMetaHelper;
|
import com.lanyuanxiaoyao.service.common.utils.TableMetaHelper;
|
||||||
import com.lanyuanxiaoyao.service.configuration.ExecutorProvider;
|
import com.lanyuanxiaoyao.service.configuration.ExecutorProvider;
|
||||||
|
import com.lanyuanxiaoyao.service.configuration.entity.info.SimpleTableMeta;
|
||||||
import com.lanyuanxiaoyao.service.configuration.entity.queue.QueueItem;
|
import com.lanyuanxiaoyao.service.configuration.entity.queue.QueueItem;
|
||||||
import com.lanyuanxiaoyao.service.configuration.utils.QueueUtil;
|
import com.lanyuanxiaoyao.service.configuration.utils.QueueUtil;
|
||||||
import com.lanyuanxiaoyao.service.forest.service.HudiService;
|
import com.lanyuanxiaoyao.service.forest.service.HudiService;
|
||||||
@@ -42,7 +42,7 @@ public class ScheduleHelper {
|
|||||||
InfoService infoService,
|
InfoService infoService,
|
||||||
HudiService hudiService,
|
HudiService hudiService,
|
||||||
ObjectMapper mapper,
|
ObjectMapper mapper,
|
||||||
Predicate<TableMeta> predicate,
|
Predicate<SimpleTableMeta> predicate,
|
||||||
String comment
|
String comment
|
||||||
) {
|
) {
|
||||||
schedule(discoveryClient, infoService, hudiService, mapper, predicate, comment, Maps.immutable.empty());
|
schedule(discoveryClient, infoService, hudiService, mapper, predicate, comment, Maps.immutable.empty());
|
||||||
@@ -53,57 +53,57 @@ public class ScheduleHelper {
|
|||||||
InfoService infoService,
|
InfoService infoService,
|
||||||
HudiService hudiService,
|
HudiService hudiService,
|
||||||
ObjectMapper mapper,
|
ObjectMapper mapper,
|
||||||
Predicate<TableMeta> predicate,
|
Predicate<SimpleTableMeta> predicate,
|
||||||
String comment,
|
String comment,
|
||||||
ImmutableMap<String, String> metadata
|
ImmutableMap<String, String> metadata
|
||||||
) {
|
) {
|
||||||
String batchId = IdUtil.nanoId(10);
|
String batchId = IdUtil.nanoId(10);
|
||||||
infoService.tableMetaList()
|
infoService.simpleTableMetas()
|
||||||
// 只调度 MOR 表
|
// 只调度 MOR 表
|
||||||
.select(meta -> StrUtil.equals(Constants.MOR, meta.getHudi().getTargetTableType()))
|
.select(meta -> StrUtil.equals(Constants.MOR, meta.getTargetTableType()))
|
||||||
.asParallel(ExecutorProvider.EXECUTORS, 1)
|
.asParallel(ExecutorProvider.EXECUTORS, 1)
|
||||||
.select(predicate::test)
|
.select(predicate::test)
|
||||||
// 没有 Hudi 表的过滤掉
|
// 没有 Hudi 表的过滤掉
|
||||||
.select(meta -> {
|
.select(meta -> {
|
||||||
try {
|
try {
|
||||||
return hudiService.existsHudiTable(meta.getJob().getId(), meta.getAlias());
|
return hudiService.existsHudiTable(meta.getFlinkJobId(), meta.getAlias());
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
logger.error(makeMarker(meta.getJob().getId(), meta.getAlias()), "Get hudi status failure", throwable);
|
logger.error(makeMarker(meta.getFlinkJobId(), meta.getAlias()), "Get hudi status failure", throwable);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
// 没有压缩计划的过滤掉
|
// 没有压缩计划的过滤掉
|
||||||
.select(meta -> {
|
.select(meta -> {
|
||||||
try {
|
try {
|
||||||
return hudiService.existsCompactionPlan(meta.getJob().getId(), meta.getAlias());
|
return hudiService.existsCompactionPlan(meta.getFlinkJobId(), meta.getAlias());
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
logger.error(makeMarker(meta.getJob().getId(), meta.getAlias()), "Get compaction status failure", throwable);
|
logger.error(makeMarker(meta.getFlinkJobId(), meta.getAlias()), "Get compaction status failure", throwable);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
// 拒绝不压缩标志的任务
|
// 拒绝不压缩标志的任务
|
||||||
.reject(meta -> TableMetaHelper.existsTag(meta, Constants.TAGS_NO_COMPACT))
|
.reject(meta -> TableMetaHelper.existsTag(meta.getTags(), Constants.TAGS_NO_COMPACT))
|
||||||
// 拒绝不调度压缩标志的任务
|
// 拒绝不调度压缩标志的任务
|
||||||
.reject(meta -> TableMetaHelper.existsTag(meta, Constants.TAGS_NO_SCHEDULE_COMPACT))
|
.reject(meta -> TableMetaHelper.existsTag(meta.getTags(), Constants.TAGS_NO_SCHEDULE_COMPACT))
|
||||||
.collect(meta -> {
|
.collect(meta -> {
|
||||||
long compactionDuration = 0L;
|
long compactionDuration = 0L;
|
||||||
try {
|
try {
|
||||||
// 计算压缩耗时
|
// 计算压缩耗时
|
||||||
SyncState syncState = infoService.syncStateDetail(meta.getJob().getId(), meta.getAlias());
|
SyncState syncState = infoService.syncStateDetail(meta.getFlinkJobId(), meta.getAlias());
|
||||||
if (ObjectUtil.isNotNull(syncState)
|
if (ObjectUtil.isNotNull(syncState)
|
||||||
&& ObjectUtil.isNotNull(syncState.getCompactionFinishTime())
|
&& ObjectUtil.isNotNull(syncState.getCompactionFinishTime())
|
||||||
&& ObjectUtil.isNotNull(syncState.getCompactionStartTime())) {
|
&& ObjectUtil.isNotNull(syncState.getCompactionStartTime())) {
|
||||||
compactionDuration = syncState.getCompactionFinishTime() - syncState.getCompactionStartTime();
|
compactionDuration = syncState.getCompactionFinishTime() - syncState.getCompactionStartTime();
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error(makeMarker(meta.getJob().getId(), meta.getAlias()), "Get sync state failure for {} {}", meta.getJob().getId(), meta.getAlias());
|
logger.error(makeMarker(meta.getFlinkJobId(), meta.getAlias()), "Get sync state failure for {} {}", meta.getFlinkJobId(), meta.getAlias());
|
||||||
}
|
}
|
||||||
return new TableMetaWrapper(meta, compactionDuration);
|
return new TableMetaWrapper(meta, compactionDuration);
|
||||||
})
|
})
|
||||||
.toSortedList(
|
.toSortedList(
|
||||||
Comparator
|
Comparator
|
||||||
// 比较 Bucket 数,数量大的在前面
|
// 比较 Bucket 数,数量大的在前面
|
||||||
.comparing(TableMetaWrapper::getBucketIndexNumber, Comparator.reverseOrder())
|
.comparing(TableMetaWrapper::getBucketNumber, Comparator.reverseOrder())
|
||||||
// 比较压缩耗时,压缩耗时长的在前面
|
// 比较压缩耗时,压缩耗时长的在前面
|
||||||
.thenComparing(TableMetaWrapper::getCompactionDuration, Comparator.reverseOrder()))
|
.thenComparing(TableMetaWrapper::getCompactionDuration, Comparator.reverseOrder()))
|
||||||
.collect(meta -> new QueueItem<>(
|
.collect(meta -> new QueueItem<>(
|
||||||
@@ -131,28 +131,28 @@ public class ScheduleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final class TableMetaWrapper {
|
private static final class TableMetaWrapper {
|
||||||
private final TableMeta tableMeta;
|
private final SimpleTableMeta meta;
|
||||||
private final Long compactionDuration;
|
private final Long compactionDuration;
|
||||||
|
|
||||||
private TableMetaWrapper(TableMeta tableMeta, Long compactionDuration) {
|
private TableMetaWrapper(SimpleTableMeta meta, Long compactionDuration) {
|
||||||
this.tableMeta = tableMeta;
|
this.meta = meta;
|
||||||
this.compactionDuration = compactionDuration;
|
this.compactionDuration = compactionDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getFlinkJobId() {
|
public Long getFlinkJobId() {
|
||||||
return tableMeta.getJob().getId();
|
return meta.getFlinkJobId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAlias() {
|
public String getAlias() {
|
||||||
return tableMeta.getAlias();
|
return meta.getAlias();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getBucketIndexNumber() {
|
public Integer getBucketNumber() {
|
||||||
return tableMeta.getHudi().getBucketIndexNumber();
|
return meta.getBucketNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getPriority() {
|
public Integer getPriority() {
|
||||||
return tableMeta.getPriority();
|
return meta.getPriority();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getCompactionDuration() {
|
public Long getCompactionDuration() {
|
||||||
|
|||||||
Reference in New Issue
Block a user