[Enhancement](fe-core) make UT-SelectRollupTest more stable (#13030)

This commit is contained in:
DingGeGe
2022-09-29 14:25:01 +08:00
committed by GitHub
parent c2fae109c3
commit fae7296336

View File

@ -35,13 +35,17 @@ import org.apache.doris.analysis.SqlParser;
import org.apache.doris.analysis.SqlScanner;
import org.apache.doris.analysis.StatementBase;
import org.apache.doris.analysis.UserIdentity;
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.DiskInfo;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Table;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.FeConstants;
import org.apache.doris.common.MetaNotFoundException;
import org.apache.doris.common.util.SqlParserUtils;
import org.apache.doris.nereids.CascadesContext;
import org.apache.doris.nereids.StatementContext;
@ -506,12 +510,12 @@ public abstract class TestWithFeService {
protected void addRollup(String sql) throws Exception {
AlterTableStmt alterTableStmt = (AlterTableStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, connectContext);
Env.getCurrentEnv().alterTable(alterTableStmt);
// waiting alter job state: finished AND table state: normal
checkAlterJob();
// waiting table state to normal
Thread.sleep(100);
}
private void checkAlterJob() throws InterruptedException {
private void checkAlterJob() throws InterruptedException, MetaNotFoundException {
// check alter job
Map<Long, AlterJobV2> alterJobs = Env.getCurrentEnv().getMaterializedViewHandler().getAlterJobsV2();
for (AlterJobV2 alterJobV2 : alterJobs.values()) {
@ -522,6 +526,17 @@ public abstract class TestWithFeService {
}
System.out.println("alter job " + alterJobV2.getDbId() + " is done. state: " + alterJobV2.getJobState());
Assert.assertEquals(AlterJobV2.JobState.FINISHED, alterJobV2.getJobState());
// Add table state check in case of below Exception:
// there is still a short gap between "job finish" and "table become normal",
// so if user send next alter job right after the "job finish",
// it may encounter "table's state not NORMAL" error.
Database db =
Env.getCurrentInternalCatalog().getDbOrMetaException(alterJobV2.getDbId());
OlapTable tbl = (OlapTable) db.getTableOrMetaException(alterJobV2.getTableId(), Table.TableType.OLAP);
while (tbl.getState() != OlapTable.OlapTableState.NORMAL) {
Thread.sleep(1000);
}
}
}