-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-17800 Prevent observer node from returning partial block data for erasure coded files #7754
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
Open
Kimahriman
wants to merge
4
commits into
apache:trunk
Choose a base branch
from
Kimahriman:observer-invalid-ec-blocks
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+177
−20
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2227,20 +2227,7 @@ LocatedBlocks getBlockLocations(String clientMachine, String srcArg, | |
| dir, pc, srcArg, offset, length, true); | ||
| inode = res.getIIp().getLastINode(); | ||
| if (isInSafeMode()) { | ||
| for (LocatedBlock b : res.blocks.getLocatedBlocks()) { | ||
| // if safemode & no block locations yet then throw safemodeException | ||
| if ((b.getLocations() == null) || (b.getLocations().length == 0)) { | ||
| SafeModeException se = newSafemodeException( | ||
| "Zero blocklocations for " + srcArg); | ||
| if (haEnabled && haContext != null && | ||
| (haContext.getState().getServiceState() == ACTIVE || | ||
| haContext.getState().getServiceState() == OBSERVER)) { | ||
| throw new RetriableException(se); | ||
| } else { | ||
| throw se; | ||
| } | ||
| } | ||
| } | ||
| checkBlockLocationsInSafeMode(res.blocks, srcArg); | ||
| } else if (isObserver()) { | ||
| checkBlockLocationsWhenObserver(res.blocks, srcArg); | ||
| } | ||
|
|
@@ -4326,11 +4313,15 @@ BatchedDirectoryListing getBatchedListing(String[] srcs, byte[] startAfter, | |
| if (dirListing == null) { | ||
| throw new FileNotFoundException("Path " + src + " does not exist"); | ||
| } | ||
| if (needLocation && isObserver()) { | ||
| if (needLocation) { | ||
| for (HdfsFileStatus fs : dirListing.getPartialListing()) { | ||
| if (fs instanceof HdfsLocatedFileStatus) { | ||
| LocatedBlocks lbs = ((HdfsLocatedFileStatus) fs).getLocatedBlocks(); | ||
| checkBlockLocationsWhenObserver(lbs, fs.toString()); | ||
| if (isInSafeMode()) { | ||
| checkBlockLocationsInSafeMode(lbs, fs.toString()); | ||
| } else if (isObserver()) { | ||
| checkBlockLocationsWhenObserver(lbs, fs.toString()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -9206,16 +9197,75 @@ private boolean isObserver() { | |
| return haEnabled && haContext != null && haContext.getState().getServiceState() == OBSERVER; | ||
| } | ||
|
|
||
| private boolean hasSufficientReplicas(LocatedBlock block, | ||
| ErasureCodingPolicy ecPolicy) { | ||
| DatanodeInfo[] locations = block.getLocations(); | ||
| if (locations == null) { | ||
| return false; | ||
| } | ||
|
|
||
| if (block.isStriped()) { | ||
| LocatedStripedBlock stripedBlock = (LocatedStripedBlock) block; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // For erasure coded files, require enough data units to reconstruct | ||
| // the block, bounded by the number of cells in the block. | ||
| long numCells = | ||
| (block.getBlockSize() - 1) / (long) ecPolicy.getCellSize() + 1; | ||
| int minBlocks = (int) Math.min((long) ecPolicy.getNumDataUnits(), numCells); | ||
|
|
||
| // Units can be over-replicated, so need to account for unique indices | ||
| byte[] indices = stripedBlock.getBlockIndices(); | ||
| boolean[] seen = new boolean[ecPolicy.getNumDataUnits() + ecPolicy.getNumParityUnits()]; | ||
|
|
||
| int count = 0; | ||
| for (byte idx : indices) { | ||
| int i = idx & 0xFF; | ||
| if (!seen[i]) { | ||
| seen[i] = true; | ||
| if (++count >= minBlocks) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } else { | ||
| return locations.length > 0; | ||
| } | ||
| } | ||
|
|
||
| private void checkBlockLocationsInSafeMode(LocatedBlocks blocks, String src) | ||
| throws SafeModeException, RetriableException { | ||
| if (blocks == null) { | ||
| return; | ||
| } | ||
| List<LocatedBlock> locatedBlockList = blocks.getLocatedBlocks(); | ||
| if (locatedBlockList != null) { | ||
| ErasureCodingPolicy ecPolicy = blocks.getErasureCodingPolicy(); | ||
| for (LocatedBlock block : locatedBlockList) { | ||
| if (!hasSufficientReplicas(block, ecPolicy)) { | ||
| SafeModeException se = newSafemodeException( | ||
| "Not enough blocklocations for " + src); | ||
| if (haEnabled && haContext != null && | ||
| (haContext.getState().getServiceState() == ACTIVE || | ||
| haContext.getState().getServiceState() == OBSERVER)) { | ||
| throw new RetriableException(se); | ||
| } | ||
| throw se; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void checkBlockLocationsWhenObserver(LocatedBlocks blocks, String src) | ||
| throws ObserverRetryOnActiveException { | ||
| if (blocks == null) { | ||
| return; | ||
| } | ||
| List<LocatedBlock> locatedBlockList = blocks.getLocatedBlocks(); | ||
| if (locatedBlockList != null) { | ||
| for (LocatedBlock b : locatedBlockList) { | ||
| if (b.getLocations() == null || b.getLocations().length == 0) { | ||
| throw new ObserverRetryOnActiveException("Zero blocklocations for " + src); | ||
| ErasureCodingPolicy ecPolicy = blocks.getErasureCodingPolicy(); | ||
| for (LocatedBlock block : locatedBlockList) { | ||
| if (!hasSufficientReplicas(block, ecPolicy)) { | ||
| throw new ObserverRetryOnActiveException("Not enough blocklocations for " + src); | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
hasSufficientBlockLocations