rkhachatryan commented on a change in pull request #16606:
URL: https://github.com/apache/flink/pull/16606#discussion_r716642699



##########
File path: 
flink-state-backends/flink-statebackend-changelog/src/main/java/org/apache/flink/state/changelog/PeriodicMaterializationManager.java
##########
@@ -0,0 +1,252 @@
+/*
+ * 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.flink.state.changelog;
+
+import org.apache.flink.api.common.operators.MailboxExecutor;
+import org.apache.flink.core.fs.FileSystemSafetyNet;
+import org.apache.flink.runtime.state.KeyedStateHandle;
+import org.apache.flink.runtime.state.SnapshotResult;
+import org.apache.flink.runtime.state.StateObject;
+import org.apache.flink.runtime.state.changelog.SequenceNumber;
+import org.apache.flink.runtime.taskmanager.AsyncExceptionHandler;
+import org.apache.flink.util.concurrent.ExecutorThreadFactory;
+import org.apache.flink.util.concurrent.FutureUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.RunnableFuture;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/** Stateless Materialization Manager. */
+public class PeriodicMaterializationManager implements Closeable {
+    private static final Logger LOG = 
LoggerFactory.getLogger(PeriodicMaterializationManager.class);
+
+    /** task mailbox executor, execute from Task Thread. */
+    private final MailboxExecutor mailboxExecutor;
+
+    /** Async thread pool, to complete async phase of materialization. */
+    private final ExecutorService asyncOperationsThreadPool;
+
+    /** scheduled executor, periodically trigger materialization. */
+    private final ScheduledExecutorService periodicExecutor;
+
+    private final AsyncExceptionHandler asyncExceptionHandler;
+
+    private final String subtaskName;
+
+    private final long periodicMaterializeDelay;
+
+    /** Allowed number of consecutive materialization failures. */
+    private final int allowedNumberOfFailures;
+
+    /** Number of consecutive materialization failures. */
+    private final AtomicInteger numberOfConsecutiveFailures;
+
+    private final ChangelogKeyedStateBackend<?> keyedStateBackend;
+
+    PeriodicMaterializationManager(
+            MailboxExecutor mailboxExecutor,
+            ExecutorService asyncOperationsThreadPool,
+            String subtaskName,
+            AsyncExceptionHandler asyncExceptionHandler,
+            long periodicMaterializeDelay,
+            int allowedNumberOfFailures,
+            ChangelogKeyedStateBackend<?> keyedStateBackend) {
+        this.mailboxExecutor = mailboxExecutor;
+        this.asyncOperationsThreadPool = asyncOperationsThreadPool;
+
+        this.subtaskName = subtaskName;
+        this.periodicMaterializeDelay = periodicMaterializeDelay;
+        this.asyncExceptionHandler = asyncExceptionHandler;
+        this.allowedNumberOfFailures = allowedNumberOfFailures;
+        this.numberOfConsecutiveFailures = new AtomicInteger(0);
+        this.keyedStateBackend = keyedStateBackend;
+
+        this.periodicExecutor =
+                Executors.newSingleThreadScheduledExecutor(
+                        new ExecutorThreadFactory(
+                                "periodic-materialization-scheduler-" + 
subtaskName));
+    }
+
+    public void start() {

Review comment:
       It's not called twice currently - and I'm proposing to enforce this; so 
that it's not re-used for example.
   WDYT?




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to