Search in sources :

Example 6 with ZKWatcher

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

the class DumpReplicationQueues method dumpReplicationQueues.

private int dumpReplicationQueues(DumpOptions opts) throws Exception {
    Configuration conf = getConf();
    Connection connection = ConnectionFactory.createConnection(conf);
    Admin admin = connection.getAdmin();
    ZKWatcher zkw = new ZKWatcher(conf, "DumpReplicationQueues" + EnvironmentEdgeManager.currentTime(), new WarnOnlyAbortable(), true);
    try {
        // Our zk watcher
        LOG.info("Our Quorum: " + zkw.getQuorum());
        List<TableCFs> replicatedTableCFs = admin.listReplicatedTableCFs();
        if (replicatedTableCFs.isEmpty()) {
            LOG.info("No tables with a configured replication peer were found.");
            return (0);
        } else {
            LOG.info("Replicated Tables: " + replicatedTableCFs);
        }
        List<ReplicationPeerDescription> peers = admin.listReplicationPeers();
        if (peers.isEmpty()) {
            LOG.info("Replication is enabled but no peer configuration was found.");
        }
        System.out.println("Dumping replication peers and configurations:");
        System.out.println(dumpPeersState(peers));
        if (opts.isDistributed()) {
            LOG.info("Found [--distributed], will poll each RegionServer.");
            Set<String> peerIds = peers.stream().map((peer) -> peer.getPeerId()).collect(Collectors.toSet());
            System.out.println(dumpQueues(zkw, peerIds, opts.isHdfs()));
            System.out.println(dumpReplicationSummary());
        } else {
            // use ZK instead
            System.out.print("Dumping replication znodes via ZooKeeper:");
            System.out.println(ZKDump.getReplicationZnodesDump(zkw));
        }
        return (0);
    } catch (IOException e) {
        return (-1);
    } finally {
        zkw.close();
    }
}
Also used : StringUtils(org.apache.hadoop.hbase.procedure2.util.StringUtils) Arrays(java.util.Arrays) FileSystem(org.apache.hadoop.fs.FileSystem) ReplicationStorageFactory(org.apache.hadoop.hbase.replication.ReplicationStorageFactory) LoggerFactory(org.slf4j.LoggerFactory) FileStatus(org.apache.hadoop.fs.FileStatus) ReplicationQueueStorage(org.apache.hadoop.hbase.replication.ReplicationQueueStorage) ArrayList(java.util.ArrayList) WALLink(org.apache.hadoop.hbase.io.WALLink) ReplicationQueueInfo(org.apache.hadoop.hbase.replication.ReplicationQueueInfo) AtomicLongMap(org.apache.hbase.thirdparty.com.google.common.util.concurrent.AtomicLongMap) Configured(org.apache.hadoop.conf.Configured) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) TableCFs(org.apache.hadoop.hbase.client.replication.TableCFs) LinkedList(java.util.LinkedList) ServerName(org.apache.hadoop.hbase.ServerName) Logger(org.slf4j.Logger) ZKUtil(org.apache.hadoop.hbase.zookeeper.ZKUtil) Abortable(org.apache.hadoop.hbase.Abortable) ToolRunner(org.apache.hadoop.util.ToolRunner) Set(java.util.Set) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) IOException(java.io.IOException) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) ConnectionFactory(org.apache.hadoop.hbase.client.ConnectionFactory) Tool(org.apache.hadoop.util.Tool) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Admin(org.apache.hadoop.hbase.client.Admin) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Connection(org.apache.hadoop.hbase.client.Connection) EnvironmentEdgeManager(org.apache.hadoop.hbase.util.EnvironmentEdgeManager) ReplicationPeerDescription(org.apache.hadoop.hbase.replication.ReplicationPeerDescription) Queue(java.util.Queue) Collections(java.util.Collections) ZKDump(org.apache.hadoop.hbase.zookeeper.ZKDump) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Connection(org.apache.hadoop.hbase.client.Connection) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) TableCFs(org.apache.hadoop.hbase.client.replication.TableCFs) ReplicationPeerDescription(org.apache.hadoop.hbase.replication.ReplicationPeerDescription)

Example 7 with ZKWatcher

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

the class TestMetaTableLocator method before.

@Before
public void before() throws IOException {
    this.abortable = new Abortable() {

        @Override
        public void abort(String why, Throwable e) {
            LOG.info(why, e);
        }

        @Override
        public boolean isAborted() {
            return false;
        }
    };
    this.watcher = new ZKWatcher(UTIL.getConfiguration(), this.getClass().getSimpleName(), this.abortable, true);
}
Also used : ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) Before(org.junit.Before)

Example 8 with ZKWatcher

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

the class TestMetaReplicasAddressChange 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();
    ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
    String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
    String primaryMetaZnode = ZNodePaths.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().getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet();
    ServerName moveToServer = liveServers.stream().filter(s -> !currentServer.equals(s)).findAny().get();
    final TableName tableName = name.getTableName();
    TEST_UTIL.createTable(tableName, "f");
    assertTrue(TEST_UTIL.getAdmin().tableExists(tableName));
    TEST_UTIL.getAdmin().move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), moveToServer);
    assertNotEquals(currentServer, moveToServer);
    LOG.debug("CurrentServer={}, moveToServer={}", currentServer, moveToServer);
    TEST_UTIL.waitFor(60000, () -> {
        byte[] bytes = ZKUtil.getData(zkw, primaryMetaZnode);
        ServerName actualServer = ProtobufUtil.toServerName(bytes);
        return moveToServer.equals(actualServer);
    });
    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) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 9 with ZKWatcher

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

