You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/01/28 05:52:12 UTC

[GitHub] [shardingsphere] sandynz commented on a change in pull request #15136: For #14722: Refactor the issue that cannot have multiple jobs under the same Schema name

sandynz commented on a change in pull request #15136:
URL: https://github.com/apache/shardingsphere/pull/15136#discussion_r794216994



##########
File path: shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/ZookeeperDistributeLock.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.shardingsphere.data.pipeline.core.lock;
+
+import com.google.common.collect.Maps;
+import org.apache.shardingsphere.data.pipeline.core.context.PipelineContext;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.service.LockRegistryService;
+import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
+import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
+import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
+
+import java.util.Map;
+
+/**
+ * Zookeeper Distribute Lock.
+ */
+public final class ZookeeperDistributeLock {
+    
+    private static final LockRegistryService LOCK_REGISTRY_SERVICE;
+    
+    private static final Map<String, Boolean> LOCK_NAME_LOCKED_MAP;
+    
+    static {
+        ClusterPersistRepositoryConfiguration repositoryConfig = (ClusterPersistRepositoryConfiguration) PipelineContext.getModeConfig().getRepository();
+        ClusterPersistRepository repository = TypedSPIRegistry.getRegisteredService(ClusterPersistRepository.class, repositoryConfig.getType(), repositoryConfig.getProps());
+        repository.init(repositoryConfig);
+        LOCK_REGISTRY_SERVICE = new LockRegistryService(repository);
+        LOCK_NAME_LOCKED_MAP = Maps.newConcurrentMap();
+    }

Review comment:
       1. Do not init repository here, since it's referenced in `RuleAlteredJobWorker` and then in `BootstrapInitializer`, if initialization throw exception, then it'll cause proxy startup failure.
   
   2. It's better to reuse existing repository but not create another one. Try `PipelineContext.getContextManager().getMetaDataContexts().getMetaDataPersistService().getPersistRepository()`, need to verify whether context and service is null or not.
   

##########
File path: shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/ZookeeperDistributeLock.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.shardingsphere.data.pipeline.core.lock;
+
+import com.google.common.collect.Maps;
+import org.apache.shardingsphere.data.pipeline.core.context.PipelineContext;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.service.LockRegistryService;
+import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
+import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
+import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
+
+import java.util.Map;
+
+/**
+ * Zookeeper Distribute Lock.

Review comment:
       Doc format could be improved.

##########
File path: shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java
##########
@@ -265,4 +270,38 @@ private void disableSSLForMySQL(final Map<String, Map<String, Object>> yamlDataS
             entry.getValue().put(jdbcUrlKey, new JdbcUrlAppender().appendQueryProperties((String) entry.getValue().get(jdbcUrlKey), queryProps));
         }
     }
+    
+    private void isUncompletedJobOfSameSchemaInJobList(final String schema) {
+        boolean isUncompletedJobOfSameSchema = false;
+        for (JobInfo each : PipelineJobAPIFactory.getRuleAlteredJobAPI().list()) {
+            JobConfiguration jobConfiguration = YamlEngine.unmarshal(each.getJobParameter(), JobConfiguration.class, true);
+            if (isUncompletedJobOfSameSchema(jobConfiguration, each.getJobId(), schema)) {
+                isUncompletedJobOfSameSchema = true;
+                break;
+            }
+        }
+        if (isUncompletedJobOfSameSchema) {
+            log.warn("There is an outstanding job with the same schema name");
+        }
+    }
+    
+    private boolean isUncompletedJobOfSameSchema(final JobConfiguration jobConfig, final String jobId, final String currentSchema) {
+        HandleConfiguration handleConfig = jobConfig.getHandleConfig();
+        WorkflowConfiguration workflowConfig;
+        if (null == handleConfig || null == (workflowConfig = jobConfig.getWorkflowConfig())) {
+            log.warn("handleConfig or workflowConfig null, jobId={}", jobId);
+            return false;
+        }
+        return currentSchema.equals(workflowConfig.getSchemaName());
+    }
+    
+    /**
+     * scaling release schema name lock.
+     *
+     * @param event scaling release schema name lock event
+     */
+    @Subscribe
+    public void scalingReleaseSchemaNameLock(final ScalingReleaseSchemaNameLockEvent event) {
+        ZookeeperDistributeLock.releaseLock(event.getSchemaName());
+    }

Review comment:
       It's better to keep it in `ScalingRegistrySubscriber`, all subscribes should be put there later.

##########
File path: shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/PipelineJobExecutor.java
##########
@@ -59,12 +63,18 @@ private void watchGovernanceRepositoryConfiguration() {
                 log.info("remove and stop {}", jobConfigPOJO.getJobName());
                 EXECUTING_JOBS.remove(jobConfigPOJO.getJobName());
                 RuleAlteredJobSchedulerCenter.stop(jobConfigPOJO.getJobName());
+                JobConfiguration jobConfiguration = YamlEngine.unmarshal(jobConfigPOJO.getJobParameter(), JobConfiguration.class, true);

Review comment:
       `jobConfiguration` could be `jobConfig`.

##########
File path: shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java
##########
@@ -163,6 +167,7 @@ private static YamlRootConfiguration getYamlRootConfig(final JobConfiguration jo
      */
     @Subscribe
     public void start(final StartScalingEvent event) {
+        isUncompletedJobOfSameSchemaInJobList(event.getSchemaName());

Review comment:
       `isUncompletedJobOfSameSchemaInJobList` doesn't return result, if this check doesn't pass, it just print log but the process will go on.

##########
File path: shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/ZookeeperDistributeLock.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.shardingsphere.data.pipeline.core.lock;
+
+import com.google.common.collect.Maps;
+import org.apache.shardingsphere.data.pipeline.core.context.PipelineContext;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.service.LockRegistryService;
+import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
+import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
+import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
+
+import java.util.Map;
+
+/**
+ * Zookeeper Distribute Lock.
+ */
+public final class ZookeeperDistributeLock {

Review comment:
       Registry center is not only ZooKeeper, `ZookeeperDistributeLock` class name could be improved.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org