This is an automated email from the ASF dual-hosted git repository. w41ter pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new f75f7ae8d7a [chore](backup) reduce the complex if conditions (#39983) f75f7ae8d7a is described below commit f75f7ae8d7a808191337ed953ffe52f5d36e2098 Author: walter <w41te...@gmail.com> AuthorDate: Tue Aug 27 21:08:45 2024 +0800 [chore](backup) reduce the complex if conditions (#39983) --- .../java/org/apache/doris/backup/BackupJob.java | 56 +++++++++------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java index 6f73334f0c2..d7d550e5208 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java +++ b/fe/fe-core/src/main/java/org/apache/doris/backup/BackupJob.java @@ -489,29 +489,17 @@ public class BackupJob extends AbstractJob { break; case OLAP: OlapTable olapTable = (OlapTable) tbl; - if (!checkOlapTable(olapTable, tableRef).ok()) { - return; - } + checkOlapTable(olapTable, tableRef); if (getContent() == BackupContent.ALL) { - if (!prepareSnapshotTaskForOlapTableWithoutLock( - db, (OlapTable) tbl, tableRef, batchTask).ok()) { - return; - } - } - if (!prepareBackupMetaForOlapTableWithoutLock(tableRef, olapTable, copiedTables).ok()) { - return; + prepareSnapshotTaskForOlapTableWithoutLock(db, (OlapTable) tbl, tableRef, batchTask); } + prepareBackupMetaForOlapTableWithoutLock(tableRef, olapTable, copiedTables); break; case VIEW: - if (!prepareBackupMetaForViewWithoutLock((View) tbl, copiedTables).ok()) { - return; - } + prepareBackupMetaForViewWithoutLock((View) tbl, copiedTables); break; case ODBC: - if (!prepareBackupMetaForOdbcTableWithoutLock( - (OdbcTable) tbl, copiedTables, copiedResources).ok()) { - return; - } + prepareBackupMetaForOdbcTableWithoutLock((OdbcTable) tbl, copiedTables, copiedResources); break; default: status = new Status(ErrCode.COMMON_ERROR, @@ -521,6 +509,11 @@ public class BackupJob extends AbstractJob { } finally { tbl.readUnlock(); } + + // Avoid submitting a lot of tasks but cancel them immediately. + if (!status.ok()) { + return; + } } backupMeta = new BackupMeta(copiedTables, copiedResources); @@ -538,7 +531,7 @@ public class BackupJob extends AbstractJob { LOG.info("finished to send snapshot tasks to backend. {}", this); } - private Status checkOlapTable(OlapTable olapTable, TableRef backupTableRef) { + private void checkOlapTable(OlapTable olapTable, TableRef backupTableRef) { olapTable.readLock(); try { // check backup table again @@ -548,17 +541,16 @@ public class BackupJob extends AbstractJob { if (partition == null) { status = new Status(ErrCode.NOT_FOUND, "partition " + partName + " does not exist in table" + backupTableRef.getName().getTbl()); - return status; + return; } } } } finally { olapTable.readUnlock(); } - return Status.OK; } - private Status prepareSnapshotTaskForOlapTableWithoutLock(Database db, OlapTable olapTable, + private void prepareSnapshotTaskForOlapTableWithoutLock(Database db, OlapTable olapTable, TableRef backupTableRef, AgentBatchTask batchTask) { // Add barrier editolog for barrier commit seq long dbId = db.getId(); @@ -578,7 +570,7 @@ public class BackupJob extends AbstractJob { if (partition == null) { status = new Status(ErrCode.NOT_FOUND, "partition " + partName + " does not exist in table" + backupTableRef.getName().getTbl()); - return status; + return; } } } @@ -607,7 +599,7 @@ public class BackupJob extends AbstractJob { status = new Status(ErrCode.COMMON_ERROR, "failed to choose replica to make snapshot for tablet " + tablet.getId() + ". visible version: " + visibleVersion); - return status; + return; } SnapshotTask task = new SnapshotTask(null, replica.getBackendId(), tablet.getId(), jobId, dbId, olapTable.getId(), partition.getId(), @@ -622,7 +614,6 @@ public class BackupJob extends AbstractJob { LOG.info("snapshot for partition {}, version: {}, job: {}", partition.getId(), visibleVersion, label); } - return Status.OK; } private void checkResourceForOdbcTable(OdbcTable odbcTable) { @@ -638,7 +629,7 @@ public class BackupJob extends AbstractJob { } } - private Status prepareBackupMetaForOlapTableWithoutLock(TableRef tableRef, OlapTable olapTable, + private void prepareBackupMetaForOlapTableWithoutLock(TableRef tableRef, OlapTable olapTable, List<Table> copiedTables) { // only copy visible indexes List<String> reservedPartitions = tableRef.getPartitionNames() == null ? null @@ -646,30 +637,28 @@ public class BackupJob extends AbstractJob { OlapTable copiedTbl = olapTable.selectiveCopy(reservedPartitions, IndexExtState.VISIBLE, true); if (copiedTbl == null) { status = new Status(ErrCode.COMMON_ERROR, "failed to copy table: " + olapTable.getName()); - return status; + return; } removeUnsupportProperties(copiedTbl); copiedTables.add(copiedTbl); - return Status.OK; } - private Status prepareBackupMetaForViewWithoutLock(View view, List<Table> copiedTables) { + private void prepareBackupMetaForViewWithoutLock(View view, List<Table> copiedTables) { View copiedView = view.clone(); if (copiedView == null) { status = new Status(ErrCode.COMMON_ERROR, "failed to copy view: " + view.getName()); - return status; + return; } copiedTables.add(copiedView); - return Status.OK; } - private Status prepareBackupMetaForOdbcTableWithoutLock(OdbcTable odbcTable, List<Table> copiedTables, + private void prepareBackupMetaForOdbcTableWithoutLock(OdbcTable odbcTable, List<Table> copiedTables, List<Resource> copiedResources) { OdbcTable copiedOdbcTable = odbcTable.clone(); if (copiedOdbcTable == null) { status = new Status(ErrCode.COMMON_ERROR, "failed to copy odbc table: " + odbcTable.getName()); - return status; + return; } copiedTables.add(copiedOdbcTable); if (copiedOdbcTable.getOdbcCatalogResourceName() != null) { @@ -679,11 +668,10 @@ public class BackupJob extends AbstractJob { if (copiedResource == null) { status = new Status(ErrCode.COMMON_ERROR, "failed to copy odbc resource: " + resource.getName()); - return status; + return; } copiedResources.add(copiedResource); } - return Status.OK; } private void removeUnsupportProperties(OlapTable tbl) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org