[opt](session var) throw exception when setting query time out to zero (#28247)
This commit is contained in:
@ -1048,7 +1048,7 @@ public enum ErrorCode {
|
||||
ERR_BAD_PARTITION_STATE(5015, new byte[] {'H', 'Y', '0', '0', '0'}, "Partition state is not NORMAL: '%s':'%s'"),
|
||||
ERR_PARTITION_HAS_LOADING_JOBS(5016, new byte[] {'H', 'Y', '0', '0', '0'}, "Partition has loading jobs: '%s'"),
|
||||
ERR_NOT_KEY_COLUMN(5017, new byte[] {'H', 'Y', '0', '0', '0'}, "Column is not a key column: '%s'"),
|
||||
ERR_INVALID_VALUE(5018, new byte[] {'H', 'Y', '0', '0', '0'}, "Invalid value format: '%s'"),
|
||||
ERR_INVALID_VALUE(5018, new byte[] {'H', 'Y', '0', '0', '0'}, "Value '%s' of '%s' is invalid, '%s'"),
|
||||
ERR_REPLICA_NOT_CATCH_UP_WITH_VERSION(5019, new byte[] {'H', 'Y', '0', '0', '0'},
|
||||
"Replica does not catch up with version: '%s':'%s'"),
|
||||
ERR_BACKEND_OFFLINE(5021, new byte[] {'H', 'Y', '0', '0', '0'}, "Backend is offline: '%s'"),
|
||||
|
||||
@ -56,6 +56,7 @@ public class AcceptListener implements ChannelListener<AcceptingChannel<StreamCo
|
||||
// connection has been established, so need to call context.cleanup()
|
||||
// if exception happens.
|
||||
ConnectContext context = new ConnectContext(connection);
|
||||
LOG.info("Connection query timeout: {}", context.getSessionVariable().getQueryTimeoutS());
|
||||
context.setEnv(Env.getCurrentEnv());
|
||||
connectScheduler.submit(context);
|
||||
|
||||
@ -80,6 +81,8 @@ public class AcceptListener implements ChannelListener<AcceptingChannel<StreamCo
|
||||
context.setStartTime();
|
||||
context.setUserQueryTimeout(
|
||||
context.getEnv().getAuth().getQueryTimeout(context.getQualifiedUser()));
|
||||
LOG.info("Connection set query timeout {}",
|
||||
context.getSessionVariable().getQueryTimeoutS());
|
||||
context.setUserInsertTimeout(
|
||||
context.getEnv().getAuth().getInsertTimeout(context.getQualifiedUser()));
|
||||
ConnectProcessor processor = new MysqlConnectProcessor(context);
|
||||
|
||||
@ -25,6 +25,8 @@ import org.apache.doris.resource.workloadgroup.WorkloadGroupMgr;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@ -35,6 +37,8 @@ import java.util.Set;
|
||||
* Used in
|
||||
*/
|
||||
public class CommonUserProperties implements Writable {
|
||||
private static final Logger LOG = LogManager.getLogger(CommonUserProperties.class);
|
||||
|
||||
// The max connections allowed for a user on one FE
|
||||
@SerializedName("maxConn")
|
||||
private long maxConn = 100;
|
||||
@ -126,6 +130,9 @@ public class CommonUserProperties implements Writable {
|
||||
}
|
||||
|
||||
public void setQueryTimeout(int timeout) {
|
||||
if (timeout <= 0) {
|
||||
LOG.warn("Setting 0 query timeout", new RuntimeException(""));
|
||||
}
|
||||
this.queryTimeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
@ -529,8 +529,8 @@ public class SessionVariable implements Serializable, Writable {
|
||||
private long defaultOrderByLimit = -1;
|
||||
|
||||
// query timeout in second.
|
||||
@VariableMgr.VarAttr(name = QUERY_TIMEOUT)
|
||||
public int queryTimeoutS = 900;
|
||||
@VariableMgr.VarAttr(name = QUERY_TIMEOUT, checker = "checkQueryTimeoutValid", setter = "setQueryTimeoutS")
|
||||
private int queryTimeoutS = 900;
|
||||
|
||||
// query timeout in second.
|
||||
@VariableMgr.VarAttr(name = ANALYZE_TIMEOUT, flag = VariableMgr.GLOBAL, needForward = true)
|
||||
@ -1851,9 +1851,25 @@ public class SessionVariable implements Serializable, Writable {
|
||||
}
|
||||
|
||||
public void setQueryTimeoutS(int queryTimeoutS) {
|
||||
if (queryTimeoutS <= 0) {
|
||||
LOG.warn("Setting invalid query timeout", new RuntimeException(""));
|
||||
}
|
||||
this.queryTimeoutS = queryTimeoutS;
|
||||
}
|
||||
|
||||
// This method will be called by VariableMgr.replayGlobalVariableV2
|
||||
// We dont want any potential exception is thrown during replay oplog
|
||||
// so we do not check its validation. Here potential excaption
|
||||
// will become real in cases where user set global query timeout 0 before
|
||||
// upgrading to this version.
|
||||
public void setQueryTimeoutS(String queryTimeoutS) {
|
||||
int newQueryTimeoutS = Integer.valueOf(queryTimeoutS);
|
||||
if (newQueryTimeoutS <= 0) {
|
||||
LOG.warn("Invalid query timeout: {}", newQueryTimeoutS, new RuntimeException(""));
|
||||
}
|
||||
this.queryTimeoutS = newQueryTimeoutS;
|
||||
}
|
||||
|
||||
public void setAnalyzeTimeoutS(int analyzeTimeoutS) {
|
||||
this.analyzeTimeoutS = analyzeTimeoutS;
|
||||
}
|
||||
@ -1861,11 +1877,17 @@ public class SessionVariable implements Serializable, Writable {
|
||||
public void setMaxExecutionTimeMS(int maxExecutionTimeMS) {
|
||||
this.maxExecutionTimeMS = maxExecutionTimeMS;
|
||||
this.queryTimeoutS = this.maxExecutionTimeMS / 1000;
|
||||
if (queryTimeoutS <= 0) {
|
||||
LOG.warn("Invalid query timeout: {}", queryTimeoutS, new RuntimeException(""));
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxExecutionTimeMS(String maxExecutionTimeMS) {
|
||||
this.maxExecutionTimeMS = Integer.valueOf(maxExecutionTimeMS);
|
||||
this.queryTimeoutS = this.maxExecutionTimeMS / 1000;
|
||||
if (queryTimeoutS <= 0) {
|
||||
LOG.warn("Invalid query timeout: {}", queryTimeoutS, new RuntimeException(""));
|
||||
}
|
||||
}
|
||||
|
||||
public void setPipelineTaskNum(String value) throws Exception {
|
||||
@ -2497,6 +2519,14 @@ public class SessionVariable implements Serializable, Writable {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkQueryTimeoutValid(String newQueryTimeout) {
|
||||
int value = Integer.valueOf(newQueryTimeout);
|
||||
if (value <= 0) {
|
||||
LOG.warn("Setting invalid query timeout {}", value, new RuntimeException(""));
|
||||
throw new UnsupportedOperationException("Query timeout must be greater than 0");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnableFileCache() {
|
||||
return enableFileCache;
|
||||
}
|
||||
|
||||
@ -162,8 +162,11 @@ public class VariableMgr {
|
||||
Preconditions.checkArgument(obj instanceof SessionVariable);
|
||||
try {
|
||||
SessionVariable.class.getDeclaredMethod(attr.checker(), String.class).invoke(obj, value);
|
||||
} catch (InvocationTargetException e) {
|
||||
// Exception thrown from reflect method will always be InvocationTargetException
|
||||
ErrorReport.reportDdlException(((InvocationTargetException) e).getTargetException().getMessage());
|
||||
} catch (Exception e) {
|
||||
ErrorReport.reportDdlException(ErrorCode.ERR_INVALID_VALUE, attr.name(), value, e.getMessage());
|
||||
ErrorReport.reportDdlException(ErrorCode.ERR_INVALID_VALUE, value, attr.name(), e.getMessage());
|
||||
}
|
||||
}
|
||||
// If the session variable has specified the setter, then not use reflect
|
||||
@ -174,7 +177,7 @@ public class VariableMgr {
|
||||
} catch (InvocationTargetException e) {
|
||||
ErrorReport.reportDdlException(((InvocationTargetException) e).getTargetException().getMessage());
|
||||
} catch (Exception e) {
|
||||
ErrorReport.reportDdlException(ErrorCode.ERR_INVALID_VALUE, attr.name(), value, e.getMessage());
|
||||
ErrorReport.reportDdlException(ErrorCode.ERR_INVALID_VALUE, value, attr.name(), e.getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
||||
@ -184,7 +184,7 @@ public class StatisticsUtil {
|
||||
sessionVariable.setEnablePipelineEngine(false);
|
||||
sessionVariable.enableProfile = false;
|
||||
sessionVariable.enableScanRunSerial = limitScan;
|
||||
sessionVariable.queryTimeoutS = StatisticsUtil.getAnalyzeTimeout();
|
||||
sessionVariable.setQueryTimeoutS(StatisticsUtil.getAnalyzeTimeout());
|
||||
sessionVariable.insertTimeoutS = StatisticsUtil.getAnalyzeTimeout();
|
||||
sessionVariable.enableFileCache = false;
|
||||
sessionVariable.forbidUnknownColStats = false;
|
||||
|
||||
Reference in New Issue
Block a user