Skip to content

Commit

Permalink
use ignoredNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
KeeProMise committed Jan 3, 2024
1 parent 556fbcf commit 5f91a53
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -601,6 +602,19 @@ private List<LocatedBlock> getFinalizedBlockRange(
*/
private synchronized DatanodeInfo blockSeekTo(long target)
throws IOException {
return blockSeekTo(target, null);
}

/**
* Open a DataInputStream to a DataNode so that it can be read from.
* We get block ID and the IDs of the destinations at startup, from the namenode.
*
* @param target block corresponding to this target offset in file is returned.
* @param ignoredNodes Ignored nodes inside.
* @return best DataNode for desired Block, with potential offset.
*/
private synchronized DatanodeInfo blockSeekTo(
long target, Collection<DatanodeInfo> ignoredNodes) throws IOException {
if (target >= getFileLength()) {
throw new IOException("Attempted to read past end of file");
}
Expand Down Expand Up @@ -634,7 +648,7 @@ private synchronized DatanodeInfo blockSeekTo(long target)

long offsetIntoBlock = target - targetBlock.getStartOffset();

DNAddrPair retval = chooseDataNode(targetBlock, null);
DNAddrPair retval = chooseDataNode(targetBlock, ignoredNodes);
chosenNode = retval.info;
InetSocketAddress targetAddr = retval.addr;
StorageType storageType = retval.storageType;
Expand Down Expand Up @@ -1647,16 +1661,8 @@ public synchronized boolean seekToNewSource(long targetPos)
if (currentNode == null) {
return seekToBlockSource(targetPos);
}
boolean markedDead = dfsClient.isDeadNode(this, currentNode);
addToLocalDeadNodes(currentNode);
DatanodeInfo oldNode = currentNode;
DatanodeInfo newNode = blockSeekTo(targetPos);
if (!markedDead) {
/* remove it from deadNodes. blockSeekTo could have cleared
* deadNodes and added currentNode again. Thats ok. */
removeFromLocalDeadNodes(oldNode);
}
if (!oldNode.getDatanodeUuid().equals(newNode.getDatanodeUuid())) {
DatanodeInfo newNode = blockSeekTo(targetPos, Collections.singletonList(currentNode));
if (!currentNode.getDatanodeUuid().equals(newNode.getDatanodeUuid())) {
currentNode = newNode;
return true;
} else {
Expand Down

0 comments on commit 5f91a53

Please sign in to comment.