Skip to content

Commit

Permalink
[refactor](fe) remove some forward session var logic (#47649)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiguolei authored Feb 9, 2025
1 parent 853e99b commit 89c3e91
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 74 deletions.
32 changes: 0 additions & 32 deletions fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,38 +599,6 @@ public TMasterOpResult proxyExecute(TMasterOpRequest request) throws TException

if (request.isSetSessionVariables()) {
ctx.getSessionVariable().setForwardedSessionVariables(request.getSessionVariables());
} else {
// For compatibility, all following variables are moved to SessionVariables.
// Should move in future.
if (request.isSetTimeZone()) {
ctx.getSessionVariable().setTimeZone(request.getTimeZone());
}
if (request.isSetSqlMode()) {
ctx.getSessionVariable().setSqlMode(request.sqlMode);
}
if (request.isSetEnableStrictMode()) {
ctx.getSessionVariable().setEnableInsertStrict(request.enableStrictMode);
}
if (request.isSetCurrentUserIdent()) {
UserIdentity currentUserIdentity = UserIdentity.fromThrift(request.getCurrentUserIdent());
ctx.setCurrentUserIdentity(currentUserIdentity);
}
if (request.isSetInsertVisibleTimeoutMs()) {
ctx.getSessionVariable().setInsertVisibleTimeoutMs(request.getInsertVisibleTimeoutMs());
}
}

if (request.isSetQueryOptions()) {
ctx.getSessionVariable().setForwardedSessionVariables(request.getQueryOptions());
} else {
// For compatibility, all following variables are moved to TQueryOptions.
// Should move in future.
if (request.isSetExecMemLimit()) {
ctx.getSessionVariable().setMaxExecMemByte(request.getExecMemLimit());
}
if (request.isSetQueryTimeout()) {
ctx.getSessionVariable().setQueryTimeoutS(request.getQueryTimeout());
}
}

if (request.isSetUserVariables()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ private TMasterOpRequest buildStmtForwardParams() {
if (!Strings.isNullOrEmpty(cluster)) {
params.setCloudCluster(cluster);
}

// query options
params.setQueryOptions(ctx.getSessionVariable().getQueryOptionVariables());
// session variables
params.setSessionVariables(ctx.getSessionVariable().getForwardVariables());
params.setUserVariables(getForwardUserVariables(ctx.getUserVars()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ private TMasterOpRequest buildStmtForwardParams() throws AnalysisException {
}
}

// query options
params.setQueryOptions(ctx.getSessionVariable().getQueryOptionVariables());
// session variables
params.setSessionVariables(ctx.getSessionVariable().getForwardVariables());
params.setUserVariables(getForwardUserVariables(ctx.getUserVars()));
Expand Down
26 changes: 5 additions & 21 deletions fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,10 @@ public class SessionVariable implements Serializable, Writable {
public long insertVisibleTimeoutMs = DEFAULT_INSERT_VISIBLE_TIMEOUT_MS;

// max memory used on every backend.
@VariableMgr.VarAttr(name = EXEC_MEM_LIMIT)
@VariableMgr.VarAttr(name = EXEC_MEM_LIMIT, needForward = true)
public long maxExecMemByte = 2147483648L;

@VariableMgr.VarAttr(name = SCAN_QUEUE_MEM_LIMIT,
@VariableMgr.VarAttr(name = SCAN_QUEUE_MEM_LIMIT, needForward = true,
description = {"每个 Scan Instance 的 block queue 能够保存多少字节的 block",
"How many bytes of block can be saved in the block queue of each Scan Instance"})
// 100MB
Expand Down Expand Up @@ -784,7 +784,8 @@ public class SessionVariable implements Serializable, Writable {
private long defaultOrderByLimit = -1;

// query timeout in second.
@VariableMgr.VarAttr(name = QUERY_TIMEOUT, checker = "checkQueryTimeoutValid", setter = "setQueryTimeoutS")
@VariableMgr.VarAttr(name = QUERY_TIMEOUT, needForward = true,
checker = "checkQueryTimeoutValid", setter = "setQueryTimeoutS")
private int queryTimeoutS = 900;

// query timeout in second.
Expand All @@ -804,7 +805,7 @@ public class SessionVariable implements Serializable, Writable {
setter = "setMaxExecutionTimeMS")
public int maxExecutionTimeMS = 900000;

@VariableMgr.VarAttr(name = INSERT_TIMEOUT)
@VariableMgr.VarAttr(name = INSERT_TIMEOUT, needForward = true)
public int insertTimeoutS = 14400;

// if true, need report to coordinator when plan fragment execute successfully.
Expand Down Expand Up @@ -4197,23 +4198,6 @@ public void setForwardedSessionVariables(TQueryOptions queryOptions) {
}
}

/**
* Get all variables which need to be set in TQueryOptions.
**/
public TQueryOptions getQueryOptionVariables() {
TQueryOptions queryOptions = new TQueryOptions();
queryOptions.setMemLimit(maxExecMemByte);
queryOptions.setScanQueueMemLimit(maxScanQueueMemByte);
queryOptions.setNumScannerThreads(numScannerThreads);
queryOptions.setMinScannerConcurrency(minScannerConcurrency);
queryOptions.setMinScanSchedulerConcurrency(minScanSchedulerConcurrency);
queryOptions.setQueryTimeout(queryTimeoutS);
queryOptions.setInsertTimeout(insertTimeoutS);
queryOptions.setAnalyzeTimeout(analyzeTimeoutS);
queryOptions.setBeExecVersion(Config.be_exec_version);
return queryOptions;
}

/**
* The sessionContext is as follows:
* "k1:v1;k2:v2;..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void testPutBackExprs() throws Exception {
+ " (SELECT curdate()) a;";
StatementBase stmt = UtFrameUtils.parseAndAnalyzeStmt(sql, ctx);
SessionVariable sessionVariable = new SessionVariable();
TQueryOptions queryOptions = sessionVariable.getQueryOptionVariables();
TQueryOptions queryOptions = sessionVariable.toThrift();
stmt.foldConstant(new Analyzer(ctx.getEnv(), ctx).getExprRewriter(), queryOptions);

// reAnalyze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.doris.common.PatternMatcherWrapper;
import org.apache.doris.common.VariableAnnotation;
import org.apache.doris.nereids.parser.NereidsParser;
import org.apache.doris.thrift.TQueryOptions;
import org.apache.doris.utframe.TestWithFeService;

import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -141,20 +140,6 @@ public void testForwardSessionVariables() {
Assertions.assertTrue(sessionVariable.enableProfile);
}

@Test
public void testForwardQueryOptions() {
TQueryOptions queryOptions = sessionVariable.getQueryOptionVariables();
Assertions.assertTrue(queryOptions.isSetMemLimit());
Assertions.assertFalse(queryOptions.isSetLoadMemLimit());
Assertions.assertTrue(queryOptions.isSetQueryTimeout());

queryOptions.setQueryTimeout(123);
queryOptions.setInsertTimeout(123);
sessionVariable.setForwardedSessionVariables(queryOptions);
Assertions.assertEquals(123, sessionVariable.getQueryTimeoutS());
Assertions.assertEquals(123, sessionVariable.getInsertTimeoutS());
}

@Test
public void testCloneSessionVariablesWithSessionOriginValueNotEmpty() throws NoSuchFieldException {
Field txIsolation = SessionVariable.class.getField("txIsolation");
Expand Down

0 comments on commit 89c3e91

Please sign in to comment.