You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "sandynz (via GitHub)" <gi...@apache.org> on 2023/04/23 08:26:31 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #25289: Add drop streaming DistSQL implementation

sandynz commented on code in PR #25289:
URL: https://github.com/apache/shardingsphere/pull/25289#discussion_r1174532181


##########
kernel/data-pipeline/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/impl/CDCJobAPI.java:
##########
@@ -218,6 +220,45 @@ protected String marshalJobIdLeftPart(final PipelineJobId pipelineJobId) {
         return DigestUtils.md5Hex(text.getBytes(StandardCharsets.UTF_8));
     }
     
+    /**
+     * Start job.
+     *
+     * @param jobId             job id
+     * @param importerConnector importer connector
+     */
+    public void startJob(final String jobId, final ImporterConnector importerConnector) {
+        CDCJob job = new CDCJob(importerConnector);
+        PipelineJobCenter.addJob(jobId, job);
+        JobConfigurationPOJO jobConfigPOJO = getElasticJobConfigPOJO(jobId);
+        updateJobConfigurationDisabled(jobConfigPOJO, false);
+        OneOffJobBootstrap oneOffJobBootstrap = new OneOffJobBootstrap(PipelineAPIFactory.getRegistryCenter(PipelineJobIdUtils.parseContextKey(jobId)), job, jobConfigPOJO.toJobConfiguration());
+        job.setJobBootstrap(oneOffJobBootstrap);
+        oneOffJobBootstrap.execute();
+    }
+    
+    /**
+     * Update job configuration disabled.
+     *
+     * @param jobId    job id
+     * @param disabled disabled
+     */
+    public void updateJobConfigurationDisabled(final String jobId, final boolean disabled) {
+        JobConfigurationPOJO jobConfigPOJO = getElasticJobConfigPOJO(jobId);
+        updateJobConfigurationDisabled(jobConfigPOJO, disabled);
+    }
+    
+    private void updateJobConfigurationDisabled(final JobConfigurationPOJO jobConfigPOJO, final boolean disabled) {

Review Comment:
   Could we combine these 2 methods?



##########
kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/cdc/distsql/handler/update/DropStreamingUpdater.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.cdc.distsql.handler.update;
+
+import org.apache.shardingsphere.cdc.distsql.statement.DropStreamingStatement;
+import org.apache.shardingsphere.data.pipeline.cdc.api.impl.CDCJobAPI;
+import org.apache.shardingsphere.distsql.handler.ral.update.RALUpdater;
+
+import java.sql.SQLException;
+
+/**
+ * Drop streaming updater.
+ */
+public final class DropStreamingUpdater implements RALUpdater<DropStreamingStatement> {
+    
+    private final CDCJobAPI jobAPI = new CDCJobAPI();
+    
+    @Override
+    public void executeUpdate(final String databaseName, final DropStreamingStatement sqlStatement) throws SQLException {
+        jobAPI.rollback(sqlStatement.getJobId());
+    }

Review Comment:
   Could we keep `commit` and `rollback` but not `drop`?



##########
kernel/data-pipeline/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/api/impl/CDCJobAPI.java:
##########
@@ -218,6 +220,45 @@ protected String marshalJobIdLeftPart(final PipelineJobId pipelineJobId) {
         return DigestUtils.md5Hex(text.getBytes(StandardCharsets.UTF_8));
     }
     
+    /**
+     * Start job.
+     *
+     * @param jobId             job id
+     * @param importerConnector importer connector
+     */
+    public void startJob(final String jobId, final ImporterConnector importerConnector) {
+        CDCJob job = new CDCJob(importerConnector);
+        PipelineJobCenter.addJob(jobId, job);
+        JobConfigurationPOJO jobConfigPOJO = getElasticJobConfigPOJO(jobId);
+        updateJobConfigurationDisabled(jobConfigPOJO, false);
+        OneOffJobBootstrap oneOffJobBootstrap = new OneOffJobBootstrap(PipelineAPIFactory.getRegistryCenter(PipelineJobIdUtils.parseContextKey(jobId)), job, jobConfigPOJO.toJobConfiguration());
+        job.setJobBootstrap(oneOffJobBootstrap);
+        oneOffJobBootstrap.execute();
+    }
+    
+    /**
+     * Update job configuration disabled.
+     *
+     * @param jobId    job id
+     * @param disabled disabled
+     */
+    public void updateJobConfigurationDisabled(final String jobId, final boolean disabled) {
+        JobConfigurationPOJO jobConfigPOJO = getElasticJobConfigPOJO(jobId);
+        updateJobConfigurationDisabled(jobConfigPOJO, disabled);
+    }
+    
+    private void updateJobConfigurationDisabled(final JobConfigurationPOJO jobConfigPOJO, final boolean disabled) {
+        // TODO, ensure that there is only one consumer at a time, job config disable may not be updated when the program is forced to close
+        jobConfigPOJO.setDisabled(disabled);

Review Comment:
   Could this TODO resolved this time? What's the plan if it's not



##########
test/it/parser/src/main/resources/sql/supported/ral/cdc.xml:
##########
@@ -19,4 +19,5 @@
 <sql-cases>
     <sql-case id="show-streaming-list" value="SHOW STREAMING LIST;" db-types="ShardingSphere"/>
     <sql-case id="show-streaming-status" value="SHOW STREAMING STATUS 123;" db-types="ShardingSphere"/>
+    <sql-case id="drop-streaming" value="DROP STREAMING 123;" db-types="ShardingSphere"/>

Review Comment:
   Could we add new DistSQL test in E2E?



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