HDFS-10351. Ozone: Optimize key writes to chunks by providing a bulk write implementation in ChunkOutputStream. Contributed by Chris Nauroth.

This commit is contained in:
Anu Engineer 2016-05-02 14:50:40 -07:00 committed by Owen O'Malley
parent acf0b220ce
commit aa3ca951f9
2 changed files with 26 additions and 2 deletions

View File

@ -380,8 +380,6 @@ public final class OzoneMetadataManager {
public ListVolumes listVolumes(ListArgs args) throws OzoneException { public ListVolumes listVolumes(ListArgs args) throws OzoneException {
lock.readLock().lock(); lock.readLock().lock();
try { try {
Preconditions.checkState(args.getArgs() instanceof UserArgs);
if (args.isRootScan()) { if (args.isRootScan()) {
return listAllVolumes(args); return listAllVolumes(args);
} }

View File

@ -100,6 +100,32 @@ class ChunkOutputStream extends OutputStream {
} }
} }
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
}
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
}
if (len == 0) {
return;
}
checkOpen();
while (len > 0) {
int writeLen = Math.min(CHUNK_SIZE - buffer.position(), len);
int rollbackPosition = buffer.position();
int rollbackLimit = buffer.limit();
buffer.put(b, off, writeLen);
if (buffer.position() == CHUNK_SIZE) {
flushBufferToChunk(rollbackPosition, rollbackLimit);
}
off += writeLen;
len -= writeLen;
}
}
@Override @Override
public synchronized void flush() throws IOException { public synchronized void flush() throws IOException {
checkOpen(); checkOpen();