From 5731d82805cca6cea68a874bf2d377a8fbf5b22c Mon Sep 17 00:00:00 2001 From: Lei Zhang <27994433+SWJTU-ZhangLei@users.noreply.github.com> Date: Sun, 18 Feb 2024 20:55:28 +0800 Subject: [PATCH] [fix](fe) Fix `UnsetVariableStmt` write editlog in non master node * Problem introduced by https://github.com/apache/doris/pull/27552 --- .../org/apache/doris/qe/StmtExecutor.java | 14 +++++++++++++ .../java/org/apache/doris/qe/VariableMgr.java | 20 +++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index 5c89a5c0590934..94190b2b3d13fd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -56,6 +56,7 @@ import org.apache.doris.analysis.SelectStmt; import org.apache.doris.analysis.SetOperationStmt; import org.apache.doris.analysis.SetStmt; +import org.apache.doris.analysis.SetType; import org.apache.doris.analysis.SetVar; import org.apache.doris.analysis.SetVar.SetVarType; import org.apache.doris.analysis.ShowStmt; @@ -936,6 +937,19 @@ private void forwardToMaster() throws Exception { for (SetVar var : setStmt.getSetVars()) { VariableMgr.setVarForNonMasterFE(context.getSessionVariable(), var); } + } else if (parsedStmt instanceof UnsetVariableStmt) { + UnsetVariableStmt unsetStmt = (UnsetVariableStmt) parsedStmt; + if (unsetStmt.isApplyToAll()) { + VariableMgr.setAllVarsToDefaultValue(context.getSessionVariable(), SetType.SESSION); + } else { + String defaultValue = VariableMgr.getDefaultValue(unsetStmt.getVariable()); + if (defaultValue == null) { + ErrorReport.reportDdlException(ErrorCode.ERR_UNKNOWN_SYSTEM_VARIABLE, unsetStmt.getVariable()); + } + SetVar var = new SetVar(SetType.SESSION, unsetStmt.getVariable(), + new StringLiteral(defaultValue), SetVarType.SET_SESSION_VAR); + VariableMgr.setVar(context.getSessionVariable(), var); + } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java index 84dfcef543d3b4..b1195e405c3b28 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/VariableMgr.java @@ -713,21 +713,15 @@ public static void setAllVarsToDefaultValue(SessionVariable sessionVariable, Set throws DdlException { for (Map.Entry entry : ctxByDisplayVarName.entrySet()) { VarContext varCtx = entry.getValue(); - - SetType newSetType = null; - // some variables are GLOBAL only or SESSION only - if ((varCtx.getFlag() & GLOBAL) != 0) { - newSetType = SetType.GLOBAL; - } else if ((varCtx.getFlag() & SESSION_ONLY) != 0) { - newSetType = SetType.SESSION; - } - - SetVar setVar = new SetVar(newSetType != null ? newSetType : setType, entry.getKey(), + SetVar setVar = new SetVar(setType, entry.getKey(), new StringLiteral(varCtx.defaultValue), SetVarType.SET_SESSION_VAR); - //skip read only variables - if ((varCtx.getFlag() & READ_ONLY) == 0) { - setVar(sessionVariable, setVar); + try { + checkUpdate(setVar, varCtx.getFlag()); + } catch (DdlException e) { + LOG.debug("no need to set var for non master fe: {}", setVar.getVariable(), e); + continue; } + setVarInternal(sessionVariable, setVar, varCtx); } }