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);
}
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);
}
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();
}
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();
}
Aggregations