github-actions[bot] commented on code in PR #60559:
URL: https://github.com/apache/doris/pull/60559#discussion_r3409162692
##########
fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadConditionUsername.java:
##########
@@ -41,7 +43,15 @@ public WorkloadMetricType getMetricType() {
return WorkloadMetricType.USERNAME;
}
- public static WorkloadConditionUsername
createWorkloadCondition(WorkloadConditionOperator op, String value) {
+ public static WorkloadConditionUsername
createWorkloadCondition(WorkloadConditionOperator op, String value)
+ throws UserException {
+ if (op != WorkloadConditionOperator.EQUAL) {
+ throw new UserException("username only support EQUAL operator");
Review Comment:
This validation is right for new DDL, but this factory is also used during
edit-log/image replay through `WorkloadSchedPolicy.gsonPostProcess()`. Before
this PR, FE accepted and persisted policies such as `CREATE WORKLOAD POLICY p
CONDITIONS(username > 'admin') ACTIONS(set_session_variable
'workload_group=normal')`. After this change, replay throws `UserException`;
`gsonPostProcess()` catches it and simply omits the condition, so a policy
whose only condition was that username check becomes conditionless and
`isMatch()` returns true for every query. Please keep create-time validation
separate from replay, or make replay fail/disable/drop the whole invalid policy
instead of silently removing the condition.
##########
fe/fe-core/src/main/java/org/apache/doris/resource/workloadschedpolicy/WorkloadSchedPolicyMgr.java:
##########
@@ -245,27 +246,36 @@ public void createWorkloadSchedPolicy(String policyName,
boolean isIfNotExists,
}
}
- private boolean checkPolicyCondition(List<WorkloadCondition>
conditionList) throws UserException {
+ private Boolean checkPolicyCondition(List<WorkloadCondition>
conditionList) throws UserException {
if (conditionList.size() >
Config.workload_max_condition_num_in_policy) {
throw new UserException(
"condition num in a policy can not exceed " +
Config.workload_max_condition_num_in_policy);
}
- boolean containsFeMetric = false;
- boolean containsBeMetric = false;
+ boolean hasFeOnlyMetric = false;
+ boolean hasBeOnlyMetric = false;
for (WorkloadCondition cond : conditionList) {
- if (FE_METRIC_SET.contains(cond.getMetricType())) {
- containsFeMetric = true;
- }
- if (BE_METRIC_SET.contains(cond.getMetricType())) {
- containsBeMetric = true;
+ boolean isFe = FE_METRIC_SET.contains(cond.getMetricType());
+ boolean isBe = BE_METRIC_SET.contains(cond.getMetricType());
+
+ if (isFe && !isBe) {
+ hasFeOnlyMetric = true;
+ } else if (isBe && !isFe) {
+ hasBeOnlyMetric = true;
}
- if (containsFeMetric && containsBeMetric) {
+
+ if (hasFeOnlyMetric && hasBeOnlyMetric) {
throw new UserException(
- "one policy can not contains fe and be metric, FE
metric list is " + FE_METRIC_SET
+ "one policy can not contains fe only and be only
metric, FE metric list is " + FE_METRIC_SET
+ ", BE metric list is " + BE_METRIC_SET);
}
}
- return containsFeMetric;
+ if (hasFeOnlyMetric) {
+ return true;
+ } else if (hasBeOnlyMetric) {
+ return false;
+ } else {
+ return null;
+ }
Review Comment:
Returning `null` here also covers `conditionList.isEmpty()`, not just
policies whose conditions are all shared metrics. Because
`createWorkloadSchedPolicy()` skips the FE/BE action-placement check when
`feCondition` is null, `CREATE WORKLOAD POLICY p ACTIONS(set_session_variable
'parallel_pipeline_task_num=1')` is now accepted.
`WorkloadSchedPolicy.isMatch()` returns true for an empty condition list, so
the FE scheduler applies that action to every connection; before this patch the
same DDL was rejected with `feAction=true` and `feCondition=false`. Please
distinguish the empty-condition case from the shared-metric case, or explicitly
document and test this behavior change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]