HDFS-3024. Improve performance of stringification in addStoredBlock. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1294754 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2012-02-28 18:04:13 +00:00
parent ab29f5c5f9
commit 7decf112c0
4 changed files with 60 additions and 14 deletions

View File

@ -201,6 +201,8 @@ Release 0.23.3 - UNRELEASED
OPTIMIZATIONS OPTIMIZATIONS
HDFS-3024. Improve performance of stringification in addStoredBlock (todd)
BUG FIXES BUG FIXES
HDFS-2481. Unknown protocol: org.apache.hadoop.hdfs.protocol.ClientProtocol. HDFS-2481. Unknown protocol: org.apache.hadoop.hdfs.protocol.ClientProtocol.

View File

@ -150,6 +150,14 @@ public class Block implements Writable, Comparable<Block> {
return getBlockName() + "_" + getGenerationStamp(); return getBlockName() + "_" + getGenerationStamp();
} }
public void appendStringTo(StringBuilder sb) {
sb.append(BLOCK_FILE_PREFIX)
.append(blockId)
.append("_")
.append(getGenerationStamp());
}
///////////////////////////////////// /////////////////////////////////////
// Writable // Writable
///////////////////////////////////// /////////////////////////////////////

View File

@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs.server.blockmanagement;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.protocol.Block;
@ -114,14 +115,19 @@ public class BlockInfoUnderConstruction extends BlockInfo {
@Override @Override
public String toString() { public String toString() {
final StringBuilder b = new StringBuilder(getClass().getSimpleName()); final StringBuilder b = new StringBuilder(50);
b.append("[") appendStringTo(b);
.append(expectedLocation)
.append("|")
.append(state)
.append("]");
return b.toString(); return b.toString();
} }
@Override
public void appendStringTo(StringBuilder sb) {
sb.append("ReplicaUnderConstruction[")
.append(expectedLocation)
.append("|")
.append(state)
.append("]");
}
} }
/** /**
@ -269,11 +275,29 @@ public class BlockInfoUnderConstruction extends BlockInfo {
@Override @Override
public String toString() { public String toString() {
final StringBuilder b = new StringBuilder(super.toString()); final StringBuilder b = new StringBuilder(100);
b.append("{blockUCState=").append(blockUCState) appendStringTo(b);
.append(", primaryNodeIndex=").append(primaryNodeIndex)
.append(", replicas=").append(replicas)
.append("}");
return b.toString(); return b.toString();
} }
@Override
public void appendStringTo(StringBuilder sb) {
super.appendStringTo(sb);
appendUCParts(sb);
}
private void appendUCParts(StringBuilder sb) {
sb.append("{blockUCState=").append(blockUCState)
.append(", primaryNodeIndex=").append(primaryNodeIndex)
.append(", replicas=[");
Iterator<ReplicaUnderConstruction> iter = replicas.iterator();
if (iter.hasNext()) {
iter.next().appendStringTo(sb);
while (iter.hasNext()) {
sb.append(", ");
iter.next().appendStringTo(sb);
}
}
sb.append("]}");
}
} }

View File

@ -1722,9 +1722,7 @@ public class BlockManager {
if (added) { if (added) {
curReplicaDelta = 1; curReplicaDelta = 1;
if (logEveryBlock) { if (logEveryBlock) {
NameNode.stateChangeLog.info("BLOCK* addStoredBlock: " logAddStoredBlock(storedBlock, node);
+ "blockMap updated: " + node.getName() + " is added to " +
storedBlock + " size " + storedBlock.getNumBytes());
} }
} else { } else {
curReplicaDelta = 0; curReplicaDelta = 0;
@ -1784,6 +1782,20 @@ public class BlockManager {
return storedBlock; return storedBlock;
} }
private void logAddStoredBlock(BlockInfo storedBlock, DatanodeDescriptor node) {
if (!NameNode.stateChangeLog.isInfoEnabled()) {
return;
}
StringBuilder sb = new StringBuilder(500);
sb.append("BLOCK* addStoredBlock: blockMap updated: ")
.append(node.getName())
.append(" is added to ");
storedBlock.appendStringTo(sb);
sb.append(" size " )
.append(storedBlock.getNumBytes());
NameNode.stateChangeLog.info(sb);
}
/** /**
* Invalidate corrupt replicas. * Invalidate corrupt replicas.
* <p> * <p>