Search in sources :

Example 6 with BookieImpl

use of org.apache.bookkeeper.bookie.BookieImpl in project bookkeeper by apache.

the class ReadOnlyBookieTest method testBookieShutdownIfReadOnlyModeNotEnabled.

/**
 * check readOnlyModeEnabled=false.
 */
@Test
public void testBookieShutdownIfReadOnlyModeNotEnabled() throws Exception {
    killBookie(1);
    baseConf.setReadOnlyModeEnabled(false);
    startNewBookie();
    File[] ledgerDirs = confByIndex(1).getLedgerDirs();
    assertEquals("Only one ledger dir should be present", 1, ledgerDirs.length);
    BookieImpl bookie = (BookieImpl) serverByIndex(1).getBookie();
    LedgerHandle ledger = bkc.createLedger(2, 2, DigestType.MAC, "".getBytes());
    LedgerDirsManager ledgerDirsManager = bookie.getLedgerDirsManager();
    for (int i = 0; i < 10; i++) {
        ledger.addEntry("data".getBytes());
    }
    // Now add the current ledger dir to filled dirs list
    ledgerDirsManager.addToFilledDirs(new File(ledgerDirs[0], "current"));
    try {
        ledger.addEntry("data".getBytes());
        fail("Should fail to add entry since there isn't enough bookies alive.");
    } catch (BKException.BKNotEnoughBookiesException e) {
    // Expected
    }
    // wait for up to 10 seconds for bookie to shut down
    for (int i = 0; i < 10 && bookie.isAlive(); i++) {
        Thread.sleep(1000);
    }
    assertFalse("Bookie should shutdown if readOnlyMode not enabled", bookie.isAlive());
}
Also used : BookieImpl(org.apache.bookkeeper.bookie.BookieImpl) LedgerDirsManager(org.apache.bookkeeper.bookie.LedgerDirsManager) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) BKException(org.apache.bookkeeper.client.BKException) File(java.io.File) Test(org.junit.Test)

Example 7 with BookieImpl

use of org.apache.bookkeeper.bookie.BookieImpl in project bookkeeper by apache.

the class ReadOnlyBookieTest method testBookieContinueWritingIfMultipleLedgersPresent.

/**
 * Check multiple ledger dirs.
 */
@Test
public void testBookieContinueWritingIfMultipleLedgersPresent() throws Exception {
    startNewBookieWithMultipleLedgerDirs(2);
    File[] ledgerDirs = confByIndex(1).getLedgerDirs();
    assertEquals("Only one ledger dir should be present", 2, ledgerDirs.length);
    BookieImpl bookie = (BookieImpl) serverByIndex(1).getBookie();
    LedgerHandle ledger = bkc.createLedger(2, 2, DigestType.MAC, "".getBytes());
    LedgerDirsManager ledgerDirsManager = bookie.getLedgerDirsManager();
    for (int i = 0; i < 10; i++) {
        ledger.addEntry("data".getBytes());
    }
    // Now add the current ledger dir to filled dirs list
    ledgerDirsManager.addToFilledDirs(new File(ledgerDirs[0], "current"));
    for (int i = 0; i < 10; i++) {
        ledger.addEntry("data".getBytes());
    }
    assertEquals("writable dirs should have one dir", 1, ledgerDirsManager.getWritableLedgerDirs().size());
    assertTrue("Bookie should shutdown if readOnlyMode not enabled", bookie.isAlive());
}
Also used : BookieImpl(org.apache.bookkeeper.bookie.BookieImpl) LedgerDirsManager(org.apache.bookkeeper.bookie.LedgerDirsManager) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) File(java.io.File) Test(org.junit.Test)

Example 8 with BookieImpl

use of org.apache.bookkeeper.bookie.BookieImpl in project bookkeeper by apache.

the class ReadOnlyBookieTest method testBookieShouldServeAsReadOnly.

/**
 * Check readonly bookie.
 */
@Test
public void testBookieShouldServeAsReadOnly() throws Exception {
    killBookie(0);
    baseConf.setReadOnlyModeEnabled(true);
    startNewBookie();
    LedgerHandle ledger = bkc.createLedger(2, 2, DigestType.MAC, "".getBytes());
    // Check new bookie with readonly mode enabled.
    File[] ledgerDirs = confByIndex(1).getLedgerDirs();
    assertEquals("Only one ledger dir should be present", 1, ledgerDirs.length);
    Bookie bookie = serverByIndex(1).getBookie();
    LedgerDirsManager ledgerDirsManager = ((BookieImpl) bookie).getLedgerDirsManager();
    for (int i = 0; i < 10; i++) {
        ledger.addEntry("data".getBytes());
    }
    // Now add the current ledger dir to filled dirs list
    ledgerDirsManager.addToFilledDirs(new File(ledgerDirs[0], "current"));
    try {
        ledger.addEntry("data".getBytes());
        fail("Should fail to add entry since there isn't enough bookies alive.");
    } catch (BKException.BKNotEnoughBookiesException e) {
    // Expected
    }
    assertTrue("Bookie should be running and converted to readonly mode", bookie.isRunning() && bookie.isReadOnly());
    // Now kill the other bookie and read entries from the readonly bookie
    killBookie(0);
    Enumeration<LedgerEntry> readEntries = ledger.readEntries(0, 9);
    while (readEntries.hasMoreElements()) {
        LedgerEntry entry = readEntries.nextElement();
        assertEquals("Entry should contain correct data", "data", new String(entry.getEntry()));
    }
}
Also used : BookieImpl(org.apache.bookkeeper.bookie.BookieImpl) LedgerDirsManager(org.apache.bookkeeper.bookie.LedgerDirsManager) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) Bookie(org.apache.bookkeeper.bookie.Bookie) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) BKException(org.apache.bookkeeper.client.BKException) File(java.io.File) Test(org.junit.Test)

