Package org.chaidb.db.index.btree.bufmgr

Examples of org.chaidb.db.index.btree.bufmgr.PageBufferManager


        if (nextNodePos == null) {
            nextNodePos = nodePos;
        }

        final PageBufferManager buffer = btree.getBuffer();
        final BTreeSpec btreeSpec = btree.getBTreeSpec();
        PageNumber dupPageNumber = new PageNumber(nodePos.getPageNo());
        try {
            DataPage curDataPage = new DataPage(btree.getBtreeId(), dupPageNumber, btreeSpec, buffer);
            DataNode curDataNode = new DataNode(curDataPage, nodePos.getOffsetInPage());
            curDataNode.setFlags(BTreeSpec.DATA_NODE_DUP_NEXT);
            byte[] oldData = ByteTool.copyByteArray(curDataNode.getPage().getPage(), curDataNode.getNodeOffset(), (int) curDataNode.getNodeSpace());
            byte[] data = new byte[8];
            ByteTool.intToBytes(data, 0, nextNodePos.getOffsetInPage());
            ByteTool.intToBytes(data, 4, nextNodePos.getPageNo());
            curDataNode.storeNode(data, oldData, kContext);
            buffer.releasePage(btree.getBtreeId(), nodePos.getPageNo(), true);
        } catch (ChaiDBException e) {
            logger.error(e);
            buffer.releasePage(btree.getBtreeId(), nodePos.getPageNo(), false);
        }
    }
View Full Code Here


        }

        int nPageNo = bulkNextNodePos.getPageNo();

        int id = btree.getBtreeId();
        final PageBufferManager buffer = btree.getBuffer();
        final BTreeSpec btreeSpec = btree.getBTreeSpec();
        PageNumber dupPageNumber = new PageNumber(nPageNo);

        try {
            DataPage dupDataPage = new DataPage(id, dupPageNumber, btreeSpec, buffer);
            int pageCount = 0;
            while (pageCount < page && !finished) {
                NodeInfo node = new NodeInfo();
                node.nodePosition = bulkNextNodePos;
                int ret = getNode(dupDataPage, node);
                bulkNextNodePos = node.nodeNextPosition;
                if ((ret & DUP_FINISHED) == DUP_FINISHED) {
                    finished = true;
                    if ((ret & DUP_NEXT) == DUP_NEXT) {
                        break;
                    }
                }
                if ((ret & DUP_DATA) == DUP_DATA) {
                    cache.add(node);
                } else if ((ret & DUP_NEXT) == DUP_NEXT) {
                    if (bulkNextNodePos.getPageNo() == nPageNo) {
                        continue;
                    } else {
                        if (cache.size() > 0) {
                            pageCount++;
                        }
                        if (pageCount < page) {
                            nPageNo = bulkNextNodePos.getPageNo();
                            buffer.releasePage(id, dupPageNumber, false);
                            dupPageNumber = new PageNumber(nPageNo);
                            dupDataPage = new DataPage(id, dupPageNumber, btreeSpec, buffer);
                        }
                    }
                } else {
                    logger.error("Failed to get next dup node.");
                }
            }
        } catch (ChaiDBException e) {
            logger.error(e);
        } finally {
            buffer.releasePage(id, dupPageNumber, false);
        }
        return Collections.unmodifiableList(cache);
    }
View Full Code Here

    protected NodeInfo getNextDataNode(NodePosition nodePos) {
        if (finished) {
            return null;
        }
        int id = btree.getBtreeId();
        final PageBufferManager buffer = btree.getBuffer();
        final BTreeSpec btreeSpec = btree.getBTreeSpec();
        dupNextCountForTest = dupNextCountForNextNode;
        dupNextCountForNextNode = 0;

        int curPageNo = nodePos.getPageNo();
        PageNumber dupPageNumber = new PageNumber(curPageNo);
        try {
            DataPage dupDataPage = new DataPage(id, dupPageNumber, btreeSpec, buffer);
            NodeInfo node = new NodeInfo();
            node.nodePosition = nodePos;
            while (true) {
                int ret = getNode(dupDataPage, node);
                if ((ret & DUP_FINISHED) == DUP_FINISHED) {
                    finished = true;
                    if ((ret & DUP_NEXT) == DUP_NEXT) {
                        break;
                    }
                }
                if ((ret & DUP_DATA) == DUP_DATA) {
                    return node;
                } else if ((ret & DUP_NEXT) == DUP_NEXT) {
                    node.nodePosition = node.nodeNextPosition;
                    if (node.nodeNextPosition.getPageNo() != curPageNo) {
                        curPageNo = node.nodeNextPosition.getPageNo();
                        buffer.releasePage(id, dupPageNumber, false);
                        dupPageNumber = new PageNumber(curPageNo);
                        dupDataPage = new DataPage(id, dupPageNumber, btreeSpec, buffer);
                    }
                } else {
                    logger.error("Failed to get next dup node.");
                    break;
                }
            }
        } catch (ChaiDBException e) {
            logger.error(e);
        } finally {
            buffer.releasePage(id, dupPageNumber, false);
        }

        return null;
    }
