/** * Adds a hbase:meta row for each of the specified new regions. Initial state for new regions * is CLOSED. * @param connection connection we're using * @param regionInfos region information list * @param regionReplication * @param ts desired timestamp * @throws IOException if problem connecting or updating meta */ private static void addRegionsToMeta(Connection connection, List<RegionInfo> regionInfos, int regionReplication, long ts) throws IOException { List<Put> puts = new ArrayList<>(); for (RegionInfo regionInfo : regionInfos) { if (RegionReplicaUtil.isDefaultReplica(regionInfo)) { Put put = makePutFromRegionInfo(regionInfo, ts); // New regions are added with initial state of CLOSED. addRegionStateToPut(put, RegionState.State.CLOSED); // Add empty locations for region replicas so that number of replicas can be cached // whenever the primary region is looked up from meta for (int i = 1; i < regionReplication; i++) { addEmptyLocation(put, i); } puts.add(put); } } putsToMetaTable(connection, puts); LOG.info("Added {} regions to meta.", puts.size()); }
Put p = MetaTableAccessor.makePutFromRegionInfo(hri, EnvironmentEdgeManager.currentTime()); puts.add(p);
/** * Puts the specified RegionInfo into META with replica related columns */ public static void fixMetaHoleOnlineAndAddReplicas(Configuration conf, RegionInfo hri, Collection<ServerName> servers, int numReplicas) throws IOException { Connection conn = ConnectionFactory.createConnection(conf); Table meta = conn.getTable(TableName.META_TABLE_NAME); Put put = MetaTableAccessor.makePutFromRegionInfo(hri, EnvironmentEdgeManager.currentTime()); if (numReplicas > 1) { Random r = new Random(); ServerName[] serversArr = servers.toArray(new ServerName[servers.size()]); for (int i = 1; i < numReplicas; i++) { ServerName sn = serversArr[r.nextInt(serversArr.length)]; // the column added here is just to make sure the master is able to // see the additional replicas when it is asked to assign. The // final value of these columns will be different and will be updated // by the actual regionservers that start hosting the respective replicas MetaTableAccessor.addLocation(put, sn, sn.getStartcode(), i); } } meta.put(put); meta.close(); conn.close(); }
/** * Adds daughter region infos to hbase:meta row for the specified region. Note that this does not * add its daughter's as different rows, but adds information about the daughters in the same row * as the parent. Use * {@link #splitRegion(Connection, RegionInfo, long, RegionInfo, RegionInfo, ServerName, int)} * if you want to do that. * @param connection connection we're using * @param regionInfo RegionInfo of parent region * @param splitA first split daughter of the parent regionInfo * @param splitB second split daughter of the parent regionInfo * @throws IOException if problem connecting or updating meta */ public static void addSplitsToParent(Connection connection, RegionInfo regionInfo, RegionInfo splitA, RegionInfo splitB) throws IOException { Table meta = getMetaHTable(connection); try { Put put = makePutFromRegionInfo(regionInfo, EnvironmentEdgeManager.currentTime()); addDaughtersToPut(put, splitA, splitB); meta.put(put); debugLogMutation(put); LOG.debug("Added region {}", regionInfo.getRegionNameAsString()); } finally { meta.close(); } }
long time = EnvironmentEdgeManager.currentTime(); Put putParent = makePutFromRegionInfo(RegionInfoBuilder.newBuilder(parent) .setOffline(true) .setSplit(true).build(), time); Put putA = makePutFromRegionInfo(splitA, time); Put putB = makePutFromRegionInfo(splitB, time); if (parentOpenSeqNum > 0) { addReplicationBarrier(putParent, parentOpenSeqNum);
/** * Generates and returns a Put containing the region info for the catalog table and the servers * @return Put object */ private static Put makePutFromRegionInfo(RegionInfo regionInfo, List<ServerName> favoredNodeList) throws IOException { Put put = null; if (favoredNodeList != null) { long time = EnvironmentEdgeManager.currentTime(); put = MetaTableAccessor.makePutFromRegionInfo(regionInfo, time); byte[] favoredNodes = getFavoredNodes(favoredNodeList); put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(FAVOREDNODES_QUALIFIER) .setTimestamp(time) .setType(Type.Put) .setValue(favoredNodes) .build()); LOG.debug("Create the region {} with favored nodes {}", regionInfo.getRegionNameAsString(), favoredNodeList); } return put; }
/** * Reset the split parent region info in meta table */ private void resetSplitParent(HbckInfo hi) throws IOException { RowMutations mutations = new RowMutations(hi.metaEntry.getRegionName()); Delete d = new Delete(hi.metaEntry.getRegionName()); d.addColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER); d.addColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER); mutations.add(d); RegionInfo hri = RegionInfoBuilder.newBuilder(hi.metaEntry) .setOffline(false) .setSplit(false) .build(); Put p = MetaTableAccessor.makePutFromRegionInfo(hri, EnvironmentEdgeManager.currentTime()); mutations.add(p); meta.mutateRow(mutations); LOG.info("Reset split parent " + hi.metaEntry.getRegionNameAsString() + " in META" ); }
Put putOfMerged = makePutFromRegionInfo(mergedRegion, time); putOfMerged.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(putOfMerged.getRow())
MetaTableAccessor.makePutFromRegionInfo(hri, EnvironmentEdgeManager.currentTime()); put.setDurability(Durability.SKIP_WAL); mr.put(put);
/** * Adds a hbase:meta row for each of the specified new regions. Initial state for new regions * is CLOSED. * @param connection connection we're using * @param regionInfos region information list * @param regionReplication * @param ts desired timestamp * @throws IOException if problem connecting or updating meta */ private static void addRegionsToMeta(Connection connection, List<RegionInfo> regionInfos, int regionReplication, long ts) throws IOException { List<Put> puts = new ArrayList<>(); for (RegionInfo regionInfo : regionInfos) { if (RegionReplicaUtil.isDefaultReplica(regionInfo)) { Put put = makePutFromRegionInfo(regionInfo, ts); // New regions are added with initial state of CLOSED. addRegionStateToPut(put, RegionState.State.CLOSED); // Add empty locations for region replicas so that number of replicas can be cached // whenever the primary region is looked up from meta for (int i = 1; i < regionReplication; i++) { addEmptyLocation(put, i); } puts.add(put); } } putsToMetaTable(connection, puts); LOG.info("Added {} regions to meta.", puts.size()); }
/** * Adds daughter region infos to hbase:meta row for the specified region. Note that this does not * add its daughter's as different rows, but adds information about the daughters in the same row * as the parent. Use * {@link #splitRegion(Connection, RegionInfo, long, RegionInfo, RegionInfo, ServerName, int)} * if you want to do that. * @param connection connection we're using * @param regionInfo RegionInfo of parent region * @param splitA first split daughter of the parent regionInfo * @param splitB second split daughter of the parent regionInfo * @throws IOException if problem connecting or updating meta */ public static void addSplitsToParent(Connection connection, RegionInfo regionInfo, RegionInfo splitA, RegionInfo splitB) throws IOException { Table meta = getMetaHTable(connection); try { Put put = makePutFromRegionInfo(regionInfo, EnvironmentEdgeManager.currentTime()); addDaughtersToPut(put, splitA, splitB); meta.put(put); debugLogMutation(put); LOG.debug("Added region {}", regionInfo.getRegionNameAsString()); } finally { meta.close(); } }
long time = EnvironmentEdgeManager.currentTime(); Put putParent = makePutFromRegionInfo(RegionInfoBuilder.newBuilder(parent) .setOffline(true) .setSplit(true).build(), time); Put putA = makePutFromRegionInfo(splitA, time); Put putB = makePutFromRegionInfo(splitB, time); if (parentOpenSeqNum > 0) { addReplicationBarrier(putParent, parentOpenSeqNum);
/** * Generates and returns a Put containing the region into for the catalog table */ public static Put makePutFromRegionInfo(HRegionInfo regionInfo) throws IOException { return makePutFromRegionInfo(regionInfo, HConstants.LATEST_TIMESTAMP); } /**
Put putOfMerged = makePutFromRegionInfo(mergedRegion, time); putOfMerged.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(putOfMerged.getRow())
/** * Adds a hbase:meta row for the specified new region. * @param connection connection we're using * @param regionInfo region information * @throws IOException if problem connecting or updating meta */ public static void addRegionToMeta(Connection connection, HRegionInfo regionInfo) throws IOException { putToMetaTable(connection, makePutFromRegionInfo(regionInfo)); LOG.info("Added " + regionInfo.getRegionNameAsString()); }
private void offlineParentInMetaAndputMetaEntries(HConnection hConnection, HRegionInfo parent, HRegionInfo splitA, HRegionInfo splitB, ServerName serverName, List<Mutation> metaEntries, int regionReplication) throws IOException { List<Mutation> mutations = metaEntries; HRegionInfo copyOfParent = new HRegionInfo(parent); copyOfParent.setOffline(true); copyOfParent.setSplit(true); //Put for parent Put putParent = MetaTableAccessor.makePutFromRegionInfo(copyOfParent); MetaTableAccessor.addDaughtersToPut(putParent, splitA, splitB); mutations.add(putParent); //Puts for daughters Put putA = MetaTableAccessor.makePutFromRegionInfo(splitA); Put putB = MetaTableAccessor.makePutFromRegionInfo(splitB); addLocation(putA, serverName, 1); //these are new regions, openSeqNum = 1 is fine. addLocation(putB, serverName, 1); mutations.add(putA); mutations.add(putB); // Add empty locations for region replicas of daughters so that number of replicas can be // cached whenever the primary region is looked up from meta for (int i = 1; i < regionReplication; i++) { addEmptyLocation(putA, i); addEmptyLocation(putB, i); } MetaTableAccessor.mutateMetaTable(hConnection, mutations); }
/** * Puts the specified HRegionInfo into META with replica related columns */ public static void fixMetaHoleOnlineAndAddReplicas(Configuration conf, HRegionInfo hri, Collection<ServerName> servers, int numReplicas) throws IOException { Connection conn = ConnectionFactory.createConnection(conf); Table meta = conn.getTable(TableName.META_TABLE_NAME); Put put = MetaTableAccessor.makePutFromRegionInfo(hri); if (numReplicas > 1) { Random r = new Random(); ServerName[] serversArr = servers.toArray(new ServerName[servers.size()]); for (int i = 1; i < numReplicas; i++) { ServerName sn = serversArr[r.nextInt(serversArr.length)]; // the column added here is just to make sure the master is able to // see the additional replicas when it is asked to assign. The // final value of these columns will be different and will be updated // by the actual regionservers that start hosting the respective replicas MetaTableAccessor.addLocation(put, sn, sn.getStartcode(), -1, i); } } meta.put(put); meta.close(); conn.close(); }
/** * Generates and returns a Put containing the region info for the catalog table * and the servers * @param regionInfo * @param favoredNodeList * @return Put object */ static Put makePutFromRegionInfo(HRegionInfo regionInfo, List<ServerName>favoredNodeList) throws IOException { Put put = null; if (favoredNodeList != null) { put = MetaTableAccessor.makePutFromRegionInfo(regionInfo); byte[] favoredNodes = getFavoredNodes(favoredNodeList); put.addImmutable(HConstants.CATALOG_FAMILY, FAVOREDNODES_QUALIFIER, EnvironmentEdgeManager.currentTime(), favoredNodes); LOG.info("Create the region " + regionInfo.getRegionNameAsString() + " with favored nodes " + Bytes.toString(favoredNodes)); } return put; }
/** * Adds a (single) hbase:meta row for the specified new region and its daughters. Note that this * does not add its daughter's as different rows, but adds information about the daughters * in the same row as the parent. Use * {@link #splitRegion(Connection, HRegionInfo, HRegionInfo, HRegionInfo, ServerName, int)} * if you want to do that. * @param meta the Table for META * @param regionInfo region information * @param splitA first split daughter of the parent regionInfo * @param splitB second split daughter of the parent regionInfo * @throws IOException if problem connecting or updating meta */ public static void addRegionToMeta(Table meta, HRegionInfo regionInfo, HRegionInfo splitA, HRegionInfo splitB) throws IOException { Put put = makePutFromRegionInfo(regionInfo); addDaughtersToPut(put, splitA, splitB); meta.put(put); if (LOG.isDebugEnabled()) { LOG.debug("Added " + regionInfo.getRegionNameAsString()); } }
/** * Reset the split parent region info in meta table */ private void resetSplitParent(HbckInfo hi) throws IOException { RowMutations mutations = new RowMutations(hi.metaEntry.getRegionName()); Delete d = new Delete(hi.metaEntry.getRegionName()); d.deleteColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER); d.deleteColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER); mutations.add(d); HRegionInfo hri = new HRegionInfo(hi.metaEntry); hri.setOffline(false); hri.setSplit(false); Put p = MetaTableAccessor.makePutFromRegionInfo(hri); mutations.add(p); meta.mutateRow(mutations); LOG.info("Reset split parent " + hi.metaEntry.getRegionNameAsString() + " in META" ); }