jojochuang commented on code in PR #9312: URL: https://github.com/apache/ozone/pull/9312#discussion_r2539794174
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/diff/delta/CompositeDeltaDiffComputer.java: ########## @@ -0,0 +1,130 @@ +/* + * 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.hadoop.ozone.om.snapshot.diff.delta; + +import static org.apache.hadoop.ozone.om.snapshot.diff.delta.FullDiffComputer.getSSTFileSetForSnapshot; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.hadoop.hdds.utils.db.TablePrefixInfo; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OmSnapshot; +import org.apache.hadoop.ozone.om.OmSnapshotManager; +import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; +import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse; +import org.apache.ozone.rocksdb.util.SstFileInfo; +import org.apache.ratis.util.function.UncheckedAutoCloseableSupplier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CompositeDeltaDiffComputer is responsible for computing the delta file + * differences between two snapshots, utilizing different strategies such + * as partial differ computation and full differ computation. + * + * It serves as an orchestrator to decide whether to perform a full diff + * or a more efficient partial diff, and handles fallback mechanisms if + * the chosen method fails. + * + * The class leverages two main difference computation strategies: + * - {@code RDBDifferComputer} for partial diff computation + * - {@code FullDiffComputer} for exhaustive diff + * + * This class also includes support for handling non-native diff scenarios + * through additional processing of input files from the "from" snapshot + * when native RocksDB tools are not used. + * + * Inherits from {@code FileLinkDeltaFileComputer} and implements the + * functionality for computing delta files and resource management. + */ +public class CompositeDeltaDiffComputer extends FileLinkDeltaFileComputer { + + private static final Logger LOG = LoggerFactory.getLogger(CompositeDeltaDiffComputer.class); + + private final RDBDifferComputer differComputer; + private final FullDiffComputer fullDiffComputer; + private final boolean nonNativeDiff; + + public CompositeDeltaDiffComputer(OmSnapshotManager snapshotManager, + OMMetadataManager activeMetadataManager, Path deltaDirPath, + Consumer<SnapshotDiffResponse.SubStatus> activityReporter, boolean fullDiff, + boolean nonNativeDiff) throws IOException { + super(snapshotManager, activeMetadataManager, deltaDirPath, activityReporter); + differComputer = fullDiff ? null : new RDBDifferComputer(snapshotManager, activeMetadataManager, + deltaDirPath.resolve("rdbDiffer"), activityReporter); + fullDiffComputer = new FullDiffComputer(snapshotManager, activeMetadataManager, + deltaDirPath.resolve("fullDiff"), activityReporter); + this.nonNativeDiff = nonNativeDiff; + } + + @Override + Optional<Map<Path, Pair<Path, SstFileInfo>>> computeDeltaFiles(SnapshotInfo fromSnapshotInfo, + SnapshotInfo toSnapshotInfo, Set<String> tablesToLookup, TablePrefixInfo tablePrefixInfo) throws IOException { + Map<Path, Pair<Path, SstFileInfo>> deltaFiles = null; + try { + if (differComputer != null) { + updateActivity(SnapshotDiffResponse.SubStatus.SST_FILE_DELTA_DAG_WALK); + deltaFiles = differComputer.computeDeltaFiles(fromSnapshotInfo, toSnapshotInfo, tablesToLookup, + tablePrefixInfo).orElse(null); + } + } catch (Exception e) { + LOG.error("Falling back to full diff.", e); Review Comment: it should be a WARN if this operation can continue with the fallback approach. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/diff/delta/RDBDifferComputer.java: ########## @@ -0,0 +1,117 @@ +/* + * 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.hadoop.ozone.om.snapshot.diff.delta; + +import static java.util.stream.Collectors.toMap; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; +import java.util.Optional; +import java.util.Set; +import java.util.TreeMap; +import java.util.UUID; +import java.util.function.Consumer; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.hadoop.hdds.utils.db.TablePrefixInfo; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.OmSnapshotLocalData; +import org.apache.hadoop.ozone.om.OmSnapshotManager; +import org.apache.hadoop.ozone.om.helpers.SnapshotInfo; +import org.apache.hadoop.ozone.om.snapshot.OmSnapshotLocalDataManager; +import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.SubStatus; +import org.apache.ozone.rocksdb.util.SstFileInfo; +import org.apache.ozone.rocksdiff.DifferSnapshotInfo; +import org.apache.ozone.rocksdiff.RocksDBCheckpointDiffer; + +/** + * Computes RocksDB SST file differences between two snapshots and materializes + * differing SST files as hard links in the configured delta directory. + * + * <p>This class uses {@link RocksDBCheckpointDiffer} to obtain the list of SST + * files that differ between a \"from\" and a \"to\" snapshot. It opens local + * snapshot metadata via {@link #getLocalDataProvider}, and delegates the + * comparison to the differ to compute the delta files.</p> + * + * <p>Each source SST file returned by the differ is linked into the delta + * directory using {@link FileLinkDeltaFileComputer#createLink(Path)}, and the + * returned value from {@link #computeDeltaFiles} is a list of those link + * paths. The implementation synchronizes on the internal {@code differ} + * instance because the differ is not assumed to be thread-safe.</p> + */ +class RDBDifferComputer extends FileLinkDeltaFileComputer { + + private final RocksDBCheckpointDiffer differ; + + RDBDifferComputer(OmSnapshotManager omSnapshotManager, OMMetadataManager activeMetadataManager, + Path deltaDirPath, Consumer<SubStatus> activityReporter) throws IOException { + super(omSnapshotManager, activeMetadataManager, deltaDirPath, activityReporter); + this.differ = activeMetadataManager.getStore().getRocksDBCheckpointDiffer(); + } + + @Override + public Optional<Map<Path, Pair<Path, SstFileInfo>>> computeDeltaFiles(SnapshotInfo fromSnapshot, + SnapshotInfo toSnapshot, Set<String> tablesToLookup, TablePrefixInfo tablePrefixInfo) throws IOException { + if (differ != null) { + try (OmSnapshotLocalDataManager.ReadableOmSnapshotLocalDataProvider snapProvider = + getLocalDataProvider(toSnapshot.getSnapshotId(), fromSnapshot.getSnapshotId())) { + final DifferSnapshotInfo fromDSI = getDSIFromSI(getActiveMetadataManager(), fromSnapshot, + snapProvider.getPreviousSnapshotLocalData()); + final DifferSnapshotInfo toDSI = getDSIFromSI(getActiveMetadataManager(), toSnapshot, + snapProvider.getSnapshotLocalData()); + final Map<Integer, Integer> versionMap = snapProvider.getSnapshotLocalData().getVersionSstFileInfos().entrySet() + .stream().collect(toMap(Map.Entry::getKey, entry -> entry.getValue().getPreviousSnapshotVersion())); + synchronized (differ) { Review Comment: is this necessary? getSSTDiffListWithFullPath() is a synchronized method. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
