Search in sources :

Example 71 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class HBaseTestingUtility method getRSForFirstRegionInTable.

/**
 * Tool to get the reference to the region server object that holds the
 * region of the specified user table.
 * @param tableName user table to lookup in hbase:meta
 * @return region server that holds it, null if the row doesn't exist
 * @throws IOException
 * @throws InterruptedException
 */
public HRegionServer getRSForFirstRegionInTable(TableName tableName) throws IOException, InterruptedException {
    List<RegionInfo> regions = getRegions(tableName);
    if (regions == null || regions.isEmpty()) {
        return null;
    }
    LOG.debug("Found " + regions.size() + " regions for table " + tableName);
    byte[] firstRegionName = regions.stream().filter(r -> !r.isOffline()).map(RegionInfo::getRegionName).findFirst().orElseThrow(() -> new IOException("online regions not found in table " + tableName));
    LOG.debug("firstRegionName=" + Bytes.toString(firstRegionName));
    long pause = getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE, HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
    int numRetries = getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
    RetryCounter retrier = new RetryCounter(numRetries + 1, (int) pause, TimeUnit.MICROSECONDS);
    while (retrier.shouldRetry()) {
        int index = getMiniHBaseCluster().getServerWith(firstRegionName);
        if (index != -1) {
            return getMiniHBaseCluster().getRegionServerThreads().get(index).getRegionServer();
        }
        // Came back -1.  Region may not be online yet.  Sleep a while.
        retrier.sleepUntilNextRetry();
    }
    return null;
}
Also used : ZKConfig(org.apache.hadoop.hbase.zookeeper.ZKConfig) Arrays(java.util.Arrays) UserProvider(org.apache.hadoop.hbase.security.UserProvider) SplitAlgorithm(org.apache.hadoop.hbase.util.RegionSplitter.SplitAlgorithm) VisibilityLabelsCache(org.apache.hadoop.hbase.security.visibility.VisibilityLabelsCache) FileSystem(org.apache.hadoop.fs.FileSystem) HFileSystem(org.apache.hadoop.hbase.fs.HFileSystem) BooleanSupplier(java.util.function.BooleanSupplier) RegionState(org.apache.hadoop.hbase.master.RegionState) InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) Delete(org.apache.hadoop.hbase.client.Delete) MemStoreLAB(org.apache.hadoop.hbase.regionserver.MemStoreLAB) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) Consistency(org.apache.hadoop.hbase.client.Consistency) BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) WAL(org.apache.hadoop.hbase.wal.WAL) Closeables(org.apache.hbase.thirdparty.com.google.common.io.Closeables) Pair(org.apache.hadoop.hbase.util.Pair) ZooKeeper(org.apache.zookeeper.ZooKeeper) ChecksumUtil(org.apache.hadoop.hbase.io.hfile.ChecksumUtil) CommonFSUtils(org.apache.hadoop.hbase.util.CommonFSUtils) Get(org.apache.hadoop.hbase.client.Get) Set(java.util.Set) BloomType(org.apache.hadoop.hbase.regionserver.BloomType) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) DFSClient(org.apache.hadoop.hdfs.DFSClient) RpcServerInterface(org.apache.hadoop.hbase.ipc.RpcServerInterface) InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) Region(org.apache.hadoop.hbase.regionserver.Region) FSUtils(org.apache.hadoop.hbase.util.FSUtils) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) ChunkCreator(org.apache.hadoop.hbase.regionserver.ChunkCreator) HStore(org.apache.hadoop.hbase.regionserver.HStore) EmptyWatcher(org.apache.hadoop.hbase.zookeeper.EmptyWatcher) WALFactory(org.apache.hadoop.hbase.wal.WALFactory) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) DatagramSocket(java.net.DatagramSocket) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) Properties(java.util.Properties) DataBlockEncoding(org.apache.hadoop.hbase.io.encoding.DataBlockEncoding) Predicate(org.apache.hadoop.hbase.Waiter.Predicate) AssignmentTestingUtil(org.apache.hadoop.hbase.master.assignment.AssignmentTestingUtil) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RetryCounter(org.apache.hadoop.hbase.util.RetryCounter) EditLogFileOutputStream(org.apache.hadoop.hdfs.server.namenode.EditLogFileOutputStream) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Field(java.lang.reflect.Field) UnknownHostException(java.net.UnknownHostException) RegionServerStoppedException(org.apache.hadoop.hbase.regionserver.RegionServerStoppedException) File(java.io.File) ConnectionFactory(org.apache.hadoop.hbase.client.ConnectionFactory) Scan(org.apache.hadoop.hbase.client.Scan) Admin(org.apache.hadoop.hbase.client.Admin) Connection(org.apache.hadoop.hbase.client.Connection) RegionStateStore(org.apache.hadoop.hbase.master.assignment.RegionStateStore) Log4jUtils(org.apache.hadoop.hbase.logging.Log4jUtils) MobFileCache(org.apache.hadoop.hbase.mob.MobFileCache) Result(org.apache.hadoop.hbase.client.Result) Random(java.util.Random) MiniMRCluster(org.apache.hadoop.mapred.MiniMRCluster) ServerManager(org.apache.hadoop.hbase.master.ServerManager) States(org.apache.zookeeper.ZooKeeper.States) BlockCache(org.apache.hadoop.hbase.io.hfile.BlockCache) RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) Algorithm(org.apache.hadoop.hbase.io.compress.Compression.Algorithm) Path(org.apache.hadoop.fs.Path) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) Durability(org.apache.hadoop.hbase.client.Durability) HFile(org.apache.hadoop.hbase.io.hfile.HFile) ProtobufUtil(org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil) RegionSplitter(org.apache.hadoop.hbase.util.RegionSplitter) Collection(java.util.Collection) Compression(org.apache.hadoop.hbase.io.compress.Compression) NavigableSet(java.util.NavigableSet) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) HBaseKerberosUtils(org.apache.hadoop.hbase.security.HBaseKerberosUtils) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) List(java.util.List) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Modifier(java.lang.reflect.Modifier) EnvironmentEdgeManager(org.apache.hadoop.hbase.util.EnvironmentEdgeManager) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) MasterRegistry(org.apache.hadoop.hbase.client.MasterRegistry) RegionInfoBuilder(org.apache.hadoop.hbase.client.RegionInfoBuilder) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) HMaster(org.apache.hadoop.hbase.master.HMaster) Socket(java.net.Socket) MessageDigest(java.security.MessageDigest) TableState(org.apache.hadoop.hbase.client.TableState) BindException(java.net.BindException) Hbck(org.apache.hadoop.hbase.client.Hbck) AtomicReference(java.util.concurrent.atomic.AtomicReference) User(org.apache.hadoop.hbase.security.User) HashSet(java.util.HashSet) AsyncClusterConnection(org.apache.hadoop.hbase.client.AsyncClusterConnection) Threads(org.apache.hadoop.hbase.util.Threads) TaskLog(org.apache.hadoop.mapred.TaskLog) Bytes(org.apache.hadoop.hbase.util.Bytes) OutputStream(java.io.OutputStream) ReadType(org.apache.hadoop.hbase.client.Scan.ReadType) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) Iterator(java.util.Iterator) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) ReflectionUtils(org.apache.hadoop.hbase.util.ReflectionUtils) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Put(org.apache.hadoop.hbase.client.Put) MiniKdc(org.apache.hadoop.minikdc.MiniKdc) WatchedEvent(org.apache.zookeeper.WatchedEvent) TimeUnit(java.util.concurrent.TimeUnit) JobConf(org.apache.hadoop.mapred.JobConf) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) ClusterConnectionFactory(org.apache.hadoop.hbase.client.ClusterConnectionFactory) MapreduceTestingShim(org.apache.hadoop.hbase.mapreduce.MapreduceTestingShim) Table(org.apache.hadoop.hbase.client.Table) ExplainingPredicate(org.apache.hadoop.hbase.Waiter.ExplainingPredicate) Collections(java.util.Collections) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) RetryCounter(org.apache.hadoop.hbase.util.RetryCounter) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 72 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class HBaseTestingUtility method assertRegionOnlyOnServer.

