Package org.chaidb.db.log

Examples of org.chaidb.db.log.LogRecord


    /**
     * Undo the transaction.
     */
    private void undo() throws ChaiDBException {
        Lsn keyLsn;
        LogRecord logRecord;

        keyLsn = this.lastLsn;
        if (keyLsn.equals(_INVALID_LSN)) return;
        logRecord = lnkTransactionManager.getLogManager().get(keyLsn);

        /* Allocate a transaction list for children or aborted page creates. */
        for (keyLsn = this.lastLsn; !keyLsn.equals(_INVALID_LSN); keyLsn = logRecord.getPrevLsn()) {
            logRecord = lnkTransactionManager.getLogManager().get(keyLsn);
            try {
                logRecord.recover(LogRecord.UNDO);
            } catch (ChaiDBException ie) {
                logger.error(ie);
                throw new ChaiDBException(ErrorCode.UNDO_FAILURE, ie);
            }

View Full Code Here


     * Redo operation.
     * @exception ChaiDBException Exception while doing redo operation.
     *
     */
    private void redo() throws ChaiDBException {
        LogRecord cursorLogRecord;
        boolean cont = true;
        int currentProcess = 0;
        int percent;
        while (cont) {
            long start1 = System.currentTimeMillis();

            while (redoStack.size() != 0) {
                cursorLogRecord = (LogRecord) redoStack.pop();
                if (this instanceof CatastrophicTxnRecoverImpl) {
                    redo_current++;
                    percent = redo_current / redo_average;
                    if (percent != currentProcess) {
                        currentProcess++;
                        if (currentProcess <= 5) System.out.print("\r" + (currentProcess + 5) + "0% completed.");
                    }
                }
                try {
                    cursorLogRecord.recover(LogRecord.REDO);
                } catch (ChaiDBException e) {
                    logger.error(e.toString());
                    continue;
                }
            }
View Full Code Here

     * V3.1 should be compatible to V3.0
     */
    protected boolean undo() throws ChaiDBException {
        this.status = UNDO_STAGE;
        Lsn cursorLsn = null;
        LogRecord cursorLogRecord = null;
        int countCkp = 0; //checkpoint count number

        //Gets the lastest lsn in lsn.idb file.
        cursorLsn = txnManager.getLogManager().getLastLsnInFlush();
        boolean isEnd = false;
        Lsn smallestLsn = null;
        while (!isEnd) {
            try {
                cursorLogRecord = txnManager.getLogManager().get(cursorLsn);
            } catch (ChaiDBException e) {
                logger.error(e);
                throw e;
            }
            /* according to different log type to do different handling */
            switch (cursorLogRecord.getType()) {
                case LogRecord.LOG_TXN_CHILD:
                    break;
                case LogRecord.LOG_TXN_CHECKPOINT://V3.0 standard checkpoint consistent state
                    countCkp++;
                    if (countCkp == 1) {
                        this.txnManager.setLastCkp(cursorLsn);
                    } else if (countCkp == 2) {
                        isEnd = true;
                    }
                    break;
                case LogRecord.LOG_TXN_FUZZY_CHECKPOINT://V3.1 fuzzy checkpoint
                    countCkp++;
                    if (countCkp == 1) {
                        this.txnManager.setLastCkp(cursorLsn);
                    } else if (countCkp == 2) {
                        TxnFuzzyCkpLogRecord fuzzyCkpLog = (TxnFuzzyCkpLogRecord) cursorLogRecord;
                        /* V3.1, if no active txn while doing fuzzy checkpoint,
                            smallestLsn is equals to current checkpoint log lsn,if
                            has active txns,it's euqals to smallest first_lsn of all
                            active txns. */
                        smallestLsn = fuzzyCkpLog.getSmallestLsn();
                    }
                    break;
                default:
                    //Adding TxnRegopLogRecord to redostack,and do its redo function for release txn resource of btree.
                    if (cursorLogRecord.getType() == LogRecord.LOG_TXN_REGOP) {
                        Integer txnid = new Integer(cursorLogRecord.getTxnId());
                        redoTable.put(txnid, txnid);
                    }

                    boolean doUNDO = false;
                    if (!redoTable.containsKey(new Integer(cursorLogRecord.getTxnId()))) {
                        doUNDO = true;
                    }

                    if (cursorLogRecord.getType() == LogRecord.LOG_DELETE_FILES) {
                        if (!redoTable.containsKey(new Integer(cursorLogRecord.getTxnId()))) {
                            Integer txnid = new Integer(cursorLogRecord.getTxnId());
                            redoTable.put(txnid, txnid);
                        }
                        doUNDO = false;
                    }

                    if (doUNDO) {
                        try {
                            cursorLogRecord.recover(LogRecord.UNDO);
                        } catch (ChaiDBException ie11) {
                            logger.error(ie11);
                            continue;
                        }
                    } else { //push into redo stack
                        redoStack.push(cursorLogRecord);
                        if (redoStack.size() == STACK_MAXSIZE) {
                            logger.info("Stack change. " + redoStack.size());

                            saveStack(cursorLsn);
                            logger.info(", New=" + redoStack.size() + " Stack" + (++stacks));
                        }

                    }
            }//switch

            if (cursorLsn.getOffset() == LogManager.FIRSTREC_PREVOFFSET || //current lsn is the first lsn of all log files
                    (smallestLsn != null && cursorLsn.compare(smallestLsn) == 0)//current lsn is equal to smallest lsn
                    ) {
                isEnd = true;
            }

            cursorLsn = new Lsn(cursorLsn.getFileId(), cursorLogRecord.getHeader().getPrevOffset());

        }//while

        if (countCkp == 0) {
            this.txnManager.setLastCkp(new Lsn(LogManager.FIRSTREC_LSN));
View Full Code Here

        }
        while (lastTxnList.size() > 0) {
            TransactionLog transactionLog = (TransactionLog) lastTxnList.getFirst();
            byte[] data = transactionLog.pop();
            if (data != null) {
                LogRecord log = RecordFactory.createRecord(data, 0);
                if (log != null) {
                    logCount++;
                    return log;
                }
            }
View Full Code Here

TOP

Related Classes of org.chaidb.db.log.LogRecord

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.