Skip to content

Commit 71b7dcf

Browse files
authored
[feature][executor]support workload schedule policy (#28443)
1 parent c72191e commit 71b7dcf

38 files changed

+2150
-3
lines changed

fe/fe-common/src/main/java/org/apache/doris/common/Config.java

+6
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,12 @@ public class Config extends ConfigBase {
22752275
@ConfField(mutable = true, masterOnly = true)
22762276
public static int publish_topic_info_interval_ms = 30000; // 30s
22772277

2278+
@ConfField(mutable = true)
2279+
public static int workload_sched_policy_interval_ms = 10000; // 10s
2280+
2281+
@ConfField(mutable = true)
2282+
public static int workload_action_interval_ms = 10000; // 10s
2283+
22782284
@ConfField(description = {"查询be wal_queue 的超时阈值(ms)",
22792285
"the timeout threshold of checking wal_queue on be(ms)"})
22802286
public static int check_wal_queue_timeout_threshold = 180000; // 3 min

fe/fe-core/src/main/cup/sql_parser.cup

+163-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ import org.apache.doris.common.Version;
5252
import org.apache.doris.mysql.MysqlPassword;
5353
import org.apache.doris.load.loadv2.LoadTask;
5454
import org.apache.doris.policy.PolicyTypeEnum;
55+
import org.apache.doris.resource.workloadschedpolicy.WorkloadConditionMeta;
56+
import org.apache.doris.resource.workloadschedpolicy.WorkloadActionMeta;
5557

5658
import com.google.common.collect.Lists;
5759
import com.google.common.collect.Maps;
@@ -530,6 +532,9 @@ terminal String
530532
KW_PROCESSLIST,
531533
KW_PROFILE,
532534
KW_PROPERTIES,
535+
KW_CONDITIONS,
536+
KW_ACTIONS,
537+
KW_SET_SESSION_VAR,
533538
KW_PROPERTY,
534539
KW_QUANTILE_STATE,
535540
KW_QUANTILE_UNION,
@@ -841,6 +846,8 @@ nonterminal SetVar option_value, option_value_follow_option_type, option_value_n
841846
// List of set variable
842847
nonterminal List<SetVar> option_value_list, option_value_list_continued, start_option_value_list,
843848
start_option_value_list_following_option_type, user_property_list;
849+
nonterminal List<WorkloadConditionMeta> workload_policy_condition_list, conditions, opt_conditions;
850+
nonterminal List<WorkloadActionMeta> workload_policy_action_list, opt_actions, actions;
844851

845852
nonterminal Map<String, String> key_value_map, opt_key_value_map, opt_key_value_map_in_paren, opt_properties,
846853
opt_ext_properties, opt_enable_feature_properties, properties;
@@ -963,6 +970,9 @@ nonterminal StorageBackend storage_backend;
963970
nonterminal ArrayList<LockTable> opt_lock_tables_list;
964971
nonterminal LockTable lock_table;
965972

973+
// workload policy/group
974+
nonterminal String policy_condition_op, policy_condition_value;
975+
966976
precedence nonassoc COMMA;
967977
precedence nonassoc STRING_LITERAL;
968978
precedence nonassoc KW_COLUMNS;
@@ -986,7 +996,7 @@ precedence left BITAND, BITOR, BITXOR;
986996
precedence left KW_PIPE;
987997
precedence left BITNOT;
988998
precedence left KW_ORDER, KW_BY, KW_LIMIT;
989-
precedence right KW_PROPERTIES;
999+
precedence right KW_PROPERTIES, KW_CONDITIONS, KW_ACTIONS;
9901000
precedence left LPAREN, RPAREN;
9911001
precedence left KW_PREPARE, KW_EXECUTE;
9921002
// Support chaining of timestamp arithmetic exprs.
@@ -1362,6 +1372,10 @@ alter_stmt ::=
13621372
{:
13631373
RESULT = new AlterWorkloadGroupStmt(workloadGroupName, properties);
13641374
:}
1375+
| KW_ALTER KW_WORKLOAD KW_SCHEDULE KW_POLICY ident_or_text:policyName opt_properties:properties
1376+
{:
1377+
RESULT = new AlterWorkloadSchedPolicyStmt(policyName, properties);
1378+
:}
13651379
| KW_ALTER KW_ROUTINE KW_LOAD KW_FOR job_label:jobLabel opt_properties:jobProperties
13661380
opt_datasource_properties:datasourceProperties
13671381
{:
@@ -1884,6 +1898,11 @@ create_stmt ::=
18841898
{:
18851899
RESULT = new CreateWorkloadGroupStmt(ifNotExists, workloadGroupName, properties);
18861900
:}
1901+
/* workload schedule policy */
1902+
| KW_CREATE KW_WORKLOAD KW_SCHEDULE KW_POLICY opt_if_not_exists:ifNotExists ident_or_text:workloadPolicyName opt_conditions:conditions opt_actions:actions opt_properties:properties
1903+
{:
1904+
RESULT = new CreateWorkloadSchedPolicyStmt(ifNotExists, workloadPolicyName, conditions, actions, properties);
1905+
:}
18871906
/* encryptkey */
18881907
| KW_CREATE KW_ENCRYPTKEY opt_if_not_exists:ifNotExists encryptkey_name:keyName KW_AS STRING_LITERAL:keyString
18891908
{:
@@ -2987,6 +3006,10 @@ drop_stmt ::=
29873006
{:
29883007
RESULT = new DropWorkloadGroupStmt(ifExists, workloadGroupName);
29893008
:}
3009+
| KW_DROP KW_WORKLOAD KW_SCHEDULE KW_POLICY opt_if_exists:ifExists ident_or_text:policyName
3010+
{:
3011+
RESULT = new DropWorkloadSchedPolicyStmt(ifExists, policyName);
3012+
:}
29903013
| KW_DROP KW_ENCRYPTKEY opt_if_exists:ifExists encryptkey_name:keyName
29913014
{:
29923015
RESULT = new DropEncryptKeyStmt(ifExists, keyName);
@@ -3455,6 +3478,135 @@ opt_properties ::=
34553478
:}
34563479
;
34573480

3481+
policy_condition_op ::=
3482+
EQUAL
3483+
{:
3484+
RESULT = "=";
3485+
:}
3486+
| GREATERTHAN
3487+
{:
3488+
RESULT = ">";
3489+
:}
3490+
| LESSTHAN
3491+
{:
3492+
RESULT = "<";
3493+
:}
3494+
| GREATERTHAN EQUAL
3495+
{:
3496+
RESULT = ">=";
3497+
:}
3498+
| LESSTHAN EQUAL
3499+
{:
3500+
RESULT = "<=";
3501+
:};
3502+
3503+
policy_condition_value ::=
3504+
INTEGER_LITERAL:val
3505+
{:
3506+
RESULT = String.valueOf(val);
3507+
:}
3508+
| STRING_LITERAL:val
3509+
{:
3510+
RESULT = val;
3511+
:}
3512+
| FLOATINGPOINT_LITERAL:val
3513+
{:
3514+
RESULT = String.valueOf(val);
3515+
:}
3516+
| DECIMAL_LITERAL:val
3517+
{:
3518+
RESULT = val.toString();
3519+
:}
3520+
;
3521+
3522+
workload_policy_condition_list ::=
3523+
ident:metricName policy_condition_op:op policy_condition_value:value
3524+
{:
3525+
RESULT = new ArrayList<>();
3526+
WorkloadConditionMeta cm = new WorkloadConditionMeta(metricName, op, value);
3527+
RESULT.add(cm);
3528+
:}
3529+
| workload_policy_condition_list:list COMMA ident:metricName policy_condition_op:op policy_condition_value:value
3530+
{:
3531+
WorkloadConditionMeta cm = new WorkloadConditionMeta(metricName, op, value);
3532+
list.add(cm);
3533+
RESULT = list;
3534+
:};
3535+
3536+
conditions ::=
3537+
KW_CONDITIONS LPAREN workload_policy_condition_list:list RPAREN
3538+
{:
3539+
RESULT = list;
3540+
:}
3541+
;
3542+
3543+
opt_conditions ::=
3544+
{:
3545+
RESULT = null;
3546+
:}
3547+
| conditions:conditions
3548+
{:
3549+
RESULT = conditions;
3550+
:}
3551+
;
3552+
3553+
workload_policy_action_list ::=
3554+
KW_SET_SESSION_VAR STRING_LITERAL:args
3555+
{:
3556+
RESULT = Lists.newArrayList();
3557+
WorkloadActionMeta wam = new WorkloadActionMeta("set_session_variable", args);
3558+
RESULT.add(wam);
3559+
:}
3560+
| workload_policy_action_list:list COMMA KW_SET_SESSION_VAR STRING_LITERAL:args
3561+
{:
3562+
WorkloadActionMeta wam = new WorkloadActionMeta("set_session_variable", args);
3563+
list.add(wam);
3564+
RESULT = list;
3565+
:}
3566+
| ident:firstArgs
3567+
{:
3568+
RESULT = Lists.newArrayList();
3569+
WorkloadActionMeta wam = new WorkloadActionMeta(firstArgs, "");
3570+
RESULT.add(wam);
3571+
:}
3572+
| ident:firstArgs STRING_LITERAL:secondArgs
3573+
{:
3574+
RESULT = Lists.newArrayList();
3575+
WorkloadActionMeta wam = new WorkloadActionMeta(firstArgs, secondArgs);
3576+
RESULT.add(wam);
3577+
:}
3578+
| workload_policy_action_list:list COMMA ident:firstArgs
3579+
{:
3580+
WorkloadActionMeta wam = new WorkloadActionMeta(firstArgs, "");
3581+
list.add(wam);
3582+
RESULT = list;
3583+
:}
3584+
| workload_policy_action_list:list COMMA ident:firstArgs STRING_LITERAL:secondArgs
3585+
{:
3586+
WorkloadActionMeta wam = new WorkloadActionMeta(firstArgs, secondArgs);
3587+
list.add(wam);
3588+
RESULT = list;
3589+
:}
3590+
;
3591+
3592+
3593+
actions ::=
3594+
KW_ACTIONS LPAREN workload_policy_action_list:list RPAREN
3595+
{:
3596+
RESULT = list;
3597+
:}
3598+
;
3599+
3600+
opt_actions ::=
3601+
{:
3602+
RESULT = null;
3603+
:}
3604+
| actions:actions
3605+
{:
3606+
RESULT = actions;
3607+
:}
3608+
;
3609+
34583610
opt_ext_properties ::=
34593611
{:
34603612
RESULT = null;
@@ -4003,6 +4155,10 @@ show_param ::=
40034155
{:
40044156
RESULT = new ShowWorkloadGroupsStmt();
40054157
:}
4158+
| KW_WORKLOAD KW_SCHEDULE KW_POLICY
4159+
{:
4160+
RESULT = new ShowWorkloadSchedPolicyStmt();
4161+
:}
40064162
| KW_BACKENDS
40074163
{:
40084164
RESULT = new ShowBackendsStmt();
@@ -7640,6 +7796,12 @@ keyword ::=
76407796
{: RESULT = id; :}
76417797
| KW_PROPERTIES:id
76427798
{: RESULT = id; :}
7799+
| KW_CONDITIONS:id
7800+
{: RESULT = id; :}
7801+
| KW_ACTIONS:id
7802+
{: RESULT = id; :}
7803+
| KW_SET_SESSION_VAR:id
7804+
{: RESULT = id; :}
76437805
| KW_PROPERTY:id
76447806
{: RESULT = id; :}
76457807
| KW_QUERY:id
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.analysis;
19+
20+
import org.apache.doris.catalog.Env;
21+
import org.apache.doris.common.AnalysisException;
22+
import org.apache.doris.common.ErrorCode;
23+
import org.apache.doris.common.ErrorReport;
24+
import org.apache.doris.common.UserException;
25+
import org.apache.doris.common.util.PrintableMap;
26+
import org.apache.doris.mysql.privilege.PrivPredicate;
27+
import org.apache.doris.qe.ConnectContext;
28+
29+
import java.util.Map;
30+
31+
public class AlterWorkloadSchedPolicyStmt extends DdlStmt {
32+
33+
private final String policyName;
34+
private final Map<String, String> properties;
35+
36+
public AlterWorkloadSchedPolicyStmt(String policyName, Map<String, String> properties) {
37+
this.policyName = policyName;
38+
this.properties = properties;
39+
}
40+
41+
public String getPolicyName() {
42+
return policyName;
43+
}
44+
45+
public Map<String, String> getProperties() {
46+
return properties;
47+
}
48+
49+
public void analyze(Analyzer analyzer) throws UserException {
50+
super.analyze(analyzer);
51+
52+
// check auth
53+
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
54+
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
55+
}
56+
57+
if (properties == null || properties.isEmpty()) {
58+
throw new AnalysisException("properties can't be null when alter workload schedule policy");
59+
}
60+
}
61+
62+
@Override
63+
public String toSql() {
64+
StringBuilder sb = new StringBuilder();
65+
sb.append("ALTER WORKLOAD SCHEDULE POLICY ");
66+
sb.append(policyName);
67+
sb.append("PROPERTIES(").append(new PrintableMap<>(properties, " = ", true, false)).append(")");
68+
return sb.toString();
69+
}
70+
71+
}

0 commit comments

Comments
 (0)