Search in sources :

Example 1 with Abortable

use of org.apache.hadoop.hbase.Abortable in project hbase by apache.

the class ReplicationSyncUp method run.

@Override
public int run(String[] args) throws Exception {
    Replication replication;
    ReplicationSourceManager manager;
    FileSystem fs;
    Path oldLogDir, logDir, walRootDir;
    ZooKeeperWatcher zkw;
    Abortable abortable = new Abortable() {

        @Override
        public void abort(String why, Throwable e) {
        }

        @Override
        public boolean isAborted() {
            return false;
        }
    };
    zkw = new ZooKeeperWatcher(conf, "syncupReplication" + System.currentTimeMillis(), abortable, true);
    walRootDir = FSUtils.getWALRootDir(conf);
    fs = FSUtils.getWALFileSystem(conf);
    oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
    logDir = new Path(walRootDir, HConstants.HREGION_LOGDIR_NAME);
    System.out.println("Start Replication Server start");
    replication = new Replication(new DummyServer(zkw), fs, logDir, oldLogDir);
    manager = replication.getReplicationManager();
    manager.init();
    try {
        // default wait once
        int numberOfOldSource = 1;
        while (numberOfOldSource > 0) {
            Thread.sleep(SLEEP_TIME);
            numberOfOldSource = manager.getOldSources().size();
        }
    } catch (InterruptedException e) {
        System.err.println("didn't wait long enough:" + e);
        return (-1);
    }
    manager.join();
    zkw.close();
    return (0);
}
Also used : Path(org.apache.hadoop.fs.Path) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) Abortable(org.apache.hadoop.hbase.Abortable) FileSystem(org.apache.hadoop.fs.FileSystem)

Example 2 with Abortable

use of org.apache.hadoop.hbase.Abortable in project hbase by apache.

the class TestMasterCoprocessorExceptionWithRemove method testExceptionFromCoprocessorWhenCreatingTable.

@Test(timeout = 30000)
public void testExceptionFromCoprocessorWhenCreatingTable() throws IOException {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    BuggyMasterObserver cp = (BuggyMasterObserver) host.findCoprocessor(BuggyMasterObserver.class.getName());
    assertFalse("No table created yet", cp.wasCreateTableCalled());
    // Set a watch on the zookeeper /hbase/master node. If the master dies,
    // the node will be deleted.
    // Master should *NOT* die:
    // we are testing that the default setting of hbase.coprocessor.abortonerror
    // =false
    // is respected.
    ZooKeeperWatcher zkw = new ZooKeeperWatcher(UTIL.getConfiguration(), "unittest", new Abortable() {

        @Override
        public void abort(String why, Throwable e) {
            throw new RuntimeException("Fatal ZK error: " + why, e);
        }

        @Override
        public boolean isAborted() {
            return false;
        }
    });
    MasterTracker masterTracker = new MasterTracker(zkw, "/hbase/master", new Abortable() {

        @Override
        public void abort(String why, Throwable e) {
            throw new RuntimeException("Fatal ZooKeeper tracker error, why=", e);
        }

        @Override
        public boolean isAborted() {
            return false;
        }
    });
    masterTracker.start();
    zkw.registerListener(masterTracker);
    // Test (part of the) output that should have be printed by master when it aborts:
    // (namely the part that shows the set of loaded coprocessors).
    // In this test, there is only a single coprocessor (BuggyMasterObserver).
    String coprocessorName = BuggyMasterObserver.class.getName();
    assertTrue(HMaster.getLoadedCoprocessors().contains(coprocessorName));
    HTableDescriptor htd1 = new HTableDescriptor(TableName.valueOf(TEST_TABLE1));
    htd1.addFamily(new HColumnDescriptor(TEST_FAMILY1));
    boolean threwDNRE = false;
    try {
        Admin admin = UTIL.getAdmin();
        admin.createTable(htd1);
    } catch (IOException e) {
        if (e.getClass().getName().equals("org.apache.hadoop.hbase.DoNotRetryIOException")) {
            threwDNRE = true;
        }
    } finally {
        assertTrue(threwDNRE);
    }
    // wait for a few seconds to make sure that the Master hasn't aborted.
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        fail("InterruptedException while sleeping.");
    }
    assertFalse("Master survived coprocessor NPE, as expected.", masterTracker.masterZKNodeWasDeleted);
    String loadedCoprocessors = HMaster.getLoadedCoprocessors();
    assertTrue(loadedCoprocessors.contains(coprocessorName));
    // Verify that BuggyMasterObserver has been removed due to its misbehavior
    // by creating another table: should not have a problem this time.
    HTableDescriptor htd2 = new HTableDescriptor(TableName.valueOf(TEST_TABLE2));
    htd2.addFamily(new HColumnDescriptor(TEST_FAMILY2));
    Admin admin = UTIL.getAdmin();
    try {
        admin.createTable(htd2);
    } catch (IOException e) {
        fail("Failed to create table after buggy coprocessor removal: " + e);
    }
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) Abortable(org.apache.hadoop.hbase.Abortable) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 3 with Abortable

