@Override void last(PageBtreeCursor cursor) { int child = childPageIds[entryCount]; index.getPage(child).last(cursor); }
@Override void freeRecursive() { index.getPageStore().logUndo(this, data); index.getPageStore().free(getPos()); for (int i = 0; i < entryCount + 1; i++) { int child = childPageIds[i]; index.getPage(child).freeRecursive(); } }
@Override protected void remapChildren() { for (int i = 0; i < entryCount + 1; i++) { int child = childPageIds[i]; PageBtree p = index.getPage(child); p.setParentPageId(getPos()); index.getPageStore().update(p); } }
@Override PageBtreeLeaf getFirstLeaf() { int child = childPageIds[0]; return index.getPage(child).getFirstLeaf(); }
@Override int addRowTry(SearchRow row) { while (true) { int x = find(row, false, true, true); PageBtree page = index.getPage(childPageIds[x]); int splitPoint = page.addRowTry(row); if (splitPoint == -1) { break; } SearchRow pivot = page.getRow(splitPoint - 1); index.getPageStore().logUndo(this, data); int splitPoint2 = addChildTry(pivot); if (splitPoint2 != -1) { return splitPoint2; } PageBtree page2 = page.split(splitPoint); readAllRows(); addChild(x, page2.getPos(), pivot); index.getPageStore().update(page); index.getPageStore().update(page2); index.getPageStore().update(this); } updateRowCount(1); written = false; changeCount = index.getPageStore().getChangeCount(); return -1; }
@Override PageBtreeLeaf getLastLeaf() { int child = childPageIds[entryCount]; return index.getPage(child).getLastLeaf(); }
private void removeChild(int i) { readAllRows(); entryCount--; if (pageStoreInternalCount) { updateRowCount(-index.getPage(childPageIds[i]).getRowCount()); } written = false; changeCount = index.getPageStore().getChangeCount(); if (entryCount < 0) { DbException.throwInternalError("" + entryCount); } if (entryCount > i) { int startNext = i > 0 ? offsets[i - 1] : index.getPageStore().getPageSize(); int rowLength = startNext - offsets[i]; add(offsets, i, entryCount + 1, rowLength); } rows = remove(rows, entryCount + 1, i); offsets = remove(offsets, entryCount + 1, i); childPageIds = remove(childPageIds, entryCount + 2, i); start -= CHILD_OFFSET_PAIR_LENGTH; }
private void invalidateRowCount() { PageBtree root = getPage(rootPageId); root.setRowCountStored(PageData.UNKNOWN_ROWCOUNT); }
@Override void find(PageBtreeCursor cursor, SearchRow first, boolean bigger) { int i = find(first, bigger, false, false); if (i > entryCount) { if (parentPageId == PageBtree.ROOT) { return; } PageBtreeNode next = (PageBtreeNode) index.getPage(parentPageId); next.find(cursor, first, bigger); return; } PageBtree page = index.getPage(childPageIds[i]); page.find(cursor, first, bigger); }
@Override public void writeRowCount() { if (SysProperties.MODIFY_ON_WRITE && rootPageId == 0) { // currently creating the index return; } PageBtree root = getPage(rootPageId); root.setRowCountStored(MathUtils.convertLongToInt(rowCount)); }
/** * Set the cursor to the last row of the previous page. * * @param cursor the cursor */ void previousPage(PageBtreeCursor cursor) { if (parentPageId == PageBtree.ROOT) { cursor.setCurrent(null, 0); return; } PageBtreeNode next = (PageBtreeNode) index.getPage(parentPageId); next.previousPage(cursor, getPos()); }
private Cursor find(Session session, SearchRow first, boolean bigger, SearchRow last) { if (SysProperties.CHECK && store == null) { throw DbException.get(ErrorCode.OBJECT_CLOSED); } PageBtree root = getPage(rootPageId); PageBtreeCursor cursor = new PageBtreeCursor(session, this, last); root.find(cursor, first, bigger); return cursor; }
@Override void find(PageBtreeCursor cursor, SearchRow first, boolean bigger) { int i = find(first, bigger, false, false); if (i > entryCount) { if (parentPageId == PageBtree.ROOT) { return; } PageBtreeNode next = (PageBtreeNode) index.getPage(parentPageId); next.find(cursor, first, bigger); return; } cursor.setCurrent(this, i); }
/** * Set the cursor to the first row of the next page. * * @param cursor the cursor */ void nextPage(PageBtreeCursor cursor) { if (parentPageId == PageBtree.ROOT) { cursor.setCurrent(null, 0); return; } PageBtreeNode next = (PageBtreeNode) index.getPage(parentPageId); next.nextPage(cursor, getPos()); }
/** * Set the cursor to the first row of the next page. * * @param cursor the cursor * @param pageId id of the next page */ void nextPage(PageBtreeCursor cursor, int pageId) { int i; // TODO maybe keep the index in the child page (transiently) for (i = 0; i < entryCount + 1; i++) { if (childPageIds[i] == pageId) { i++; break; } } if (i > entryCount) { if (parentPageId == PageBtree.ROOT) { cursor.setCurrent(null, 0); return; } PageBtreeNode next = (PageBtreeNode) index.getPage(parentPageId); next.nextPage(cursor, getPos()); return; } PageBtree page = index.getPage(childPageIds[i]); PageBtreeLeaf leaf = page.getFirstLeaf(); cursor.setCurrent(leaf, 0); }
/** * Set the cursor to the last row of the previous page. * * @param cursor the cursor * @param pageId id of the previous page */ void previousPage(PageBtreeCursor cursor, int pageId) { int i; // TODO maybe keep the index in the child page (transiently) for (i = entryCount; i >= 0; i--) { if (childPageIds[i] == pageId) { i--; break; } } if (i < 0) { if (parentPageId == PageBtree.ROOT) { cursor.setCurrent(null, 0); return; } PageBtreeNode previous = (PageBtreeNode) index.getPage(parentPageId); previous.previousPage(cursor, getPos()); return; } PageBtree page = index.getPage(childPageIds[i]); PageBtreeLeaf leaf = page.getLastLeaf(); cursor.setCurrent(leaf, leaf.entryCount - 1); }
@Override int getRowCount() { if (rowCount == UNKNOWN_ROWCOUNT) { int count = 0; for (int i = 0; i < entryCount + 1; i++) { int child = childPageIds[i]; PageBtree page = index.getPage(child); count += page.getRowCount(); index.getDatabase().setProgress( DatabaseEventListener.STATE_SCAN_FILE, index.getName(), count, Integer.MAX_VALUE); } rowCount = count; } return rowCount; }
private void removeAllRows() { try { PageBtree root = getPage(rootPageId); root.freeRecursive(); root = PageBtreeLeaf.create(this, rootPageId, PageBtree.ROOT); store.removeFromCache(rootPageId); store.update(root); rowCount = 0; } finally { store.incrementChangeCount(); } }
@Override public void remove(Session session, Row row) { if (trace.isDebugEnabled()) { trace.debug("{0} remove {1}", getName(), row); } // TODO invalidate row count // setChanged(session); if (rowCount == 1) { removeAllRows(); } else { try { PageBtree root = getPage(rootPageId); root.remove(row); invalidateRowCount(); rowCount--; } finally { store.incrementChangeCount(); } } }
PageBtree root = getPage(rootPageId); PageBtreeCursor cursor = new PageBtreeCursor(session, this, null); root.last(cursor);