use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.
the class GetLedgerMetaService method handle.
@Override
public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
HttpServiceResponse response = new HttpServiceResponse();
Map<String, String> params = request.getParams();
if (HttpServer.Method.GET == request.getMethod() && (params != null) && params.containsKey("ledger_id")) {
Long ledgerId = Long.parseLong(params.get("ledger_id"));
LedgerManagerFactory mFactory = bookieServer.getBookie().getLedgerManagerFactory();
LedgerManager manager = mFactory.newLedgerManager();
// output <ledgerId: ledgerMetadata>
Map<String, String> output = Maps.newHashMap();
ListLedgerService.ReadLedgerMetadataCallback cb = new ListLedgerService.ReadLedgerMetadataCallback(ledgerId);
manager.readLedgerMetadata(ledgerId, cb);
LedgerMetadata md = cb.get();
output.put(ledgerId.toString(), new String(md.serialize(), UTF_8));
manager.close();
String jsonResponse = JsonUtil.toJson(output);
LOG.debug("output body:" + jsonResponse);
response.setBody(jsonResponse);
response.setCode(HttpServer.StatusCode.OK);
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 AuditorPeriodicCheckTest method testIndexCorruption.
/**
* test that the period checker will detect corruptions in
* the bookie index files.
*/
@Test
public void testIndexCorruption() throws Exception {
LedgerManagerFactory mFactory = driver.getLedgerManagerFactory();
LedgerUnderreplicationManager underReplicationManager = mFactory.newLedgerUnderreplicationManager();
LedgerHandle lh = bkc.createLedger(3, 3, DigestType.CRC32, "passwd".getBytes());
long ledgerToCorrupt = lh.getId();
for (int i = 0; i < 100; i++) {
lh.addEntry("testdata".getBytes());
}
lh.close();
// push ledgerToCorrupt out of page cache (bookie is configured to only use 1 page)
lh = bkc.createLedger(3, 3, DigestType.CRC32, "passwd".getBytes());
for (int i = 0; i < 100; i++) {
lh.addEntry("testdata".getBytes());
}
lh.close();
BookieAccessor.forceFlush(bs.get(0).getBookie());
File ledgerDir = bsConfs.get(0).getLedgerDirs()[0];
ledgerDir = Bookie.getCurrentDirectory(ledgerDir);
// corrupt of entryLogs
File index = new File(ledgerDir, IndexPersistenceMgr.getLedgerName(ledgerToCorrupt));
LOG.info("file to corrupt{}", index);
ByteBuffer junk = ByteBuffer.allocate(1024 * 1024);
FileOutputStream out = new FileOutputStream(index);
out.getChannel().write(junk);
out.close();
long underReplicatedLedger = -1;
for (int i = 0; i < 10; i++) {
underReplicatedLedger = underReplicationManager.pollLedgerToRereplicate();
if (underReplicatedLedger != -1) {
break;
}
Thread.sleep(CHECK_INTERVAL * 1000);
}
assertEquals("Ledger should be under replicated", ledgerToCorrupt, underReplicatedLedger);
underReplicationManager.close();
}
use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.
the class ZKMetadataDriverBaseTest method testGetLedgerManagerFactory.
@Test
public void testGetLedgerManagerFactory() throws Exception {
driver.initialize(conf, NullStatsLogger.INSTANCE, retryPolicy, Optional.empty());
mockStatic(AbstractZkLedgerManagerFactory.class);
LedgerManagerFactory factory = mock(LedgerManagerFactory.class);
PowerMockito.when(AbstractZkLedgerManagerFactory.class, "newLedgerManagerFactory", same(conf), same(driver.layoutManager)).thenReturn(factory);
assertSame(factory, driver.getLedgerManagerFactory());
assertSame(factory, driver.lmFactory);
verifyStatic(AbstractZkLedgerManagerFactory.class, times(1));
AbstractZkLedgerManagerFactory.newLedgerManagerFactory(same(conf), same(driver.layoutManager));
driver.close();
verify(factory, times(1)).close();
assertNull(driver.lmFactory);
}
Aggregations