|
@@ -18,14 +18,13 @@
|
|
package org.apache.hadoop.ozone;
|
|
package org.apache.hadoop.ozone;
|
|
|
|
|
|
import com.google.common.base.Joiner;
|
|
import com.google.common.base.Joiner;
|
|
-import java.io.BufferedInputStream;
|
|
|
|
-import java.io.BufferedOutputStream;
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
-import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.OutputStream;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
@@ -34,16 +33,22 @@ import java.security.SecureRandom;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
-import java.util.zip.GZIPOutputStream;
|
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import com.google.common.base.Strings;
|
|
import com.google.common.base.Strings;
|
|
-import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
|
|
|
|
|
+
|
|
|
|
+import org.apache.commons.compress.archivers.ArchiveEntry;
|
|
|
|
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
|
|
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
|
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
|
|
|
+import org.apache.commons.compress.compressors.CompressorException;
|
|
|
|
+import org.apache.commons.compress.compressors.CompressorOutputStream;
|
|
|
|
+import org.apache.commons.compress.compressors.CompressorStreamFactory;
|
|
import org.apache.commons.compress.utils.IOUtils;
|
|
import org.apache.commons.compress.utils.IOUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.hdds.scm.HddsServerUtil;
|
|
import org.apache.hadoop.hdds.scm.HddsServerUtil;
|
|
import org.apache.hadoop.hdds.server.ServerUtils;
|
|
import org.apache.hadoop.hdds.server.ServerUtils;
|
|
|
|
+import org.apache.hadoop.hdds.utils.db.DBCheckpoint;
|
|
import org.apache.hadoop.net.NetUtils;
|
|
import org.apache.hadoop.net.NetUtils;
|
|
import org.apache.hadoop.ozone.om.OMConfigKeys;
|
|
import org.apache.hadoop.ozone.om.OMConfigKeys;
|
|
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
|
|
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
|
|
@@ -346,61 +351,51 @@ public final class OmUtils {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Given a source directory, create a tar.gz file from it.
|
|
|
|
- *
|
|
|
|
- * @param sourcePath the path to the directory to be archived.
|
|
|
|
- * @return tar.gz file
|
|
|
|
|
|
+ * Write OM DB Checkpoint to an output stream as a compressed file (tgz).
|
|
|
|
+ * @param checkpoint checkpoint file
|
|
|
|
+ * @param destination desination output stream.
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public static File createTarFile(Path sourcePath) throws IOException {
|
|
|
|
- TarArchiveOutputStream tarOs = null;
|
|
|
|
- try {
|
|
|
|
- String sourceDir = sourcePath.toString();
|
|
|
|
- String fileName = sourceDir.concat(".tar.gz");
|
|
|
|
- FileOutputStream fileOutputStream = new FileOutputStream(fileName);
|
|
|
|
- GZIPOutputStream gzipOutputStream =
|
|
|
|
- new GZIPOutputStream(new BufferedOutputStream(fileOutputStream));
|
|
|
|
- tarOs = new TarArchiveOutputStream(gzipOutputStream);
|
|
|
|
- File folder = new File(sourceDir);
|
|
|
|
- File[] filesInDir = folder.listFiles();
|
|
|
|
- if (filesInDir != null) {
|
|
|
|
- for (File file : filesInDir) {
|
|
|
|
- addFilesToArchive(file.getName(), file, tarOs);
|
|
|
|
|
|
+ public static void writeOmDBCheckpointToStream(DBCheckpoint checkpoint,
|
|
|
|
+ OutputStream destination)
|
|
|
|
+ throws IOException {
|
|
|
|
+
|
|
|
|
+ try (CompressorOutputStream gzippedOut = new CompressorStreamFactory()
|
|
|
|
+ .createCompressorOutputStream(CompressorStreamFactory.GZIP,
|
|
|
|
+ destination)) {
|
|
|
|
+
|
|
|
|
+ try (ArchiveOutputStream archiveOutputStream =
|
|
|
|
+ new TarArchiveOutputStream(gzippedOut)) {
|
|
|
|
+
|
|
|
|
+ Path checkpointPath = checkpoint.getCheckpointLocation();
|
|
|
|
+ for (Path path : Files.list(checkpointPath)
|
|
|
|
+ .collect(Collectors.toList())) {
|
|
|
|
+ if (path != null) {
|
|
|
|
+ Path fileName = path.getFileName();
|
|
|
|
+ if (fileName != null) {
|
|
|
|
+ includeFile(path.toFile(), fileName.toString(),
|
|
|
|
+ archiveOutputStream);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return new File(fileName);
|
|
|
|
- } finally {
|
|
|
|
- try {
|
|
|
|
- org.apache.hadoop.io.IOUtils.closeStream(tarOs);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- LOG.error("Exception encountered when closing " +
|
|
|
|
- "TAR file output stream: " + e);
|
|
|
|
- }
|
|
|
|
|
|
+ } catch (CompressorException e) {
|
|
|
|
+ throw new IOException(
|
|
|
|
+ "Can't compress the checkpoint: " +
|
|
|
|
+ checkpoint.getCheckpointLocation(), e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private static void addFilesToArchive(String source, File file,
|
|
|
|
- TarArchiveOutputStream
|
|
|
|
- tarFileOutputStream)
|
|
|
|
|
|
+ private static void includeFile(File file, String entryName,
|
|
|
|
+ ArchiveOutputStream archiveOutputStream)
|
|
throws IOException {
|
|
throws IOException {
|
|
- tarFileOutputStream.putArchiveEntry(new TarArchiveEntry(file, source));
|
|
|
|
- if (file.isFile()) {
|
|
|
|
- FileInputStream fileInputStream = new FileInputStream(file);
|
|
|
|
- BufferedInputStream bufferedInputStream =
|
|
|
|
- new BufferedInputStream(fileInputStream);
|
|
|
|
- IOUtils.copy(bufferedInputStream, tarFileOutputStream);
|
|
|
|
- tarFileOutputStream.closeArchiveEntry();
|
|
|
|
- fileInputStream.close();
|
|
|
|
- } else if (file.isDirectory()) {
|
|
|
|
- tarFileOutputStream.closeArchiveEntry();
|
|
|
|
- File[] filesInDir = file.listFiles();
|
|
|
|
- if (filesInDir != null) {
|
|
|
|
- for (File cFile : filesInDir) {
|
|
|
|
- addFilesToArchive(cFile.getAbsolutePath(), cFile,
|
|
|
|
- tarFileOutputStream);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ ArchiveEntry archiveEntry =
|
|
|
|
+ archiveOutputStream.createArchiveEntry(file, entryName);
|
|
|
|
+ archiveOutputStream.putArchiveEntry(archiveEntry);
|
|
|
|
+ try (FileInputStream fis = new FileInputStream(file)) {
|
|
|
|
+ IOUtils.copy(fis, archiveOutputStream);
|
|
}
|
|
}
|
|
|
|
+ archiveOutputStream.closeArchiveEntry();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|