anton-vinogradov commented on a change in pull request #49:
URL: https://github.com/apache/ignite-extensions/pull/49#discussion_r649769612



##########
File path: 
modules/cdc-to-kafka-ext/src/main/java/org/apache/ignite/cdc/conflictplugin/CacheVersionConflictResolverCachePluginProvider.java
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.ignite.cdc.conflictplugin;
+
+import javax.cache.Cache;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import 
org.apache.ignite.internal.processors.cache.CacheConflictResolutionManager;
+import 
org.apache.ignite.internal.processors.cache.version.CacheVersionConflictResolver;
+import org.apache.ignite.plugin.CachePluginConfiguration;
+import org.apache.ignite.plugin.CachePluginProvider;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Intermediate component to provide {@link 
CacheConflictResolutionManagerImpl} for specific cache.
+ *
+ * @see CacheConflictResolutionManagerImpl
+ * @see CacheVersionConflictResolverImpl
+ * @see CacheVersionConflictResolver
+ */
+public class CacheVersionConflictResolverCachePluginProvider<K, V, C extends 
CachePluginConfiguration<K, V>>
+    implements CachePluginProvider<C> {
+    /**
+     * Field for conflict resolve.
+     * Value of this field will be used to compare two entries in case of 
conflicting changes.
+     * Note, values of this field must implement {@link Comparable}.
+     *
+     * @see CacheVersionConflictResolverImpl
+     */
+    private final String conflictResolveField;

Review comment:
       Please mention this used only for external data applying.

##########
File path: 
modules/cdc-to-kafka-ext/src/main/java/org/apache/ignite/cdc/conflictplugin/CacheVersionConflictResolverPluginProvider.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.ignite.cdc.conflictplugin;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.IgniteEx;
+import 
org.apache.ignite.internal.processors.cache.version.CacheVersionConflictResolver;
+import org.apache.ignite.plugin.CachePluginContext;
+import org.apache.ignite.plugin.CachePluginProvider;
+import org.apache.ignite.plugin.ExtensionRegistry;
+import org.apache.ignite.plugin.IgnitePlugin;
+import org.apache.ignite.plugin.PluginConfiguration;
+import org.apache.ignite.plugin.PluginContext;
+import org.apache.ignite.plugin.PluginProvider;
+import org.apache.ignite.plugin.PluginValidationException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Plugin to enable {@link CacheVersionConflictResolverImpl} for provided 
caches.
+ *
+ * @see CacheVersionConflictResolverImpl
+ * @see CacheVersionConflictResolver
+ */
+public class CacheVersionConflictResolverPluginProvider<C extends 
PluginConfiguration> implements PluginProvider<C> {
+    /** Plugin context. */
+    private PluginContext ctx;
+
+    /** Cluster id. */
+    private byte clusterId;
+
+    /** Cache names. */
+    private Set<String> caches;
+
+    /**
+     * Field for conflict resolve.
+     * Value of this field will be used to compare two entries in case of 
conflicting changes.
+     * Note, values of this field must implement {@link Comparable}.
+     *
+     * @see CacheVersionConflictResolverImpl
+     */
+    private String conflictResolveField;
+
+    /** Cache plugin provider. */
+    private CachePluginProvider<?> provider;
+
+    /** */
+    public CacheVersionConflictResolverPluginProvider() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return "cache-version-conflict-resolver";

Review comment:
       How about the plain name like "Cache version ..."?

##########
File path: 
modules/cdc-to-kafka-ext/src/main/java/org/apache/ignite/cdc/conflictplugin/CacheVersionConflictResolverPluginProvider.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.ignite.cdc.conflictplugin;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.IgniteEx;
+import 
org.apache.ignite.internal.processors.cache.version.CacheVersionConflictResolver;
+import org.apache.ignite.plugin.CachePluginContext;
+import org.apache.ignite.plugin.CachePluginProvider;
+import org.apache.ignite.plugin.ExtensionRegistry;
+import org.apache.ignite.plugin.IgnitePlugin;
+import org.apache.ignite.plugin.PluginConfiguration;
+import org.apache.ignite.plugin.PluginContext;
+import org.apache.ignite.plugin.PluginProvider;
+import org.apache.ignite.plugin.PluginValidationException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Plugin to enable {@link CacheVersionConflictResolverImpl} for provided 
caches.
+ *
+ * @see CacheVersionConflictResolverImpl
+ * @see CacheVersionConflictResolver
+ */
+public class CacheVersionConflictResolverPluginProvider<C extends 
PluginConfiguration> implements PluginProvider<C> {
+    /** Plugin context. */
+    private PluginContext ctx;
+
+    /** Cluster id. */
+    private byte clusterId;
+
+    /** Cache names. */
+    private Set<String> caches;
+
+    /**
+     * Field for conflict resolve.
+     * Value of this field will be used to compare two entries in case of 
conflicting changes.
+     * Note, values of this field must implement {@link Comparable}.
+     *
+     * @see CacheVersionConflictResolverImpl
+     */
+    private String conflictResolveField;
+
+    /** Cache plugin provider. */
+    private CachePluginProvider<?> provider;
+
+    /** */
+    public CacheVersionConflictResolverPluginProvider() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return "cache-version-conflict-resolver";
+    }
+
+    /** {@inheritDoc} */
+    @Override public String version() {
+        return "0.0.1-SNAPSHOT";

Review comment:
       1.0.0-SNAPSHOT

##########
File path: 
modules/cdc-ext/src/main/java/org/apache/ignite/cdc/kafka/KafkaToIgniteCdcStreamer.java
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.ignite.cdc.kafka;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cdc.ChangeDataCaptureEvent;
+import 
org.apache.ignite.cdc.conflictresolve.CacheConflictResolutionManagerImpl;
+import org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.cdc.ChangeDataCapture;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.ByteArrayDeserializer;
+import org.apache.kafka.common.serialization.IntegerDeserializer;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG;
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG;
+
+/**
+ * Main class of Kafka to Ignite application.
+ * This application is counterpart of {@link IgniteToKafkaCdcStreamer} Change 
Data Capture consumer.
+ * Application runs several {@link Applier} thread to read Kafka topic 
partitions and apply {@link ChangeDataCaptureEvent} to Ignite.
+ * <p>
+ * Each applier receive even number of kafka topic partition to read.
+ * <p>
+ * In case of any error during read applier just fail. Fail of any applier 
will lead to the fail of whole application.
+ * It expected that application will be configured for automatic restarts with 
the OS tool to failover temporary errors
+ * such as Kafka or Ignite unavailability.
+ * <p>
+ * To resolve possible update conflicts(in case of concurrent update in source 
and destination Ignite clusters)

Review comment:
       > conflicts(in
   
   whitespace missed

##########
File path: 
modules/cdc-ext/src/main/java/org/apache/ignite/cdc/kafka/KafkaToIgniteCdcStreamer.java
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.ignite.cdc.kafka;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cdc.ChangeDataCaptureEvent;
+import 
org.apache.ignite.cdc.conflictresolve.CacheConflictResolutionManagerImpl;
+import org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.cdc.ChangeDataCapture;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.ByteArrayDeserializer;
+import org.apache.kafka.common.serialization.IntegerDeserializer;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG;
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG;
+
+/**
+ * Main class of Kafka to Ignite application.
+ * This application is counterpart of {@link IgniteToKafkaCdcStreamer} Change 
Data Capture consumer.
+ * Application runs several {@link Applier} thread to read Kafka topic 
partitions and apply {@link ChangeDataCaptureEvent} to Ignite.
+ * <p>
+ * Each applier receive even number of kafka topic partition to read.
+ * <p>
+ * In case of any error during read applier just fail. Fail of any applier 
will lead to the fail of whole application.
+ * It expected that application will be configured for automatic restarts with 
the OS tool to failover temporary errors
+ * such as Kafka or Ignite unavailability.
+ * <p>
+ * To resolve possible update conflicts(in case of concurrent update in source 
and destination Ignite clusters)
+ * real-world deployments should use some conflict resolver, for example 
{@link CacheVersionConflictResolverImpl}.
+ * Example of Ignite configuration with the conflict resolver:
+ * <pre>
+ * {@code
+ * CacheVersionConflictResolverCachePluginProvider conflictPlugin = new 
CacheVersionConflictResolverCachePluginProvider();
+ *
+ * conflictPlugin.setClusterId(clusterId); // Cluster id.
+ * conflictPlugin.setCaches(new HashSet<>(Arrays.asList("my-cache", 
"some-other-cache"))); // Caches to replicate.
+ *
+ * IgniteConfiguration cfg = ...;
+ *
+ * cfg.setPluginProviders(conflictPlugin);
+ * }
+ * </pre>
+ * Please, see {@link CacheConflictResolutionManagerImpl} for additional 
information.
+ *
+ * @see ChangeDataCapture
+ * @see IgniteToKafkaCdcStreamer
+ * @see ChangeDataCaptureEvent
+ * @see Applier
+ * @see CacheConflictResolutionManagerImpl
+ */
+public class KafkaToIgniteCdcStreamer implements Runnable {
+    /** Ignite configuration. */
+    private final IgniteConfiguration igniteCfg;
+
+    /** Kafka consumer properties. */
+    private final Properties kafkaProps;
+
+    /** Streamer configuration. */
+    private final KafkaToIgniteCdcStreamerConfiguration streamerCfg;
+
+    /** Executor service to run {@link Applier} instances. */
+    private final ExecutorService execSvc;
+
+    /** Appliers. */
+    private final List<Applier> appliers;
+
+    /**
+     * @param igniteCfg Ignite configuration.
+     * @param kafkaProps Kafka properties.
+     * @param streamerCfg Streamer configuration.
+     */
+    public KafkaToIgniteCdcStreamer(
+        IgniteConfiguration igniteCfg,
+        Properties kafkaProps,
+        KafkaToIgniteCdcStreamerConfiguration streamerCfg
+    ) {
+        this.igniteCfg = igniteCfg;
+        this.kafkaProps = kafkaProps;
+        this.streamerCfg = streamerCfg;
+
+        appliers = new ArrayList<>(streamerCfg.getThreadCount());
+
+        execSvc = Executors.newFixedThreadPool(streamerCfg.getThreadCount(), 
new ThreadFactory() {
+            private final AtomicInteger cntr = new AtomicInteger();
+
+            @Override public Thread newThread(@NotNull Runnable r) {
+                Thread th = new Thread(r);
+
+                th.setName("applier-thread-" + cntr.getAndIncrement());
+
+                return th;
+            }
+        });
+
+        if (!kafkaProps.containsKey(ConsumerConfig.GROUP_ID_CONFIG))
+            throw new IllegalArgumentException("Kafka properties don't 
contains " + ConsumerConfig.GROUP_ID_CONFIG);
+
+        kafkaProps.put(KEY_DESERIALIZER_CLASS_CONFIG, 
IntegerDeserializer.class.getName());
+        kafkaProps.put(VALUE_DESERIALIZER_CLASS_CONFIG, 
ByteArrayDeserializer.class.getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void run() {
+        try (IgniteEx ign = (IgniteEx)Ignition.start(igniteCfg)) {
+            IgniteLogger log = U.initLogger(
+                igniteCfg.getGridLogger(),
+                "kafka-ignite-streamer",
+                igniteCfg.getNodeId() != null ? igniteCfg.getNodeId() : 
UUID.randomUUID(),
+                igniteCfg.getWorkDirectory()
+            );

Review comment:
       duplicates code at ChangeDataCapture#ChangeDataCapture
   
   Could we deduplicate this?

##########
File path: 
modules/cdc-ext/src/main/java/org/apache/ignite/cdc/kafka/KafkaToIgniteCdcStreamer.java
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.ignite.cdc.kafka;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cdc.ChangeDataCaptureEvent;
+import 
org.apache.ignite.cdc.conflictresolve.CacheConflictResolutionManagerImpl;
+import org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.cdc.ChangeDataCapture;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.ByteArrayDeserializer;
+import org.apache.kafka.common.serialization.IntegerDeserializer;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG;
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG;
+
+/**
+ * Main class of Kafka to Ignite application.
+ * This application is counterpart of {@link IgniteToKafkaCdcStreamer} Change 
Data Capture consumer.
+ * Application runs several {@link Applier} thread to read Kafka topic 
partitions and apply {@link ChangeDataCaptureEvent} to Ignite.
+ * <p>
+ * Each applier receive even number of kafka topic partition to read.
+ * <p>
+ * In case of any error during read applier just fail. Fail of any applier 
will lead to the fail of whole application.
+ * It expected that application will be configured for automatic restarts with 
the OS tool to failover temporary errors
+ * such as Kafka or Ignite unavailability.
+ * <p>
+ * To resolve possible update conflicts(in case of concurrent update in source 
and destination Ignite clusters)
+ * real-world deployments should use some conflict resolver, for example 
{@link CacheVersionConflictResolverImpl}.
+ * Example of Ignite configuration with the conflict resolver:
+ * <pre>
+ * {@code
+ * CacheVersionConflictResolverCachePluginProvider conflictPlugin = new 
CacheVersionConflictResolverCachePluginProvider();
+ *
+ * conflictPlugin.setClusterId(clusterId); // Cluster id.
+ * conflictPlugin.setCaches(new HashSet<>(Arrays.asList("my-cache", 
"some-other-cache"))); // Caches to replicate.
+ *
+ * IgniteConfiguration cfg = ...;
+ *
+ * cfg.setPluginProviders(conflictPlugin);
+ * }
+ * </pre>
+ * Please, see {@link CacheConflictResolutionManagerImpl} for additional 
information.
+ *
+ * @see ChangeDataCapture
+ * @see IgniteToKafkaCdcStreamer
+ * @see ChangeDataCaptureEvent
+ * @see Applier
+ * @see CacheConflictResolutionManagerImpl
+ */
+public class KafkaToIgniteCdcStreamer implements Runnable {
+    /** Ignite configuration. */
+    private final IgniteConfiguration igniteCfg;
+
+    /** Kafka consumer properties. */
+    private final Properties kafkaProps;
+
+    /** Streamer configuration. */
+    private final KafkaToIgniteCdcStreamerConfiguration streamerCfg;
+
+    /** Executor service to run {@link Applier} instances. */
+    private final ExecutorService execSvc;
+
+    /** Appliers. */
+    private final List<Applier> appliers;
+
+    /**
+     * @param igniteCfg Ignite configuration.
+     * @param kafkaProps Kafka properties.
+     * @param streamerCfg Streamer configuration.
+     */
+    public KafkaToIgniteCdcStreamer(
+        IgniteConfiguration igniteCfg,
+        Properties kafkaProps,
+        KafkaToIgniteCdcStreamerConfiguration streamerCfg
+    ) {
+        this.igniteCfg = igniteCfg;
+        this.kafkaProps = kafkaProps;
+        this.streamerCfg = streamerCfg;
+
+        appliers = new ArrayList<>(streamerCfg.getThreadCount());
+
+        execSvc = Executors.newFixedThreadPool(streamerCfg.getThreadCount(), 
new ThreadFactory() {
+            private final AtomicInteger cntr = new AtomicInteger();
+
+            @Override public Thread newThread(@NotNull Runnable r) {
+                Thread th = new Thread(r);
+
+                th.setName("applier-thread-" + cntr.getAndIncrement());
+
+                return th;
+            }
+        });
+
+        if (!kafkaProps.containsKey(ConsumerConfig.GROUP_ID_CONFIG))
+            throw new IllegalArgumentException("Kafka properties don't 
contains " + ConsumerConfig.GROUP_ID_CONFIG);
+
+        kafkaProps.put(KEY_DESERIALIZER_CLASS_CONFIG, 
IntegerDeserializer.class.getName());
+        kafkaProps.put(VALUE_DESERIALIZER_CLASS_CONFIG, 
ByteArrayDeserializer.class.getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void run() {
+        try (IgniteEx ign = (IgniteEx)Ignition.start(igniteCfg)) {
+            IgniteLogger log = U.initLogger(
+                igniteCfg.getGridLogger(),
+                "kafka-ignite-streamer",
+                igniteCfg.getNodeId() != null ? igniteCfg.getNodeId() : 
UUID.randomUUID(),
+                igniteCfg.getWorkDirectory()
+            );
+
+            AtomicBoolean closed = new AtomicBoolean();
+
+            Set<Integer> caches = null;
+
+            if (!F.isEmpty(streamerCfg.getCacheNames())) {
+                caches = streamerCfg.getCacheNames().stream()
+                    .peek(cache -> Objects.requireNonNull(ign.cache(cache), 
cache + " not exists!"))
+                    .map(CU::cacheId).collect(Collectors.toSet());
+            }
+
+            int partPerApplier = streamerCfg.getKafkaPartitions() / 
streamerCfg.getThreadCount();

Review comment:
       > streamerCfg.getKafkaPartitions() and streamerCfg.getThreadCount()
   
   call, set to variable, use twice or more.

##########
File path: 
modules/cdc-ext/src/main/java/org/apache/ignite/cdc/kafka/KafkaToIgniteCdcStreamer.java
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.ignite.cdc.kafka;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cdc.ChangeDataCaptureEvent;
+import 
org.apache.ignite.cdc.conflictresolve.CacheConflictResolutionManagerImpl;
+import org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.cdc.ChangeDataCapture;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.ByteArrayDeserializer;
+import org.apache.kafka.common.serialization.IntegerDeserializer;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG;
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG;
+
+/**
+ * Main class of Kafka to Ignite application.
+ * This application is counterpart of {@link IgniteToKafkaCdcStreamer} Change 
Data Capture consumer.
+ * Application runs several {@link Applier} thread to read Kafka topic 
partitions and apply {@link ChangeDataCaptureEvent} to Ignite.
+ * <p>
+ * Each applier receive even number of kafka topic partition to read.
+ * <p>
+ * In case of any error during read applier just fail. Fail of any applier 
will lead to the fail of whole application.
+ * It expected that application will be configured for automatic restarts with 
the OS tool to failover temporary errors
+ * such as Kafka or Ignite unavailability.
+ * <p>
+ * To resolve possible update conflicts(in case of concurrent update in source 
and destination Ignite clusters)
+ * real-world deployments should use some conflict resolver, for example 
{@link CacheVersionConflictResolverImpl}.
+ * Example of Ignite configuration with the conflict resolver:
+ * <pre>
+ * {@code
+ * CacheVersionConflictResolverCachePluginProvider conflictPlugin = new 
CacheVersionConflictResolverCachePluginProvider();
+ *
+ * conflictPlugin.setClusterId(clusterId); // Cluster id.
+ * conflictPlugin.setCaches(new HashSet<>(Arrays.asList("my-cache", 
"some-other-cache"))); // Caches to replicate.
+ *
+ * IgniteConfiguration cfg = ...;
+ *
+ * cfg.setPluginProviders(conflictPlugin);
+ * }
+ * </pre>
+ * Please, see {@link CacheConflictResolutionManagerImpl} for additional 
information.
+ *
+ * @see ChangeDataCapture
+ * @see IgniteToKafkaCdcStreamer
+ * @see ChangeDataCaptureEvent
+ * @see Applier
+ * @see CacheConflictResolutionManagerImpl
+ */
+public class KafkaToIgniteCdcStreamer implements Runnable {
+    /** Ignite configuration. */
+    private final IgniteConfiguration igniteCfg;
+
+    /** Kafka consumer properties. */
+    private final Properties kafkaProps;
+
+    /** Streamer configuration. */
+    private final KafkaToIgniteCdcStreamerConfiguration streamerCfg;
+
+    /** Executor service to run {@link Applier} instances. */
+    private final ExecutorService execSvc;
+
+    /** Appliers. */
+    private final List<Applier> appliers;
+
+    /**
+     * @param igniteCfg Ignite configuration.
+     * @param kafkaProps Kafka properties.
+     * @param streamerCfg Streamer configuration.
+     */
+    public KafkaToIgniteCdcStreamer(
+        IgniteConfiguration igniteCfg,
+        Properties kafkaProps,
+        KafkaToIgniteCdcStreamerConfiguration streamerCfg
+    ) {
+        this.igniteCfg = igniteCfg;
+        this.kafkaProps = kafkaProps;
+        this.streamerCfg = streamerCfg;
+
+        appliers = new ArrayList<>(streamerCfg.getThreadCount());

Review comment:
       > streamerCfg.getThreadCount()
   
   call, set to variable, use twice or more.

##########
File path: 
modules/cdc-ext/src/main/java/org/apache/ignite/cdc/kafka/KafkaToIgniteCdcStreamerConfiguration.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.ignite.cdc.kafka;
+
+import java.util.Collection;
+import java.util.Map;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+
+/**
+ * Configuration of {@link KafkaToIgniteCdcStreamer} application.
+ *
+ * @see KafkaToIgniteCdcStreamer
+ * @see KafkaToIgniteLoader
+ */
+public class KafkaToIgniteCdcStreamerConfiguration {
+    /** Default {@link #kafkaParts} value. */
+    public static final int DFLT_PARTS = 16;
+
+    /** Default {@link #topic} value. */
+    public static final String DFLT_TOPIC = "ignite";
+
+    /** Default {@link #maxBatchSize} value. */
+    public static final int DFLT_MAX_BATCH_SIZE = 1024;
+
+    /** {@link Applier} thread count. */
+    private int threadCnt = DFLT_PARTS;
+
+    /** Topic name. */
+    private String topic = DFLT_TOPIC;
+
+    /** Kafka partitions count. */
+    private int kafkaParts = DFLT_PARTS;

Review comment:
       Do we really need 2 params with the same defaults?
   Seems that having `kafkaParts` is enough and some `topics per thread` may be 
required, instead of `partPerApplier` calculation?

##########
File path: 
modules/cdc-ext/src/main/java/org/apache/ignite/cdc/kafka/KafkaToIgniteCdcStreamer.java
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.ignite.cdc.kafka;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cdc.ChangeDataCaptureEvent;
+import 
org.apache.ignite.cdc.conflictresolve.CacheConflictResolutionManagerImpl;
+import org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.cdc.ChangeDataCapture;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.ByteArrayDeserializer;
+import org.apache.kafka.common.serialization.IntegerDeserializer;
+import org.jetbrains.annotations.NotNull;
+
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG;
+import static 
org.apache.kafka.clients.consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG;
+
+/**
+ * Main class of Kafka to Ignite application.
+ * This application is counterpart of {@link IgniteToKafkaCdcStreamer} Change 
Data Capture consumer.
+ * Application runs several {@link Applier} thread to read Kafka topic 
partitions and apply {@link ChangeDataCaptureEvent} to Ignite.
+ * <p>
+ * Each applier receive even number of kafka topic partition to read.
+ * <p>
+ * In case of any error during read applier just fail. Fail of any applier 
will lead to the fail of whole application.
+ * It expected that application will be configured for automatic restarts with 
the OS tool to failover temporary errors
+ * such as Kafka or Ignite unavailability.
+ * <p>
+ * To resolve possible update conflicts(in case of concurrent update in source 
and destination Ignite clusters)
+ * real-world deployments should use some conflict resolver, for example 
{@link CacheVersionConflictResolverImpl}.
+ * Example of Ignite configuration with the conflict resolver:
+ * <pre>
+ * {@code
+ * CacheVersionConflictResolverCachePluginProvider conflictPlugin = new 
CacheVersionConflictResolverCachePluginProvider();
+ *
+ * conflictPlugin.setClusterId(clusterId); // Cluster id.
+ * conflictPlugin.setCaches(new HashSet<>(Arrays.asList("my-cache", 
"some-other-cache"))); // Caches to replicate.
+ *
+ * IgniteConfiguration cfg = ...;
+ *
+ * cfg.setPluginProviders(conflictPlugin);
+ * }
+ * </pre>
+ * Please, see {@link CacheConflictResolutionManagerImpl} for additional 
information.
+ *
+ * @see ChangeDataCapture
+ * @see IgniteToKafkaCdcStreamer
+ * @see ChangeDataCaptureEvent
+ * @see Applier
+ * @see CacheConflictResolutionManagerImpl
+ */
+public class KafkaToIgniteCdcStreamer implements Runnable {
+    /** Ignite configuration. */
+    private final IgniteConfiguration igniteCfg;
+
+    /** Kafka consumer properties. */
+    private final Properties kafkaProps;
+
+    /** Streamer configuration. */
+    private final KafkaToIgniteCdcStreamerConfiguration streamerCfg;
+
+    /** Executor service to run {@link Applier} instances. */
+    private final ExecutorService execSvc;
+
+    /** Appliers. */
+    private final List<Applier> appliers;
+
+    /**
+     * @param igniteCfg Ignite configuration.
+     * @param kafkaProps Kafka properties.
+     * @param streamerCfg Streamer configuration.
+     */
+    public KafkaToIgniteCdcStreamer(
+        IgniteConfiguration igniteCfg,
+        Properties kafkaProps,
+        KafkaToIgniteCdcStreamerConfiguration streamerCfg
+    ) {
+        this.igniteCfg = igniteCfg;
+        this.kafkaProps = kafkaProps;
+        this.streamerCfg = streamerCfg;
+
+        appliers = new ArrayList<>(streamerCfg.getThreadCount());
+
+        execSvc = Executors.newFixedThreadPool(streamerCfg.getThreadCount(), 
new ThreadFactory() {
+            private final AtomicInteger cntr = new AtomicInteger();
+
+            @Override public Thread newThread(@NotNull Runnable r) {
+                Thread th = new Thread(r);
+
+                th.setName("applier-thread-" + cntr.getAndIncrement());
+
+                return th;
+            }
+        });
+
+        if (!kafkaProps.containsKey(ConsumerConfig.GROUP_ID_CONFIG))
+            throw new IllegalArgumentException("Kafka properties don't 
contains " + ConsumerConfig.GROUP_ID_CONFIG);
+
+        kafkaProps.put(KEY_DESERIALIZER_CLASS_CONFIG, 
IntegerDeserializer.class.getName());
+        kafkaProps.put(VALUE_DESERIALIZER_CLASS_CONFIG, 
ByteArrayDeserializer.class.getName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void run() {
+        try (IgniteEx ign = (IgniteEx)Ignition.start(igniteCfg)) {
+            IgniteLogger log = U.initLogger(
+                igniteCfg.getGridLogger(),
+                "kafka-ignite-streamer",
+                igniteCfg.getNodeId() != null ? igniteCfg.getNodeId() : 
UUID.randomUUID(),
+                igniteCfg.getWorkDirectory()
+            );
+
+            AtomicBoolean closed = new AtomicBoolean();
+
+            Set<Integer> caches = null;
+
+            if (!F.isEmpty(streamerCfg.getCacheNames())) {
+                caches = streamerCfg.getCacheNames().stream()
+                    .peek(cache -> Objects.requireNonNull(ign.cache(cache), 
cache + " not exists!"))
+                    .map(CU::cacheId).collect(Collectors.toSet());
+            }
+
+            int partPerApplier = streamerCfg.getKafkaPartitions() / 
streamerCfg.getThreadCount();
+
+            for (int i = 0; i < streamerCfg.getThreadCount(); i++) {
+                int from = i * partPerApplier;
+
+                int to = (i == streamerCfg.getThreadCount() - 1)
+                    ? streamerCfg.getKafkaPartitions() + 1
+                    : (i + 1) * partPerApplier;

Review comment:
       some black magic detected here :)
   spent 2 minutes and still have no clue what's going on here %) 
   
   why not just iterate over the appliers and partitions, and append parts to 
appliers?




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

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


Reply via email to