HBASE-19977 FileMmapEngine allocation of byte buffers should be

synchronized (Ram)
This commit is contained in:
Vasudevan 2018-02-13 15:49:37 +05:30
parent 5b95ea01da
commit 3623089cba
1 changed files with 4 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -69,12 +70,11 @@ public class FileMmapEngine implements IOEngine {
throw ioex; throw ioex;
} }
ByteBufferAllocator allocator = new ByteBufferAllocator() { ByteBufferAllocator allocator = new ByteBufferAllocator() {
int pos = 0; AtomicInteger pos = new AtomicInteger(0);
@Override @Override
public ByteBuffer allocate(long size) throws IOException { public ByteBuffer allocate(long size) throws IOException {
ByteBuffer buffer = fileChannel.map(java.nio.channels.FileChannel.MapMode.READ_WRITE, ByteBuffer buffer = fileChannel.map(java.nio.channels.FileChannel.MapMode.READ_WRITE,
pos * size, size); pos.getAndIncrement() * size, size);
pos++;
return buffer; return buffer;
} }
}; };