Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: srlch <linzichao@starrocks.com>
  • Loading branch information
srlch committed Oct 24, 2024
1 parent 55de013 commit 6f10cfa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
13 changes: 10 additions & 3 deletions fe/fe-core/src/main/java/com/starrocks/backup/BackupHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.starrocks.catalog.OlapTable;
import com.starrocks.catalog.Partition;
import com.starrocks.catalog.Table;
import com.starrocks.catalog.View;
import com.starrocks.common.Config;
import com.starrocks.common.DdlException;
import com.starrocks.common.ErrorCode;
Expand Down Expand Up @@ -442,8 +443,12 @@ private void restore(Repository repository, Database db, RestoreStmt stmt) throw

// If TableRefs is empty, it means that we do not specify any table in Restore stmt.
// So, we should restore all table in current database.
List<View> restoredViews = Lists.newArrayList();
if (stmt.getTableRefs().size() != 0) {
checkAndFilterRestoreObjsExistInSnapshot(jobInfo, stmt.getTableRefs(), backupMeta);
checkAndFilterRestoreObjsExistInSnapshot(jobInfo, stmt.getTableRefs(), backupMeta, restoredViews);
} else {
restoredViews = backupMeta.getTables().values().stream().filter(Table::isOlapView)
.map(x -> (View) x).collect(Collectors.toList());
}

// Create a restore job
Expand All @@ -462,6 +467,7 @@ private void restore(Repository repository, Database db, RestoreStmt stmt) throw
restoreJob = new RestoreJob(stmt.getLabel(), stmt.getBackupTimestamp(),
db.getId(), db.getOriginName(), jobInfo, stmt.allowLoad(), stmt.getReplicationNum(),
stmt.getTimeoutMs(), globalStateMgr, repository.getId(), backupMeta, mvRestoreContext);
restoreJob.setRestoredViews(restoredViews);
globalStateMgr.getEditLog().logRestoreJob(restoreJob);

// must put to dbIdToBackupOrRestoreJob after edit log, otherwise the state of job may be changed.
Expand Down Expand Up @@ -489,7 +495,8 @@ private BackupMeta downloadAndDeserializeMetaInfo(BackupJobInfo jobInfo, Reposit
return backupMetas.get(0);
}

private void checkAndFilterRestoreObjsExistInSnapshot(BackupJobInfo jobInfo, List<TableRef> tblRefs, BackupMeta backupMeta)
private void checkAndFilterRestoreObjsExistInSnapshot(BackupJobInfo jobInfo, List<TableRef> tblRefs, BackupMeta backupMeta,
List<View> restoredViews)
throws DdlException {
Set<String> allTbls = Sets.newHashSet();
for (TableRef tblRef : tblRefs) {
Expand All @@ -500,7 +507,7 @@ private void checkAndFilterRestoreObjsExistInSnapshot(BackupJobInfo jobInfo, Lis
// simple reset alias for view in backupMeta to be restored.
tbl.setName(tblRef.getExplicitAlias());
}
continue;
restoredViews.add((View) tbl);
}

if (!jobInfo.containsTbl(tblName)) {
Expand Down
20 changes: 14 additions & 6 deletions fe/fe-core/src/main/java/com/starrocks/backup/RestoreJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ public enum RestoreJobState {
private AgentBatchTask batchTask;

boolean enableColocateRestore = Config.enable_colocate_restore;

@SerializedName(value = "restoredViews")
private List<View> restoredViews = Lists.newArrayList();

public RestoreJob() {
super(JobType.RESTORE);
Expand Down Expand Up @@ -789,9 +792,7 @@ private void checkAndPrepareMeta() {
}

// add all restored olap view into globalStateMgr
List<View> restoredOlapViews = backupMeta.getTables().values().stream().filter(Table::isOlapView)
.map(x -> (View) x).collect(Collectors.toList());
addRestoreOlapView(restoredOlapViews);
addRestoreOlapView(restoredViews);
if (!status.ok()) {
return;
}
Expand Down Expand Up @@ -1174,9 +1175,7 @@ private void replayCheckAndPrepareMeta() {
locker.unLockDatabase(db.getId(), LockType.WRITE);
}

List<View> restoredOlapViews = backupMeta.getTables().values().stream().filter(Table::isOlapView)
.map(x -> (View) x).collect(Collectors.toList());
addRestoreOlapView(restoredOlapViews);
addRestoreOlapView(restoredViews);

LOG.info("replay check and prepare meta. {}", this);
}
Expand Down Expand Up @@ -1622,6 +1621,10 @@ private void replayWaitingAllTabletsCommitted() {
allTabletCommitted(true /* is replay */);
}

public void setRestoredViews(List<View> restoredViews) {
this.restoredViews = restoredViews;
}

public List<String> getInfo() {
List<String> info = Lists.newArrayList();
info.add(String.valueOf(jobId));
Expand Down Expand Up @@ -1740,6 +1743,11 @@ public void cancelInternal(boolean isReplay) {

restoreTbl.dropPartition(dbId, entry.second.getName(), true /* is restore */);
}

// remove restored View
for (View restoredView : restoredViews) {
db.dropTable(restoredView.getName());
}
} finally {
locker.unLockDatabase(db.getId(), LockType.WRITE);
}
Expand Down

0 comments on commit 6f10cfa

Please sign in to comment.