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:
parent
ab29f5c5f9
commit
7decf112c0
|
@ -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.
|
||||
|
|
|
@ -150,6 +150,14 @@ public class Block implements Writable, Comparable<Block> {
|
|||
return getBlockName() + "_" + getGenerationStamp();
|
||||
}
|
||||
|
||||
public void appendStringTo(StringBuilder sb) {
|
||||
sb.append(BLOCK_FILE_PREFIX)
|
||||
.append(blockId)
|
||||
.append("_")
|
||||
.append(getGenerationStamp());
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Writable
|
||||
/////////////////////////////////////
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs.server.blockmanagement;
|
|||
|
||||
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 class BlockInfoUnderConstruction extends BlockInfo {
|
|||
|
||||
@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 class BlockInfoUnderConstruction extends BlockInfo {
|
|||
|
||||
@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("]}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1722,9 +1722,7 @@ public class BlockManager {
|
|||
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 @@ public class BlockManager {
|
|||
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>
|
||||
|
|
Loading…
Reference in New Issue