Example 9 with BookieImpl

use of org.apache.bookkeeper.bookie.BookieImpl in project bookkeeper by apache.

the class ForceReadOnlyBookieTest method testBookieForceStartAsReadOnly.

/**
 * Check force start readonly bookie.
 */
@Test
public void testBookieForceStartAsReadOnly() throws Exception {
    // create ledger, add entries
    LedgerHandle ledger = bkc.createLedger(2, 2, DigestType.MAC, "".getBytes());
    for (int i = 0; i < 10; i++) {
        ledger.addEntry("data".getBytes());
    }
    ledger.close();
    LOG.info("successed prepare");
    // start bookie 1 as readonly
    confByIndex(1).setReadOnlyModeEnabled(true);
    confByIndex(1).setForceReadOnlyBookie(true);
    restartBookies();
    Bookie bookie = serverByIndex(1).getBookie();
    assertTrue("Bookie should be running and in readonly mode", bookie.isRunning() && bookie.isReadOnly());
    LOG.info("successed force start ReadOnlyBookie");
    // Check new bookie with readonly mode enabled.
    File[] ledgerDirs = confByIndex(1).getLedgerDirs();
    assertEquals("Only one ledger dir should be present", 1, ledgerDirs.length);
    // kill the writable bookie
    killBookie(0);
    // read entry from read only bookie
    Enumeration<LedgerEntry> readEntries = ledger.readEntries(0, 9);
    while (readEntries.hasMoreElements()) {
        LedgerEntry entry = readEntries.nextElement();
        assertEquals("Entry should contain correct data", "data", new String(entry.getEntry()));
    }
    LOG.info("successed read entry from ReadOnlyBookie");
    // test will not transfer to Writable mode.
    LedgerDirsManager ledgerDirsManager = ((BookieImpl) bookie).getLedgerDirsManager();
    ledgerDirsManager.addToWritableDirs(new File(ledgerDirs[0], "current"), true);
    assertTrue("Bookie should be running and in readonly mode", bookie.isRunning() && bookie.isReadOnly());
    LOG.info("successed: bookie still readonly");
}
Also used : BookieImpl(org.apache.bookkeeper.bookie.BookieImpl) LedgerDirsManager(org.apache.bookkeeper.bookie.LedgerDirsManager) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) Bookie(org.apache.bookkeeper.bookie.Bookie) LedgerEntry(org.apache.bookkeeper.client.LedgerEntry) File(java.io.File) Test(org.junit.Test)

Example 10 with BookieImpl

use of org.apache.bookkeeper.bookie.BookieImpl in project bookkeeper by apache.

the class DbLedgerStorageTest method setup.

@Before
public void setup() throws Exception {
    tmpDir = File.createTempFile("bkTest", ".dir");
    tmpDir.delete();
    tmpDir.mkdir();
    File curDir = BookieImpl.getCurrentDirectory(tmpDir);
    BookieImpl.checkDirectoryStructure(curDir);
    int gcWaitTime = 1000;
    conf = TestBKConfiguration.newServerConfiguration();
    conf.setGcWaitTime(gcWaitTime);
    conf.setLedgerStorageClass(DbLedgerStorage.class.getName());
    conf.setLedgerDirNames(new String[] { tmpDir.toString() });
    BookieImpl bookie = new TestBookieImpl(conf);
    ledgerDirsManager = bookie.getLedgerDirsManager();
    storage = (DbLedgerStorage) bookie.getLedgerStorage();
}
Also used : TestBookieImpl(org.apache.bookkeeper.bookie.TestBookieImpl) BookieImpl(org.apache.bookkeeper.bookie.BookieImpl) TestBookieImpl(org.apache.bookkeeper.bookie.TestBookieImpl) File(java.io.File) Before(org.junit.Before)

Aggregations

BookieImpl (org.apache.bookkeeper.bookie.BookieImpl)18 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)9 BookieId (org.apache.bookkeeper.net.BookieId)9 File (java.io.File)8 Cleanup (lombok.Cleanup)8 LedgerDirsManager (org.apache.bookkeeper.bookie.LedgerDirsManager)8 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)8 BookieServer (org.apache.bookkeeper.proto.BookieServer)8 PulsarService (org.apache.pulsar.broker.PulsarService)8 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)8 ModularLoadManagerImpl (org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl)8 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)8 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)8 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)8 PulsarClient (org.apache.pulsar.client.api.PulsarClient)8 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)8 TenantInfoImpl (org.apache.pulsar.common.policies.data.TenantInfoImpl)8 ZooKeeper (org.apache.zookeeper.ZooKeeper)8 Test (org.testng.annotations.Test)8 BookKeeper (org.apache.bookkeeper.client.BookKeeper)7