Search in sources :

Example 1 with GarbageCleaner

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()));
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) GarbageCleaner(org.apache.bookkeeper.bookie.GarbageCollector.GarbageCleaner) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) Test(org.junit.Test)

Example 2 with GarbageCleaner

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()));
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) GarbageCleaner(org.apache.bookkeeper.bookie.GarbageCollector.GarbageCleaner) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) Test(org.junit.Test)

Example 3 with GarbageCleaner

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()));
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) GarbageCleaner(org.apache.bookkeeper.bookie.GarbageCollector.GarbageCleaner) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 GarbageCleaner (org.apache.bookkeeper.bookie.GarbageCollector.GarbageCleaner)3 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)3 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)3 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)3 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1