HBASE-22768 Revert to MPIR 2.9 (#433)
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / master / RegionPlan.java
blobf4d6e63771aab4a34d3ea3cece368f40f3db29a0
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.master;
20 import java.io.Serializable;
21 import java.util.Comparator;
23 import org.apache.hadoop.hbase.ServerName;
24 import org.apache.hadoop.hbase.client.RegionInfo;
25 import org.apache.yetus.audience.InterfaceAudience;
26 import org.apache.yetus.audience.InterfaceStability;
28 /**
29 * Stores the plan for the move of an individual region.
31 * Contains info for the region being moved, info for the server the region
32 * should be moved from, and info for the server the region should be moved
33 * to.
35 * The comparable implementation of this class compares only the region
36 * information and not the source/dest server info.
38 @InterfaceAudience.LimitedPrivate("Coprocessors")
39 @InterfaceStability.Evolving
40 public class RegionPlan implements Comparable<RegionPlan> {
41 private final RegionInfo hri;
42 private final ServerName source;
43 private ServerName dest;
45 public static class RegionPlanComparator implements Comparator<RegionPlan>, Serializable {
46 private static final long serialVersionUID = 4213207330485734853L;
48 @Override
49 public int compare(RegionPlan l, RegionPlan r) {
50 return RegionPlan.compareTo(l, r);
54 /**
55 * Instantiate a plan for a region move, moving the specified region from
56 * the specified source server to the specified destination server.
58 * Destination server can be instantiated as null and later set
59 * with {@link #setDestination(ServerName)}.
61 * @param hri region to be moved
62 * @param source regionserver region should be moved from
63 * @param dest regionserver region should be moved to
65 public RegionPlan(final RegionInfo hri, ServerName source, ServerName dest) {
66 this.hri = hri;
67 this.source = source;
68 this.dest = dest;
71 /**
72 * Set the destination server for the plan for this region.
74 public void setDestination(ServerName dest) {
75 this.dest = dest;
78 /**
79 * Get the source server for the plan for this region.
80 * @return server info for source
82 public ServerName getSource() {
83 return source;
86 /**
87 * Get the destination server for the plan for this region.
88 * @return server info for destination
90 public ServerName getDestination() {
91 return dest;
94 /**
95 * Get the encoded region name for the region this plan is for.
96 * @return Encoded region name
98 public String getRegionName() {
99 return this.hri.getEncodedName();
102 public RegionInfo getRegionInfo() {
103 return this.hri;
107 * Compare the region info.
108 * @param other region plan you are comparing against
110 @Override
111 public int compareTo(RegionPlan other) {
112 return compareTo(this, other);
115 private static int compareTo(RegionPlan left, RegionPlan right) {
116 int result = compareServerName(left.source, right.source);
117 if (result != 0) {
118 return result;
120 if (left.hri == null) {
121 if (right.hri != null) {
122 return -1;
124 } else if (right.hri == null) {
125 return +1;
126 } else {
127 result = RegionInfo.COMPARATOR.compare(left.hri, right.hri);
129 if (result != 0) {
130 return result;
132 return compareServerName(left.dest, right.dest);
135 private static int compareServerName(ServerName left, ServerName right) {
136 if (left == null) {
137 return right == null? 0: -1;
138 } else if (right == null) {
139 return +1;
141 return left.compareTo(right);
144 @Override
145 public int hashCode() {
146 final int prime = 31;
147 int result = 1;
148 result = prime * result + ((dest == null) ? 0 : dest.hashCode());
149 result = prime * result + ((hri == null) ? 0 : hri.hashCode());
150 result = prime * result + ((source == null) ? 0 : source.hashCode());
151 return result;
154 @Override
155 public boolean equals(Object obj) {
156 if (this == obj) {
157 return true;
159 if (obj == null) {
160 return false;
162 if (getClass() != obj.getClass()) {
163 return false;
165 RegionPlan other = (RegionPlan) obj;
166 if (dest == null) {
167 if (other.dest != null) {
168 return false;
170 } else if (!dest.equals(other.dest)) {
171 return false;
173 if (hri == null) {
174 if (other.hri != null) {
175 return false;
177 } else if (!hri.equals(other.hri)) {
178 return false;
180 if (source == null) {
181 if (other.source != null) {
182 return false;
184 } else if (!source.equals(other.source)) {
185 return false;
187 return true;
190 @Override
191 public String toString() {
192 return "hri=" + this.hri.getEncodedName() + ", source=" +
193 (this.source == null? "": this.source.toString()) +
194 ", destination=" + (this.dest == null? "": this.dest.toString());