HDFS-9398. Make ByteArraryManager log message in one-line format. Contributed by Mingliang Liu
This commit is contained in:
parent
2801b42a7e
commit
9614dea71a
@ -36,6 +36,18 @@
|
|||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public abstract class ByteArrayManager {
|
public abstract class ByteArrayManager {
|
||||||
static final Logger LOG = LoggerFactory.getLogger(ByteArrayManager.class);
|
static final Logger LOG = LoggerFactory.getLogger(ByteArrayManager.class);
|
||||||
|
private static final ThreadLocal<StringBuilder> DEBUG_MESSAGE =
|
||||||
|
new ThreadLocal<StringBuilder>() {
|
||||||
|
protected StringBuilder initialValue() {
|
||||||
|
return new StringBuilder();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static void logDebugMessage() {
|
||||||
|
final StringBuilder b = DEBUG_MESSAGE.get();
|
||||||
|
LOG.debug(b.toString());
|
||||||
|
b.setLength(0);
|
||||||
|
}
|
||||||
|
|
||||||
static final int MIN_ARRAY_LENGTH = 32;
|
static final int MIN_ARRAY_LENGTH = 32;
|
||||||
static final byte[] EMPTY_BYTE_ARRAY = {};
|
static final byte[] EMPTY_BYTE_ARRAY = {};
|
||||||
@ -148,18 +160,27 @@ static class FixedLengthManager {
|
|||||||
* via the {@link FixedLengthManager#recycle(byte[])} method.
|
* via the {@link FixedLengthManager#recycle(byte[])} method.
|
||||||
*/
|
*/
|
||||||
synchronized byte[] allocate() throws InterruptedException {
|
synchronized byte[] allocate() throws InterruptedException {
|
||||||
LOG.debug(", {}", this);
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get().append(", ").append(this);
|
||||||
|
}
|
||||||
for(; numAllocated >= maxAllocated;) {
|
for(; numAllocated >= maxAllocated;) {
|
||||||
LOG.debug(": wait ...");
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get().append(": wait ...");
|
||||||
|
logDebugMessage();
|
||||||
|
}
|
||||||
|
|
||||||
wait();
|
wait();
|
||||||
|
|
||||||
LOG.debug("wake up: {}", this);
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get().append("wake up: ").append(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
numAllocated++;
|
numAllocated++;
|
||||||
|
|
||||||
final byte[] array = freeQueue.poll();
|
final byte[] array = freeQueue.poll();
|
||||||
LOG.debug(", recycled? {}", array != null);
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get().append(", recycled? ").append(array != null);
|
||||||
|
}
|
||||||
return array != null? array : new byte[byteArrayLength];
|
return array != null? array : new byte[byteArrayLength];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +194,9 @@ synchronized byte[] allocate() throws InterruptedException {
|
|||||||
synchronized int recycle(byte[] array) {
|
synchronized int recycle(byte[] array) {
|
||||||
Preconditions.checkNotNull(array);
|
Preconditions.checkNotNull(array);
|
||||||
Preconditions.checkArgument(array.length == byteArrayLength);
|
Preconditions.checkArgument(array.length == byteArrayLength);
|
||||||
LOG.debug(", {}", this);
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get().append(", ").append(this);
|
||||||
|
}
|
||||||
|
|
||||||
notify();
|
notify();
|
||||||
numAllocated--;
|
numAllocated--;
|
||||||
@ -184,7 +207,9 @@ synchronized int recycle(byte[] array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (freeQueue.size() < maxAllocated - numAllocated) {
|
if (freeQueue.size() < maxAllocated - numAllocated) {
|
||||||
LOG.debug(", freeQueue.offer");
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get().append(", freeQueue.offer");
|
||||||
|
}
|
||||||
freeQueue.offer(array);
|
freeQueue.offer(array);
|
||||||
}
|
}
|
||||||
return freeQueue.size();
|
return freeQueue.size();
|
||||||
@ -324,7 +349,9 @@ static class Impl extends ByteArrayManager {
|
|||||||
public byte[] newByteArray(final int arrayLength)
|
public byte[] newByteArray(final int arrayLength)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
Preconditions.checkArgument(arrayLength >= 0);
|
Preconditions.checkArgument(arrayLength >= 0);
|
||||||
LOG.debug("allocate({})", arrayLength);
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get().append("allocate(").append(arrayLength).append(")");
|
||||||
|
}
|
||||||
|
|
||||||
final byte[] array;
|
final byte[] array;
|
||||||
if (arrayLength == 0) {
|
if (arrayLength == 0) {
|
||||||
@ -338,12 +365,18 @@ public byte[] newByteArray(final int arrayLength)
|
|||||||
final FixedLengthManager manager =
|
final FixedLengthManager manager =
|
||||||
managers.get(powerOfTwo, aboveThreshold);
|
managers.get(powerOfTwo, aboveThreshold);
|
||||||
|
|
||||||
LOG.debug(": count={}, {}Threshold", count,
|
if (LOG.isDebugEnabled()) {
|
||||||
aboveThreshold ? "above" : "below");
|
DEBUG_MESSAGE.get().append(": count=").append(count)
|
||||||
|
.append(aboveThreshold? ", aboveThreshold": ", belowThreshold");
|
||||||
|
}
|
||||||
array = manager != null? manager.allocate(): new byte[powerOfTwo];
|
array = manager != null? manager.allocate(): new byte[powerOfTwo];
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug(", return byte[{}]", array.length);
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get().append(", return byte[")
|
||||||
|
.append(array.length).append("]");
|
||||||
|
logDebugMessage();
|
||||||
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +391,10 @@ public byte[] newByteArray(final int arrayLength)
|
|||||||
@Override
|
@Override
|
||||||
public int release(final byte[] array) {
|
public int release(final byte[] array) {
|
||||||
Preconditions.checkNotNull(array);
|
Preconditions.checkNotNull(array);
|
||||||
LOG.debug("recycle: array.length={}", array.length);
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get()
|
||||||
|
.append("recycle: array.length=").append(array.length);
|
||||||
|
}
|
||||||
|
|
||||||
final int freeQueueSize;
|
final int freeQueueSize;
|
||||||
if (array.length == 0) {
|
if (array.length == 0) {
|
||||||
@ -368,7 +404,10 @@ public int release(final byte[] array) {
|
|||||||
freeQueueSize = manager == null? -1: manager.recycle(array);
|
freeQueueSize = manager == null? -1: manager.recycle(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug(", freeQueueSize={}", freeQueueSize);
|
if (LOG.isDebugEnabled()) {
|
||||||
|
DEBUG_MESSAGE.get().append(", freeQueueSize=").append(freeQueueSize);
|
||||||
|
logDebugMessage();
|
||||||
|
}
|
||||||
return freeQueueSize;
|
return freeQueueSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1635,6 +1635,9 @@ Release 2.8.0 - UNRELEASED
|
|||||||
HDFS-9379. Make NNThroughputBenchmark$BlockReportStats support more than 10
|
HDFS-9379. Make NNThroughputBenchmark$BlockReportStats support more than 10
|
||||||
datanodes. (Mingliang Liu via Arpit Agarwal)
|
datanodes. (Mingliang Liu via Arpit Agarwal)
|
||||||
|
|
||||||
|
HDFS-9398. Make ByteArraryManager log message in one-line format.
|
||||||
|
(Mingliang Liu via szetszwo)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than
|
HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than
|
||||||
|
Loading…
Reference in New Issue
Block a user