Search in sources :

Example 1 with UnknownRegionException

use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.

the class AsyncHBaseAdmin method closeRegion.

@Override
public CompletableFuture<Void> closeRegion(byte[] regionName, String serverName) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    getRegion(regionName).whenComplete((p, err) -> {
        if (err != null) {
            future.completeExceptionally(err);
            return;
        }
        if (p == null || p.getFirst() == null) {
            future.completeExceptionally(new UnknownRegionException(Bytes.toStringBinary(regionName)));
            return;
        }
        if (serverName != null) {
            closeRegion(ServerName.valueOf(serverName), p.getFirst()).whenComplete((p2, err2) -> {
                if (err2 != null) {
                    future.completeExceptionally(err2);
                } else {
                    future.complete(null);
                }
            });
        } else {
            if (p.getSecond() == null) {
                future.completeExceptionally(new NotServingRegionException(regionName));
            } else {
                closeRegion(p.getSecond(), p.getFirst()).whenComplete((p2, err2) -> {
                    if (err2 != null) {
                        future.completeExceptionally(err2);
                    } else {
                        future.complete(null);
                    }
                });
            }
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException)

Example 2 with UnknownRegionException

use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.

the class MasterRpcServices method assignRegion.

@Override
public AssignRegionResponse assignRegion(RpcController controller, AssignRegionRequest req) throws ServiceException {
    try {
        server.checkInitialized();
        final RegionSpecifierType type = req.getRegion().getType();
        if (type != RegionSpecifierType.REGION_NAME) {
            LOG.warn("assignRegion specifier type: expected: " + RegionSpecifierType.REGION_NAME + " actual: " + type);
        }
        final byte[] regionName = req.getRegion().getValue().toByteArray();
        final RegionInfo regionInfo = server.getAssignmentManager().getRegionInfo(regionName);
        if (regionInfo == null) {
            throw new UnknownRegionException(Bytes.toStringBinary(regionName));
        }
        final AssignRegionResponse arr = AssignRegionResponse.newBuilder().build();
        if (server.cpHost != null) {
            server.cpHost.preAssign(regionInfo);
        }
        LOG.info(server.getClientIdAuditPrefix() + " assign " + regionInfo.getRegionNameAsString());
        server.getAssignmentManager().assign(regionInfo);
        if (server.cpHost != null) {
            server.cpHost.postAssign(regionInfo);
        }
        return arr;
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) RegionSpecifierType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType) AssignRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AssignRegionResponse) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 3 with UnknownRegionException

use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.

the class AssignmentManager method loadRegionFromMeta.

/**
 * Query META if the given <code>RegionInfo</code> exists, adding to
 * <code>AssignmentManager.regionStateStore</code> cache if the region is found in META.
 * @param regionEncodedName encoded name for the region to be loaded from META into
 *                          <code>AssignmentManager.regionStateStore</code> cache
 * @return <code>RegionInfo</code> instance for the given region if it is present in META
 *          and got successfully loaded into <code>AssignmentManager.regionStateStore</code>
 *          cache, <b>null</b> otherwise.
 * @throws UnknownRegionException if any errors occur while querying meta.
 */
public RegionInfo loadRegionFromMeta(String regionEncodedName) throws UnknownRegionException {
    try {
        RegionMetaLoadingVisitor visitor = new RegionMetaLoadingVisitor();
        regionStateStore.visitMetaForRegion(regionEncodedName, visitor);
        return regionStates.getRegionState(regionEncodedName) == null ? null : regionStates.getRegionState(regionEncodedName).getRegion();
    } catch (IOException e) {
        throw new UnknownRegionException("Error trying to load region " + regionEncodedName + " from META", e);
    }
}
Also used : UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) IOException(java.io.IOException)

Example 4 with UnknownRegionException

use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.

the class MergeTableRegionsProcedure method prepareMergeRegion.

/**
 * Prepare merge and do some check
 */
