use of org.apache.bookkeeper.bookie.GarbageCollector.GarbageCleaner in project bookkeeper by apache.
the class TestGcOverreplicatedLedger method testGcOverreplicatedLedger.
@Test
public void testGcOverreplicatedLedger() throws Exception {
LedgerHandle lh = bkc.createLedger(2, 2, DigestType.MAC, "".getBytes());
activeLedgers.put(lh.getId(), true);
final AtomicReference<LedgerMetadata> newLedgerMetadata = new AtomicReference<>(null);
final CountDownLatch latch = new CountDownLatch(1);
ledgerManager.readLedgerMetadata(lh.getId(), new GenericCallback<LedgerMetadata>() {
@Override
public void operationComplete(int rc, LedgerMetadata result) {
if (rc == BKException.Code.OK) {
newLedgerMetadata.set(result);
}
latch.countDown();
}
});
latch.await();
if (newLedgerMetadata.get() == null) {
Assert.fail("No ledger metadata found");
}
BookieSocketAddress bookieNotInEnsemble = getBookieNotInEnsemble(newLedgerMetadata.get());
ServerConfiguration bkConf = getBkConf(bookieNotInEnsemble);
bkConf.setGcOverreplicatedLedgerWaitTime(10, TimeUnit.MILLISECONDS);
lh.close();
final CompactableLedgerStorage mockLedgerStorage = new MockLedgerStorage();
final GarbageCollector garbageCollector = new ScanAndCompareGarbageCollector(ledgerManager, mockLedgerStorage, bkConf, NullStatsLogger.INSTANCE);
Thread.sleep(bkConf.getGcOverreplicatedLedgerWaitTimeMillis() + 1);
garbageCollector.gc(new GarbageCleaner() {
@Override
public void clean(long ledgerId) {
try {
mockLedgerStorage.deleteLedger(ledgerId);
} catch (IOException e) {
e.printStackTrace();
return;
}
}
});
Assert.assertFalse(activeLedgers.containsKey(lh.getId()));
}
use of org.apache.bookkeeper.bookie.GarbageCollector.GarbageCleaner in project bookkeeper by apache.
the class TestGcOverreplicatedLedger method testNoGcOfLedger.
@Test
public void testNoGcOfLedger() throws Exception {
LedgerHandle lh = bkc.createLedger(2, 2, DigestType.MAC, "".getBytes());
activeLedgers.put(lh.getId(), true);
final AtomicReference<LedgerMetadata> newLedgerMetadata = new AtomicReference<>(null);
final CountDownLatch latch = new CountDownLatch(1);
ledgerManager.readLedgerMetadata(lh.getId(), new GenericCallback<LedgerMetadata>() {
@Override
public void operationComplete(int rc, LedgerMetadata result) {
if (rc == BKException.Code.OK) {
newLedgerMetadata.set(result);
}
latch.countDown();
}
});
latch.await();
if (newLedgerMetadata.get() == null) {
Assert.fail("No ledger metadata found");
}
BookieSocketAddress address = null;
SortedMap<Long, ArrayList<BookieSocketAddress>> ensembleMap = newLedgerMetadata.get().getEnsembles();
for (ArrayList<BookieSocketAddress> ensemble : ensembleMap.values()) {
address = ensemble.get(0);
}
ServerConfiguration bkConf = getBkConf(address);
bkConf.setGcOverreplicatedLedgerWaitTime(10, TimeUnit.MILLISECONDS);
lh.close();
final CompactableLedgerStorage mockLedgerStorage = new MockLedgerStorage();
final GarbageCollector garbageCollector = new ScanAndCompareGarbageCollector(ledgerManager, mockLedgerStorage, bkConf, NullStatsLogger.INSTANCE);
Thread.sleep(bkConf.getGcOverreplicatedLedgerWaitTimeMillis() + 1);
garbageCollector.gc(new GarbageCleaner() {
@Override
public void clean(long ledgerId) {
try {
mockLedgerStorage.deleteLedger(ledgerId);
} catch (IOException e) {
e.printStackTrace();
return;
}
}
});
Assert.assertTrue(activeLedgers.containsKey(lh.getId()));
}
use of org.apache.bookkeeper.bookie.GarbageCollector.GarbageCleaner in project bookkeeper by apache.
the class TestGcOverreplicatedLedger method testNoGcIfLedgerBeingReplicated.
@Test
public void testNoGcIfLedgerBeingReplicated() throws Exception {
LedgerHandle lh = bkc.createLedger(2, 2, DigestType.MAC, "".getBytes());
activeLedgers.put(lh.getId(), true);
final AtomicReference<LedgerMetadata> newLedgerMetadata = new AtomicReference<>(null);
final CountDownLatch latch = new CountDownLatch(1);
ledgerManager.readLedgerMetadata(lh.getId(), new GenericCallback<LedgerMetadata>() {
@Override
public void operationComplete(int rc, LedgerMetadata result) {
if (rc == BKException.Code.OK) {
newLedgerMetadata.set(result);
}
latch.countDown();
}
});
latch.await();
if (newLedgerMetadata.get() == null) {
Assert.fail("No ledger metadata found");
}
BookieSocketAddress bookieNotInEnsemble = getBookieNotInEnsemble(newLedgerMetadata.get());
ServerConfiguration bkConf = getBkConf(bookieNotInEnsemble);
bkConf.setGcOverreplicatedLedgerWaitTime(10, TimeUnit.MILLISECONDS);
lh.close();
ZkLedgerUnderreplicationManager.acquireUnderreplicatedLedgerLock(zkc, baseConf.getZkLedgersRootPath(), lh.getId(), ZooDefs.Ids.OPEN_ACL_UNSAFE);
final CompactableLedgerStorage mockLedgerStorage = new MockLedgerStorage();
final GarbageCollector garbageCollector = new ScanAndCompareGarbageCollector(ledgerManager, mockLedgerStorage, bkConf, NullStatsLogger.INSTANCE);
Thread.sleep(bkConf.getGcOverreplicatedLedgerWaitTimeMillis() + 1);
garbageCollector.gc(new GarbageCleaner() {
@Override
public void clean(long ledgerId) {
try {
mockLedgerStorage.deleteLedger(ledgerId);
} catch (IOException e) {
e.printStackTrace();
return;
}
}
});
Assert.assertTrue(activeLedgers.containsKey(lh.getId()));
}
Aggregations