Search in sources :

Example 21 with ZKWatcher

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

the class TestCleanupMetaReplicaThroughConfig method testReplicaCleanup.

@Test
public void testReplicaCleanup() throws Exception {
    ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
    List<String> metaReplicaZnodes = zkw.getMetaReplicaNodes();
    assertEquals(3, metaReplicaZnodes.size());
    final HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
    master.stop("Restarting");
    TEST_UTIL.waitFor(30000, () -> master.isStopped());
    TEST_UTIL.getMiniHBaseCluster().getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 1);
    JVMClusterUtil.MasterThread newMasterThread = TEST_UTIL.getMiniHBaseCluster().startMaster();
    final HMaster newMaster = newMasterThread.getMaster();
    // wait until new master finished meta replica assignment logic
    TEST_UTIL.waitFor(30000, () -> newMaster.getMasterQuotaManager() != null);
    TEST_UTIL.waitFor(30000, () -> TEST_UTIL.getZooKeeperWatcher().getMetaReplicaNodes().size() == 1);
}
Also used : JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 22 with ZKWatcher

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

the class TestReplicationHFileCleaner method testZooKeeperAbort.

/**
 * ReplicationHFileCleaner should be able to ride over ZooKeeper errors without aborting.
 */
@Test
public void testZooKeeperAbort() throws Exception {
    ReplicationHFileCleaner cleaner = new ReplicationHFileCleaner();
    List<FileStatus> dummyFiles = Lists.newArrayList(new FileStatus(100, false, 3, 100, EnvironmentEdgeManager.currentTime(), new Path("hfile1")), new FileStatus(100, false, 3, 100, EnvironmentEdgeManager.currentTime(), new Path("hfile2")));
    FaultyZooKeeperWatcher faultyZK = new FaultyZooKeeperWatcher(conf, "testZooKeeperAbort-faulty", null);
    try {
        faultyZK.init();
        cleaner.setConf(conf, faultyZK);
        // should keep all files due to a ConnectionLossException getting the queues znodes
        Iterable<FileStatus> toDelete = cleaner.getDeletableFiles(dummyFiles);
        assertFalse(toDelete.iterator().hasNext());
        assertFalse(cleaner.isStopped());
    } finally {
        faultyZK.close();
    }
    // when zk is working both files should be returned
    cleaner = new ReplicationHFileCleaner();
    ZKWatcher zkw = new ZKWatcher(conf, "testZooKeeperAbort-normal", null);
    try {
        cleaner.setConf(conf, zkw);
        Iterable<FileStatus> filesToDelete = cleaner.getDeletableFiles(dummyFiles);
        Iterator<FileStatus> iter = filesToDelete.iterator();
        assertTrue(iter.hasNext());
        assertEquals(new Path("hfile1"), iter.next().getPath());
        assertTrue(iter.hasNext());
        assertEquals(new Path("hfile2"), iter.next().getPath());
        assertFalse(iter.hasNext());
    } finally {
        zkw.close();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ReplicationHFileCleaner(org.apache.hadoop.hbase.replication.master.ReplicationHFileCleaner) FileStatus(org.apache.hadoop.fs.FileStatus) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) Test(org.junit.Test)

Example 23 with ZKWatcher

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

the class TestMasterStatusServlet method setupBasicMocks.

@Before
public void setupBasicMocks() {
    conf = HBaseConfiguration.create();
    master = Mockito.mock(HMaster.class);
    Mockito.doReturn(FAKE_HOST).when(master).getServerName();
    Mockito.doReturn(conf).when(master).getConfiguration();
    // Fake DeadServer
    DeadServer deadServer = Mockito.mock(DeadServer.class);
    // Fake serverManager
    ServerManager serverManager = Mockito.mock(ServerManager.class);
    Mockito.doReturn(1.0).when(serverManager).getAverageLoad();
    Mockito.doReturn(serverManager).when(master).getServerManager();
    Mockito.doReturn(deadServer).when(serverManager).getDeadServers();
    // Fake AssignmentManager and RIT
    AssignmentManager am = Mockito.mock(AssignmentManager.class);
    RegionStates rs = Mockito.mock(RegionStates.class);
    List<RegionState> regionsInTransition = new ArrayList<>();
    regionsInTransition.add(new RegionState(FAKE_HRI, RegionState.State.CLOSING, 12345L, FAKE_HOST));
    Mockito.doReturn(rs).when(am).getRegionStates();
    Mockito.doReturn(regionsInTransition).when(rs).getRegionsInTransition();
    Mockito.doReturn(am).when(master).getAssignmentManager();
    Mockito.doReturn(serverManager).when(master).getServerManager();
    // Fake ZKW
    ZKWatcher zkw = Mockito.mock(ZKWatcher.class);
    Mockito.doReturn(new ZNodePaths(conf)).when(zkw).getZNodePaths();
    Mockito.doReturn("fakequorum").when(zkw).getQuorum();
    Mockito.doReturn(zkw).when(master).getZooKeeper();
    // Fake ActiveMaster
    Mockito.doReturn(Optional.of(FAKE_HOST)).when(master).getActiveMaster();
    // Mock admin
    admin = Mockito.mock(Admin.class);
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) RegionState(org.apache.hadoop.hbase.master.RegionState) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) ArrayList(java.util.ArrayList) ZNodePaths(org.apache.hadoop.hbase.zookeeper.ZNodePaths) Admin(org.apache.hadoop.hbase.client.Admin) DeadServer(org.apache.hadoop.hbase.master.DeadServer) Before(org.junit.Before)

