HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / HRegionLocation.java
blob8f356f1fe774071501355ada24d0c7794afc3cec
1 /**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org.apache.hadoop.hbase;
21 import org.apache.hadoop.hbase.client.RegionInfo;
22 import org.apache.hadoop.hbase.util.Addressing;
23 import org.apache.yetus.audience.InterfaceAudience;
25 /**
26 * Data structure to hold RegionInfo and the address for the hosting
27 * HRegionServer. Immutable. Comparable, but we compare the 'location' only:
28 * i.e. the hostname and port, and *not* the regioninfo. This means two
29 * instances are the same if they refer to the same 'location' (the same
30 * hostname and port), though they may be carrying different regions.
32 * On a big cluster, each client will have thousands of instances of this object, often
33 * 100 000 of them if not million. It's important to keep the object size as small
34 * as possible.
36 * <br>This interface has been marked InterfaceAudience.Public in 0.96 and 0.98.
38 @InterfaceAudience.Public
39 public class HRegionLocation implements Comparable<HRegionLocation> {
40 private final RegionInfo regionInfo;
41 private final ServerName serverName;
42 private final long seqNum;
44 public HRegionLocation(RegionInfo regionInfo, ServerName serverName) {
45 this(regionInfo, serverName, HConstants.NO_SEQNUM);
48 public HRegionLocation(RegionInfo regionInfo, ServerName serverName, long seqNum) {
49 this.regionInfo = regionInfo;
50 this.serverName = serverName;
51 this.seqNum = seqNum;
54 /**
55 * @see java.lang.Object#toString()
57 @Override
58 public String toString() {
59 return "region=" + (this.regionInfo == null ? "null" : this.regionInfo.getRegionNameAsString())
60 + ", hostname=" + this.serverName + ", seqNum=" + seqNum;
63 /**
64 * @see java.lang.Object#equals(java.lang.Object)
66 @Override
67 public boolean equals(Object o) {
68 if (this == o) {
69 return true;
71 if (o == null) {
72 return false;
74 if (!(o instanceof HRegionLocation)) {
75 return false;
77 return this.compareTo((HRegionLocation)o) == 0;
80 /**
81 * @see java.lang.Object#hashCode()
83 @Override
84 public int hashCode() {
85 return this.serverName.hashCode();
88 /**
89 * @return regionInfo
91 public RegionInfo getRegion(){
92 return regionInfo;
95 public String getHostname() {
96 return this.serverName.getHostname();
99 public int getPort() {
100 return this.serverName.getPort();
103 public long getSeqNum() {
104 return seqNum;
108 * @return String made of hostname and port formatted as
109 * per {@link Addressing#createHostAndPortStr(String, int)}
111 public String getHostnamePort() {
112 return Addressing.createHostAndPortStr(this.getHostname(), this.getPort());
115 public ServerName getServerName() {
116 return serverName;
119 @Override
120 public int compareTo(HRegionLocation o) {
121 return serverName.compareTo(o.getServerName());