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



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/cdc/IgniteCDC.java
##########
@@ -0,0 +1,481 @@
+/*
+ * 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.internal.cdc;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cdc.ChangeDataCaptureConfiguration;
+import org.apache.ignite.cdc.ChangeDataCaptureConsumer;
+import org.apache.ignite.cdc.ChangeDataCaptureEvent;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.MarshallerContextImpl;
+import org.apache.ignite.internal.pagemem.wal.WALIterator;
+import 
org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import 
org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver;
+import 
org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings;
+import org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory;
+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.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.startup.cmdline.CDCCommandLineStartup;
+
+import static 
org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.DATA_RECORD_V2;
+import static 
org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager.WAL_NAME_PATTERN;
+
+/**
+ * CDC(Change Data Capture) application.
+ * Application run independently of Ignite node process and provide ability 
for the {@link ChangeDataCaptureConsumer}
+ * to consume events({@link ChangeDataCaptureEvent}) from WAL segments.
+ * User should responsible {@link ChangeDataCaptureConsumer} implementation 
with custom consumption logic.
+ *
+ * Ignite node should be explicitly configured for using {@link IgniteCDC}.
+ * <ol>
+ *     <li>Set {@link DataStorageConfiguration#setCdcEnabled(boolean)} to 
true.</li>
+ *     <li>Optional: Set {@link DataStorageConfiguration#setCdcPath(String)} 
to path to the directory to store
+ *     WAL segments for CDC.</li>
+ *     <li>Optional: Set {@link 
DataStorageConfiguration#setWalForceArchiveTimeout(long)} to configure timeout 
for
+ *     force WAL rollover, so new events will be available for consumptions 
with the predicted time.</li>
+ * </ol>
+ *
+ * When {@link DataStorageConfiguration#getCdcPath()} is true then Ignite node 
on each WAL segment rollover creates
+ * hard link to archive WAL segment in {@link 
DataStorageConfiguration#getCdcPath()} directory.
+ * {@link IgniteCDC} application takes segment file and consumes events from 
it.
+ * After successful consumption (see {@link 
ChangeDataCaptureConsumer#onChange(Iterator)})
+ * WAL segment will be deleted from directory.
+ *
+ * Several Ignite nodes can be started on the same host.
+ * If your deployment done with custom consistent id then you should specify 
it via
+ * {@link IgniteConfiguration#setConsistentId(Serializable)} in provided 
{@link IgniteConfiguration}.
+ *
+ * Application works as follows:
+ * <ol>
+ *     <li>Search node work directory based on provided {@link 
IgniteConfiguration}.</li>
+ *     <li>Await for creation of CDC directory if it not exists.</li>
+ *     <li>Acquire file lock to ensure exclusive consumption.</li>
+ *     <li>Loads state of consumption if it exists.</li>
+ *     <li>Infinetely wait for new available segment and process it.</li>
+ * </ol>
+ *
+ * @see DataStorageConfiguration#setCdcEnabled(boolean)
+ * @see DataStorageConfiguration#setCdcPath(String)
+ * @see DataStorageConfiguration#setWalForceArchiveTimeout(long)
+ * @see CDCCommandLineStartup
+ * @see ChangeDataCaptureConsumer
+ * @see DataStorageConfiguration#DFLT_CDC_PATH
+ */
+public class IgniteCDC implements Runnable {
+    /** State dir. */
+    public static final String STATE_DIR = "state";
+
+    /** Wal segments filter. */
+    private static final Predicate<Path> WAL_SEGMENTS_FILTER =
+        p -> WAL_NAME_PATTERN.matcher(p.getFileName().toString()).matches();
+
+    /** Ignite configuration. */
+    private final IgniteConfiguration cfg;
+
+    /** CDC configuration. */
+    private final ChangeDataCaptureConfiguration cdcCfg;
+
+    /** WAL iterator factory. */
+    private final IgniteWalIteratorFactory factory;
+
+    /** Events consumer. */
+    private final WALRecordsConsumer<?, ?> consumer;
+
+    /** Logger. */
+    private final IgniteLogger log;
+
+    /** CDC directory. */
+    private Path cdcDir;
+
+    /** Binary meta directory. */
+    private File binaryMeta;
+
+    /** Marshaller directory. */
+    private File marshaller;
+
+    /** CDC state. */
+    private CDCConsumerState state;
+
+    /** Save state to start from. */
+    private WALPointer initState;
+
+    /** Stoped flag. */

Review comment:
       Stopped.

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/cdc/IgniteCDC.java
##########
@@ -0,0 +1,481 @@
+/*
+ * 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.internal.cdc;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cdc.ChangeDataCaptureConfiguration;
+import org.apache.ignite.cdc.ChangeDataCaptureConsumer;
+import org.apache.ignite.cdc.ChangeDataCaptureEvent;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.MarshallerContextImpl;
+import org.apache.ignite.internal.pagemem.wal.WALIterator;
+import 
org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import 
org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver;
+import 
org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings;
+import org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer;
+import 
org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory;
+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.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.startup.cmdline.CDCCommandLineStartup;
+
+import static 
org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.DATA_RECORD_V2;
+import static 
org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager.WAL_NAME_PATTERN;
+
+/**
+ * CDC(Change Data Capture) application.
+ * Application run independently of Ignite node process and provide ability 
for the {@link ChangeDataCaptureConsumer}
+ * to consume events({@link ChangeDataCaptureEvent}) from WAL segments.
+ * User should responsible {@link ChangeDataCaptureConsumer} implementation 
with custom consumption logic.
+ *
+ * Ignite node should be explicitly configured for using {@link IgniteCDC}.
+ * <ol>
+ *     <li>Set {@link DataStorageConfiguration#setCdcEnabled(boolean)} to 
true.</li>
+ *     <li>Optional: Set {@link DataStorageConfiguration#setCdcPath(String)} 
to path to the directory to store
+ *     WAL segments for CDC.</li>
+ *     <li>Optional: Set {@link 
DataStorageConfiguration#setWalForceArchiveTimeout(long)} to configure timeout 
for
+ *     force WAL rollover, so new events will be available for consumptions 
with the predicted time.</li>
+ * </ol>
+ *
+ * When {@link DataStorageConfiguration#getCdcPath()} is true then Ignite node 
on each WAL segment rollover creates
+ * hard link to archive WAL segment in {@link 
DataStorageConfiguration#getCdcPath()} directory.
+ * {@link IgniteCDC} application takes segment file and consumes events from 
it.
+ * After successful consumption (see {@link 
ChangeDataCaptureConsumer#onChange(Iterator)})
+ * WAL segment will be deleted from directory.
+ *
+ * Several Ignite nodes can be started on the same host.
+ * If your deployment done with custom consistent id then you should specify 
it via
+ * {@link IgniteConfiguration#setConsistentId(Serializable)} in provided 
{@link IgniteConfiguration}.
+ *
+ * Application works as follows:
+ * <ol>
+ *     <li>Search node work directory based on provided {@link 
IgniteConfiguration}.</li>
+ *     <li>Await for creation of CDC directory if it not exists.</li>
+ *     <li>Acquire file lock to ensure exclusive consumption.</li>
+ *     <li>Loads state of consumption if it exists.</li>
+ *     <li>Infinetely wait for new available segment and process it.</li>
+ * </ol>
+ *
+ * @see DataStorageConfiguration#setCdcEnabled(boolean)
+ * @see DataStorageConfiguration#setCdcPath(String)
+ * @see DataStorageConfiguration#setWalForceArchiveTimeout(long)
+ * @see CDCCommandLineStartup
+ * @see ChangeDataCaptureConsumer
+ * @see DataStorageConfiguration#DFLT_CDC_PATH
+ */
+public class IgniteCDC implements Runnable {
+    /** State dir. */
+    public static final String STATE_DIR = "state";
+
+    /** Wal segments filter. */
+    private static final Predicate<Path> WAL_SEGMENTS_FILTER =
+        p -> WAL_NAME_PATTERN.matcher(p.getFileName().toString()).matches();
+
+    /** Ignite configuration. */
+    private final IgniteConfiguration cfg;
+
+    /** CDC configuration. */
+    private final ChangeDataCaptureConfiguration cdcCfg;
+
+    /** WAL iterator factory. */
+    private final IgniteWalIteratorFactory factory;
+
+    /** Events consumer. */
+    private final WALRecordsConsumer<?, ?> consumer;
+
+    /** Logger. */
+    private final IgniteLogger log;
+
+    /** CDC directory. */
+    private Path cdcDir;
+
+    /** Binary meta directory. */
+    private File binaryMeta;
+
+    /** Marshaller directory. */
+    private File marshaller;
+
+    /** CDC state. */
+    private CDCConsumerState state;
+
+    /** Save state to start from. */
+    private WALPointer initState;
+
+    /** Stoped flag. */
+    private volatile boolean stoped;

Review comment:
       stopped.




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