void flushLedgerEntries(long l, List<LedgerEntryPage> entries) throws IOException { FileInfo fi = null; try { Collections.sort( entries, new Comparator<LedgerEntryPage>() { @Override public int compare(LedgerEntryPage o1, LedgerEntryPage o2) { return (int) (o1.getFirstEntry() - o2.getFirstEntry()); } }); int[] versions = new int[entries.size()]; try { fi = getFileInfo(l, null); } catch (Bookie.NoLedgerException nle) { // ledger has been deleted LOG.info("No ledger {} found when flushing entries.", l); return; } // flush the header if necessary relocateIndexFileAndFlushHeader(l, fi); int start = 0; long lastOffset = -1; for (int i = 0; i < entries.size(); i++) { versions[i] = entries.get(i).getVersion(); if (lastOffset != -1 && (entries.get(i).getFirstEntry() - lastOffset) != entriesPerPage) { // send up a sequential list int count = i - start; if (count == 0) { LOG.warn("Count cannot possibly be zero!"); } writeBuffers(l, entries, fi, start, count); start = i; } lastOffset = entries.get(i).getFirstEntry(); } if (entries.size() - start == 0 && entries.size() != 0) { LOG.warn("Nothing to write, but there were entries!"); } writeBuffers(l, entries, fi, start, entries.size() - start); for (int i = 0; i < entries.size(); i++) { LedgerEntryPage lep = entries.get(i); lep.setClean(versions[i]); } if (LOG.isDebugEnabled()) { LOG.debug("Flushed ledger {} with {} pages.", l, entries.size()); } } finally { if (fi != null) { fi.release(); } } }
void flushLedgerHeader(long ledger) throws IOException { FileInfo fi = null; try { fi = getFileInfo(ledger, null); relocateIndexFileAndFlushHeader(ledger, fi); } catch (Bookie.NoLedgerException nle) { // ledger has been deleted LOG.info("No ledger {} found when flushing header.", ledger); return; } finally { if (null != fi) { fi.release(); } } }