Search in sources :

Example 1 with ServerName

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

the class ClusterStatusListener method receive.

/**
   * Acts upon the reception of a new cluster status.
   *
   * @param ncs the cluster status
   */
public void receive(ClusterStatus ncs) {
    if (ncs.getDeadServerNames() != null) {
        for (ServerName sn : ncs.getDeadServerNames()) {
            if (!isDeadServer(sn)) {
                LOG.info("There is a new dead server: " + sn);
                deadServers.add(sn);
                if (deadServerHandler != null) {
                    deadServerHandler.newDead(sn);
                }
            }
        }
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName)

Example 2 with ServerName

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

the class ConnectionImplementation method locateRegionInMeta.

/*
    * Search the hbase:meta table for the HRegionLocation
    * info that contains the table and row we're seeking.
    */
private RegionLocations locateRegionInMeta(TableName tableName, byte[] row, boolean useCache, boolean retry, int replicaId) throws IOException {
    // we already have the region.
    if (useCache) {
        RegionLocations locations = getCachedLocation(tableName, row);
        if (locations != null && locations.getRegionLocation(replicaId) != null) {
            return locations;
        }
    }
    // build the key of the meta region we should be looking for.
    // the extra 9's on the end are necessary to allow "exact" matches
    // without knowing the precise region names.
    byte[] metaKey = HRegionInfo.createRegionName(tableName, row, HConstants.NINES, false);
    Scan s = new Scan();
    s.setReversed(true);
    s.withStartRow(metaKey);
    s.addFamily(HConstants.CATALOG_FAMILY);
    s.setOneRowLimit();
    if (this.useMetaReplicas) {
        s.setConsistency(Consistency.TIMELINE);
    }
    int maxAttempts = (retry ? numTries : 1);
    for (int tries = 0; true; tries++) {
        if (tries >= maxAttempts) {
            throw new NoServerForRegionException("Unable to find region for " + Bytes.toStringBinary(row) + " in " + tableName + " after " + tries + " tries.");
        }
        if (useCache) {
            RegionLocations locations = getCachedLocation(tableName, row);
            if (locations != null && locations.getRegionLocation(replicaId) != null) {
                return locations;
            }
        } else {
            // If we are not supposed to be using the cache, delete any existing cached location
            // so it won't interfere.
            metaCache.clearCache(tableName, row);
        }
        // Query the meta region
        long pauseBase = this.pause;
        try {
            Result regionInfoRow = null;
            s.resetMvccReadPoint();
            try (ReversedClientScanner rcs = new ReversedClientScanner(conf, s, TableName.META_TABLE_NAME, this, rpcCallerFactory, rpcControllerFactory, getMetaLookupPool(), 0)) {
                regionInfoRow = rcs.next();
            }
            if (regionInfoRow == null) {
                throw new TableNotFoundException(tableName);
            }
            // convert the row result into the HRegionLocation we need!
            RegionLocations locations = MetaTableAccessor.getRegionLocations(regionInfoRow);
            if (locations == null || locations.getRegionLocation(replicaId) == null) {
                throw new IOException("HRegionInfo was null in " + tableName + ", row=" + regionInfoRow);
            }
            HRegionInfo regionInfo = locations.getRegionLocation(replicaId).getRegionInfo();
            if (regionInfo == null) {
                throw new IOException("HRegionInfo was null or empty in " + TableName.META_TABLE_NAME + ", row=" + regionInfoRow);
            }
            // possible we got a region of a different table...
            if (!regionInfo.getTable().equals(tableName)) {
                throw new TableNotFoundException("Table '" + tableName + "' was not found, got: " + regionInfo.getTable() + ".");
            }
            if (regionInfo.isSplit()) {
                throw new RegionOfflineException("the only available region for" + " the required row is a split parent," + " the daughters should be online soon: " + regionInfo.getRegionNameAsString());
            }
            if (regionInfo.isOffline()) {
                throw new RegionOfflineException("the region is offline, could" + " be caused by a disable table call: " + regionInfo.getRegionNameAsString());
            }
            ServerName serverName = locations.getRegionLocation(replicaId).getServerName();
            if (serverName == null) {
                throw new NoServerForRegionException("No server address listed " + "in " + TableName.META_TABLE_NAME + " for region " + regionInfo.getRegionNameAsString() + " containing row " + Bytes.toStringBinary(row));
            }
            if (isDeadServer(serverName)) {
                throw new RegionServerStoppedException("hbase:meta says the region " + regionInfo.getRegionNameAsString() + " is managed by the server " + serverName + ", but it is dead.");
            }
            // Instantiate the location
            cacheLocation(tableName, locations);
            return locations;
        } catch (TableNotFoundException e) {
            // from the HTable constructor.
            throw e;
        } catch (IOException e) {
            ExceptionUtil.rethrowIfInterrupt(e);
            if (e instanceof RemoteException) {
                e = ((RemoteException) e).unwrapRemoteException();
            }
            if (e instanceof CallQueueTooBigException) {
                // Give a special check on CallQueueTooBigException, see #HBASE-17114
                pauseBase = this.pauseForCQTBE;
            }
            if (tries < maxAttempts - 1) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("locateRegionInMeta parentTable=" + TableName.META_TABLE_NAME + ", metaLocation=" + ", attempt=" + tries + " of " + maxAttempts + " failed; retrying after sleep of " + ConnectionUtils.getPauseTime(pauseBase, tries) + " because: " + e.getMessage());
                }
            } else {
                throw e;
            }
            // Only relocate the parent region if necessary
            if (!(e instanceof RegionOfflineException || e instanceof NoServerForRegionException)) {
                relocateRegion(TableName.META_TABLE_NAME, metaKey, replicaId);
            }
        }
        try {
            Thread.sleep(ConnectionUtils.getPauseTime(pauseBase, tries));
        } catch (InterruptedException e) {
            throw new InterruptedIOException("Giving up trying to location region in " + "meta: thread is interrupted.");
        }
    }
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) InterruptedIOException(java.io.InterruptedIOException) CallQueueTooBigException(org.apache.hadoop.hbase.CallQueueTooBigException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) RegionServerStoppedException(org.apache.hadoop.hbase.regionserver.RegionServerStoppedException) ServerName(org.apache.hadoop.hbase.ServerName) RemoteException(org.apache.hadoop.ipc.RemoteException)

