/** * Returns a new or recycled _Node instance, latched exclusively, marked * dirty and unevictable. Caller must hold commit lock. * * @param mode MODE_UNEVICTABLE if allocated node cannot be automatically evicted */ _Node allocDirtyNode(int mode) throws IOException { _Node node = mPageDb.allocLatchedNode(this, mode); /*P*/ // [| if (mFullyMapped) { node.mPage = mPageDb.dirtyPage(node.mId); } /*P*/ // ] mDirtyList.add(node, mCommitState); return node; }
/** * Mark an unmapped node as dirty. Caller must hold commit lock and exclusive latch on * node. Method does nothing if node is already dirty. Latch is never released by this * method, even if an exception is thrown. */ void markUnmappedDirty(_Node node) throws IOException { if (node.mCachedState != mCommitState) { node.write(mPageDb); long newId = mPageDb.allocPage(); long oldId = node.mId; try { mPageDb.deletePage(oldId); } catch (Throwable e) { try { mPageDb.recyclePage(newId); } catch (Throwable e2) { // Panic. e.addSuppressed(e2); close(e); } throw e; } dirty(node, newId); } }
@Override public long preallocate(long bytes) throws IOException { if (!mClosed && mPageDb.isDurable()) { int pageSize = mPageSize; long pageCount = (bytes + pageSize - 1) / pageSize; if (pageCount > 0) { pageCount = mPageDb.allocatePages(pageCount); if (pageCount > 0) { try { checkpoint(true, 0, 0); } catch (Throwable e) { DatabaseException.rethrowIfRecoverable(e); closeQuietly(null, this, e); throw e; } } return pageCount * pageSize; } } return 0; }
mCheckpointLock.lock(); try { _PageDb.Stats stats = mPageDb.stats(); long usedPages = stats.totalPages - stats.freePages; targetPageCount = Math.max(usedPages, (long) (usedPages / target)); if (targetPageCount >= stats.totalPages && targetPageCount >= mPageDb.pageCount()) { return true; if (!mPageDb.compactionStart(targetPageCount)) { return false; boolean completed = mPageDb.compactionScanFreeList(); if (completed && mPageDb.compactionScanFreeList()) { if (!mPageDb.compactionVerify() && mPageDb.compactionScanFreeList()) { checkpoint(true, 0, 0); completed &= mPageDb.compactionEnd(); mPageDb.compactionReclaim(); return mPageDb.truncatePages();
rootId = mPageDb.allocPage(); rootIdBytes = new byte[8]; } else { root.mPage = mPageDb.dirtyPage(rootId); mPageDb.recyclePage(rootId); } catch (Throwable e2) { Utils.suppress(e, e2);
mCheckpointLock.lock(); try { _PageDb.Stats stats = mPageDb.stats(); long usedPages = stats.totalPages - stats.freePages; targetPageCount = Math.max(usedPages, (long) (usedPages / target)); if (targetPageCount >= stats.totalPages && targetPageCount >= mPageDb.pageCount()) { return true; if (!mPageDb.compactionStart(targetPageCount)) { return false; boolean completed = mPageDb.compactionScanFreeList(); if (completed && mPageDb.compactionScanFreeList()) { if (!mPageDb.compactionVerify() && mPageDb.compactionScanFreeList()) { checkpoint(true, 0, 0); completed &= mPageDb.compactionEnd(); mPageDb.compactionReclaim(); return mPageDb.truncatePages();
mCheckpointLock.lock(); try { _PageDb.Stats stats = mPageDb.stats(); long usedPages = stats.totalPages - stats.freePages; targetPageCount = Math.max(usedPages, (long) (usedPages / target)); if (targetPageCount >= stats.totalPages && targetPageCount >= mPageDb.pageCount()) { return true; if (!mPageDb.compactionStart(targetPageCount)) { return false; boolean completed = mPageDb.compactionScanFreeList(); if (completed && mPageDb.compactionScanFreeList()) { if (!mPageDb.compactionVerify() && mPageDb.compactionScanFreeList()) { checkpoint(true, 0, 0); completed &= mPageDb.compactionEnd(); mPageDb.compactionReclaim(); return mPageDb.truncatePages();
/** * Mark an unmapped node as dirty. Caller must hold commit lock and exclusive latch on * node. Method does nothing if node is already dirty. Latch is never released by this * method, even if an exception is thrown. */ void markUnmappedDirty(_Node node) throws IOException { if (node.mCachedState != mCommitState) { node.write(mPageDb); long newId = mPageDb.allocPage(); long oldId = node.mId; try { mPageDb.deletePage(oldId); } catch (Throwable e) { try { mPageDb.recyclePage(newId); } catch (Throwable e2) { // Panic. Utils.suppress(e, e2); close(e); } throw e; } dirty(node, newId); } }
/** * Returns a new or recycled _Node instance, latched exclusively, marked * dirty and unevictable. Caller must hold commit lock. * * @param mode MODE_UNEVICTABLE if allocated node cannot be automatically evicted */ _Node allocDirtyNode(int mode) throws IOException { _Node node = mPageDb.allocLatchedNode(this, mode); /*P*/ // [| if (mFullyMapped) { node.mPage = mPageDb.dirtyPage(node.mId); } /*P*/ // ] mDirtyList.add(node, mCommitState); return node; }
@Override public long preallocate(long bytes) throws IOException { if (!isClosed() && mPageDb.isDurable()) { int pageSize = mPageSize; long pageCount = (bytes + pageSize - 1) / pageSize; if (pageCount > 0) { pageCount = mPageDb.allocatePages(pageCount); if (pageCount > 0) { try { checkpoint(true, 0, 0); } catch (Throwable e) { DatabaseException.rethrowIfRecoverable(e); closeQuietly(null, this, e); throw e; } } return pageCount * pageSize; } } return 0; }
/** * Mark an unmapped node as dirty. Caller must hold commit lock and exclusive latch on * node. Method does nothing if node is already dirty. Latch is never released by this * method, even if an exception is thrown. */ void markUnmappedDirty(_Node node) throws IOException { if (node.mCachedState != mCommitState) { node.write(mPageDb); long newId = mPageDb.allocPage(); long oldId = node.mId; try { // No need to force delete when dirtying. Caller is responsible for cleaning up. mPageDb.deletePage(oldId, false); } catch (Throwable e) { try { mPageDb.recyclePage(newId); } catch (Throwable e2) { // Panic. Utils.suppress(e, e2); close(e); } throw e; } dirty(node, newId); } }