void putEntryOffset(long ledger, long entry, long offset) throws IOException {
   int offsetInPage = (int) (entry % entriesPerPage);
   // find the id of the first entry of the page that has the entry
   // we are looking for
   long pageEntry = entry - offsetInPage;
   LedgerEntryPage lep = getLedgerEntryPage(ledger, pageEntry, false);
   if (lep == null) {
     lep = grabLedgerEntryPage(ledger, pageEntry);
   }
   assert lep != null;
   lep.setOffset(offset, offsetInPage * LedgerEntryPage.getIndexEntrySize());
   lep.releasePage();
 }
 long getPersistEntryBeyondInMem(long ledgerId, long lastEntryInMem) throws IOException {
   FileInfo fi = null;
   long lastEntry = lastEntryInMem;
   try {
     fi = getFileInfo(ledgerId, null);
     long size = fi.size();
     // make sure the file size is aligned with index entry size
     // otherwise we may read incorret data
     if (0 != size % LedgerEntryPage.getIndexEntrySize()) {
       LOG.warn("Index file of ledger {} is not aligned with index entry size.", ledgerId);
       size = size - size % LedgerEntryPage.getIndexEntrySize();
     }
     // we may not have the last entry in the cache
     if (size > lastEntry * LedgerEntryPage.getIndexEntrySize()) {
       ByteBuffer bb = ByteBuffer.allocate(pageSize);
       long position = size - pageSize;
       if (position < 0) {
         position = 0;
       }
       fi.read(bb, position);
       bb.flip();
       long startingEntryId = position / LedgerEntryPage.getIndexEntrySize();
       for (int i = entriesPerPage - 1; i >= 0; i--) {
         if (bb.getLong(i * LedgerEntryPage.getIndexEntrySize()) != 0) {
           if (lastEntry < startingEntryId + i) {
             lastEntry = startingEntryId + i;
           }
           break;
         }
       }
     }
   } finally {
     if (fi != null) {
       fi.release();
     }
   }
   return lastEntry;
 }
 long getEntryOffset(long ledger, long entry) throws IOException {
   int offsetInPage = (int) (entry % entriesPerPage);
   // find the id of the first entry of the page that has the entry
   // we are looking for
   long pageEntry = entry - offsetInPage;
   LedgerEntryPage lep = getLedgerEntryPage(ledger, pageEntry, false);
   try {
     if (lep == null) {
       lep = grabLedgerEntryPage(ledger, pageEntry);
     }
     return lep.getOffset(offsetInPage * LedgerEntryPage.getIndexEntrySize());
   } finally {
     if (lep != null) {
       lep.releasePage();
     }
   }
 }