Example 3 with ServerName

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

the class ConnectionImplementation method isTableAvailable.

@Override
public boolean isTableAvailable(final TableName tableName, @Nullable final byte[][] splitKeys) throws IOException {
    if (this.closed) {
        throw new IOException(toString() + " closed");
    }
    try {
        if (!isTableEnabled(tableName)) {
            LOG.debug("Table " + tableName + " not enabled");
            return false;
        }
        List<Pair<HRegionInfo, ServerName>> locations = MetaTableAccessor.getTableRegionsAndLocations(this, tableName, true);
        int notDeployed = 0;
        int regionCount = 0;
        for (Pair<HRegionInfo, ServerName> pair : locations) {
            HRegionInfo info = pair.getFirst();
            if (pair.getSecond() == null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Table " + tableName + " has not deployed region " + pair.getFirst().getEncodedName());
                }
                notDeployed++;
            } else if (splitKeys != null && !Bytes.equals(info.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) {
                for (byte[] splitKey : splitKeys) {
                    // Just check if the splitkey is available
                    if (Bytes.equals(info.getStartKey(), splitKey)) {
                        regionCount++;
                        break;
                    }
                }
            } else {
                // Always empty start row should be counted
                regionCount++;
            }
        }
        if (notDeployed > 0) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Table " + tableName + " has " + notDeployed + " regions");
            }
            return false;
        } else if (splitKeys != null && regionCount != splitKeys.length + 1) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Table " + tableName + " expected to have " + (splitKeys.length + 1) + " regions, but only " + regionCount + " available");
            }
            return false;
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Table " + tableName + " should be available");
            }
            return true;
        }
    } catch (TableNotFoundException tnfe) {
        LOG.warn("Table " + tableName + " not enabled, it is not exists");
        return false;
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) ServerName(org.apache.hadoop.hbase.ServerName) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) Pair(org.apache.hadoop.hbase.util.Pair)

Example 4 with ServerName

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

the class AsyncBatchRpcRetryingCaller method send.

