Package org.exist.storage.journal

Examples of org.exist.storage.journal.Loggable


                default :
                    throw new BTreeException("Invalid Page Type In split");
            }
            // Log the update of the current page
            if (transaction != null && isTransactional && pageHeader.getStatus() == LEAF) {
                final Loggable log = new UpdatePageLoggable(transaction, fileId,
                    page.getPageNum(), prefix, leftVals, leftVals.length, leftPtrs, leftPtrs.length);
                writeToLog(log, this);
            }
            setValues(leftVals);
            setPointers(leftPtrs);
            recalculateDataLen();
            // Promote the pivot to the parent branch
            BTreeNode parent = getParent();
            if (parent == null) {
                // This can only happen if this is the root
                parent = createBTreeNode(transaction, BRANCH, null, false);
                // Log change of the parent page
                if (transaction != null && isTransactional && pageHeader.getStatus() == LEAF) {
                    final Loggable log = new SetParentLoggable(transaction, fileId, page.getPageNum(),
                        parent.page.getPageNum());
                    writeToLog(log, this);
                }
                setParent(parent);
                final BTreeNode rNode = createBTreeNode(transaction, pageHeader.getStatus(), parent, false);
                rNode.setValues(rightVals);
                rNode.setPointers(rightPtrs);
                rNode.setAsParent(transaction);
                if (pageHeader.getStatus() == BRANCH) {
                    rNode.prefix = prefix;
                    rNode.growPrefix();
                } else {
                    if (transaction != null && isTransactional) {
                        final Loggable log = new SetPageLinkLoggable(transaction,
                            fileId, page.getPageNum(), rNode.page.getPageNum());
                        writeToLog(log, this);
                    }
                    pageHeader.setNextPage(rNode.page.getPageNum());
                }
                // Log update of the right node
                if (isTransactional && transaction != null && pageHeader.getStatus() == LEAF) {
                    final Loggable log = new UpdatePageLoggable(transaction, fileId,
                        rNode.page.getPageNum(), rNode.prefix, rNode.keys, rNode.nKeys, rightPtrs, rightPtrs.length);
                    writeToLog(log, rNode);
                }
                rNode.recalculateDataLen();
                parent.prefix = separator;
                parent.setValues(new Value[] { Value.EMPTY_VALUE });
                parent.setPointers(new long[] { page.getPageNum(), rNode.page.getPageNum()});
                parent.recalculateDataLen();
                cache.add(parent);
                setRootNode(parent);
                if(rNode.mustSplit()) {
                    LOG.debug(getFile().getName() + " right node requires second split: " + rNode.getDataLen());
                    rNode.split(transaction);
                }
                cache.add(rNode);
            } else {
                final BTreeNode rNode = createBTreeNode(transaction, pageHeader.getStatus(), parent, false);
                rNode.setValues(rightVals);
                rNode.setPointers(rightPtrs);
                rNode.setAsParent(transaction);
                if (pageHeader.getStatus() == BRANCH) {
                    rNode.prefix = prefix;
                    rNode.growPrefix();
                } else {
                    if (transaction != null && isTransactional) {
                        Loggable log = new SetPageLinkLoggable(transaction, fileId,
                            rNode.page.getPageNum(), pageHeader.getNextPage());
                        writeToLog(log, this);
                        log = new SetPageLinkLoggable(transaction, fileId,
                            page.getPageNum(), rNode.page.getPageNum());
                        writeToLog(log, this);
                    }
                    rNode.pageHeader.setNextPage(pageHeader.getNextPage());
                    pageHeader.setNextPage(rNode.page.getPageNum());
                }
                // Log update of the right node
                if (isTransactional && transaction != null && pageHeader.getStatus() == LEAF) {
                    final Loggable log = new UpdatePageLoggable(transaction, fileId,
                        rNode.page.getPageNum(), rNode.prefix, rNode.keys,
                        rNode.nKeys, rightPtrs, rightPtrs.length);
                    writeToLog(log, rNode);
                }
                rNode.recalculateDataLen();
View Full Code Here


            rec.getPage().len = dataLength + LENGTH_TID + LENGTH_DATA_LENGTH + value.length;
            rec.getPage().getPageHeader().setDataLength(rec.getPage().len);
        }
        final short tupleID = rec.getPage().getPageHeader().getNextTupleID();
        if (isTransactional && transaction != null) {
            final Loggable loggable = new InsertValueLoggable(transaction, rec.getPage().getPageNum(), isOverflow, tupleID, value, rec.offset);
            writeToLog(loggable, rec.getPage().page);
        }
        //Write tid
        ByteConversion.shortToByte(tupleID, rec.getPage().data, rec.offset);
        rec.offset += LENGTH_TID;
