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

HDFS-16732. [SBN READ] Avoid get location from observer when the block report is delayed #4756

Merged
merged 4 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -103,6 +103,7 @@
import org.apache.commons.text.CaseUtils;
import org.apache.hadoop.hdfs.protocol.ECTopologyVerifierResult;
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus;
import org.apache.hadoop.hdfs.protocol.SnapshotStatus;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_KEY;
import static org.apache.hadoop.hdfs.server.namenode.FSDirStatAndListingOp.*;
Expand Down Expand Up @@ -2202,14 +2203,8 @@ LocatedBlocks getBlockLocations(String clientMachine, String srcArg,
}
}
}
} else if (haEnabled && haContext != null &&
haContext.getState().getServiceState() == OBSERVER) {
for (LocatedBlock b : res.blocks.getLocatedBlocks()) {
if (b.getLocations() == null || b.getLocations().length == 0) {
throw new ObserverRetryOnActiveException("Zero blocklocations "
+ "for " + srcArg);
}
}
} else if (isObserver()) {
checkBlockLocationsWhenObserver(res.blocks, srcArg);
}
} finally {
readUnlock(operationName, getLockReportInfoSupplier(srcArg));
Expand Down Expand Up @@ -3470,6 +3465,10 @@ HdfsFileStatus getFileInfo(final String src, boolean resolveLink,
logAuditEvent(false, operationName, src);
throw e;
}
if (needLocation && isObserver() && stat instanceof HdfsLocatedFileStatus) {
LocatedBlocks lbs = ((HdfsLocatedFileStatus) stat).getLocatedBlocks();
checkBlockLocationsWhenObserver(lbs, src);
}
logAuditEvent(true, operationName, src);
return stat;
}
Expand Down Expand Up @@ -4175,6 +4174,14 @@ DirectoryListing getListing(String src, byte[] startAfter,
logAuditEvent(false, operationName, src);
throw e;
}
if (needLocation && isObserver()) {
for (HdfsFileStatus fs : dl.getPartialListing()) {
if (fs instanceof HdfsLocatedFileStatus) {
LocatedBlocks lbs = ((HdfsLocatedFileStatus) fs).getLocatedBlocks();
checkBlockLocationsWhenObserver(lbs, fs.toString());
}
}
}
logAuditEvent(true, operationName, src);
return dl;
}
Expand Down Expand Up @@ -9020,4 +9027,17 @@ public void checkErasureCodingSupported(String operationName)
throw new UnsupportedActionException(operationName + " not supported.");
}
}

private boolean isObserver() {
return haEnabled && haContext != null && haContext.getState().getServiceState() == OBSERVER;
}

private void checkBlockLocationsWhenObserver(LocatedBlocks blocks, String src)
throws ObserverRetryOnActiveException {
for (LocatedBlock b : blocks.getLocatedBlocks()) {
if (b.getLocations() == null || b.getLocations().length == 0) {
throw new ObserverRetryOnActiveException("Zero blocklocations for " + src);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ public void testObserverNodeBlockMissingRetry() throws Exception {
dfs.open(testPath);
assertSentTo(0);

dfs.getClient().listPaths("/", new byte[0], true);
assertSentTo(0);

dfs.getClient().getLocatedFileInfo(testPath.toString(), false);
assertSentTo(0);

Mockito.reset(bmSpy);
}

Expand Down