use of org.apache.hadoop.hbase.Abortable in project hbase by apache.

the class TestEntityLocks method testHeartbeatException.

/**
   * Test that abort is called when lockHeartbeat fails with IOException.
   */
@Test
public void testHeartbeatException() throws Exception {
    // in ms
    final long workerSleepTime = 100;
    Abortable abortable = Mockito.mock(Abortable.class);
    EntityLock lock = admin.namespaceLock("namespace", "description", abortable);
    lock.setTestingSleepTime(workerSleepTime);
    when(master.requestLock(any(), any())).thenReturn(LockResponse.newBuilder().setProcId(procId).build());
    when(master.lockHeartbeat(any(), any())).thenReturn(LOCKED_RESPONSE).thenThrow(new ServiceException("Failed heartbeat!"));
    lock.requestLock();
    lock.await();
    assertTrue(waitLockTimeOut(lock, 100 * workerSleepTime));
    verify(abortable, times(1)).abort(any(), isA(HBaseIOException.class));
    assertFalse(lock.getWorker().isAlive());
}
Also used : ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) Abortable(org.apache.hadoop.hbase.Abortable) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) Test(org.junit.Test)

Example 4 with Abortable

use of org.apache.hadoop.hbase.Abortable in project hbase by apache.

the class TestRpcHandlerException method testRpcScheduler.

/*
   * This is a unit test to make sure to abort region server when the number of Rpc handler thread
   * caught errors exceeds the threshold. Client will hang when RS aborts.
   */
@Ignore
@Test
public void testRpcScheduler() throws IOException, InterruptedException {
    PriorityFunction qosFunction = mock(PriorityFunction.class);
    Abortable abortable = new AbortServer();
    RpcScheduler scheduler = new SimpleRpcScheduler(CONF, 2, 0, 0, qosFunction, abortable, 0);
    RpcServer rpcServer = RpcServerFactory.createRpcServer(null, "testRpcServer", Lists.newArrayList(new BlockingServiceAndInterface((BlockingService) SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, scheduler);
    try (BlockingRpcClient client = new BlockingRpcClient(CONF)) {
        rpcServer.start();
        BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
        stub.echo(null, EchoRequestProto.newBuilder().setMessage("hello").build());
    } catch (Throwable e) {
        assert (abortable.isAborted() == true);
    } finally {
        rpcServer.stop();
    }
}
Also used : BlockingInterface(org.apache.hadoop.hbase.shaded.ipc.protobuf.generated.TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface) BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) Abortable(org.apache.hadoop.hbase.Abortable) InetSocketAddress(java.net.InetSocketAddress) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Abortable

use of org.apache.hadoop.hbase.Abortable in project hbase by apache.

the class TestZKMulti method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.startMiniZKCluster();
    Configuration conf = TEST_UTIL.getConfiguration();
    Abortable abortable = new Abortable() {

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

        @Override
        public boolean isAborted() {
            return false;
        }
    };
    zkw = new ZooKeeperWatcher(conf, "TestZKMulti", abortable, true);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Abortable(org.apache.hadoop.hbase.Abortable) BeforeClass(org.junit.BeforeClass)

Aggregations

Abortable (org.apache.hadoop.hbase.Abortable)18 Test (org.junit.Test)12 Configuration (org.apache.hadoop.conf.Configuration)10 ExecutorService (java.util.concurrent.ExecutorService)7 Stoppable (org.apache.hadoop.hbase.Stoppable)7 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)7 StubAbortable (org.apache.phoenix.hbase.index.StubAbortable)7 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)6 HashMap (java.util.HashMap)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)5 Mutation (org.apache.hadoop.hbase.client.Mutation)5 Put (org.apache.hadoop.hbase.client.Put)5 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 IOException (java.io.IOException)3 Pair (org.apache.hadoop.hbase.util.Pair)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)2