Search in sources :

Example 21 with LedgerUnderreplicationManager

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

the class TestLedgerUnderreplicationManager method testManyFailures.

/**
 * Test that when a failure occurs on a ledger, while the ledger
 * is already being rereplicated, the ledger will still be in the
 * under replicated ledger list when first rereplicating client marks
 * it as replicated.
 */
@Test
public void testManyFailures() throws Exception {
    String missingReplica1 = "localhost:3181";
    String missingReplica2 = "localhost:3182";
    LedgerUnderreplicationManager m1 = lmf1.newLedgerUnderreplicationManager();
    Long ledgerA = 0xfeadeefdacL;
    m1.markLedgerUnderreplicated(ledgerA, missingReplica1);
    Future<Long> fA = getLedgerToReplicate(m1);
    Long lA = fA.get(5, TimeUnit.SECONDS);
    m1.markLedgerUnderreplicated(ledgerA, missingReplica2);
    assertEquals("Should be the ledger I just marked", lA, ledgerA);
    m1.markLedgerReplicated(lA);
    Future<Long> f = getLedgerToReplicate(m1);
    lA = f.get(5, TimeUnit.SECONDS);
    assertEquals("Should be the ledger I had marked previously", lA, ledgerA);
}
Also used : ZkLedgerUnderreplicationManager(org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager) LedgerUnderreplicationManager(org.apache.bookkeeper.meta.LedgerUnderreplicationManager) Test(org.junit.Test)

Example 22 with LedgerUnderreplicationManager

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

the class TestLedgerUnderreplicationManager method testDisableLedegerReplication.

/**
 * Test disabling the ledger re-replication. After disabling, it will not be
 * able to getLedgerToRereplicate(). This calls will enter into infinite
 * waiting until enabling rereplication process
 */
