ruanwenjun commented on code in PR #17159:
URL: 
https://github.com/apache/dolphinscheduler/pull/17159#discussion_r2078840094


##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/config/MasterServerLoadProtection.java:
##########
@@ -18,10 +18,44 @@
 package org.apache.dolphinscheduler.server.master.config;
 
 import org.apache.dolphinscheduler.meter.metrics.BaseServerLoadProtection;
+import org.apache.dolphinscheduler.meter.metrics.SystemMetrics;
+import 
org.apache.dolphinscheduler.server.master.engine.WorkflowCacheRepository;
 
+import lombok.Getter;
+import lombok.Setter;
 import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
+@Getter
+@Setter
 public class MasterServerLoadProtection extends BaseServerLoadProtection {
 
+    private Integer maxConcurrentWorkflowInstances = Integer.MAX_VALUE;
+
+    private IWorkflowRepository workflowRepository;
+
+    @Override
+    public boolean isOverload(SystemMetrics systemMetrics) {
+        if (!enabled) {
+            return false;
+        }
+
+        // Check system metrics first
+        if (super.isOverload(systemMetrics)) {
+            return true;
+        }
+
+        // Check workflow instance count if repository is available
+        if (workflowRepository != null) {

Review Comment:
   ```suggestion
   
   ```
   We don't need to check here, this component is must.



##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/config/MasterServerLoadProtectionConfig.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.dolphinscheduler.server.master.config;
+
+import org.apache.dolphinscheduler.server.master.engine.IWorkflowRepository;
+
+import javax.annotation.PostConstruct;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+
+@Slf4j
+@Configuration
+public class MasterServerLoadProtectionConfig {
+
+    @Autowired
+    private MasterConfig masterConfig;
+
+    @Autowired
+    private IWorkflowRepository workflowRepository;
+
+    @PostConstruct
+    public void init() {
+        MasterServerLoadProtection serverLoadProtection = 
masterConfig.getServerLoadProtection();
+        serverLoadProtection.setWorkflowRepository(workflowRepository);

Review Comment:
   It's better to inject at the constructor.



-- 
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]

Reply via email to