Skip to content
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
23 changes: 22 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/analysis/SetVar.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@

package org.apache.doris.analysis;

import com.google.common.base.Strings;
import org.apache.doris.catalog.Catalog;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
import org.apache.doris.common.util.ParseUtil;
import org.apache.doris.common.util.TimeUtils;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.mysql.privilege.UserResource;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.GlobalVariable;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.system.HeartbeatFlags;

import com.google.common.base.Strings;

// change one variable.
public class SetVar {

Expand Down Expand Up @@ -125,6 +128,24 @@ public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
throw new AnalysisException("Invalid rowset type, now we support {alpha, beta}.");
}
}

if (getVariable().toLowerCase().equals("prefer_join_method")) {
String value = getValue().getStringValue();
if (!value.toLowerCase().equals("broadcast") && !value.toLowerCase().equals("shuffle")) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_WRONG_VALUE_FOR_VAR, "prefer_join_method", value);
}
}

// Check variable time_zone value is valid
if (getVariable().toLowerCase().equals("time_zone")) {
this.value = new StringLiteral(TimeUtils.checkTimeZoneValidAndStandardize(getValue().getStringValue()));
this.result = (LiteralExpr) this.value;
}

if (getVariable().toLowerCase().equals("exec_mem_limit")) {
this.value = new StringLiteral(Long.toString(ParseUtil.analyzeDataVolumn(getValue().getStringValue())));
this.result = (LiteralExpr) this.value;
}
}

public String toSql() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
import org.apache.doris.persist.DropLinkDbAndUpdateDbInfo;
import org.apache.doris.persist.DropPartitionInfo;
import org.apache.doris.persist.EditLog;
import org.apache.doris.persist.GlobalVarPersistInfo;
import org.apache.doris.persist.ModifyPartitionInfo;
import org.apache.doris.persist.ModifyTablePropertyOperationLog;
import org.apache.doris.persist.OperationType;
Expand Down Expand Up @@ -210,6 +211,8 @@
import org.apache.doris.thrift.TTaskType;
import org.apache.doris.transaction.GlobalTransactionMgr;
import org.apache.doris.transaction.PublishVersionDaemon;
import org.apache.doris.transaction.UpdateDbUsedDataQuotaDaemon;

import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
Expand All @@ -225,7 +228,6 @@
import com.sleepycat.je.rep.NetworkRestoreConfig;

import org.apache.commons.collections.CollectionUtils;
import org.apache.doris.transaction.UpdateDbUsedDataQuotaDaemon;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
Expand Down Expand Up @@ -2230,6 +2232,10 @@ public void replayGlobalVariable(SessionVariable variable) throws IOException, D
VariableMgr.replayGlobalVariable(variable);
}

public void replayGlobalVariableV2(GlobalVarPersistInfo info) throws IOException, DdlException {
VariableMgr.replayGlobalVariableV2(info);
}

