Package org.chaidb.db.exception

Examples of org.chaidb.db.exception.ChaiDBException


            // unfix child page
            buffer.releasePage(childPage.pageNumber.getTreeId(), childPage.pageNumber, true);
        } else {
            // leftmost is the new data
            if (data.length != 4) throw new ChaiDBException(ErrorCode.BTREE_INT_PAGE_NUMBER);
            PageNumber leftmostPageNumber = new PageNumber(ByteTool.bytesToInt(data, 0, btreeSpec.isMsbFirst()));
            leftmostPageNumber.setTreeId(btreeSpec.btree.getBtreeId());

            /********* add by leon *******/
            newPage.setLogInfo(txnId, needLog);
View Full Code Here


        try {
            // fix the page first
            page = buffer.getPage(pageNumber.getTreeId(), pageNumber);

            if (page == null)
                throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "Page is null: " + pageNumber.toHexString() + " of " + btreeSpec.getBtreeName());
            if (Debug.DEBUG_CHECKPAGENUMBER) {
                if (!Debug.checkPageNumber(pageNumber, this.page)) {
                    logger.fatal(new Throwable("there is hole in GetPage!"));
                    this.buffer.dump();
                    Db.getLogManager().flush();
                    Debug.dumpPageToLog(page);
                    if (Debug.DEBUG_PAGEINFO_TRACE) Debug.pageHistory(this.pageNumber);

                    System.exit(-1);

                }
            }

            if (isLeaf()) {
                return this;
            }
            int nodeNumbers = getCurrNodeNumbers();
            if (nodeNumbers <= 0 || nodeNumbers > btreeSpec.getNodeOrder()) {
                String logMessage = new StringBuffer().append("Page ").append(pageNumber).append(" has invalid node number: ").append(nodeNumbers).toString();
                logger.error(logMessage);
                throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, logMessage);
            }

            int nodeIndexFirst = 0;
            int nodeIndexLast = nodeNumbers - 1;
            int nodeIndex = 0;

            // Binary search within page nodes
            while (nodeIndexLast > nodeIndexFirst) {
                nodeIndex = (nodeIndexFirst + nodeIndexLast) / 2;
                BTreeNode node = getNode(nodeIndex);
                /*Modified by ben zhang at aug, 12, 2002 */
                Key tmpKey = node.getKey();
                int cmp = tmpKey.compareTo(key);
                if (cmp > 0) {
                    nodeIndexLast = nodeIndex - 1;
                } else if (cmp < 0) {
                    nodeIndexFirst = nodeIndex;
                    if (nodeIndexLast - nodeIndexFirst == 1) {
                        BTreeNode node2 = getNode(nodeIndexLast);
                        /*Modified by ben zhang at aug, 12, 2002 */
                        tmpKey = node2.getKey();
                        int cmpResult = tmpKey.compareTo(key);
                        if (cmpResult > 0) {
                            //lock it with shared lock.

                            //update the lowest predecessor must be locked
                            BTreePage nPage = lockAPage(kContext, node.getPageNumber(), oper);

                            // unfix current page
                            buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);
                            returnPage = nPage.getLeaf(key, kContext, oper);
                            buffer.releasePage(nPage.pageNumber.getTreeId(), nPage.pageNumber, false);
                            return returnPage;
                        } else {
                            //lock it with shared lock.

                            BTreePage page = lockAPage(kContext, node2.getPageNumber(), oper);
                            // unfix current page
                            buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);
                            returnPage = page.getLeaf(key, kContext, oper);
                            buffer.releasePage(page.pageNumber.getTreeId(), page.pageNumber, false);
                            return returnPage;
                        }
                    }
                } else { // Exact match
                    //lock it with shared lock.
                    BTreePage page = lockAPage(kContext, node.getPageNumber(), oper);
                    // unfix current page
                    buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);
                    returnPage = page.getLeaf(key, kContext, oper);
                    buffer.releasePage(page.pageNumber.getTreeId(), page.pageNumber, false);
                    return returnPage;
                }
            } // end of binary search

            if (nodeIndexFirst - nodeIndexLast == 1) {
                // go to leftmost node
                if (nextPage.getPageNumber() > 0) {
                    //lock it with shared lock.

                    BTreePage leftPage = lockAPage(kContext, nextPage, oper);
                    // unfix current page
                    buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);
                    returnPage = leftPage.getLeaf(key, kContext, oper);
                    buffer.releasePage(leftPage.pageNumber.getTreeId(), leftPage.pageNumber, false);
                    return returnPage;
                } else {
                    logger.error("Page " + pageNumber.toHexString() + " " + buffer.getBTreeName(pageNumber.getTreeId()) + " missing leftmost page " + Debug.getDebugInfo());
                    //Debug.pageHistory(Integer.toHexString(pageNumber.getPageNumber()));
                    Debug.flushPages();
                    if (Debug.DEBUG_THREAD) Debug.flushThreads();
                    // details -ranjeet
                    String details = "The page number is " + pageNumber.toHexString() + ".";
                    throw new ChaiDBException(ErrorCode.BTREE_LEFTMOST_PAGE_MISSING, details);
                }
            }
            // now binary search has identified a single node
            BTreeNode node = getNode(nodeIndexFirst);
            /* Modified by ben zhang at aug, 12, 2002 */
            Key tmpKey1 = node.getKey();
            int cmp = key.compareTo(tmpKey1);
            if (cmp < 0) {
                // go to leftmost pointer
                if (nextPage.getPageNumber() > 0) {
                    //lock it with shared lock.

                    BTreePage leftPage = lockAPage(kContext, nextPage, oper);
                    // unfix current page
                    buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);
                    returnPage = leftPage.getLeaf(key, kContext, oper);
                    buffer.releasePage(leftPage.pageNumber.getTreeId(), leftPage.pageNumber, false);
                    return returnPage;
                } else {
                    logger.error("Page " + pageNumber + " missing leftmost page " + Debug.getDebugInfo());
                    //Debug.pageHistory(Integer.toHexString(pageNumber.getPageNumber()));
                    Debug.flushPages();
                    if (Debug.DEBUG_THREAD) Debug.flushThreads();

                    //Thread.dumpStack(); System.exit(1);
                    // details -ranjeet
                    String details = "The page number is " + pageNumber.getPageNumber() + ".";
                    throw new ChaiDBException(ErrorCode.BTREE_LEFTMOST_PAGE_MISSING, details);
                }
            }

            BTreePage nPage = lockAPage(kContext, node.getPageNumber(), oper);
            // unfix current page
