Skip to content

Commit

Permalink
feat: 执行历史归档新增模式-只备份不删除 TencentBlueKing#3037
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Jun 5, 2024
1 parent 733811e commit 29d15c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,23 @@ private void backupAndDelete() throws IOException {
long start = this.minNeedArchiveId - 1;
long stop = start;
boolean success = true;
long backupCost = 0;
long deleteCost = 0;
try {
while (maxNeedArchiveId > start) {
// start < id <= stop
stop = Math.min(maxNeedArchiveId, start + readIdStepSize);
Pair<Long, Long> backupResult = null;
if (backupEnabled) {
long backupStartTime = System.currentTimeMillis();
backupResult = backupRecords(start, stop);
readRows += backupResult.getLeft();
backupRows += backupResult.getRight();
backupCost += (System.currentTimeMillis() - backupStartTime);
}

if (deleteEnabled) {
long deleteStartTime = System.currentTimeMillis();
if (backupResult != null) {
if (backupResult.getLeft() > 0) {
// 降低 delete 执行次数:备份过程中读取的数据行数大于 0,才会执行 delete 操作
Expand All @@ -246,6 +251,7 @@ private void backupAndDelete() throws IOException {
} else {
deleteRows += delete(start, stop);
}
deleteCost += (System.currentTimeMillis() - deleteStartTime);
}

start = stop;
Expand All @@ -268,7 +274,7 @@ private void backupAndDelete() throws IOException {
archiveCost
);
setArchiveSummary(minNeedArchiveId, maxNeedArchiveId, readRows, backupRows, deleteRows,
stop, archiveCost, success);
stop, archiveCost, success, backupCost, deleteCost);
}
}

Expand Down Expand Up @@ -355,7 +361,9 @@ private void setArchiveSummary(Long minNeedArchiveId,
long deleteRows,
long stop,
long archiveCost,
boolean success) {
boolean success,
long backupCost,
long deleteCost) {
archiveSummary.setArchiveIdStart(minNeedArchiveId);
archiveSummary.setArchiveIdEnd(maxNeedArchiveId);
archiveSummary.setNeedArchiveRecordSize(readRows);
Expand All @@ -365,6 +373,8 @@ private void setArchiveSummary(Long minNeedArchiveId,
archiveSummary.setLastDeletedId(stop);
archiveSummary.setArchiveCost(archiveCost);
archiveSummary.setSuccess(success);
archiveSummary.setBackupCost(backupCost);
archiveSummary.setDeleteCost(deleteCost);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public class ArchiveSummary {
private boolean success;

private String archiveMode;

/**
* 备份数据耗时(单位毫秒)
*/
private Long backupCost;
/**
* 删除热数据耗时(单位毫秒)
*/
private Long deleteCost;
/**
* 归档总耗时(单位毫秒)
*/
private Long archiveCost;

private Long archiveIdStart;
Expand Down

0 comments on commit 29d15c1

Please sign in to comment.