the class TestMetaWithReplicasShutdownHandling method shutdownMetaAndDoValidations.

public static void shutdownMetaAndDoValidations(HBaseTestingUtil 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
    ZKWatcher 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 = ZNodePaths.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server"));
    byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
    ServerName primary = ProtobufUtil.toServerName(data);
    LOG.info("Primary=" + primary.toString());
    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);
    }
    byte[] row = Bytes.toBytes("test");
    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<RegionInfo> 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.getRegion().getEncodedNameAsBytes());
                // 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);
            }
            // Ensure all metas are not on same hbase:meta replica=0 server!
            master = util.getHBaseClusterInterface().getClusterMetrics().getMasterName();
            // kill the master so that regionserver recovery is not triggered at all
            // for the meta server
            LOG.info("Stopping master=" + master.toString());
            util.getHBaseClusterInterface().stopMaster(master);
            util.getHBaseClusterInterface().waitForMasterToStop(master, 60000);
            LOG.info("Master " + master + " stopped!");
            if (!master.equals(primary)) {
                util.getHBaseClusterInterface().killRegionServer(primary);
                util.getHBaseClusterInterface().waitForRegionServerToStop(primary, 60000);
            }
            c.clearRegionLocationCache();
        }
        LOG.info("Running GETs");
        try (Table htable = c.getTable(TABLE)) {
            Put put = new Put(row);
            put.addColumn(Bytes.toBytes("foo"), row, row);
            BufferedMutator m = c.getBufferedMutator(TABLE);
            m.mutate(put);
            m.flush();
            // Try to do a get of the row that was just put
            Result r = htable.get(new Get(row));
            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
            LOG.info("Starting Master");
            util.getHBaseClusterInterface().startMaster(master.getHostname(), 0);
            util.getHBaseClusterInterface().startRegionServer(primary.getHostname(), 0);
            util.getHBaseClusterInterface().waitForActiveAndReadyMaster();
            LOG.info("Master active!");
            c.clearRegionLocationCache();
        }
    }
    conf.setBoolean(HConstants.USE_META_REPLICAS, false);
    LOG.info("Running GETs no replicas");
    try (Connection c = ConnectionFactory.createConnection(conf);
        Table htable = c.getTable(TABLE)) {
        Result r = htable.get(new Get(row));
        assertArrayEquals(row, r.getRow());
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) ServerName(org.apache.hadoop.hbase.ServerName)

Example 10 with ZKWatcher

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

the class TestGlobalReplicationThrottler method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    conf1 = HBaseConfiguration.create();
    conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
    conf1.setLong("replication.source.sleepforretries", 100);
    // Each WAL is about 120 bytes
    conf1.setInt(HConstants.REPLICATION_SOURCE_TOTAL_BUFFER_KEY, REPLICATION_SOURCE_QUOTA);
    conf1.setLong("replication.source.per.peer.node.bandwidth", 100L);
    utility1 = new HBaseTestingUtil(conf1);
    utility1.startMiniZKCluster();
    MiniZooKeeperCluster miniZK = utility1.getZkCluster();
    new ZKWatcher(conf1, "cluster1", null, true);
    conf2 = new Configuration(conf1);
    conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
    utility2 = new HBaseTestingUtil(conf2);
    utility2.setZkCluster(miniZK);
    new ZKWatcher(conf2, "cluster2", null, true);
    ReplicationPeerConfig rpc = ReplicationPeerConfig.newBuilder().setClusterKey(utility2.getClusterKey()).build();
    utility1.startMiniCluster();
    utility2.startMiniCluster();
    try (Connection connection = ConnectionFactory.createConnection(utility1.getConfiguration());
        Admin admin1 = connection.getAdmin()) {
        admin1.addReplicationPeer("peer1", rpc);
        admin1.addReplicationPeer("peer2", rpc);
        admin1.addReplicationPeer("peer3", rpc);
        numOfPeer = admin1.listReplicationPeers().size();
    }
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) Connection(org.apache.hadoop.hbase.client.Connection) MiniZooKeeperCluster(org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Admin(org.apache.hadoop.hbase.client.Admin) BeforeClass(org.junit.BeforeClass)

Aggregations

ZKWatcher (org.apache.hadoop.hbase.zookeeper.ZKWatcher)66 Configuration (org.apache.hadoop.conf.Configuration)27 Test (org.junit.Test)24 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)13 ArrayList (java.util.ArrayList)10 ServerName (org.apache.hadoop.hbase.ServerName)10 IOException (java.io.IOException)8 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)8 Before (org.junit.Before)8 BeforeClass (org.junit.BeforeClass)8 Admin (org.apache.hadoop.hbase.client.Admin)7 Abortable (org.apache.hadoop.hbase.Abortable)6 HMaster (org.apache.hadoop.hbase.master.HMaster)6 MiniZooKeeperCluster (org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster)6 List (java.util.List)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)5 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)5 ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)5 KeeperException (org.apache.zookeeper.KeeperException)5 CountDownLatch (java.util.concurrent.CountDownLatch)4