Ejemplo n.º 1
0
  /**
   * Flush a specified ledger
   *
   * @param ledger Ledger Id
   * @throws IOException
   */
  private void flushSpecificLedger(long ledger) throws IOException {
    LinkedList<Long> firstEntryList = pageMapAndList.getFirstEntryListToBeFlushed(ledger);

    // flush ledger index file header if necessary
    indexPersistenceManager.flushLedgerHeader(ledger);

    if (null == firstEntryList || firstEntryList.size() == 0) {
      LOG.debug("Nothing to flush for ledger {}.", ledger);
      // nothing to do
      return;
    }

    // Now flush all the pages of a ledger
    List<LedgerEntryPage> entries = new ArrayList<LedgerEntryPage>(firstEntryList.size());
    try {
      for (Long firstEntry : firstEntryList) {
        LedgerEntryPage lep = getLedgerEntryPage(ledger, firstEntry, true);
        if (lep != null) {
          entries.add(lep);
        }
      }
      indexPersistenceManager.flushLedgerEntries(ledger, entries);
    } finally {
      for (LedgerEntryPage lep : entries) {
        lep.releasePage();
      }
    }
  }
Ejemplo n.º 2
0
 /**
  * Grab ledger entry page whose first entry is <code>pageEntry</code>.
  *
  * <p>If the page doesn't existed before, we allocate a memory page. Otherwise, we grab a clean
  * page and read it from disk.
  *
  * @param ledger Ledger Id
  * @param pageEntry Start entry of this entry page.
  */
 private LedgerEntryPage grabLedgerEntryPage(long ledger, long pageEntry) throws IOException {
   LedgerEntryPage lep = grabCleanPage(ledger, pageEntry);
   try {
     // should get the up to date page from the persistence manager
     // before we put it into table otherwise we would put
     // an empty page in it
     indexPersistenceManager.updatePage(lep);
     LedgerEntryPage oldLep;
     if (lep != (oldLep = pageMapAndList.putPage(lep))) {
       lep.releasePage();
       // Decrement the page count because we couldn't put this lep in the page cache.
       pageCount.decrementAndGet();
       // Increment the use count of the old lep because this is unexpected
       oldLep.usePage();
       lep = oldLep;
     }
   } catch (IOException ie) {
     // if we grab a clean page, but failed to update the page
     // we are exhausting the count of ledger entry pages.
     // since this page will be never used, so we need to decrement
     // page count of ledger cache.
     lep.releasePage();
     pageCount.decrementAndGet();
     throw ie;
   }
   return lep;
 }