Package org.exist.storage.journal

Examples of org.exist.storage.journal.Loggable


        SinglePage firstPage;

        public OverflowPage(Txn transaction) throws IOException {
            firstPage = new SinglePage(false);
            if (isTransactional && transaction != null) {
                final Loggable loggable = new OverflowCreateLoggable(fileId, transaction, firstPage.getPageNum());
                writeToLog(loggable, firstPage);
            }
            final BFilePageHeader ph = firstPage.getPageHeader();
            ph.setStatus(MULTI_PAGE);
            ph.setNextInChain(0L);
View Full Code Here


            int chunkSize = fileHeader.getWorkSize() - ph.getDataLength();
            final int chunkLen = chunk.size();
            if (chunkLen < chunkSize) {chunkSize = chunkLen;}
            // fill last page
            if (isTransactional && transaction != null) {
                final Loggable loggable =
                    new OverflowAppendLoggable(fileId, transaction, page.getPageNum(), chunk, 0, chunkSize);
                writeToLog(loggable, page);
            }
            chunk.copyTo(0, page.getData(), ph.getDataLength(), chunkSize);
            if(page != firstPage)
                {ph.setDataLength(ph.getDataLength() + chunkSize);}
            page.setDirty(true);
            // write the remaining chunks to new pages
            int remaining = chunkLen - chunkSize;
            int current = chunkSize;
            chunkSize = fileHeader.getWorkSize();
            if (remaining > 0) {
                // walk through chain of pages
                while (remaining > 0) {
                    if (remaining < chunkSize) {chunkSize = remaining;}
                   
                    // add a new page to the chain
                    nextPage = createDataPage();
                    if (isTransactional && transaction != null) {
                        Loggable loggable = new OverflowCreatePageLoggable(transaction, fileId, nextPage.getPageNum(),
                                page.getPageNum());
                        writeToLog(loggable, nextPage);
                       
                        loggable = new OverflowAppendLoggable(fileId, transaction, nextPage.getPageNum(),
                                chunk, current, chunkSize);
                        writeToLog(loggable, page);
                    }
                    nextPage.setData(new byte[fileHeader.getWorkSize()]);
                    page.getPageHeader().setNextInChain(nextPage.getPageNum());
                    page.setDirty(true);
                    dataCache.add(page);
                    page = nextPage;
                    // copy next chunk of data to the page
                    chunk.copyTo(current, page.getData(), 0, chunkSize);
                    page.setDirty(true);
                    if (page != firstPage)
                            {page.getPageHeader().setDataLength(chunkSize);}
                    remaining = remaining - chunkSize;
                    current += chunkSize;
                }
            }
            ph = firstPage.getPageHeader();
            if (isTransactional && transaction != null) {
                final Loggable loggable = new OverflowModifiedLoggable(fileId, transaction, firstPage.getPageNum(),
                        ph.getDataLength() + chunkLen, ph.getDataLength(), page == firstPage ? 0 : page.getPageNum());
                writeToLog(loggable, page);
            }
            if (page != firstPage) {
                // add link to last page
View Full Code Here

                next = page.ph.getNextInChain();
                if (isTransactional && transaction != null) {
                    int dataLen = page.ph.getDataLength();
                    if (dataLen > fileHeader.getWorkSize())
                        {dataLen = fileHeader.getWorkSize();}
                    final Loggable loggable = new OverflowRemoveLoggable(fileId, transaction,
                            page.ph.getStatus(), page.getPageNum(),
                            page.getData(), dataLen,
                            page.ph.getNextInChain());
                    writeToLog(loggable, page);
                }
View Full Code Here

            while (remaining > 0) {
                if (remaining < chunkSize) {chunkSize = remaining;}
                page.clear();
                // copy next chunk of data to the page
                if (isTransactional && transaction != null) {
                    final Loggable loggable = new OverflowStoreLoggable(fileId, transaction, page.getPageNum(), prevPageNum,
                            data, current, chunkSize);
                    writeToLog(loggable, page);
                }
                System.arraycopy(data, current, page.getData(), 0, chunkSize);
                if (page != firstPage)
                    {page.getPageHeader().setDataLength(chunkSize);}
                page.setDirty(true);
                remaining -= chunkSize;
                current += chunkSize;
                next = page.getPageHeader().getNextInChain();
                if (remaining > 0) {
                    if (next > 0) {
                        // load next page in chain
                        nextPage = (SinglePage) getDataPage(next, false);
                        dataCache.add(page);
                        prevPageNum = page.getPageNum();
                        page = nextPage;
                    } else {
                        // add a new page to the chain
                        nextPage = createDataPage();
                        if (isTransactional && transaction != null) {
                            final Loggable loggable = new CreatePageLoggable(transaction, fileId, nextPage.getPageNum());
                            writeToLog(loggable, nextPage);
                        }
                        nextPage.setData(new byte[fileHeader.getWorkSize()]);
                        nextPage.getPageHeader().setNextInChain(0L);
                        page.getPageHeader().setNextInChain(
                                nextPage.getPageNum());
                        dataCache.add(page);
                        prevPageNum = page.getPageNum();
                        page = nextPage;
                    }
                } else {
                    page.getPageHeader().setNextInChain(0L);
                    if (page != firstPage) {
                        page.setDirty(true);
                        dataCache.add(page);
                        firstPage.getPageHeader().setLastInChain(
                                page.getPageNum());
                    } else
                        {firstPage.getPageHeader().setLastInChain(0L);}
                    firstPage.setDirty(true);
                    dataCache.add(firstPage, 3);
                }
            }
            if (next > 0) {
                // there are more pages in the chain:
                // remove them
                while (next > 0) {
                    nextPage = (SinglePage) getDataPage(next, false);
                   
                    next = nextPage.getPageHeader().getNextInChain();
                   
                    if (isTransactional && transaction != null) {
                        final Loggable loggable = new OverflowRemoveLoggable(fileId, transaction,
                                nextPage.getPageHeader().getStatus(), nextPage.getPageNum(),
                                nextPage.getData(), nextPage.getPageHeader().getDataLength(),
                                nextPage.getPageHeader().getNextInChain());
                        writeToLog(loggable, nextPage);
                    }
View Full Code Here

        if(sourceDir.exists()) {
            if(targetDir.exists()) {
                final File targetDelDir = getCollectionFile(fsBackupDir, transaction, destination.getURI().append(newName), true);
                targetDelDir.getParentFile().mkdirs();
                if(targetDir.renameTo(targetDelDir)) {
                    final Loggable loggable = new RenameBinaryLoggable(this, transaction, targetDir, targetDelDir);
                    try {
                        logManager.writeToLog(loggable);
                    } catch(final TransactionException e) {
                        LOG.warn(e.getMessage(), e);
                    }
                } else {
                    LOG.fatal("Cannot rename " + targetDir + " to " + targetDelDir);
                }
            }
            targetDir.getParentFile().mkdirs();
            if(sourceDir.renameTo(targetDir)) {
                final Loggable loggable = new RenameBinaryLoggable(this, transaction, sourceDir, targetDir);
                try {
                    logManager.writeToLog(loggable);
                } catch(final TransactionException e) {
                    LOG.warn(e.getMessage(), e);
                }
View Full Code Here

                    //XXX: log first, rename second ??? -shabanovd
                    // DW: not sure a Fatal is required here. Copy and delete
                    // maybe?
                    if(fsSourceDir.renameTo(fsTargetDir)) {
                        final Loggable loggable = new RenameBinaryLoggable(this, transaction, fsSourceDir, fsTargetDir);
                        try {
                            logManager.writeToLog(loggable);
                        } catch(final TransactionException e) {
                            LOG.warn(e.getMessage(), e);
                        }
View Full Code Here

        }
        final OutputStream os = new FileOutputStream(binFile);
        os.write(data, 0, data.length);
        os.close();

        final Loggable loggable;
        if(exists) {
            loggable = new UpdateBinaryLoggable(this, transaction, binFile, backupFile);
        } else {
            loggable = new CreateBinaryLoggable(this, transaction, binFile);
        }
View Full Code Here

                os.write(buffer, 0, len);
            }
        }
        os.close();

        final Loggable loggable;
        if(exists) {
            loggable = new UpdateBinaryLoggable(this, transaction, binFile, backupFile);
        } else {
            loggable = new CreateBinaryLoggable(this, transaction, binFile);
        }
View Full Code Here

                final File sourceFile = getCollectionFile(fsDir, doc.getURI(), false);
                /* Create required directories */
                binFile.getParentFile().mkdirs();
                /* Rename original file to new location */
                if(fsOriginalDocument.renameTo(binFile)) {
                    final Loggable loggable = new RenameBinaryLoggable(this, transaction, sourceFile, binFile);
                    try {
                        logManager.writeToLog(loggable);
                    } catch(final TransactionException e) {
                        LOG.warn(e.getMessage(), e);
                    }
View Full Code Here

        }

        final File binFile = getCollectionFile(fsDir, blob.getURI(), false);
        if(binFile.exists()) {
            final File binBackupFile = getCollectionFile(fsBackupDir, transaction, blob.getURI(), true);
            final Loggable loggable = new RenameBinaryLoggable(this, transaction, binFile, binBackupFile);
            if(!binFile.renameTo(binBackupFile)) {
                // Workaround for Java bug 6213298 - renameTo() sometimes doesn't work
                // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213298
                System.gc(); //TODO remove this, must be a better approach in Java 7?
                try {
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.