|
@@ -49,7 +49,6 @@ class FSNamesystem implements FSConstants {
|
|
//
|
|
//
|
|
// Stores the block-->datanode(s) map. Updated only in response
|
|
// Stores the block-->datanode(s) map. Updated only in response
|
|
// to client-sent information.
|
|
// to client-sent information.
|
|
- // Mapping: Block -> TreeSet<DatanodeDescriptor>
|
|
|
|
//
|
|
//
|
|
TreeMap blocksMap = new TreeMap();
|
|
TreeMap blocksMap = new TreeMap();
|
|
|
|
|
|
@@ -57,10 +56,10 @@ class FSNamesystem implements FSConstants {
|
|
// Stores the datanode-->block map. Done by storing a
|
|
// Stores the datanode-->block map. Done by storing a
|
|
// set of datanode info objects, sorted by name. Updated only in
|
|
// set of datanode info objects, sorted by name. Updated only in
|
|
// response to client-sent information.
|
|
// response to client-sent information.
|
|
- // Mapping: StorageID -> DatanodeDescriptor
|
|
|
|
//
|
|
//
|
|
TreeMap datanodeMap = new TreeMap();
|
|
TreeMap datanodeMap = new TreeMap();
|
|
|
|
|
|
|
|
+
|
|
//
|
|
//
|
|
// Stores the set of dead datanodes
|
|
// Stores the set of dead datanodes
|
|
TreeMap deaddatanodeMap = new TreeMap();
|
|
TreeMap deaddatanodeMap = new TreeMap();
|
|
@@ -69,7 +68,6 @@ class FSNamesystem implements FSConstants {
|
|
// Keeps a Vector for every named machine. The Vector contains
|
|
// Keeps a Vector for every named machine. The Vector contains
|
|
// blocks that have recently been invalidated and are thought to live
|
|
// blocks that have recently been invalidated and are thought to live
|
|
// on the machine in question.
|
|
// on the machine in question.
|
|
- // Mapping: StorageID -> Vector<Block>
|
|
|
|
//
|
|
//
|
|
TreeMap recentInvalidateSets = new TreeMap();
|
|
TreeMap recentInvalidateSets = new TreeMap();
|
|
|
|
|
|
@@ -77,20 +75,19 @@ class FSNamesystem implements FSConstants {
|
|
// Keeps a TreeSet for every named node. Each treeset contains
|
|
// Keeps a TreeSet for every named node. Each treeset contains
|
|
// a list of the blocks that are "extra" at that location. We'll
|
|
// a list of the blocks that are "extra" at that location. We'll
|
|
// eventually remove these extras.
|
|
// eventually remove these extras.
|
|
- // Mapping: Block -> TreeSet<DatanodeDescriptor>
|
|
|
|
//
|
|
//
|
|
TreeMap excessReplicateMap = new TreeMap();
|
|
TreeMap excessReplicateMap = new TreeMap();
|
|
|
|
|
|
//
|
|
//
|
|
// Keeps track of files that are being created, plus the
|
|
// Keeps track of files that are being created, plus the
|
|
// blocks that make them up.
|
|
// blocks that make them up.
|
|
- // Mapping: fileName -> FileUnderConstruction
|
|
|
|
|
|
+ //
|
|
|
|
+ // Maps file names to FileUnderConstruction objects
|
|
//
|
|
//
|
|
TreeMap pendingCreates = new TreeMap();
|
|
TreeMap pendingCreates = new TreeMap();
|
|
|
|
|
|
//
|
|
//
|
|
// Keeps track of the blocks that are part of those pending creates
|
|
// Keeps track of the blocks that are part of those pending creates
|
|
- // Set of: Block
|
|
|
|
//
|
|
//
|
|
TreeSet pendingCreateBlocks = new TreeSet();
|
|
TreeSet pendingCreateBlocks = new TreeSet();
|
|
|
|
|
|
@@ -111,14 +108,14 @@ class FSNamesystem implements FSConstants {
|
|
Random r = new Random();
|
|
Random r = new Random();
|
|
|
|
|
|
//
|
|
//
|
|
- // Stores a set of DatanodeDescriptor objects, sorted by heartbeat
|
|
|
|
|
|
+ // Stores a set of datanode info objects, sorted by heartbeat
|
|
//
|
|
//
|
|
TreeSet heartbeats = new TreeSet(new Comparator() {
|
|
TreeSet heartbeats = new TreeSet(new Comparator() {
|
|
public int compare(Object o1, Object o2) {
|
|
public int compare(Object o1, Object o2) {
|
|
- DatanodeDescriptor d1 = (DatanodeDescriptor) o1;
|
|
|
|
- DatanodeDescriptor d2 = (DatanodeDescriptor) o2;
|
|
|
|
- long lu1 = d1.getLastUpdate();
|
|
|
|
- long lu2 = d2.getLastUpdate();
|
|
|
|
|
|
+ DatanodeInfo d1 = (DatanodeInfo) o1;
|
|
|
|
+ DatanodeInfo d2 = (DatanodeInfo) o2;
|
|
|
|
+ long lu1 = d1.lastUpdate();
|
|
|
|
+ long lu2 = d2.lastUpdate();
|
|
if (lu1 < lu2) {
|
|
if (lu1 < lu2) {
|
|
return -1;
|
|
return -1;
|
|
} else if (lu1 > lu2) {
|
|
} else if (lu1 > lu2) {
|
|
@@ -132,17 +129,14 @@ class FSNamesystem implements FSConstants {
|
|
//
|
|
//
|
|
// Store set of Blocks that need to be replicated 1 or more times.
|
|
// Store set of Blocks that need to be replicated 1 or more times.
|
|
// We also store pending replication-orders.
|
|
// We also store pending replication-orders.
|
|
- // Set of: Block
|
|
|
|
//
|
|
//
|
|
private TreeSet neededReplications = new TreeSet();
|
|
private TreeSet neededReplications = new TreeSet();
|
|
private TreeSet pendingReplications = new TreeSet();
|
|
private TreeSet pendingReplications = new TreeSet();
|
|
|
|
|
|
//
|
|
//
|
|
// Used for handling lock-leases
|
|
// Used for handling lock-leases
|
|
- // Mapping: leaseHolder -> Lease
|
|
|
|
//
|
|
//
|
|
private TreeMap leases = new TreeMap();
|
|
private TreeMap leases = new TreeMap();
|
|
- // Set of: Lease
|
|
|
|
private TreeSet sortedLeases = new TreeSet();
|
|
private TreeSet sortedLeases = new TreeSet();
|
|
|
|
|
|
//
|
|
//
|
|
@@ -252,17 +246,17 @@ class FSNamesystem implements FSConstants {
|
|
Block blocks[] = dir.getFile(src);
|
|
Block blocks[] = dir.getFile(src);
|
|
if (blocks != null) {
|
|
if (blocks != null) {
|
|
results = new Object[2];
|
|
results = new Object[2];
|
|
- DatanodeDescriptor machineSets[][] = new DatanodeDescriptor[blocks.length][];
|
|
|
|
|
|
+ DatanodeInfo machineSets[][] = new DatanodeInfo[blocks.length][];
|
|
|
|
|
|
for (int i = 0; i < blocks.length; i++) {
|
|
for (int i = 0; i < blocks.length; i++) {
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(blocks[i]);
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(blocks[i]);
|
|
if (containingNodes == null) {
|
|
if (containingNodes == null) {
|
|
- machineSets[i] = new DatanodeDescriptor[0];
|
|
|
|
|
|
+ machineSets[i] = new DatanodeInfo[0];
|
|
} else {
|
|
} else {
|
|
- machineSets[i] = new DatanodeDescriptor[containingNodes.size()];
|
|
|
|
|
|
+ machineSets[i] = new DatanodeInfo[containingNodes.size()];
|
|
int j = 0;
|
|
int j = 0;
|
|
for (Iterator it = containingNodes.iterator(); it.hasNext(); j++) {
|
|
for (Iterator it = containingNodes.iterator(); it.hasNext(); j++) {
|
|
- machineSets[i][j] = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ machineSets[i][j] = (DatanodeInfo) it.next();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -388,7 +382,7 @@ class FSNamesystem implements FSConstants {
|
|
}
|
|
}
|
|
|
|
|
|
// Get the array of replication targets
|
|
// Get the array of replication targets
|
|
- DatanodeDescriptor targets[] = chooseTargets(replication, null,
|
|
|
|
|
|
+ DatanodeInfo targets[] = chooseTargets(replication, null,
|
|
clientMachine, blockSize);
|
|
clientMachine, blockSize);
|
|
if (targets.length < this.minReplication) {
|
|
if (targets.length < this.minReplication) {
|
|
throw new IOException("failed to create file "+src
|
|
throw new IOException("failed to create file "+src
|
|
@@ -470,7 +464,7 @@ class FSNamesystem implements FSConstants {
|
|
}
|
|
}
|
|
|
|
|
|
// Get the array of replication targets
|
|
// Get the array of replication targets
|
|
- DatanodeDescriptor targets[] = chooseTargets(pendingFile.getReplication(),
|
|
|
|
|
|
+ DatanodeInfo targets[] = chooseTargets(pendingFile.getReplication(),
|
|
null, pendingFile.getClientMachine(), pendingFile.getBlockSize());
|
|
null, pendingFile.getClientMachine(), pendingFile.getBlockSize());
|
|
if (targets.length < this.minReplication) {
|
|
if (targets.length < this.minReplication) {
|
|
throw new IOException("File " + src + " could only be replicated to " +
|
|
throw new IOException("File " + src + " could only be replicated to " +
|
|
@@ -574,7 +568,7 @@ class FSNamesystem implements FSConstants {
|
|
for (int i = 0; i < nrBlocks; i++) {
|
|
for (int i = 0; i < nrBlocks; i++) {
|
|
Block b = (Block)pendingBlocks[i];
|
|
Block b = (Block)pendingBlocks[i];
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(b);
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(b);
|
|
- DatanodeDescriptor node = (DatanodeDescriptor) containingNodes.first();
|
|
|
|
|
|
+ DatanodeInfo node = (DatanodeInfo) containingNodes.first();
|
|
for (Iterator it = node.getBlockIterator(); it.hasNext(); ) {
|
|
for (Iterator it = node.getBlockIterator(); it.hasNext(); ) {
|
|
Block cur = (Block) it.next();
|
|
Block cur = (Block) it.next();
|
|
if (b.getBlockId() == cur.getBlockId()) {
|
|
if (b.getBlockId() == cur.getBlockId()) {
|
|
@@ -706,7 +700,7 @@ class FSNamesystem implements FSConstants {
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(b);
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(b);
|
|
if (containingNodes != null) {
|
|
if (containingNodes != null) {
|
|
for (Iterator it = containingNodes.iterator(); it.hasNext(); ) {
|
|
for (Iterator it = containingNodes.iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor node = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo node = (DatanodeInfo) it.next();
|
|
Vector invalidateSet = (Vector) recentInvalidateSets.get(node.getStorageID());
|
|
Vector invalidateSet = (Vector) recentInvalidateSets.get(node.getStorageID());
|
|
if (invalidateSet == null) {
|
|
if (invalidateSet == null) {
|
|
invalidateSet = new Vector();
|
|
invalidateSet = new Vector();
|
|
@@ -801,7 +795,7 @@ class FSNamesystem implements FSConstants {
|
|
Vector v = new Vector();
|
|
Vector v = new Vector();
|
|
if (containingNodes != null) {
|
|
if (containingNodes != null) {
|
|
for (Iterator it =containingNodes.iterator(); it.hasNext();) {
|
|
for (Iterator it =containingNodes.iterator(); it.hasNext();) {
|
|
- DatanodeDescriptor cur = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo cur = (DatanodeInfo) it.next();
|
|
v.add(new UTF8( cur.getHost() ));
|
|
v.add(new UTF8( cur.getHost() ));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1051,8 +1045,8 @@ class FSNamesystem implements FSConstants {
|
|
+ " storage " + nodeReg.getStorageID() );
|
|
+ " storage " + nodeReg.getStorageID() );
|
|
|
|
|
|
nodeReg.registrationID = getRegistrationID();
|
|
nodeReg.registrationID = getRegistrationID();
|
|
- DatanodeDescriptor nodeS = (DatanodeDescriptor)datanodeMap.get(nodeReg.getStorageID());
|
|
|
|
- DatanodeDescriptor nodeN = getDatanodeByName( nodeReg.getName() );
|
|
|
|
|
|
+ DatanodeInfo nodeS = (DatanodeInfo)datanodeMap.get(nodeReg.getStorageID());
|
|
|
|
+ DatanodeInfo nodeN = getDatanodeByName( nodeReg.getName() );
|
|
|
|
|
|
if( nodeN != null && nodeS != null && nodeN == nodeS ) {
|
|
if( nodeN != null && nodeS != null && nodeN == nodeS ) {
|
|
// The same datanode has been just restarted to serve the same data
|
|
// The same datanode has been just restarted to serve the same data
|
|
@@ -1084,7 +1078,7 @@ class FSNamesystem implements FSConstants {
|
|
}
|
|
}
|
|
// register new datanode
|
|
// register new datanode
|
|
datanodeMap.put(nodeReg.getStorageID(),
|
|
datanodeMap.put(nodeReg.getStorageID(),
|
|
- new DatanodeDescriptor( nodeReg ) ) ;
|
|
|
|
|
|
+ new DatanodeInfo( nodeReg ) ) ;
|
|
NameNode.stateChangeLog.debug(
|
|
NameNode.stateChangeLog.debug(
|
|
"BLOCK* NameSystem.registerDatanode: "
|
|
"BLOCK* NameSystem.registerDatanode: "
|
|
+ "node registered." );
|
|
+ "node registered." );
|
|
@@ -1143,13 +1137,13 @@ class FSNamesystem implements FSConstants {
|
|
synchronized (datanodeMap) {
|
|
synchronized (datanodeMap) {
|
|
long capacityDiff = 0;
|
|
long capacityDiff = 0;
|
|
long remainingDiff = 0;
|
|
long remainingDiff = 0;
|
|
- DatanodeDescriptor nodeinfo = getDatanode( nodeID );
|
|
|
|
|
|
+ DatanodeInfo nodeinfo = getDatanode( nodeID );
|
|
deaddatanodeMap.remove(nodeID.getName());
|
|
deaddatanodeMap.remove(nodeID.getName());
|
|
|
|
|
|
if (nodeinfo == null) {
|
|
if (nodeinfo == null) {
|
|
NameNode.stateChangeLog.debug("BLOCK* NameSystem.gotHeartbeat: "
|
|
NameNode.stateChangeLog.debug("BLOCK* NameSystem.gotHeartbeat: "
|
|
+"brand-new heartbeat from "+nodeID.getName() );
|
|
+"brand-new heartbeat from "+nodeID.getName() );
|
|
- nodeinfo = new DatanodeDescriptor(nodeID, capacity, remaining);
|
|
|
|
|
|
+ nodeinfo = new DatanodeInfo(nodeID, capacity, remaining);
|
|
datanodeMap.put(nodeinfo.getStorageID(), nodeinfo);
|
|
datanodeMap.put(nodeinfo.getStorageID(), nodeinfo);
|
|
capacityDiff = capacity;
|
|
capacityDiff = capacity;
|
|
remainingDiff = remaining;
|
|
remainingDiff = remaining;
|
|
@@ -1185,12 +1179,12 @@ class FSNamesystem implements FSConstants {
|
|
|
|
|
|
/**
|
|
/**
|
|
* remove a datanode info
|
|
* remove a datanode info
|
|
- * @param nodeID datanode ID
|
|
|
|
|
|
+ * @param name: datanode name
|
|
* @author hairong
|
|
* @author hairong
|
|
*/
|
|
*/
|
|
synchronized public void removeDatanode( DatanodeID nodeID )
|
|
synchronized public void removeDatanode( DatanodeID nodeID )
|
|
throws IOException {
|
|
throws IOException {
|
|
- DatanodeDescriptor nodeInfo = getDatanode( nodeID );
|
|
|
|
|
|
+ DatanodeInfo nodeInfo = getDatanode( nodeID );
|
|
if (nodeInfo != null) {
|
|
if (nodeInfo != null) {
|
|
removeDatanode( nodeInfo );
|
|
removeDatanode( nodeInfo );
|
|
} else {
|
|
} else {
|
|
@@ -1201,10 +1195,10 @@ class FSNamesystem implements FSConstants {
|
|
|
|
|
|
/**
|
|
/**
|
|
* remove a datanode info
|
|
* remove a datanode info
|
|
- * @param nodeInfo datanode info
|
|
|
|
|
|
+ * @param nodeInfo: datanode info
|
|
* @author hairong
|
|
* @author hairong
|
|
*/
|
|
*/
|
|
- private void removeDatanode( DatanodeDescriptor nodeInfo ) {
|
|
|
|
|
|
+ private void removeDatanode( DatanodeInfo nodeInfo ) {
|
|
heartbeats.remove(nodeInfo);
|
|
heartbeats.remove(nodeInfo);
|
|
datanodeMap.remove(nodeInfo.getStorageID());
|
|
datanodeMap.remove(nodeInfo.getStorageID());
|
|
deaddatanodeMap.put(nodeInfo.getName(), nodeInfo);
|
|
deaddatanodeMap.put(nodeInfo.getName(), nodeInfo);
|
|
@@ -1225,19 +1219,17 @@ class FSNamesystem implements FSConstants {
|
|
*/
|
|
*/
|
|
synchronized void heartbeatCheck() {
|
|
synchronized void heartbeatCheck() {
|
|
synchronized (heartbeats) {
|
|
synchronized (heartbeats) {
|
|
- DatanodeDescriptor nodeInfo = null;
|
|
|
|
|
|
+ DatanodeInfo nodeInfo = null;
|
|
|
|
|
|
while ((heartbeats.size() > 0) &&
|
|
while ((heartbeats.size() > 0) &&
|
|
- ((nodeInfo = (DatanodeDescriptor) heartbeats.first()) != null) &&
|
|
|
|
- (nodeInfo.isDead())) {
|
|
|
|
|
|
+ ((nodeInfo = (DatanodeInfo) heartbeats.first()) != null) &&
|
|
|
|
+ (nodeInfo.lastUpdate() < System.currentTimeMillis() - EXPIRE_INTERVAL)) {
|
|
NameNode.stateChangeLog.info("BLOCK* NameSystem.heartbeatCheck: "
|
|
NameNode.stateChangeLog.info("BLOCK* NameSystem.heartbeatCheck: "
|
|
+ "lost heartbeat from " + nodeInfo.getName());
|
|
+ "lost heartbeat from " + nodeInfo.getName());
|
|
removeDatanode( nodeInfo );
|
|
removeDatanode( nodeInfo );
|
|
- /* SHV
|
|
|
|
if (heartbeats.size() > 0) {
|
|
if (heartbeats.size() > 0) {
|
|
- nodeInfo = (DatanodeDescriptor) heartbeats.first();
|
|
|
|
|
|
+ nodeInfo = (DatanodeInfo) heartbeats.first();
|
|
}
|
|
}
|
|
- */
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1251,7 +1243,7 @@ class FSNamesystem implements FSConstants {
|
|
) throws IOException {
|
|
) throws IOException {
|
|
NameNode.stateChangeLog.debug("BLOCK* NameSystem.processReport: "
|
|
NameNode.stateChangeLog.debug("BLOCK* NameSystem.processReport: "
|
|
+"from "+nodeID.getName()+" "+newReport.length+" blocks" );
|
|
+"from "+nodeID.getName()+" "+newReport.length+" blocks" );
|
|
- DatanodeDescriptor node = getDatanode( nodeID );
|
|
|
|
|
|
+ DatanodeInfo node = getDatanode( nodeID );
|
|
|
|
|
|
//
|
|
//
|
|
// Modify the (block-->datanode) map, according to the difference
|
|
// Modify the (block-->datanode) map, according to the difference
|
|
@@ -1321,7 +1313,7 @@ class FSNamesystem implements FSConstants {
|
|
* Modify (block-->datanode) map. Remove block from set of
|
|
* Modify (block-->datanode) map. Remove block from set of
|
|
* needed replications if this takes care of the problem.
|
|
* needed replications if this takes care of the problem.
|
|
*/
|
|
*/
|
|
- synchronized void addStoredBlock(Block block, DatanodeDescriptor node) {
|
|
|
|
|
|
+ synchronized void addStoredBlock(Block block, DatanodeInfo node) {
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(block);
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(block);
|
|
if (containingNodes == null) {
|
|
if (containingNodes == null) {
|
|
containingNodes = new TreeSet();
|
|
containingNodes = new TreeSet();
|
|
@@ -1377,7 +1369,7 @@ class FSNamesystem implements FSConstants {
|
|
return;
|
|
return;
|
|
Vector nonExcess = new Vector();
|
|
Vector nonExcess = new Vector();
|
|
for (Iterator it = containingNodes.iterator(); it.hasNext(); ) {
|
|
for (Iterator it = containingNodes.iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor cur = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo cur = (DatanodeInfo) it.next();
|
|
TreeSet excessBlocks = (TreeSet) excessReplicateMap.get(cur.getStorageID());
|
|
TreeSet excessBlocks = (TreeSet) excessReplicateMap.get(cur.getStorageID());
|
|
if (excessBlocks == null || ! excessBlocks.contains(block)) {
|
|
if (excessBlocks == null || ! excessBlocks.contains(block)) {
|
|
nonExcess.add(cur);
|
|
nonExcess.add(cur);
|
|
@@ -1398,7 +1390,7 @@ class FSNamesystem implements FSConstants {
|
|
void chooseExcessReplicates(Vector nonExcess, Block b, short replication) {
|
|
void chooseExcessReplicates(Vector nonExcess, Block b, short replication) {
|
|
while (nonExcess.size() - replication > 0) {
|
|
while (nonExcess.size() - replication > 0) {
|
|
int chosenNode = r.nextInt(nonExcess.size());
|
|
int chosenNode = r.nextInt(nonExcess.size());
|
|
- DatanodeDescriptor cur = (DatanodeDescriptor) nonExcess.elementAt(chosenNode);
|
|
|
|
|
|
+ DatanodeInfo cur = (DatanodeInfo) nonExcess.elementAt(chosenNode);
|
|
nonExcess.removeElementAt(chosenNode);
|
|
nonExcess.removeElementAt(chosenNode);
|
|
|
|
|
|
TreeSet excessBlocks = (TreeSet) excessReplicateMap.get(cur.getStorageID());
|
|
TreeSet excessBlocks = (TreeSet) excessReplicateMap.get(cur.getStorageID());
|
|
@@ -1434,7 +1426,7 @@ class FSNamesystem implements FSConstants {
|
|
* Modify (block-->datanode) map. Possibly generate
|
|
* Modify (block-->datanode) map. Possibly generate
|
|
* replication tasks, if the removed block is still valid.
|
|
* replication tasks, if the removed block is still valid.
|
|
*/
|
|
*/
|
|
- synchronized void removeStoredBlock(Block block, DatanodeDescriptor node) {
|
|
|
|
|
|
+ synchronized void removeStoredBlock(Block block, DatanodeInfo node) {
|
|
NameNode.stateChangeLog.debug("BLOCK* NameSystem.removeStoredBlock: "
|
|
NameNode.stateChangeLog.debug("BLOCK* NameSystem.removeStoredBlock: "
|
|
+block.getBlockName() + " from "+node.getName() );
|
|
+block.getBlockName() + " from "+node.getName() );
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(block);
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(block);
|
|
@@ -1479,7 +1471,7 @@ class FSNamesystem implements FSConstants {
|
|
public synchronized void blockReceived( DatanodeID nodeID,
|
|
public synchronized void blockReceived( DatanodeID nodeID,
|
|
Block block
|
|
Block block
|
|
) throws IOException {
|
|
) throws IOException {
|
|
- DatanodeDescriptor node = getDatanode( nodeID );
|
|
|
|
|
|
+ DatanodeInfo node = getDatanode( nodeID );
|
|
if (node == null) {
|
|
if (node == null) {
|
|
NameNode.stateChangeLog.warn("BLOCK* NameSystem.blockReceived: "
|
|
NameNode.stateChangeLog.warn("BLOCK* NameSystem.blockReceived: "
|
|
+ block.getBlockName() + " is received from an unrecorded node "
|
|
+ block.getBlockName() + " is received from an unrecorded node "
|
|
@@ -1517,14 +1509,14 @@ class FSNamesystem implements FSConstants {
|
|
|
|
|
|
/**
|
|
/**
|
|
*/
|
|
*/
|
|
- public DatanodeDescriptor[] datanodeReport() {
|
|
|
|
- DatanodeDescriptor results[] = null;
|
|
|
|
|
|
+ public DatanodeInfo[] datanodeReport() {
|
|
|
|
+ DatanodeInfo results[] = null;
|
|
synchronized (heartbeats) {
|
|
synchronized (heartbeats) {
|
|
synchronized (datanodeMap) {
|
|
synchronized (datanodeMap) {
|
|
- results = new DatanodeDescriptor[datanodeMap.size()];
|
|
|
|
|
|
+ results = new DatanodeInfo[datanodeMap.size()];
|
|
int i = 0;
|
|
int i = 0;
|
|
for (Iterator it = datanodeMap.values().iterator(); it.hasNext(); ) {
|
|
for (Iterator it = datanodeMap.values().iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor cur = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo cur = (DatanodeInfo) it.next();
|
|
results[i++] = cur;
|
|
results[i++] = cur;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1545,9 +1537,9 @@ class FSNamesystem implements FSConstants {
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
*/
|
|
*/
|
|
- public DatanodeDescriptor getDataNodeInfo(String name) {
|
|
|
|
|
|
+ public DatanodeInfo getDataNodeInfo(String name) {
|
|
UTF8 src = new UTF8(name);
|
|
UTF8 src = new UTF8(name);
|
|
- return (DatanodeDescriptor)datanodeMap.get(src);
|
|
|
|
|
|
+ return (DatanodeInfo)datanodeMap.get(src);
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
*/
|
|
*/
|
|
@@ -1599,11 +1591,11 @@ class FSNamesystem implements FSConstants {
|
|
*
|
|
*
|
|
* The Array that we return consists of two objects:
|
|
* The Array that we return consists of two objects:
|
|
* The 1st elt is an array of Blocks.
|
|
* The 1st elt is an array of Blocks.
|
|
- * The 2nd elt is a 2D array of DatanodeDescriptor objs, identifying the
|
|
|
|
|
|
+ * The 2nd elt is a 2D array of DatanodeInfo objs, identifying the
|
|
* target sequence for the Block at the appropriate index.
|
|
* target sequence for the Block at the appropriate index.
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- public synchronized Object[] pendingTransfers(DatanodeDescriptor srcNode,
|
|
|
|
|
|
+ public synchronized Object[] pendingTransfers(DatanodeInfo srcNode,
|
|
int xmitsInProgress) {
|
|
int xmitsInProgress) {
|
|
synchronized (neededReplications) {
|
|
synchronized (neededReplications) {
|
|
Object results[] = null;
|
|
Object results[] = null;
|
|
@@ -1638,7 +1630,7 @@ class FSNamesystem implements FSConstants {
|
|
// not be scheduled for removal on that node
|
|
// not be scheduled for removal on that node
|
|
if (containingNodes.contains(srcNode)
|
|
if (containingNodes.contains(srcNode)
|
|
&& (excessBlocks == null || ! excessBlocks.contains(block))) {
|
|
&& (excessBlocks == null || ! excessBlocks.contains(block))) {
|
|
- DatanodeDescriptor targets[] = chooseTargets(
|
|
|
|
|
|
+ DatanodeInfo targets[] = chooseTargets(
|
|
Math.min( fileINode.getReplication() - containingNodes.size(),
|
|
Math.min( fileINode.getReplication() - containingNodes.size(),
|
|
this.maxReplicationStreams - xmitsInProgress),
|
|
this.maxReplicationStreams - xmitsInProgress),
|
|
containingNodes, null, blockSize);
|
|
containingNodes, null, blockSize);
|
|
@@ -1662,8 +1654,8 @@ class FSNamesystem implements FSConstants {
|
|
int i = 0;
|
|
int i = 0;
|
|
for (Iterator it = replicateBlocks.iterator(); it.hasNext(); i++) {
|
|
for (Iterator it = replicateBlocks.iterator(); it.hasNext(); i++) {
|
|
Block block = (Block) it.next();
|
|
Block block = (Block) it.next();
|
|
- DatanodeDescriptor targets[] =
|
|
|
|
- (DatanodeDescriptor[]) replicateTargetSets.elementAt(i);
|
|
|
|
|
|
+ DatanodeInfo targets[] =
|
|
|
|
+ (DatanodeInfo[]) replicateTargetSets.elementAt(i);
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(block);
|
|
TreeSet containingNodes = (TreeSet) blocksMap.get(block);
|
|
|
|
|
|
if (containingNodes.size() + targets.length >=
|
|
if (containingNodes.size() + targets.length >=
|
|
@@ -1692,10 +1684,10 @@ class FSNamesystem implements FSConstants {
|
|
//
|
|
//
|
|
// Build returned objects from above lists
|
|
// Build returned objects from above lists
|
|
//
|
|
//
|
|
- DatanodeDescriptor targetMatrix[][] =
|
|
|
|
- new DatanodeDescriptor[replicateTargetSets.size()][];
|
|
|
|
|
|
+ DatanodeInfo targetMatrix[][] =
|
|
|
|
+ new DatanodeInfo[replicateTargetSets.size()][];
|
|
for (i = 0; i < targetMatrix.length; i++) {
|
|
for (i = 0; i < targetMatrix.length; i++) {
|
|
- targetMatrix[i] = (DatanodeDescriptor[]) replicateTargetSets.elementAt(i);
|
|
|
|
|
|
+ targetMatrix[i] = (DatanodeInfo[]) replicateTargetSets.elementAt(i);
|
|
}
|
|
}
|
|
|
|
|
|
results = new Object[2];
|
|
results = new Object[2];
|
|
@@ -1713,10 +1705,10 @@ class FSNamesystem implements FSConstants {
|
|
* @param desiredReplicates
|
|
* @param desiredReplicates
|
|
* number of duplicates wanted.
|
|
* number of duplicates wanted.
|
|
* @param forbiddenNodes
|
|
* @param forbiddenNodes
|
|
- * of DatanodeDescriptor instances that should not be considered targets.
|
|
|
|
- * @return array of DatanodeDescriptor instances uses as targets.
|
|
|
|
|
|
+ * of DatanodeInfo instances that should not be considered targets.
|
|
|
|
+ * @return array of DatanodeInfo instances uses as targets.
|
|
*/
|
|
*/
|
|
- DatanodeDescriptor[] chooseTargets(int desiredReplicates, TreeSet forbiddenNodes,
|
|
|
|
|
|
+ DatanodeInfo[] chooseTargets(int desiredReplicates, TreeSet forbiddenNodes,
|
|
UTF8 clientMachine, long blockSize) {
|
|
UTF8 clientMachine, long blockSize) {
|
|
if (desiredReplicates > datanodeMap.size()) {
|
|
if (desiredReplicates > datanodeMap.size()) {
|
|
LOG.warn("Replication requested of "+desiredReplicates
|
|
LOG.warn("Replication requested of "+desiredReplicates
|
|
@@ -1729,14 +1721,14 @@ class FSNamesystem implements FSConstants {
|
|
Vector targets = new Vector();
|
|
Vector targets = new Vector();
|
|
|
|
|
|
for (int i = 0; i < desiredReplicates; i++) {
|
|
for (int i = 0; i < desiredReplicates; i++) {
|
|
- DatanodeDescriptor target = chooseTarget(forbiddenNodes, alreadyChosen,
|
|
|
|
|
|
+ DatanodeInfo target = chooseTarget(forbiddenNodes, alreadyChosen,
|
|
clientMachine, blockSize);
|
|
clientMachine, blockSize);
|
|
if (target == null)
|
|
if (target == null)
|
|
break; // calling chooseTarget again won't help
|
|
break; // calling chooseTarget again won't help
|
|
targets.add(target);
|
|
targets.add(target);
|
|
alreadyChosen.add(target);
|
|
alreadyChosen.add(target);
|
|
}
|
|
}
|
|
- return (DatanodeDescriptor[]) targets.toArray(new DatanodeDescriptor[targets.size()]);
|
|
|
|
|
|
+ return (DatanodeInfo[]) targets.toArray(new DatanodeInfo[targets.size()]);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1746,12 +1738,12 @@ class FSNamesystem implements FSConstants {
|
|
* Right now it chooses randomly from available boxes. In future could
|
|
* Right now it chooses randomly from available boxes. In future could
|
|
* choose according to capacity and load-balancing needs (or even
|
|
* choose according to capacity and load-balancing needs (or even
|
|
* network-topology, to avoid inter-switch traffic).
|
|
* network-topology, to avoid inter-switch traffic).
|
|
- * @param forbidden1 DatanodeDescriptor targets not allowed, null allowed.
|
|
|
|
- * @param forbidden2 DatanodeDescriptor targets not allowed, null allowed.
|
|
|
|
- * @return DatanodeDescriptor instance to use or null if something went wrong
|
|
|
|
|
|
+ * @param forbidden1 DatanodeInfo targets not allowed, null allowed.
|
|
|
|
+ * @param forbidden2 DatanodeInfo targets not allowed, null allowed.
|
|
|
|
+ * @return DatanodeInfo instance to use or null if something went wrong
|
|
* (a log message is emitted if null is returned).
|
|
* (a log message is emitted if null is returned).
|
|
*/
|
|
*/
|
|
- DatanodeDescriptor chooseTarget(TreeSet forbidden1, TreeSet forbidden2,
|
|
|
|
|
|
+ DatanodeInfo chooseTarget(TreeSet forbidden1, TreeSet forbidden2,
|
|
UTF8 clientMachine, long blockSize) {
|
|
UTF8 clientMachine, long blockSize) {
|
|
//
|
|
//
|
|
// Check if there are any available targets at all
|
|
// Check if there are any available targets at all
|
|
@@ -1768,13 +1760,13 @@ class FSNamesystem implements FSConstants {
|
|
TreeSet forbiddenMachines = new TreeSet();
|
|
TreeSet forbiddenMachines = new TreeSet();
|
|
if (forbidden1 != null) {
|
|
if (forbidden1 != null) {
|
|
for (Iterator it = forbidden1.iterator(); it.hasNext(); ) {
|
|
for (Iterator it = forbidden1.iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor cur = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo cur = (DatanodeInfo) it.next();
|
|
forbiddenMachines.add(cur.getHost());
|
|
forbiddenMachines.add(cur.getHost());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (forbidden2 != null) {
|
|
if (forbidden2 != null) {
|
|
for (Iterator it = forbidden2.iterator(); it.hasNext(); ) {
|
|
for (Iterator it = forbidden2.iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor cur = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo cur = (DatanodeInfo) it.next();
|
|
forbiddenMachines.add(cur.getHost());
|
|
forbiddenMachines.add(cur.getHost());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1784,7 +1776,7 @@ class FSNamesystem implements FSConstants {
|
|
//
|
|
//
|
|
Vector targetList = new Vector();
|
|
Vector targetList = new Vector();
|
|
for (Iterator it = datanodeMap.values().iterator(); it.hasNext(); ) {
|
|
for (Iterator it = datanodeMap.values().iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor node = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo node = (DatanodeInfo) it.next();
|
|
if (! forbiddenMachines.contains(node.getHost())) {
|
|
if (! forbiddenMachines.contains(node.getHost())) {
|
|
targetList.add(node);
|
|
targetList.add(node);
|
|
}
|
|
}
|
|
@@ -1801,7 +1793,7 @@ class FSNamesystem implements FSConstants {
|
|
//
|
|
//
|
|
if (clientMachine != null && clientMachine.getLength() > 0) {
|
|
if (clientMachine != null && clientMachine.getLength() > 0) {
|
|
for (Iterator it = targetList.iterator(); it.hasNext(); ) {
|
|
for (Iterator it = targetList.iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor node = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo node = (DatanodeInfo) it.next();
|
|
if (clientMachine.equals(node.getHost())) {
|
|
if (clientMachine.equals(node.getHost())) {
|
|
if (node.getRemaining() > blockSize * MIN_BLOCKS_FOR_WRITE) {
|
|
if (node.getRemaining() > blockSize * MIN_BLOCKS_FOR_WRITE) {
|
|
return node;
|
|
return node;
|
|
@@ -1814,7 +1806,7 @@ class FSNamesystem implements FSConstants {
|
|
// Otherwise, choose node according to target capacity
|
|
// Otherwise, choose node according to target capacity
|
|
//
|
|
//
|
|
for (Iterator it = targetList.iterator(); it.hasNext(); ) {
|
|
for (Iterator it = targetList.iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor node = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo node = (DatanodeInfo) it.next();
|
|
if (node.getRemaining() > blockSize * MIN_BLOCKS_FOR_WRITE) {
|
|
if (node.getRemaining() > blockSize * MIN_BLOCKS_FOR_WRITE) {
|
|
return node;
|
|
return node;
|
|
}
|
|
}
|
|
@@ -1826,7 +1818,7 @@ class FSNamesystem implements FSConstants {
|
|
// a last resort, pick the first valid one we can find.
|
|
// a last resort, pick the first valid one we can find.
|
|
//
|
|
//
|
|
for (Iterator it = targetList.iterator(); it.hasNext(); ) {
|
|
for (Iterator it = targetList.iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor node = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo node = (DatanodeInfo) it.next();
|
|
if (node.getRemaining() > blockSize) {
|
|
if (node.getRemaining() > blockSize) {
|
|
return node;
|
|
return node;
|
|
}
|
|
}
|
|
@@ -1894,12 +1886,12 @@ class FSNamesystem implements FSConstants {
|
|
* Get data node by storage ID.
|
|
* Get data node by storage ID.
|
|
*
|
|
*
|
|
* @param nodeID
|
|
* @param nodeID
|
|
- * @return DatanodeDescriptor or null if the node is not found.
|
|
|
|
|
|
+ * @return DatanodeInfo or null if the node is not found.
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public DatanodeDescriptor getDatanode( DatanodeID nodeID ) throws IOException {
|
|
|
|
|
|
+ public DatanodeInfo getDatanode( DatanodeID nodeID ) throws IOException {
|
|
UnregisteredDatanodeException e = null;
|
|
UnregisteredDatanodeException e = null;
|
|
- DatanodeDescriptor node = (DatanodeDescriptor) datanodeMap.get(nodeID.getStorageID());
|
|
|
|
|
|
+ DatanodeInfo node = (DatanodeInfo) datanodeMap.get(nodeID.getStorageID());
|
|
if (node == null)
|
|
if (node == null)
|
|
return null;
|
|
return null;
|
|
if (!node.getName().equals(nodeID.getName())) {
|
|
if (!node.getName().equals(nodeID.getName())) {
|
|
@@ -1919,12 +1911,12 @@ class FSNamesystem implements FSConstants {
|
|
* Otherwise an additional tree-like structure will be required.
|
|
* Otherwise an additional tree-like structure will be required.
|
|
*
|
|
*
|
|
* @param name
|
|
* @param name
|
|
- * @return DatanodeDescriptor if found or null otherwise
|
|
|
|
|
|
+ * @return DatanodeInfo if found or null otherwise
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
- public DatanodeDescriptor getDatanodeByName( String name ) throws IOException {
|
|
|
|
|
|
+ public DatanodeInfo getDatanodeByName( String name ) throws IOException {
|
|
for (Iterator it = datanodeMap.values().iterator(); it.hasNext(); ) {
|
|
for (Iterator it = datanodeMap.values().iterator(); it.hasNext(); ) {
|
|
- DatanodeDescriptor node = (DatanodeDescriptor) it.next();
|
|
|
|
|
|
+ DatanodeInfo node = (DatanodeInfo) it.next();
|
|
if( node.getName().equals(name) )
|
|
if( node.getName().equals(name) )
|
|
return node;
|
|
return node;
|
|
}
|
|
}
|