Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,8 @@ private void changeTableState(long dbId, long tableId, OlapTableState olapTableS
try {
if (olapTable.getState() == olapTableState) {
return;
} else if (olapTable.getState() == OlapTableState.SCHEMA_CHANGE) {
} else if (olapTable.getState() == OlapTableState.SCHEMA_CHANGE
|| olapTable.getState() == OlapTableState.WAITING_STABLE) {
olapTable.setState(olapTableState);
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,46 @@ public void testSchemaChangeWhileTabletNotStable() throws Exception {
Assertions.assertEquals(JobState.FINISHED, schemaChangeJob.getJobState());
}

@Test
public void testCancelSchemaChangeWhileTableWaitingStable() throws Exception {
if (fakeEnv != null) {
fakeEnv.close();
}
fakeEnv = new FakeEnv();
if (fakeEditLog != null) {
fakeEditLog.close();
}
fakeEditLog = new FakeEditLog();
FakeEnv.setEnv(masterEnv);
SchemaChangeHandler schemaChangeHandler = Env.getCurrentEnv().getSchemaChangeHandler();

// add a schema change job
ArrayList<AlterOp> alterOps = new ArrayList<>();
alterOps.add(addColumnOp);
Database db = masterEnv.getInternalCatalog().getDbOrDdlException(CatalogTestUtil.testDbId1);
OlapTable olapTable = (OlapTable) db.getTableOrDdlException(CatalogTestUtil.testTableId1);
Partition testPartition = olapTable.getPartition(CatalogTestUtil.testPartitionId1);
schemaChangeHandler.process(alterOps, db, olapTable);
Map<Long, AlterJobV2> alterJobsV2 = schemaChangeHandler.getAlterJobsV2();
Assertions.assertEquals(1, alterJobsV2.size());
SchemaChangeJobV2 schemaChangeJob = (SchemaChangeJobV2) alterJobsV2.values().stream().findAny().get();
Assertions.assertEquals(OlapTableState.SCHEMA_CHANGE, olapTable.getState());

// make the table unstable, so that the job stays in PENDING and the table
// state is switched to WAITING_STABLE
MaterializedIndex baseIndex = testPartition.getBaseIndex();
Replica replica = baseIndex.getTablets().get(0).getReplicas().get(0);
replica.setState(Replica.ReplicaState.DECOMMISSION);
schemaChangeHandler.runAfterCatalogReady();
Assertions.assertEquals(JobState.PENDING, schemaChangeJob.getJobState());
Assertions.assertEquals(OlapTableState.WAITING_STABLE, olapTable.getState());

// cancel the job, the table state must be reset to NORMAL
Assertions.assertTrue(schemaChangeJob.cancel("user cancelled"));
Assertions.assertEquals(JobState.CANCELLED, schemaChangeJob.getJobState());
Assertions.assertEquals(OlapTableState.NORMAL, olapTable.getState());
}

@Test
public void testModifyDynamicPartitionNormal() throws UserException {
if (fakeEnv != null) {
Expand Down
Loading