Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: srlch <[email protected]>
  • Loading branch information
srlch committed Jan 13, 2025
1 parent 799a7c7 commit 79fd688
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public boolean isUnFinishedState() {
state == ClusterSnapshotJobState.FINISHED;
}

public boolean isSuccess() {
return state == ClusterSnapshotJobState.FINISHED;
}

public void logJob() {
ClusterSnapshotLog log = new ClusterSnapshotLog();
log.setSnapshotJob(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public class ClusterSnapshotMgr implements GsonPostProcessable {
@SerializedName(value = "historyAutomatedSnapshotJobs")
private TreeMap<Long, ClusterSnapshotJob> historyAutomatedSnapshotJobs = new TreeMap<>();

private long previousAutomatedSnapshotCreatedTimsMs = 0;

public ClusterSnapshotMgr() {}

// Turn on automated snapshot, use stmt for extension in future
Expand Down Expand Up @@ -109,7 +107,6 @@ protected void addAutomatedClusterSnapshot(ClusterSnapshot newAutomatedClusterSn
GlobalStateMgr.getCurrentState().getEditLog().logClusterSnapshotLog(log);

if (automatedSnapshot != null && automatedSnapshot.getSnapshotName().startsWith(AUTOMATED_NAME_PREFIX)) {
previousAutomatedSnapshotCreatedTimsMs = automatedSnapshot.getCreatedTimeMs();
try {
ClusterSnapshotUtils.clearAutomatedSnapshotFromRemote(automatedSnapshot.getSnapshotName());
} catch (StarRocksException e) {
Expand Down Expand Up @@ -152,15 +149,34 @@ public boolean containsAutomatedSnapshot() {
}

public synchronized void addJob(ClusterSnapshotJob job) {
if (Config.max_historical_automated_cluster_snapshot_jobs >= 1 &&
if (Config.max_historical_automated_cluster_snapshot_jobs >= 2 &&
historyAutomatedSnapshotJobs.size() == Config.max_historical_automated_cluster_snapshot_jobs) {
historyAutomatedSnapshotJobs.pollFirstEntry();
}
historyAutomatedSnapshotJobs.put(job.getId(), job);
}

public synchronized long getValidDeletionTimeMsByAutomatedSnapshot() {
return isAutomatedSnapshotOn() ? previousAutomatedSnapshotCreatedTimsMs : Long.MAX_VALUE;
if (!isAutomatedSnapshotOn()) {
return Long.MAX_VALUE;
}

boolean findFirstSuccess = false;
long previousAutomatedSnapshotCreatedTimsMs = 0;
for (Long key : historyAutomatedSnapshotJobs.descendingKeySet()) {
ClusterSnapshotJob job = historyAutomatedSnapshotJobs.get(key);
if (job.isSuccess()) {
if (findFirstSuccess) {
previousAutomatedSnapshotCreatedTimsMs = job.getCreatedTimeMs();
break;
}

findFirstSuccess = true;
continue;
}
}

return previousAutomatedSnapshotCreatedTimsMs;
}

public synchronized boolean checkValidDeletionForTableFromAlterJob(long tableId) {
Expand Down

0 comments on commit 79fd688

Please sign in to comment.