AlexYinHan commented on code in PR #25924: URL: https://github.com/apache/flink/pull/25924#discussion_r1917715662
########## flink-state-backends/flink-statebackend-forst/src/main/java/org/apache/flink/state/forst/datatransfer/DataTransferStrategyBuilder.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.forst.datatransfer; + +import org.apache.flink.core.execution.RecoveryClaimMode; +import org.apache.flink.core.fs.FileSystem; +import org.apache.flink.core.fs.Path; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Builder for {@link DataTransferStrategy}. */ +public class DataTransferStrategyBuilder { + private static final Logger LOG = LoggerFactory.getLogger(DataTransferStrategyBuilder.class); + + private Path dbRemotePath; + + private FileSystem dbDelegateFileSystem; + + private boolean isDbPathUnderCheckpointPath; + + private RecoveryClaimMode claimMode; + + public void withoutDbRemotePath() { + this.dbRemotePath = null; + this.dbDelegateFileSystem = null; + this.claimMode = RecoveryClaimMode.DEFAULT; + } + + public void withDbRemotePath(FileSystem dbDelegateFileSystem, Path dbRemotePath) { + this.dbRemotePath = dbRemotePath; + this.dbDelegateFileSystem = dbDelegateFileSystem; + } + + public void withIsDbPathUnderCheckpointPath(Boolean isDbPathUnderCheckpointPath) { + this.isDbPathUnderCheckpointPath = isDbPathUnderCheckpointPath; + } + + public void withClaimMode(RecoveryClaimMode claimMode) { + this.claimMode = claimMode; + } + + public DataTransferStrategyBuilder() { + this.dbRemotePath = null; + this.dbDelegateFileSystem = null; + this.isDbPathUnderCheckpointPath = false; + } + + public DataTransferStrategy build() { + DataTransferStrategy strategy; + if (dbDelegateFileSystem == null) { + strategy = new LocalFsDataTransferStrategy(claimMode); + LOG.info("Build DataTransferStrategy: {}", strategy); + return strategy; + } + + RemoteFsDataTransferStrategy.FileTransferStyle snapshotStyle; + RemoteFsDataTransferStrategy.FileTransferStyle restoreStyle; + if (isDbPathUnderCheckpointPath) { + snapshotStyle = RemoteFsDataTransferStrategy.FileTransferStyle.REUSE; + restoreStyle = + claimMode == RecoveryClaimMode.CLAIM + ? RemoteFsDataTransferStrategy.FileTransferStyle.REUSE + : RemoteFsDataTransferStrategy.FileTransferStyle.COPY; + } else { + snapshotStyle = RemoteFsDataTransferStrategy.FileTransferStyle.COPY; + restoreStyle = RemoteFsDataTransferStrategy.FileTransferStyle.COPY; + } + + strategy = + new RemoteFsDataTransferStrategy( + snapshotStyle, + restoreStyle, + claimMode, + dbDelegateFileSystem, + isDbPathUnderCheckpointPath); + LOG.info("Build DataTransferStrategy: {}", strategy); + return strategy; Review Comment: Local/Remote is not straightforward enough. I've modified them to ```CopyDataTransferStrategy``` and ```ReusableDataTransferStrategy``` , with the latter extending the former. -- 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]
