This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 24f2511a39bff7ca8e6fc0cfc39f8865b1723c5c Author: wxy <[email protected]> AuthorDate: Thu Jan 19 08:06:39 2023 +0800 [Fix](profile) do not send export profile when enable_profile=false. (#15996) --- .../main/java/org/apache/doris/load/ExportJob.java | 10 +- .../org/apache/doris/task/ExportExportingTask.java | 3 + .../org/apache/doris/qe/SessionVariablesTest.java | 131 ++++++++++++++++++--- 3 files changed, 125 insertions(+), 19 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/load/ExportJob.java b/fe/fe-core/src/main/java/org/apache/doris/load/ExportJob.java index a7f6bef921..3b79ca70de 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/load/ExportJob.java +++ b/fe/fe-core/src/main/java/org/apache/doris/load/ExportJob.java @@ -129,12 +129,11 @@ public class ExportJob implements Writable { private String lineDelimiter; private Map<String, String> properties = Maps.newHashMap(); private List<String> partitions; - private TableName tableName; - private String sql = ""; - private JobState state; + // If set to true, the profile of export job with be pushed to ProfileManager + private volatile boolean enableProfile = false; private long createTimeMs; private long startTimeMs; private long finishTimeMs; @@ -239,6 +238,7 @@ public class ExportJob implements Writable { if (ConnectContext.get() != null) { SessionVariable var = ConnectContext.get().getSessionVariable(); this.sessionVariables.put(SessionVariable.SQL_MODE, Long.toString(var.getSqlMode())); + this.enableProfile = var.enableProfile(); } else { this.sessionVariables.put(SessionVariable.SQL_MODE, String.valueOf(SqlModeHelper.MODE_DEFAULT)); } @@ -751,6 +751,10 @@ public class ExportJob implements Writable { return queryId; } + public boolean getEnableProfile() { + return enableProfile; + } + @Override public String toString() { return "ExportJob [jobId=" + id diff --git a/fe/fe-core/src/main/java/org/apache/doris/task/ExportExportingTask.java b/fe/fe-core/src/main/java/org/apache/doris/task/ExportExportingTask.java index fe6dde27fb..7d6a3b3c74 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/task/ExportExportingTask.java +++ b/fe/fe-core/src/main/java/org/apache/doris/task/ExportExportingTask.java @@ -271,6 +271,9 @@ public class ExportExportingTask extends MasterTask { } private void registerProfile() { + if (!job.getEnableProfile()) { + return; + } initProfile(); for (RuntimeProfile p : fragmentProfiles) { profile.addChild(p); diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java index c1911cc687..947e83d95d 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java @@ -17,24 +17,39 @@ package org.apache.doris.qe; +import org.apache.doris.analysis.ExportStmt; +import org.apache.doris.analysis.SetStmt; +import org.apache.doris.common.FeConstants; +import org.apache.doris.common.util.ProfileManager; +import org.apache.doris.common.util.RuntimeProfile; +import org.apache.doris.load.ExportJob; +import org.apache.doris.task.ExportExportingTask; import org.apache.doris.thrift.TQueryOptions; +import org.apache.doris.utframe.TestWithFeService; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import com.google.common.collect.Lists; +import mockit.Expectations; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.lang.reflect.Field; import java.util.Map; -public class SessionVariablesTest { +public class SessionVariablesTest extends TestWithFeService { - private static SessionVariable sessionVariable; - private static int numOfForwardVars; + private SessionVariable sessionVariable; + private int numOfForwardVars; + private ProfileManager profileManager = ProfileManager.getInstance(); - @BeforeClass - public static void beforeClass() throws Exception { - sessionVariable = new SessionVariable(); + @Override + protected void runBeforeAll() throws Exception { + FeConstants.runningUnitTest = true; + createDatabase("test_d"); + useDatabase("test_d"); + createTable("create table test_t1 \n" + "(k1 int, k2 int) distributed by hash(k1) buckets 1\n" + + "properties(\"replication_num\" = \"1\");"); + sessionVariable = new SessionVariable(); Field[] fields = SessionVariable.class.getFields(); for (Field f : fields) { VariableMgr.VarAttr varAttr = f.getAnnotation(VariableMgr.VarAttr.class); @@ -48,23 +63,107 @@ public class SessionVariablesTest { @Test public void testForwardSessionVariables() { Map<String, String> vars = sessionVariable.getForwardVariables(); - Assert.assertTrue(numOfForwardVars >= 6); - Assert.assertEquals(numOfForwardVars, vars.size()); + Assertions.assertTrue(numOfForwardVars >= 6); + Assertions.assertEquals(numOfForwardVars, vars.size()); vars.put(SessionVariable.ENABLE_PROFILE, "true"); sessionVariable.setForwardedSessionVariables(vars); - Assert.assertEquals(true, sessionVariable.enableProfile); + Assertions.assertEquals(true, sessionVariable.enableProfile); } @Test public void testForwardQueryOptions() { TQueryOptions queryOptions = sessionVariable.getQueryOptionVariables(); - Assert.assertTrue(queryOptions.isSetMemLimit()); - Assert.assertFalse(queryOptions.isSetLoadMemLimit()); - Assert.assertTrue(queryOptions.isSetQueryTimeout()); + Assertions.assertTrue(queryOptions.isSetMemLimit()); + Assertions.assertFalse(queryOptions.isSetLoadMemLimit()); + Assertions.assertTrue(queryOptions.isSetQueryTimeout()); queryOptions.setQueryTimeout(123); sessionVariable.setForwardedSessionVariables(queryOptions); - Assert.assertEquals(123, sessionVariable.getQueryTimeoutS()); + Assertions.assertEquals(123, sessionVariable.getQueryTimeoutS()); + } + + @Test + public void testEnableProfile() { + try { + SetStmt setStmt = (SetStmt) parseAndAnalyzeStmt("set enable_profile=true", connectContext); + SetExecutor setExecutor = new SetExecutor(connectContext, setStmt); + setExecutor.execute(); + + ExportStmt exportStmt = (ExportStmt) + parseAndAnalyzeStmt("EXPORT TABLE test_d.test_t1 TO \"file:///tmp/test_t1\"", connectContext); + ExportJob job = new ExportJob(1234); + job.setJob(exportStmt); + + new Expectations(job) { + { + job.getState(); + minTimes = 0; + result = ExportJob.JobState.EXPORTING; + + job.getCoordList(); + minTimes = 0; + result = Lists.newArrayList(); + } + }; + + new Expectations(profileManager) { + { + profileManager.pushProfile((RuntimeProfile) any); + // if enable_profile=true, method pushProfile will be called once + times = 1; + } + }; + + ExportExportingTask task = new ExportExportingTask(job); + task.run(); + Assertions.assertTrue(job.isFinalState()); + } catch (Exception e) { + e.printStackTrace(); + Assertions.fail(e.getMessage()); + } + + } + + @Test + public void testDisableProfile() { + try { + SetStmt setStmt = (SetStmt) parseAndAnalyzeStmt("set enable_profile=false", connectContext); + SetExecutor setExecutor = new SetExecutor(connectContext, setStmt); + setExecutor.execute(); + + ExportStmt exportStmt = (ExportStmt) + parseAndAnalyzeStmt("EXPORT TABLE test_d.test_t1 TO \"file:///tmp/test_t1\"", connectContext); + ExportJob job = new ExportJob(1234); + job.setJob(exportStmt); + + new Expectations(job) { + { + job.getState(); + minTimes = 0; + result = ExportJob.JobState.EXPORTING; + + job.getCoordList(); + minTimes = 0; + result = Lists.newArrayList(); + } + }; + + new Expectations(profileManager) { + { + profileManager.pushProfile((RuntimeProfile) any); + // if enable_profile=false, method pushProfile will not be called + times = 0; + } + }; + + ExportExportingTask task = new ExportExportingTask(job); + task.run(); + Assertions.assertTrue(job.isFinalState()); + } catch (Exception e) { + e.printStackTrace(); + Assertions.fail(e.getMessage()); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
