Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.HBaseCluster


        conn.commit();
       
        // find a RS which doesn't has CATALOG table
        byte[] catalogTable = Bytes.toBytes("SYSTEM.CATALOG");
        byte[] indexTable = Bytes.toBytes(INDEX_TABLE_FULL_NAME);
        final HBaseCluster cluster = util.getHBaseCluster();
        Collection<ServerName> rss = cluster.getClusterStatus().getServers();
        HBaseAdmin admin = util.getHBaseAdmin();
        List<HRegionInfo> regions = admin.getTableRegions(catalogTable);
        ServerName catalogRS = cluster.getServerHoldingRegion(regions.get(0).getRegionName());
        ServerName metaRS = cluster.getServerHoldingMeta();
        ServerName rsToBeKilled = null;
       
        // find first RS isn't holding META or CATALOG table
        for(ServerName curRS : rss) {
            if(!curRS.equals(catalogRS) && !metaRS.equals(curRS)) {
                rsToBeKilled = curRS;
                break;
            }
        }
        assertTrue(rsToBeKilled != null);
       
        regions = admin.getTableRegions(indexTable);
        final HRegionInfo indexRegion = regions.get(0);
        final ServerName dstRS = rsToBeKilled;
        admin.move(indexRegion.getEncodedNameAsBytes(), Bytes.toBytes(rsToBeKilled.getServerName()));
       
        long started = System.currentTimeMillis();
        while(true) {
            ServerName sn = cluster.getServerHoldingRegion(indexRegion.getRegionName());
            if (sn != null && sn.equals(dstRS)) {
                break;
            }
            if((System.currentTimeMillis() - started) > 30000) {
                assertTrue("Timeout waiting for " + indexRegion + " move to " + rsToBeKilled, false);
            }
            Thread.sleep(200);
        }

        // use timer sending updates in every 10ms
        this.scheduleTimer = new Timer(true);
        this.scheduleTimer.schedule(new SendingUpdatesScheduleTask(conn), 0, 10);
        // let timer sending some updates
        Thread.sleep(100);
       
        // kill RS hosting index table
        util.getHBaseCluster().killRegionServer(rsToBeKilled);
       
        // wait for index table completes recovery
        util.waitUntilAllRegionsAssigned(indexTable);
       
        // Verify the metadata for index is correct.      
        do {
          Thread.sleep(15 * 1000); // sleep 15 secs
          rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(SCHEMA_NAME), INDEX_TABLE_NAME,
              new String[] { PTableType.INDEX.toString() });
          assertTrue(rs.next());
          if(PIndexState.ACTIVE.toString().equals(rs.getString("INDEX_STATE"))){
              break;
          }
        } while(true);
        this.scheduleTimer.cancel();
       
        assertEquals(cluster.getClusterStatus().getDeadServers(), 1);
    }
View Full Code Here


        conn.commit();
       
        // find a RS which doesn't has CATALOG table
        TableName catalogTable = TableName.valueOf("SYSTEM.CATALOG");
        TableName indexTable = TableName.valueOf(INDEX_TABLE_FULL_NAME);
        final HBaseCluster cluster = this.util.getHBaseCluster();
        Collection<ServerName> rss = cluster.getClusterStatus().getServers();
        HBaseAdmin admin = this.util.getHBaseAdmin();
        List<HRegionInfo> regions = admin.getTableRegions(catalogTable);
        ServerName catalogRS = cluster.getServerHoldingRegion(regions.get(0).getRegionName());
        ServerName metaRS = cluster.getServerHoldingMeta();
        ServerName rsToBeKilled = null;
       
        // find first RS isn't holding META or CATALOG table
        for(ServerName curRS : rss) {
            if(!curRS.equals(catalogRS) && !metaRS.equals(curRS)) {
                rsToBeKilled = curRS;
                break;
            }
        }
        assertTrue(rsToBeKilled != null);
       
        regions = admin.getTableRegions(indexTable);
        final HRegionInfo indexRegion = regions.get(0);
        final ServerName dstRS = rsToBeKilled;
        admin.move(indexRegion.getEncodedNameAsBytes(), Bytes.toBytes(rsToBeKilled.getServerName()));
        this.util.waitFor(30000, 200, new Waiter.Predicate<Exception>() {
            @Override
            public boolean evaluate() throws Exception {
              ServerName sn = cluster.getServerHoldingRegion(indexRegion.getRegionName());
              return (sn != null && sn.equals(dstRS));
            }
          });
       
        // use timer sending updates in every 10ms
        this.scheduleTimer = new Timer(true);
        this.scheduleTimer.schedule(new SendingUpdatesScheduleTask(conn), 0, 10);
        // let timer sending some updates
        Thread.sleep(100);
       
        // kill RS hosting index table
        this.util.getHBaseCluster().killRegionServer(rsToBeKilled);
       
        // wait for index table completes recovery
        this.util.waitUntilAllRegionsAssigned(indexTable);
       
        // Verify the metadata for index is correct.      
        do {
          Thread.sleep(15 * 1000); // sleep 15 secs
          rs = conn.getMetaData().getTables(null, StringUtil.escapeLike(SCHEMA_NAME), INDEX_TABLE_NAME,
              new String[] { PTableType.INDEX.toString() });
          assertTrue(rs.next());
          if(PIndexState.ACTIVE.toString().equals(rs.getString("INDEX_STATE"))){
              break;
          }
        } while(true);
        this.scheduleTimer.cancel();
       
        assertEquals(cluster.getClusterStatus().getDeadServers(), 1);
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.HBaseCluster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.