View Full Code Here

        final DOMFilePageHeader pageHeader = rec.getPage().getPageHeader();
        //Copy the old data up to the split point into a new array
        final int oldDataLen = pageHeader.getDataLength();
        final byte[] oldData = rec.getPage().data;
        if (isTransactional && transaction != null) {
            final Loggable loggable = new SplitPageLoggable(transaction,
                rec.getPage().getPageNum(), rec.offset, oldData, oldDataLen);
            writeToLog(loggable, rec.getPage().page);
        }
        rec.getPage().data = new byte[fileHeader.getWorkSize()];
        System.arraycopy(oldData, 0, rec.getPage().data, 0, rec.offset);
        //The old rec.page now contains a copy of the data up to the split point
        rec.getPage().len = rec.offset;
        pageHeader.setDataLength(rec.getPage().len);
        rec.getPage().setDirty(true);
        //Create a first split page
        DOMPage firstSplitPage = new DOMPage();
        if (isTransactional && transaction != null) {
            final Loggable loggable = new CreatePageLoggable(transaction,
                rec.getPage().getPageNum(), firstSplitPage.getPageNum(),
                Page.NO_PAGE, pageHeader.getCurrentTupleID());
            writeToLog(loggable, firstSplitPage.page);
        }
        DOMPage nextSplitPage = firstSplitPage;
        nextSplitPage.getPageHeader().setNextTupleID(pageHeader.getCurrentTupleID());
        long backLink;
        short splitRecordCount = 0;
        LOG.debug("Splitting " + rec.getPage().getPageNum() + " at " + rec.offset
            + ": New page: " + nextSplitPage.getPageNum() +
            "; Next page: " + pageHeader.getNextDataPage());
        //Start copying records from rec.offset to the new split pages
        for (int pos = rec.offset; pos < oldDataLen; splitRecordCount++) {
            //Read the current id
            final short tupleID = ByteConversion.byteToShort(oldData, pos);
            pos += LENGTH_TID;
            //This is already a link, so we just copy it
            if (ItemId.isLink(tupleID)) {
                /* No room in the old page, append a new one */
                if (rec.getPage().len + LENGTH_TID + LENGTH_FORWARD_LOCATION > fileHeader.getWorkSize()) {
                    final DOMPage newPage = new DOMPage();
                    final DOMFilePageHeader newPageHeader = newPage.getPageHeader();
                    if (isTransactional && transaction != null) {
                        Loggable loggable = new CreatePageLoggable(transaction,
                            rec.getPage().getPageNum(), newPage.getPageNum(),
                            pageHeader.getNextDataPage(), pageHeader.getCurrentTupleID());
                        writeToLog(loggable, firstSplitPage.page);
                        loggable = new UpdateHeaderLoggable(transaction,
                            pageHeader.getPreviousDataPage(), rec.getPage().getPageNum(),
                            newPage.getPageNum(), pageHeader.getPreviousDataPage(),
                            pageHeader.getNextDataPage());
                        writeToLog(loggable, nextSplitPage.page);
                    }
                    newPageHeader.setNextTupleID(pageHeader.getCurrentTupleID());
                    newPageHeader.setPrevDataPage(rec.getPage().getPageNum());
                    newPageHeader.setNextDataPage(pageHeader.getNextDataPage());
                    LOG.debug("Appending page after split: " + newPage.getPageNum());
                    pageHeader.setNextDataPage(newPage.getPageNum());
                    pageHeader.setDataLength(rec.getPage().len);
                    pageHeader.setRecordCount(countRecordsInPage(rec.getPage()));
                    rec.getPage().cleanUp();
                    rec.getPage().setDirty(true);
                    dataCache.add(rec.getPage());
                    //Switch record to new page...
                    rec.setPage(newPage);
                    rec.getPage().len = 0;
                    dataCache.add(newPage);
                }
                if (isTransactional && transaction != null) {
                    final long oldLink = ByteConversion.byteToLong(oldData, pos);
                    final Loggable loggable = new AddLinkLoggable(transaction,
                        rec.getPage().getPageNum(), ItemId.getId(tupleID), oldLink);
                    writeToLog(loggable, rec.getPage().page);
                }
                ByteConversion.shortToByte(tupleID, rec.getPage().data, rec.getPage().len);
                rec.getPage().len += LENGTH_TID;
                System.arraycopy(oldData, pos, rec.getPage().data, rec.getPage().len,
                    LENGTH_FORWARD_LOCATION);
                rec.getPage().len += LENGTH_FORWARD_LOCATION;
                pos += LENGTH_FORWARD_LOCATION;
                continue;
            }
            //Read data length
            final short vlen = ByteConversion.byteToShort(oldData, pos);
            pos += LENGTH_DATA_LENGTH;
            //If this is an overflow page, the real data length is always
            //LENGTH_LINK byte for the page number of the overflow page
            final short realLen = (vlen == OVERFLOW ? LENGTH_OVERFLOW_LOCATION : vlen);
            //Check if we have room in the current split page
            if (nextSplitPage.len + LENGTH_TID + LENGTH_DATA_LENGTH +
                    LENGTH_ORIGINAL_LOCATION + realLen > fileHeader.getWorkSize()) {
                //Not enough room in the split page: append a new page
                final DOMPage newPage = new DOMPage();
                final DOMFilePageHeader newPageHeader = newPage.getPageHeader();
                if (isTransactional && transaction != null) {
                    Loggable loggable = new CreatePageLoggable(transaction,
                        nextSplitPage.getPageNum(), newPage.getPageNum(),
                        Page.NO_PAGE, pageHeader.getCurrentTupleID());
                    writeToLog(loggable, firstSplitPage.page);
                    loggable = new UpdateHeaderLoggable(transaction,
                        nextSplitPage.getPageHeader().getPreviousDataPage(),
                        nextSplitPage.getPageNum(), newPage.getPageNum(),
                        nextSplitPage.getPageHeader().getPreviousDataPage(),
                        nextSplitPage.getPageHeader().getNextDataPage());
                    writeToLog(loggable, nextSplitPage.page);
                }
                newPageHeader.setNextTupleID(pageHeader.getCurrentTupleID());
                newPageHeader.setPrevDataPage(nextSplitPage.getPageNum());
                //No next page ? Well... we might want to enforce the value -pb
                LOG.debug("Creating new split page: " + newPage.getPageNum());
                nextSplitPage.getPageHeader().setNextDataPage(newPage.getPageNum());
                nextSplitPage.getPageHeader().setDataLength(nextSplitPage.len);
                nextSplitPage.getPageHeader().setRecordCount(splitRecordCount);
                nextSplitPage.cleanUp();
                nextSplitPage.setDirty(true);
                dataCache.add(nextSplitPage);
                dataCache.add(newPage);
                nextSplitPage = newPage;
                splitRecordCount = 0;
            }
            /*
             * If the record has already been relocated,
             * read the original storage address and update the link there.
             */
            if (ItemId.isRelocated(tupleID)) {
                backLink = ByteConversion.byteToLong(oldData, pos);
                pos += LENGTH_ORIGINAL_LOCATION;
                final RecordPos originalRecordPos = findRecord(backLink, false);
                final long oldLink = ByteConversion.byteToLong(originalRecordPos.getPage().data,
                        originalRecordPos.offset);
                final long forwardLink = StorageAddress.createPointer((int)
                    nextSplitPage.getPageNum(), ItemId.getId(tupleID));
                if (isTransactional && transaction != null) {
                    final Loggable loggable = new UpdateLinkLoggable(transaction,
                        originalRecordPos.getPage().getPageNum(), originalRecordPos.offset,
                        forwardLink, oldLink);
                    writeToLog(loggable, originalRecordPos.getPage().page);
                }
                ByteConversion.longToByte(forwardLink, originalRecordPos.getPage().data,
                    originalRecordPos.offset);
                originalRecordPos.getPage().setDirty(true);
                dataCache.add(originalRecordPos.getPage());
            } else {
                backLink = StorageAddress.createPointer((int) rec.getPage().getPageNum(),
                    ItemId.getId(tupleID));
            }
            /*
             * Save the record to the split page:
            */
            if (isTransactional && transaction != null) {
                //What does this "log" mean really ? Original ? -pb
                final byte[] logData = new byte[realLen];
                System.arraycopy(oldData, pos, logData, 0, realLen);
                final Loggable loggable = new AddMovedValueLoggable(transaction,
                    nextSplitPage.getPageNum(), tupleID, logData, backLink);
                writeToLog(loggable, nextSplitPage.page);
            }
            //Set the relocated flag and save the item id
            ByteConversion.shortToByte(ItemId.setIsRelocated(tupleID), nextSplitPage.data,
                nextSplitPage.len);
            nextSplitPage.len += LENGTH_TID;
            //Save length field
            ByteConversion.shortToByte(vlen, nextSplitPage.data, nextSplitPage.len);
            nextSplitPage.len += LENGTH_DATA_LENGTH;
            //Save link to the original page
            ByteConversion.longToByte(backLink, nextSplitPage.data,  nextSplitPage.len);
            nextSplitPage.len += LENGTH_ORIGINAL_LOCATION;
            //Now save the data
            try {
                System.arraycopy(oldData, pos, nextSplitPage.data, nextSplitPage.len, realLen);
            } catch (final ArrayIndexOutOfBoundsException e) {
                SanityCheck.TRACE("pos = " + pos + "; len = " + nextSplitPage.len +
                    "; currentLen = " + realLen + "; tupleID = " + tupleID +
                    "; page = " + rec.getPage().getPageNum());
                throw e;
            }
            nextSplitPage.len += realLen;
            pos += realLen;
            // save a link pointer in the original page if the record has not
            // been relocated before.
            if (!ItemId.isRelocated(tupleID)) {
                // the link doesn't fit into the old page. Append a new page
                if (rec.getPage().len + LENGTH_TID + LENGTH_FORWARD_LOCATION > fileHeader.getWorkSize()) {
                    final DOMPage newPage = new DOMPage();
                    final DOMFilePageHeader newPageHeader = newPage.getPageHeader();
                    if (isTransactional && transaction != null) {
                        Loggable loggable = new CreatePageLoggable(transaction,
                            rec.getPage().getPageNum(), newPage.getPageNum(),
                            pageHeader.getNextDataPage(), pageHeader.getCurrentTupleID());
                        writeToLog(loggable, firstSplitPage.page);
                        loggable = new UpdateHeaderLoggable(transaction,
                            pageHeader.getPreviousDataPage(),
                            rec.getPage().getPageNum(), newPage.getPageNum(),
                            pageHeader.getPreviousDataPage(), pageHeader.getNextDataPage());
                        writeToLog(loggable, nextSplitPage.page);
                    }
                    newPageHeader.setNextTupleID(pageHeader.getCurrentTupleID());
                    newPageHeader.setPrevDataPage(rec.getPage().getPageNum());
                    newPageHeader.setNextDataPage(pageHeader.getNextDataPage());
                    LOG.debug("Creating new page after split: "  + newPage.getPageNum());
                    pageHeader.setNextDataPage(newPage.getPageNum());
                    pageHeader.setDataLength(rec.getPage().len);
                    pageHeader.setRecordCount(countRecordsInPage(rec.getPage()));
                    rec.getPage().cleanUp();
                    rec.getPage().setDirty(true);
                    dataCache.add(rec.getPage());
                    //switch record to new page...
                    rec.setPage(newPage);
                    rec.getPage().len = 0;
                    dataCache.add(newPage);
                }
                final long forwardLink = StorageAddress.createPointer(
                    (int) nextSplitPage.getPageNum(), ItemId.getId(tupleID));
                if (isTransactional && transaction != null) {
                    final Loggable loggable = new AddLinkLoggable(transaction,
                        rec.getPage().getPageNum(), tupleID, forwardLink);
                    writeToLog(loggable, rec.getPage().page);
                }
                ByteConversion.shortToByte(ItemId.setIsLink(tupleID), rec.getPage().data, rec.getPage().len);
                rec.getPage().len += LENGTH_TID;
                ByteConversion.longToByte(forwardLink, rec.getPage().data, rec.getPage().len);
                rec.getPage().len += LENGTH_FORWARD_LOCATION;
            }
        } //End of for loop: finished copying data
        //Link the split pages to the original page
        if (nextSplitPage.len == 0) {
            LOG.warn("Page " + nextSplitPage.getPageNum() + " is empty. Remove it");
            //If nothing has been copied to the last split page, remove it
            if (nextSplitPage == firstSplitPage)
                {firstSplitPage = null;}
            try {
                unlinkPages(nextSplitPage.page);
            } catch (final IOException e) {
                LOG.warn("Failed to remove empty split page: " + e.getMessage(), e);
            }
            nextSplitPage.setDirty(true);
            dataCache.remove(nextSplitPage);
            nextSplitPage = null;
        } else {
            if (isTransactional && transaction != null) {
                final Loggable loggable = new UpdateHeaderLoggable(transaction,
                    nextSplitPage.getPageHeader().getPreviousDataPage(), nextSplitPage.getPageNum(),
                    pageHeader.getNextDataPage(), nextSplitPage.getPageHeader().getPreviousDataPage(),
                    nextSplitPage.getPageHeader().getNextDataPage());
                writeToLog(loggable, nextSplitPage.page);
            }
            nextSplitPage.getPageHeader().setDataLength(nextSplitPage.len);
            nextSplitPage.getPageHeader().setNextDataPage(pageHeader.getNextDataPage());
            nextSplitPage.getPageHeader().setRecordCount(splitRecordCount);
            nextSplitPage.cleanUp();
            nextSplitPage.setDirty(true);
            dataCache.add(nextSplitPage);
            if (isTransactional && transaction != null) {
                final DOMFilePageHeader fisrtPageHeader = firstSplitPage.getPageHeader();
                final Loggable loggable = new UpdateHeaderLoggable(transaction,
                    rec.getPage().getPageNum(), firstSplitPage.getPageNum(),
                    fisrtPageHeader.getNextDataPage(), fisrtPageHeader.getPreviousDataPage(),
                    fisrtPageHeader.getNextDataPage());
                writeToLog(loggable, nextSplitPage.page);
            }
            firstSplitPage.getPageHeader().setPrevDataPage(rec.getPage().getPageNum());
            if (nextSplitPage != firstSplitPage) {
                firstSplitPage.setDirty(true);
                dataCache.add(firstSplitPage);
            }
        }
        final long nextPageNum = pageHeader.getNextDataPage();
        if (Page.NO_PAGE != nextPageNum) {
            final DOMPage nextPage = getDOMPage(nextPageNum);
            if (isTransactional && transaction != null) {
                final Loggable loggable = new UpdateHeaderLoggable(transaction,
                    nextSplitPage.getPageNum(), nextPage.getPageNum(),
                    Page.NO_PAGE, nextPage.getPageHeader().getPreviousDataPage(),
                    nextPage.getPageHeader().getNextDataPage());
                writeToLog(loggable, nextPage.page);
            }
            nextPage.getPageHeader().setPrevDataPage(nextSplitPage.getPageNum());
            nextPage.setDirty(true);
            dataCache.add(nextPage);
        }
        rec.setPage(getDOMPage(rec.getPage().getPageNum()));
        if (firstSplitPage != null) {
            if (isTransactional && transaction != null) {
                final Loggable loggable = new UpdateHeaderLoggable(transaction,
                    pageHeader.getPreviousDataPage(), rec.getPage().getPageNum(),
                    firstSplitPage.getPageNum(), pageHeader.getPreviousDataPage(),
                    pageHeader.getNextDataPage());
                writeToLog(loggable, rec.getPage().page);
            }
View Full Code Here

            if (isTransactional && transaction != null) {
                if (ItemId.getId(recordPos.getTupleID()) < 0) {
                    LOG.error("Tuple ID < 0");
                    //TODO : throw exception ? -pb
                }
                final Loggable loggable = new UpdateValueLoggable(transaction,
                    recordPos.getPage().getPageNum(), recordPos.getTupleID(),
                    value, recordPos.getPage().data, recordPos.offset);
                writeToLog(loggable, recordPos.getPage().page);
            }
            // value length unchanged
View Full Code Here

            boolean reuseDeleted) {
        try {
            final Page page = getFreePage(reuseDeleted);
            final BTreeNode node = new BTreeNode(page, true);
            if (transaction != null && isTransactional && status == LEAF) {
                final Loggable loggable = new CreateBTNodeLoggable(transaction, fileId,
                    status, page.getPageNum(), parent != null ? parent.page.getPageNum() : Page.NO_PAGE);
                writeToLog(loggable, node);
            }
            node.pageHeader.setStatus(status);
            node.setPointers(new long[0]);
View Full Code Here

                        final Value value = new Value(fullbuf, 0, chunkSize);
                        Page nextPage = createNewPage();
                        currentPage.getPageHeader().setNextPage(nextPage.getPageNum());
                        if (isTransactional && transaction != null) {
                            final long nextPageNum = nextPage.getPageNum();
                            final Loggable loggable = new WriteOverflowPageLoggable(
                                transaction, currentPage.getPageNum(),
                                nextPageNum , value);
                            writeToLog(loggable, currentPage);
                        }
                        writeValue(currentPage, value);
                        pageCount++;
                        currentPage = nextPage;
                        fullbuf=null;
                    }
                    // Let's swap the buffer
                    basebuf += len;
                    if(basebuf == chunkSize) {
                        fullbuf = currbuf;
                        currbuf = (isaltbuf)? buf : altbuf;
                        isaltbuf = !isaltbuf;
                        basebuf = 0;
                        basemax = chunkSize;
                    } else {
                        basemax -= len;
                    }
                }
                // Detecting a zero byte stream
                if(emptyPage) {
                    currentPage.setPageNum(Page.NO_PAGE);
                    currentPage.getPageHeader().setNextPage(Page.NO_PAGE);
                } else {
                    // Just in the limit of a page
                    if (fullbuf != null) {
                        basebuf = chunkSize;
                        currbuf = fullbuf;
                    }
                    final Value value = new Value(currbuf, 0, basebuf);
                    currentPage.getPageHeader().setNextPage(Page.NO_PAGE);
                    if (isTransactional && transaction != null) {
                        final long nextPageNum = Page.NO_PAGE;
                        final Loggable loggable = new WriteOverflowPageLoggable(
                            transaction, currentPage.getPageNum(), nextPageNum , value);
                        writeToLog(loggable, currentPage);
                    }
                    writeValue(currentPage, value);
                    pageCount++;
View Full Code Here

                    } else {
                        nextPage = null;
                        currentPage.getPageHeader().setNextPage(Page.NO_PAGE);
                    }
                    if (isTransactional && transaction != null) {
                        final Loggable loggable = new WriteOverflowPageLoggable(
                            transaction, currentPage.getPageNum(),
                            remaining > 0 ? nextPage.getPageNum() : Page.NO_PAGE, value);
                        writeToLog(loggable, currentPage);
                    }
                    writeValue(currentPage, value);