/**
 * Check to make sure the region is open on the specified
 * region server, but not on any other one.
 */
public void assertRegionOnlyOnServer(final RegionInfo hri, final ServerName server, final long timeout) throws IOException, InterruptedException {
    long timeoutTime = EnvironmentEdgeManager.currentTime() + timeout;
    while (true) {
        List<RegionInfo> regions = getAdmin().getRegions(server);
        if (regions.stream().anyMatch(r -> RegionInfo.COMPARATOR.compare(r, hri) == 0)) {
            List<JVMClusterUtil.RegionServerThread> rsThreads = getHBaseCluster().getLiveRegionServerThreads();
            for (JVMClusterUtil.RegionServerThread rsThread : rsThreads) {
                HRegionServer rs = rsThread.getRegionServer();
                if (server.equals(rs.getServerName())) {
                    continue;
                }
                Collection<HRegion> hrs = rs.getOnlineRegionsLocalContext();
                for (HRegion r : hrs) {
                    if (r.getRegionInfo().getRegionId() == hri.getRegionId()) {
                        throw new AssertionError("Region should not be double assigned");
                    }
                }
            }
            // good, we are happy
            return;
        }
        long now = EnvironmentEdgeManager.currentTime();
        if (now > timeoutTime)
            break;
        Thread.sleep(10);
    }
    throw new AssertionError("Could not find region " + hri.getRegionNameAsString() + " on server " + server);
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Example 73 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class MiniHBaseCluster method getServerWith.

/**
 * Get the location of the specified region
 * @param regionName Name of the region in bytes
 * @return Index into List of {@link MiniHBaseCluster#getRegionServerThreads()}
 * of HRS carrying hbase:meta. Returns -1 if none found.
 */
public int getServerWith(byte[] regionName) {
    int index = 0;
    for (JVMClusterUtil.RegionServerThread rst : getRegionServerThreads()) {
        HRegionServer hrs = rst.getRegionServer();
        if (!hrs.isStopped()) {
            Region region = hrs.getOnlineRegion(regionName);
            if (region != null) {
                return index;
            }
        }
        index++;
    }
    return -1;
}
Also used : JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Region(org.apache.hadoop.hbase.regionserver.Region) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Example 74 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestScannersFromClientSide method testScanOnReopenedRegion.

/**
 * Test from client side for scan while the region is reopened
 * on the same region server.
 */
@Test
public void testScanOnReopenedRegion() throws Exception {
    final TableName tableName = name.getTableName();
    byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, 2);
    Table ht = TEST_UTIL.createTable(tableName, FAMILY);
    Put put;
    Scan scan;
    Result result;
    ResultScanner scanner;
    boolean toLog = false;
    List<Cell> kvListExp;
    // table: row, family, c0:0, c1:1
    put = new Put(ROW);
    for (int i = 0; i < QUALIFIERS.length; i++) {
        KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[i], i, VALUE);
        put.add(kv);
    }
    ht.put(put);
    scan = new Scan().withStartRow(ROW);
    scanner = ht.getScanner(scan);
    HRegionLocation loc;
    try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
        loc = locator.getRegionLocation(ROW);
    }
    RegionInfo hri = loc.getRegion();
    SingleProcessHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
    byte[] regionName = hri.getRegionName();
    int i = cluster.getServerWith(regionName);
    HRegionServer rs = cluster.getRegionServer(i);
    LOG.info("Unassigning " + hri);
    TEST_UTIL.getAdmin().unassign(hri.getRegionName(), true);
    long startTime = EnvironmentEdgeManager.currentTime();
    long timeOut = 10000;
    boolean offline = false;
    while (true) {
        if (rs.getOnlineRegion(regionName) == null) {
            offline = true;
            break;
        }
        assertTrue("Timed out in closing the testing region", EnvironmentEdgeManager.currentTime() < startTime + timeOut);
    }
    assertTrue(offline);
    LOG.info("Assigning " + hri);
    TEST_UTIL.getAdmin().assign(hri.getRegionName());
    startTime = EnvironmentEdgeManager.currentTime();
    while (true) {
        rs = cluster.getRegionServer(cluster.getServerWith(regionName));
        if (rs != null && rs.getOnlineRegion(regionName) != null) {
            offline = false;
            break;
        }
        assertTrue("Timed out in open the testing region", EnvironmentEdgeManager.currentTime() < startTime + timeOut);
    }
    assertFalse(offline);
    // c0:0, c1:1
    kvListExp = new ArrayList<>();
    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[0], 0, VALUE));
    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[1], 1, VALUE));
    result = scanner.next();
    verifyResult(result, kvListExp, toLog, "Testing scan on re-opened region");
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) KeyValue(org.apache.hadoop.hbase.KeyValue) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 75 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestSeparateClientZKCluster method testMetaMoveDuringClientZkClusterRestart.

