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
HDFS-3024. Improve performance of stringification in addStoredBlock (todd)
BUG FIXES
HDFS-2481. Unknown protocol: org.apache.hadoop.hdfs.protocol.ClientProtocol.

View File

@ -150,6 +150,14 @@ public String toString() {
return getBlockName() + "_" + getGenerationStamp();
}
public void appendStringTo(StringBuilder sb) {
sb.append(BLOCK_FILE_PREFIX)
.append(blockId)
.append("_")
.append(getGenerationStamp());
}
/////////////////////////////////////
// Writable
/////////////////////////////////////

View File

@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.hadoop.hdfs.protocol.Block;
@ -114,14 +115,19 @@ public boolean equals(Object obj) {
@Override
public String toString() {
final StringBuilder b = new StringBuilder(getClass().getSimpleName());
b.append("[")
.append(expectedLocation)
.append("|")
.append(state)
.append("]");
final StringBuilder b = new StringBuilder(50);
appendStringTo(b);
return b.toString();
}
@Override
public void appendStringTo(StringBuilder sb) {
sb.append("ReplicaUnderConstruction[")
.append(expectedLocation)
.append("|")
.append(state)
.append("]");
}
}
/**
@ -269,11 +275,29 @@ public boolean equals(Object obj) {
@Override
public String toString() {
final StringBuilder b = new StringBuilder(super.toString());
b.append("{blockUCState=").append(blockUCState)
.append(", primaryNodeIndex=").append(primaryNodeIndex)
.append(", replicas=").append(replicas)
.append("}");
final StringBuilder b = new StringBuilder(100);
appendStringTo(b);
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 @@ private Block addStoredBlock(final BlockInfo block,
if (added) {
curReplicaDelta = 1;
if (logEveryBlock) {
NameNode.stateChangeLog.info("BLOCK* addStoredBlock: "
+ "blockMap updated: " + node.getName() + " is added to " +
storedBlock + " size " + storedBlock.getNumBytes());
logAddStoredBlock(storedBlock, node);
}
} else {
curReplicaDelta = 0;
@ -1784,6 +1782,20 @@ private Block addStoredBlock(final BlockInfo block,
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.
* <p>