This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new d60d84acced Refactor PipelineJobId.marshalSuffix to reduce consistency 
check job id length (#29350)
d60d84acced is described below

commit d60d84acceda1afab34de8c265c7c7f3f6c697f5
Author: Hongsheng Zhong <zhonghongsh...@apache.org>
AuthorDate: Sun Dec 10 17:57:17 2023 +0800

    Refactor PipelineJobId.marshalSuffix to reduce consistency check job id 
length (#29350)
---
 .../data/pipeline/core/job/id/PipelineJobId.java    | 21 +++++++--------------
 .../pipeline/core/job/id/PipelineJobIdUtils.java    | 12 +++---------
 .../consistencycheck/ConsistencyCheckJobId.java     | 11 ++---------
 3 files changed, 12 insertions(+), 32 deletions(-)

diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobId.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobId.java
index 361feba6cf8..c62315511cd 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobId.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobId.java
@@ -17,10 +17,12 @@
 
 package org.apache.shardingsphere.data.pipeline.core.job.id;
 
+import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.shardingsphere.data.pipeline.core.context.PipelineContextKey;
 import org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType;
+import org.apache.shardingsphere.infra.util.json.JsonUtils;
 
-import java.util.Optional;
+import java.nio.charset.StandardCharsets;
 
 /**
  * Pipeline job id.
@@ -44,20 +46,11 @@ public interface PipelineJobId {
     PipelineContextKey getContextKey();
     
     /**
-     * Get parent job id.
+     * Marshal job id suffix.
      *
-     * @return parent job id
+     * @return marshaled suffix
      */
-    default Optional<String> getParentJobId() {
-        return Optional.empty();
-    }
-    
-    /**
-     * Get sequence.
-     *
-     * @return sequence
-     */
-    default Optional<Integer> getSequence() {
-        return Optional.empty();
+    default String marshalSuffix() {
+        return 
DigestUtils.md5Hex(JsonUtils.toJsonString(this).getBytes(StandardCharsets.UTF_8));
     }
 }
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobIdUtils.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobIdUtils.java
index ef3f7b3127e..8972531cca2 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobIdUtils.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/id/PipelineJobIdUtils.java
@@ -24,17 +24,15 @@ import lombok.NoArgsConstructor;
 import lombok.SneakyThrows;
 import org.apache.commons.codec.DecoderException;
 import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.shardingsphere.data.pipeline.core.context.PipelineContextKey;
+import 
org.apache.shardingsphere.data.pipeline.core.exception.job.PipelineJobNotFoundException;
+import org.apache.shardingsphere.data.pipeline.core.job.api.PipelineAPIFactory;
 import org.apache.shardingsphere.data.pipeline.core.job.type.JobCodeRegistry;
 import org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType;
 import org.apache.shardingsphere.data.pipeline.core.util.InstanceTypeUtils;
-import 
org.apache.shardingsphere.data.pipeline.core.exception.job.PipelineJobNotFoundException;
-import org.apache.shardingsphere.data.pipeline.core.job.api.PipelineAPIFactory;
 import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceType;
-import org.apache.shardingsphere.infra.util.json.JsonUtils;
 
 import java.nio.charset.StandardCharsets;
 
@@ -51,7 +49,7 @@ public final class PipelineJobIdUtils {
      * @return job id
      */
     public static String marshal(final PipelineJobId jobId) {
-        return marshalPrefix(jobId.getJobType(), jobId.getContextKey()) + 
marshalSuffix(jobId) + jobId.getParentJobId().orElse("") + 
jobId.getSequence().map(String::valueOf).orElse("");
+        return marshalPrefix(jobId.getJobType(), jobId.getContextKey()) + 
jobId.marshalSuffix();
     }
     
     private static String marshalPrefix(final PipelineJobType jobType, final 
PipelineContextKey contextKey) {
@@ -63,10 +61,6 @@ public final class PipelineJobIdUtils {
         return 'j' + jobType.getCode() + PipelineJobId.CURRENT_VERSION + 
encodedInstanceType + databaseNameLengthHex + databaseNameHex;
     }
     
-    private static String marshalSuffix(final PipelineJobId jobId) {
-        return 
DigestUtils.md5Hex(JsonUtils.toJsonString(jobId).getBytes(StandardCharsets.UTF_8));
-    }
-    
     /**
      * Parse job type.
      *
diff --git 
a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobId.java
 
b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobId.java
index 03206e6fa3b..96236921003 100644
--- 
a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobId.java
+++ 
b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobId.java
@@ -23,8 +23,6 @@ import 
org.apache.shardingsphere.data.pipeline.core.job.id.PipelineJobId;
 import org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType;
 import 
org.apache.shardingsphere.data.pipeline.scenario.consistencycheck.util.ConsistencyCheckSequence;
 
-import java.util.Optional;
-
 /**
  * Consistency check job id.
  */
@@ -64,12 +62,7 @@ public final class ConsistencyCheckJobId implements 
PipelineJobId {
     }
     
     @Override
-    public Optional<String> getParentJobId() {
-        return Optional.of(parentJobId);
-    }
-    
-    @Override
-    public Optional<Integer> getSequence() {
-        return Optional.of(sequence);
+    public String marshalSuffix() {
+        return parentJobId + sequence;
     }
 }

Reply via email to