You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/09/09 12:38:20 UTC

(shardingsphere) branch master updated: Refactor InventoryPositionCalculator and PrimaryKeyIngestPositionFactory method return type (#36511)

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 f035a0ef58b Refactor InventoryPositionCalculator and PrimaryKeyIngestPositionFactory method return type (#36511)
f035a0ef58b is described below

commit f035a0ef58b75f5d8f7d9dd5f2b21d076f751578
Author: Hongsheng Zhong <zh...@apache.org>
AuthorDate: Tue Sep 9 20:38:14 2025 +0800

    Refactor InventoryPositionCalculator and PrimaryKeyIngestPositionFactory method return type (#36511)
    
    * Refactor InventoryPositionCalculator method return type
    
    * Improve ConsistencyCheckTasksRunner onSuccess
    
    * Refactor PrimaryKeyIngestPositionFactory method return type
---
 .../ingest/position/type/pk/PrimaryKeyIngestPositionFactory.java  | 5 ++---
 .../inventory/calculator/InventoryPositionCalculator.java         | 6 +++---
 .../inventory/calculator/InventoryPositionCalculatorTest.java     | 8 ++++----
 .../consistencycheck/task/ConsistencyCheckTasksRunner.java        | 2 +-
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactory.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactory.java
index e9629373e8a..76bf0c16a57 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactory.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactory.java
@@ -21,7 +21,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.data.pipeline.core.ingest.position.IngestPosition;
 import org.apache.shardingsphere.data.pipeline.core.ingest.position.type.pk.type.IntegerPrimaryKeyIngestPosition;
 import org.apache.shardingsphere.data.pipeline.core.ingest.position.type.pk.type.StringPrimaryKeyIngestPosition;
 import org.apache.shardingsphere.data.pipeline.core.ingest.position.type.pk.type.UnsupportedKeyIngestPosition;
@@ -41,7 +40,7 @@ public final class PrimaryKeyIngestPositionFactory {
      * @return primary key position
      * @throws IllegalArgumentException illegal argument exception
      */
-    public static IngestPosition newInstance(final String data) {
+    public static PrimaryKeyIngestPosition<?> newInstance(final String data) {
         List<String> parts = Splitter.on(',').splitToList(data);
         Preconditions.checkArgument(3 == parts.size(), "Unknown primary key position: " + data);
         Preconditions.checkArgument(1 == parts.get(0).length(), "Invalid primary key position type: " + parts.get(0));
@@ -67,7 +66,7 @@ public final class PrimaryKeyIngestPositionFactory {
      * @param endValue end value
      * @return ingest position
      */
-    public static IngestPosition newInstance(final Object beginValue, final Object endValue) {
+    public static PrimaryKeyIngestPosition<?> newInstance(final Object beginValue, final Object endValue) {
         if (beginValue instanceof Number) {
             return new IntegerPrimaryKeyIngestPosition(((Number) beginValue).longValue(), null == endValue ? Long.MAX_VALUE : ((Number) endValue).longValue());
         }
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculator.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculator.java
index af7f5c5b2b4..11cea24cb28 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculator.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculator.java
@@ -25,9 +25,9 @@ import org.apache.shardingsphere.data.pipeline.core.ingest.position.type.pk.type
 import org.apache.shardingsphere.data.pipeline.core.util.IntervalToRangeIterator;
 
 import java.math.BigInteger;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
+import java.util.List;
 
 /**
  * Inventory position calculator.
@@ -43,11 +43,11 @@ public final class InventoryPositionCalculator {
      * @param shardingSize sharding size
      * @return position collection
      */
-    public static Collection<IngestPosition> getPositionByIntegerUniqueKeyRange(final long tableRecordsCount, final Range<Long> uniqueKeyValuesRange, final long shardingSize) {
+    public static List<IngestPosition> getPositionByIntegerUniqueKeyRange(final long tableRecordsCount, final Range<Long> uniqueKeyValuesRange, final long shardingSize) {
         if (0 == tableRecordsCount) {
             return Collections.singletonList(new IntegerPrimaryKeyIngestPosition(0, 0));
         }
-        Collection<IngestPosition> result = new LinkedList<>();
+        List<IngestPosition> result = new LinkedList<>();
         long splitCount = tableRecordsCount / shardingSize + (tableRecordsCount % shardingSize > 0 ? 1 : 0);
         long interval = BigInteger.valueOf(uniqueKeyValuesRange.getMaximum()).subtract(BigInteger.valueOf(uniqueKeyValuesRange.getMinimum())).divide(BigInteger.valueOf(splitCount)).longValue();
         IntervalToRangeIterator rangeIterator = new IntervalToRangeIterator(uniqueKeyValuesRange.getMinimum(), uniqueKeyValuesRange.getMaximum(), interval);
diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculatorTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculatorTest.java
index 966e9b414ac..e4460263af3 100644
--- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculatorTest.java
+++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculatorTest.java
@@ -32,7 +32,7 @@ class InventoryPositionCalculatorTest {
     
     @Test
     void assertGetPositionByIntegerUniqueKeyRange() {
-        List<IngestPosition> actualPositions = (List<IngestPosition>) InventoryPositionCalculator.getPositionByIntegerUniqueKeyRange(200L, Range.of(1L, 600L), 100L);
+        List<IngestPosition> actualPositions = InventoryPositionCalculator.getPositionByIntegerUniqueKeyRange(200L, Range.of(1L, 600L), 100L);
         assertThat(actualPositions.size(), is(2));
         for (IngestPosition each : actualPositions) {
             assertThat(each, isA(IntegerPrimaryKeyIngestPosition.class));
@@ -48,7 +48,7 @@ class InventoryPositionCalculatorTest {
     
     @Test
     void assertGetPositionByIntegerUniqueKeyRangeWithZeroTotalRecordsCount() {
-        List<IngestPosition> actualPositions = (List<IngestPosition>) InventoryPositionCalculator.getPositionByIntegerUniqueKeyRange(0L, Range.of(0L, 0L), 1L);
+        List<IngestPosition> actualPositions = InventoryPositionCalculator.getPositionByIntegerUniqueKeyRange(0L, Range.of(0L, 0L), 1L);
         assertThat(actualPositions.size(), is(1));
         assertThat(actualPositions.get(0), isA(IntegerPrimaryKeyIngestPosition.class));
         assertPosition(new IntegerPrimaryKeyIngestPosition(0L, 0L), (IntegerPrimaryKeyIngestPosition) actualPositions.get(0));
@@ -56,7 +56,7 @@ class InventoryPositionCalculatorTest {
     
     @Test
     void assertGetPositionByIntegerUniqueKeyRangeWithTheSameMinMax() {
-        List<IngestPosition> actualPositions = (List<IngestPosition>) InventoryPositionCalculator.getPositionByIntegerUniqueKeyRange(200L, Range.of(5L, 5L), 100L);
+        List<IngestPosition> actualPositions = InventoryPositionCalculator.getPositionByIntegerUniqueKeyRange(200L, Range.of(5L, 5L), 100L);
         assertThat(actualPositions.size(), is(1));
         assertThat(actualPositions.get(0), isA(IntegerPrimaryKeyIngestPosition.class));
         assertPosition(new IntegerPrimaryKeyIngestPosition(5L, 5L), (IntegerPrimaryKeyIngestPosition) actualPositions.get(0));
@@ -68,7 +68,7 @@ class InventoryPositionCalculatorTest {
         long shardingSize = tableRecordsCount / 2L;
         long minimum = Long.MIN_VALUE + 1L;
         long maximum = Long.MAX_VALUE;
-        List<IngestPosition> actualPositions = (List<IngestPosition>) InventoryPositionCalculator.getPositionByIntegerUniqueKeyRange(tableRecordsCount, Range.of(minimum, maximum), shardingSize);
+        List<IngestPosition> actualPositions = InventoryPositionCalculator.getPositionByIntegerUniqueKeyRange(tableRecordsCount, Range.of(minimum, maximum), shardingSize);
         assertThat(actualPositions.size(), is(2));
         for (IngestPosition each : actualPositions) {
             assertThat(each, isA(IntegerPrimaryKeyIngestPosition.class));
diff --git a/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/task/ConsistencyCheckTasksRunner.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/task/ConsistencyCheckTasksRunner.java
index 0190fd40117..df6806eb0ba 100644
--- a/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/task/ConsistencyCheckTasksRunner.java
+++ b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/task/ConsistencyCheckTasksRunner.java
@@ -146,7 +146,7 @@ public final class ConsistencyCheckTasksRunner implements PipelineTasksRunner {
             log.info("onSuccess, check job id: {}, parent job id: {}", checkJobId, parentJobId);
             Map<String, TableDataConsistencyCheckResult> checkJobResult = PipelineAPIFactory.getPipelineGovernanceFacade(
                     PipelineJobIdUtils.parseContextKey(parentJobId)).getJobFacade().getCheck().getCheckJobResult(parentJobId, checkJobId);
-            if (checkJobResult.values().stream().allMatch(TableDataConsistencyCheckResult::isSuccessful)) {
+            if (!checkJobResult.isEmpty() && checkJobResult.values().stream().allMatch(TableDataConsistencyCheckResult::isSuccessful)) {
                 jobItemContext.setStatus(JobStatus.FINISHED);
             } else {
                 jobItemContext.setStatus(JobStatus.CONSISTENCY_CHECK_FAILURE);