Addendum HBASE-17522 missed some branch-1 specific direct uses of MemoryMXBean

This commit is contained in:
Sean Busbey 2017-02-01 11:15:20 -06:00
parent 3d4639f34d
commit fab0b2e603
3 changed files with 18 additions and 7 deletions

View File

@ -18,7 +18,7 @@
*/ */
package org.apache.hadoop.hbase.regionserver; package org.apache.hadoop.hbase.regionserver;
import java.lang.management.ManagementFactory; import java.lang.management.MemoryUsage;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
@ -203,7 +203,11 @@ public class MemStoreChunkPool {
if (poolSizePercentage > 1.0) { if (poolSizePercentage > 1.0) {
throw new IllegalArgumentException(CHUNK_POOL_MAXSIZE_KEY + " must be between 0.0 and 1.0"); throw new IllegalArgumentException(CHUNK_POOL_MAXSIZE_KEY + " must be between 0.0 and 1.0");
} }
long heapMax = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax(); long heapMax = -1L;
final MemoryUsage usage = HeapMemorySizeUtil.safeGetHeapMemoryUsage();
if (usage != null) {
heapMax = usage.getMax();
}
long globalMemStoreLimit = (long) (heapMax * HeapMemorySizeUtil.getGlobalMemStorePercent(conf, long globalMemStoreLimit = (long) (heapMax * HeapMemorySizeUtil.getGlobalMemStorePercent(conf,
false)); false));
int chunkSize = conf.getInt(HeapMemStoreLAB.CHUNK_SIZE_KEY, int chunkSize = conf.getInt(HeapMemStoreLAB.CHUNK_SIZE_KEY,

View File

@ -22,7 +22,7 @@ import static org.apache.hadoop.util.StringUtils.humanReadableInt;
import java.io.IOException; import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler; import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.management.ManagementFactory; import java.lang.management.MemoryUsage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.HashMap; import java.util.HashMap;
@ -110,7 +110,11 @@ class MemStoreFlusher implements FlushRequester {
this.server = server; this.server = server;
this.threadWakeFrequency = this.threadWakeFrequency =
conf.getLong(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000); conf.getLong(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000);
long max = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax(); long max = -1L;
final MemoryUsage usage = HeapMemorySizeUtil.safeGetHeapMemoryUsage();
if (usage != null) {
max = usage.getMax();
}
float globalMemStorePercent = HeapMemorySizeUtil.getGlobalMemStorePercent(conf, true); float globalMemStorePercent = HeapMemorySizeUtil.getGlobalMemStorePercent(conf, true);
this.globalMemStoreLimit = (long) (max * globalMemStorePercent); this.globalMemStoreLimit = (long) (max * globalMemStorePercent);
this.globalMemStoreLimitLowMarkPercent = this.globalMemStoreLimitLowMarkPercent =

View File

@ -23,7 +23,6 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage; import java.lang.management.MemoryUsage;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -574,8 +573,12 @@ public class FSHLog implements WAL {
} }
private int calculateMaxLogFiles(float memstoreSizeRatio, long logRollSize) { private int calculateMaxLogFiles(float memstoreSizeRatio, long logRollSize) {
MemoryUsage mu = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long max = -1L;
int maxLogs = Math.round(mu.getMax() * memstoreSizeRatio * 2 / logRollSize); final MemoryUsage usage = HeapMemorySizeUtil.safeGetHeapMemoryUsage();
if (usage != null) {
max = usage.getMax();
}
int maxLogs = Math.round(max * memstoreSizeRatio * 2 / logRollSize);
return maxLogs; return maxLogs;
} }