View Full Code Here

        try {
            // fix the page
            page = buffer.getPage(pageNumber.getTreeId(), pageNumber);
            if (page == null)
                throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "Page is null: " + pageNumber.toHexString() + " of " + btreeSpec.getBtreeName());
            if (Debug.DEBUG_CHECKPAGENUMBER) {
                if (!Debug.checkPageNumber(pageNumber, this.page)) {
                    logger.fatal(new Throwable("there is hole in GetPage!"));
                    this.buffer.dump();
                    Db.getLogManager().flush();
                    Debug.dumpPageToLog(page);
                    if (Debug.DEBUG_PAGEINFO_TRACE) Debug.pageHistory(this.pageNumber);

                    System.exit(-1);

                }
            }

            // Binary search within page
            int nodeIndexFirst = 0;
            int nodeIndexLast = getCurrNodeNumbers() - 1;
            while (nodeIndexLast > nodeIndexFirst) {
                int nodeIndex = (nodeIndexFirst + nodeIndexLast) / 2;
                BTreeNode node = getNode(nodeIndex);
                /* Modified by ben zhang at aug, 12, 2002 */
                Key tmpKey = node.getKey();
                int cmp = tmpKey.compareTo(key);
                if (cmp > 0) {
                    nodeIndexLast = nodeIndex - 1;
                } else if (cmp < 0) {
                    nodeIndexFirst = nodeIndex;
                    if (isLeaf()) nodeIndexFirst++;
                    else if (nodeIndexLast - nodeIndexFirst == 1) {
                        BTreeNode node2 = getNode(nodeIndexLast);
                        /*Modified by ben zhang at aug, 12, 2002 */
                        tmpKey = node2.getKey();
                        int cmpResult = tmpKey.compareTo(key);
                        if (cmpResult > 0) {
                            BTreePage page = this.lockAPage(kContext, node.getPageNumber(), SEARCH);
                            // unfix the current page
                            buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);

                            returnNode = page.search(key, kContext);
                            // unfix the current page
                            buffer.releasePage(btreeSpec.btree.getBtreeId(), page.pageNumber, false);
                            return returnNode;
                        } else {
                            BTreePage page = this.lockAPage(kContext, node2.getPageNumber(), SEARCH);
                            // unfix the current page
                            buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);

                            returnNode = page.search(key, kContext);
                            // unfix the current page
                            buffer.releasePage(btreeSpec.btree.getBtreeId(), page.pageNumber, false);
                            return returnNode;
                        }
                    }
                } else { // Exact match
                    if (isLeaf()) {
                        return node;
                    }
                    BTreePage page = this.lockAPage(kContext, node.getPageNumber(), SEARCH);
                    // unfix the current page
                    buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);

                    returnNode = page.search(key, kContext);
                    // unfix the new allocated page
                    buffer.releasePage(btreeSpec.btree.getBtreeId(), page.pageNumber, false);
                    return returnNode;
                }
            } // end of binary search

            if (!isLeaf() && nodeIndexFirst - nodeIndexLast == 1) {
                // go to leftmost node
                if (nextPage.getPageNumber() > 0) {
                    BTreePage page = this.lockAPage(kContext, nextPage, SEARCH);
                    // unfix current page
                    buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);

                    returnNode = page.search(key, kContext);
                    // unfix the new allocated page
                    buffer.releasePage(btreeSpec.btree.getBtreeId(), page.pageNumber, false);
                    return returnNode;
                } else {
                    logger.error("Page " + pageNumber.toHexString() + " " + buffer.getBTreeName(pageNumber.getTreeId()) + " missing leftmost page " + Debug.getDebugInfo());
                    //Debug.pageHistory(Integer.toHexString(pageNumber.getPageNumber()));
                    Debug.flushPages();
                    if (Debug.DEBUG_THREAD) Debug.flushThreads();
                    // details -ranjeet
                    String details = "The page number is " + pageNumber.toHexString() + ".";
                    throw new ChaiDBException(ErrorCode.BTREE_LEFTMOST_PAGE_MISSING, details);
                }
            }

            // now binary search has identified a single node
            // node.setTreeId(btreeSpec.btree.getBtreeId());
            // Leaf node? need an exact match to avoid failure
            if (isLeaf()) {
                BTreeNode node = getNode(nodeIndexFirst);
                //buffer.releasePage(pageNumber.getTreeId() ,pageNumber, false);
                /*Modified by ben zhang at aug, 12, 2002 */
                if (node != null && node.getKey().compareTo(key) == 0) return node;
                else {
                    //release it for outside this method, this page can't be found any longer.
                    buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);
                    return null;
                }
            } else {
                BTreeNode node = getNode(nodeIndexFirst);
                /*Modified by ben zhang at aug, 12, 2002 */
                Key tmpKey = node.getKey();
                int cmp = key.compareTo(tmpKey);
                if (cmp < 0) {
                    // go to leftmost pointer
                    if (nextPage.getPageNumber() > 0) {
                        BTreePage page = this.lockAPage(kContext, nextPage, SEARCH);
                        // unfix current page
                        buffer.releasePage(pageNumber.getTreeId(), pageNumber, false);

                        returnNode = page.search(key, kContext);
                        // unfix the new allocated page
                        buffer.releasePage(btreeSpec.btree.getBtreeId(), page.pageNumber, false);
                        return returnNode;
                    } else {
                        logger.error("Page " + pageNumber + " missing leftmost page " + Debug.getDebugInfo());
                        //Debug.pageHistory(Integer.toHexString(pageNumber.getPageNumber()));
                        Debug.flushPages();
                        if (Debug.DEBUG_THREAD) Debug.flushThreads();
                        // details -ranjeet
                        String details = "The page number is " + pageNumber.getPageNumber() + ".";
                        throw new ChaiDBException(ErrorCode.BTREE_LEFTMOST_PAGE_MISSING, details);
                    }
                }

                BTreePage page = this.lockAPage(kContext, node.getPageNumber(), SEARCH);
                // unfix the current page
View Full Code Here

     * @return an object representing the indicated node on this page
     */
    // did NOT unfix the page ###
    public BTreeNode getNode(int nodeIndex) throws ChaiDBException {
        if (nodeIndex >= getCurrNodeNumbers())
            throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "nodeIndex is out of bound:" + nodeIndex + " max available:" + getCurrNodeNumbers());
        // Build and return a node object
        BTreeNode node = new BTreeNode(this, getNodeOffset(nodeIndex));

        return node;
    }