@Test
public void testDisableLedegerReplication() throws Exception {
    final LedgerUnderreplicationManager replicaMgr = lmf1.newLedgerUnderreplicationManager();
    // simulate few urLedgers before disabling
    final Long ledgerA = 0xfeadeefdacL;
    final String missingReplica = "localhost:3181";
    // disabling replication
    replicaMgr.disableLedgerReplication();
    LOG.info("Disabled Ledeger Replication");
    try {
        replicaMgr.markLedgerUnderreplicated(ledgerA, missingReplica);
    } catch (UnavailableException e) {
        LOG.debug("Unexpected exception while marking urLedger", e);
        fail("Unexpected exception while marking urLedger" + e.getMessage());
    }
    Future<Long> fA = getLedgerToReplicate(replicaMgr);
    try {
        fA.get(1, TimeUnit.SECONDS);
        fail("Shouldn't be able to find a ledger to replicate");
    } catch (TimeoutException te) {
        // expected behaviour, as the replication is disabled
        isLedgerReplicationDisabled = false;
    }
    assertTrue("Ledger replication is not disabled!", !isLedgerReplicationDisabled);
}
Also used : ZkLedgerUnderreplicationManager(org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager) LedgerUnderreplicationManager(org.apache.bookkeeper.meta.LedgerUnderreplicationManager) UnavailableException(org.apache.bookkeeper.replication.ReplicationException.UnavailableException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 23 with LedgerUnderreplicationManager

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

the class TestLedgerUnderreplicationManager method testMultipleManagersShouldBeAbleToTakeAndReleaseLock.

/**
 * Test that multiple LedgerUnderreplicationManagers should be able to take
 * lock and release for same ledger.
 */
@Test
public void testMultipleManagersShouldBeAbleToTakeAndReleaseLock() throws Exception {
    String missingReplica1 = "localhost:3181";
    final LedgerUnderreplicationManager m1 = lmf1.newLedgerUnderreplicationManager();
    final LedgerUnderreplicationManager m2 = lmf2.newLedgerUnderreplicationManager();
    Long ledgerA = 0xfeadeefdacL;
    m1.markLedgerUnderreplicated(ledgerA, missingReplica1);
    final int iterationCount = 100;
    final CountDownLatch latch1 = new CountDownLatch(iterationCount);
    final CountDownLatch latch2 = new CountDownLatch(iterationCount);
    Thread thread1 = new Thread() {

        @Override
        public void run() {
            takeLedgerAndRelease(m1, latch1, iterationCount);
        }
    };
    Thread thread2 = new Thread() {

        @Override
        public void run() {
            takeLedgerAndRelease(m2, latch2, iterationCount);
        }
    };
    thread1.start();
    thread2.start();
    // wait until at least one thread completed
    while (!latch1.await(50, TimeUnit.MILLISECONDS) && !latch2.await(50, TimeUnit.MILLISECONDS)) {
        Thread.sleep(50);
    }
    m1.close();
    m2.close();
    // After completing 'lock acquire,release' job, it should notify below
    // wait
    latch1.await();
    latch2.await();
}
Also used : ZkLedgerUnderreplicationManager(org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager) LedgerUnderreplicationManager(org.apache.bookkeeper.meta.LedgerUnderreplicationManager) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 24 with LedgerUnderreplicationManager

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

the class TestHttpService method testListUnderReplicatedLedgerService.

private void testListUnderReplicatedLedgerService(LedgerManagerFactory mFactory) throws Exception {
    startAuditorElector();
    HttpEndpointService listUnderReplicatedLedgerService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LIST_UNDER_REPLICATED_LEDGER);
    // 1,  PUT, should return error, because only support GET.
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
    HttpServiceResponse response1 = listUnderReplicatedLedgerService.handle(request1);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
    // 2,  GET, should return success.
    // first put ledger into rereplicate. then use api to list ur ledger.
    @Cleanup LedgerManager ledgerManager = mFactory.newLedgerManager();
    @Cleanup final LedgerUnderreplicationManager underReplicationManager = mFactory.newLedgerUnderreplicationManager();
    LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, "passwd".getBytes());
    LedgerMetadata md = LedgerHandleAdapter.getLedgerMetadata(lh);
    List<BookieSocketAddress> ensemble = md.getEnsembles().get(0L);
    ensemble.set(0, new BookieSocketAddress("1.1.1.1", 1000));
    TestCallbacks.GenericCallbackFuture<Void> cb = new TestCallbacks.GenericCallbackFuture<Void>();
    ledgerManager.writeLedgerMetadata(lh.getId(), md, cb);
    cb.get();
    long underReplicatedLedger = -1;
    for (int i = 0; i < 10; i++) {
        underReplicatedLedger = underReplicationManager.pollLedgerToRereplicate();
        if (underReplicatedLedger != -1) {
            break;
        }
        Thread.sleep(1000);
    }
    HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response2 = listUnderReplicatedLedgerService.handle(request2);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
    stopAuditorElector();
}
Also used : LedgerManager(org.apache.bookkeeper.meta.LedgerManager) LedgerUnderreplicationManager(org.apache.bookkeeper.meta.LedgerUnderreplicationManager) HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) Cleanup(lombok.Cleanup) TestCallbacks(org.apache.bookkeeper.test.TestCallbacks) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse)

Aggregations

LedgerUnderreplicationManager (org.apache.bookkeeper.meta.LedgerUnderreplicationManager)24 Test (org.junit.Test)18 ZkLedgerUnderreplicationManager (org.apache.bookkeeper.meta.ZkLedgerUnderreplicationManager)12 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)9 TimeoutException (java.util.concurrent.TimeoutException)7 LedgerManagerFactory (org.apache.bookkeeper.meta.LedgerManagerFactory)7 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)7 Cleanup (lombok.Cleanup)4 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)4 UnavailableException (org.apache.bookkeeper.replication.ReplicationException.UnavailableException)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 TestCallbacks (org.apache.bookkeeper.test.TestCallbacks)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ByteBuffer (java.nio.ByteBuffer)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)2 HttpEndpointService (org.apache.bookkeeper.http.service.HttpEndpointService)2