use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestAddEntryQuorumTimeout method testLedgerClosedAfterTimeout.
@Test
public void testLedgerClosedAfterTimeout() throws Exception {
BookKeeperTestClient bkc = new BookKeeperTestClient(baseClientConf);
LedgerHandle lh = bkc.createLedger(3, 3, 3, digestType, testPasswd);
List<BookieSocketAddress> curEns = lh.getLedgerMetadata().currentEnsemble;
byte[] data = "foobar".getBytes();
CountDownLatch b0latch = sleepBookie(curEns.get(0), 5);
try {
lh.addEntry(data);
fail("should have thrown");
} catch (BKException.BKAddEntryQuorumTimeoutException ex) {
}
b0latch.await();
try {
lh.addEntry(data);
fail("should have thrown");
} catch (BKException.BKLedgerClosedException ex) {
}
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestDisableEnsembleChange method disableEnsembleChangeTest.
void disableEnsembleChangeTest(boolean startNewBookie) throws Exception {
ClientConfiguration conf = new ClientConfiguration();
conf.setZkServers(zkUtil.getZooKeeperConnectString());
conf.setDelayEnsembleChange(false).setDisableEnsembleChangeFeatureName(FEATURE_DISABLE_ENSEMBLE_CHANGE);
SettableFeatureProvider featureProvider = new SettableFeatureProvider("test", 0);
BookKeeper bkc = BookKeeper.forConfig(conf).featureProvider(featureProvider).build();
SettableFeature disableEnsembleChangeFeature = featureProvider.getFeature(FEATURE_DISABLE_ENSEMBLE_CHANGE);
disableEnsembleChangeFeature.set(true);
final byte[] password = new byte[0];
final LedgerHandle lh = bkc.createLedger(4, 3, 2, BookKeeper.DigestType.CRC32, password);
final AtomicBoolean finished = new AtomicBoolean(false);
final AtomicBoolean failTest = new AtomicBoolean(false);
final byte[] entry = "test-disable-ensemble-change".getBytes(UTF_8);
assertEquals(1, lh.getLedgerMetadata().getEnsembles().size());
ArrayList<BookieSocketAddress> ensembleBeforeFailure = new ArrayList<>(lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue());
final RateLimiter rateLimiter = RateLimiter.create(10);
Thread addThread = new Thread() {
@Override
public void run() {
try {
while (!finished.get()) {
rateLimiter.acquire();
lh.addEntry(entry);
}
} catch (Exception e) {
logger.error("Exception on adding entry : ", e);
failTest.set(true);
}
}
};
addThread.start();
Thread.sleep(2000);
killBookie(0);
Thread.sleep(2000);
finished.set(true);
addThread.join();
assertFalse("Should not fail adding entries facing one bookie failure when disable ensemble change", failTest.get());
// check the ensemble after failure
assertEquals("No new ensemble should be added when disable ensemble change.", 1, lh.getLedgerMetadata().getEnsembles().size());
ArrayList<BookieSocketAddress> ensembleAfterFailure = new ArrayList<>(lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue());
assertArrayEquals(ensembleBeforeFailure.toArray(new BookieSocketAddress[ensembleBeforeFailure.size()]), ensembleAfterFailure.toArray(new BookieSocketAddress[ensembleAfterFailure.size()]));
// enable ensemble change
disableEnsembleChangeFeature.set(false);
if (startNewBookie) {
startNewBookie();
}
// reset add thread
finished.set(false);
final CountDownLatch failLatch = new CountDownLatch(1);
addThread = new Thread() {
@Override
public void run() {
try {
while (!finished.get()) {
lh.addEntry(entry);
}
} catch (Exception e) {
logger.error("Exception on adding entry : ", e);
failLatch.countDown();
failTest.set(true);
}
}
};
addThread.start();
failLatch.await(4000, TimeUnit.MILLISECONDS);
finished.set(true);
addThread.join();
if (startNewBookie) {
assertFalse("Should not fail adding entries when enable ensemble change again.", failTest.get());
assertFalse("Ledger should be closed when enable ensemble change again.", lh.getLedgerMetadata().isClosed());
assertEquals("New ensemble should be added when enable ensemble change again.", 2, lh.getLedgerMetadata().getEnsembles().size());
} else {
assertTrue("Should fail adding entries when enable ensemble change again.", failTest.get());
assertTrue("Ledger should be closed when enable ensemble change again.", lh.getLedgerMetadata().isClosed());
}
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestLedgerFragmentReplication method testReplicateLFShouldCopyFailedBookieFragmentsToTargetBookie.
/**
* Tests that replicate method should replicate the failed bookie fragments
* to target bookie passed.
*/
@Test
public void testReplicateLFShouldCopyFailedBookieFragmentsToTargetBookie() throws Exception {
byte[] data = "TestLedgerFragmentReplication".getBytes();
LedgerHandle lh = bkc.createLedger(3, 3, TEST_DIGEST_TYPE, TEST_PSSWD);
for (int i = 0; i < 10; i++) {
lh.addEntry(data);
}
BookieSocketAddress replicaToKill = lh.getLedgerMetadata().getEnsembles().get(0L).get(0);
LOG.info("Killing Bookie", replicaToKill);
killBookie(replicaToKill);
BookieSocketAddress newBkAddr = startNewBookieAndReturnAddress();
LOG.info("New Bookie addr : {}", newBkAddr);
for (int i = 0; i < 10; i++) {
lh.addEntry(data);
}
Set<LedgerFragment> result = getFragmentsToReplicate(lh);
BookKeeperAdmin admin = new BookKeeperAdmin(baseClientConf);
lh.close();
for (LedgerFragment lf : result) {
admin.replicateLedgerFragment(lh, lf);
}
// Killing all bookies except newly replicated bookie
SortedMap<Long, ArrayList<BookieSocketAddress>> allBookiesBeforeReplication = lh.getLedgerMetadata().getEnsembles();
Set<Entry<Long, ArrayList<BookieSocketAddress>>> entrySet = allBookiesBeforeReplication.entrySet();
for (Entry<Long, ArrayList<BookieSocketAddress>> entry : entrySet) {
ArrayList<BookieSocketAddress> bookies = entry.getValue();
for (BookieSocketAddress bookie : bookies) {
if (newBkAddr.equals(bookie)) {
continue;
}
killBookie(bookie);
}
}
// Should be able to read the entries from 0-9
verifyRecoveredLedgers(lh, 0, 9);
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestReadTimeout method testReadTimeout.
@SuppressWarnings("deprecation")
@Test
public void testReadTimeout() throws Exception {
final AtomicBoolean completed = new AtomicBoolean(false);
LedgerHandle writelh = bkc.createLedger(3, 3, digestType, "testPasswd".getBytes());
String tmp = "Foobar";
final int numEntries = 10;
for (int i = 0; i < numEntries; i++) {
writelh.addEntry(tmp.getBytes());
}
Set<BookieSocketAddress> beforeSet = new HashSet<BookieSocketAddress>();
beforeSet.addAll(writelh.getLedgerMetadata().getEnsemble(numEntries));
final BookieSocketAddress bookieToSleep = writelh.getLedgerMetadata().getEnsemble(numEntries).get(0);
int sleeptime = baseClientConf.getReadTimeout() * 3;
CountDownLatch latch = sleepBookie(bookieToSleep, sleeptime);
latch.await();
writelh.asyncAddEntry(tmp.getBytes(), new AddCallback() {
public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
completed.set(true);
}
}, null);
Thread.sleep((baseClientConf.getReadTimeout() * 3) * 1000);
Assert.assertTrue("Write request did not finish", completed.get());
Set<BookieSocketAddress> afterSet = new HashSet<BookieSocketAddress>();
afterSet.addAll(writelh.getLedgerMetadata().getEnsemble(numEntries + 1));
beforeSet.removeAll(afterSet);
Assert.assertTrue("Bookie set should not match", beforeSet.size() != 0);
}
use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.
the class TestSequenceRead method createLedgerWithDuplicatedBookies.
private LedgerHandle createLedgerWithDuplicatedBookies() throws Exception {
final LedgerHandle lh = bkc.createLedger(3, 3, 3, digestType, passwd);
// introduce duplicated bookies in an ensemble.
SortedMap<Long, ArrayList<BookieSocketAddress>> ensembles = lh.getLedgerMetadata().getEnsembles();
TreeMap<Long, ArrayList<BookieSocketAddress>> newEnsembles = new TreeMap<>();
for (Map.Entry<Long, ArrayList<BookieSocketAddress>> entry : ensembles.entrySet()) {
ArrayList<BookieSocketAddress> newList = new ArrayList<BookieSocketAddress>(entry.getValue().size());
BookieSocketAddress firstBookie = entry.getValue().get(0);
for (BookieSocketAddress ignored : entry.getValue()) {
newList.add(firstBookie);
}
newEnsembles.put(entry.getKey(), newList);
}
lh.getLedgerMetadata().setEnsembles(newEnsembles);
// update the ledger metadata with duplicated bookies
final CountDownLatch latch = new CountDownLatch(1);
bkc.getLedgerManager().writeLedgerMetadata(lh.getId(), lh.getLedgerMetadata(), new BookkeeperInternalCallbacks.GenericCallback<Void>() {
@Override
public void operationComplete(int rc, Void result) {
if (BKException.Code.OK == rc) {
latch.countDown();
} else {
logger.error("Error on writing ledger metadata for ledger {} : ", lh.getId(), BKException.getMessage(rc));
}
}
});
latch.await();
logger.info("Update ledger metadata with duplicated bookies for ledger {}.", lh.getId());
return lh;
}
Aggregations