Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.ozone.OzoneConsts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Create and extract archives. */
public final class Archiver {

static final int MIN_BUFFER_SIZE = 8 * (int) OzoneConsts.KB; // same as IOUtils.DEFAULT_BUFFER_SIZE
static final int MAX_BUFFER_SIZE = (int) OzoneConsts.MB;
private static final Logger LOG = LoggerFactory.getLogger(Archiver.class);

private Archiver() {
// no instances (for now)
Expand Down Expand Up @@ -111,6 +114,34 @@ public static long includeFile(File file, String entryName,
return bytes;
}

/**
* Creates a hardlink for the given file in a temporary directory, adds it
* as an entry in the archive, and includes its contents in the archive output.
* The temporary hardlink is deleted after processing.
*/
Comment thread
sadanand48 marked this conversation as resolved.
public static long linkAndIncludeFile(File file, String entryName,
ArchiveOutputStream<TarArchiveEntry> archiveOutput, Path tmpDir) throws IOException {
File link = tmpDir.resolve(entryName).toFile();
long bytes = 0;
try {
Files.createLink(link.toPath(), file.toPath());
TarArchiveEntry entry = archiveOutput.createArchiveEntry(link, entryName);
archiveOutput.putArchiveEntry(entry);
try (InputStream input = Files.newInputStream(link.toPath())) {
bytes = IOUtils.copyLarge(input, archiveOutput);
}
archiveOutput.closeArchiveEntry();
} catch (IOException ioe) {
Comment thread
sadanand48 marked this conversation as resolved.
LOG.error("Couldn't create hardlink for file {} while including it in tarball.",
Comment thread
sadanand48 marked this conversation as resolved.
file.getAbsolutePath(), ioe);
} finally {
if (link != null) {
Comment thread
sadanand48 marked this conversation as resolved.
Outdated
Files.deleteIfExists(link.toPath());
Comment thread
sadanand48 marked this conversation as resolved.
Outdated
}
}
return bytes;
}

public static void extractEntry(ArchiveEntry entry, InputStream input, long size,
Path ancestor, Path path) throws IOException {
HddsUtils.validatePath(path, ancestor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public void initialize(DBStore store, DBCheckpointMetrics metrics,
}
}

public File getBootstrapTempData() {
return bootstrapTempData;
}

private boolean hasPermission(UserGroupInformation user) {
// Check ACL for dbCheckpoint only when global Ozone ACL and SPNEGO is
// enabled
Expand All @@ -132,7 +136,7 @@ private boolean hasPermission(UserGroupInformation user) {
}
}

private static void logSstFileList(Collection<String> sstList, String msg, int sampleSize) {
protected static void logSstFileList(Collection<String> sstList, String msg, int sampleSize) {
Comment thread
sadanand48 marked this conversation as resolved.
int count = sstList.size();
if (LOG.isDebugEnabled()) {
LOG.debug(msg, count, "", sstList);
Expand Down Expand Up @@ -199,7 +203,7 @@ private void generateSnapshotCheckpoint(HttpServletRequest request,
processMetadataSnapshotRequest(request, response, isFormData, flush);
}

private void processMetadataSnapshotRequest(HttpServletRequest request, HttpServletResponse response,
protected void processMetadataSnapshotRequest(HttpServletRequest request, HttpServletResponse response,
boolean isFormData, boolean flush) {
List<String> excludedSstList = new ArrayList<>();
String[] sstParam = isFormData ?
Expand Down Expand Up @@ -292,7 +296,7 @@ public DBCheckpoint getCheckpoint(Path ignoredTmpdir, boolean flush)
* @param request the HTTP servlet request
* @return array of parsed sst form data parameters for exclusion
*/
private static String[] parseFormDataParameters(HttpServletRequest request) {
protected static String[] parseFormDataParameters(HttpServletRequest request) {
ServletFileUpload upload = new ServletFileUpload();
List<String> sstParam = new ArrayList<>();

Expand Down
Loading
Loading