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
[BEAM-747] Improve FileChecksumMatcher That Inconsistent With Filesystem #1189
Conversation
bc6a892
to
be73409
Compare
+R: @jasonkuster |
private String actualChecksum; | ||
|
||
public FileChecksumMatcher(String checksum, String filePath) { | ||
this(checksum, filePath, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing in null here, probably clearer to pass in DEFAULT_SHARD_TEMPLATE. Leave the null-handling in the constructor below of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
IOChannelUtils.resolve(tmpFolder.getRoot().getPath(), "*")); | ||
|
||
assertThat(pResult, matcher); | ||
} | ||
|
||
@Test | ||
public void testReadWithRetriesFailsWhenTemplateIncorrect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a test here that verifies incorrect template behavior, but no test which verifies any template other than the default template. Probably a good idea to add one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
/** | ||
* Check if total number of files is correct by comparing with the number that | ||
* is parsed from shard name using a name template. If no template are specified, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no template is specified
be73409
to
e3cb725
Compare
PTAL @jasonkuster |
@markflyhigh can you rebase to kick the tests until we get a clean execution? (or until you uncover a real bug) |
5385c10
to
65a09aa
Compare
Rebased with latest master and all integration tests passed. The Jenkins build failed because known existing bugs that doesn't related to this PR. PTAL: @kennknowles @jasonkuster |
LGTM, assuming Jenkins failure is transient. Suggest rebasing and kicking tests off again. |
Refer to this link for build results (access rights to CI server needed): |
65a09aa
to
b29d495
Compare
friendly ping @kennknowles |
*/ | ||
@VisibleForTesting | ||
boolean checkTotalNumOfFiles(Collection<String> files) { | ||
for (String filePath : files.toArray(new String[0])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need toArray
here? Should be able to just use for (String filePath : files) { ... }
. If not, please comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, should just use the simple way to iterate collections. done
.withInitialBackoff(DEFAULT_SLEEP_DURATION) | ||
.withMaxRetries(MAX_READ_RETRIES); | ||
|
||
private static final String DEFAULT_SHARD_TEMPLATE = "\\S*\\d+-of-(\\d+)$"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have type Pattern
unless there is a special reason not to compile it right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
.withInitialBackoff(DEFAULT_SLEEP_DURATION) | ||
.withMaxRetries(MAX_READ_RETRIES); | ||
|
||
private static final String DEFAULT_SHARD_TEMPLATE = "\\S*\\d+-of-(\\d+)$"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend using named groups and allowing space via (?x)
for greater clarity. Here I've just demonstrated adding also a capture for shardnum
.
// Whitespace is ignored
Pattern.compile("(?x) \\S* (?shardnum \\d+) -of- (?numshards \\d+)")
This will allow your later use of .group(1)
to be .group("numshards")
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! done
this(checksum, filePath, DEFAULT_SHARD_TEMPLATE); | ||
} | ||
|
||
public FileChecksumMatcher(String checksum, String filePath, String shardTemplate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should take a Pattern
unless there is a special reason not to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -66,48 +99,105 @@ public FileChecksumMatcher(String checksum, String filePath) { | |||
|
|||
this.expectedChecksum = checksum; | |||
this.filePath = filePath; | |||
this.shardTemplate = | |||
Pattern.compile(shardTemplate == null ? DEFAULT_SHARD_TEMPLATE : shardTemplate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't check for null
but should require the user to call the other constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a precondition check to make sure it's non-null.
LOG.info("Generated checksum for output data: {}", actualChecksum); | ||
// Verify outputs. Checksum is computed using SHA-1 algorithm | ||
actualChecksum = computeHash(outputs); | ||
LOG.info("Generated checksum: {}", actualChecksum); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silence this or LOG.debug
. If there is a mismatch the error thrown should contain this information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
LOG.info( | ||
"[{} of {}] Read {} lines from file: {}", i, files.size() - 1, lines.size(), file); | ||
"[{} of {}] Read {} lines from file: {}", i, files.size(), lines.size(), file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silence, or LOG.debug
.
try { | ||
// Match inputPath which may contains glob | ||
Collection<String> files = factory.match(filePath); | ||
LOG.info("Found {} file(s) by matching the path: {}", files.size(), filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silence or LOG.debug
// once match, extract total number of shards and compare to file list | ||
return files.size() == Integer.parseInt(matcher.group(1)); | ||
} | ||
LOG.warn("No name matches the shard template: {}", shardTemplate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should either be an error or remain silent. When is this expected to be OK and when is it not OK?
continue; | ||
} | ||
// once match, extract total number of shards and compare to file list | ||
return files.size() == Integer.parseInt(matcher.group(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above how to make this more self-explanatory as .group("numshards")
. Either way, requires a brief comment about the expectations of the shard template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! I'll add javadoc to explain more for customized shard template.
b29d495
to
7adbe6c
Compare
7adbe6c
to
ae339c1
Compare
PTAL @kennknowles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I'll merge. Thanks!
Be sure to do all of the following to help us incorporate your contribution
quickly and easily:
[BEAM-<Jira issue #>] Description of pull request
mvn clean verify
. (Even better, enableTravis-CI on your fork and ensure the whole test matrix passes).
<Jira issue #>
in the title with the actual Jira issuenumber, if there is one.
Individual Contributor License Agreement.
Add retry in FileChecksumMatcher when following conditions happens:
Default retry times are 4. Default sleep duration between each retry are 10s.