1 /** 2 * Copyright 2007 The Apache Software Foundation 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package org.apache.hadoop.hbase.master; 21 22 import java.io.IOException; 23 import java.util.ArrayList; 24 import java.util.List; 25 26 import org.apache.hadoop.hbase.HBaseConfiguration; 27 import org.apache.hadoop.hbase.HMsg; 28 import org.apache.hadoop.hbase.HRegionInfo; 29 import org.apache.hadoop.hbase.HServerInfo; 30 import org.apache.zookeeper.KeeperException; 31 32 /** 33 * An HMaster that runs out of memory. 34 * Everytime a region server reports in, add to the retained heap of memory. 35 * Needs to be started manually as in 36 * <code>${HBASE_HOME}/bin/hbase ./bin/hbase org.apache.hadoop.hbase.OOMEHMaster start/code>. 37 */ 38 public class OOMEHMaster extends HMaster { 39 private List<byte []> retainer = new ArrayList<byte[]>(); 40 41 public OOMEHMaster(HBaseConfiguration conf) 42 throws IOException, KeeperException, InterruptedException { 43 super(conf); 44 } 45 46 @Override 47 public HMsg[] regionServerReport(HServerInfo serverInfo, HMsg[] msgs, 48 HRegionInfo[] mostLoadedRegions) 49 throws IOException { 50 // Retain 1M. 51 this.retainer.add(new byte [1024 * 1024]); 52 return super.regionServerReport(serverInfo, msgs, mostLoadedRegions); 53 } 54 55 public static void main(String[] args) throws Exception { 56 new HMasterCommandLine(OOMEHMaster.class).doMain(args); 57 } 58 }