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 17, 2025
1 parent cc37675 commit 82ed7d4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public synchronized boolean checkValidDeletionForTableFromAlterJob(long tableId)

boolean valid = true;
Map<Long, AlterJobV2> alterJobs = GlobalStateMgr.getCurrentState().getRollupHandler().getAlterJobsV2();
alterJobs.putAll(GlobalStateMgr.getCurrentState().getSchemaChangeHandler().getAlterJobsV2());
for (Map.Entry<Long, AlterJobV2> entry : alterJobs.entrySet()) {
AlterJobV2 alterJob = entry.getValue();
if (alterJob.getTableId() == tableId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package com.starrocks.lake.snapshot;

import com.starrocks.alter.AlterJobV2;
import com.starrocks.alter.AlterTest;
import com.starrocks.alter.MaterializedViewHandler;
import com.starrocks.alter.SchemaChangeHandler;
import com.starrocks.alter.SchemaChangeJobV2;
import com.starrocks.common.AlreadyExistsException;
import com.starrocks.common.Config;
import com.starrocks.common.DdlException;
Expand Down Expand Up @@ -66,6 +70,8 @@ public class ClusterSnapshotTest {
private ClusterSnapshotMgr clusterSnapshotMgr = new ClusterSnapshotMgr();
private boolean initSv = false;

private long nextId = 0;

@BeforeClass
public static void beforeClass() throws Exception {
AlterTest.beforeClass();
Expand Down Expand Up @@ -103,7 +109,8 @@ public ClusterSnapshotMgr getClusterSnapshotMgr() {

@Mock
public long getNextId() {
return 0L;
nextId = nextId + 1;
return nextId;
}
};

Expand Down Expand Up @@ -310,4 +317,70 @@ public long getMaxJournalId() {
}
setAutomatedSnapshotOff(false);
}
}

@Test
public void testDeletionControl() {
new MockUp<RunMode>() {
@Mock
public boolean isSharedDataMode() {
return true;
}
};

ClusterSnapshotMgr localClusterSnapshotMgr = new ClusterSnapshotMgr();
Assert.assertTrue(localClusterSnapshotMgr.getValidDeletionTimeMsByAutomatedSnapshot() == Long.MAX_VALUE);
localClusterSnapshotMgr.setAutomatedSnapshotOn(storageVolumeName);
Assert.assertEquals(localClusterSnapshotMgr.getValidDeletionTimeMsByAutomatedSnapshot(), 0L);

ClusterSnapshotJob job1 = localClusterSnapshotMgr.createAutomatedSnapshotJob();
job1.setState(ClusterSnapshotJobState.FINISHED);
Assert.assertEquals(localClusterSnapshotMgr.getValidDeletionTimeMsByAutomatedSnapshot(), 0L);
ClusterSnapshotJob job2 = localClusterSnapshotMgr.createAutomatedSnapshotJob();
job2.setState(ClusterSnapshotJobState.FINISHED);
Assert.assertEquals(localClusterSnapshotMgr.getValidDeletionTimeMsByAutomatedSnapshot(), job1.getCreatedTimeMs());
localClusterSnapshotMgr.setAutomatedSnapshotOff();

localClusterSnapshotMgr = new ClusterSnapshotMgr();
Assert.assertTrue(localClusterSnapshotMgr.checkValidDeletionForTableFromAlterJob(10));
AlterJobV2 alterjob1 = new SchemaChangeJobV2(1, 2, 10, "table1", 100000);
AlterJobV2 alterjob2 = new SchemaChangeJobV2(2, 2, 11, "table2", 100000);
alterjob1.setJobState(AlterJobV2.JobState.FINISHED);
alterjob1.setFinishedTimeMs(1000);
alterjob2.setJobState(AlterJobV2.JobState.FINISHED);
alterjob2.setFinishedTimeMs(1000);


MaterializedViewHandler rollupHandler = new MaterializedViewHandler();
SchemaChangeHandler schemaChangeHandler = new SchemaChangeHandler();
schemaChangeHandler.addAlterJobV2(alterjob1);
schemaChangeHandler.addAlterJobV2(alterjob2);

new MockUp<GlobalStateMgr>() {
@Mock
public SchemaChangeHandler getSchemaChangeHandler() {
return schemaChangeHandler;
}

@Mock
public MaterializedViewHandler getRollupHandler() {
return rollupHandler;
}
};

localClusterSnapshotMgr.setAutomatedSnapshotOn(storageVolumeName);
Assert.assertTrue(!localClusterSnapshotMgr.checkValidDeletionForTableFromAlterJob(10));
Assert.assertTrue(!localClusterSnapshotMgr.checkValidDeletionForTableFromAlterJob(11));
ClusterSnapshotJob j1 = localClusterSnapshotMgr.createAutomatedSnapshotJob();
j1.setState(ClusterSnapshotJobState.FINISHED);

Assert.assertTrue(!localClusterSnapshotMgr.checkValidDeletionForTableFromAlterJob(10));
Assert.assertTrue(!localClusterSnapshotMgr.checkValidDeletionForTableFromAlterJob(11));

ClusterSnapshotJob j2 = localClusterSnapshotMgr.createAutomatedSnapshotJob();
j2.setState(ClusterSnapshotJobState.FINISHED);

Assert.assertTrue(localClusterSnapshotMgr.checkValidDeletionForTableFromAlterJob(10));
Assert.assertTrue(localClusterSnapshotMgr.checkValidDeletionForTableFromAlterJob(11));
localClusterSnapshotMgr.setAutomatedSnapshotOff();
}
}

0 comments on commit 82ed7d4

Please sign in to comment.