1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.master.normalizer;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.hbase.HRegionInfo;
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.client.Admin;
26
27 import java.io.IOException;
28
29
30
31
32 @InterfaceAudience.Private
33 public class MergeNormalizationPlan implements NormalizationPlan {
34 private static final Log LOG = LogFactory.getLog(MergeNormalizationPlan.class.getName());
35
36 private final HRegionInfo firstRegion;
37 private final HRegionInfo secondRegion;
38
39 public MergeNormalizationPlan(HRegionInfo firstRegion, HRegionInfo secondRegion) {
40 this.firstRegion = firstRegion;
41 this.secondRegion = secondRegion;
42 }
43
44 @Override
45 public PlanType getType() {
46 return PlanType.MERGE;
47 }
48
49 HRegionInfo getFirstRegion() {
50 return firstRegion;
51 }
52
53 HRegionInfo getSecondRegion() {
54 return secondRegion;
55 }
56
57 @Override
58 public String toString() {
59 return "MergeNormalizationPlan{" +
60 "firstRegion=" + firstRegion +
61 ", secondRegion=" + secondRegion +
62 '}';
63 }
64
65
66
67
68 @Override
69 public void execute(Admin admin) {
70 LOG.info("Executing merging normalization plan: " + this);
71 try {
72 admin.mergeRegions(firstRegion.getEncodedNameAsBytes(),
73 secondRegion.getEncodedNameAsBytes(), true);
74 } catch (IOException ex) {
75 LOG.error("Error during region merge: ", ex);
76 }
77 }
78 }