private boolean prepareMergeRegion(final MasterProcedureEnv env) throws IOException {
    // Fail if we are taking snapshot for the given table
    TableName tn = regionsToMerge[0].getTable();
    if (env.getMasterServices().getSnapshotManager().isTakingSnapshot(tn)) {
        throw new MergeRegionException("Skip merging regions " + RegionInfo.getShortNameToLog(regionsToMerge) + ", because we are snapshotting " + tn);
    }
    // the switch was set to false after submit.
    if (!env.getMasterServices().isSplitOrMergeEnabled(MasterSwitchType.MERGE)) {
        String regionsStr = Arrays.deepToString(this.regionsToMerge);
        LOG.warn("Merge switch is off! skip merge of " + regionsStr);
        setFailure(getClass().getSimpleName(), new IOException("Merge of " + regionsStr + " failed because merge switch is off"));
        return false;
    }
    if (!env.getMasterServices().getTableDescriptors().get(getTableName()).isMergeEnabled()) {
        String regionsStr = Arrays.deepToString(regionsToMerge);
        LOG.warn("Merge is disabled for the table! Skipping merge of {}", regionsStr);
        setFailure(getClass().getSimpleName(), new IOException("Merge of " + regionsStr + " failed as region merge is disabled for the table"));
        return false;
    }
    RegionStates regionStates = env.getAssignmentManager().getRegionStates();
    RegionStateStore regionStateStore = env.getAssignmentManager().getRegionStateStore();
    for (RegionInfo ri : this.regionsToMerge) {
        if (regionStateStore.hasMergeRegions(ri)) {
            String msg = "Skip merging " + RegionInfo.getShortNameToLog(regionsToMerge) + ", because a parent, " + RegionInfo.getShortNameToLog(ri) + ", has a merge qualifier " + "(if a 'merge column' in parent, it was recently merged but still has outstanding " + "references to its parents that must be cleared before it can participate in merge -- " + "major compact it to hurry clearing of its references)";
            LOG.warn(msg);
            throw new MergeRegionException(msg);
        }
        RegionState state = regionStates.getRegionState(ri.getEncodedName());
        if (state == null) {
            throw new UnknownRegionException(RegionInfo.getShortNameToLog(ri) + " UNKNOWN (Has it been garbage collected?)");
        }
        if (!state.isOpened()) {
            throw new MergeRegionException("Unable to merge regions that are NOT online: " + ri);
        }
        // along with the failure, so we can see why regions are not mergeable at this time.
        try {
            if (!isMergeable(env, state)) {
                setFailure(getClass().getSimpleName(), new MergeRegionException("Skip merging " + RegionInfo.getShortNameToLog(regionsToMerge) + ", because a parent, " + RegionInfo.getShortNameToLog(ri) + ", is not mergeable"));
                return false;
            }
        } catch (IOException e) {
            IOException ioe = new IOException(RegionInfo.getShortNameToLog(ri) + " NOT mergeable", e);
            setFailure(getClass().getSimpleName(), ioe);
            return false;
        }
    }
    // Update region states to Merging
    setRegionStateToMerging(env);
    return true;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RegionState(org.apache.hadoop.hbase.master.RegionState) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MergeRegionException(org.apache.hadoop.hbase.exceptions.MergeRegionException) IOException(java.io.IOException)

Example 5 with UnknownRegionException

use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.

the class MasterRpcServices method unassignRegion.

@Override
public UnassignRegionResponse unassignRegion(RpcController controller, UnassignRegionRequest req) throws ServiceException {
    try {
        final byte[] regionName = req.getRegion().getValue().toByteArray();
        RegionSpecifierType type = req.getRegion().getType();
        UnassignRegionResponse urr = UnassignRegionResponse.newBuilder().build();
        server.checkInitialized();
        if (type != RegionSpecifierType.REGION_NAME) {
            LOG.warn("unassignRegion specifier type: expected: " + RegionSpecifierType.REGION_NAME + " actual: " + type);
        }
        RegionStateNode rsn = server.getAssignmentManager().getRegionStates().getRegionStateNodeFromName(regionName);
        if (rsn == null) {
            throw new UnknownRegionException(Bytes.toString(regionName));
        }
        RegionInfo hri = rsn.getRegionInfo();
        if (server.cpHost != null) {
            server.cpHost.preUnassign(hri);
        }
        LOG.debug(server.getClientIdAuditPrefix() + " unassign " + hri.getRegionNameAsString() + " in current location if it is online");
        server.getAssignmentManager().unassign(hri);
        if (server.cpHost != null) {
            server.cpHost.postUnassign(hri);
        }
        return urr;
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : UnassignRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.UnassignRegionResponse) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) RegionSpecifierType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode)

Aggregations

UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)18 IOException (java.io.IOException)14 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)10 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)9 TableName (org.apache.hadoop.hbase.TableName)8 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)5 InterruptedIOException (java.io.InterruptedIOException)4 ServerName (org.apache.hadoop.hbase.ServerName)4 MergeRegionException (org.apache.hadoop.hbase.exceptions.MergeRegionException)4 RegionSpecifierType (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType)4 Test (org.junit.Test)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)2 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 TableExistsException (org.apache.hadoop.hbase.TableExistsException)2 TableNotDisabledException (org.apache.hadoop.hbase.TableNotDisabledException)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 Admin (org.apache.hadoop.hbase.client.Admin)2 ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)2