View Full Code Here

                if (Debug.DEBUG_DUMP_MEMORY) buffer.dumpMemInfo(Debug.DUMP_ALL, "memory");
                if (Debug.DEBUG_PAGEINFO_TRACE) Debug.pageHistory(this.pageNumber);
                System.exit(-1);
            }

            throw new ChaiDBException(ErrorCode.ENTRY_NOEXIST, details);
        }
        if (nodeIndex >= getCurrNodeNumbers()) {
            // details -ranjeet
            String details = "Request for node that is not present." + " nodeIndex=" + nodeIndex + " page=" + pageNumber.toHexString() + " of " + btreeSpec.getBtreeName() + ByteTool.toHexString(2, page, 0, page.length);

            logger.error(details);
            Debug.pageHistory(pageNumber);

            throw new ChaiDBException(ErrorCode.ENTRY_NOEXIST, details);
        }
        // fix the page first
        //page = buffer.getPage(pageNumber.getTreeId() ,pageNumber);
        // 20-byte header + 2 bytes per pointer
        int offset = BTreeSpec.PAGE_HEADER_SIZE + 2 * nodeIndex;
        // Convert the two-byte pointer to an short
        short ptr = ByteTool.bytesToShort(page, offset, btreeSpec.isMsbFirst());
        if (ptr > page.length) {
            throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "offset of btree node is out of bound:" + ptr);
        }
        return (int) ptr;
    }