View Full Code Here

            while (page != null) {
                LOG.debug("Removing overflow page " + page.getPageNum());
                final long nextPageNumber = page.getPageHeader().getNextPage();
                if (isTransactional && transaction != null) {
                    final byte[] chunk = page.read();
                    final Loggable loggable = new RemoveOverflowLoggable(transaction,
                        page.getPageNum(), nextPageNumber, chunk);
                    writeToLog(loggable, page);
                }
                unlinkPages(page);
                page = (nextPageNumber == Page.NO_PAGE) ? null : getPage(nextPageNumber);
View Full Code Here

            LOG.error("wrong pointer (tid: " + tid + ", " + page.getPageInfo() + ")");
            return;
        }
        final int l = ByteConversion.byteToInt(data, offset);
        if (isTransactional && transaction != null) {
            final Loggable loggable = new RemoveValueLoggable(transaction, fileId, page.getPageNum(), tid, data, offset + 4, l);
            writeToLog(loggable, page);
        }
        final BFilePageHeader ph = page.getPageHeader();
        final int end = offset + 4 + l;
        int len = ph.getDataLength();
        // remove old value
        System.arraycopy(data, end, data, offset - 2, len - end);
        ph.setDirty(true);
        ph.decRecordCount();
        len = len - l - 6;
        ph.setDataLength(len);
        page.setDirty(true);
        // if this page is empty, remove it
        if (len == 0) {
            if (isTransactional && transaction != null) {
                final Loggable loggable = new RemoveEmptyPageLoggable(transaction, fileId, page.getPageNum());
                writeToLog(loggable, page);
            }
            fileHeader.removeFreeSpace(fileHeader.getFreeSpace(page.getPageNum()));
            dataCache.remove(page);
            page.delete();
View Full Code Here

        while (tid < 0) {
            free = fileHeader.findFreeSpace(vlen + 6);
            if (free == null) {
                page = createDataPage();
                if (isTransactional && transaction != null) {
                    final Loggable loggable = new CreatePageLoggable(transaction, fileId, page.getPageNum());
                    writeToLog(loggable, page);
                }
                page.setData(new byte[fileHeader.getWorkSize()]);
                free = new FreeSpace(page.getPageNum(),
                        fileHeader.getWorkSize() - page.getPageHeader().getDataLength());
                fileHeader.addFreeSpace(free);
            } else {
                page = getDataPage(free.getPage());
                // check if this is really a data page
                if (page.getPageHeader().getStatus() != BFile.RECORD) {
                    LOG.warn("page " + page.getPageNum()
                            + " is not a data page; removing it");
                    fileHeader.removeFreeSpace(free);
                    continue;
                }
                // check if the information about free space is really correct
                realSpace = fileHeader.getWorkSize() - page.getPageHeader().getDataLength();
                if (realSpace < 6 + vlen) {
                    // not correct: adjust and continue
                    LOG.warn("Wrong data length in list of free pages: adjusting to " + realSpace);
                    free.setFree(realSpace);
                    continue;
                }
            }
            tid = page.getNextTID();
            if (tid < 0) {
                LOG.info("removing page " + page.getPageNum() + " from free pages");
                fileHeader.removeFreeSpace(free);
            }
        }
        if (isTransactional && transaction != null) {
            final Loggable loggable = new StoreValueLoggable(transaction, fileId, page.getPageNum(), tid, value);
            writeToLog(loggable, page);
        }
        int len = page.getPageHeader().getDataLength();
        final byte[] data = page.getData();
        // save tid
View Full Code Here

TOP

Related Classes of org.exist.storage.journal.Loggable

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.