sadanand48 commented on code in PR #8477: URL: https://github.com/apache/ozone/pull/8477#discussion_r2101110847
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckPointServletInodeBasedXfer.java: ########## @@ -0,0 +1,272 @@ +/* + * 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; + +import org.apache.commons.compress.archivers.ArchiveOutputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.hadoop.hdds.utils.db.DBCheckpoint; +import org.apache.hadoop.ozone.om.snapshot.OmSnapshotUtils; +import org.apache.hadoop.util.Time; +import org.apache.ozone.rocksdiff.RocksDBCheckpointDiffer; +import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.apache.hadoop.hdds.utils.Archiver.includeFile; +import static org.apache.hadoop.hdds.utils.Archiver.tar; +import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_CHECKPOINT_DIR; +import static org.apache.hadoop.ozone.OzoneConsts.ROCKSDB_SST_SUFFIX; +import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_RATIS_SNAPSHOT_MAX_TOTAL_SST_SIZE_DEFAULT; +import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_RATIS_SNAPSHOT_MAX_TOTAL_SST_SIZE_KEY; + +public class OMDBCheckPointServletInodeBasedXfer extends OMDBCheckpointServlet { + + @Override + public void writeDbDataToStream(DBCheckpoint checkpoint, HttpServletRequest request, OutputStream destination, + List<String> toExcludeList, List<String> excludedList, Path tmpdir) throws IOException, InterruptedException { + + // Key is the InodeID and path is the first encountered file path with this inodeID + // This will be later used to while writing to the tar. + Map<String, Path> copyFiles = new HashMap<>(); + + try (ArchiveOutputStream<TarArchiveEntry> archiveOutputStream = tar(destination)) { + RocksDBCheckpointDiffer differ = + getDbStore().getRocksDBCheckpointDiffer(); + DirectoryData sstBackupDir = new DirectoryData(tmpdir, + differ.getSSTBackupDir()); + DirectoryData compactionLogDir = new DirectoryData(tmpdir, + differ.getCompactionLogDir()); + + Set<String> sstFilesToExclude = new HashSet<>(toExcludeList); + + Map<Object, Set<Path>> hardlinkFiles = new HashMap<>(); + + boolean completed = getFilesForArchive(checkpoint, copyFiles, hardlinkFiles, + sstFilesToExclude, + includeSnapshotData(request), excludedList, + sstBackupDir, compactionLogDir); + writeFilesToArchive(copyFiles, hardlinkFiles, archiveOutputStream, + completed, checkpoint.getCheckpointLocation()); + + } catch (Exception e) { + LOG.error("got exception writing to archive " + e); + throw e; + } + } + + private void writeFilesToArchive(Map<String, Path> copyFiles, Map<Object, Set<Path>> hardlinkFiles, + ArchiveOutputStream<TarArchiveEntry> archiveOutputStream, boolean completed, Path checkpointLocation) + throws IOException { + Map<String, Path> filteredCopyFiles = completed ? copyFiles : + copyFiles.entrySet().stream().filter(e -> e.getValue().getFileName().toString().toLowerCase().endsWith(".sst")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Path metaDirPath = getMetaDirPath(checkpointLocation); + long bytesWritten = 0L; + int filesWritten = 0; + long lastLoggedTime = Time.monotonicNow(); + + // Go through each of the files to be copied and add to archive. + for (Map.Entry<String, Path> entry : filteredCopyFiles.entrySet()) { + Path path = entry.getValue(); + // Confirm the data is in the right place. + if (!path.toString().startsWith(metaDirPath.toString())) { + throw new IOException("tarball file not in metadata dir: " + + path + ": " + metaDirPath); + } + + File file = path.toFile(); + if (!file.isDirectory()) { + filesWritten++; + } + bytesWritten += includeFile(file, entry.getKey(), archiveOutputStream); + // Log progress every 30 seconds + if (Time.monotonicNow() - lastLoggedTime >= 30000) { + LOG.info("Transferred {} KB, #files {} to checkpoint tarball stream...", + bytesWritten / (1024), filesWritten); + lastLoggedTime = Time.monotonicNow(); + } + } + + if (completed) { + // TODO: + // 1. take an OM db checkpoint , + // 2. hold a snapshotCache lock, + // 3. copy remaining files + // 4. create hardlink file + } + + } + + boolean getFilesForArchive(DBCheckpoint checkpoint, Map<String,Path> copyFiles, + Map<Object, Set<Path>> hardlinkFiles, + Set<String> sstFilesToExclude, boolean includeSnapshotData, + List<String> excluded, + DirectoryData sstBackupDir, + DirectoryData compactionLogDir) throws IOException { + maxTotalSstSize = + OZONE_OM_RATIS_SNAPSHOT_MAX_TOTAL_SST_SIZE_DEFAULT; + + // Tarball limits are not implemented for processes that don't + // include snapshots. Currently, this is just for recon. + if (!includeSnapshotData) { + maxTotalSstSize = Long.MAX_VALUE; + } + + AtomicLong copySize = new AtomicLong(0L); + + // Log estimated total data transferred on first request. + if (sstFilesToExclude.isEmpty()) { + logEstimatedTarballSize(checkpoint, includeSnapshotData); + } + + if (includeSnapshotData) { + Set<Path> snapshotPaths = getSnapshotDirs(checkpoint, true); Review Comment: done. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBCheckpointServlet.java: ########## @@ -96,11 +96,11 @@ */ public class OMDBCheckpointServlet extends DBCheckpointServlet { - private static final Logger LOG = + protected static final Logger LOG = LoggerFactory.getLogger(OMDBCheckpointServlet.class); private static final long serialVersionUID = 1L; private transient BootstrapStateHandler.Lock lock; - private long maxTotalSstSize = 0; + protected long maxTotalSstSize = 0; Review Comment: done. -- 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...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org