use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestFencing method testFencingInteractionWithBookieRecovery.
/**
* create a ledger and write entries.
* kill a bookie in the ensemble. Recover.
* Fence the ledger. Kill another bookie. Recover.
*/
@Test
public void testFencingInteractionWithBookieRecovery() throws Exception {
System.setProperty("digestType", digestType.toString());
System.setProperty("passwd", "testPasswd");
BookKeeperAdmin admin = new BookKeeperAdmin(zkUtil.getZooKeeperConnectString());
LedgerHandle writelh = bkc.createLedger(digestType, "testPasswd".getBytes());
String tmp = "Foobar";
final int numEntries = 10;
for (int i = 0; i < numEntries; i++) {
writelh.addEntry(tmp.getBytes());
}
BookieSocketAddress bookieToKill = writelh.getLedgerMetadata().getEnsemble(numEntries).get(0);
killBookie(bookieToKill);
// write entries to change ensemble
for (int i = 0; i < numEntries; i++) {
writelh.addEntry(tmp.getBytes());
}
admin.recoverBookieData(bookieToKill);
for (int i = 0; i < numEntries; i++) {
writelh.addEntry(tmp.getBytes());
}
LedgerHandle readlh = bkc.openLedger(writelh.getId(), digestType, "testPasswd".getBytes());
try {
writelh.addEntry(tmp.getBytes());
LOG.error("Should have thrown an exception");
fail("Should have thrown an exception when trying to write");
} catch (BKException.BKLedgerFencedException e) {
// correct behaviour
}
readlh.close();
writelh.close();
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestLedgerChecker method testChecker.
/**
* Tests that the LedgerChecker should detect the underReplicated fragments
* on multiple Bookie crashes.
*/
@Test
public void testChecker() throws Exception {
LedgerHandle lh = bkc.createLedger(BookKeeper.DigestType.CRC32, TEST_LEDGER_PASSWORD);
startNewBookie();
for (int i = 0; i < 10; i++) {
lh.addEntry(TEST_LEDGER_ENTRY_DATA);
}
BookieSocketAddress replicaToKill = lh.getLedgerMetadata().getEnsembles().get(0L).get(0);
LOG.info("Killing {}", replicaToKill);
killBookie(replicaToKill);
for (int i = 0; i < 10; i++) {
lh.addEntry(TEST_LEDGER_ENTRY_DATA);
}
Set<LedgerFragment> result = getUnderReplicatedFragments(lh);
assertNotNull("Result shouldn't be null", result);
for (LedgerFragment r : result) {
LOG.info("unreplicated fragment: {}", r);
}
assertEquals("Should have one missing fragment", 1, result.size());
assertTrue("Fragment should be missing from first replica", result.iterator().next().getAddresses().contains(replicaToKill));
BookieSocketAddress replicaToKill2 = lh.getLedgerMetadata().getEnsembles().get(0L).get(1);
LOG.info("Killing {}", replicaToKill2);
killBookie(replicaToKill2);
result = getUnderReplicatedFragments(lh);
assertNotNull("Result shouldn't be null", result);
for (LedgerFragment r : result) {
LOG.info("unreplicated fragment: {}", r);
}
AtomicInteger number = new AtomicInteger();
result.forEach(ledgerFragment -> number.addAndGet(ledgerFragment.getAddresses().size()));
assertEquals("Should have three missing fragments", 3, number.get());
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestLedgerChecker method testShouldNotGetAnyFragmentIfNoLedgerPresent.
/**
* Tests that LedgerChecker should not get any underReplicated fragments, if
* corresponding ledger does not exists.
*/
@Test
public void testShouldNotGetAnyFragmentIfNoLedgerPresent() throws Exception {
LedgerHandle lh = bkc.createLedger(3, 2, BookKeeper.DigestType.CRC32, TEST_LEDGER_PASSWORD);
ArrayList<BookieSocketAddress> firstEnsemble = lh.getLedgerMetadata().getEnsembles().get(0L);
BookieSocketAddress firstBookieFromEnsemble = firstEnsemble.get(0);
killBookie(firstBookieFromEnsemble);
startNewBookie();
lh.addEntry(TEST_LEDGER_ENTRY_DATA);
bkc.deleteLedger(lh.getId());
LOG.info("Waiting to see ledger id {} deletion", lh.getId());
int retries = 40;
boolean noSuchLedger = false;
while (retries > 0) {
try {
lh.readEntries(0, 0);
} catch (BKException.BKNoSuchLedgerExistsException bkn) {
noSuchLedger = true;
break;
}
retries--;
Thread.sleep(500);
}
assertEquals("Ledger exists", true, noSuchLedger);
Set<LedgerFragment> result = getUnderReplicatedFragments(lh);
assertNotNull("Result shouldn't be null", result);
assertEquals("There should be 0 fragments. But returned fragments are " + result, 0, result.size());
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestLedgerChecker method testShouldGetOneFragmentWithSingleEntryOpenedLedger.
/**
* Tests that LedgerChecker should one fragment as underReplicated
* if there is an open ledger with single entry written.
*/
@Test
public void testShouldGetOneFragmentWithSingleEntryOpenedLedger() throws Exception {
LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, TEST_LEDGER_PASSWORD);
lh.addEntry(TEST_LEDGER_ENTRY_DATA);
ArrayList<BookieSocketAddress> firstEnsemble = lh.getLedgerMetadata().getEnsembles().get(0L);
BookieSocketAddress lastBookieFromEnsemble = firstEnsemble.get(0);
LOG.info("Killing " + lastBookieFromEnsemble + " from ensemble=" + firstEnsemble);
killBookie(lastBookieFromEnsemble);
startNewBookie();
// Open ledger separately for Ledger checker.
LedgerHandle lh1 = bkc.openLedgerNoRecovery(lh.getId(), BookKeeper.DigestType.CRC32, TEST_LEDGER_PASSWORD);
Set<LedgerFragment> result = getUnderReplicatedFragments(lh1);
assertNotNull("Result shouldn't be null", result);
assertEquals("There should be 1 fragment. But returned fragments are " + result, 1, result.size());
assertEquals("There should be 1 failed bookies in the fragment", 1, result.iterator().next().getBookiesIndexes().size());
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestLedgerChecker method testShouldGet2FragmentsWithEmptyLedgerButBookiesDead.
/**
* Tests that LedgerChecker should get all fragments if ledger is empty
* but all bookies in the ensemble are down.
* In this case, there's no way to tell whether data was written or not.
* In this case, there'll only be two fragments, as quorum is 2 and we only
* suspect that the first entry of the ledger could exist.
*/
@Test
public void testShouldGet2FragmentsWithEmptyLedgerButBookiesDead() throws Exception {
LedgerHandle lh = bkc.createLedger(3, 2, BookKeeper.DigestType.CRC32, TEST_LEDGER_PASSWORD);
for (BookieSocketAddress b : lh.getLedgerMetadata().getEnsembles().get(0L)) {
killBookie(b);
}
Set<LedgerFragment> result = getUnderReplicatedFragments(lh);
assertNotNull("Result shouldn't be null", result);
assertEquals("There should be 1 fragments.", 1, result.size());
assertEquals("There should be 2 failed bookies in the fragment", 2, result.iterator().next().getBookiesIndexes().size());
}
Aggregations