Java Code Examples for org.apache.bookkeeper.proto.BookieServer#shutdown()

The following examples show how to use org.apache.bookkeeper.proto.BookieServer#shutdown() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalBookkeeperEnsemble.java    From pulsar with Apache License 2.0 6 votes vote down vote up
public void stop() throws Exception {
    if (null != streamStorage) {
        LOG.debug("Local bk stream storage stopping ...");
        streamStorage.close();
    }

    LOG.debug("Local ZK/BK stopping ...");
    for (BookieServer bookie : bs) {
        bookie.shutdown();
    }

    zkc.close();
    zks.shutdown();
    serverFactory.shutdown();
    LOG.debug("Local ZK/BK stopped");
}
 
Example 2
Source File: BookKeeperClusterTestCase.java    From pulsar with Apache License 2.0 6 votes vote down vote up
/**
 * Stop cluster. Also, stops all the auto recovery processes for the bookie cluster, if isAutoRecoveryEnabled is
 * true.
 *
 * @throws Exception
 */
protected void stopBKCluster() throws Exception {
    if (bkc != null) {
        bkc.close();
    }

    for (BookieServer server : bs) {
        server.shutdown();
        AutoRecoveryMain autoRecovery = autoRecoveryProcesses.get(server);
        if (autoRecovery != null && isAutoRecoveryEnabled()) {
            autoRecovery.shutdown();
            LOG.debug("Shutdown auto recovery for bookieserver:" + server.getLocalAddress());
        }
    }
    bs.clear();
    for (File f : tmpDirs) {
        FileUtils.deleteDirectory(f);
    }
}
 
Example 3
Source File: BookKeeperClusterTestCase.java    From pulsar with Apache License 2.0 6 votes vote down vote up
/**
 * Kill a bookie by its socket address. Also, stops the autorecovery process for the corresponding bookie server, if
 * isAutoRecoveryEnabled is true.
 *
 * @param addr
 *            Socket Address
 * @return the configuration of killed bookie
 * @throws InterruptedException
 */
public ServerConfiguration killBookie(InetSocketAddress addr) throws Exception {
    BookieServer toRemove = null;
    int toRemoveIndex = 0;
    for (BookieServer server : bs) {
        if (server.getLocalAddress().equals(addr)) {
            server.shutdown();
            toRemove = server;
            break;
        }
        ++toRemoveIndex;
    }
    if (toRemove != null) {
        stopAutoRecoveryService(toRemove);
        bs.remove(toRemove);
        return bsConfs.remove(toRemoveIndex);
    }
    return null;
}
 
Example 4
Source File: BookKeeperClusterTestCase.java    From pulsar with Apache License 2.0 6 votes vote down vote up
/**
 * Restart bookie servers using new configuration settings. Also restart the respective auto recovery process, if
 * isAutoRecoveryEnabled is true.
 *
 * @param newConf
 *            New Configuration Settings
 * @throws InterruptedException
 * @throws IOException
 * @throws KeeperException
 * @throws BookieException
 */
public void restartBookies(ServerConfiguration newConf) throws Exception {
    // shut down bookie server
    for (BookieServer server : bs) {
        server.shutdown();
        stopAutoRecoveryService(server);
    }
    bs.clear();
    Thread.sleep(1000);
    // restart them to ensure we can't

    List<ServerConfiguration> bsConfsCopy = new ArrayList<ServerConfiguration>(bsConfs);
    bsConfs.clear();
    for (ServerConfiguration conf : bsConfsCopy) {
        if (null != newConf) {
            conf.loadConf(newConf);
        }
        startBookie(conf);
    }
}
 
Example 5
Source File: TestBookKeeperSpeculativeRead.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void teardownBookkeeper() throws Exception {
  bkutil.teardown();
  for (BookieServer bk : bks) {
    bk.shutdown();
  }
}
 
Example 6
Source File: ZKTestEnv.java    From herddb with Apache License 2.0 5 votes vote down vote up
public void stopBookie(String addr) throws Exception {
    for (BookieServer bookie : bookies) {
        if (bookie.getLocalAddress().getSocketAddress().toString().equals(addr)) {
            bookie.shutdown();
            bookie.join();
            return;
        }
    }
    throw new Exception("Cannot find bookie " + addr);
}
 
Example 7
Source File: TestBookKeeperSpeculativeRead.java    From big-c with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void teardownBookkeeper() throws Exception {
  bkutil.teardown();
  for (BookieServer bk : bks) {
    bk.shutdown();
  }
}
 
Example 8
Source File: RackAwareTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@AfterClass
protected void shutdown() throws Exception {
    super.shutdown();

    for (BookieServer bs : bookies) {
        bs.shutdown();
    }

    bookies.clear();
}
 
Example 9
Source File: BookKeeperClusterTestCase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
/**
 * Kill a bookie by index. Also, stops the respective auto recovery process for this bookie, if
 * isAutoRecoveryEnabled is true.
 *
 * @param index
 *            Bookie Index
 * @return the configuration of killed bookie
 * @throws InterruptedException
 * @throws IOException
 */
public ServerConfiguration killBookie(int index) throws Exception {
    if (index >= bs.size()) {
        throw new IOException("Bookie does not exist");
    }
    BookieServer server = bs.get(index);
    server.shutdown();
    stopAutoRecoveryService(server);
    bs.remove(server);
    return bsConfs.remove(index);
}
 
Example 10
Source File: TestBookKeeperAsHASharedDir.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Test HA failover, where BK, as the shared storage, fails.
 * Once it becomes available again, a standby can come up.
 * Verify that any write happening after the BK fail is not
 * available on the standby.
 */
