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 2c45de62b9c Add InventoryChannelCreator and IncrementalChannelCreator
(#32589)
2c45de62b9c is described below
commit 2c45de62b9cdcc6460470178e00deecb00cd577b
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Aug 19 00:06:43 2024 +0800
Add InventoryChannelCreator and IncrementalChannelCreator (#32589)
* Refactor PipelineTaskUtils
* Add InventoryChannelCreator and IncrementalChannelCreator
* Add InventoryChannelCreator and IncrementalChannelCreator
---
.../core/channel/IncrementalChannelCreator.java | 43 ++++++++++++++++++++
.../core/channel/InventoryChannelCreator.java | 46 ++++++++++++++++++++++
.../preparer/inventory/InventoryTaskSplitter.java | 5 ++-
.../data/pipeline/core/task/PipelineTaskUtils.java | 29 --------------
.../pipeline/cdc/core/prepare/CDCJobPreparer.java | 6 ++-
.../migration/preparer/MigrationJobPreparer.java | 3 +-
6 files changed, 98 insertions(+), 34 deletions(-)
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/channel/IncrementalChannelCreator.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/channel/IncrementalChannelCreator.java
new file mode 100644
index 00000000000..c809d0857fc
--- /dev/null
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/channel/IncrementalChannelCreator.java
@@ -0,0 +1,43 @@
+/*
+ * 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.channel;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.data.pipeline.core.task.IncrementalTaskAckCallback;
+import
org.apache.shardingsphere.data.pipeline.core.task.progress.IncrementalTaskProgress;
+import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+
+/**
+ * Incremental channel creator.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class IncrementalChannelCreator {
+
+ /**
+ * Create pipeline channel for incremental task.
+ *
+ * @param channelConfig pipeline channel configuration
+ * @param progress incremental task progress
+ * @return created pipeline channel
+ */
+ public static PipelineChannel create(final AlgorithmConfiguration
channelConfig, final IncrementalTaskProgress progress) {
+ return TypedSPILoader.getService(PipelineChannelCreator.class,
channelConfig.getType(), channelConfig.getProps()).newInstance(5, new
IncrementalTaskAckCallback(progress));
+ }
+}
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/channel/InventoryChannelCreator.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/channel/InventoryChannelCreator.java
new file mode 100644
index 00000000000..8d52f7e8b12
--- /dev/null
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/channel/InventoryChannelCreator.java
@@ -0,0 +1,46 @@
+/*
+ * 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.channel;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.data.pipeline.core.ingest.position.IngestPosition;
+import
org.apache.shardingsphere.data.pipeline.core.task.InventoryTaskAckCallback;
+import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Inventory channel creator.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class InventoryChannelCreator {
+
+ /**
+ * Create pipeline channel for inventory task.
+ *
+ * @param channelConfig pipeline channel configuration
+ * @param importerBatchSize importer batch size
+ * @param position ingest position
+ * @return created pipeline channel
+ */
+ public static PipelineChannel create(final AlgorithmConfiguration
channelConfig, final int importerBatchSize, final
AtomicReference<IngestPosition> position) {
+ return TypedSPILoader.getService(PipelineChannelCreator.class,
channelConfig.getType(),
channelConfig.getProps()).newInstance(importerBatchSize, new
InventoryTaskAckCallback(position));
+ }
+}
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/InventoryTaskSplitter.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/InventoryTaskSplitter.java
index 88a2f5536a5..2d614aa0dc9 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/InventoryTaskSplitter.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/InventoryTaskSplitter.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.data.pipeline.core.preparer.inventory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.Range;
+import
org.apache.shardingsphere.data.pipeline.core.channel.InventoryChannelCreator;
import org.apache.shardingsphere.data.pipeline.core.channel.PipelineChannel;
import
org.apache.shardingsphere.data.pipeline.core.context.TransmissionJobItemContext;
import
org.apache.shardingsphere.data.pipeline.core.context.TransmissionProcessContext;
@@ -83,7 +84,7 @@ public final class InventoryTaskSplitter {
TransmissionProcessContext processContext =
jobItemContext.getJobProcessContext();
for (InventoryDumperContext each :
splitInventoryDumperContext(jobItemContext)) {
AtomicReference<IngestPosition> position = new
AtomicReference<>(each.getCommonContext().getPosition());
- PipelineChannel channel =
PipelineTaskUtils.createInventoryChannel(processContext.getProcessConfiguration().getStreamChannel(),
importerConfig.getBatchSize(), position);
+ PipelineChannel channel =
InventoryChannelCreator.create(processContext.getProcessConfiguration().getStreamChannel(),
importerConfig.getBatchSize(), position);
Dumper dumper = new InventoryDumper(each, channel,
sourceDataSource, jobItemContext.getSourceMetaDataLoader());
Importer importer = new SingleChannelConsumerImporter(channel,
importerConfig.getBatchSize(), 3000L, jobItemContext.getSink(), jobItemContext);
result.add(new
InventoryTask(PipelineTaskUtils.generateInventoryTaskId(each),
processContext.getInventoryDumperExecuteEngine(),
@@ -209,7 +210,7 @@ public final class InventoryTaskSplitter {
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql)) {
resultSet.next();
- return Range.between(resultSet.getLong(1), resultSet.getLong(2));
+ return Range.of(resultSet.getLong(1), resultSet.getLong(2));
} catch (final SQLException ex) {
throw new
SplitPipelineJobByUniqueKeyException(dumperContext.getActualTableName(),
uniqueKey, ex);
}
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/task/PipelineTaskUtils.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/task/PipelineTaskUtils.java
index 99481541350..a29460f6fef 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/task/PipelineTaskUtils.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/task/PipelineTaskUtils.java
@@ -19,17 +19,12 @@ package org.apache.shardingsphere.data.pipeline.core.task;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.data.pipeline.core.channel.PipelineChannel;
-import
org.apache.shardingsphere.data.pipeline.core.channel.PipelineChannelCreator;
import
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.inventory.InventoryDumperContext;
import
org.apache.shardingsphere.data.pipeline.core.ingest.position.IngestPosition;
import
org.apache.shardingsphere.data.pipeline.core.job.progress.TransmissionJobItemProgress;
import
org.apache.shardingsphere.data.pipeline.core.task.progress.IncrementalTaskProgress;
-import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import java.util.Optional;
-import java.util.concurrent.atomic.AtomicReference;
/**
* Pipeline task utilities.
@@ -63,28 +58,4 @@ public final class PipelineTaskUtils {
}
return result;
}
-
- /**
- * Create pipeline channel for inventory task.
- *
- * @param channelConfig pipeline channel configuration
- * @param importerBatchSize importer batch size
- * @param position ingest position
- * @return created pipeline channel
- */
- public static PipelineChannel createInventoryChannel(final
AlgorithmConfiguration channelConfig, final int importerBatchSize, final
AtomicReference<IngestPosition> position) {
- return TypedSPILoader.getService(PipelineChannelCreator.class,
channelConfig.getType(),
channelConfig.getProps()).newInstance(importerBatchSize, new
InventoryTaskAckCallback(position));
- }
-
- /**
- * Create pipeline channel for incremental task.
- *
- * @param channelConfig pipeline channel configuration
- * @param progress incremental task progress
- * @return created pipeline channel
- */
- public static PipelineChannel createIncrementalChannel(final
AlgorithmConfiguration channelConfig, final IncrementalTaskProgress progress) {
- PipelineChannelCreator channelCreator =
TypedSPILoader.getService(PipelineChannelCreator.class,
channelConfig.getType(), channelConfig.getProps());
- return channelCreator.newInstance(5, new
IncrementalTaskAckCallback(progress));
- }
}
diff --git
a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/core/prepare/CDCJobPreparer.java
b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/core/prepare/CDCJobPreparer.java
index dde3d6a7176..57d86dcc8c8 100644
---
a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/core/prepare/CDCJobPreparer.java
+++
b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/core/prepare/CDCJobPreparer.java
@@ -25,6 +25,8 @@ import
org.apache.shardingsphere.data.pipeline.cdc.core.importer.CDCChannelProgr
import org.apache.shardingsphere.data.pipeline.cdc.core.importer.CDCImporter;
import
org.apache.shardingsphere.data.pipeline.cdc.core.task.CDCIncrementalTask;
import org.apache.shardingsphere.data.pipeline.cdc.core.task.CDCInventoryTask;
+import
org.apache.shardingsphere.data.pipeline.core.channel.IncrementalChannelCreator;
+import
org.apache.shardingsphere.data.pipeline.core.channel.InventoryChannelCreator;
import org.apache.shardingsphere.data.pipeline.core.channel.PipelineChannel;
import
org.apache.shardingsphere.data.pipeline.core.context.TransmissionProcessContext;
import
org.apache.shardingsphere.data.pipeline.core.exception.job.PrepareJobWithGetBinlogPositionException;
@@ -118,7 +120,7 @@ public final class CDCJobPreparer {
for (InventoryDumperContext each : new
InventoryTaskSplitter(jobItemContext.getSourceDataSource(), new
InventoryDumperContext(taskConfig.getDumperContext().getCommonContext()),
importerConfig)
.splitInventoryDumperContext(jobItemContext)) {
AtomicReference<IngestPosition> position = new
AtomicReference<>(each.getCommonContext().getPosition());
- PipelineChannel channel =
PipelineTaskUtils.createInventoryChannel(processContext.getProcessConfiguration().getStreamChannel(),
importerConfig.getBatchSize(), position);
+ PipelineChannel channel =
InventoryChannelCreator.create(processContext.getProcessConfiguration().getStreamChannel(),
importerConfig.getBatchSize(), position);
if (!(position.get() instanceof IngestFinishedPosition)) {
channelProgressPairs.add(new CDCChannelProgressPair(channel,
jobItemContext));
}
@@ -138,7 +140,7 @@ public final class CDCJobPreparer {
CDCTaskConfiguration taskConfig = jobItemContext.getTaskConfig();
IncrementalDumperContext dumperContext = taskConfig.getDumperContext();
IncrementalTaskProgress taskProgress =
PipelineTaskUtils.createIncrementalTaskProgress(dumperContext.getCommonContext().getPosition(),
jobItemContext.getInitProgress());
- PipelineChannel channel =
PipelineTaskUtils.createIncrementalChannel(jobItemContext.getJobProcessContext().getProcessConfiguration().getStreamChannel(),
taskProgress);
+ PipelineChannel channel =
IncrementalChannelCreator.create(jobItemContext.getJobProcessContext().getProcessConfiguration().getStreamChannel(),
taskProgress);
channelProgressPairs.add(new CDCChannelProgressPair(channel,
jobItemContext));
CreateIncrementalDumperParameter param = new
CreateIncrementalDumperParameter(
dumperContext, dumperContext.getCommonContext().getPosition(),
channel, jobItemContext.getSourceMetaDataLoader(),
jobItemContext.getDataSourceManager());
diff --git
a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java
b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java
index 29f21a14173..d30ef4d2390 100644
---
a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java
+++
b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.data.pipeline.scenario.migration.preparer;
import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.data.pipeline.api.PipelineDataSourceConfiguration;
import
org.apache.shardingsphere.data.pipeline.api.type.StandardPipelineDataSourceConfiguration;
+import
org.apache.shardingsphere.data.pipeline.core.channel.IncrementalChannelCreator;
import org.apache.shardingsphere.data.pipeline.core.channel.PipelineChannel;
import
org.apache.shardingsphere.data.pipeline.core.checker.PipelineDataSourceCheckEngine;
import
org.apache.shardingsphere.data.pipeline.core.context.PipelineContextManager;
@@ -195,7 +196,7 @@ public final class MigrationJobPreparer {
IncrementalDumperContext dumperContext = taskConfig.getDumperContext();
ExecuteEngine incrementalExecuteEngine =
jobItemContext.getJobProcessContext().getIncrementalExecuteEngine();
IncrementalTaskProgress taskProgress =
PipelineTaskUtils.createIncrementalTaskProgress(dumperContext.getCommonContext().getPosition(),
jobItemContext.getInitProgress());
- PipelineChannel channel =
PipelineTaskUtils.createIncrementalChannel(jobItemContext.getJobProcessContext().getProcessConfiguration().getStreamChannel(),
taskProgress);
+ PipelineChannel channel =
IncrementalChannelCreator.create(jobItemContext.getJobProcessContext().getProcessConfiguration().getStreamChannel(),
taskProgress);
CreateIncrementalDumperParameter param = new
CreateIncrementalDumperParameter(
dumperContext, dumperContext.getCommonContext().getPosition(),
channel, jobItemContext.getSourceMetaDataLoader(),
jobItemContext.getDataSourceManager());
Dumper dumper = IncrementalDumperCreator.create(param);