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

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


        return dataNode;
    }

    private void insertWhenKeyExistAndOverflow(DataNode dataNode, boolean needLog, int txnId) throws ChaiDBException {
        // free the overflow pages
        PageNumber overflowPageNumber = new PageNumber(ByteTool.bytesToInt(page, dataNode.getNodeOffset() + BTreeSpec.DATA_NODE_HEADER_SIZE, btreeSpec.isMsbFirst()));
        overflowPageNumber.setTreeId(btreeSpec.btree.getBtreeId());

        DataPage overflowPage = new DataPage(btreeSpec.btree.getBtreeId(), overflowPageNumber, btreeSpec, buffer);

        // put into freeList
        /* begin:added by marriane 2001-9-29 for logging free overflow page log record */
 
View Full Code Here


                throw new ChaiDBException(ErrorCode.BTREE_INVALID_DATAPAGE, "Page is null: " + pageNumber.toHexString() + " of " + btreeSpec.getBtreeName());

            DataNode node = getNode(nodeOff);
            // 1. free the overflow pages
            if (node.isOverflow()) {
                PageNumber overflowPageNumber = new PageNumber(ByteTool.bytesToInt(page, node.getNodeOffset() + BTreeSpec.DATA_NODE_HEADER_SIZE, btreeSpec.isMsbFirst()));
                if (needLog) {
                    byte[] removeData = ByteTool.append(node.getHeader(), ByteTool.intToBytes(overflowPageNumber.getPageNumber()));
                    BTreeAddRemoveLogRecord logRec = new BTreeAddRemoveLogRecord(pageNumber.getTreeId(), pageNumber.getPageNumber(), txnId, BTreeAddRemoveLogRecord.REMOVE_FLAG, node.getNodeOffset(), removeData, btreeSpec.btree.getType());
                    logRec.log();
                }

                overflowPageNumber.setTreeId(btreeSpec.btree.getBtreeId());

                DataPage overflowPage = new DataPage(btreeSpec.btree.getBtreeId(), overflowPageNumber, btreeSpec, buffer);
                // put into freeList
                /* begin:added by marriane 2001-9-29 for logging free overflow page log record */
                if (needLog) {
View Full Code Here

    private void init() throws ChaiDBException {
        nextNodeIndexes = new int[nBTree.getLayers()];
        currentPageNumbers = new PageNumber[nextNodeIndexes.length];
        keys = new Key[nextNodeIndexes.length];

        PageNumber root = new PageNumber(nBTree.getTopRoot());
        resetLayers(0, root);

    }
View Full Code Here

        resetLayers(0, root);

    }

    private void resetLayers(int layer, PageNumber root) throws ChaiDBException {
        PageNumber tmpRoot = new PageNumber(root);
        for (int i = layer; i < nextNodeIndexes.length; i++) {
            BTreePage bPage = nBTree.findLeftMostLeaf(tmpRoot);
            currentPageNumbers[i] = new PageNumber(bPage.getPageNumber());
            if (bPage.getPage() == null) return;

            nextNodeIndexes[i] = 0;
            if (i < nextNodeIndexes.length - 1) {
                BTreeNode node = bPage.getNode(nextNodeIndexes[i]);
                tmpRoot = new PageNumber((PageNumber) nBTree.convertValue(node.getData(kContext), i));
            }
            bPage.release(false);
        }
    }
View Full Code Here

        }

        //reset the underlying btree
        if (layer < nextNodeIndexes.length - 1) {
            BTreeNode node = bPage.getNode(nextNodeIndexes[layer]);
            PageNumber root = (PageNumber) (nBTree.convertValue(node.getData(kContext), layer));
            resetLayers(layer + 1, root);
        }

        return false;
    }
View Full Code Here

    public static synchronized void pageHistoryAll() {
        java.util.Collection colTrees = trees.values();
        java.util.Iterator iterTrees = colTrees.iterator();
        Hashtable hashTree = null;
        java.util.Enumeration enuTree = null;
        PageNumber history = null;
        while (iterTrees.hasNext()) {
            hashTree = (Hashtable) iterTrees.next();
            enuTree = hashTree.keys();

            while (enuTree.hasMoreElements()) {
View Full Code Here

                String details = "Converter failed to decode : " + ee.toString() + ".";
                throw new ChaiDBException(ErrorCode.CONVERTER_DECODING_ERROR, details);
            }
            else return data;
        } else {
            PageNumber pg = new PageNumber(ByteTool.bytesToInt(data, 0, btreeSpec.isMsbFirst()));
            pg.setTreeId(id);
            return pg;
        }
    }
View Full Code Here

        ValueList values = null;
        for (int i = 0; i < 3; i++) {
            try {
                checkKeyPath(keys, canNotBeNulls);

                PageNumber root = new PageNumber(getTopRoot());
                values = new ValueList(false);
                lookup(keys, 1, root, values, kContext);


            } catch (ChaiDBException e) {
View Full Code Here

        return values.size() > 0 ? values : null;
    }

    private PageNumber store(Key[] keys, byte[] value, short mode, int level, PageNumber root, KernelContext kContext) throws ChaiDBException {

        PageNumber newRoot = null;

        if (level == getLayers()) {
            newRoot = super.store(keys[level - 1], value, mode, root, kContext);
        } else {
            BTreePage rootPage = getPage(root);
            if (rootPage.getPage() == null) {
                rootPage = BTreePage.newPage(btreeSpec, getBuffer(), kContext);
                rootPage.setLeaf();
                rootPage.setPrevPage(new PageNumber(id, 0, 0)); // root
                newRoot = rootPage.pageNumber;
            }
            BTreePage leafPage = rootPage.getLeaf(keys[level - 1], kContext, BTreePage.INSERT);
            //unfix rootPage
            getBuffer().releasePage(id, rootPage.pageNumber, false);

            //find the next layer root
            BTreeNode node = leafPage.search(keys[level - 1], kContext);

            if (node != null) root = (PageNumber) convertValue(node.getData(kContext), level);
            else root.setPageNumber(BTreeSpec.INVALID_PAGENO);

            PageNumber tmpPgNum = store(keys, value, mode, level + 1, root, kContext);
            boolean leafPageUpdated = (tmpPgNum != null);
            if (tmpPgNum != null)
                tmpPgNum = leafPage.insert(keys[level - 1], ByteTool.intToBytes(tmpPgNum.getPageNumber(), btreeSpec.isMsbFirst()), STORE_REPLACE, kContext);

            getBuffer().releasePage(id, leafPage.pageNumber, leafPageUpdated);

            //remember the new root
            if (tmpPgNum != null) newRoot = tmpPgNum;
View Full Code Here

        }


        for (int retry = 0; retry < BTreeLock.MAX_RETRYS + 1 && !succ; retry++) {
            try {
                PageNumber root = new PageNumber(getTopRoot());
                root = store(keys, data, mode, 1, root, kContext);
                if (root != null) updateRootOnMetaPage(root, kContext);
                succ = true;
            } catch (ChaiDBException e) {
                if (e.getErrorCode() != ErrorCode.LOCK_NO_GRANT || retry == BTreeLock.MAX_RETRYS) throw e;
View Full Code Here

TOP

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

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.