Search in sources :

Example 1 with Journal

use of org.apache.bookkeeper.bookie.Journal 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());
    }
}
Also used : LogMark(org.apache.bookkeeper.bookie.LogMark) LedgerDirsManager(org.apache.bookkeeper.bookie.LedgerDirsManager) DiskChecker(org.apache.bookkeeper.util.DiskChecker) Journal(org.apache.bookkeeper.bookie.Journal) File(java.io.File)

Example 2 with Journal

use of org.apache.bookkeeper.bookie.Journal 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:
             *  {
             *    "&lt;Journal_id&gt;" : "&lt;Pos&gt;",
             *    ...
             *  }
             */
            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;
    }
}
Also used : LogMark(org.apache.bookkeeper.bookie.LogMark) LedgerDirsManager(org.apache.bookkeeper.bookie.LedgerDirsManager) DiskChecker(org.apache.bookkeeper.util.DiskChecker) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) Journal(org.apache.bookkeeper.bookie.Journal) File(java.io.File)

Aggregations

File (java.io.File)2 Journal (org.apache.bookkeeper.bookie.Journal)2 LedgerDirsManager (org.apache.bookkeeper.bookie.LedgerDirsManager)2 LogMark (org.apache.bookkeeper.bookie.LogMark)2 DiskChecker (org.apache.bookkeeper.util.DiskChecker)2 HttpServiceResponse (org.apache.bookkeeper.http.service.HttpServiceResponse)1