Java Code Examples for org.apache.hadoop.hbase.client.RegionInfo#DEFAULT_REPLICA_ID
The following examples show how to use
org.apache.hadoop.hbase.client.RegionInfo#DEFAULT_REPLICA_ID .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HRegionFileSystem.java From hbase with Apache License 2.0 | 6 votes |
/** * Create a new Region on file-system. * @param conf the {@link Configuration} to use * @param fs {@link FileSystem} from which to add the region * @param tableDir {@link Path} to where the table is being stored * @param regionInfo {@link RegionInfo} for region to be added * @throws IOException if the region creation fails due to a FileSystem exception. */ public static HRegionFileSystem createRegionOnFileSystem(final Configuration conf, final FileSystem fs, final Path tableDir, final RegionInfo regionInfo) throws IOException { HRegionFileSystem regionFs = new HRegionFileSystem(conf, fs, tableDir, regionInfo); // We only create a .regioninfo and the region directory if this is the default region replica if (regionInfo.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { Path regionDir = regionFs.getRegionDir(); if (fs.exists(regionDir)) { LOG.warn("Trying to create a region that already exists on disk: " + regionDir); } else { // Create the region directory if (!createDirOnFileSystem(fs, conf, regionDir)) { LOG.warn("Unable to create the region directory: " + regionDir); throw new IOException("Unable to create region directory: " + regionDir); } } // Write HRI to a file in case we need to recover hbase:meta regionFs.writeRegionInfoOnFilesystem(false); } else { if (LOG.isDebugEnabled()) LOG.debug("Skipping creation of .regioninfo file for " + regionInfo); } return regionFs; }
Example 2
Source File: HbckTableInfo.java From hbase with Apache License 2.0 | 6 votes |
public void addRegionInfo(HbckRegionInfo hir) { if (Bytes.equals(hir.getEndKey(), HConstants.EMPTY_END_ROW)) { // end key is absolute end key, just add it. // ignore replicas other than primary for these checks if (hir.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { sc.add(hir); } return; } // if not the absolute end key, check for cycle if (Bytes.compareTo(hir.getStartKey(), hir.getEndKey()) > 0) { hbck.getErrors().reportError(HbckErrorReporter.ERROR_CODE.REGION_CYCLE, String.format( "The endkey for this region comes before the " + "startkey, startkey=%s, endkey=%s", Bytes.toStringBinary(hir.getStartKey()), Bytes.toStringBinary(hir.getEndKey())), this, hir); backwards.add(hir); return; } // main case, add to split calculator // ignore replicas other than primary for these checks if (hir.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { sc.add(hir); } }
Example 3
Source File: HBaseFsck.java From hbase with Apache License 2.0 | 6 votes |
private void undeployRegions(HbckRegionInfo hi) throws IOException, InterruptedException { undeployRegionsForHbi(hi); // undeploy replicas of the region (but only if the method is invoked for the primary) if (hi.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID) { return; } int numReplicas = admin.getDescriptor(hi.getTableName()).getRegionReplication(); for (int i = 1; i < numReplicas; i++) { if (hi.getPrimaryHRIForDeployedReplica() == null) continue; RegionInfo hri = RegionReplicaUtil.getRegionInfoForReplica( hi.getPrimaryHRIForDeployedReplica(), i); HbckRegionInfo h = regionInfoMap.get(hri.getEncodedName()); if (h != null) { undeployRegionsForHbi(h); //set skip checks; we undeployed it, and we don't want to evaluate this anymore //in consistency checks h.setSkipChecks(true); } } }
Example 4
Source File: HBaseFsck.java From hbase with Apache License 2.0 | 5 votes |
private void tryAssignmentRepair(HbckRegionInfo hbi, String msg) throws IOException, KeeperException, InterruptedException { // If we are trying to fix the errors if (shouldFixAssignments()) { errors.print(msg); undeployRegions(hbi); setShouldRerun(); RegionInfo hri = hbi.getHdfsHRI(); if (hri == null) { hri = hbi.getMetaEntry().getRegionInfo(); } HBaseFsckRepair.fixUnassigned(admin, hri); HBaseFsckRepair.waitUntilAssigned(admin, hri); // also assign replicas if needed (do it only when this call operates on a primary replica) if (hbi.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID) return; int replicationCount = admin.getDescriptor(hri.getTable()).getRegionReplication(); for (int i = 1; i < replicationCount; i++) { hri = RegionReplicaUtil.getRegionInfoForReplica(hri, i); HbckRegionInfo h = regionInfoMap.get(hri.getEncodedName()); if (h != null) { undeployRegions(h); //set skip checks; we undeploy & deploy it; we don't want to evaluate this hbi anymore //in consistency checks h.setSkipChecks(true); } HBaseFsckRepair.fixUnassigned(admin, hri); HBaseFsckRepair.waitUntilAssigned(admin, hri); } } }
Example 5
Source File: MetaTableLocator.java From hbase with Apache License 2.0 | 5 votes |
public static void deleteMetaLocation(ZKWatcher zookeeper, int replicaId) throws KeeperException { if (replicaId == RegionInfo.DEFAULT_REPLICA_ID) { LOG.info("Deleting hbase:meta region location in ZooKeeper"); } else { LOG.info("Deleting hbase:meta for {} region location in ZooKeeper", replicaId); } try { // Just delete the node. Don't need any watches. ZKUtil.deleteNode(zookeeper, zookeeper.getZNodePaths().getZNodeForReplica(replicaId)); } catch(KeeperException.NoNodeException nne) { // Has already been deleted } }
Example 6
Source File: MetaTableLocator.java From hbase with Apache License 2.0 | 5 votes |
/** * Sets the location of <code>hbase:meta</code> in ZooKeeper to the specified server address. * @param zookeeper reference to the {@link ZKWatcher} which also contains configuration and * operation * @param serverName the name of the server * @param replicaId the ID of the replica * @param state the state of the region * @throws KeeperException if a ZooKeeper operation fails */ public static void setMetaLocation(ZKWatcher zookeeper, ServerName serverName, int replicaId, RegionState.State state) throws KeeperException { if (serverName == null) { LOG.warn("Tried to set null ServerName in hbase:meta; skipping -- ServerName required"); return; } LOG.info("Setting hbase:meta (replicaId={}) location in ZooKeeper as {}", replicaId, serverName); // Make the MetaRegionServer pb and then get its bytes and save this as // the znode content. MetaRegionServer pbrsr = MetaRegionServer.newBuilder() .setServer(ProtobufUtil.toServerName(serverName)) .setRpcVersion(HConstants.RPC_CURRENT_VERSION) .setState(state.convert()).build(); byte[] data = ProtobufUtil.prependPBMagic(pbrsr.toByteArray()); try { ZKUtil.setData(zookeeper, zookeeper.getZNodePaths().getZNodeForReplica(replicaId), data); } catch(KeeperException.NoNodeException nne) { if (replicaId == RegionInfo.DEFAULT_REPLICA_ID) { LOG.debug("META region location doesn't exist, create it"); } else { LOG.debug("META region location doesn't exist for replicaId=" + replicaId + ", create it"); } ZKUtil.createAndWatch(zookeeper, zookeeper.getZNodePaths().getZNodeForReplica(replicaId), data); } }
Example 7
Source File: HRegionFileSystem.java From hbase with Apache License 2.0 | 5 votes |
/** * Open Region from file-system. * @param conf the {@link Configuration} to use * @param fs {@link FileSystem} from which to add the region * @param tableDir {@link Path} to where the table is being stored * @param regionInfo {@link RegionInfo} for region to be added * @param readOnly True if you don't want to edit the region data * @throws IOException if the region creation fails due to a FileSystem exception. */ public static HRegionFileSystem openRegionFromFileSystem(final Configuration conf, final FileSystem fs, final Path tableDir, final RegionInfo regionInfo, boolean readOnly) throws IOException { HRegionFileSystem regionFs = new HRegionFileSystem(conf, fs, tableDir, regionInfo); Path regionDir = regionFs.getRegionDir(); if (!fs.exists(regionDir)) { LOG.warn("Trying to open a region that do not exists on disk: " + regionDir); throw new IOException("The specified region do not exists on disk: " + regionDir); } if (!readOnly) { // Cleanup temporary directories regionFs.cleanupTempDir(); regionFs.cleanupSplitsDir(); regionFs.cleanupMergesDir(); // If it doesn't exists, Write HRI to a file, in case we need to recover hbase:meta // Only create HRI if we are the default replica if (regionInfo.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { regionFs.checkRegionInfoOnFilesystem(); } else { if (LOG.isDebugEnabled()) { LOG.debug("Skipping creation of .regioninfo file for " + regionInfo); } } } return regionFs; }
Example 8
Source File: WALFactory.java From hbase with Apache License 2.0 | 5 votes |
/** * @param region the region which we want to get a WAL for it. Could be null. */ public WAL getWAL(RegionInfo region) throws IOException { // use different WAL for hbase:meta if (region != null && region.isMetaRegion() && region.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { return getMetaProvider().getWAL(region); } else { return provider.getWAL(region); } }
Example 9
Source File: RecoverMetaProcedure.java From hbase with Apache License 2.0 | 5 votes |
@Override protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { super.deserializeStateData(serializer); MasterProcedureProtos.RecoverMetaStateData state = serializer.deserialize(MasterProcedureProtos.RecoverMetaStateData.class); this.shouldSplitWal = state.hasShouldSplitWal() && state.getShouldSplitWal(); this.failedMetaServer = state.hasFailedMetaServer() ? ProtobufUtil.toServerName(state.getFailedMetaServer()) : null; this.replicaId = state.hasReplicaId() ? state.getReplicaId() : RegionInfo.DEFAULT_REPLICA_ID; }
Example 10
Source File: WALSplitUtil.java From hbase with Apache License 2.0 | 5 votes |
/** * Check whether there is recovered.edits in the region dir * @param conf conf * @param regionInfo the region to check * @return true if recovered.edits exist in the region dir */ public static boolean hasRecoveredEdits(final Configuration conf, final RegionInfo regionInfo) throws IOException { // No recovered.edits for non default replica regions if (regionInfo.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID) { return false; } // Only default replica region can reach here, so we can use regioninfo // directly without converting it to default replica's regioninfo. Path regionWALDir = CommonFSUtils.getWALRegionDir(conf, regionInfo.getTable(), regionInfo.getEncodedName()); Path regionDir = FSUtils.getRegionDirFromRootDir(CommonFSUtils.getRootDir(conf), regionInfo); Path wrongRegionWALDir = CommonFSUtils.getWrongWALRegionDir(conf, regionInfo.getTable(), regionInfo.getEncodedName()); FileSystem walFs = CommonFSUtils.getWALFileSystem(conf); FileSystem rootFs = CommonFSUtils.getRootDirFileSystem(conf); NavigableSet<Path> files = getSplitEditFilesSorted(walFs, regionWALDir); if (!files.isEmpty()) { return true; } files = getSplitEditFilesSorted(rootFs, regionDir); if (!files.isEmpty()) { return true; } files = getSplitEditFilesSorted(walFs, wrongRegionWALDir); return !files.isEmpty(); }
Example 11
Source File: HBaseFsck.java From hbase with Apache License 2.0 | 4 votes |
/** * Attempts to undeploy a region from a region server based in information in * META. Any operations that modify the file system should make sure that * its corresponding region is not deployed to prevent data races. * * A separate call is required to update the master in-memory region state * kept in the AssignementManager. Because disable uses this state instead of * that found in META, we can't seem to cleanly disable/delete tables that * have been hbck fixed. When used on a version of HBase that does not have * the offline ipc call exposed on the master (<0.90.5, <0.92.0) a master * restart or failover may be required. */ void closeRegion(HbckRegionInfo hi) throws IOException, InterruptedException { if (hi.getMetaEntry() == null && hi.getHdfsEntry() == null) { undeployRegions(hi); return; } // get assignment info and hregioninfo from meta. Get get = new Get(hi.getRegionName()); get.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); get.addColumn(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER); get.addColumn(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER); // also get the locations of the replicas to close if the primary region is being closed if (hi.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { int numReplicas = admin.getDescriptor(hi.getTableName()).getRegionReplication(); for (int i = 0; i < numReplicas; i++) { get.addColumn(HConstants.CATALOG_FAMILY, CatalogFamilyFormat.getServerColumn(i)); get.addColumn(HConstants.CATALOG_FAMILY, CatalogFamilyFormat.getStartCodeColumn(i)); } } Result r = meta.get(get); RegionLocations rl = CatalogFamilyFormat.getRegionLocations(r); if (rl == null) { LOG.warn("Unable to close region " + hi.getRegionNameAsString() + " since meta does not have handle to reach it"); return; } for (HRegionLocation h : rl.getRegionLocations()) { ServerName serverName = h.getServerName(); if (serverName == null) { errors.reportError("Unable to close region " + hi.getRegionNameAsString() + " because meta does not " + "have handle to reach it."); continue; } RegionInfo hri = h.getRegion(); if (hri == null) { LOG.warn("Unable to close region " + hi.getRegionNameAsString() + " because hbase:meta had invalid or missing " + HConstants.CATALOG_FAMILY_STR + ":" + Bytes.toString(HConstants.REGIONINFO_QUALIFIER) + " qualifier value."); continue; } // close the region -- close files and remove assignment HBaseFsckRepair.closeRegionSilentlyAndWait(connection, serverName, hri); } }
Example 12
Source File: HBaseFsck.java From hbase with Apache License 2.0 | 4 votes |
/** * Scan hbase:meta, adding all regions found to the regionInfo map. * @throws IOException if an error is encountered */ boolean loadMetaEntries() throws IOException { ClientMetaTableAccessor.Visitor visitor = new ClientMetaTableAccessor.Visitor() { int countRecord = 1; // comparator to sort KeyValues with latest modtime final Comparator<Cell> comp = new Comparator<Cell>() { @Override public int compare(Cell k1, Cell k2) { return Long.compare(k1.getTimestamp(), k2.getTimestamp()); } }; @Override public boolean visit(Result result) throws IOException { try { // record the latest modification of this META record long ts = Collections.max(result.listCells(), comp).getTimestamp(); RegionLocations rl = CatalogFamilyFormat.getRegionLocations(result); if (rl == null) { emptyRegionInfoQualifiers.add(result); errors.reportError(ERROR_CODE.EMPTY_META_CELL, "Empty REGIONINFO_QUALIFIER found in hbase:meta"); return true; } ServerName sn = null; if (rl.getRegionLocation(RegionInfo.DEFAULT_REPLICA_ID) == null || rl.getRegionLocation(RegionInfo.DEFAULT_REPLICA_ID).getRegion() == null) { emptyRegionInfoQualifiers.add(result); errors.reportError(ERROR_CODE.EMPTY_META_CELL, "Empty REGIONINFO_QUALIFIER found in hbase:meta"); return true; } RegionInfo hri = rl.getRegionLocation(RegionInfo.DEFAULT_REPLICA_ID).getRegion(); if (!(isTableIncluded(hri.getTable()) || hri.isMetaRegion())) { return true; } PairOfSameType<RegionInfo> daughters = MetaTableAccessor.getDaughterRegions(result); for (HRegionLocation h : rl.getRegionLocations()) { if (h == null || h.getRegion() == null) { continue; } sn = h.getServerName(); hri = h.getRegion(); HbckRegionInfo.MetaEntry m = null; if (hri.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { m = new HbckRegionInfo.MetaEntry(hri, sn, ts, daughters.getFirst(), daughters.getSecond()); } else { m = new HbckRegionInfo.MetaEntry(hri, sn, ts, null, null); } HbckRegionInfo previous = regionInfoMap.get(hri.getEncodedName()); if (previous == null) { regionInfoMap.put(hri.getEncodedName(), new HbckRegionInfo(m)); } else if (previous.getMetaEntry() == null) { previous.setMetaEntry(m); } else { throw new IOException("Two entries in hbase:meta are same " + previous); } } List<RegionInfo> mergeParents = MetaTableAccessor.getMergeRegions(result.rawCells()); if (mergeParents != null) { for (RegionInfo mergeRegion : mergeParents) { if (mergeRegion != null) { // This region is already being merged HbckRegionInfo hbInfo = getOrCreateInfo(mergeRegion.getEncodedName()); hbInfo.setMerged(true); } } } // show proof of progress to the user, once for every 100 records. if (countRecord % 100 == 0) { errors.progress(); } countRecord++; return true; } catch (RuntimeException e) { LOG.error("Result=" + result); throw e; } } }; if (!checkMetaOnly) { // Scan hbase:meta to pick up user regions MetaTableAccessor.fullScanRegions(connection, visitor); } errors.print(""); return true; }
Example 13
Source File: RegionStateStore.java From hbase with Apache License 2.0 | 4 votes |
private void updateUserRegionLocation(RegionInfo regionInfo, State state, ServerName regionLocation, long openSeqNum, long pid) throws IOException { long time = EnvironmentEdgeManager.currentTime(); final int replicaId = regionInfo.getReplicaId(); final Put put = new Put(CatalogFamilyFormat.getMetaKeyForRegion(regionInfo), time); MetaTableAccessor.addRegionInfo(put, regionInfo); final StringBuilder info = new StringBuilder("pid=").append(pid).append(" updating hbase:meta row=") .append(regionInfo.getEncodedName()).append(", regionState=").append(state); if (openSeqNum >= 0) { Preconditions.checkArgument(state == State.OPEN && regionLocation != null, "Open region should be on a server"); MetaTableAccessor.addLocation(put, regionLocation, openSeqNum, replicaId); // only update replication barrier for default replica if (regionInfo.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID && hasGlobalReplicationScope(regionInfo.getTable())) { MetaTableAccessor.addReplicationBarrier(put, openSeqNum); info.append(", repBarrier=").append(openSeqNum); } info.append(", openSeqNum=").append(openSeqNum); info.append(", regionLocation=").append(regionLocation); } else if (regionLocation != null) { // Ideally, if no regionLocation, write null to the hbase:meta but this will confuse clients // currently; they want a server to hit. TODO: Make clients wait if no location. put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(CatalogFamilyFormat.getServerNameColumn(replicaId)) .setTimestamp(put.getTimestamp()) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(regionLocation.getServerName())) .build()); info.append(", regionLocation=").append(regionLocation); } put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(put.getRow()) .setFamily(HConstants.CATALOG_FAMILY) .setQualifier(getStateColumn(replicaId)) .setTimestamp(put.getTimestamp()) .setType(Cell.Type.Put) .setValue(Bytes.toBytes(state.name())) .build()); LOG.info(info.toString()); updateRegionLocation(regionInfo, state, put); }
Example 14
Source File: HStore.java From hbase with Apache License 2.0 | 4 votes |
@Override public boolean isPrimaryReplicaStore() { return getRegionInfo().getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID; }
Example 15
Source File: ZNodePaths.java From hbase with Apache License 2.0 | 4 votes |
/** * Parse the meta replicaId from the passed znode * @param znode the name of the znode, does not include baseZNode * @return replicaId */ public int getMetaReplicaIdFromZnode(String znode) { return znode.equals(metaZNodePrefix)? RegionInfo.DEFAULT_REPLICA_ID: Integer.parseInt(znode.substring(metaZNodePrefix.length() + 1)); }
Example 16
Source File: RegionLocations.java From hbase with Apache License 2.0 | 4 votes |
public HRegionLocation getDefaultRegionLocation() { return locations[RegionInfo.DEFAULT_REPLICA_ID]; }
Example 17
Source File: FileSystemUtilizationChore.java From hbase with Apache License 2.0 | 4 votes |
@Override protected void chore() { final RegionSizeStore regionSizeStore = getRegionSizeStore(); final Set<Region> onlineRegions = new HashSet<>(rs.getRegions()); // Process the regions from the last run if we have any. If we are somehow having difficulty // processing the Regions, we want to avoid creating a backlog in memory of Region objs. Iterator<Region> oldRegionsToProcess = getLeftoverRegions(); final Iterator<Region> iterator; final boolean processingLeftovers; if (oldRegionsToProcess == null) { iterator = onlineRegions.iterator(); processingLeftovers = false; } else { iterator = oldRegionsToProcess; processingLeftovers = true; } // Reset the leftoverRegions and let the loop re-assign if necessary. setLeftoverRegions(null); long regionSizesCalculated = 0L; long offlineRegionsSkipped = 0L; long skippedSplitParents = 0L; long skippedRegionReplicas = 0L; final long start = EnvironmentEdgeManager.currentTime(); while (iterator.hasNext()) { // Make sure this chore doesn't hog the thread. long timeRunning = EnvironmentEdgeManager.currentTime() - start; if (timeRunning > maxIterationMillis) { LOG.debug("Preempting execution of FileSystemUtilizationChore because it exceeds the" + " maximum iteration configuration value. Will process remaining Regions" + " on a subsequent invocation."); setLeftoverRegions(iterator); break; } final Region region = iterator.next(); // If we're processing leftover regions, the region may no-longer be online. // If so, we can skip it. if (processingLeftovers && !onlineRegions.contains(region)) { offlineRegionsSkipped++; continue; } // Avoid computing the size of regions which are the parent of split. if (region.getRegionInfo().isSplitParent()) { skippedSplitParents++; continue; } // Avoid computing the size of region replicas. if (RegionInfo.DEFAULT_REPLICA_ID != region.getRegionInfo().getReplicaId()) { skippedRegionReplicas++; continue; } final long sizeInBytes = computeSize(region); regionSizeStore.put(region.getRegionInfo(), sizeInBytes); regionSizesCalculated++; } if (LOG.isTraceEnabled()) { LOG.trace("Computed the size of " + regionSizesCalculated + " Regions. Skipped computation" + " of " + offlineRegionsSkipped + " regions due to not being online on this RS, " + skippedSplitParents + " regions due to being the parent of a split, and" + skippedRegionReplicas + " regions due to being region replicas."); } }