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());
}
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());
}
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()));
}
}
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");
}
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();
}
Aggregations