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

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


        boolean succ = false;

        //retry to finish this operation with maxized MAX_RETRYS times.
        for (int retry = 0; retry < BTreeLock.MAX_RETRYS + 1 && !succ; retry++)
            try {
                PageNumber root = getDocRoot(((NodeId) key).getDocId(), kContext);

                root = store(key, value, mode, root, kContext);
                if (root == null) {
                    succ = true;
                    return;
View Full Code Here


    /**
     * load root of the specified document
     */
    private PageNumber getDocRoot(int docID, KernelContext kContext) throws ChaiDBException {

        PageNumber docRoot;
        docRoot = (PageNumber) id2root.get(new Integer(docID));

        if (docRoot != null) {
            return docRoot;
        }
        Key tmpKey = new IntKey(docID);
        indexBTree.acquire(kContext, READ_MODE);
        byte[] bRoot = null;
        try {
            bRoot = (byte[]) indexBTree.lookup(tmpKey, kContext);
        } finally {
            indexBTree.release(kContext);
        }
        if (bRoot != null) docRoot = new PageNumber(ByteTool.bytesToInt(bRoot, 0, btreeSpec.isMsbFirst()));
        else docRoot = new PageNumber(BTreeSpec.INVALID_PAGENO);
        synchronized (cleanIdQueue) {
            if (id2root.size() >= MAX_ENTRY_NUMBERS) {
                //need to kick out last entry.
                Integer doc_id = null;
                //Todo: cleanIdQueue.size == 0 , exist memory leak
                for (int i = 0; i < KICK_NUMBERS && cleanIdQueue.size() > 0; i++) {
                    doc_id = (Integer) cleanIdQueue.removeLast();
                    id2root.remove(doc_id);
                }
            }

            id2root.put(new Integer(docID), docRoot);
            cleanIdQueue.addFirst(new Integer(docID));
        }


        docRoot.setTreeId(id);
        return docRoot;
    }
View Full Code Here

        int txnId = kContext.getLocker();
        boolean needLog = kContext.getNeedLog();

        //search key2root first
        Integer idocID = new Integer(docID);
        PageNumber subRoot = (PageNumber) id2root.get(idocID);
        if (subRoot == null) {
            Key tmpKey = new IntKey(docID);
            indexBTree.acquire(kContext, READ_MODE);
            byte[] bRoot = null;
            try {
                bRoot = (byte[]) indexBTree.lookup(tmpKey, kContext);
            } finally {
                indexBTree.release(kContext);
            }

            if (bRoot != null) subRoot = new PageNumber(ByteTool.bytesToInt(bRoot, 0, btreeSpec.isMsbFirst()));
            else subRoot = null;

        }

        if (needLog) {
            BTreeSpecLogRecord logRec = new BTreeSpecLogRecord(id, subRoot == null ? -1 : subRoot.getPageNumber(), docRoot.getPageNumber(), BTreeSpecLogRecord.DOC_ROOT_PAGE_NUMBER_FLAG, txnId, docID, IDBIndex.ID2NODE_BTREE);
            logRec.log();
        }

        docRoot.setTreeId(id);
        if (subRoot == null) id2root.put(idocID, docRoot);
        else subRoot.setPageNumber(docRoot);

        //This situation occurs to do commit like operation(such as delete, modify node etc)after getDocument operation
        synchronized (cleanIdQueue) {
            cleanIdQueue.remove(idocID);
        }
View Full Code Here

    }

    //called when a txn commits if txn exists OR btree destroy if no txn
    public void flushDocRoot(Integer docID, KernelContext kContext) throws ChaiDBException {

        PageNumber docRoot = (PageNumber) id2root.get(docID);
        if (docRoot == null) {
            //Due to dirty root don't join into clean queue, so don't be kick out.
            //so there is no entry in memory, it represents it don't need be flushed.
//            if (Debug.DEBUG_ID2ROOT){    //Todo: remove it
//                new Throwable("doc id " + docID.intValue()).printStackTrace(System.err);
//            }
            return;
        }
        this.getBTreeSpec().setModified(true);
        /*Appended by ben zhang at aug, 14, 2002 */
        IntKey tmpKey = new IntKey(docID.intValue());

        try {
            indexBTree.acquire(kContext, WRITE_MODE);
            if (docRoot.getPageNumber() <= 0) {
                indexBTree.delete(tmpKey, kContext);
            } else {
                indexBTree.store(tmpKey, ByteTool.intToBytes(docRoot.getPageNumber(), btreeSpec.isMsbFirst()), STORE_REPLACE, kContext);

            }
        } finally {
            indexBTree.release(kContext);
        }
View Full Code Here

            }

            return;
        }

        PageNumber subRoot = (PageNumber) id2root.get(idocID);
        if (subRoot == null) id2root.put(idocID, docRoot);
        else subRoot.setPageNumber(docRoot);


        synchronized (cleanIdQueue) {
            cleanIdQueue.remove(idocID);
            cleanIdQueue.addFirst(idocID);
View Full Code Here

     * @param kContext
     * @throws ChaiDBException
     */
    public void deleteSubTree(int docId, KernelContext kContext) throws ChaiDBException {
        this.getBTreeSpec().setModified(true);
        PageNumber subRoot = new PageNumber(getDocRoot(docId, kContext));
        updateDocRoot(docId, new PageNumber(BTreeSpec.INVALID_PAGENO), kContext);
        delSubTreeCore(subRoot, false, kContext);

    }
View Full Code Here

    protected void initParameter(IBTree bt, BTreeSpec btSpec, PageBufferManager buffer, KernelContext kContext) {
        setBtree(bt);
        setBtreeSpec(btSpec);
        this.setBuffer(buffer);
        setCurrentPageNumber(new PageNumber());
        this.setkContext(kContext);
    }
View Full Code Here

    /**
     * find the leftmost leaf page number, store it to currentPageNumber
     */
    protected void init() throws ChaiDBException {
        PageNumber root = null;
        root = getBtreeSpec().getRootPageNumber();
        TreeEnumeratorUtils.findLeftMostLeaf(this, root);
    }
View Full Code Here

                // and there is no successing leaf page after the current one, return false
                int nodes = leafPage.getCurrNodeNumbers();

                if (getNextNodeIndex() >= nodes) {
                    if (leafPage.nextPage.getPageNumber() > 0) setNextNodeIndex(0);
                    this.currentPageNumber = new PageNumber(leafPage.nextPage);

                } else return true;

            }
        } catch (Exception e) {
View Full Code Here

    public void acquire(KernelContext kContext, int mode) throws ChaiDBException {
        Lock lock = null;
        try {
            if (mode == IBTreeConst.READ_MODE) {
                lock = BTreeLock.acquire(kContext, LockManager.LOCK_WAITING, new PageNumber(id, 0, 0), LockManager.LOCK_READ);
            } else if (mode == IBTreeConst.WRITE_MODE) {
                lock = BTreeLock.acquire(kContext, LockManager.LOCK_WAITING, new PageNumber(id, 0, 0), LockManager.LOCK_WRITE);
            } else {
                logger.fatal("Open mode is not recognized.");
            }
            kContext.addLock(getBTreeName(), lock);
        } catch (ChaiDBException 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.