Search in sources :

Example 6 with InvalidCookieException

use of org.apache.bookkeeper.bookie.BookieException.InvalidCookieException in project bookkeeper by apache.

the class CookieTest method testRestartWithHostNameAsBookieID.

/**
 * Test restart bookie with useHostNameAsBookieID=true, which had cookie generated
 * with ipaddress.
 */
@Test
public void testRestartWithHostNameAsBookieID() throws Exception {
    String[] ledgerDirs = new String[] { newDirectory(), newDirectory(), newDirectory() };
    String journalDir = newDirectory();
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    conf.setJournalDirName(journalDir).setLedgerDirNames(ledgerDirs).setBookiePort(bookiePort).setZkServers(zkUtil.getZooKeeperConnectString());
    // should work fine
    Bookie b = new Bookie(conf);
    b.start();
    b.shutdown();
    conf.setUseHostNameAsBookieID(true);
    try {
        new Bookie(conf);
        fail("Should not start a bookie with hostname if the bookie has been started with an ip");
    } catch (InvalidCookieException e) {
    // expected
    }
}
Also used : InvalidCookieException(org.apache.bookkeeper.bookie.BookieException.InvalidCookieException) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) Test(org.junit.Test)

Example 7 with InvalidCookieException

use of org.apache.bookkeeper.bookie.BookieException.InvalidCookieException in project incubator-pulsar by apache.

the class LocalBookkeeperEnsemble method runBookies.

private void runBookies(ServerConfiguration baseConf) throws Exception {
    LOG.info("Starting Bookie(s)");
    // Create Bookie Servers (B1, B2, B3)
    bs = new BookieServer[numberOfBookies];
    bsConfs = new ServerConfiguration[numberOfBookies];
    for (int i = 0; i < numberOfBookies; i++) {
        File bkDataDir = isNotBlank(bkDataDirName) ? Files.createDirectories(Paths.get(bkDataDirName + Integer.toString(i))).toFile() : Files.createTempDirectory("bk" + Integer.toString(i) + "test").toFile();
        if (this.clearOldData) {
            cleanDirectory(bkDataDir);
        }
        bsConfs[i] = new ServerConfiguration(baseConf);
        // override settings
        bsConfs[i].setBookiePort(initialPort + i);
        bsConfs[i].setZkServers("127.0.0.1:" + ZooKeeperDefaultPort);
        bsConfs[i].setJournalDirName(bkDataDir.getPath());
        bsConfs[i].setLedgerDirNames(new String[] { bkDataDir.getPath() });
        bsConfs[i].setAllowLoopback(true);
        bsConfs[i].setGcWaitTime(60000);
        try {
            bs[i] = new BookieServer(bsConfs[i], NullStatsLogger.INSTANCE);
        } catch (InvalidCookieException e) {
            // from localhost, we can ignore the error
            for (String path : zkc.getChildren("/ledgers/cookies", false)) {
                zkc.delete("/ledgers/cookies/" + path, -1);
            }
            // Also clean the on-disk cookie
            new File(new File(bkDataDir, "current"), "VERSION").delete();
            // Retry to start the bookie after cleaning the old left cookie
            bs[i] = new BookieServer(bsConfs[i], NullStatsLogger.INSTANCE);
        }
        bs[i].start();
        LOG.debug("Local BK[{}] started (port: {}, data_directory: {})", i, initialPort + i, bkDataDir.getAbsolutePath());
    }
}
Also used : InvalidCookieException(org.apache.bookkeeper.bookie.BookieException.InvalidCookieException) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) File(java.io.File)

Aggregations

InvalidCookieException (org.apache.bookkeeper.bookie.BookieException.InvalidCookieException)7 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)4 File (java.io.File)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1 List (java.util.List)1 Set (java.util.Set)1 RegistrationManager (org.apache.bookkeeper.discover.RegistrationManager)1 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)1 BookieServer (org.apache.bookkeeper.proto.BookieServer)1 Versioned (org.apache.bookkeeper.versioning.Versioned)1