Skip to content

Commit

Permalink
[Feature](show) show backend config using ShowStmt (#36525)
Browse files Browse the repository at this point in the history
Currently, Doris only supports accessing backend configurations via HTTP
APIs. To enhance this functionality, I have added some syntax extensions
to allow displaying backend configurations using SQL commands.

The SQL syntax for displaying backend configurations is similar to that
for displaying frontend configurations:

1. Display backend configurations matching a pattern:
This statement will display all active backend configurations that match
the specified pattern.

show backend config like ${pattern}

3. Display backend configurations for a specific BE using the backend ID

show backend config from ${beId}

4. Use both a pattern and a backend ID:

show backend config like ${pattern} from ${backendID}


The output of these statements consists of 6 columns: BE ID, BE host IP,
configuration key, configuration value, configuration type, and whether
it is mutable or not.

+-----------+---------------+---------+-------+---------+-----------+
| BackendId | Host          | Key     | Value | Type    | IsMutable |
+-----------+---------------+---------+-------+---------+-----------+
| 10001     | xx.xx.xxx.xxx | be_port | 9060  | int32_t | false     |
+-----------+---------------+---------+-------+---------+-----------+

This provides an additional way to access backend configurations within
Doris.


Co-authored-by: duanxujian <[email protected]>
  • Loading branch information
DarvenDuan and duanxujian authored Aug 16, 2024
1 parent 2605b18 commit ed560bb
Show file tree
Hide file tree
Showing 12 changed files with 427 additions and 36 deletions.
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 @@ -3683,4 +3686,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

0 comments on commit ed560bb

Please sign in to comment.