HBASE-18002 Investigate why bucket cache filling up in file mode in an
exisiting file is slower (Ram)
This commit is contained in:
parent
1049025e1d
commit
381a151d14
|
@ -227,7 +227,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
public BucketCache(String ioEngineName, long capacity, int blockSize, int[] bucketSizes,
|
public BucketCache(String ioEngineName, long capacity, int blockSize, int[] bucketSizes,
|
||||||
int writerThreadNum, int writerQLen, String persistencePath, int ioErrorsTolerationDuration)
|
int writerThreadNum, int writerQLen, String persistencePath, int ioErrorsTolerationDuration)
|
||||||
throws FileNotFoundException, IOException {
|
throws FileNotFoundException, IOException {
|
||||||
this.ioEngine = getIOEngineFromName(ioEngineName, capacity);
|
this.ioEngine = getIOEngineFromName(ioEngineName, capacity, persistencePath);
|
||||||
this.writerThreads = new WriterThread[writerThreadNum];
|
this.writerThreads = new WriterThread[writerThreadNum];
|
||||||
long blockNumCapacity = capacity / blockSize;
|
long blockNumCapacity = capacity / blockSize;
|
||||||
if (blockNumCapacity >= Integer.MAX_VALUE) {
|
if (blockNumCapacity >= Integer.MAX_VALUE) {
|
||||||
|
@ -309,10 +309,11 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
* Get the IOEngine from the IO engine name
|
* Get the IOEngine from the IO engine name
|
||||||
* @param ioEngineName
|
* @param ioEngineName
|
||||||
* @param capacity
|
* @param capacity
|
||||||
|
* @param persistencePath
|
||||||
* @return the IOEngine
|
* @return the IOEngine
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private IOEngine getIOEngineFromName(String ioEngineName, long capacity)
|
private IOEngine getIOEngineFromName(String ioEngineName, long capacity, String persistencePath)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (ioEngineName.startsWith("file:") || ioEngineName.startsWith("files:")) {
|
if (ioEngineName.startsWith("file:") || ioEngineName.startsWith("files:")) {
|
||||||
// In order to make the usage simple, we only need the prefix 'files:' in
|
// In order to make the usage simple, we only need the prefix 'files:' in
|
||||||
|
@ -320,7 +321,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
||||||
// the compatibility
|
// the compatibility
|
||||||
String[] filePaths = ioEngineName.substring(ioEngineName.indexOf(":") + 1)
|
String[] filePaths = ioEngineName.substring(ioEngineName.indexOf(":") + 1)
|
||||||
.split(FileIOEngine.FILE_DELIMITER);
|
.split(FileIOEngine.FILE_DELIMITER);
|
||||||
return new FileIOEngine(capacity, filePaths);
|
return new FileIOEngine(capacity, persistencePath != null, filePaths);
|
||||||
} else if (ioEngineName.startsWith("offheap")) {
|
} else if (ioEngineName.startsWith("offheap")) {
|
||||||
return new ByteBufferIOEngine(capacity, true);
|
return new ByteBufferIOEngine(capacity, true);
|
||||||
} else if (ioEngineName.startsWith("heap")) {
|
} else if (ioEngineName.startsWith("heap")) {
|
||||||
|
|
|
@ -52,11 +52,24 @@ public class FileIOEngine implements IOEngine {
|
||||||
private FileReadAccessor readAccessor = new FileReadAccessor();
|
private FileReadAccessor readAccessor = new FileReadAccessor();
|
||||||
private FileWriteAccessor writeAccessor = new FileWriteAccessor();
|
private FileWriteAccessor writeAccessor = new FileWriteAccessor();
|
||||||
|
|
||||||
public FileIOEngine(long capacity, String... filePaths) throws IOException {
|
public FileIOEngine(long capacity, boolean maintainPersistence, String... filePaths)
|
||||||
|
throws IOException {
|
||||||
this.sizePerFile = capacity / filePaths.length;
|
this.sizePerFile = capacity / filePaths.length;
|
||||||
this.capacity = this.sizePerFile * filePaths.length;
|
this.capacity = this.sizePerFile * filePaths.length;
|
||||||
this.filePaths = filePaths;
|
this.filePaths = filePaths;
|
||||||
this.fileChannels = new FileChannel[filePaths.length];
|
this.fileChannels = new FileChannel[filePaths.length];
|
||||||
|
if (!maintainPersistence) {
|
||||||
|
for (String filePath : filePaths) {
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (file.exists()) {
|
||||||
|
if (LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug("File " + filePath + " already exists. Deleting!!");
|
||||||
|
}
|
||||||
|
file.delete();
|
||||||
|
// If deletion fails still we can manage with the writes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
this.rafs = new RandomAccessFile[filePaths.length];
|
this.rafs = new RandomAccessFile[filePaths.length];
|
||||||
for (int i = 0; i < filePaths.length; i++) {
|
for (int i = 0; i < filePaths.length; i++) {
|
||||||
String filePath = filePaths[i];
|
String filePath = filePaths[i];
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class TestFileIOEngine {
|
||||||
boundaryStopPositions.add(sizePerFile * i + 1);
|
boundaryStopPositions.add(sizePerFile * i + 1);
|
||||||
}
|
}
|
||||||
boundaryStopPositions.add(sizePerFile * filePaths.length - 1);
|
boundaryStopPositions.add(sizePerFile * filePaths.length - 1);
|
||||||
FileIOEngine fileIOEngine = new FileIOEngine(totalCapacity, filePaths);
|
FileIOEngine fileIOEngine = new FileIOEngine(totalCapacity, false, filePaths);
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < 500; i++) {
|
for (int i = 0; i < 500; i++) {
|
||||||
int len = (int) Math.floor(Math.random() * 100);
|
int len = (int) Math.floor(Math.random() * 100);
|
||||||
|
|
Loading…
Reference in New Issue