@Test
public void testFailoverWithFailingBKCluster() throws Exception {
  int ensembleSize = numBookies + 1;
  BookieServer newBookie = bkutil.newBookie();
  assertEquals("New bookie didn't start",
               ensembleSize, bkutil.checkBookiesUp(ensembleSize, 10));

  BookieServer replacementBookie = null;

  MiniDFSCluster cluster = null;

  try {
    Configuration conf = new Configuration();
    conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
    conf.set(DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY,
             BKJMUtil.createJournalURI("/hotfailoverWithFail").toString());
    conf.setInt(BookKeeperJournalManager.BKJM_BOOKKEEPER_ENSEMBLE_SIZE,
                ensembleSize);
    conf.setInt(BookKeeperJournalManager.BKJM_BOOKKEEPER_QUORUM_SIZE,
                ensembleSize);
    BKJMUtil.addJournalManagerDefinition(conf);

    cluster = new MiniDFSCluster.Builder(conf)
      .nnTopology(MiniDFSNNTopology.simpleHATopology())
      .numDataNodes(0)
      .manageNameDfsSharedDirs(false)
      .checkExitOnShutdown(false)
      .build();
    NameNode nn1 = cluster.getNameNode(0);
    NameNode nn2 = cluster.getNameNode(1);

    cluster.waitActive();
    cluster.transitionToActive(0);

    Path p1 = new Path("/testBKJMFailingBKCluster1");
    Path p2 = new Path("/testBKJMFailingBKCluster2");

    FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);

    fs.mkdirs(p1);
    newBookie.shutdown(); // will take down shared storage
    assertEquals("New bookie didn't stop",
                 numBookies, bkutil.checkBookiesUp(numBookies, 10));

    try {
      fs.mkdirs(p2);
      fail("mkdirs should result in the NN exiting");
    } catch (RemoteException re) {
      assertTrue(re.getClassName().contains("ExitException"));
    }
    cluster.shutdownNameNode(0);

    try {
      cluster.transitionToActive(1);
      fail("Shouldn't have been able to transition with bookies down");
    } catch (ExitException ee) {
      assertTrue("Should shutdown due to required journal failure",
          ee.getMessage().contains(
              "starting log segment 3 failed for required journal"));
    }

    replacementBookie = bkutil.newBookie();
    assertEquals("Replacement bookie didn't start",
                 ensembleSize, bkutil.checkBookiesUp(ensembleSize, 10));
    cluster.transitionToActive(1); // should work fine now

    assertTrue(fs.exists(p1));
    assertFalse(fs.exists(p2));
  } finally {
    newBookie.shutdown();
    if (replacementBookie != null) {
      replacementBookie.shutdown();
    }

    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
Example 11
Source File: TestBookKeeperAsHASharedDir.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Test HA failover, where BK, as the shared storage, fails.
 * Once it becomes available again, a standby can come up.
 * Verify that any write happening after the BK fail is not
 * available on the standby.
 */
@Test
public void testFailoverWithFailingBKCluster() throws Exception {
  int ensembleSize = numBookies + 1;
  BookieServer newBookie = bkutil.newBookie();
  assertEquals("New bookie didn't start",
               ensembleSize, bkutil.checkBookiesUp(ensembleSize, 10));

  BookieServer replacementBookie = null;

  MiniDFSCluster cluster = null;

  try {
    Configuration conf = new Configuration();
    conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
    conf.set(DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY,
             BKJMUtil.createJournalURI("/hotfailoverWithFail").toString());
    conf.setInt(BookKeeperJournalManager.BKJM_BOOKKEEPER_ENSEMBLE_SIZE,
                ensembleSize);
    conf.setInt(BookKeeperJournalManager.BKJM_BOOKKEEPER_QUORUM_SIZE,
                ensembleSize);
    BKJMUtil.addJournalManagerDefinition(conf);

    cluster = new MiniDFSCluster.Builder(conf)
      .nnTopology(MiniDFSNNTopology.simpleHATopology())
      .numDataNodes(0)
      .manageNameDfsSharedDirs(false)
      .checkExitOnShutdown(false)
      .build();
    NameNode nn1 = cluster.getNameNode(0);
    NameNode nn2 = cluster.getNameNode(1);

    cluster.waitActive();
    cluster.transitionToActive(0);

    Path p1 = new Path("/testBKJMFailingBKCluster1");
    Path p2 = new Path("/testBKJMFailingBKCluster2");

    FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);

    fs.mkdirs(p1);
    newBookie.shutdown(); // will take down shared storage
    assertEquals("New bookie didn't stop",
                 numBookies, bkutil.checkBookiesUp(numBookies, 10));

    try {
      fs.mkdirs(p2);
      fail("mkdirs should result in the NN exiting");
    } catch (RemoteException re) {
      assertTrue(re.getClassName().contains("ExitException"));
    }
    cluster.shutdownNameNode(0);

    try {
      cluster.transitionToActive(1);
      fail("Shouldn't have been able to transition with bookies down");
    } catch (ExitException ee) {
      assertTrue("Should shutdown due to required journal failure",
          ee.getMessage().contains(
              "starting log segment 3 failed for required journal"));
    }

    replacementBookie = bkutil.newBookie();
    assertEquals("Replacement bookie didn't start",
                 ensembleSize, bkutil.checkBookiesUp(ensembleSize, 10));
    cluster.transitionToActive(1); // should work fine now

    assertTrue(fs.exists(p1));
    assertFalse(fs.exists(p2));
  } finally {
    newBookie.shutdown();
    if (replacementBookie != null) {
      replacementBookie.shutdown();
    }

    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
Example 12
Source File: LocalBookkeeperEnsemble.java    From pulsar with Apache License 2.0 4 votes vote down vote up
public void stopBK() {
    LOG.debug("Local ZK/BK stopping ...");
    for (BookieServer bookie : bs) {
        bookie.shutdown();
    }
}