ChenSammi commented on code in PR #3648:
URL: https://github.com/apache/ozone/pull/3648#discussion_r1045968115
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java:
##########
@@ -69,48 +71,27 @@
*/
@Override
public byte[] unpackContainerData(Container<KeyValueContainerData> container,
- InputStream input)
+ InputStream input, Path tmpDir, Path destContainerDir)
throws IOException {
- byte[] descriptorFileContent = null;
KeyValueContainerData containerData = container.getContainerData();
- Path dbRoot = getDbPath(containerData);
- Path chunksRoot = Paths.get(containerData.getChunksPath());
+ long containerId = containerData.getContainerID();
- try (InputStream decompressed = decompress(input);
- ArchiveInputStream archiveInput = untar(decompressed)) {
+ Path containerUntarDir = tmpDir.resolve(String.valueOf(containerId));
+ if (containerUntarDir.toFile().exists()) {
+ Files.delete(containerUntarDir);
+ }
- ArchiveEntry entry = archiveInput.getNextEntry();
- while (entry != null) {
- String name = entry.getName();
- long size = entry.getSize();
- if (name.startsWith(DB_DIR_NAME + "/")) {
- Path destinationPath = dbRoot
- .resolve(name.substring(DB_DIR_NAME.length() + 1));
- extractEntry(entry, archiveInput, size, dbRoot,
- destinationPath);
- } else if (name.startsWith(CHUNKS_DIR_NAME + "/")) {
- Path destinationPath = chunksRoot
- .resolve(name.substring(CHUNKS_DIR_NAME.length() + 1));
- extractEntry(entry, archiveInput, size, chunksRoot,
- destinationPath);
- } else if (CONTAINER_FILE_NAME.equals(name)) {
- //Don't do anything. Container file should be unpacked in a
- //separated step by unpackContainerDescriptor call.
- descriptorFileContent = readEntry(archiveInput, size);
- } else {
- throw new IllegalArgumentException(
- "Unknown entry in the tar file: " + "" + name);
- }
- entry = archiveInput.getNextEntry();
- }
- return descriptorFileContent;
+ Path dbRoot = getDbPath(containerUntarDir, containerData);
+ Path chunksRoot = getChunkPath(containerUntarDir, containerData);
+ byte[] descriptorFileContent = innerUnpack(input, dbRoot, chunksRoot);
- } catch (CompressorException e) {
- throw new IOException(
- "Can't uncompress the given container: " + container
- .getContainerData().getContainerID(),
- e);
+ if (!Files.exists(destContainerDir)) {
+ Files.createDirectories(destContainerDir);
}
+ Files.move(containerUntarDir, destContainerDir,
Review Comment:
We should not use REPLACE_EXISTING here. If destContainerDir already exists,
should throw out exception, just like the current behavior.
--
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]