001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.master.normalizer; 020 021import java.io.IOException; 022 023import org.apache.hadoop.hbase.HConstants; 024import org.apache.hadoop.hbase.client.RegionInfo; 025import org.apache.hadoop.hbase.master.MasterServices; 026import org.apache.yetus.audience.InterfaceAudience; 027import org.slf4j.Logger; 028import org.slf4j.LoggerFactory; 029 030/** 031 * Normalization plan to merge regions (smallest region in the table with its smallest neighbor). 032 */ 033@InterfaceAudience.Private 034public class MergeNormalizationPlan implements NormalizationPlan { 035 private static final Logger LOG = LoggerFactory.getLogger(MergeNormalizationPlan.class.getName()); 036 037 private final RegionInfo firstRegion; 038 private final RegionInfo secondRegion; 039 040 public MergeNormalizationPlan(RegionInfo firstRegion, RegionInfo secondRegion) { 041 this.firstRegion = firstRegion; 042 this.secondRegion = secondRegion; 043 } 044 045 /** 046 * {@inheritDoc} 047 */ 048 @Override 049 public long submit(MasterServices masterServices) throws IOException { 050 LOG.info("Executing merging normalization plan: " + this); 051 // Do not use force=true as corner cases can happen, non adjacent regions, 052 // merge with a merged child region with no GC done yet, it is going to 053 // cause all different issues. 054 return masterServices 055 .mergeRegions(new RegionInfo[] { firstRegion, secondRegion }, false, HConstants.NO_NONCE, 056 HConstants.NO_NONCE); 057 } 058 059 @Override 060 public PlanType getType() { 061 return PlanType.MERGE; 062 } 063 064 RegionInfo getFirstRegion() { 065 return firstRegion; 066 } 067 068 RegionInfo getSecondRegion() { 069 return secondRegion; 070 } 071 072 @Override 073 public String toString() { 074 return "MergeNormalizationPlan{" + 075 "firstRegion=" + firstRegion + 076 ", secondRegion=" + secondRegion + 077 '}'; 078 } 079 080}