@Test
public void testMetaMoveDuringClientZkClusterRestart() throws Exception {
    TableName tn = name.getTableName();
    // create table
    Connection conn = TEST_UTIL.getConnection();
    try (Admin admin = conn.getAdmin();
        Table table = conn.getTable(tn)) {
        ColumnFamilyDescriptorBuilder cfDescBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family);
        TableDescriptorBuilder tableDescBuilder = TableDescriptorBuilder.newBuilder(tn).setColumnFamily(cfDescBuilder.build());
        admin.createTable(tableDescBuilder.build());
        // put some data
        Put put = new Put(row);
        put.addColumn(family, qualifier, value);
        table.put(put);
        // invalid connection cache
        conn.clearRegionLocationCache();
        // stop client zk cluster
        clientZkCluster.shutdown();
        // stop current meta server and confirm the server shutdown process
        // is not affected by client ZK crash
        SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
        int metaServerId = cluster.getServerWithMeta();
        HRegionServer metaServer = cluster.getRegionServer(metaServerId);
        metaServer.stop("Stop current RS holding meta region");
        while (metaServer.isAlive()) {
            Thread.sleep(200);
        }
        // wait for meta region online
        AssignmentTestingUtil.waitForAssignment(cluster.getMaster().getAssignmentManager(), RegionInfoBuilder.FIRST_META_REGIONINFO);
        // wait some long time to make sure we will retry sync data to client ZK until data set
        Thread.sleep(10000);
        clientZkCluster.startup(clientZkDir);
        // new request should pass
        Get get = new Get(row);
        Result result = table.get(get);
        LOG.debug("Result: " + Bytes.toString(result.getValue(family, qualifier)));
        assertArrayEquals(value, result.getValue(family, qualifier));
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) TableName(org.apache.hadoop.hbase.TableName) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Aggregations

HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)253 Test (org.junit.Test)188 TableName (org.apache.hadoop.hbase.TableName)70 Table (org.apache.hadoop.hbase.client.Table)67 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)59 IOException (java.io.IOException)53 Region (org.apache.hadoop.hbase.regionserver.Region)49 Configuration (org.apache.hadoop.conf.Configuration)47 ServerName (org.apache.hadoop.hbase.ServerName)46 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)41 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)41 Put (org.apache.hadoop.hbase.client.Put)39 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)32 RegionServerThread (org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)32 JVMClusterUtil (org.apache.hadoop.hbase.util.JVMClusterUtil)23 List (java.util.List)22 HMaster (org.apache.hadoop.hbase.master.HMaster)22 ArrayList (java.util.ArrayList)21 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)21 Waiter (org.apache.hadoop.hbase.Waiter)21