Skip to content
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

Fix a bug that creates 0 byte block file mistakenly #17497

Merged
merged 2 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,32 +183,36 @@ public BlockReader createUfsBlockReader(long sessionId, long blockId, long offse
BlockReader reader = mUnderFileSystemBlockStore.createBlockReader(sessionId, blockId, offset,
positionShort, options);
BlockReader blockReader = new DelegatingBlockReader(reader,
() -> closeUfsBlock(sessionId, blockId));
() -> closeUfsBlock(sessionId, blockId, true));
Metrics.WORKER_ACTIVE_CLIENTS.inc();
return blockReader;
} 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().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,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")) {
Expand All @@ -711,6 +711,10 @@ public InputStream open(String path, OpenOptions options) throws IOException {
}
}
}
if (te != null) {
LOG.error("{} failed attempts to open \"{}\" with last error:",
retryPolicy.getAttemptCount(), path, te);
}
throw te;
}

Expand Down