use of org.apache.bookkeeper.bookie.LogMark in project bookkeeper by apache.
the class LastMarkCommand method run.
@Override
public void run(ServerConfiguration conf) throws Exception {
LedgerDirsManager dirsManager = new LedgerDirsManager(conf, conf.getJournalDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));
File[] journalDirs = conf.getJournalDirs();
for (int idx = 0; idx < journalDirs.length; idx++) {
Journal journal = new Journal(idx, journalDirs[idx], conf, dirsManager);
LogMark lastLogMark = journal.getLastLogMark().getCurMark();
System.out.println("LastLogMark : Journal Id - " + lastLogMark.getLogFileId() + "(" + Long.toHexString(lastLogMark.getLogFileId()) + ".txn), Pos - " + lastLogMark.getLogFileOffset());
}
}
use of org.apache.bookkeeper.bookie.LogMark in project bookkeeper by apache.
the class GetLastLogMarkService method handle.
@Override
public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
HttpServiceResponse response = new HttpServiceResponse();
if (HttpServer.Method.GET == request.getMethod()) {
try {
/**
* output:
* {
* "<Journal_id>" : "<Pos>",
* ...
* }
*/
Map<String, String> output = Maps.newHashMap();
List<Journal> journals = Lists.newArrayListWithCapacity(conf.getJournalDirs().length);
int idx = 0;
for (File journalDir : conf.getJournalDirs()) {
journals.add(new Journal(idx++, journalDir, conf, new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()))));
}
for (Journal journal : journals) {
LogMark lastLogMark = journal.getLastLogMark().getCurMark();
LOG.debug("LastLogMark: Journal Id - " + lastLogMark.getLogFileId() + "(" + Long.toHexString(lastLogMark.getLogFileId()) + ".txn), Pos - " + lastLogMark.getLogFileOffset());
output.put("LastLogMark: Journal Id - " + lastLogMark.getLogFileId() + "(" + Long.toHexString(lastLogMark.getLogFileId()) + ".txn)", "Pos - " + lastLogMark.getLogFileOffset());
}
String jsonResponse = JsonUtil.toJson(output);
LOG.debug("output body:" + jsonResponse);
response.setBody(jsonResponse);
response.setCode(HttpServer.StatusCode.OK);
return response;
} catch (Exception e) {
LOG.error("Exception occurred while getting last log mark", e);
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("ERROR handling request: " + e.getMessage());
return response;
}
} else {
response.setCode(HttpServer.StatusCode.NOT_FOUND);
response.setBody("Not found method. Should be GET method");
return response;
}
}
Aggregations