public long saveLoadJobsV2(DataOutputStream out, long checksum) throws IOException {
Catalog.getCurrentCatalog().getLoadManager().write(out);
return checksum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ public final class FeMetaVersion {
// force drop db, force drop table, force drop partition
// make force drop operation do not recycle meta
public static final int VERSION_89 = 89;
// for global variable persist
public static final int VERSION_90 = 90;
// note: when increment meta version, should assign the latest version to VERSION_CURRENT
public static final int VERSION_CURRENT = VERSION_89;
public static final int VERSION_CURRENT = VERSION_90;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.VariableMgr;

import com.google.common.base.Preconditions;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.text.ParseException;
Expand Down Expand Up @@ -122,7 +122,7 @@ public static TimeZone getTimeZone() {
if (ConnectContext.get() != null) {
timezone = ConnectContext.get().getSessionVariable().getTimeZone();
} else {
timezone = VariableMgr.getGlobalSessionVariable().getTimeZone();
timezone = VariableMgr.getDefaultSessionVariable().getTimeZone();
}
return TimeZone.getTimeZone(ZoneId.of(timezone, timeZoneAliasMap));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.apache.doris.persist.DropLinkDbAndUpdateDbInfo;
import org.apache.doris.persist.DropPartitionInfo;
import org.apache.doris.persist.DropResourceOperationLog;
import org.apache.doris.persist.GlobalVarPersistInfo;
import org.apache.doris.persist.HbPackage;
import org.apache.doris.persist.ModifyPartitionInfo;
import org.apache.doris.persist.ModifyTablePropertyOperationLog;
Expand Down Expand Up @@ -581,6 +582,11 @@ public void readFields(DataInput in) throws IOException {
isRead = true;
break;
}
case OperationType.OP_GLOBAL_VARIABLE_V2: {
data = GlobalVarPersistInfo.read(in);
isRead = true;
break;
}
default: {
IOException e = new IOException();
LOG.error("UNKNOWN Operation Type {}", opCode, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ public static void loadJournal(Catalog catalog, JournalEntity journal) {
catalog.getRoutineLoadManager().replayAlterRoutineLoadJob(log);
break;
}
case OperationType.OP_GLOBAL_VARIABLE_V2: {
GlobalVarPersistInfo info = (GlobalVarPersistInfo) journal.getData();
catalog.replayGlobalVariableV2(info);
break;
}
default: {
IOException e = new IOException();
LOG.error("UNKNOWN Operation Type {}", opCode, e);
Expand Down Expand Up @@ -1355,4 +1360,8 @@ public void logRemoveExpiredAlterJobV2(RemoveAlterJobV2OperationLog log) {
public void logAlterRoutineLoadJob(AlterRoutineLoadJobOperationLog log) {
logEdit(OperationType.OP_ALTER_ROUTINE_LOAD_JOB, log);
}

public void logGlobalVariableV2(GlobalVarPersistInfo info) {
logEdit(OperationType.OP_GLOBAL_VARIABLE_V2, info);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.persist;

import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.qe.GlobalVariable;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.qe.VariableMgr;

import com.google.common.base.Preconditions;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;

// for persist global variables
public class GlobalVarPersistInfo implements Writable {
private static final Logger LOG = LogManager.getLogger(GlobalVarPersistInfo.class);
// current default session variable when writing the edit log
private SessionVariable defaultSessionVariable;
// variable names which are modified
private List<String> varNames;

// the modified variable info will be saved as a json string
private String persistJsonString;

private GlobalVarPersistInfo() {
// for persist
}

public GlobalVarPersistInfo(SessionVariable defaultSessionVariable, List<String> varNames) {
this.defaultSessionVariable = defaultSessionVariable;
this.varNames = varNames;
}

public String getPersistJsonString() {
return persistJsonString;
}

@Override
public void write(DataOutput out) throws IOException {
try {
JSONObject root = new JSONObject();
for (String varName : varNames) {
// find attr in defaultSessionVariable or GlobalVariables
Object varInstance = null;
Field theField = null;
boolean found = false;
// 1. first find in defaultSessionVariable
for (Field field : SessionVariable.class.getDeclaredFields()) {
VariableMgr.VarAttr attr = field.getAnnotation(VariableMgr.VarAttr.class);
if (attr == null) {
continue;
}
if (attr.name().equalsIgnoreCase(varName)) {
varInstance = this.defaultSessionVariable;
theField = field;
found = true;
break;
}
}

if (!found) {
// find in GlobalVariables
for (Field field : GlobalVariable.class.getDeclaredFields()) {
VariableMgr.VarAttr attr = field.getAnnotation(VariableMgr.VarAttr.class);
if (attr == null) {
continue;
}

if (attr.name().equalsIgnoreCase(varName)) {
found = true;
varInstance = null;
theField = field;
break;
}
}
}
Preconditions.checkState(found, varName);

theField.setAccessible(true);
String fieldName = theField.getAnnotation(VariableMgr.VarAttr.class).name();
switch (theField.getType().getSimpleName()) {
case "boolean":
root.put(fieldName, (Boolean) theField.get(varInstance));
break;
case "int":
root.put(fieldName, (Integer) theField.get(varInstance));
break;
case "long":
root.put(fieldName, (Long) theField.get(varInstance));
break;
case "float":
root.put(fieldName, (Float) theField.get(varInstance));
break;
case "double":
root.put(fieldName, (Double) theField.get(varInstance));
break;
case "String":
root.put(fieldName, (String) theField.get(varInstance));
break;
default:
// Unsupported type variable.
throw new IOException("invalid type: " + theField.getType().getSimpleName());
}
} // end for all variables

Text.writeString(out, root.toString());
} catch (Exception e) {
throw new IOException("failed to write session variable: " + e.getMessage());
}
}

public static GlobalVarPersistInfo read(DataInput in) throws IOException {
GlobalVarPersistInfo info = new GlobalVarPersistInfo();
info.persistJsonString = Text.readString(in);
return info;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public class OperationType {
public static final short OP_TIMESTAMP = 70;
public static final short OP_MASTER_INFO_CHANGE = 71;
public static final short OP_META_VERSION = 72;

@Deprecated
// replaced by OP_GLOBAL_VARIABLE_V2
public static final short OP_GLOBAL_VARIABLE = 73;

public static final short OP_CREATE_CLUSTER = 74;
Expand All @@ -117,6 +118,7 @@ public class OperationType {
public static final short OP_SHOW_CLUSTERS = 80;
public static final short OP_UPDATE_DB = 82;
public static final short OP_DROP_LINKDB = 83;
public static final short OP_GLOBAL_VARIABLE_V2 = 84;

public static final short OP_ADD_BROKER = 85;
public static final short OP_DROP_BROKER = 86;
Expand Down
17 changes: 17 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/qe/GlobalVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import org.apache.doris.common.Version;
import org.apache.doris.common.util.TimeUtils;

import com.google.common.collect.Lists;

import java.lang.reflect.Field;
import java.util.List;

// You can place your global variable in this class with public and VariableMgr.VarAttr annotation.
// You can get this variable from MySQL client with statement `SELECT @@variable_name`,
// and change its value through `SET variable_name = xxx`
Expand Down Expand Up @@ -73,4 +78,16 @@ public final class GlobalVariable {
private GlobalVariable() {

}

public static List<String> getAllGlobalVarNames() {
List<String> varNames = Lists.newArrayList();
for (Field field : GlobalVariable.class.getDeclaredFields()) {
VariableMgr.VarAttr attr = field.getAnnotation(VariableMgr.VarAttr.class);
if (attr == null || attr.flag() != VariableMgr.GLOBAL) {
continue;
}
varNames.add(attr.name());
}
return varNames;
}
}
Loading