hailin0 commented on code in PR #4147:
URL: 
https://github.com/apache/incubator-seatunnel/pull/4147#discussion_r1109599928


##########
seatunnel-engine/seatunnel-engine-core/src/main/java/org/apache/seatunnel/engine/core/dag/actions/ShuffleConfig.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.seatunnel.engine.core.dag.actions;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import org.apache.seatunnel.api.table.type.MultipleRowType;
+import org.apache.seatunnel.api.table.type.Record;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+
+import com.hazelcast.collection.IQueue;
+import com.hazelcast.config.QueueConfig;
+import com.hazelcast.core.HazelcastInstance;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+@Getter
+@Setter
+@Accessors(chain = true)
+@ToString
+@NoArgsConstructor
+public class ShuffleConfig implements Config {
+    public static final int DEFAULT_QUEUE_SIZE = 2048;
+    public static final int DEFAULT_QUEUE_BACKUP_COUNT = 0;
+    public static final int DEFAULT_QUEUE_ASYNC_BACKUP_COUNT = 0;
+    public static final int DEFAULT_BATCH_SIZE = 1024;
+    public static final long DEFAULT_BATCH_FLUSH_INTERVAL = 
TimeUnit.SECONDS.toMillis(3);
+
+    private int batchSize;
+    private long batchFlushInterval;
+    private ShuffleStrategy shuffleStrategy;
+
+    @Getter
+    @Setter
+    @AllArgsConstructor
+    @NoArgsConstructor
+    @ToString
+    public abstract static class ShuffleStrategy implements Serializable {
+        private long jobId;
+        private int inputPartitions;
+        private int targetPartitions;
+        private QueueConfig queueConfig;
+
+        public abstract Map<String, IQueue<Record<?>>> 
createShuffles(HazelcastInstance hazelcast, int inputIndex);
+
+        public abstract String createShuffleKey(Record<?> record, int 
inputIndex);
+
+        public abstract IQueue<Record<?>>[] getShuffles(HazelcastInstance 
hazelcast, int targetIndex);
+
+        protected IQueue<Record<?>> getIQueue(HazelcastInstance hazelcast, 
String queueName) {
+            QueueConfig targetQueueConfig = 
hazelcast.getConfig().getQueueConfig(queueName);
+            if (queueConfig != null) {
+                targetQueueConfig.setMaxSize(queueConfig.getMaxSize())
+                    .setBackupCount(queueConfig.getBackupCount())
+                    .setAsyncBackupCount(queueConfig.getAsyncBackupCount())
+                    .setEmptyQueueTtl(queueConfig.getEmptyQueueTtl());
+            }
+            return hazelcast.getQueue(queueName);
+        }
+    }
+
+    @NoArgsConstructor
+    @ToString
+    public static class PartitionShuffleStrategy extends ShuffleStrategy {
+        private final Map<Integer, String[]> inputQueueMapping = new 
HashMap<>();
+
+        public PartitionShuffleStrategy(long jobId,
+                                        int inputPartitions,
+                                        int targetPartitions) {
+            this(jobId, inputPartitions, targetPartitions, null);
+        }
+
+        public PartitionShuffleStrategy(long jobId,
+                                        int inputPartitions,
+                                        int targetPartitions,
+                                        QueueConfig queueConfig) {
+            super(jobId, inputPartitions, targetPartitions, queueConfig);
+        }
+
+        @Override
+        public Map<String, IQueue<Record<?>>> createShuffles(HazelcastInstance 
hazelcast, int inputIndex) {
+            checkArgument(inputIndex >= 0 && inputIndex < 
getInputPartitions());
+            Map<String, IQueue<Record<?>>> shuffleMap = new HashMap<>();
+            for (int targetIndex = 0; targetIndex < getTargetPartitions(); 
targetIndex++) {
+                String queueName = generateQueueName(inputIndex, targetIndex);
+                IQueue<Record<?>> queue = getIQueue(hazelcast, queueName);
+                shuffleMap.put(queueName, queue);

Review Comment:
   fixed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to