Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6F85B18DEB for ; Mon, 2 Nov 2015 03:51:31 +0000 (UTC) Received: (qmail 14727 invoked by uid 500); 2 Nov 2015 03:51:31 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 14693 invoked by uid 500); 2 Nov 2015 03:51:31 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 14622 invoked by uid 99); 2 Nov 2015 03:51:31 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Nov 2015 03:51:31 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 9C63BC0FF9 for ; Mon, 2 Nov 2015 03:51:30 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.99 X-Spam-Level: X-Spam-Status: No, score=0.99 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id lmAc43cenaWr for ; Mon, 2 Nov 2015 03:51:11 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 7AB5023039 for ; Mon, 2 Nov 2015 03:51:11 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 16209E0FC8 for ; Mon, 2 Nov 2015 03:51:10 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 1537F3A078D for ; Mon, 2 Nov 2015 03:51:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1711891 [21/50] - in /hbase/hbase.apache.org/trunk: ./ apidocs/ apidocs/org/apache/hadoop/hbase/ apidocs/org/apache/hadoop/hbase/class-use/ apidocs/org/apache/hadoop/hbase/client/ apidocs/org/apache/hadoop/hbase/client/class-use/ apidocs/o... Date: Mon, 02 Nov 2015 03:51:05 -0000 To: commits@hbase.apache.org From: misty@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151102035110.1537F3A078D@svn01-us-west.apache.org> Modified: hbase/hbase.apache.org/trunk/devapidocs/src-html/org/apache/hadoop/hbase/MetaTableAccessor.Visitor.html URL: http://svn.apache.org/viewvc/hbase/hbase.apache.org/trunk/devapidocs/src-html/org/apache/hadoop/hbase/MetaTableAccessor.Visitor.html?rev=1711891&r1=1711890&r2=1711891&view=diff ============================================================================== --- hbase/hbase.apache.org/trunk/devapidocs/src-html/org/apache/hadoop/hbase/MetaTableAccessor.Visitor.html (original) +++ hbase/hbase.apache.org/trunk/devapidocs/src-html/org/apache/hadoop/hbase/MetaTableAccessor.Visitor.html Mon Nov 2 03:51:02 2015 @@ -310,7 +310,7 @@ 302 parsedInfo = parseRegionInfoFromRegionName(regionName); 303 row = getMetaKeyForRegion(parsedInfo); 304 } catch (Exception parseEx) { -305 // Ignore. This is used with tableName passed as regionName. +305 ; // Ignore. This is used with tableName passed as regionName. 306 } 307 Get get = new Get(row); 308 get.addFamily(HConstants.CATALOG_FAMILY); @@ -927,1070 +927,1063 @@ 919 * @return A ServerName instance or null if necessary fields not found or empty. 920 */ 921 @Nullable -922 private static ServerName getServerName(final Result r, final int replicaId) { -923 byte[] serverColumn = getServerColumn(replicaId); -924 Cell cell = r.getColumnLatestCell(getCatalogFamily(), serverColumn); -925 if (cell == null || cell.getValueLength() == 0) return null; -926 String hostAndPort = Bytes.toString( -927 cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); -928 byte[] startcodeColumn = getStartCodeColumn(replicaId); -929 cell = r.getColumnLatestCell(getCatalogFamily(), startcodeColumn); -930 if (cell == null || cell.getValueLength() == 0) return null; -931 return ServerName.valueOf(hostAndPort, -932 Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); -933 } -934 -935 /** -936 * The latest seqnum that the server writing to meta observed when opening the region. -937 * E.g. the seqNum when the result of {@link #getServerName(Result, int)} was written. -938 * @param r Result to pull the seqNum from -939 * @return SeqNum, or HConstants.NO_SEQNUM if there's no value written. -940 */ -941 private static long getSeqNumDuringOpen(final Result r, final int replicaId) { -942 Cell cell = r.getColumnLatestCell(getCatalogFamily(), getSeqNumColumn(replicaId)); -943 if (cell == null || cell.getValueLength() == 0) return HConstants.NO_SEQNUM; -944 return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); -945 } -946 -947 /** -948 * Returns an HRegionLocationList extracted from the result. -949 * @return an HRegionLocationList containing all locations for the region range or null if -950 * we can't deserialize the result. -951 */ -952 @Nullable -953 public static RegionLocations getRegionLocations(final Result r) { -954 if (r == null) return null; -955 HRegionInfo regionInfo = getHRegionInfo(r, getRegionInfoColumn()); -956 if (regionInfo == null) return null; -957 -958 List<HRegionLocation> locations = new ArrayList<HRegionLocation>(1); -959 NavigableMap<byte[],NavigableMap<byte[],byte[]>> familyMap = r.getNoVersionMap(); -960 -961 locations.add(getRegionLocation(r, regionInfo, 0)); -962 -963 NavigableMap<byte[], byte[]> infoMap = familyMap.get(getCatalogFamily()); -964 if (infoMap == null) return new RegionLocations(locations); -965 -966 // iterate until all serverName columns are seen -967 int replicaId = 0; -968 byte[] serverColumn = getServerColumn(replicaId); -969 SortedMap<byte[], byte[]> serverMap = infoMap.tailMap(serverColumn, false); -970 if (serverMap.isEmpty()) return new RegionLocations(locations); +922 @InterfaceAudience.Private // for use by HMaster#getTableRegionRow which is used for testing only +923 public static ServerName getServerName(final Result r, final int replicaId) { +924 byte[] serverColumn = getServerColumn(replicaId); +925 Cell cell = r.getColumnLatestCell(getCatalogFamily(), serverColumn); +926 if (cell == null || cell.getValueLength() == 0) return null; +927 String hostAndPort = Bytes.toString( +928 cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); +929 byte[] startcodeColumn = getStartCodeColumn(replicaId); +930 cell = r.getColumnLatestCell(getCatalogFamily(), startcodeColumn); +931 if (cell == null || cell.getValueLength() == 0) return null; +932 try { +933 return ServerName.valueOf(hostAndPort, +934 Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); +935 } catch (IllegalArgumentException e) { +936 LOG.error("Ignoring invalid region for server " + hostAndPort + "; cell=" + cell, e); +937 return null; +938 } +939 } +940 +941 /** +942 * The latest seqnum that the server writing to meta observed when opening the region. +943 * E.g. the seqNum when the result of {@link #getServerName(Result, int)} was written. +944 * @param r Result to pull the seqNum from +945 * @return SeqNum, or HConstants.NO_SEQNUM if there's no value written. +946 */ +947 private static long getSeqNumDuringOpen(final Result r, final int replicaId) { +948 Cell cell = r.getColumnLatestCell(getCatalogFamily(), getSeqNumColumn(replicaId)); +949 if (cell == null || cell.getValueLength() == 0) return HConstants.NO_SEQNUM; +950 return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); +951 } +952 +953 /** +954 * Returns an HRegionLocationList extracted from the result. +955 * @return an HRegionLocationList containing all locations for the region range or null if +956 * we can't deserialize the result. +957 */ +958 @Nullable +959 public static RegionLocations getRegionLocations(final Result r) { +960 if (r == null) return null; +961 HRegionInfo regionInfo = getHRegionInfo(r, getRegionInfoColumn()); +962 if (regionInfo == null) return null; +963 +964 List<HRegionLocation> locations = new ArrayList<HRegionLocation>(1); +965 NavigableMap<byte[],NavigableMap<byte[],byte[]>> familyMap = r.getNoVersionMap(); +966 +967 locations.add(getRegionLocation(r, regionInfo, 0)); +968 +969 NavigableMap<byte[], byte[]> infoMap = familyMap.get(getCatalogFamily()); +970 if (infoMap == null) return new RegionLocations(locations); 971 -972 for (Map.Entry<byte[], byte[]> entry : serverMap.entrySet()) { -973 replicaId = parseReplicaIdFromServerColumn(entry.getKey()); -974 if (replicaId < 0) { -975 break; -976 } -977 HRegionLocation location = getRegionLocation(r, regionInfo, replicaId); -978 // In case the region replica is newly created, it's location might be null. We usually do not -979 // have HRL's in RegionLocations object with null ServerName. They are handled as null HRLs. -980 if (location == null || location.getServerName() == null) { -981 locations.add(null); -982 } else { -983 locations.add(location); -984 } -985 } -986 -987 return new RegionLocations(locations); -988 } -989 -990 /** -991 * Returns the HRegionLocation parsed from the given meta row Result -992 * for the given regionInfo and replicaId. The regionInfo can be the default region info -993 * for the replica. -994 * @param r the meta row result -995 * @param regionInfo RegionInfo for default replica -996 * @param replicaId the replicaId for the HRegionLocation -997 * @return HRegionLocation parsed from the given meta row Result for the given replicaId -998 */ -999 private static HRegionLocation getRegionLocation(final Result r, final HRegionInfo regionInfo, -1000 final int replicaId) { -1001 ServerName serverName = getServerName(r, replicaId); -1002 long seqNum = getSeqNumDuringOpen(r, replicaId); -1003 HRegionInfo replicaInfo = RegionReplicaUtil.getRegionInfoForReplica(regionInfo, replicaId); -1004 return new HRegionLocation(replicaInfo, serverName, seqNum); -1005 } -1006 -1007 /** -1008 * Returns HRegionInfo object from the column -1009 * HConstants.CATALOG_FAMILY:HConstants.REGIONINFO_QUALIFIER of the catalog -1010 * table Result. -1011 * @param data a Result object from the catalog table scan -1012 * @return HRegionInfo or null -1013 */ -1014 public static HRegionInfo getHRegionInfo(Result data) { -1015 return getHRegionInfo(data, HConstants.REGIONINFO_QUALIFIER); -1016 } -1017 -1018 /** -1019 * Returns the HRegionInfo object from the column {@link HConstants#CATALOG_FAMILY} and -1020 * <code>qualifier</code> of the catalog table result. -1021 * @param r a Result object from the catalog table scan -1022 * @param qualifier Column family qualifier -1023 * @return An HRegionInfo instance or null. -1024 */ -1025 @Nullable -1026 private static HRegionInfo getHRegionInfo(final Result r, byte [] qualifier) { -1027 Cell cell = r.getColumnLatestCell(getCatalogFamily(), qualifier); -1028 if (cell == null) return null; -1029 return HRegionInfo.parseFromOrNull(cell.getValueArray(), -1030 cell.getValueOffset(), cell.getValueLength()); -1031 } -1032 -1033 /** -1034 * Returns the daughter regions by reading the corresponding columns of the catalog table -1035 * Result. -1036 * @param data a Result object from the catalog table scan -1037 * @return a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split -1038 * parent -1039 */ -1040 public static PairOfSameType<HRegionInfo> getDaughterRegions(Result data) { -1041 HRegionInfo splitA = getHRegionInfo(data, HConstants.SPLITA_QUALIFIER); -1042 HRegionInfo splitB = getHRegionInfo(data, HConstants.SPLITB_QUALIFIER); -1043 -1044 return new PairOfSameType<HRegionInfo>(splitA, splitB); -1045 } -1046 -1047 /** -1048 * Returns the merge regions by reading the corresponding columns of the catalog table -1049 * Result. -1050 * @param data a Result object from the catalog table scan -1051 * @return a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split -1052 * parent -1053 */ -1054 public static PairOfSameType<HRegionInfo> getMergeRegions(Result data) { -1055 HRegionInfo mergeA = getHRegionInfo(data, HConstants.MERGEA_QUALIFIER); -1056 HRegionInfo mergeB = getHRegionInfo(data, HConstants.MERGEB_QUALIFIER); -1057 -1058 return new PairOfSameType<HRegionInfo>(mergeA, mergeB); -1059 } -1060 -1061 /** -1062 * Fetch table state for given table from META table -1063 * @param conn connection to use -1064 * @param tableName table to fetch state for -1065 * @return state -1066 * @throws IOException -1067 */ -1068 @Nullable -1069 public static TableState getTableState(Connection conn, TableName tableName) -1070 throws IOException { -1071 Table metaHTable = getMetaHTable(conn); -1072 Get get = new Get(tableName.getName()).addColumn(getTableFamily(), getStateColumn()); -1073 long time = EnvironmentEdgeManager.currentTime(); -1074 get.setTimeRange(0, time); -1075 Result result = -1076 metaHTable.get(get); -1077 return getTableState(result); -1078 } -1079 -1080 /** -1081 * Fetch table states from META table -1082 * @param conn connection to use -1083 * @return map {tableName -&gt; state} -1084 * @throws IOException -1085 */ -1086 public static Map<TableName, TableState> getTableStates(Connection conn) -1087 throws IOException { -1088 final Map<TableName, TableState> states = new LinkedHashMap<>(); -1089 Visitor collector = new Visitor() { -1090 @Override -1091 public boolean visit(Result r) throws IOException { -1092 TableState state = getTableState(r); -1093 if (state != null) -1094 states.put(state.getTableName(), state); -1095 return true; -1096 } -1097 }; -1098 fullScanTables(conn, collector); -1099 return states; -1100 } -1101 -1102 /** -1103 * Updates state in META -1104 * @param conn connection to use -1105 * @param tableName table to look for -1106 * @throws IOException -1107 */ -1108 public static void updateTableState(Connection conn, TableName tableName, -1109 TableState.State actual) throws IOException { -1110 updateTableState(conn, new TableState(tableName, actual)); -1111 } -1112 -1113 /** -1114 * Decode table state from META Result. -1115 * Should contain cell from HConstants.TABLE_FAMILY -1116 * @param r result -1117 * @return null if not found -1118 * @throws IOException -1119 */ -1120 @Nullable -1121 public static TableState getTableState(Result r) -1122 throws IOException { -1123 Cell cell = r.getColumnLatestCell(getTableFamily(), getStateColumn()); -1124 if (cell == null) return null; -1125 try { -1126 return TableState.parseFrom(TableName.valueOf(r.getRow()), -1127 Arrays.copyOfRange(cell.getValueArray(), -1128 cell.getValueOffset(), cell.getValueOffset() + cell.getValueLength())); -1129 } catch (DeserializationException e) { -1130 throw new IOException(e); -1131 } -1132 -1133 } -1134 -1135 /** -1136 * Implementations 'visit' a catalog table row. -1137 */ -1138 public interface Visitor { -1139 /** -1140 * Visit the catalog table row. -1141 * @param r A row from catalog table -1142 * @return True if we are to proceed scanning the table, else false if -1143 * we are to stop now. -1144 */ -1145 boolean visit(final Result r) throws IOException; -1146 } -1147 -1148 /** -1149 * Implementations 'visit' a catalog table row but with close() at the end. -1150 */ -1151 public interface CloseableVisitor extends Visitor, Closeable { +972 // iterate until all serverName columns are seen +973 int replicaId = 0; +974 byte[] serverColumn = getServerColumn(replicaId); +975 SortedMap<byte[], byte[]> serverMap = infoMap.tailMap(serverColumn, false); +976 if (serverMap.isEmpty()) return new RegionLocations(locations); +977 +978 for (Map.Entry<byte[], byte[]> entry : serverMap.entrySet()) { +979 replicaId = parseReplicaIdFromServerColumn(entry.getKey()); +980 if (replicaId < 0) { +981 break; +982 } +983 HRegionLocation location = getRegionLocation(r, regionInfo, replicaId); +984 // In case the region replica is newly created, it's location might be null. We usually do not +985 // have HRL's in RegionLocations object with null ServerName. They are handled as null HRLs. +986 if (location == null || location.getServerName() == null) { +987 locations.add(null); +988 } else { +989 locations.add(location); +990 } +991 } +992 +993 return new RegionLocations(locations); +994 } +995 +996 /** +997 * Returns the HRegionLocation parsed from the given meta row Result +998 * for the given regionInfo and replicaId. The regionInfo can be the default region info +999 * for the replica. +1000 * @param r the meta row result +1001 * @param regionInfo RegionInfo for default replica +1002 * @param replicaId the replicaId for the HRegionLocation +1003 * @return HRegionLocation parsed from the given meta row Result for the given replicaId +1004 */ +1005 private static HRegionLocation getRegionLocation(final Result r, final HRegionInfo regionInfo, +1006 final int replicaId) { +1007 ServerName serverName = getServerName(r, replicaId); +1008 long seqNum = getSeqNumDuringOpen(r, replicaId); +1009 HRegionInfo replicaInfo = RegionReplicaUtil.getRegionInfoForReplica(regionInfo, replicaId); +1010 return new HRegionLocation(replicaInfo, serverName, seqNum); +1011 } +1012 +1013 /** +1014 * Returns HRegionInfo object from the column +1015 * HConstants.CATALOG_FAMILY:HConstants.REGIONINFO_QUALIFIER of the catalog +1016 * table Result. +1017 * @param data a Result object from the catalog table scan +1018 * @return HRegionInfo or null +1019 */ +1020 public static HRegionInfo getHRegionInfo(Result data) { +1021 return getHRegionInfo(data, HConstants.REGIONINFO_QUALIFIER); +1022 } +1023 +1024 /** +1025 * Returns the HRegionInfo object from the column {@link HConstants#CATALOG_FAMILY} and +1026 * <code>qualifier</code> of the catalog table result. +1027 * @param r a Result object from the catalog table scan +1028 * @param qualifier Column family qualifier +1029 * @return An HRegionInfo instance or null. +1030 */ +1031 @Nullable +1032 private static HRegionInfo getHRegionInfo(final Result r, byte [] qualifier) { +1033 Cell cell = r.getColumnLatestCell(getCatalogFamily(), qualifier); +1034 if (cell == null) return null; +1035 return HRegionInfo.parseFromOrNull(cell.getValueArray(), +1036 cell.getValueOffset(), cell.getValueLength()); +1037 } +1038 +1039 /** +1040 * Returns the daughter regions by reading the corresponding columns of the catalog table +1041 * Result. +1042 * @param data a Result object from the catalog table scan +1043 * @return a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split +1044 * parent +1045 */ +1046 public static PairOfSameType<HRegionInfo> getDaughterRegions(Result data) { +1047 HRegionInfo splitA = getHRegionInfo(data, HConstants.SPLITA_QUALIFIER); +1048 HRegionInfo splitB = getHRegionInfo(data, HConstants.SPLITB_QUALIFIER); +1049 +1050 return new PairOfSameType<HRegionInfo>(splitA, splitB); +1051 } +1052 +1053 /** +1054 * Returns the merge regions by reading the corresponding columns of the catalog table +1055 * Result. +1056 * @param data a Result object from the catalog table scan +1057 * @return a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split +1058 * parent +1059 */ +1060 public static PairOfSameType<HRegionInfo> getMergeRegions(Result data) { +1061 HRegionInfo mergeA = getHRegionInfo(data, HConstants.MERGEA_QUALIFIER); +1062 HRegionInfo mergeB = getHRegionInfo(data, HConstants.MERGEB_QUALIFIER); +1063 +1064 return new PairOfSameType<HRegionInfo>(mergeA, mergeB); +1065 } +1066 +1067 /** +1068 * Fetch table state for given table from META table +1069 * @param conn connection to use +1070 * @param tableName table to fetch state for +1071 * @return state +1072 * @throws IOException +1073 */ +1074 @Nullable +1075 public static TableState getTableState(Connection conn, TableName tableName) +1076 throws IOException { +1077 Table metaHTable = getMetaHTable(conn); +1078 Get get = new Get(tableName.getName()).addColumn(getTableFamily(), getStateColumn()); +1079 long time = EnvironmentEdgeManager.currentTime(); +1080 get.setTimeRange(0, time); +1081 Result result = +1082 metaHTable.get(get); +1083 return getTableState(result); +1084 } +1085 +1086 /** +1087 * Fetch table states from META table +1088 * @param conn connection to use +1089 * @return map {tableName -&gt; state} +1090 * @throws IOException +1091 */ +1092 public static Map<TableName, TableState> getTableStates(Connection conn) +1093 throws IOException { +1094 final Map<TableName, TableState> states = new LinkedHashMap<>(); +1095 Visitor collector = new Visitor() { +1096 @Override +1097 public boolean visit(Result r) throws IOException { +1098 TableState state = getTableState(r); +1099 if (state != null) +1100 states.put(state.getTableName(), state); +1101 return true; +1102 } +1103 }; +1104 fullScanTables(conn, collector); +1105 return states; +1106 } +1107 +1108 /** +1109 * Updates state in META +1110 * @param conn connection to use +1111 * @param tableName table to look for +1112 * @throws IOException +1113 */ +1114 public static void updateTableState(Connection conn, TableName tableName, +1115 TableState.State actual) throws IOException { +1116 updateTableState(conn, new TableState(tableName, actual)); +1117 } +1118 +1119 /** +1120 * Decode table state from META Result. +1121 * Should contain cell from HConstants.TABLE_FAMILY +1122 * @param r result +1123 * @return null if not found +1124 * @throws IOException +1125 */ +1126 @Nullable +1127 public static TableState getTableState(Result r) +1128 throws IOException { +1129 Cell cell = r.getColumnLatestCell(getTableFamily(), getStateColumn()); +1130 if (cell == null) return null; +1131 try { +1132 return TableState.parseFrom(TableName.valueOf(r.getRow()), +1133 Arrays.copyOfRange(cell.getValueArray(), +1134 cell.getValueOffset(), cell.getValueOffset() + cell.getValueLength())); +1135 } catch (DeserializationException e) { +1136 throw new IOException(e); +1137 } +1138 +1139 } +1140 +1141 /** +1142 * Implementations 'visit' a catalog table row. +1143 */ +1144 public interface Visitor { +1145 /** +1146 * Visit the catalog table row. +1147 * @param r A row from catalog table +1148 * @return True if we are to proceed scanning the table, else false if +1149 * we are to stop now. +1150 */ +1151 boolean visit(final Result r) throws IOException; 1152 } 1153 1154 /** -1155 * A {@link Visitor} that collects content out of passed {@link Result}. +1155 * Implementations 'visit' a catalog table row but with close() at the end. 1156 */ -1157 static abstract class CollectingVisitor<T> implements Visitor { -1158 final List<T> results = new ArrayList<T>(); -1159 @Override -1160 public boolean visit(Result r) throws IOException { -1161 if (r == null || r.isEmpty()) return true; -1162 add(r); -1163 return true; -1164 } -1165 -1166 abstract void add(Result r); -1167 -1168 /** -1169 * @return Collected results; wait till visits complete to collect all -1170 * possible results -1171 */ -1172 List<T> getResults() { -1173 return this.results; -1174 } -1175 } -1176 -1177 /** -1178 * Collects all returned. -1179 */ -1180 static class CollectAllVisitor extends CollectingVisitor<Result> { -1181 @Override -1182 void add(Result r) { -1183 this.results.add(r); -1184 } -1185 } -1186 -1187 /** -1188 * A Visitor that skips offline regions and split parents -1189 */ -1190 public static abstract class DefaultVisitorBase implements Visitor { -1191 -1192 public DefaultVisitorBase() { -1193 super(); -1194 } -1195 -1196 public abstract boolean visitInternal(Result rowResult) throws IOException; +1157 public interface CloseableVisitor extends Visitor, Closeable { +1158 } +1159 +1160 /** +1161 * A {@link Visitor} that collects content out of passed {@link Result}. +1162 */ +1163 static abstract class CollectingVisitor<T> implements Visitor { +1164 final List<T> results = new ArrayList<T>(); +1165 @Override +1166 public boolean visit(Result r) throws IOException { +1167 if (r == null || r.isEmpty()) return true; +1168 add(r); +1169 return true; +1170 } +1171 +1172 abstract void add(Result r); +1173 +1174 /** +1175 * @return Collected results; wait till visits complete to collect all +1176 * possible results +1177 */ +1178 List<T> getResults() { +1179 return this.results; +1180 } +1181 } +1182 +1183 /** +1184 * Collects all returned. +1185 */ +1186 static class CollectAllVisitor extends CollectingVisitor<Result> { +1187 @Override +1188 void add(Result r) { +1189 this.results.add(r); +1190 } +1191 } +1192 +1193 /** +1194 * A Visitor that skips offline regions and split parents +1195 */ +1196 public static abstract class DefaultVisitorBase implements Visitor { 1197 -1198 @Override -1199 public boolean visit(Result rowResult) throws IOException { -1200 HRegionInfo info = getHRegionInfo(rowResult); -1201 if (info == null) { -1202 return true; -1203 } -1204 -1205 //skip over offline and split regions -1206 if (!(info.isOffline() || info.isSplit())) { -1207 return visitInternal(rowResult); -1208 } -1209 return true; -1210 } -1211 } -1212 -1213 /** -1214 * A Visitor for a table. Provides a consistent view of the table's -1215 * hbase:meta entries during concurrent splits (see HBASE-5986 for details). This class -1216 * does not guarantee ordered traversal of meta entries, and can block until the -1217 * hbase:meta entries for daughters are available during splits. -1218 */ -1219 public static abstract class TableVisitorBase extends DefaultVisitorBase { -1220 private TableName tableName; -1221 -1222 public TableVisitorBase(TableName tableName) { -1223 super(); -1224 this.tableName = tableName; -1225 } -1226 -1227 @Override -1228 public final boolean visit(Result rowResult) throws IOException { -1229 HRegionInfo info = getHRegionInfo(rowResult); -1230 if (info == null) { -1231 return true; -1232 } -1233 if (!(info.getTable().equals(tableName))) { -1234 return false; -1235 } -1236 return super.visit(rowResult); -1237 } -1238 } -1239 -1240 /** -1241 * Count regions in <code>hbase:meta</code> for passed table. -1242 * @param c Configuration object -1243 * @param tableName table name to count regions for -1244 * @return Count or regions in table <code>tableName</code> -1245 * @throws IOException -1246 */ -1247 @Deprecated -1248 public static int getRegionCount(final Configuration c, final String tableName) -1249 throws IOException { -1250 return getRegionCount(c, TableName.valueOf(tableName)); -1251 } -1252 -1253 /** -1254 * Count regions in <code>hbase:meta</code> for passed table. -1255 * @param c Configuration object -1256 * @param tableName table name to count regions for -1257 * @return Count or regions in table <code>tableName</code> -1258 * @throws IOException -1259 */ -1260 public static int getRegionCount(final Configuration c, final TableName tableName) -1261 throws IOException { -1262 try (Connection connection = ConnectionFactory.createConnection(c)) { -1263 return getRegionCount(connection, tableName); -1264 } -1265 } -1266 -1267 /** -1268 * Count regions in <code>hbase:meta</code> for passed table. -1269 * @param connection Connection object -1270 * @param tableName table name to count regions for -1271 * @return Count or regions in table <code>tableName</code> -1272 * @throws IOException -1273 */ -1274 public static int getRegionCount(final Connection connection, final TableName tableName) -1275 throws IOException { -1276 try (RegionLocator locator = connection.getRegionLocator(tableName)) { -1277 List<HRegionLocation> locations = locator.getAllRegionLocations(); -1278 return locations == null? 0: locations.size(); -1279 } -1280 } -1281 -1282 //////////////////////// -1283 // Editing operations // -1284 //////////////////////// -1285 -1286 /** -1287 * Generates and returns a Put containing the region into for the catalog table -1288 */ -1289 public static Put makePutFromRegionInfo(HRegionInfo regionInfo) -1290 throws IOException { -1291 return makePutFromRegionInfo(regionInfo, EnvironmentEdgeManager.currentTime()); -1292 } -1293 -1294 /** -1295 * Generates and returns a Put containing the region into for the catalog table -1296 */ -1297 public static Put makePutFromRegionInfo(HRegionInfo regionInfo, long ts) -1298 throws IOException { -1299 Put put = new Put(regionInfo.getRegionName(), ts); -1300 addRegionInfo(put, regionInfo); -1301 return put; -1302 } -1303 -1304 /** -1305 * Generates and returns a Delete containing the region info for the catalog -1306 * table -1307 */ -1308 public static Delete makeDeleteFromRegionInfo(HRegionInfo regionInfo) { -1309 long now = EnvironmentEdgeManager.currentTime(); -1310 return makeDeleteFromRegionInfo(regionInfo, now); -1311 } -1312 -1313 /** -1314 * Generates and returns a Delete containing the region info for the catalog -1315 * table -1316 */ -1317 public static Delete makeDeleteFromRegionInfo(HRegionInfo regionInfo, long ts) { -1318 if (regionInfo == null) { -1319 throw new IllegalArgumentException("Can't make a delete for null region"); -1320 } -1321 Delete delete = new Delete(regionInfo.getRegionName()); -1322 delete.addFamily(getCatalogFamily(), ts); -1323 return delete; -1324 } -1325 -1326 /** -1327 * Adds split daughters to the Put -1328 */ -1329 public static Put addDaughtersToPut(Put put, HRegionInfo splitA, HRegionInfo splitB) { -1330 if (splitA != null) { -1331 put.addImmutable( -1332 HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER, splitA.toByteArray()); -1333 } -1334 if (splitB != null) { -1335 put.addImmutable( -1336 HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER, splitB.toByteArray()); -1337 } -1338 return put; -1339 } -1340 -1341 /** -1342 * Put the passed <code>p</code> to the <code>hbase:meta</code> table. -1343 * @param connection connection we're using -1344 * @param p Put to add to hbase:meta -1345 * @throws IOException -1346 */ -1347 static void putToMetaTable(final Connection connection, final Put p) -1348 throws IOException { -1349 put(getMetaHTable(connection), p); -1350 } -1351 -1352 /** -1353 * @param t Table to use (will be closed when done). -1354 * @param p put to make -1355 * @throws IOException -1356 */ -1357 private static void put(final Table t, final Put p) throws IOException { -1358 try { -1359 if (METALOG.isDebugEnabled()) { -1360 METALOG.debug(mutationToString(p)); -1361 } -1362 t.put(p); -1363 } finally { -1364 t.close(); -1365 } -1366 } -1367 -1368 /** -1369 * Put the passed <code>ps</code> to the <code>hbase:meta</code> table. -1370 * @param connection connection we're using -1371 * @param ps Put to add to hbase:meta -1372 * @throws IOException -1373 */ -1374 public static void putsToMetaTable(final Connection connection, final List<Put> ps) -1375 throws IOException { -1376 Table t = getMetaHTable(connection); -1377 try { -1378 if (METALOG.isDebugEnabled()) { -1379 METALOG.debug(mutationsToString(ps)); -1380 } -1381 t.put(ps); -1382 } finally { -1383 t.close(); -1384 } -1385 } -1386 -1387 /** -1388 * Delete the passed <code>d</code> from the <code>hbase:meta</code> table. -1389 * @param connection connection we're using -1390 * @param d Delete to add to hbase:meta -1391 * @throws IOException -1392 */ -1393 static void deleteFromMetaTable(final Connection connection, final Delete d) -1394 throws IOException { -1395 List<Delete> dels = new ArrayList<Delete>(1); -1396 dels.add(d); -1397 deleteFromMetaTable(connection, dels); -1398 } -1399 -1400 /** -1401 * Delete the passed <code>deletes</code> from the <code>hbase:meta</code> table. -1402 * @param connection connection we're using -1403 * @param deletes Deletes to add to hbase:meta This list should support #remove. -1404 * @throws IOException -1405 */ -1406 public static void deleteFromMetaTable(final Connection connection, final List<Delete> deletes) -1407 throws IOException { -1408 Table t = getMetaHTable(connection); -1409 try { -1410 if (METALOG.isDebugEnabled()) { -1411 METALOG.debug(mutationsToString(deletes)); -1412 } -1413 t.delete(deletes); -1414 } finally { -1415 t.close(); -1416 } -1417 } -1418 -1419 /** -1420 * Deletes some replica columns corresponding to replicas for the passed rows -1421 * @param metaRows rows in hbase:meta -1422 * @param replicaIndexToDeleteFrom the replica ID we would start deleting from -1423 * @param numReplicasToRemove how many replicas to remove -1424 * @param connection connection we're using to access meta table -1425 * @throws IOException -1426 */ -1427 public static void removeRegionReplicasFromMeta(Set<byte[]> metaRows, -1428 int replicaIndexToDeleteFrom, int numReplicasToRemove, Connection connection) -1429 throws IOException { -1430 int absoluteIndex = replicaIndexToDeleteFrom + numReplicasToRemove; -1431 for (byte[] row : metaRows) { -1432 long now = EnvironmentEdgeManager.currentTime(); -1433 Delete deleteReplicaLocations = new Delete(row); -1434 for (int i = replicaIndexToDeleteFrom; i < absoluteIndex; i++) { -1435 deleteReplicaLocations.addColumns(getCatalogFamily(), -1436 getServerColumn(i), now); -1437 deleteReplicaLocations.addColumns(getCatalogFamily(), -1438 getSeqNumColumn(i), now); -1439 deleteReplicaLocations.addColumns(getCatalogFamily(), -1440 getStartCodeColumn(i), now); -1441 } -1442 deleteFromMetaTable(connection, deleteReplicaLocations); -1443 } -1444 } -1445 -1446 /** -1447 * Execute the passed <code>mutations</code> against <code>hbase:meta</code> table. -1448 * @param connection connection we're using -1449 * @param mutations Puts and Deletes to execute on hbase:meta -1450 * @throws IOException -1451 */ -1452 public static void mutateMetaTable(final Connection connection, -1453 final List<Mutation> mutations) -1454 throws IOException { -1455 Table t = getMetaHTable(connection); -1456 try { -1457 if (METALOG.isDebugEnabled()) { -1458 METALOG.debug(mutationsToString(mutations)); -1459 } -1460 t.batch(mutations, null); -1461 } catch (InterruptedException e) { -1462 InterruptedIOException ie = new InterruptedIOException(e.getMessage()); -1463 ie.initCause(e); -1464 throw ie; -1465 } finally { -1466 t.close(); -1467 } -1468 } -1469 -1470 /** -1471 * Adds a hbase:meta row for the specified new region. -1472 * @param connection connection we're using -1473 * @param regionInfo region information -1474 * @throws IOException if problem connecting or updating meta -1475 */ -1476 public static void addRegionToMeta(Connection connection, -1477 HRegionInfo regionInfo) -1478 throws IOException { -1479 putToMetaTable(connection, makePutFromRegionInfo(regionInfo)); -1480 LOG.info("Added " + regionInfo.getRegionNameAsString()); -1481 } -1482 -1483 /** -1484 * Adds a hbase:meta row for the specified new region to the given catalog table. The -1485 * Table is not flushed or closed. -1486 * @param meta the Table for META -1487 * @param regionInfo region information -1488 * @throws IOException if problem connecting or updating meta -1489 */ -1490 public static void addRegionToMeta(Table meta, HRegionInfo regionInfo) throws IOException { -1491 addRegionToMeta(meta, regionInfo, null, null); -1492 } -1493 -1494 /** -1495 * Adds a (single) hbase:meta row for the specified new region and its daughters. Note that this -1496 * does not add its daughter's as different rows, but adds information about the daughters -1497 * in the same row as the parent. Use -1498 * {@link #splitRegion(Connection, HRegionInfo, HRegionInfo, HRegionInfo, ServerName, int)} -1499 * if you want to do that. -1500 * @param meta the Table for META -1501 * @param regionInfo region information -1502 * @param splitA first split daughter of the parent regionInfo -1503 * @param splitB second split daughter of the parent regionInfo -1504 * @throws IOException if problem connecting or updating meta -1505 */ -1506 public static void addRegionToMeta(Table meta, HRegionInfo regionInfo, -1507 HRegionInfo splitA, HRegionInfo splitB) throws IOException { -1508 Put put = makePutFromRegionInfo(regionInfo); -1509 addDaughtersToPut(put, splitA, splitB); -1510 meta.put(put); -1511 if (METALOG.isDebugEnabled()) { -1512 METALOG.debug(mutationToString(put)); -1513 } -1514 if (LOG.isDebugEnabled()) { -1515 LOG.debug("Added " + regionInfo.getRegionNameAsString()); -1516 } -1517 } -1518 -1519 /** -1520 * Adds a (single) hbase:meta row for the specified new region and its daughters. Note that this -1521 * does not add its daughter's as different rows, but adds information about the daughters -1522 * in the same row as the parent. Use -1523 * {@link #splitRegion(Connection, HRegionInfo, HRegionInfo, HRegionInfo, ServerName, int)} -1524 * if you want to do that. -1525 * @param connection connection we're using -1526 * @param regionInfo region information -1527 * @param splitA first split daughter of the parent regionInfo -1528 * @param splitB second split daughter of the parent regionInfo -1529 * @throws IOException if problem connecting or updating meta -1530 */ -1531 public static void addRegionToMeta(Connection connection, HRegionInfo regionInfo, -1532 HRegionInfo splitA, HRegionInfo splitB) throws IOException { -1533 Table meta = getMetaHTable(connection); -1534 try { -1535 addRegionToMeta(meta, regionInfo, splitA, splitB); -1536 } finally { -1537 meta.close(); -1538 } -1539 } -1540 -1541 /** [... 1221 lines stripped ...]