View Full Code Here

        try {
            // fix the page
            page = buffer.getPage(pageNumber.getTreeId(), pageNumber);
            if (page == null)
                throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "Page is null: " + pageNumber.toHexString() + " of " + btreeSpec.getBtreeName());
            if (Debug.DEBUG_CHECKPAGENUMBER) {
                if (!Debug.checkPageNumber(pageNumber, this.page)) {
                    logger.fatal(new Throwable("there is hole in GetPage!"));
                    this.buffer.dump();
                    Db.getLogManager().flush();
View Full Code Here

            }

            // fix the current page
            page = buffer.getPage(pageNumber.getTreeId(), pageNumber);
            if (page == null)
                throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "Page is null: " + pageNumber.toHexString() + " of " + btreeSpec.getBtreeName());
            if (Debug.DEBUG_CHECKPAGENUMBER) {
                if (!Debug.checkPageNumber(pageNumber, this.page)) {
                    logger.fatal(new Throwable("there is hole in GetPage!"));
                    this.buffer.dump();
                    Db.getLogManager().flush();
View Full Code Here

                return ret;
            }
        } catch (Exception e) {
            logger.error(e);
            String errorMsg = "Exception in insertDupNode: Key is " + ((IntKey) key).getInt();
            throw new ChaiDBException(ErrorCode.BTREE_ERROR_BASE, errorMsg);
        } finally {
            //Debug
//            buffer.dumpMemInfo(PageBufferManager.DUMP_ALL, "insertDupNode_finally");
        }
    }
View Full Code Here

        nodeOffset = offset;

        /* need read the node from the page */
        byte[] rawPage = this.page.getPage();
        if (nodeOffset > rawPage.length) {
            throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "offset of btree node is out of bound:" + offset);
        }

        keySize = ByteTool.bytesToInt(rawPage, nodeOffset + BTreeSpec.NODE_OFF_KEYSIZE, this.page.btreeSpec.isMsbFirst());
        /* to prevent OOM */
        if (keySize > MAX_KEY_SIZE || keySize < MIN_KEY_SIZE) {
            throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "keysize is out of bound:" + keySize);
        }

        pageNumber = new PageNumber(ByteTool.bytesToInt(rawPage, nodeOffset + BTreeSpec.NODE_OFF_PAGENUMBER, this.page.btreeSpec.isMsbFirst()));
        pageNumber.setTreeId(page.btreeSpec.btree.getBtreeId());

        flags = rawPage[nodeOffset + BTreeSpec.NODE_OFF_FLAGS];
        if (flags < 0 || flags > 3) {
            throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "flags is out of bound:" + flags);
        }
//        if (isLeafNode()){}
        dataNodeOffset = ByteTool.bytesToShort(rawPage, nodeOffset + BTreeSpec.NODE_OFF_DATANODEOFFSET, this.page.btreeSpec.isMsbFirst());
    }
View Full Code Here

        BTreeNode node = new BTreeNode();
        node.page = page;
        node.nodeOffset = offset;
        node.keySize = key.length;
        if (node.keySize > MAX_KEY_SIZE || node.keySize < MIN_KEY_SIZE) {
            throw new ChaiDBException(ErrorCode.BTREE_INVALID_BTREEPAGE, "keysize is out of bound:" + node.keySize);
        }
        node.pageNumber = new PageNumber(dataPageNum);
        node.flags = 0;
        return node;
    }
View Full Code Here

TOP

Related Classes of org.chaidb.db.exception.ChaiDBException

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.