Example 24 with ZKWatcher

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

the class TestLogsCleaner method testZooKeeperNormal.

/**
 * When zk is working both files should be returned
 * @throws Exception from ZK watcher
 */
@Test
public void testZooKeeperNormal() throws Exception {
    ReplicationLogCleaner cleaner = new ReplicationLogCleaner();
    // Subtract 1000 from current time so modtime is for sure older
    // than 'now'.
    long modTime = EnvironmentEdgeManager.currentTime() - 1000;
    List<FileStatus> dummyFiles = Arrays.asList(new FileStatus(100, false, 3, 100, modTime, new Path("log1")), new FileStatus(100, false, 3, 100, modTime, new Path("log2")));
    ZKWatcher zkw = new ZKWatcher(conf, "testZooKeeperAbort-normal", null);
    try {
        cleaner.setConf(conf, zkw);
        cleaner.preClean();
        Iterable<FileStatus> filesToDelete = cleaner.getDeletableFiles(dummyFiles);
        Iterator<FileStatus> iter = filesToDelete.iterator();
        assertTrue(iter.hasNext());
        assertEquals(new Path("log1"), iter.next().getPath());
        assertTrue(iter.hasNext());
        assertEquals(new Path("log2"), iter.next().getPath());
        assertFalse(iter.hasNext());
    } finally {
        zkw.close();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) ReplicationLogCleaner(org.apache.hadoop.hbase.replication.master.ReplicationLogCleaner) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) Test(org.junit.Test)

Example 25 with ZKWatcher

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

the class TestAccessController2 method testACLZNodeDeletion.

@Test
public void testACLZNodeDeletion() throws Exception {
    String baseAclZNode = "/hbase/acl/";
    String ns = "testACLZNodeDeletionNamespace";
    NamespaceDescriptor desc = NamespaceDescriptor.create(ns).build();
    createNamespace(TEST_UTIL, desc);
    final TableName table = TableName.valueOf(ns, "testACLZNodeDeletionTable");
    final byte[] family = Bytes.toBytes("f1");
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(table).setColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build();
    createTable(TEST_UTIL, tableDescriptor);
    // Namespace needs this, as they follow the lazy creation of ACL znode.
    grantOnNamespace(TEST_UTIL, TESTGROUP1_USER1.getShortName(), ns, Action.ADMIN);
    ZKWatcher zkw = TEST_UTIL.getMiniHBaseCluster().getMaster().getZooKeeper();
    assertTrue("The acl znode for table should exist", ZKUtil.checkExists(zkw, baseAclZNode + table.getNameAsString()) != -1);
    assertTrue("The acl znode for namespace should exist", ZKUtil.checkExists(zkw, baseAclZNode + convertToNamespace(ns)) != -1);
    revokeFromNamespace(TEST_UTIL, TESTGROUP1_USER1.getShortName(), ns, Action.ADMIN);
    deleteTable(TEST_UTIL, table);
    deleteNamespace(TEST_UTIL, ns);
    assertTrue("The acl znode for table should have been deleted", ZKUtil.checkExists(zkw, baseAclZNode + table.getNameAsString()) == -1);
    assertTrue("The acl znode for namespace should have been deleted", ZKUtil.checkExists(zkw, baseAclZNode + convertToNamespace(ns)) == -1);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

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