Search in sources :

Example 96 with ServerName

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

the class HBaseAdmin method drainRegionServers.

@Override
public void drainRegionServers(List<ServerName> servers) throws IOException {
    final List<HBaseProtos.ServerName> pbServers = new ArrayList<>(servers.size());
    for (ServerName server : servers) {
        // Parse to ServerName to do simple validation.
        ServerName.parseServerName(server.toString());
        pbServers.add(ProtobufUtil.toServerName(server));
    }
    executeCallable(new MasterCallable<Void>(getConnection(), getRpcControllerFactory()) {

        @Override
        public Void rpcCall() throws ServiceException {
            DrainRegionServersRequest req = DrainRegionServersRequest.newBuilder().addAllServerName(pbServers).build();
            master.drainRegionServers(getRpcController(), req);
            return null;
        }
    });
}
Also used : DrainRegionServersRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.DrainRegionServersRequest) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList)

Example 97 with ServerName

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

the class HRegionLocator method getAllRegionLocations.

@Override
public List<HRegionLocation> getAllRegionLocations() throws IOException {
    TableName tableName = getName();
    List<Pair<HRegionInfo, ServerName>> locations = MetaTableAccessor.getTableRegionsAndLocations(this.connection, tableName);
    ArrayList<HRegionLocation> regions = new ArrayList<>(locations.size());
    for (Pair<HRegionInfo, ServerName> entry : locations) {
        regions.add(new HRegionLocation(entry.getFirst(), entry.getSecond()));
    }
    if (regions.size() > 0) {
        connection.cacheLocation(tableName, new RegionLocations(regions));
    }
    return regions;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) Pair(org.apache.hadoop.hbase.util.Pair)

Example 98 with ServerName

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

the class HBaseAdmin method closeRegionWithEncodedRegionName.

@Override
public boolean closeRegionWithEncodedRegionName(final String encodedRegionName, final String serverName) throws IOException {
    if (null == serverName || ("").equals(serverName.trim())) {
        throw new IllegalArgumentException("The servername cannot be null or empty.");
    }
    ServerName sn = ServerName.valueOf(serverName);
    AdminService.BlockingInterface admin = this.connection.getAdmin(sn);
    // Close the region without updating zk state.
    CloseRegionRequest request = ProtobufUtil.buildCloseRegionRequest(sn, encodedRegionName);
    // TODO: There is no timeout on this controller. Set one!
    HBaseRpcController controller = this.rpcControllerFactory.newController();
    try {
        CloseRegionResponse response = admin.closeRegion(controller, request);
        boolean closed = response.getClosed();
        if (false == closed) {
            LOG.error("Not able to close the region " + encodedRegionName + ".");
        }
        return closed;
    } catch (Exception e) {
        throw ProtobufUtil.handleRemoteException(e);
    }
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) ServerName(org.apache.hadoop.hbase.ServerName) CloseRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.CloseRegionResponse) CloseRegionRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.CloseRegionRequest) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) SnapshotCreationException(org.apache.hadoop.hbase.snapshot.SnapshotCreationException) InterruptedIOException(java.io.InterruptedIOException) ZooKeeperConnectionException(org.apache.hadoop.hbase.ZooKeeperConnectionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TableNotDisabledException(org.apache.hadoop.hbase.TableNotDisabledException) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) HBaseSnapshotException(org.apache.hadoop.hbase.snapshot.HBaseSnapshotException) TimeoutException(java.util.concurrent.TimeoutException) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) FailedLogCloseException(org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException) MasterNotRunningException(org.apache.hadoop.hbase.MasterNotRunningException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) NamespaceNotFoundException(org.apache.hadoop.hbase.NamespaceNotFoundException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) KeeperException(org.apache.zookeeper.KeeperException) UnknownSnapshotException(org.apache.hadoop.hbase.snapshot.UnknownSnapshotException) RemoteException(org.apache.hadoop.ipc.RemoteException) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)

Example 99 with ServerName

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

the class HBaseAdmin method flushRegion.

@Override
public void flushRegion(final byte[] regionName) throws IOException {
    Pair<HRegionInfo, ServerName> regionServerPair = getRegion(regionName);
    if (regionServerPair == null) {
        throw new IllegalArgumentException("Unknown regionname: " + Bytes.toStringBinary(regionName));
    }
    if (regionServerPair.getSecond() == null) {
        throw new NoServerForRegionException(Bytes.toStringBinary(regionName));
    }
    final HRegionInfo hRegionInfo = regionServerPair.getFirst();
    ServerName serverName = regionServerPair.getSecond();
    final AdminService.BlockingInterface admin = this.connection.getAdmin(serverName);
    Callable<Void> callable = new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            // TODO: There is no timeout on this controller. Set one!
            HBaseRpcController controller = rpcControllerFactory.newController();
            FlushRegionRequest request = RequestConverter.buildFlushRegionRequest(hRegionInfo.getRegionName());
            admin.flushRegion(controller, request);
            return null;
        }
    };
    ProtobufUtil.call(callable);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) ServerName(org.apache.hadoop.hbase.ServerName) Callable(java.util.concurrent.Callable) FlushRegionRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.FlushRegionRequest)

Example 100 with ServerName

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

the class HBaseAdmin method split.

/**
   * {@inheritDoc}
   */
@Override
public void split(final TableName tableName, final byte[] splitPoint) throws IOException {
    ZooKeeperWatcher zookeeper = null;
    try {
        checkTableExists(tableName);
        zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable());
        List<Pair<HRegionInfo, ServerName>> pairs;
        if (TableName.META_TABLE_NAME.equals(tableName)) {
            pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper);
        } else {
            pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);
        }
        for (Pair<HRegionInfo, ServerName> pair : pairs) {
            // May not be a server for a particular row
            if (pair.getSecond() == null)
                continue;
            HRegionInfo r = pair.getFirst();
            // check for parents
            if (r.isSplitParent())
                continue;
            // if a split point given, only split that particular region
            if (r.getReplicaId() != HRegionInfo.DEFAULT_REPLICA_ID || (splitPoint != null && !r.containsRow(splitPoint)))
                continue;
            // call out to region server to do split now
            split(pair.getSecond(), pair.getFirst(), splitPoint);
        }
    } finally {
        if (zookeeper != null) {
            zookeeper.close();
        }
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ServerName(org.apache.hadoop.hbase.ServerName) Pair(org.apache.hadoop.hbase.util.Pair) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)

Aggregations

ServerName (org.apache.hadoop.hbase.ServerName)426 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)202 Test (org.junit.Test)163 ArrayList (java.util.ArrayList)97 TableName (org.apache.hadoop.hbase.TableName)89 IOException (java.io.IOException)87 HashMap (java.util.HashMap)81 List (java.util.List)72 Map (java.util.Map)54 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)45 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)34 Table (org.apache.hadoop.hbase.client.Table)33 HashSet (java.util.HashSet)32 TreeMap (java.util.TreeMap)31 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)29 Configuration (org.apache.hadoop.conf.Configuration)26 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)26 Pair (org.apache.hadoop.hbase.util.Pair)24 KeeperException (org.apache.zookeeper.KeeperException)23 InterruptedIOException (java.io.InterruptedIOException)22