[fix](backup) save finished state for local repo backup (#35491)
The backup finished state in the local repo is not logged. So if there exist multiple local repo backups, and FE was restarted, then these backup records will be reset to the UPLOAD_INFO state.
This commit is contained in:
@ -764,6 +764,7 @@ public class BackupHandler extends MasterDaemon implements Writable {
|
||||
// We use replayed job, not the existing job, to do the replayRun().
|
||||
// Because if we use the existing job to run again,
|
||||
// for example: In restore job, PENDING will transfer to SNAPSHOTING, not DOWNLOAD.
|
||||
job.setEnv(env);
|
||||
job.replayRun();
|
||||
}
|
||||
|
||||
|
||||
@ -258,8 +258,11 @@ public class BackupJob extends AbstractJob {
|
||||
|
||||
@Override
|
||||
public synchronized void replayRun() {
|
||||
// Backup process does not change any current catalog state,
|
||||
// So nothing need to be done when replaying log
|
||||
LOG.info("replay run backup job: {}", this);
|
||||
if (state == BackupJobState.FINISHED && repoId == Repository.KEEP_ON_LOCAL_REPO_ID) {
|
||||
Snapshot snapshot = new Snapshot(label, metaInfoBytes, jobInfoBytes);
|
||||
env.getBackupHandler().addSnapshot(label, snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -812,22 +815,18 @@ public class BackupJob extends AbstractJob {
|
||||
}
|
||||
|
||||
private void uploadMetaAndJobInfoFile() {
|
||||
if (repoId == Repository.KEEP_ON_LOCAL_REPO_ID) {
|
||||
state = BackupJobState.FINISHED;
|
||||
Snapshot snapshot = new Snapshot(label, metaInfoBytes, jobInfoBytes);
|
||||
env.getBackupHandler().addSnapshot(label, snapshot);
|
||||
return;
|
||||
if (repoId != Repository.KEEP_ON_LOCAL_REPO_ID) {
|
||||
String remoteMetaInfoFile = repo.assembleMetaInfoFilePath(label);
|
||||
if (!uploadFile(localMetaInfoFilePath, remoteMetaInfoFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String remoteJobInfoFile = repo.assembleJobInfoFilePath(label, createTime);
|
||||
if (!uploadFile(localJobInfoFilePath, remoteJobInfoFile)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String remoteMetaInfoFile = repo.assembleMetaInfoFilePath(label);
|
||||
if (!uploadFile(localMetaInfoFilePath, remoteMetaInfoFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String remoteJobInfoFile = repo.assembleJobInfoFilePath(label, createTime);
|
||||
if (!uploadFile(localJobInfoFilePath, remoteJobInfoFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
finishedTime = System.currentTimeMillis();
|
||||
state = BackupJobState.FINISHED;
|
||||
@ -835,6 +834,12 @@ public class BackupJob extends AbstractJob {
|
||||
// log
|
||||
env.getEditLog().logBackupJob(this);
|
||||
LOG.info("job is finished. {}", this);
|
||||
|
||||
if (repoId == Repository.KEEP_ON_LOCAL_REPO_ID) {
|
||||
Snapshot snapshot = new Snapshot(label, metaInfoBytes, jobInfoBytes);
|
||||
env.getBackupHandler().addSnapshot(label, snapshot);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean uploadFile(String localFilePath, String remoteFilePath) {
|
||||
|
||||
@ -167,7 +167,7 @@ public class EditLog {
|
||||
short opCode = journal.getOpCode();
|
||||
if (opCode != OperationType.OP_SAVE_NEXTID && opCode != OperationType.OP_TIMESTAMP) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("replay journal op code: {}", opCode);
|
||||
LOG.debug("replay journal op code: {}, log id: {}", opCode, logId);
|
||||
}
|
||||
}
|
||||
try {
|
||||
@ -1202,7 +1202,7 @@ public class EditLog {
|
||||
}
|
||||
default: {
|
||||
IOException e = new IOException();
|
||||
LOG.error("UNKNOWN Operation Type {}", opCode, e);
|
||||
LOG.error("UNKNOWN Operation Type {}, log id: {}", opCode, logId, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@ -1226,9 +1226,9 @@ public class EditLog {
|
||||
* log a warning here to debug when happens. This could happen to other meta
|
||||
* like DB.
|
||||
*/
|
||||
LOG.warn("[INCONSISTENT META] replay failed {}: {}", journal, e.getMessage(), e);
|
||||
LOG.warn("[INCONSISTENT META] replay log {} failed, journal {}: {}", logId, journal, e.getMessage(), e);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Operation Type {}", opCode, e);
|
||||
LOG.error("replay Operation Type {}, log id: {}", opCode, logId, e);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user