You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@orc.apache.org by GitBox <gi...@apache.org> on 2021/10/19 13:37:56 UTC
[GitHub] [orc] guiyanakuang opened a new pull request #941: ORC-1030: Fix some bugs that Java Tools recovery file command cannot find OrcFileMAGIC accurately
guiyanakuang opened a new pull request #941:
URL: https://github.com/apache/orc/pull/941
1. The original code was not aware of the possibility of OrcFileMAGIC being separated
2. The indexOf method does not match correctly
<!--
Thanks for sending a pull request! Here are some tips for you:
1. File a JIRA issue first and use it as a prefix of your PR title, e.g., `ORC-001: Fix ABC`.
2. Use your PR title to summarize what this PR proposes instead of describing the problem.
3. Make PR title and description complete because these will be the permanent commit log.
4. If possible, provide a concise and reproducible example to reproduce the issue for a faster review.
5. If the PR is unfinished, use GitHub PR Draft feature.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If there is a discussion in the mailing list, please add the link.
-->
This pr is aimed at fixing some bugs where the Java Tools recovery file command did not accurately find OrcFileMAGIC.
```java
while (remaining > 0) {
int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
byte[] data = new byte[toRead];
long startPos = corruptFileLen - remaining;
fdis.readFully(startPos, data, 0, toRead);
// find all MAGIC string and see if the file is readable from there
int index = 0;
long nextFooterOffset;
byte[] magicBytes = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
while (index != -1) {
index = indexOf(data, magicBytes, index + 1);
if (index != -1) {
nextFooterOffset = startPos + index + magicBytes.length + 1;
if (isReadable(corruptPath, conf, nextFooterOffset)) {
footerOffsets.add(nextFooterOffset);
}
}
}
System.err.println("Scanning for valid footers - startPos: " + startPos +
" toRead: " + toRead + " remaining: " + remaining);
remaining = remaining - toRead;
}
```
Two adjacent reads may be exactly separated by OrcFile.MAGIC, making it impossible to find the location of the recovered file. Because the current implementation only matches in a single read.
```java
private static int indexOf(final byte[] data, final byte[] pattern, final int index) {
if (data == null || data.length == 0 || pattern == null || pattern.length == 0 ||
index > data.length || index < 0) {
return -1;
}
int j = 0;
for (int i = index; i < data.length; i++) {
if (pattern[j] == data[i]) {
j++;
} else {
j = 0;
}
if (j == pattern.length) {
return i - pattern.length + 1;
}
}
return -1;
}
```
This matching algorithm is wrong when i does not backtrack after a failed match in the middle. As a simple example data = OOORC, pattern= ORC, index = 1, this algorithm will return -1.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
Fix some bugs that Java Tools recovery file command cannot find OrcFileMAGIC accurately.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
Add UT.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736186932
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +714,79 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+ byte[] bytes = new byte[1024];
+ Path corruptedFilePath = new Path("corruptedFile.orc");
+
+ try {
+ FSDataInputStream fdis = fs.open(testFilePath);
+ FileStatus fileStatus = fs.getFileStatus(testFilePath);
+ FSDataOutputStream fdos = fs.create(corruptedFilePath, true,
+ conf.getInt("io.file.buffer.size", 4096),
+ fileStatus.getReplication(),
+ fileStatus.getBlockSize());
+ long remaining = fileSize;
+
+ while (remaining > 0) {
+ int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
+ byte[] data = new byte[toRead];
+ long startPos = fileSize - remaining;
+ fdis.readFully(startPos, data, 0, toRead);
+ fdos.write(data);
+ remaining = remaining - toRead;
+ }
+ fdos.write(bytes);
+ fdos.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ fdos.write(bytes);
+ fdis.close();
+ fdos.close();
Review comment:
I guess you can copy file like the following.
```
jshell> import java.nio.file.*;
jshell> Files.copy(Paths.get("/tmp/a"), Paths.get("/tmp/b"))
```
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736804930
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +710,80 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+
+ String testFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR), testFilePath))
+ .toUri().getPath();
+
+ String copyTestFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR),
+ new Path("CopyTestFileDump.testDump.orc")))
+ .toUri().getPath();
+
+ String testCrcFilePathStr = Path.mergePaths(workDir,
+ Path.mergePaths(new Path(Path.SEPARATOR),
+ new Path(".TestFileDump.testDump.orc.crc")))
+ .toUri().getPath();
+
+ try {
+ Files.copy(Paths.get(testFilePathStr), Paths.get(copyTestFilePathStr));
+
+ // Append write data to make it a corrupt file
+ try (FileOutputStream output = new FileOutputStream(testFilePathStr, true)) {
+ output.write(new byte[1024]);
+ output.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ output.write(new byte[1024]);
+ output.flush();
+ }
+
+ // Clean up the crc file and append data to avoid checksum read exceptions
Review comment:
Oh. That makes sense. I missed that.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736414367
##########
File path: java/tools/pom.xml
##########
@@ -91,6 +91,12 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
Review comment:
Removing commons-io dependency in 9c830d8
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on pull request #941: ORC-1030: Fix some bugs that Java Tools recovery file command cannot find OrcFile.MAGIC accurately
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on pull request #941:
URL: https://github.com/apache/orc/pull/941#issuecomment-946825208
https://github.com/apache/orc/blob/bf32589444802022f530e9f26b7262feb9e2aa1f/java/tools/src/java/org/apache/orc/tools/FileDump.java#L575-L579
```java
public static final String DEFAULT_BACKUP_PATH = System.getProperty("java.io.tmpdir");
```
DEFAULT_BACKUP_PATH may not end with a Path.SEPARATOR
So the path splicing in the 576 lines of code is probably faulty.
This is also the reason for the exceptions in the Travis CI logs.
I will fix this tomorrow.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #941:
URL: https://github.com/apache/orc/pull/941#issuecomment-951587837
Sorry for being late, @guiyanakuang .
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736328092
##########
File path: java/tools/pom.xml
##########
@@ -91,6 +91,12 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
Review comment:
Sorry but this is a revert of ORC-909. Shall we avoid to use this?
This is only for `FileUtils.deleteQuietly`, right?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Fix some bugs that Java Tools recovery file command cannot find OrcFile.MAGIC accurately
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r732459561
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -703,4 +709,86 @@ public void testHasNull() throws Exception {
assumeTrue(!System.getProperty("os.name").startsWith("Windows"));
TestFileDump.checkOutput(outputFilename, workDir + File.separator + outputFilename);
}
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ conf.set(OrcConf.ENCODING_STRATEGY.getAttribute(), "COMPRESSION");
+ conf.set(OrcConf.DICTIONARY_IMPL.getAttribute(), "rbtree");
Review comment:
Thank you for adding this test coverage, @guiyanakuang .
BTW, do we need this configuration for this test coverage?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #941:
URL: https://github.com/apache/orc/pull/941#issuecomment-952747484
Merged to main/1.7.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r737236731
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -583,8 +602,10 @@ private static void recoverFile(final Path corruptPath, final FileSystem fs,
// Move side file to backup path
Path sideFilePath = OrcAcidUtils.getSideFile(corruptPath);
- Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
- moveFiles(fs, sideFilePath, backupSideFilePath);
+ if (fs.exists(sideFilePath)) {
+ Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
+ moveFiles(fs, sideFilePath, backupSideFilePath);
+ }
Review comment:
Sorry, I misunderstood the intention
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736186655
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -583,8 +602,10 @@ private static void recoverFile(final Path corruptPath, final FileSystem fs,
// Move side file to backup path
Path sideFilePath = OrcAcidUtils.getSideFile(corruptPath);
- Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
- moveFiles(fs, sideFilePath, backupSideFilePath);
+ if (fs.exists(sideFilePath)) {
Review comment:
I guess you can copy file like the following.
```
jshell> import java.nio.file.*;
jshell> Files.copy(Paths.get("/tmp/a"), Paths.get("/tmp/b"))
```
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r737234983
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -583,8 +602,10 @@ private static void recoverFile(final Path corruptPath, final FileSystem fs,
// Move side file to backup path
Path sideFilePath = OrcAcidUtils.getSideFile(corruptPath);
- Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
- moveFiles(fs, sideFilePath, backupSideFilePath);
+ if (fs.exists(sideFilePath)) {
+ Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
+ moveFiles(fs, sideFilePath, backupSideFilePath);
+ }
Review comment:
I still see this code from this PR. Did you rebase your PR correctly?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736179410
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +714,79 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+ byte[] bytes = new byte[1024];
+ Path corruptedFilePath = new Path("corruptedFile.orc");
+
+ try {
+ FSDataInputStream fdis = fs.open(testFilePath);
+ FileStatus fileStatus = fs.getFileStatus(testFilePath);
+ FSDataOutputStream fdos = fs.create(corruptedFilePath, true,
+ conf.getInt("io.file.buffer.size", 4096),
+ fileStatus.getReplication(),
+ fileStatus.getBlockSize());
+ long remaining = fileSize;
+
+ while (remaining > 0) {
+ int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
+ byte[] data = new byte[toRead];
+ long startPos = fileSize - remaining;
+ fdis.readFully(startPos, data, 0, toRead);
+ fdos.write(data);
+ remaining = remaining - toRead;
+ }
+ fdos.write(bytes);
+ fdos.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ fdos.write(bytes);
+ fdis.close();
+ fdos.close();
Review comment:
Line 774 ~ 776 added redundant writes to turn this file into a corrupt file
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang edited a comment on pull request #941: ORC-1030: Fix some bugs that Java Tools recovery file command cannot find OrcFile.MAGIC accurately
Posted by GitBox <gi...@apache.org>.
guiyanakuang edited a comment on pull request #941:
URL: https://github.com/apache/orc/pull/941#issuecomment-946774472
Travis CI caught a very rare exception, which I logged here first
```
java.time.format.DateTimeParseException: Text '2021-10-19T0700:01.683210-0700' could not be parsed at index 13
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2046)
at java.base/java.time.format.DateTimeFormatter.parseBest(DateTimeFormatter.java:1994)
at org.apache.orc.tools.convert.JsonReader$TimestampColumnConverter.convert(JsonReader.java:169)
at org.apache.orc.tools.convert.JsonReader.nextBatch(JsonReader.java:375)
at org.apache.orc.tools.convert.TestJsonReader.testDateTimeTypeSupport(TestJsonReader.java:132)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at
```
update:
I made pr to fix this, https://github.com/apache/orc/pull/942
It looks like this is the problem pointed out by https://issues.apache.org/jira/projects/ORC/issues/ORC-879
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Fix some bugs that Java Tools recovery file command cannot find OrcFile.MAGIC accurately
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r732459997
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -703,4 +709,86 @@ public void testHasNull() throws Exception {
assumeTrue(!System.getProperty("os.name").startsWith("Windows"));
TestFileDump.checkOutput(outputFilename, workDir + File.separator + outputFilename);
}
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ conf.set(OrcConf.ENCODING_STRATEGY.getAttribute(), "COMPRESSION");
+ conf.set(OrcConf.DICTIONARY_IMPL.getAttribute(), "rbtree");
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema)
+ .compress(CompressionKind.ZLIB)
+ .stripeSize(100000)
+ .rowIndexStride(1000));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.addUserMetadata("hive.acid.key.index",
Review comment:
If you don't mind, shall we remove this?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736331291
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +710,80 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+
+ String testFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR), testFilePath))
+ .toUri().getPath();
+
+ String copyTestFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR),
+ new Path("CopyTestFileDump.testDump.orc")))
+ .toUri().getPath();
+
+ String testCrcFilePathStr = Path.mergePaths(workDir,
+ Path.mergePaths(new Path(Path.SEPARATOR),
+ new Path(".TestFileDump.testDump.orc.crc")))
+ .toUri().getPath();
+
+ try {
+ Files.copy(Paths.get(testFilePathStr), Paths.get(copyTestFilePathStr));
+
+ // Append write data to make it a corrupt file
+ try (FileOutputStream output = new FileOutputStream(testFilePathStr, true)) {
+ output.write(new byte[1024]);
+ output.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ output.write(new byte[1024]);
+ output.flush();
+ }
+
+ // Clean up the crc file and append data to avoid checksum read exceptions
Review comment:
as I append the file through java nio, crc file is not updated, if you do not delete the crc file, hdfs read interface will throw an exception.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736333556
##########
File path: java/tools/pom.xml
##########
@@ -91,6 +91,12 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
Review comment:
`assertTrue(FileUtils.contentEquals(new File(testFilePathStr), new File(copyTestFilePathStr)));`
The main reason is to use the file content comparison, because I found that the getFileChecksum method only gets null for the local file system. So I'll add a private method for file content comparison.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736182175
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -583,8 +602,10 @@ private static void recoverFile(final Path corruptPath, final FileSystem fs,
// Move side file to backup path
Path sideFilePath = OrcAcidUtils.getSideFile(corruptPath);
- Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
- moveFiles(fs, sideFilePath, backupSideFilePath);
+ if (fs.exists(sideFilePath)) {
Review comment:
I'm okay with this `fs.exists` checking. However, this should go first before this `OrcFileMAGIC` PR if you need this patch for your unit test. Please make a separate PR (without a test case). I can merge it.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r737247840
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -583,8 +602,10 @@ private static void recoverFile(final Path corruptPath, final FileSystem fs,
// Move side file to backup path
Path sideFilePath = OrcAcidUtils.getSideFile(corruptPath);
- Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
- moveFiles(fs, sideFilePath, backupSideFilePath);
+ if (fs.exists(sideFilePath)) {
+ Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
+ moveFiles(fs, sideFilePath, backupSideFilePath);
+ }
Review comment:
Now, it looks correct. Thank you!
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736175281
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -470,17 +476,30 @@ private static void recoverFiles(final List<String> corruptFiles, final Configur
List<Long> footerOffsets = new ArrayList<>();
// start reading the data file form top to bottom and record the valid footers
- while (remaining > 0) {
- int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
- byte[] data = new byte[toRead];
+ while (remaining > 0 && corruptFileLen > (2L * magicLength)) {
Review comment:
So, we don't care a tiny file whose size is less than 2 * magicLength because the correct ORC has at least two MAGIC strings?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736176210
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +714,79 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+ byte[] bytes = new byte[1024];
+ Path corruptedFilePath = new Path("corruptedFile.orc");
+
+ try {
+ FSDataInputStream fdis = fs.open(testFilePath);
+ FileStatus fileStatus = fs.getFileStatus(testFilePath);
+ FSDataOutputStream fdos = fs.create(corruptedFilePath, true,
+ conf.getInt("io.file.buffer.size", 4096),
+ fileStatus.getReplication(),
+ fileStatus.getBlockSize());
+ long remaining = fileSize;
+
+ while (remaining > 0) {
+ int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
+ byte[] data = new byte[toRead];
+ long startPos = fileSize - remaining;
+ fdis.readFully(startPos, data, 0, toRead);
+ fdos.write(data);
+ remaining = remaining - toRead;
+ }
+ fdos.write(bytes);
+ fdos.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ fdos.write(bytes);
+ fdis.close();
+ fdos.close();
Review comment:
Line 758 ~ 778 looks like copying a file simply. Did I understand correctly?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736327972
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +710,80 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+
+ String testFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR), testFilePath))
+ .toUri().getPath();
+
+ String copyTestFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR),
Review comment:
Fix in a1caa71
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736182175
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -583,8 +602,10 @@ private static void recoverFile(final Path corruptPath, final FileSystem fs,
// Move side file to backup path
Path sideFilePath = OrcAcidUtils.getSideFile(corruptPath);
- Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
- moveFiles(fs, sideFilePath, backupSideFilePath);
+ if (fs.exists(sideFilePath)) {
Review comment:
I'm okay with this `fs.exists` checking. However, this should go first before `OrcFile.MAGIC` PR if you need this patch for your unit test. Please make a separate PR (without a test case). I can merge it.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on pull request #941:
URL: https://github.com/apache/orc/pull/941#issuecomment-949070074
@dongjoon-hyun Sorry for the late reply. This pr is ready to review.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736190253
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +714,79 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+ byte[] bytes = new byte[1024];
+ Path corruptedFilePath = new Path("corruptedFile.orc");
+
+ try {
+ FSDataInputStream fdis = fs.open(testFilePath);
+ FileStatus fileStatus = fs.getFileStatus(testFilePath);
+ FSDataOutputStream fdos = fs.create(corruptedFilePath, true,
+ conf.getInt("io.file.buffer.size", 4096),
+ fileStatus.getReplication(),
+ fileStatus.getBlockSize());
+ long remaining = fileSize;
+
+ while (remaining > 0) {
+ int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
+ byte[] data = new byte[toRead];
+ long startPos = fileSize - remaining;
+ fdis.readFully(startPos, data, 0, toRead);
+ fdos.write(data);
+ remaining = remaining - toRead;
+ }
+ fdos.write(bytes);
+ fdos.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ fdos.write(bytes);
+ fdis.close();
+ fdos.close();
Review comment:
You should use Java IO instead of Hadoop FileSystem.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736192647
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +714,79 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+ byte[] bytes = new byte[1024];
+ Path corruptedFilePath = new Path("corruptedFile.orc");
+
+ try {
+ FSDataInputStream fdis = fs.open(testFilePath);
+ FileStatus fileStatus = fs.getFileStatus(testFilePath);
+ FSDataOutputStream fdos = fs.create(corruptedFilePath, true,
+ conf.getInt("io.file.buffer.size", 4096),
+ fileStatus.getReplication(),
+ fileStatus.getBlockSize());
+ long remaining = fileSize;
+
+ while (remaining > 0) {
+ int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
+ byte[] data = new byte[toRead];
+ long startPos = fileSize - remaining;
+ fdis.readFully(startPos, data, 0, toRead);
+ fdos.write(data);
+ remaining = remaining - toRead;
+ }
+ fdos.write(bytes);
+ fdos.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ fdos.write(bytes);
+ fdis.close();
+ fdos.close();
Review comment:
Thanks to @dongjoon-hyun for the review. Suggestions that made me feel enlightened. I'll fix it later (including checking sideFile).
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736177522
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -470,17 +476,30 @@ private static void recoverFiles(final List<String> corruptFiles, final Configur
List<Long> footerOffsets = new ArrayList<>();
// start reading the data file form top to bottom and record the valid footers
- while (remaining > 0) {
- int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
- byte[] data = new byte[toRead];
+ while (remaining > 0 && corruptFileLen > (2L * magicLength)) {
Review comment:
Yes, because after I modified it, it will move magicLength bytes outside the first read, which is to ensure that the internal move will not go out of bounds.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736328674
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +710,80 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+
+ String testFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR), testFilePath))
+ .toUri().getPath();
+
+ String copyTestFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR),
+ new Path("CopyTestFileDump.testDump.orc")))
+ .toUri().getPath();
+
+ String testCrcFilePathStr = Path.mergePaths(workDir,
+ Path.mergePaths(new Path(Path.SEPARATOR),
+ new Path(".TestFileDump.testDump.orc.crc")))
+ .toUri().getPath();
+
+ try {
+ Files.copy(Paths.get(testFilePathStr), Paths.get(copyTestFilePathStr));
+
+ // Append write data to make it a corrupt file
+ try (FileOutputStream output = new FileOutputStream(testFilePathStr, true)) {
+ output.write(new byte[1024]);
+ output.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ output.write(new byte[1024]);
+ output.flush();
+ }
+
+ // Clean up the crc file and append data to avoid checksum read exceptions
Review comment:
This looks like new. Previously, we don't have this. Why is changed from the previous?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on pull request #941: ORC-1030: Fix some bugs that Java Tools recovery file command cannot find OrcFile.MAGIC accurately
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on pull request #941:
URL: https://github.com/apache/orc/pull/941#issuecomment-947395635
> It would be great if we can have more specific PR title instead of `Fix some bugs`. If you need, you can split the PR into smaller ones.
It might be better to split it into two, I'll refine it later
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736175748
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -583,8 +602,10 @@ private static void recoverFile(final Path corruptPath, final FileSystem fs,
// Move side file to backup path
Path sideFilePath = OrcAcidUtils.getSideFile(corruptPath);
- Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
- moveFiles(fs, sideFilePath, backupSideFilePath);
+ if (fs.exists(sideFilePath)) {
Review comment:
This looks like an orthogonal fix. Is this related to this PR?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736180818
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -583,8 +602,10 @@ private static void recoverFile(final Path corruptPath, final FileSystem fs,
// Move side file to backup path
Path sideFilePath = OrcAcidUtils.getSideFile(corruptPath);
- Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
- moveFiles(fs, sideFilePath, backupSideFilePath);
+ if (fs.exists(sideFilePath)) {
Review comment:
I understand that this repair tool is geared towards this specific case, it assumes that `SideFile` must exist. The judgment I added for compatibility testing.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on pull request #941: ORC-1030: Fix some bugs that Java Tools recovery file command cannot find OrcFile.MAGIC accurately
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on pull request #941:
URL: https://github.com/apache/orc/pull/941#issuecomment-946774472
Travis CI caught a very rare exception, which I logged here first
```
java.time.format.DateTimeParseException: Text '2021-10-19T0700:01.683210-0700' could not be parsed at index 13
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2046)
at java.base/java.time.format.DateTimeFormatter.parseBest(DateTimeFormatter.java:1994)
at org.apache.orc.tools.convert.JsonReader$TimestampColumnConverter.convert(JsonReader.java:169)
at org.apache.orc.tools.convert.JsonReader.nextBatch(JsonReader.java:375)
at org.apache.orc.tools.convert.TestJsonReader.testDateTimeTypeSupport(TestJsonReader.java:132)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at
```
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun merged pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun merged pull request #941:
URL: https://github.com/apache/orc/pull/941
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #941:
URL: https://github.com/apache/orc/pull/941#issuecomment-948725592
Thank you for updating. Is this ready for review, @guiyanakuang ?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Fix some bugs that Java Tools recovery file command cannot find OrcFile.MAGIC accurately
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r732461971
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -703,4 +709,86 @@ public void testHasNull() throws Exception {
assumeTrue(!System.getProperty("os.name").startsWith("Windows"));
TestFileDump.checkOutput(outputFilename, workDir + File.separator + outputFilename);
}
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ conf.set(OrcConf.ENCODING_STRATEGY.getAttribute(), "COMPRESSION");
+ conf.set(OrcConf.DICTIONARY_IMPL.getAttribute(), "rbtree");
Review comment:
Good advice, I also think it's good to make sure test cases have pure intent, I'll fix it right away.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736323428
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +710,80 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+
+ String testFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR), testFilePath))
+ .toUri().getPath();
+
+ String copyTestFilePathStr = Path.mergePaths(
+ workDir, Path.mergePaths(new Path(Path.SEPARATOR),
Review comment:
Indentation looks inconsistent with line 752.
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r737245972
##########
File path: java/tools/src/java/org/apache/orc/tools/FileDump.java
##########
@@ -583,8 +602,10 @@ private static void recoverFile(final Path corruptPath, final FileSystem fs,
// Move side file to backup path
Path sideFilePath = OrcAcidUtils.getSideFile(corruptPath);
- Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
- moveFiles(fs, sideFilePath, backupSideFilePath);
+ if (fs.exists(sideFilePath)) {
+ Path backupSideFilePath = new Path(backupDataPath.getParent(), sideFilePath.getName());
+ moveFiles(fs, sideFilePath, backupSideFilePath);
+ }
Review comment:
@dongjoon-hyun I have removed the 1039 content, this pr merged 1034 midway and resolved the conflict, is it correct now?
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736188522
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +714,79 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+ byte[] bytes = new byte[1024];
+ Path corruptedFilePath = new Path("corruptedFile.orc");
+
+ try {
+ FSDataInputStream fdis = fs.open(testFilePath);
+ FileStatus fileStatus = fs.getFileStatus(testFilePath);
+ FSDataOutputStream fdos = fs.create(corruptedFilePath, true,
+ conf.getInt("io.file.buffer.size", 4096),
+ fileStatus.getReplication(),
+ fileStatus.getBlockSize());
+ long remaining = fileSize;
+
+ while (remaining > 0) {
+ int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
+ byte[] data = new byte[toRead];
+ long startPos = fileSize - remaining;
+ fdis.readFully(startPos, data, 0, toRead);
+ fdos.write(data);
+ remaining = remaining - toRead;
+ }
+ fdos.write(bytes);
+ fdos.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ fdos.write(bytes);
+ fdis.close();
+ fdos.close();
Review comment:
I tried `fs.append(testFilePath);`
It looks like the local filesystem doesn't support append, or is there some configuration I haven't set to make it work?
```
java.io.IOException: Not supported
at org.apache.hadoop.fs.ChecksumFileSystem.append(ChecksumFileSystem.java:358)
at org.apache.hadoop.fs.FileSystem.append(FileSystem.java:1333)
at org.apache.orc.tools.TestFileDump.testRecover(TestFileDump.java:756)
```
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] dongjoon-hyun commented on a change in pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #941:
URL: https://github.com/apache/orc/pull/941#discussion_r736184153
##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -709,6 +714,79 @@ public void testIndexOf() {
byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
- assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);
+ assertEquals(2, FileDump.indexOf(bytes, pattern, 1));
+ }
+
+ @Test
+ public void testRecover() throws Exception {
+ TypeDescription schema = getMyRecordType();
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .fileSystem(fs)
+ .setSchema(schema));
+ Random r1 = new Random(1);
+ String[] words = new String[]{"It", "was", "the", "best", "of", "times,",
+ "it", "was", "the", "worst", "of", "times,", "it", "was", "the", "age",
+ "of", "wisdom,", "it", "was", "the", "age", "of", "foolishness,", "it",
+ "was", "the", "epoch", "of", "belief,", "it", "was", "the", "epoch",
+ "of", "incredulity,", "it", "was", "the", "season", "of", "Light,",
+ "it", "was", "the", "season", "of", "Darkness,", "it", "was", "the",
+ "spring", "of", "hope,", "it", "was", "the", "winter", "of", "despair,",
+ "we", "had", "everything", "before", "us,", "we", "had", "nothing",
+ "before", "us,", "we", "were", "all", "going", "direct", "to",
+ "Heaven,", "we", "were", "all", "going", "direct", "the", "other",
+ "way"};
+ VectorizedRowBatch batch = schema.createRowBatch(1000);
+ for(int i=0; i < 21000; ++i) {
+ appendMyRecord(batch, r1.nextInt(), r1.nextLong(),
+ words[r1.nextInt(words.length)]);
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size > 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ long fileSize = fs.getFileStatus(testFilePath).getLen();
+ byte[] bytes = new byte[1024];
+ Path corruptedFilePath = new Path("corruptedFile.orc");
+
+ try {
+ FSDataInputStream fdis = fs.open(testFilePath);
+ FileStatus fileStatus = fs.getFileStatus(testFilePath);
+ FSDataOutputStream fdos = fs.create(corruptedFilePath, true,
+ conf.getInt("io.file.buffer.size", 4096),
+ fileStatus.getReplication(),
+ fileStatus.getBlockSize());
+ long remaining = fileSize;
+
+ while (remaining > 0) {
+ int toRead = (int) Math.min(DEFAULT_BLOCK_SIZE, remaining);
+ byte[] data = new byte[toRead];
+ long startPos = fileSize - remaining;
+ fdis.readFully(startPos, data, 0, toRead);
+ fdos.write(data);
+ remaining = remaining - toRead;
+ }
+ fdos.write(bytes);
+ fdos.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
+ fdos.write(bytes);
+ fdis.close();
+ fdos.close();
Review comment:
Shall we simply this by coping the file simply and append the following at the end?
```
byte[] bytes = new byte[1024];
fdos.write(bytes);
fdos.write(OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8));
fdos.write(bytes);
```
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [orc] guiyanakuang commented on pull request #941: ORC-1030: Java Tools may have missed OrcFile.MAGIC during file recovery
Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on pull request #941:
URL: https://github.com/apache/orc/pull/941#issuecomment-952657606
> [ORC-1039](https://issues.apache.org/jira/browse/ORC-1039) is merged. Could you rebase this PR?
Yes, do it now
--
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: dev-unsubscribe@orc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org