-
Notifications
You must be signed in to change notification settings - Fork 615
HDDS-6235. Empty KeyValueContainers are replicated without chunks directory. #3052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
3f27e27
a37536c
62a4e18
2381174
44cc975
bc9827a
4bfec10
34203e6
e8e2cc9
d28f10c
e332cce
42c85bc
0193016
cd963fa
5ccd826
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,11 +84,13 @@ public byte[] unpackContainerData(Container<KeyValueContainerData> container, | |
| if (name.startsWith(DB_DIR_NAME + "/")) { | ||
| Path destinationPath = dbRoot | ||
| .resolve(name.substring(DB_DIR_NAME.length() + 1)); | ||
| extractEntry(archiveInput, size, dbRoot, destinationPath); | ||
| 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(archiveInput, size, chunksRoot, destinationPath); | ||
| 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. | ||
|
|
@@ -109,27 +111,31 @@ public byte[] unpackContainerData(Container<KeyValueContainerData> container, | |
| } | ||
| } | ||
|
|
||
| private void extractEntry(InputStream input, long size, | ||
| Path ancestor, Path path) throws IOException { | ||
| private void extractEntry(ArchiveEntry entry, InputStream input, long size, | ||
| Path ancestor, Path path) throws IOException { | ||
| HddsUtils.validatePath(path, ancestor); | ||
| Path parent = path.getParent(); | ||
| if (parent != null) { | ||
| Files.createDirectories(parent); | ||
| } | ||
|
|
||
| try (OutputStream fileOutput = new FileOutputStream(path.toFile()); | ||
| OutputStream output = new BufferedOutputStream(fileOutput)) { | ||
| int bufferSize = 1024; | ||
| byte[] buffer = new byte[bufferSize + 1]; | ||
| long remaining = size; | ||
| while (remaining > 0) { | ||
| int len = (int) Math.min(remaining, bufferSize); | ||
| int read = input.read(buffer, 0, len); | ||
| if (read >= 0) { | ||
| remaining -= read; | ||
| output.write(buffer, 0, read); | ||
| } else { | ||
| remaining = 0; | ||
| if (entry.isDirectory()) { | ||
| Files.createDirectories(path); | ||
| } else { | ||
| try (OutputStream fileOutput = new FileOutputStream(path.toFile()); | ||
| OutputStream output = new BufferedOutputStream(fileOutput)) { | ||
| int bufferSize = 1024; | ||
| byte[] buffer = new byte[bufferSize + 1]; | ||
| long remaining = size; | ||
| while (remaining > 0) { | ||
| int len = (int) Math.min(remaining, bufferSize); | ||
| int read = input.read(buffer, 0, len); | ||
| if (read >= 0) { | ||
| remaining -= read; | ||
| output.write(buffer, 0, read); | ||
| } else { | ||
| remaining = 0; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -209,6 +215,12 @@ private byte[] readEntry(InputStream input, final long size) | |
| private void includePath(Path dir, String subdir, | ||
| ArchiveOutputStream archiveOutput) throws IOException { | ||
|
|
||
| // Add a directory entry before adding files, in case the directory is | ||
| // empty. | ||
| ArchiveEntry entry = archiveOutput.createArchiveEntry(dir.toFile(), subdir); | ||
| archiveOutput.putArchiveEntry(entry); | ||
|
|
||
| // Add files in the directory. | ||
| try (Stream<Path> dirEntries = Files.list(dir)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the error is thrown here, so it still needs the CHUNK file to exist? Reproduced by adding
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @symious the error is thrown because the chunk directory does not exist. Not having chunk files in the directory should not be a problem here. |
||
| for (Path path : dirEntries.collect(toList())) { | ||
| String entryName = subdir + "/" + path.getFileName(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.