Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UT] [Refactor] Fix unstable mv test cases #54320

Merged
merged 1 commit into from
Dec 26, 2024
Merged
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 @@ -62,10 +62,10 @@
import com.starrocks.sql.ast.StatementBase;
import com.starrocks.sql.optimizer.MvRewritePreprocessor;
import com.starrocks.sql.optimizer.Utils;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MVTestBase;
import com.starrocks.sql.parser.SqlParser;
import com.starrocks.sql.plan.ConnectorPlanTestBase;
import com.starrocks.sql.plan.ExecPlan;
import com.starrocks.sql.plan.PlanTestBase;
import com.starrocks.statistic.StatisticsMetaManager;
import com.starrocks.system.Backend;
import com.starrocks.system.SystemInfoService;
Expand All @@ -78,10 +78,8 @@
import org.apache.hadoop.util.ThreadUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
Expand All @@ -90,7 +88,6 @@
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -101,7 +98,7 @@

import static com.starrocks.sql.optimizer.MVTestUtils.waitingRollupJobV2Finish;

public class CreateMaterializedViewTest {
public class CreateMaterializedViewTest extends MVTestBase {
private static final Logger LOG = LogManager.getLogger(CreateMaterializedViewTest.class);

@Rule
Expand All @@ -114,13 +111,9 @@ public class CreateMaterializedViewTest {
public static TemporaryFolder temp = new TemporaryFolder();

private static ConnectContext connectContext;
private static StarRocksAssert starRocksAssert;
private static Database testDb;
private static GlobalStateMgr currentState;

private static long startSuiteTime = 0;
private long startCaseTime = 0;

@BeforeClass
public static void beforeClass() throws Exception {
ConnectorPlanTestBase.doInit(temp.newFolder().toURI().toString());
Expand All @@ -133,7 +126,6 @@ public static void beforeClass() throws Exception {
// create connect context
connectContext = UtFrameUtils.createDefaultCtx();
starRocksAssert = new StarRocksAssert(connectContext);
startSuiteTime = Instant.now().getEpochSecond();

if (!starRocksAssert.databaseExist("_statistics_")) {
StatisticsMetaManager m = new StatisticsMetaManager();
Expand Down Expand Up @@ -331,18 +323,6 @@ public static void beforeClass() throws Exception {

@AfterClass
public static void afterClass() throws Exception {
PlanTestBase.cleanupEphemeralMVs(starRocksAssert, startSuiteTime);
}

@Before
public void before() {
startCaseTime = Instant.now().getEpochSecond();
}

@After
public void after() throws Exception {
// cleanup mv after each case
PlanTestBase.cleanupEphemeralMVs(starRocksAssert, startCaseTime);
}

private static void dropMv(String mvName) throws Exception {
Expand Down Expand Up @@ -3180,20 +3160,6 @@ public void testExprAlias() throws Exception {
testMVColumnAlias("c_1_9 + c_1_10");
}

private Table getTable(String dbName, String mvName) {
Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb(dbName);
Table table = GlobalStateMgr.getCurrentState().getLocalMetastore().getTable(testDb.getFullName(), mvName);
Assert.assertNotNull(table);
return table;
}

private MaterializedView getMv(String dbName, String mvName) {
Table table = getTable(dbName, mvName);
Assert.assertTrue(table instanceof MaterializedView);
MaterializedView mv = (MaterializedView) table;
return mv;
}

@Test
public void testMvNullable() throws Exception {
starRocksAssert.withTable("create table emps (\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import com.starrocks.catalog.Table;
import com.starrocks.catalog.Tablet;
import com.starrocks.clone.DynamicPartitionScheduler;
import com.starrocks.metric.MaterializedViewMetricsEntity;
import com.starrocks.metric.MaterializedViewMetricsRegistry;
import com.starrocks.qe.StmtExecutor;
import com.starrocks.schema.MTable;
import com.starrocks.server.GlobalStateMgr;
Expand All @@ -41,7 +39,7 @@
import com.starrocks.sql.ast.RefreshMaterializedViewStatement;
import com.starrocks.sql.ast.TruncateTableStmt;
import com.starrocks.sql.common.PListCell;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MvRewriteTestBase;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MVTestBase;
import com.starrocks.sql.plan.ExecPlan;
import com.starrocks.utframe.UtFrameUtils;
import mockit.Mock;
Expand All @@ -60,13 +58,13 @@
import java.util.function.Function;
import java.util.stream.Collectors;

public class RefreshMaterializedViewTest extends MvRewriteTestBase {
public class RefreshMaterializedViewTest extends MVTestBase {
// 1hour: set it to 1 hour to avoid FE's async update too late.
private static final long MV_STALENESS = 60 * 60;

@BeforeClass
public static void beforeClass() throws Exception {
MvRewriteTestBase.beforeClass();
MVTestBase.beforeClass();
starRocksAssert.useDatabase("test")
.withTable("CREATE TABLE test.tbl_with_mv\n" +
"(\n" +
Expand Down Expand Up @@ -1279,23 +1277,15 @@ public void testTruncateTableInDiffDb() throws Exception {

executeInsertSql(connectContext, "insert into trunc_db.trunc_db_t1 values(2, 10)");
MaterializedView mv1 = getMv("mv_db", "test_mv");
MaterializedViewMetricsEntity mvEntity =
(MaterializedViewMetricsEntity) MaterializedViewMetricsRegistry.getInstance().getMetricsEntity(mv1.getMvId());
long origCount = mvEntity.histRefreshJobDuration.getCount();

Table table = getTable("trunc_db", "trunc_db_t1");
// Simulate writing to a non-existent MV
table.addRelatedMaterializedView(new MvId(1,1));
String truncateStr = "truncate table trunc_db.trunc_db_t1;";
TruncateTableStmt truncateTableStmt = (TruncateTableStmt) UtFrameUtils.parseStmtWithNewParser(truncateStr, connectContext);
GlobalStateMgr.getCurrentState().getLocalMetastore().truncateTable(truncateTableStmt, connectContext);
starRocksAssert.waitRefreshFinished(mv1.getId());
Assert.assertTrue(starRocksAssert.waitRefreshFinished(mv1.getId()));

mvEntity =
(MaterializedViewMetricsEntity) MaterializedViewMetricsRegistry.getInstance().getMetricsEntity(mv1.getMvId());
System.out.println(mvEntity.histRefreshJobDuration);
long count = mvEntity.histRefreshJobDuration.getCount();
Assert.assertEquals(origCount + 1, count);
starRocksAssert.dropTable("trunc_db.trunc_db_t1");
starRocksAssert.dropMaterializedView("mv_db.test_mv");
}
Expand Down Expand Up @@ -1328,21 +1318,13 @@ public void testDropPartitionTableInDiffDb() throws Exception {

executeInsertSql(connectContext, "insert into drop_db.tbl_with_mv partition(p2) values(\"2022-02-20\", 2, 10)");
MaterializedView mv1 = getMv("drop_mv_db", "test_mv");
MaterializedViewMetricsEntity mvEntity =
(MaterializedViewMetricsEntity) MaterializedViewMetricsRegistry.getInstance().getMetricsEntity(mv1.getMvId());
long origCount = mvEntity.histRefreshJobDuration.getCount();

OlapTable table = (OlapTable) getTable("drop_db", "tbl_with_mv");
Partition p1 = table.getPartition("p1");
DropPartitionClause dropPartitionClause = new DropPartitionClause(false, p1.getName(), false, true);
dropPartitionClause.setResolvedPartitionNames(ImmutableList.of(p1.getName()));
Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb("drop_db");
GlobalStateMgr.getCurrentState().getLocalMetastore().dropPartition(db, table, dropPartitionClause);
starRocksAssert.waitRefreshFinished(mv1.getId());
mvEntity =
(MaterializedViewMetricsEntity) MaterializedViewMetricsRegistry.getInstance().getMetricsEntity(mv1.getMvId());
long count = mvEntity.histRefreshJobDuration.getCount();
Assert.assertEquals(origCount + 1, count);
Assert.assertTrue(starRocksAssert.waitRefreshFinished(mv1.getId()));
starRocksAssert.dropTable("drop_db.tbl_with_mv");
starRocksAssert.dropMaterializedView("drop_mv_db.test_mv");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.common.collect.ImmutableList;
import com.starrocks.common.Pair;
import com.starrocks.sql.common.QueryDebugOptions;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MvRewriteTestBase;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MVTestBase;
import com.starrocks.sql.plan.PlanTestBase;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand All @@ -31,7 +31,7 @@
import java.util.List;

@Ignore
public class MVPartitionCompensateOptBench extends MvRewriteTestBase {
public class MVPartitionCompensateOptBench extends MVTestBase {

private static final int MV_NUMS = 100;
private static final int BENCHMARK_RUNS = 10;
Expand All @@ -41,7 +41,7 @@ public class MVPartitionCompensateOptBench extends MvRewriteTestBase {

@BeforeClass
public static void setup() throws Exception {
MvRewriteTestBase.beforeClass();
MVTestBase.beforeClass();
starRocksAssert.withTable(cluster, "table_with_day_partition");
starRocksAssert.withTable(cluster, "table_with_day_partition1");
starRocksAssert.withTable(cluster, "table_with_day_partition2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
import com.starrocks.schema.MTable;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.optimizer.CachingMvPlanContextBuilder;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MvRewriteTestBase;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MVTestBase;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
Expand All @@ -41,9 +42,10 @@
* x dbs which contains one table
* y mvs which contains x/2 tables and uses `union all` to concatenate them
*
* refresh mvs with concurrency to test lock and preformance
* refresh mvs with concurrency to test lock and performance
*/
public class MvRefreshConcurrencyTest extends MvRewriteTestBase {
@Ignore
public class MvRefreshConcurrencyTest extends MVTestBase {

@Rule
public TestRule benchRun = new BenchmarkRule();
Expand All @@ -62,7 +64,7 @@ private static String buildMVName(int idx) {

@BeforeClass
public static void beforeClass() throws Exception {
MvRewriteTestBase.beforeClass();
MVTestBase.beforeClass();

// Env
Config.mv_plan_cache_max_size = 1024;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import com.starrocks.common.Config;
import com.starrocks.qe.SessionVariable;
import com.starrocks.sql.optimizer.CachingMvPlanContextBuilder;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MvRewriteTestBase;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MVTestBase;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;

public class MvRewritePerfTest extends MvRewriteTestBase {
public class MvRewritePerfTest extends MVTestBase {

private static final int MV_NUM = 40;

Expand All @@ -35,7 +36,7 @@ public class MvRewritePerfTest extends MvRewriteTestBase {

@BeforeClass
public static void beforeClass() throws Exception {
MvRewriteTestBase.beforeClass();
MVTestBase.beforeClass();

// Env
Config.mv_plan_cache_max_size = 1024;
Expand Down Expand Up @@ -69,13 +70,19 @@ public static void beforeClass() throws Exception {

@Before
public void before() {
super.before();
starRocksAssert.getCtx().getSessionVariable().setEnableQueryDump(false);
starRocksAssert.getCtx().getSessionVariable().setCboMaterializedViewRewriteRuleOutputLimit(
SessionVariable.DEFAULT_SESSION_VARIABLE.getCboMaterializedViewRewriteRuleOutputLimit());
starRocksAssert.getCtx().getSessionVariable().setCboMaterializedViewRewriteCandidateLimit(
SessionVariable.DEFAULT_SESSION_VARIABLE.getCboMaterializedViewRewriteCandidateLimit());
}

@After
public void after() throws Exception {
super.after();
}

// round: 0.01 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 0, GC.time: 0.00,
// time.total: 0.57, time.warmup: 0.34, time.bench: 0.23
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.starrocks.scheduler.TaskRunBuilder;
import com.starrocks.scheduler.TaskRunScheduler;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MvRewriteTestBase;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MVTestBase;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
Expand All @@ -33,7 +33,7 @@
import org.junit.rules.TestRule;

@Ignore
public class TaskSchedulerBench extends MvRewriteTestBase {
public class TaskSchedulerBench extends MVTestBase {

// private static final int TASK_NUM = Config.task_runs_queue_length;
private static final int TASK_NUM = 10;
Expand All @@ -43,7 +43,7 @@ public class TaskSchedulerBench extends MvRewriteTestBase {

@BeforeClass
public static void beforeClass() throws Exception {
MvRewriteTestBase.beforeClass();
MVTestBase.beforeClass();
Config.task_runs_concurrency = TASK_NUM;
LOG.info("prepared {} tasks", TASK_NUM);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
import com.starrocks.common.Config;
import com.starrocks.sql.optimizer.CachingMvPlanContextBuilder;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MvRewriteTestBase;
import com.starrocks.sql.optimizer.rule.transformation.materialization.MVTestBase;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;

public class ViewBasedMvRewritePerfTest extends MvRewriteTestBase {
public class ViewBasedMvRewritePerfTest extends MVTestBase {

private static final int MV_NUM = 4;

Expand All @@ -34,7 +35,7 @@ public class ViewBasedMvRewritePerfTest extends MvRewriteTestBase {

@BeforeClass
public static void beforeClass() throws Exception {
MvRewriteTestBase.beforeClass();
MVTestBase.beforeClass();

// Env
Config.mv_plan_cache_max_size = 1024;
Expand Down Expand Up @@ -96,10 +97,16 @@ public static void beforeClass() throws Exception {

@Before
public void before() {
super.before();
starRocksAssert.getCtx().getSessionVariable().setEnableQueryDump(false);
connectContext.getSessionVariable().setEnableViewBasedMvRewrite(true);
}

@After
public void after() throws Exception {
super.after();
}

// round: 0.02 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+- 0.00], GC.calls: 1, GC.time: 0.01,
// time.total: 0.35, time.warmup: 0.05, time.bench: 0.30
@Test
Expand Down
Loading
Loading