use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.
the class ListUnderReplicatedLedgerService method handle.
/*
* Print the node which holds the auditor lock.
*/
@Override
public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
HttpServiceResponse response = new HttpServiceResponse();
// parameter as this: ?missingreplica=<bookie_address>&excludingmissingreplica=<bookid_address>
Map<String, String> params = request.getParams();
if (HttpServer.Method.GET == request.getMethod()) {
final String includingBookieId;
final String excludingBookieId;
if (params != null && params.containsKey("missingreplica")) {
includingBookieId = params.get("missingreplica");
} else {
includingBookieId = null;
}
if (params != null && params.containsKey("excludingmissingreplica")) {
excludingBookieId = params.get("excludingmissingreplica");
} else {
excludingBookieId = null;
}
Predicate<List<String>> predicate = null;
if (!StringUtils.isBlank(includingBookieId) && !StringUtils.isBlank(excludingBookieId)) {
predicate = replicasList -> (replicasList.contains(includingBookieId) && !replicasList.contains(excludingBookieId));
} else if (!StringUtils.isBlank(includingBookieId)) {
predicate = replicasList -> replicasList.contains(includingBookieId);
} else if (!StringUtils.isBlank(excludingBookieId)) {
predicate = replicasList -> !replicasList.contains(excludingBookieId);
}
try {
List<Long> outputLedgers = Lists.newArrayList();
LedgerManagerFactory mFactory = bookieServer.getBookie().getLedgerManagerFactory();
LedgerUnderreplicationManager underreplicationManager = mFactory.newLedgerUnderreplicationManager();
Iterator<Long> iter = underreplicationManager.listLedgersToRereplicate(predicate);
while (iter.hasNext()) {
outputLedgers.add(iter.next());
}
if (outputLedgers.isEmpty()) {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("No under replicated ledgers found");
return response;
} else {
response.setCode(HttpServer.StatusCode.OK);
String jsonResponse = JsonUtil.toJson(outputLedgers);
LOG.debug("output body: " + jsonResponse);
response.setBody(jsonResponse);
return response;
}
} catch (Exception e) {
LOG.error("Exception occurred while listing under replicated ledgers", e);
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("Exception when get." + e.getMessage());
return response;
}
} else {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("Not found method. Should be GET method");
return response;
}
}
use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.
the class AbstractConfigurationTest method testUnsupportedLedgerManagerFactory.
@SuppressWarnings({ "unchecked" })
@Test(expected = UnsupportedOperationException.class)
public void testUnsupportedLedgerManagerFactory() throws Exception {
LedgerManagerFactory mockFactory = mock(LedgerManagerFactory.class, CALLS_REAL_METHODS);
conf.setLedgerManagerFactoryClass(mockFactory.getClass());
conf.getMetadataServiceUri();
}
use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.
the class ZKRegistrationManager method nukeExistingCluster.
@Override
public boolean nukeExistingCluster() throws Exception {
String zkServers = conf.getZkServers();
log.info("Nuking ZooKeeper metadata of existing cluster, ZKServers: {} ledger root path: {}", zkServers, ledgersRootPath);
boolean ledgerRootExists = null != zk.exists(ledgersRootPath, false);
if (!ledgerRootExists) {
log.info("There is no existing cluster with ledgersRootPath: {} in ZKServers: {}, " + "so exiting nuke operation", ledgersRootPath, zkServers);
return true;
}
boolean availableNodeExists = null != zk.exists(bookieRegistrationPath, false);
try (RegistrationClient regClient = new ZKRegistrationClient(zk, ledgersRootPath, null)) {
if (availableNodeExists) {
Collection<BookieSocketAddress> rwBookies = FutureUtils.result(regClient.getWritableBookies(), EXCEPTION_FUNC).getValue();
if (rwBookies != null && !rwBookies.isEmpty()) {
log.error("Bookies are still up and connected to this cluster, " + "stop all bookies before nuking the cluster");
return false;
}
boolean readonlyNodeExists = null != zk.exists(bookieReadonlyRegistrationPath, false);
if (readonlyNodeExists) {
Collection<BookieSocketAddress> roBookies = FutureUtils.result(regClient.getReadOnlyBookies(), EXCEPTION_FUNC).getValue();
if (roBookies != null && !roBookies.isEmpty()) {
log.error("Readonly Bookies are still up and connected to this cluster, " + "stop all bookies before nuking the cluster");
return false;
}
}
}
}
LedgerManagerFactory ledgerManagerFactory = AbstractZkLedgerManagerFactory.newLedgerManagerFactory(conf, layoutManager);
return ledgerManagerFactory.validateAndNukeExistingCluster(conf, layoutManager);
}
use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.
the class TestReplicationWorker method testRWShouldReplicateTheLedgersAfterTimeoutIfLastFragmentIsUR.
/**
* Tests that ReplicationWorker should fence the ledger and release ledger
* lock after timeout. Then replication should happen normally.
*/
@Test
public void testRWShouldReplicateTheLedgersAfterTimeoutIfLastFragmentIsUR() throws Exception {
LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, TESTPASSWD);
for (int i = 0; i < 10; i++) {
lh.addEntry(data);
}
BookieSocketAddress replicaToKill = LedgerHandleAdapter.getLedgerMetadata(lh).getEnsembles().get(0L).get(0);
LOG.info("Killing Bookie", replicaToKill);
killBookie(replicaToKill);
BookieSocketAddress newBkAddr = startNewBookieAndReturnAddress();
LOG.info("New Bookie addr : {}", newBkAddr);
// set to 3s instead of default 30s
baseConf.setOpenLedgerRereplicationGracePeriod("3000");
ReplicationWorker rw = new ReplicationWorker(zkc, baseConf);
@Cleanup MetadataClientDriver clientDriver = MetadataDrivers.getClientDriver(URI.create(baseClientConf.getMetadataServiceUri()));
clientDriver.initialize(baseClientConf, scheduler, NullStatsLogger.INSTANCE, Optional.empty());
LedgerManagerFactory mFactory = clientDriver.getLedgerManagerFactory();
LedgerUnderreplicationManager underReplicationManager = mFactory.newLedgerUnderreplicationManager();
rw.start();
try {
underReplicationManager.markLedgerUnderreplicated(lh.getId(), replicaToKill.toString());
while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh.getId(), basePath)) {
Thread.sleep(100);
}
killAllBookies(lh, newBkAddr);
// Should be able to read the entries from 0-9
verifyRecoveredLedgers(lh, 0, 9);
lh = bkc.openLedgerNoRecovery(lh.getId(), BookKeeper.DigestType.CRC32, TESTPASSWD);
assertFalse("Ledger must have been closed by RW", ClientUtil.isLedgerOpen(lh));
} finally {
rw.shutdown();
underReplicationManager.close();
}
}
use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.
the class TestReplicationWorker method testRWShouldReplicateTheLedgersAfterTimeoutIfLastFragmentIsNotUR.
/**
* Tests that ReplicationWorker should not have identified for postponing
* the replication if ledger is in open state and lastFragment is not in
* underReplication state. Note that RW should not fence such ledgers.
*/
@Test
public void testRWShouldReplicateTheLedgersAfterTimeoutIfLastFragmentIsNotUR() throws Exception {
LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, TESTPASSWD);
for (int i = 0; i < 10; i++) {
lh.addEntry(data);
}
BookieSocketAddress replicaToKill = LedgerHandleAdapter.getLedgerMetadata(lh).getEnsembles().get(0L).get(0);
LOG.info("Killing Bookie", replicaToKill);
killBookie(replicaToKill);
BookieSocketAddress newBkAddr = startNewBookieAndReturnAddress();
LOG.info("New Bookie addr : {}", newBkAddr);
// under-replication
for (int i = 0; i < 10; i++) {
lh.addEntry(data);
}
ReplicationWorker rw = new ReplicationWorker(zkc, baseConf);
baseClientConf.setZkServers(zkUtil.getZooKeeperConnectString());
@Cleanup MetadataClientDriver driver = MetadataDrivers.getClientDriver(URI.create(baseClientConf.getMetadataServiceUri()));
driver.initialize(baseClientConf, scheduler, NullStatsLogger.INSTANCE, Optional.empty());
LedgerManagerFactory mFactory = driver.getLedgerManagerFactory();
LedgerUnderreplicationManager underReplicationManager = mFactory.newLedgerUnderreplicationManager();
rw.start();
try {
underReplicationManager.markLedgerUnderreplicated(lh.getId(), replicaToKill.toString());
while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh.getId(), basePath)) {
Thread.sleep(100);
}
killAllBookies(lh, newBkAddr);
// Should be able to read the entries from 0-9
verifyRecoveredLedgers(lh, 0, 9);
lh = bkc.openLedgerNoRecovery(lh.getId(), BookKeeper.DigestType.CRC32, TESTPASSWD);
// Ledger should be still in open state
assertTrue("Ledger must have been closed by RW", ClientUtil.isLedgerOpen(lh));
} finally {
rw.shutdown();
underReplicationManager.close();
}
}
Aggregations