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
31 /**
32 * An HMaster that runs out of memory.
33 * Everytime a region server reports in, add to the retained heap of memory.
34 * Needs to be started manually as in
35 * <code>${HBASE_HOME}/bin/hbase ./bin/hbase org.apache.hadoop.hbase.OOMEHMaster start/code>.
36 */
37 public class OOMEHMaster extends HMaster {
38 private List<byte []> retainer = new ArrayList<byte[]>();
39
40 public OOMEHMaster(HBaseConfiguration conf) throws IOException {
41 super(conf);
42 }
43
44 @Override
45 public HMsg[] regionServerReport(HServerInfo serverInfo, HMsg[] msgs,
46 HRegionInfo[] mostLoadedRegions)
47 throws IOException {
48 // Retain 1M.
49 this.retainer.add(new byte [1024 * 1024]);
50 return super.regionServerReport(serverInfo, msgs, mostLoadedRegions);
51 }
52
53 /**
54 * @param args
55 */
56 public static void main(String[] args) {
57 doMain(args, OOMEHMaster.class);
58 }
59 }