Search in sources :

Example 1 with LedgerIdGenerator

use of org.apache.bookkeeper.meta.LedgerIdGenerator in project bookkeeper by apache.

the class MockBookKeeperTestCase method setup.

@Before
public void setup() throws Exception {
    mockLedgerMetadataRegistry = new ConcurrentHashMap<>();
    mockLedgerData = new ConcurrentHashMap<>();
    mockNextLedgerId = new AtomicLong(1);
    fencedLedgers = new ConcurrentSkipListSet<>();
    scheduler = OrderedScheduler.newSchedulerBuilder().numThreads(4).name("bk-test").build();
    executor = OrderedExecutor.newBuilder().build();
    bookieWatcher = mock(BookieWatcher.class);
    bookieClient = mock(BookieClient.class);
    ledgerManager = mock(LedgerManager.class);
    ledgerIdGenerator = mock(LedgerIdGenerator.class);
    bk = mock(BookKeeper.class);
    NullStatsLogger nullStatsLogger = setupLoggers();
    failedBookies = new ArrayList<>();
    availableBookies = new HashSet<>();
    when(bk.getCloseLock()).thenReturn(new ReentrantReadWriteLock());
    when(bk.isClosed()).thenReturn(false);
    when(bk.getBookieWatcher()).thenReturn(bookieWatcher);
    when(bk.getDisableEnsembleChangeFeature()).thenReturn(mock(Feature.class));
    when(bk.getExplicitLacInterval()).thenReturn(0);
    when(bk.getMainWorkerPool()).thenReturn(executor);
    when(bk.getBookieClient()).thenReturn(bookieClient);
    when(bk.getScheduler()).thenReturn(scheduler);
    when(bk.getReadSpeculativeRequestPolicy()).thenReturn(Optional.absent());
    mockBookKeeperGetConf(new ClientConfiguration());
    when(bk.getStatsLogger()).thenReturn(nullStatsLogger);
    when(bk.getLedgerManager()).thenReturn(ledgerManager);
    when(bk.getLedgerIdGenerator()).thenReturn(ledgerIdGenerator);
    when(bk.getReturnRc(anyInt())).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
    setupLedgerIdGenerator();
    setupCreateLedgerMetadata();
    setupReadLedgerMetadata();
    setupWriteLedgerMetadata();
    setupRemoveLedgerMetadata();
    setupRegisterLedgerMetadataListener();
    setupBookieWatcherForNewEnsemble();
    setupBookieWatcherForEnsembleChange();
    setupBookieClientReadEntry();
    setupBookieClientAddEntry();
}
Also used : BookieClient(org.apache.bookkeeper.proto.BookieClient) LedgerManager(org.apache.bookkeeper.meta.LedgerManager) LedgerIdGenerator(org.apache.bookkeeper.meta.LedgerIdGenerator) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Feature(org.apache.bookkeeper.feature.Feature) AtomicLong(java.util.concurrent.atomic.AtomicLong) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Before(org.junit.Before)

Example 2 with LedgerIdGenerator

use of org.apache.bookkeeper.meta.LedgerIdGenerator in project bookkeeper by apache.

the class TestWatchEnsembleChange method testWatchMetadataRemoval.

private void testWatchMetadataRemoval(LedgerManagerFactory factory) throws Exception {
    @Cleanup final LedgerManager manager = factory.newLedgerManager();
    @Cleanup LedgerIdGenerator idGenerator = factory.newLedgerIdGenerator();
    final ByteBuffer bbLedgerId = ByteBuffer.allocate(8);
    final CountDownLatch createLatch = new CountDownLatch(1);
    final CountDownLatch removeLatch = new CountDownLatch(1);
    idGenerator.generateLedgerId(new GenericCallback<Long>() {

        @Override
        public void operationComplete(int rc, final Long lid) {
            manager.createLedgerMetadata(lid, new LedgerMetadata(4, 2, 2, digestType, "fpj was here".getBytes()), new BookkeeperInternalCallbacks.GenericCallback<Void>() {

                @Override
                public void operationComplete(int rc, Void result) {
                    bbLedgerId.putLong(lid);
                    bbLedgerId.flip();
                    createLatch.countDown();
                }
            });
        }
    });
    assertTrue(createLatch.await(2000, TimeUnit.MILLISECONDS));
    final long createdLid = bbLedgerId.getLong();
    manager.registerLedgerMetadataListener(createdLid, new LedgerMetadataListener() {

        @Override
        public void onChanged(long ledgerId, LedgerMetadata metadata) {
            assertEquals(ledgerId, createdLid);
            assertEquals(metadata, null);
            removeLatch.countDown();
        }
    });
    manager.removeLedgerMetadata(createdLid, Version.ANY, new BookkeeperInternalCallbacks.GenericCallback<Void>() {

        @Override
        public void operationComplete(int rc, Void result) {
            assertEquals(rc, BKException.Code.OK);
        }
    });
    assertTrue(removeLatch.await(2000, TimeUnit.MILLISECONDS));
}
Also used : LedgerManager(org.apache.bookkeeper.meta.LedgerManager) LedgerIdGenerator(org.apache.bookkeeper.meta.LedgerIdGenerator) CountDownLatch(java.util.concurrent.CountDownLatch) Cleanup(lombok.Cleanup) ByteBuffer(java.nio.ByteBuffer) BookkeeperInternalCallbacks(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks) GenericCallback(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback) LedgerMetadataListener(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.LedgerMetadataListener)

Example 3 with LedgerIdGenerator

use of org.apache.bookkeeper.meta.LedgerIdGenerator in project bookkeeper by apache.

the class LedgerCreateOp method generateLedgerIdAndCreateLedger.

void generateLedgerIdAndCreateLedger() {
    // generate a ledgerId
    final LedgerIdGenerator ledgerIdGenerator = bk.getLedgerIdGenerator();
    ledgerIdGenerator.generateLedgerId(new GenericCallback<Long>() {

        @Override
        public void operationComplete(int rc, Long ledgerId) {
            if (BKException.Code.OK != rc) {
                createComplete(rc, null);
                return;
            }
            LedgerCreateOp.this.ledgerId = ledgerId;
            // create a ledger with metadata
            bk.getLedgerManager().createLedgerMetadata(ledgerId, metadata, LedgerCreateOp.this);
        }
    });
}
Also used : LedgerIdGenerator(org.apache.bookkeeper.meta.LedgerIdGenerator)

Aggregations

LedgerIdGenerator (org.apache.bookkeeper.meta.LedgerIdGenerator)3 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)2 ByteBuffer (java.nio.ByteBuffer)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Cleanup (lombok.Cleanup)1 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)1 Feature (org.apache.bookkeeper.feature.Feature)1 BookieClient (org.apache.bookkeeper.proto.BookieClient)1 BookkeeperInternalCallbacks (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks)1 GenericCallback (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback)1 LedgerMetadataListener (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.LedgerMetadataListener)1 NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)1 Before (org.junit.Before)1