Exemplo n.º 1
0
  @Override
  public long allocatePages(long pageCount) throws IOException {
    if (pageCount <= 0) {
      return 0;
    }

    Stats stats = new Stats();
    mPageManager.addTo(stats);
    pageCount -= stats.freePages;

    if (pageCount <= 0) {
      return 0;
    }

    for (int i = 0; i < pageCount; i++) {
      CommitLock.Shared shared = mCommitLock.acquireShared();
      try {
        mPageManager.allocAndRecyclePage();
      } catch (Throwable e) {
        throw closeOnFailure(e);
      } finally {
        shared.release();
      }
    }

    return pageCount;
  }
Exemplo n.º 2
0
 @Override
 public void compactionReclaim() throws IOException {
   try {
     mPageManager.compactionReclaim();
   } catch (Throwable e) {
     throw closeOnFailure(e);
   }
 }
Exemplo n.º 3
0
 @Override
 public boolean compactionEnd() throws IOException {
   try {
     return mPageManager.compactionEnd(mCommitLock);
   } catch (Throwable e) {
     throw closeOnFailure(e);
   }
 }
Exemplo n.º 4
0
 @Override
 public void recyclePage(long id) throws IOException {
   checkId(id);
   CommitLock.Shared shared = mCommitLock.acquireShared();
   try {
     try {
       mPageManager.recyclePage(id);
     } catch (IOException e) {
       mPageManager.deletePage(id);
     }
   } catch (IOException e) {
     throw e;
   } catch (Throwable e) {
     throw closeOnFailure(e);
   } finally {
     shared.release();
   }
 }
Exemplo n.º 5
0
 @Override
 public boolean compactionStart(long targetPageCount) throws IOException {
   mCommitLock.acquireExclusive();
   try {
     return mPageManager.compactionStart(targetPageCount);
   } catch (Throwable e) {
     throw closeOnFailure(e);
   } finally {
     mCommitLock.releaseExclusive();
   }
 }
Exemplo n.º 6
0
  @Override
  public void commit(boolean resume, long header, final CommitCallback callback)
      throws IOException {
    // Acquire a shared lock to prevent concurrent commits after callback has released
    // exclusive lock.
    CommitLock.Shared shared = mCommitLock.acquireShared();

    try {
      mHeaderLatch.acquireShared();
      final int commitNumber = mCommitNumber + 1;
      mHeaderLatch.releaseShared();

      try {
        if (!resume) {
          mPageManager.commitStart(header, I_MANAGER_HEADER);
        }
        if (callback != null) {
          // Invoke the callback to ensure all dirty pages get written.
          callback.prepare(resume, header);
        }
      } catch (DatabaseException e) {
        if (e.isRecoverable()) {
          throw e;
        } else {
          throw closeOnFailure(e);
        }
      }

      try {
        commitHeader(header, commitNumber);
        mPageManager.commitEnd(header, I_MANAGER_HEADER);
      } catch (Throwable e) {
        throw closeOnFailure(e);
      }
    } finally {
      shared.release();
    }
  }
Exemplo n.º 7
0
 @Override
 public long allocPage() throws IOException {
   CommitLock.Shared shared = mCommitLock.acquireShared();
   try {
     return mPageManager.allocPage();
   } catch (DatabaseException e) {
     if (e.isRecoverable()) {
       throw e;
     }
     throw closeOnFailure(e);
   } catch (Throwable e) {
     throw closeOnFailure(e);
   } finally {
     shared.release();
   }
 }
Exemplo n.º 8
0
 @Override
 public boolean truncatePages() throws IOException {
   return mPageManager.truncatePages();
 }
Exemplo n.º 9
0
 @Override
 public boolean compactionVerify() throws IOException {
   // Only performs reads and so no commit lock is required. Holding it would block
   // checkpoints during reserve list scan, which is not desirable.
   return mPageManager.compactionVerify();
 }
Exemplo n.º 10
0
 @Override
 public Stats stats() {
   Stats stats = new Stats();
   mPageManager.addTo(stats);
   return stats;
 }
Exemplo n.º 11
0
 @Override
 public void pageLimitOverride(long bytes) {
   mPageManager.pageLimitOverride(bytes);
 }
Exemplo n.º 12
0
 @Override
 public long pageLimit() {
   return mPageManager.pageLimit();
 }
Exemplo n.º 13
0
 @Override
 public void pageLimit(long limit) {
   mPageManager.pageLimit(limit);
 }
Exemplo n.º 14
0
 /** Must be called when object is no longer referenced. */
 @Override
 void delete() {
   if (mPageManager != null) {
     mPageManager.delete();
   }
 }