Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature](show) show backend config using ShowStmt #36525

Merged
merged 6 commits into from
Aug 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ statement
| DROP (PROCEDURE | PROC) (IF EXISTS)? name=multipartIdentifier #dropProcedure
| SHOW PROCEDURE STATUS (LIKE pattern=valueExpression | whereClause)? #showProcedureStatus
| SHOW CREATE PROCEDURE name=multipartIdentifier #showCreateProcedure
| ADMIN? SHOW type=(FRONTEND | BACKEND) CONFIG (LIKE pattern=valueExpression)? (FROM backendId=INTEGER_VALUE)? #showConfig
;

statementBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ stmt :
| drop_procedure_stmt
| show_procedure_stmt
| show_create_procedure_stmt
| show_config_stmt
| exec_stmt
| exit_stmt
| fetch_stmt
Expand Down Expand Up @@ -343,6 +344,10 @@ show_create_procedure_stmt:
SHOW CREATE PROCEDURE name=multipartIdentifier
;

show_config_stmt:
SHOW type=(FRONTEND | BACKEND) CONFIG (LIKE pattern=valueExpression)? (FROM backendId=INTEGER_VALUE)?
;

create_routine_params :
LEFT_PAREN RIGHT_PAREN
| LEFT_PAREN create_routine_param_item (COMMA create_routine_param_item)* RIGHT_PAREN
Expand Down
27 changes: 22 additions & 5 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import org.apache.doris.load.loadv2.LoadTask;
import org.apache.doris.policy.PolicyTypeEnum;
import org.apache.doris.resource.workloadschedpolicy.WorkloadConditionMeta;
import org.apache.doris.resource.workloadschedpolicy.WorkloadActionMeta;
import org.apache.doris.system.NodeType;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -4711,7 +4712,15 @@ show_param ::=
:}
| KW_FRONTEND KW_CONFIG opt_wild_where
{:
RESULT = new ShowConfigStmt(AdminSetConfigStmt.ConfigType.FRONTEND, parser.wild);
RESULT = new ShowConfigStmt(NodeType.FRONTEND, parser.wild);
:}
| KW_BACKEND KW_CONFIG opt_wild_where
{:
RESULT = new ShowConfigStmt(NodeType.BACKEND, parser.wild);
:}
| KW_BACKEND KW_CONFIG opt_wild_where KW_FROM INTEGER_LITERAL:backendId
{:
RESULT = new ShowConfigStmt(NodeType.BACKEND, parser.wild, backendId);
:}
| KW_TABLET KW_STORAGE KW_FORMAT
{:
Expand Down Expand Up @@ -7850,20 +7859,28 @@ admin_stmt ::=
:}
| KW_ADMIN KW_SET KW_FRONTEND KW_CONFIG opt_key_value_map:configs
{:
RESULT = new AdminSetConfigStmt(AdminSetConfigStmt.ConfigType.FRONTEND, configs, false);
RESULT = new AdminSetConfigStmt(NodeType.FRONTEND, configs, false);
:}
| KW_ADMIN KW_SET KW_ALL KW_FRONTENDS KW_CONFIG opt_key_value_map:configs
{:
RESULT = new AdminSetConfigStmt(AdminSetConfigStmt.ConfigType.FRONTEND, configs, true);
RESULT = new AdminSetConfigStmt(NodeType.FRONTEND, configs, true);
:}
| KW_ADMIN KW_SET KW_FRONTEND KW_CONFIG opt_key_value_map:configs KW_ALL
{:
RESULT = new AdminSetConfigStmt(AdminSetConfigStmt.ConfigType.FRONTEND, configs, true);
RESULT = new AdminSetConfigStmt(NodeType.FRONTEND, configs, true);
:}
// deprecated
| KW_ADMIN KW_SHOW KW_FRONTEND KW_CONFIG opt_wild_where
{:
RESULT = new ShowConfigStmt(AdminSetConfigStmt.ConfigType.FRONTEND, parser.wild);
RESULT = new ShowConfigStmt(NodeType.FRONTEND, parser.wild);
:}
| KW_ADMIN KW_SHOW KW_BACKEND KW_CONFIG opt_wild_where
{:
RESULT = new ShowConfigStmt(NodeType.BACKEND, parser.wild);
:}
| KW_ADMIN KW_SHOW KW_BACKEND KW_CONFIG opt_wild_where KW_FROM INTEGER_LITERAL:backendId
{:
RESULT = new ShowConfigStmt(NodeType.BACKEND, parser.wild, backendId);
:}
| KW_ADMIN KW_CHECK KW_TABLET LPAREN integer_list:tabletIds RPAREN opt_properties:properties
{:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.OriginStatement;
import org.apache.doris.system.NodeType;

import com.google.common.collect.Maps;

Expand All @@ -34,18 +35,13 @@
// admin set frontend config ("key" = "value");
public class AdminSetConfigStmt extends DdlStmt {

public enum ConfigType {
FRONTEND,
BACKEND
}

private boolean applyToAll;
private ConfigType type;
private NodeType type;
private Map<String, String> configs;

private RedirectStatus redirectStatus = RedirectStatus.NO_FORWARD;

public AdminSetConfigStmt(ConfigType type, Map<String, String> configs, boolean applyToAll) {
public AdminSetConfigStmt(NodeType type, Map<String, String> configs, boolean applyToAll) {
this.type = type;
this.configs = configs;
if (this.configs == null) {
Expand All @@ -62,7 +58,7 @@ public AdminSetConfigStmt(ConfigType type, Map<String, String> configs, boolean
}
}

public ConfigType getType() {
public NodeType getType() {
return type;
}

Expand All @@ -86,7 +82,7 @@ public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
}

if (type != ConfigType.FRONTEND) {
if (type != NodeType.FRONTEND) {
throw new AnalysisException("Only support setting Frontend configs now");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,94 @@

package org.apache.doris.analysis;

import org.apache.doris.analysis.AdminSetConfigStmt.ConfigType;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.ScalarType;
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.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.ShowResultSetMetaData;
import org.apache.doris.system.NodeType;

import com.google.common.collect.ImmutableList;

// show frontend config;
public class ShowConfigStmt extends ShowStmt {
public static final ImmutableList<String> TITLE_NAMES = new ImmutableList.Builder<String>().add("Key").add(
public class ShowConfigStmt extends ShowStmt implements NotFallbackInParser {
public static final ImmutableList<String> FE_TITLE_NAMES = new ImmutableList.Builder<String>().add("Key").add(
"Value").add("Type").add("IsMutable").add("MasterOnly").add("Comment").build();

private ConfigType type;
public static final ImmutableList<String> BE_TITLE_NAMES = new ImmutableList.Builder<String>().add("BackendId")
.add("Host").add("Key").add("Value").add("Type").add("IsMutable").build();

private NodeType type;

private String pattern;

public ShowConfigStmt(ConfigType type, String pattern) {
private long backendId;

private boolean isShowSingleBackend;

public ShowConfigStmt(NodeType type, String pattern) {
this.type = type;
this.pattern = pattern;
}

public ShowConfigStmt(NodeType type, String pattern, long backendId) {
this.type = type;
this.pattern = pattern;
this.backendId = backendId;
this.isShowSingleBackend = true;
}

public ConfigType getType() {
public NodeType getType() {
return type;
}

public String getPattern() {
return pattern;
}

public long getBackendId() {
return backendId;
}

public boolean isShowSingleBackend() {
return isShowSingleBackend;
}

@Override
public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);

// check auth
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
}

if (type != ConfigType.FRONTEND) {
throw new AnalysisException("Only support setting Frontend configs now");
}
}

@Override
public ShowResultSetMetaData getMetaData() {
ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder();
for (String title : TITLE_NAMES) {
builder.addColumn(new Column(title, ScalarType.createVarchar(30)));
if (type == NodeType.FRONTEND) {
for (String title : FE_TITLE_NAMES) {
builder.addColumn(new Column(title, ScalarType.createVarchar(30)));
}
} else {
for (String title : BE_TITLE_NAMES) {
builder.addColumn(new Column(title, ScalarType.createVarchar(30)));
}
}
return builder.build();
}

@Override
public RedirectStatus getRedirectStatus() {
// no need forward to master for backend config
if (type == NodeType.BACKEND) {
return RedirectStatus.NO_FORWARD;
}
if (ConnectContext.get().getSessionVariable().getForwardToMaster()) {
return RedirectStatus.FORWARD_NO_SYNC;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
import org.apache.doris.nereids.DorisParser.SelectColumnClauseContext;
import org.apache.doris.nereids.DorisParser.SelectHintContext;
import org.apache.doris.nereids.DorisParser.SetOperationContext;
import org.apache.doris.nereids.DorisParser.ShowConfigContext;
import org.apache.doris.nereids.DorisParser.ShowConstraintContext;
import org.apache.doris.nereids.DorisParser.ShowCreateMTMVContext;
import org.apache.doris.nereids.DorisParser.ShowCreateProcedureContext;
Expand Down Expand Up @@ -390,6 +391,7 @@
import org.apache.doris.nereids.trees.plans.commands.PauseMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.RefreshMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.ResumeMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand;
Expand Down Expand Up @@ -472,6 +474,7 @@
import org.apache.doris.policy.PolicyTypeEnum;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SqlModeHelper;
import org.apache.doris.system.NodeType;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -3677,4 +3680,24 @@ public LogicalPlan visitCreateTableLike(CreateTableLikeContext ctx) {
rollupNames, withAllRollUp);
return new CreateTableLikeCommand(info);
}

@Override
public LogicalPlan visitShowConfig(ShowConfigContext ctx) {
ShowConfigCommand command;
if (ctx.type.getText().equalsIgnoreCase(NodeType.FRONTEND.name())) {
command = new ShowConfigCommand(NodeType.FRONTEND);
} else {
command = new ShowConfigCommand(NodeType.BACKEND);
}
if (ctx.LIKE() != null && ctx.pattern != null) {
Like like = new Like(new UnboundSlot("ProcedureName"), getExpression(ctx.pattern));
String pattern = ((Literal) like.child(1)).getStringValue();
command.setPattern(pattern);
}
if (ctx.FROM() != null && ctx.backendId != null) {
long backendId = Long.parseLong(ctx.backendId.getText());
command.setBackendId(backendId);
}
return command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,6 @@ public enum PlanType {
CREATE_TABLE_LIKE_COMMAND,

PREPARED_COMMAND,
EXECUTE_COMMAND
EXECUTE_COMMAND,
SHOW_CONFIG_COMMAND
}
Loading
Loading