View Full Code Here

        byte[] data = null;
        try {
            //lock the page pointed by this node
            DataPage dataPage = new DataPage(page.getBtreeSpec().btree.getBtreeId(), pageNumber, page.getBtreeSpec(), page.getBuffer());
            data = new DataNode(dataPage, dataNodeOffset).getData();
            PageBufferManager buffer = page.getBuffer();
            buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);
            return data;
        } catch (ChaiDBException e) {
            String details = page.pageNumber.toHexString() + " of " + page.getBtreeSpec().btree.getBTreeName();
            logger.error(details);
            throw e;
View Full Code Here

     *         update date:2001-10-12 by marriane,delete freelist recover
     */
    protected boolean doRedo(byte[] page) throws ChaiDBException {
        try {
            /* add page to freelist of BufferedPage in memory*/
            PageBufferManager bp = bpm;
            bp.addToFreeList(treeId, super.getPageNum(), new Integer(super.getTxnId()));

            if (DataPage.isNormalDataPage((int) pageFlag)) {
                bp.removeLatestDataPage(docid, treeId, super.getPageNum(), new Integer(super.getTxnId()));
            }

            return true;
        } catch (Exception e) {
            logger.debug(e);
View Full Code Here

     * redo
     *
     * @return boolean true|false
     */
    protected boolean doRedo() throws ChaiDBException {
        PageBufferManager bp = bpm;
        return bp.updateBTreeSpec(treeId, newPageNum, flag, new Integer(super.getTxnId()), docIdArr, this.btreeType);

    }
View Full Code Here

                /* needn't do undo while flag is NODE_SIZE_FLAG, because
                it is not meaning. ?!*/
                flag == NODE_SIZE_FLAG) //appended by ben at Aug, 06, 2002
            return false;

        PageBufferManager bp = bpm;
        return bp.updateBTreeSpec(treeId, oldPageNum, flag, new Integer(super.getTxnId()), docIdArr, this.btreeType);
    }
View Full Code Here

     * Get a page specified by this log record.
     *
     * @return page,if sucess. Otherwise, null.
     */
    protected byte[] getPage(int newPageNum, boolean redo) throws ChaiDBException {
        PageBufferManager bp = bpm;
        byte[] page = bp.getPage(super.getTxnId(), treeId, btreeType, newPageNum, redo, locks);
        return page;
    }
View Full Code Here

    protected boolean doRedo(byte[] page) throws ChaiDBException {
        /* redo allocate a new page function */
        /* free the allocated page function */
        try {
            /* add page to freelist of BufferedPage in memory*/
            PageBufferManager bp = bpm;
            bp.addToFreeList(treeId, super.getPageNum(), new Integer(super.getTxnId()));

            if (DataPage.isNormalDataPage((int) pageFlag)) {
                bp.removeLatestDataPage(docid, treeId, super.getPageNum(), new Integer(super.getTxnId()));
            }
            return true;
        } catch (Exception e) {
            logger.debug(e);
            throw new ChaiDBException(ErrorCode.LOG_REDO_FAILED, e.toString());
View Full Code Here

            /* set metadata's lowbound and uppbound data with default value */
            System.arraycopy(ByteTool.shortToBytes((short) BTreeSpec.PAGE_HEADER_SIZE), 0, page, BTreeSpec.OFF_LOWERBOUND, 2);
            System.arraycopy(ByteTool.shortToBytes((short) BTreeSpec.PAGE_SIZE), 0, page, BTreeSpec.OFF_UPPERBOUND, 2);

            /* add page to freelist of BufferedPage in memory*/
            PageBufferManager bp = bpm;
            bp.addToFreeList(treeId, super.getPageNum(), new Integer(super.getTxnId()));

            if (isDataPage(pageFlag))
                bp.removeLatestDataPage(docId, treeId, super.getPageNum(), new Integer(super.getTxnId()));

            //add 1 on the free page number in metadata page of file if it's not in freelist
        } catch (Exception e) {
            logger.debug(e);
            throw new ChaiDBException(ErrorCode.LOG_UNDO_FAILED, e.toString());
View Full Code Here

TOP

Related Classes of org.chaidb.db.index.btree.bufmgr.PageBufferManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.