private void send(Map<ServerName, ServerRequest> actionsByServer, int tries) {
    long remainingNs;
    if (operationTimeoutNs > 0) {
        remainingNs = remainingTimeNs();
        if (remainingNs <= 0) {
            failAll(actionsByServer.values().stream().flatMap(m -> m.actionsByRegion.values().stream()).flatMap(r -> r.actions.stream()), tries);
            return;
        }
    } else {
        remainingNs = Long.MAX_VALUE;
    }
    actionsByServer.forEach((sn, serverReq) -> {
        ClientService.Interface stub;
        try {
            stub = conn.getRegionServerStub(sn);
        } catch (IOException e) {
            onError(serverReq.actionsByRegion, tries, e, sn);
            return;
        }
        ClientProtos.MultiRequest req;
        List<CellScannable> cells = new ArrayList<>();
        try {
            req = buildReq(serverReq.actionsByRegion, cells);
        } catch (IOException e) {
            onError(serverReq.actionsByRegion, tries, e, sn);
            return;
        }
        HBaseRpcController controller = conn.rpcControllerFactory.newController();
        resetController(controller, Math.min(rpcTimeoutNs, remainingNs));
        if (!cells.isEmpty()) {
            controller.setCellScanner(createCellScanner(cells));
        }
        stub.multi(controller, req, resp -> {
            if (controller.failed()) {
                onError(serverReq.actionsByRegion, tries, controller.getFailed(), sn);
            } else {
                try {
                    onComplete(serverReq.actionsByRegion, tries, sn, ResponseConverter.getResults(req, resp, controller.cellScanner()));
                } catch (Exception e) {
                    onError(serverReq.actionsByRegion, tries, e, sn);
                    return;
                }
            }
        });
    });
}
Also used : ConnectionUtils.getPauseTime(org.apache.hadoop.hbase.client.ConnectionUtils.getPauseTime) ResponseConverter(org.apache.hadoop.hbase.shaded.protobuf.ResponseConverter) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConnectionUtils.translateException(org.apache.hadoop.hbase.client.ConnectionUtils.translateException) RegionResult(org.apache.hadoop.hbase.client.MultiResponse.RegionResult) Map(java.util.Map) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) CellScannable(org.apache.hadoop.hbase.CellScannable) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TableName(org.apache.hadoop.hbase.TableName) IdentityHashMap(java.util.IdentityHashMap) CellUtil.createCellScanner(org.apache.hadoop.hbase.CellUtil.createCellScanner) ThrowableWithExtraContext(org.apache.hadoop.hbase.client.RetriesExhaustedException.ThrowableWithExtraContext) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) CollectionUtils.computeIfAbsent(org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent) Collectors(java.util.stream.Collectors) RequestConverter(org.apache.hadoop.hbase.shaded.protobuf.RequestConverter) TimeUnit(java.util.concurrent.TimeUnit) ConnectionUtils.resetController(org.apache.hadoop.hbase.client.ConnectionUtils.resetController) List(java.util.List) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Stream(java.util.stream.Stream) RegionSpecifierType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) SLEEP_DELTA_NS(org.apache.hadoop.hbase.client.ConnectionUtils.SLEEP_DELTA_NS) EnvironmentEdgeManager(org.apache.hadoop.hbase.util.EnvironmentEdgeManager) HashedWheelTimer(io.netty.util.HashedWheelTimer) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) InterfaceAudience(org.apache.hadoop.hbase.classification.InterfaceAudience) ClientService(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ClientService) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CellScannable(org.apache.hadoop.hbase.CellScannable) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) ClientService(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ClientService) ArrayList(java.util.ArrayList) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos) ConnectionUtils.translateException(org.apache.hadoop.hbase.client.ConnectionUtils.translateException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException)

Example 5 with ServerName

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

the class TestClientNoCluster method doMetaGetResponse.

static GetResponse doMetaGetResponse(final SortedMap<byte[], Pair<HRegionInfo, ServerName>> meta, final GetRequest request) {
    ClientProtos.Result.Builder resultBuilder = ClientProtos.Result.newBuilder();
    ByteString row = request.getGet().getRow();
    Pair<HRegionInfo, ServerName> p = meta.get(row.toByteArray());
    if (p != null) {
        resultBuilder.addCell(getRegionInfo(row, p.getFirst()));
        resultBuilder.addCell(getServer(row, p.getSecond()));
    }
    resultBuilder.addCell(getStartCode(row));
    GetResponse.Builder builder = GetResponse.newBuilder();
    builder.setResult(resultBuilder.build());
    return builder.build();
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) ServerName(org.apache.hadoop.hbase.ServerName) GetResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetResponse) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult)

Aggregations

ServerName (org.apache.hadoop.hbase.ServerName)812 Test (org.junit.Test)336 ArrayList (java.util.ArrayList)206 IOException (java.io.IOException)194 TableName (org.apache.hadoop.hbase.TableName)194 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)192 List (java.util.List)180 HashMap (java.util.HashMap)155 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)153 Map (java.util.Map)119 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)75 Configuration (org.apache.hadoop.conf.Configuration)72 HashSet (java.util.HashSet)68 Table (org.apache.hadoop.hbase.client.Table)56 TreeMap (java.util.TreeMap)51 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)47 Pair (org.apache.hadoop.hbase.util.Pair)47 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)42 Waiter (org.apache.hadoop.hbase.Waiter)42 KeeperException (org.apache.zookeeper.KeeperException)41