rkhachatryan commented on a change in pull request #15322: URL: https://github.com/apache/flink/pull/15322#discussion_r669024193
########## File path: flink-dstl/flink-dstl-dfs/src/main/java/org/apache/flink/changelog/fs/FsStateChangelogWriter.java ########## @@ -0,0 +1,380 @@ +/* + * 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.changelog.fs; + +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.changelog.fs.StateChangeUploader.UploadTask; +import org.apache.flink.runtime.state.KeyGroupRange; +import org.apache.flink.runtime.state.StreamStateHandle; +import org.apache.flink.runtime.state.changelog.ChangelogStateHandleStreamImpl; +import org.apache.flink.runtime.state.changelog.SequenceNumber; +import org.apache.flink.runtime.state.changelog.SequenceNumberRange; +import org.apache.flink.runtime.state.changelog.StateChange; +import org.apache.flink.runtime.state.changelog.StateChangelogWriter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; +import javax.annotation.concurrent.GuardedBy; +import javax.annotation.concurrent.NotThreadSafe; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; +import java.util.TreeMap; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +import static java.util.concurrent.CompletableFuture.completedFuture; +import static org.apache.flink.util.Preconditions.checkArgument; +import static org.apache.flink.util.Preconditions.checkNotNull; +import static org.apache.flink.util.Preconditions.checkState; + +/** + * Filesystem-based {@link StateChangelogWriter} implementation. Assumes TM-owned state - so no + * re-uploads. + * + * <p>On {@link #append(int, byte[]) append}, it stores the changes locally in memory (without any + * thread synchronization); {@link SequenceNumber} is not changed. + * + * <p>However, if they exceed {@link #preEmptivePersistThresholdInBytes} then {@link + * #persistInternal(SequenceNumber) persist} is called. + * + * <p>On {@link #persist(SequenceNumber) persist}, accumulated changes are sent to the {@link + * StateChangeUploader} as an immutable {@link StateChangeUploader.UploadTask task}. An {@link + * FsStateChangelogWriter.UploadCompletionListener upload listener} is also registered. Upon + * notification it updates the Writer local state (for future persist calls) and completes the + * future returned to the original caller. The uploader notifies all listeners via a callback in a + * task. + * + * <p>If persist() is called for the same state change before the upload completion then the + * listener is added but not the upload task (which must already exist). + * + * <p>Invariants: + * + * <ol> + * <li>Every change has at most one associated upload (retries are performed at a lower level) + * <li>Every change is present in at most one collection: either uploaded OR notUploaded Review comment: What do you mean? Whether there are there any invariants for `activeChangeSet`? I wanted to emphasize that the change can not be present in both, as it's related to concurrency. -- 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