Search in sources :

Example 81 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestMetaWithReplicas method shutdownMetaAndDoValidations.

public static void shutdownMetaAndDoValidations(HBaseTestingUtility util) throws Exception {
    // This test creates a table, flushes the meta (with 3 replicas), kills the
    // server holding the primary meta replica. Then it does a put/get into/from
    // the test table. The put/get operations would use the replicas to locate the
    // location of the test table's region
    ZooKeeperWatcher zkw = util.getZooKeeperWatcher();
    Configuration conf = util.getConfiguration();
    conf.setBoolean(HConstants.USE_META_REPLICAS, true);
    String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
    String primaryMetaZnode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server"));
    byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
    ServerName primary = ProtobufUtil.toServerName(data);
    TableName TABLE = TableName.valueOf("testShutdownHandling");
    byte[][] FAMILIES = new byte[][] { Bytes.toBytes("foo") };
    if (util.getAdmin().tableExists(TABLE)) {
        util.getAdmin().disableTable(TABLE);
        util.getAdmin().deleteTable(TABLE);
    }
    ServerName master = null;
    try (Connection c = ConnectionFactory.createConnection(util.getConfiguration())) {
        try (Table htable = util.createTable(TABLE, FAMILIES)) {
            util.getAdmin().flush(TableName.META_TABLE_NAME);
            Thread.sleep(conf.getInt(StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, 30000) * 6);
            List<HRegionInfo> regions = MetaTableAccessor.getTableRegions(c, TABLE);
            HRegionLocation hrl = MetaTableAccessor.getRegionLocation(c, regions.get(0));
            // to another random server
            if (hrl.getServerName().equals(primary)) {
                util.getAdmin().move(hrl.getRegionInfo().getEncodedNameAsBytes(), null);
                // wait for the move to complete
                do {
                    Thread.sleep(10);
                    hrl = MetaTableAccessor.getRegionLocation(c, regions.get(0));
                } while (primary.equals(hrl.getServerName()));
                util.getAdmin().flush(TableName.META_TABLE_NAME);
                Thread.sleep(conf.getInt(StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, 30000) * 3);
            }
            master = util.getHBaseClusterInterface().getClusterStatus().getMaster();
            // kill the master so that regionserver recovery is not triggered at all
            // for the meta server
            util.getHBaseClusterInterface().stopMaster(master);
            util.getHBaseClusterInterface().waitForMasterToStop(master, 60000);
            if (!master.equals(primary)) {
                util.getHBaseClusterInterface().killRegionServer(primary);
                util.getHBaseClusterInterface().waitForRegionServerToStop(primary, 60000);
            }
            ((ClusterConnection) c).clearRegionCache();
        }
        Get get = null;
        Result r = null;
        byte[] row = "test".getBytes();
        try (Table htable = c.getTable(TABLE)) {
            Put put = new Put(row);
            put.addColumn("foo".getBytes(), row, row);
            BufferedMutator m = c.getBufferedMutator(TABLE);
            m.mutate(put);
            m.flush();
            // Try to do a get of the row that was just put
            get = new Get(row);
            r = htable.get(get);
            assertTrue(Arrays.equals(r.getRow(), row));
            // now start back the killed servers and disable use of replicas. That would mean
            // calls go to the primary
            util.getHBaseClusterInterface().startMaster(master.getHostname(), 0);
            util.getHBaseClusterInterface().startRegionServer(primary.getHostname(), 0);
            util.getHBaseClusterInterface().waitForActiveAndReadyMaster();
            ((ClusterConnection) c).clearRegionCache();
        }
        conf.setBoolean(HConstants.USE_META_REPLICAS, false);
        try (Table htable = c.getTable(TABLE)) {
            r = htable.get(get);
            assertTrue(Arrays.equals(r.getRow(), row));
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ServerName(org.apache.hadoop.hbase.ServerName)

Example 82 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestMetaWithReplicas method testMetaAddressChange.

@Test
public void testMetaAddressChange() throws Exception {
    // checks that even when the meta's location changes, the various
    // caches update themselves. Uses the master operations to test
    // this
    Configuration conf = TEST_UTIL.getConfiguration();
    ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
    String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
    String primaryMetaZnode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server"));
    // check that the data in the znode is parseable (this would also mean the znode exists)
    byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
    ServerName currentServer = ProtobufUtil.toServerName(data);
    Collection<ServerName> liveServers = TEST_UTIL.getAdmin().getClusterStatus().getServers();
    ServerName moveToServer = null;
    for (ServerName s : liveServers) {
        if (!currentServer.equals(s)) {
            moveToServer = s;
        }
    }
    assert (moveToServer != null);
    final TableName tableName = TableName.valueOf(name.getMethodName());
    TEST_UTIL.createTable(tableName, "f");
    assertTrue(TEST_UTIL.getAdmin().tableExists(tableName));
    TEST_UTIL.getAdmin().move(HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), Bytes.toBytes(moveToServer.getServerName()));
    int i = 0;
    do {
        Thread.sleep(10);
        data = ZKUtil.getData(zkw, primaryMetaZnode);
        currentServer = ProtobufUtil.toServerName(data);
        i++;
    } while (//wait for 10 seconds overall
    !moveToServer.equals(currentServer) && i < 1000);
    assert (i != 1000);
    TEST_UTIL.getAdmin().disableTable(tableName);
    assertTrue(TEST_UTIL.getAdmin().isTableDisabled(tableName));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Configuration(org.apache.hadoop.conf.Configuration) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 83 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestMetaWithReplicas method testZookeeperNodesForReplicas.

@Test
public void testZookeeperNodesForReplicas() throws Exception {
    // Checks all the znodes exist when meta's replicas are enabled
    ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
    Configuration conf = TEST_UTIL.getConfiguration();
    String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
    String primaryMetaZnode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server"));
    // check that the data in the znode is parseable (this would also mean the znode exists)
    byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
    ProtobufUtil.toServerName(data);
    for (int i = 1; i < 3; i++) {
        String secZnode = ZKUtil.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server") + "-" + i);
        String str = zkw.znodePaths.getZNodeForReplica(i);
        assertTrue(str.equals(secZnode));
        // check that the data in the znode is parseable (this would also mean the znode exists)
        data = ZKUtil.getData(zkw, secZnode);
        ProtobufUtil.toServerName(data);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) Test(org.junit.Test)

Example 84 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestMasterReplication method startMiniClusters.

@SuppressWarnings("resource")
private void startMiniClusters(int numClusters) throws Exception {
    Random random = new Random();
    utilities = new HBaseTestingUtility[numClusters];
    configurations = new Configuration[numClusters];
    for (int i = 0; i < numClusters; i++) {
        Configuration conf = new Configuration(baseConfiguration);
        conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/" + i + random.nextInt());
        HBaseTestingUtility utility = new HBaseTestingUtility(conf);
        if (i == 0) {
            utility.startMiniZKCluster();
            miniZK = utility.getZkCluster();
        } else {
            utility.setZkCluster(miniZK);
        }
        utility.startMiniCluster();
        utilities[i] = utility;
        configurations[i] = conf;
        new ZooKeeperWatcher(conf, "cluster" + i, null, true);
    }
}
Also used : Random(java.util.Random) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)

Example 85 with ZooKeeperWatcher

use of org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher in project hbase by apache.

the class TestMasterNoCluster method tearDown.

@After
public void tearDown() throws KeeperException, ZooKeeperConnectionException, IOException {
    // Make sure zk is clean before we run the next test.
    ZooKeeperWatcher zkw = new ZooKeeperWatcher(TESTUTIL.getConfiguration(), "@Before", new Abortable() {

        @Override
        public void abort(String why, Throwable e) {
            throw new RuntimeException(why, e);
        }

        @Override
        public boolean isAborted() {
            return false;
        }
    });
    ZKUtil.deleteNodeRecursively(zkw, zkw.znodePaths.baseZNode);
    zkw.close();
}
Also used : ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) Abortable(org.apache.hadoop.hbase.Abortable) After(org.junit.After)

Aggregations

ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)105 Test (org.junit.Test)46 Configuration (org.apache.hadoop.conf.Configuration)33 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)21 Table (org.apache.hadoop.hbase.client.Table)20 IOException (java.io.IOException)19 ServerName (org.apache.hadoop.hbase.ServerName)16 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)15 Ignore (org.junit.Ignore)15 ArrayList (java.util.ArrayList)14 RegionServerThread (org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)13 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)12 BeforeClass (org.junit.BeforeClass)12 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)11 List (java.util.List)10 KeeperException (org.apache.zookeeper.KeeperException)10 TimeoutException (java.util.concurrent.TimeoutException)9 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)9 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)9 Waiter (org.apache.hadoop.hbase.Waiter)9