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 static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertFalse;
022import static org.junit.Assert.assertTrue;
023import static org.junit.Assert.fail;
024
025import java.io.IOException;
026import java.util.ArrayList;
027import java.util.List;
028import java.util.Objects;
029import java.util.concurrent.TimeUnit;
030import java.util.concurrent.atomic.AtomicBoolean;
031import org.apache.commons.lang3.RandomUtils;
032import org.apache.hadoop.conf.Configuration;
033import org.apache.hadoop.fs.FileSystem;
034import org.apache.hadoop.fs.Path;
035import org.apache.hadoop.hbase.HBaseClassTestRule;
036import org.apache.hadoop.hbase.HBaseTestingUtility;
037import org.apache.hadoop.hbase.HConstants;
038import org.apache.hadoop.hbase.MetaTableAccessor;
039import org.apache.hadoop.hbase.MiniHBaseCluster;
040import org.apache.hadoop.hbase.ServerName;
041import org.apache.hadoop.hbase.TableName;
042import org.apache.hadoop.hbase.UnknownRegionException;
043import org.apache.hadoop.hbase.client.Admin;
044import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
045import org.apache.hadoop.hbase.client.DoNotRetryRegionException;
046import org.apache.hadoop.hbase.client.Put;
047import org.apache.hadoop.hbase.client.RegionInfo;
048import org.apache.hadoop.hbase.client.RegionReplicaUtil;
049import org.apache.hadoop.hbase.client.Result;
050import org.apache.hadoop.hbase.client.ResultScanner;
051import org.apache.hadoop.hbase.client.Scan;
052import org.apache.hadoop.hbase.client.Table;
053import org.apache.hadoop.hbase.client.TableDescriptor;
054import org.apache.hadoop.hbase.exceptions.MergeRegionException;
055import org.apache.hadoop.hbase.master.HMaster;
056import org.apache.hadoop.hbase.master.MasterRpcServices;
057import org.apache.hadoop.hbase.master.RegionState;
058import org.apache.hadoop.hbase.master.assignment.AssignmentManager;
059import org.apache.hadoop.hbase.master.assignment.RegionStates;
060import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
061import org.apache.hadoop.hbase.testclassification.LargeTests;
062import org.apache.hadoop.hbase.testclassification.RegionServerTests;
063import org.apache.hadoop.hbase.util.Bytes;
064import org.apache.hadoop.hbase.util.FSUtils;
065import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
066import org.apache.hadoop.hbase.util.Pair;
067import org.apache.hadoop.hbase.util.PairOfSameType;
068import org.apache.hadoop.util.StringUtils;
069import org.apache.zookeeper.KeeperException;
070import org.junit.AfterClass;
071import org.junit.BeforeClass;
072import org.junit.ClassRule;
073import org.junit.Rule;
074import org.junit.Test;
075import org.junit.experimental.categories.Category;
076import org.junit.rules.TestName;
077import org.slf4j.Logger;
078import org.slf4j.LoggerFactory;
079
080import org.apache.hbase.thirdparty.com.google.common.base.Joiner;
081import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
082import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
083
084import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode;
085import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionRequest;
086import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse;
087
088@Category({RegionServerTests.class, LargeTests.class})
089public class TestRegionMergeTransactionOnCluster {
090
091  @ClassRule
092  public static final HBaseClassTestRule CLASS_RULE =
093      HBaseClassTestRule.forClass(TestRegionMergeTransactionOnCluster.class);
094
095  private static final Logger LOG =
096      LoggerFactory.getLogger(TestRegionMergeTransactionOnCluster.class);
097
098  @Rule public TestName name = new TestName();
099
100  private static final int NB_SERVERS = 3;
101
102  private static final byte[] FAMILYNAME = Bytes.toBytes("fam");
103  private static final byte[] QUALIFIER = Bytes.toBytes("q");
104
105  private static byte[] ROW = Bytes.toBytes("testRow");
106  private static final int INITIAL_REGION_NUM = 10;
107  private static final int ROWSIZE = 200;
108  private static byte[][] ROWS = makeN(ROW, ROWSIZE);
109
110  private static int waitTime = 60 * 1000;
111
112  static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
113
114  private static HMaster MASTER;
115  private static Admin ADMIN;
116
117  @BeforeClass
118  public static void beforeAllTests() throws Exception {
119    // Start a cluster
120    TEST_UTIL.startMiniCluster(1, NB_SERVERS, null, MyMaster.class, null);
121    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
122    MASTER = cluster.getMaster();
123    MASTER.balanceSwitch(false);
124    ADMIN = TEST_UTIL.getConnection().getAdmin();
125  }
126
127  @AfterClass
128  public static void afterAllTests() throws Exception {
129    TEST_UTIL.shutdownMiniCluster();
130    if (ADMIN != null) ADMIN.close();
131  }
132
133  @Test
134  public void testWholesomeMerge() throws Exception {
135    LOG.info("Starting " + name.getMethodName());
136    final TableName tableName = TableName.valueOf(name.getMethodName());
137
138    // Create table and load data.
139    Table table = createTableAndLoadData(MASTER, tableName);
140    // Merge 1st and 2nd region
141    mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1,
142        INITIAL_REGION_NUM - 1);
143
144    // Merge 2nd and 3th region
145    PairOfSameType<RegionInfo> mergedRegions =
146      mergeRegionsAndVerifyRegionNum(MASTER, tableName, 1, 2,
147        INITIAL_REGION_NUM - 2);
148
149    verifyRowCount(table, ROWSIZE);
150
151    // Randomly choose one of the two merged regions
152    RegionInfo hri = RandomUtils.nextBoolean() ?
153      mergedRegions.getFirst() : mergedRegions.getSecond();
154    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
155    AssignmentManager am = cluster.getMaster().getAssignmentManager();
156    RegionStates regionStates = am.getRegionStates();
157
158    // We should not be able to assign it again
159    am.assign(hri);
160    assertFalse("Merged region can't be assigned",
161      regionStates.isRegionInTransition(hri));
162
163    // We should not be able to unassign it either
164    am.unassign(hri);
165    assertFalse("Merged region can't be unassigned",
166      regionStates.isRegionInTransition(hri));
167
168    table.close();
169  }
170
171  /**
172   * Not really restarting the master. Simulate it by clear of new region
173   * state since it is not persisted, will be lost after master restarts.
174   */
175  @Test
176  public void testMergeAndRestartingMaster() throws Exception {
177    final TableName tableName = TableName.valueOf(name.getMethodName());
178
179    // Create table and load data.
180    Table table = createTableAndLoadData(MASTER, tableName);
181
182    try {
183      MyMasterRpcServices.enabled.set(true);
184
185      // Merge 1st and 2nd region
186      mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1);
187    } finally {
188      MyMasterRpcServices.enabled.set(false);
189    }
190
191    table.close();
192  }
193
194  @Test
195  public void testCleanMergeReference() throws Exception {
196    LOG.info("Starting " + name.getMethodName());
197    ADMIN.enableCatalogJanitor(false);
198    try {
199      final TableName tableName = TableName.valueOf(name.getMethodName());
200      // Create table and load data.
201      Table table = createTableAndLoadData(MASTER, tableName);
202      // Merge 1st and 2nd region
203      mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1);
204      verifyRowCount(table, ROWSIZE);
205      table.close();
206
207      List<Pair<RegionInfo, ServerName>> tableRegions = MetaTableAccessor
208          .getTableRegionsAndLocations(MASTER.getConnection(), tableName);
209      RegionInfo mergedRegionInfo = tableRegions.get(0).getFirst();
210      TableDescriptor tableDescriptor = MASTER.getTableDescriptors().get(
211          tableName);
212      Result mergedRegionResult = MetaTableAccessor.getRegionResult(
213        MASTER.getConnection(), mergedRegionInfo.getRegionName());
214
215      // contains merge reference in META
216      assertTrue(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,
217          HConstants.MERGEA_QUALIFIER) != null);
218      assertTrue(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,
219          HConstants.MERGEB_QUALIFIER) != null);
220
221      // merging regions' directory are in the file system all the same
222      PairOfSameType<RegionInfo> p = MetaTableAccessor.getMergeRegions(mergedRegionResult);
223      RegionInfo regionA = p.getFirst();
224      RegionInfo regionB = p.getSecond();
225      FileSystem fs = MASTER.getMasterFileSystem().getFileSystem();
226      Path rootDir = MASTER.getMasterFileSystem().getRootDir();
227
228      Path tabledir = FSUtils.getTableDir(rootDir, mergedRegionInfo.getTable());
229      Path regionAdir = new Path(tabledir, regionA.getEncodedName());
230      Path regionBdir = new Path(tabledir, regionB.getEncodedName());
231      assertTrue(fs.exists(regionAdir));
232      assertTrue(fs.exists(regionBdir));
233
234      ColumnFamilyDescriptor[] columnFamilies = tableDescriptor.getColumnFamilies();
235      HRegionFileSystem hrfs = new HRegionFileSystem(
236        TEST_UTIL.getConfiguration(), fs, tabledir, mergedRegionInfo);
237      int count = 0;
238      for(ColumnFamilyDescriptor colFamily : columnFamilies) {
239        count += hrfs.getStoreFiles(colFamily.getName()).size();
240      }
241      ADMIN.compactRegion(mergedRegionInfo.getRegionName());
242      // clean up the merged region store files
243      // wait until merged region have reference file
244      long timeout = System.currentTimeMillis() + waitTime;
245      int newcount = 0;
246      while (System.currentTimeMillis() < timeout) {
247        for(ColumnFamilyDescriptor colFamily : columnFamilies) {
248          newcount += hrfs.getStoreFiles(colFamily.getName()).size();
249        }
250        if(newcount > count) {
251          break;
252        }
253        Thread.sleep(50);
254      }
255      assertTrue(newcount > count);
256      List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster()
257          .getRegionServerThreads();
258      for (RegionServerThread rs : regionServerThreads) {
259        CompactedHFilesDischarger cleaner = new CompactedHFilesDischarger(100, null,
260            rs.getRegionServer(), false);
261        cleaner.chore();
262        Thread.sleep(1000);
263      }
264      while (System.currentTimeMillis() < timeout) {
265        int newcount1 = 0;
266        for(ColumnFamilyDescriptor colFamily : columnFamilies) {
267          newcount1 += hrfs.getStoreFiles(colFamily.getName()).size();
268        }
269        if(newcount1 <= 1) {
270          break;
271        }
272        Thread.sleep(50);
273      }
274      // run CatalogJanitor to clean merge references in hbase:meta and archive the
275      // files of merging regions
276      int cleaned = 0;
277      while (cleaned == 0) {
278        cleaned = ADMIN.runCatalogScan();
279        LOG.debug("catalog janitor returned " + cleaned);
280        Thread.sleep(50);
281        // Cleanup is async so wait till all procedures are done running.
282        ProcedureTestingUtility.waitNoProcedureRunning(
283            TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor());
284      }
285      assertFalse(regionAdir.toString(), fs.exists(regionAdir));
286      assertFalse(regionBdir.toString(), fs.exists(regionBdir));
287      assertTrue(cleaned > 0);
288
289      mergedRegionResult = MetaTableAccessor.getRegionResult(
290        TEST_UTIL.getConnection(), mergedRegionInfo.getRegionName());
291      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,
292          HConstants.MERGEA_QUALIFIER) != null);
293      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,
294          HConstants.MERGEB_QUALIFIER) != null);
295
296    } finally {
297      ADMIN.enableCatalogJanitor(true);
298    }
299  }
300
301  /**
302   * This test tests 1, merging region not online;
303   * 2, merging same two regions; 3, merging unknown regions.
304   * They are in one test case so that we don't have to create
305   * many tables, and these tests are simple.
306   */
307  @Test
308  public void testMerge() throws Exception {
309    LOG.info("Starting " + name.getMethodName());
310    final TableName tableName = TableName.valueOf(name.getMethodName());
311    final Admin admin = TEST_UTIL.getAdmin();
312    final int syncWaitTimeout = 10 * 60000; // 10min
313
314    try {
315      // Create table and load data.
316      Table table = createTableAndLoadData(MASTER, tableName);
317      AssignmentManager am = MASTER.getAssignmentManager();
318      List<RegionInfo> regions = am.getRegionStates().getRegionsOfTable(tableName);
319      // Fake offline one region
320      RegionInfo a = regions.get(0);
321      RegionInfo b = regions.get(1);
322      am.unassign(b);
323      am.offlineRegion(b);
324      try {
325        // Merge offline region. Region a is offline here
326        admin.mergeRegionsAsync(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false)
327                .get(syncWaitTimeout, TimeUnit.MILLISECONDS);
328        fail("Offline regions should not be able to merge");
329      } catch (DoNotRetryRegionException ie) {
330        System.out.println(ie);
331        assertTrue(ie instanceof MergeRegionException);
332      }
333
334      try {
335        // Merge the same region: b and b.
336        admin.mergeRegionsAsync(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true);
337        fail("A region should not be able to merge with itself, even forcifully");
338      } catch (IOException ie) {
339        assertTrue("Exception should mention regions not online",
340          StringUtils.stringifyException(ie).contains("region to itself")
341            && ie instanceof MergeRegionException);
342      }
343
344      try {
345        // Merge unknown regions
346        admin.mergeRegionsAsync(Bytes.toBytes("-f1"), Bytes.toBytes("-f2"), true);
347        fail("Unknown region could not be merged");
348      } catch (IOException ie) {
349        assertTrue("UnknownRegionException should be thrown",
350          ie instanceof UnknownRegionException);
351      }
352      table.close();
353    } finally {
354      TEST_UTIL.deleteTable(tableName);
355    }
356  }
357
358  @Test
359  public void testMergeWithReplicas() throws Exception {
360    final TableName tableName = TableName.valueOf(name.getMethodName());
361    // Create table and load data.
362    createTableAndLoadData(MASTER, tableName, 5, 2);
363    List<Pair<RegionInfo, ServerName>> initialRegionToServers =
364        MetaTableAccessor.getTableRegionsAndLocations(
365            TEST_UTIL.getConnection(), tableName);
366    // Merge 1st and 2nd region
367    PairOfSameType<RegionInfo> mergedRegions = mergeRegionsAndVerifyRegionNum(MASTER, tableName,
368        0, 2, 5 * 2 - 2);
369    List<Pair<RegionInfo, ServerName>> currentRegionToServers =
370        MetaTableAccessor.getTableRegionsAndLocations(
371            TEST_UTIL.getConnection(), tableName);
372    List<RegionInfo> initialRegions = new ArrayList<>();
373    for (Pair<RegionInfo, ServerName> p : initialRegionToServers) {
374      initialRegions.add(p.getFirst());
375    }
376    List<RegionInfo> currentRegions = new ArrayList<>();
377    for (Pair<RegionInfo, ServerName> p : currentRegionToServers) {
378      currentRegions.add(p.getFirst());
379    }
380    assertTrue(initialRegions.contains(mergedRegions.getFirst())); //this is the first region
381    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(
382        mergedRegions.getFirst(), 1))); //this is the replica of the first region
383    assertTrue(initialRegions.contains(mergedRegions.getSecond())); //this is the second region
384    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(
385        mergedRegions.getSecond(), 1))); //this is the replica of the second region
386    assertTrue(!initialRegions.contains(currentRegions.get(0))); //this is the new region
387    assertTrue(!initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(
388        currentRegions.get(0), 1))); //replica of the new region
389    assertTrue(currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(
390        currentRegions.get(0), 1))); //replica of the new region
391    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(
392        mergedRegions.getFirst(), 1))); //replica of the merged region
393    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(
394        mergedRegions.getSecond(), 1))); //replica of the merged region
395  }
396
397  private PairOfSameType<RegionInfo> mergeRegionsAndVerifyRegionNum(
398      HMaster master, TableName tablename,
399      int regionAnum, int regionBnum, int expectedRegionNum) throws Exception {
400    PairOfSameType<RegionInfo> mergedRegions =
401      requestMergeRegion(master, tablename, regionAnum, regionBnum);
402    waitAndVerifyRegionNum(master, tablename, expectedRegionNum);
403    return mergedRegions;
404  }
405
406  private PairOfSameType<RegionInfo> requestMergeRegion(
407      HMaster master, TableName tablename,
408      int regionAnum, int regionBnum) throws Exception {
409    List<Pair<RegionInfo, ServerName>> tableRegions = MetaTableAccessor
410        .getTableRegionsAndLocations(
411            TEST_UTIL.getConnection(), tablename);
412    RegionInfo regionA = tableRegions.get(regionAnum).getFirst();
413    RegionInfo regionB = tableRegions.get(regionBnum).getFirst();
414    ADMIN.mergeRegionsAsync(
415      regionA.getEncodedNameAsBytes(),
416      regionB.getEncodedNameAsBytes(), false);
417    return new PairOfSameType<>(regionA, regionB);
418  }
419
420  private void waitAndVerifyRegionNum(HMaster master, TableName tablename,
421      int expectedRegionNum) throws Exception {
422    List<Pair<RegionInfo, ServerName>> tableRegionsInMeta;
423    List<RegionInfo> tableRegionsInMaster;
424    long timeout = System.currentTimeMillis() + waitTime;
425    while (System.currentTimeMillis() < timeout) {
426      tableRegionsInMeta =
427          MetaTableAccessor.getTableRegionsAndLocations(TEST_UTIL.getConnection(), tablename);
428      tableRegionsInMaster =
429          master.getAssignmentManager().getRegionStates().getRegionsOfTable(tablename);
430      LOG.info(Objects.toString(tableRegionsInMaster));
431      LOG.info(Objects.toString(tableRegionsInMeta));
432      int tableRegionsInMetaSize = tableRegionsInMeta.size();
433      int tableRegionsInMasterSize = tableRegionsInMaster.size();
434      if (tableRegionsInMetaSize == expectedRegionNum
435          && tableRegionsInMasterSize == expectedRegionNum) {
436        break;
437      }
438      Thread.sleep(250);
439    }
440
441    tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(
442        TEST_UTIL.getConnection(), tablename);
443    LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta));
444    assertEquals(expectedRegionNum, tableRegionsInMeta.size());
445  }
446
447  private Table createTableAndLoadData(HMaster master, TableName tablename)
448      throws Exception {
449    return createTableAndLoadData(master, tablename, INITIAL_REGION_NUM, 1);
450  }
451
452  private Table createTableAndLoadData(HMaster master, TableName tablename,
453      int numRegions, int replication) throws Exception {
454    assertTrue("ROWSIZE must > numregions:" + numRegions, ROWSIZE > numRegions);
455    byte[][] splitRows = new byte[numRegions - 1][];
456    for (int i = 0; i < splitRows.length; i++) {
457      splitRows[i] = ROWS[(i + 1) * ROWSIZE / numRegions];
458    }
459
460    Table table = TEST_UTIL.createTable(tablename, FAMILYNAME, splitRows);
461    LOG.info("Created " + table.getName());
462    if (replication > 1) {
463      HBaseTestingUtility.setReplicas(ADMIN, tablename, replication);
464      LOG.info("Set replication of " + replication + " on " + table.getName());
465    }
466    loadData(table);
467    LOG.info("Loaded " + table.getName());
468    verifyRowCount(table, ROWSIZE);
469    LOG.info("Verified " + table.getName());
470
471    List<Pair<RegionInfo, ServerName>> tableRegions;
472    TEST_UTIL.waitUntilAllRegionsAssigned(tablename);
473    LOG.info("All regions assigned for table - " + table.getName());
474    tableRegions = MetaTableAccessor.getTableRegionsAndLocations(
475        TEST_UTIL.getConnection(), tablename);
476    assertEquals("Wrong number of regions in table " + tablename,
477        numRegions * replication, tableRegions.size());
478    LOG.info(tableRegions.size() + "Regions after load: " + Joiner.on(',').join(tableRegions));
479    assertEquals(numRegions * replication, tableRegions.size());
480    return table;
481  }
482
483  private static byte[][] makeN(byte[] base, int n) {
484    byte[][] ret = new byte[n][];
485    for (int i = 0; i < n; i++) {
486      ret[i] = Bytes.add(base, Bytes.toBytes(String.format("%04d", i)));
487    }
488    return ret;
489  }
490
491  private void loadData(Table table) throws IOException {
492    for (int i = 0; i < ROWSIZE; i++) {
493      Put put = new Put(ROWS[i]);
494      put.addColumn(FAMILYNAME, QUALIFIER, Bytes.toBytes(i));
495      table.put(put);
496    }
497  }
498
499  private void verifyRowCount(Table table, int expectedRegionNum)
500      throws IOException {
501    ResultScanner scanner = table.getScanner(new Scan());
502    int rowCount = 0;
503    while (scanner.next() != null) {
504      rowCount++;
505    }
506    assertEquals(expectedRegionNum, rowCount);
507    scanner.close();
508  }
509
510  // Make it public so that JVMClusterUtil can access it.
511  public static class MyMaster extends HMaster {
512    public MyMaster(Configuration conf) throws IOException, KeeperException, InterruptedException {
513      super(conf);
514    }
515
516    @Override
517    protected RSRpcServices createRpcServices() throws IOException {
518      return new MyMasterRpcServices(this);
519    }
520  }
521
522  static class MyMasterRpcServices extends MasterRpcServices {
523    static AtomicBoolean enabled = new AtomicBoolean(false);
524
525    private HMaster myMaster;
526    public MyMasterRpcServices(HMaster master) throws IOException {
527      super(master);
528      myMaster = master;
529    }
530
531    @Override
532    public ReportRegionStateTransitionResponse reportRegionStateTransition(RpcController c,
533        ReportRegionStateTransitionRequest req) throws ServiceException {
534      ReportRegionStateTransitionResponse resp = super.reportRegionStateTransition(c, req);
535      if (enabled.get() && req.getTransition(0).getTransitionCode()
536          == TransitionCode.READY_TO_MERGE && !resp.hasErrorMessage()) {
537        RegionStates regionStates = myMaster.getAssignmentManager().getRegionStates();
538        for (RegionState regionState: regionStates.getRegionsStateInTransition()) {
539          // Find the merging_new region and remove it
540          if (regionState.isMergingNew()) {
541            regionStates.deleteRegion(regionState.getRegion());
542          }
543        }
544      }
545      return resp;
546    }
547  }
548}