Skip to content

Commit

Permalink
Fix a bug that creates 0 byte block file mistakenly
Browse files Browse the repository at this point in the history
Cherry-pick of existing commit.
orig-pr: #17497
orig-commit: 812855f
orig-commit-author: Bin Fan <fanbin103@gmail.com>

			pr-link: #17519
			change-id: cid-92e96a46cf67606c3087115cf065a8470d929421
Xenorith authored May 30, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 5307320 commit 63b975f
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -171,30 +171,34 @@ public BlockReader createUfsBlockReader(long sessionId, long blockId, long offse
try {
BlockReader reader = mUnderFileSystemBlockStore.createBlockReader(sessionId, blockId, offset,
positionShort, options);
return new DelegatingBlockReader(reader, () -> closeUfsBlock(sessionId, blockId));
return new DelegatingBlockReader(reader, () -> closeUfsBlock(sessionId, blockId, true));
} catch (Exception e) {
try {
closeUfsBlock(sessionId, blockId);
closeUfsBlock(sessionId, blockId, false);
} catch (Exception ee) {
LOG.warn("Failed to close UFS block", ee);
}
String errorMessage = format("Failed to read from UFS, sessionId=%d, "
+ "blockId=%d, offset=%d, positionShort=%s, options=%s: %s",
sessionId, blockId, offset, positionShort, options, e);
sessionId, blockId, offset, positionShort, options, e.toString());
if (e instanceof FileNotFoundException) {
throw new NotFoundException(errorMessage, e);
}
throw new UnavailableException(errorMessage, e);
}
}

private void closeUfsBlock(long sessionId, long blockId)
private void closeUfsBlock(long sessionId, long blockId, boolean successful)
throws IOException {
try {
mUnderFileSystemBlockStore.closeBlock(sessionId, blockId);
Optional<TempBlockMeta> tempBlockMeta = mLocalBlockStore.getTempBlockMeta(blockId);
if (tempBlockMeta.isPresent() && tempBlockMeta.get().getSessionId() == sessionId) {
commitBlock(sessionId, blockId, false);
if (successful) {
commitBlock(sessionId, blockId, false);
} else {
abortBlock(sessionId, blockId);
}
} else {
// When getTempBlockMeta() return null, such as a block readType NO_CACHE writeType THROUGH.
// Counter will not be decrement in the commitblock().
Original file line number Diff line number Diff line change
@@ -667,7 +667,7 @@ public InputStream open(String path, OpenOptions options) throws IOException {
LOG.debug("Using original API to HDFS");
return new HdfsUnderFileInputStream(inputStream);
} catch (IOException e) {
LOG.warn("{} try to open {} : {}", retryPolicy.getAttemptCount(), path, e.toString());
LOG.debug("{} try to open {} : {}", retryPolicy.getAttemptCount(), path, e.toString());
te = e;
if (options.getRecoverFailedOpen() && dfs != null && e.getMessage().toLowerCase()
.startsWith("cannot obtain block length for")) {
@@ -694,7 +694,12 @@ public InputStream open(String path, OpenOptions options) throws IOException {
}
}
}
throw te;
if (te != null) {
LOG.error("{} failed attempts to open \"{}\" with last error:",
retryPolicy.getAttemptCount(), path, te);
throw te;
}
throw new IllegalStateException("Exceeded the number of retry attempts with no exception");
}

@Override

0 comments on commit 63b975f

Please sign in to comment.