001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver; 019 020import java.io.IOException; 021import java.util.ArrayList; 022import java.util.List; 023import org.apache.hadoop.hbase.HBaseConfiguration; 024import org.apache.hadoop.hbase.client.Put; 025 026import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; 027import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter; 028import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest; 029 030/** 031 * A region server that will OOME. Everytime {@link #put(byte[], Put)} is called, we add keep around 032 * a reference to the batch. Use this class to test OOME extremes. Needs to be started manually as 033 * in 034 * <code>${HBASE_HOME}/bin/hbase ./bin/hbase org.apache.hadoop.hbase.OOMERegionServer start</code>. 035 */ 036public class OOMERegionServer extends HRegionServer { 037 private List<Put> retainer = new ArrayList<>(); 038 039 public OOMERegionServer(HBaseConfiguration conf) throws IOException, InterruptedException { 040 super(conf); 041 } 042 043 public void put(byte[] regionName, Put put) throws IOException { 044 try { 045 MutateRequest request = RequestConverter.buildMutateRequest(regionName, put); 046 rpcServices.mutate(null, request); 047 for (int i = 0; i < 30; i++) { 048 // Add the batch update 30 times to bring on the OOME faster. 049 this.retainer.add(put); 050 } 051 } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException e) { 052 throw ProtobufUtil.handleRemoteException(e); 053 } 054 } 055 056 public static void main(String[] args) { 057 new HRegionServerCommandLine(OOMERegionServer.class).doMain(args); 058 } 059}