Search in sources :

Example 6 with UberPage

use of org.sirix.page.UberPage in project sirix by sirixdb.

the class XdmNodeWriterTrxImpl method rollback.

@Override
public XdmNodeWriteTrx rollback() {
    acquireLock();
    try {
        mNodeReader.assertNotClosed();
        // Reset modification counter.
        mModificationCount = 0L;
        // Close current page transaction.
        final long trxID = getId();
        final int revision = getRevisionNumber();
        final int revNumber = getPageTransaction().getUberPage().isBootstrap() ? 0 : revision - 1;
        final UberPage uberPage = getPageTransaction().rollback();
        // Remember succesfully committed uber page in resource manager.
        mNodeReader.mResourceManager.setLastCommittedUberPage(uberPage);
        mNodeReader.getPageTransaction().clearCaches();
        mNodeReader.getPageTransaction().closeCaches();
        mNodeReader.mResourceManager.closeNodePageWriteTransaction(getId());
        mNodeReader.setPageReadTransaction(null);
        removeCommitFile();
        final PageWriteTrx<Long, Record, UnorderedKeyValuePage> trx = mNodeReader.mResourceManager.createPageWriteTransaction(trxID, revNumber, revNumber, Abort.YES);
        mNodeReader.setPageReadTransaction(trx);
        mNodeReader.mResourceManager.setNodePageWriteTransaction(getId(), trx);
        mNodeFactory = null;
        mNodeFactory = new NodeFactoryImpl(trx);
        reInstantiateIndexes();
        return this;
    } finally {
        unLock();
    }
}
Also used : UberPage(org.sirix.page.UberPage) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage)

Example 7 with UberPage

use of org.sirix.page.UberPage in project sirix by sirixdb.

the class PageWriteTrxImpl method rollback.

@Override
public UberPage rollback() {
    mPageRtx.assertNotClosed();
    mLog.clear();
    mLog.close();
    mLog = createTrxIntentLog(mPageRtx.mResourceManager);
    final UberPage lastUberPage = (UberPage) mPageWriter.read(mPageWriter.readUberPageReference(), mPageRtx);
    return lastUberPage;
}
Also used : UberPage(org.sirix.page.UberPage)

Example 8 with UberPage

use of org.sirix.page.UberPage in project sirix by sirixdb.

the class PageWriteTrxImpl method commit.

@Override
public UberPage commit() {
    mPageRtx.assertNotClosed();
    mPageRtx.mResourceManager.getCommitLock().lock();
    final Path commitFile = mPageRtx.mResourceManager.commitFile();
    commitFile.toFile().deleteOnExit();
    // Issues with windows that it's not created in the first time?
    while (!Files.exists(commitFile)) {
        try {
            Files.createFile(commitFile);
        } catch (final IOException e) {
            throw new SirixIOException(e);
        }
    }
    // Forcefully flush write-ahead transaction logs to persistent storage.
    if (mPageRtx.mResourceManager.getResourceManagerConfig().dumpLogs()) {
        mLog.toSecondCache();
    }
    final PageReference uberPageReference = new PageReference();
    final UberPage uberPage = getUberPage();
    uberPageReference.setPage(uberPage);
    final int revision = uberPage.getRevisionNumber();
    // Recursively write indirectly referenced pages.
    uberPage.commit(this);
    uberPageReference.setPage(uberPage);
    mPageWriter.writeUberPageReference(uberPageReference);
    uberPageReference.setPage(null);
    final Path indexes = mPageRtx.mResourceConfig.mPath.resolve(ResourceConfiguration.ResourcePaths.INDEXES.getFile() + String.valueOf(revision) + ".xml");
    if (!Files.exists(indexes)) {
        try {
            Files.createFile(indexes);
        } catch (final IOException e) {
            throw new SirixIOException(e);
        }
    }
    try (final OutputStream out = new FileOutputStream(indexes.toFile())) {
        mIndexController.serialize(out);
    } catch (final IOException e) {
        throw new SirixIOException("Index definitions couldn't be serialized!", e);
    }
    mLog.clear();
    mLog.close();
    mLog = createTrxIntentLog(mPageRtx.mResourceManager);
    try {
        Files.delete(commitFile);
    } catch (final IOException e) {
        throw new SirixIOException("Commit file couldn't be deleted!");
    }
    final UberPage commitedUberPage = (UberPage) mPageWriter.read(mPageWriter.readUberPageReference(), mPageRtx);
    mPageRtx.mResourceManager.getCommitLock().unlock();
    return commitedUberPage;
}
Also used : Path(java.nio.file.Path) PageReference(org.sirix.page.PageReference) UberPage(org.sirix.page.UberPage) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) SirixIOException(org.sirix.exception.SirixIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) SirixIOException(org.sirix.exception.SirixIOException)

Example 9 with UberPage

use of org.sirix.page.UberPage in project sirix by sirixdb.

the class PageWriteTrxImpl method close.

@Override
public void close() {
    if (!mIsClosed) {
        mPageRtx.assertNotClosed();
        final UberPage lastUberPage = (UberPage) mPageWriter.read(mPageWriter.readUberPageReference(), mPageRtx);
        mPageRtx.mResourceManager.setLastCommittedUberPage(lastUberPage);
        mPageRtx.clearCaches();
        mPageRtx.closeCaches();
        closeCaches();
        mPageWriter.close();
        mIsClosed = true;
        final long trxId = mPageRtx.getTrxId();
        if (!mPageRtx.mResourceManager.getXdmNodeReadTrx(trxId).isPresent())
            mPageRtx.mResourceManager.closeWriteTransaction(trxId);
    }
}
Also used : UberPage(org.sirix.page.UberPage)

Example 10 with UberPage

use of org.sirix.page.UberPage in project sirix by sirixdb.

the class ResourceStore method openResource.

/**
 * Open a resource, that is get an instance of a {@link ResourceManager} in order to read/write
 * from the resource.
 *
 * @param database The database.
 * @param resourceConfig The resource configuration.
 * @param resourceManagerConfig The resource manager configuration.
 * @param bufferManager The buffer manager.
 * @param resourceFile The resource to open.
 * @return A resource manager.
 */
public ResourceManager openResource(@Nonnull final DatabaseImpl database, @Nonnull final ResourceConfiguration resourceConfig, @Nonnull final ResourceManagerConfiguration resourceManagerConfig, @Nonnull final BufferManager bufferManager, @Nonnull final Path resourceFile) {
    checkNotNull(database);
    checkNotNull(resourceConfig);
    return mResourceManagers.computeIfAbsent(resourceFile, k -> {
        final Storage storage = StorageType.getStorage(resourceConfig);
        final UberPage uberPage;
        if (storage.exists()) {
            try (final Reader reader = storage.createReader()) {
                final PageReference firstRef = reader.readUberPageReference();
                if (firstRef.getPage() == null) {
                    uberPage = (UberPage) reader.read(firstRef, null);
                } else {
                    uberPage = (UberPage) firstRef.getPage();
                }
            }
        } else {
            // Bootstrap uber page and make sure there already is a root node.
            uberPage = new UberPage();
        }
        final ResourceManager resourceManager = new XdmResourceManager(database, this, resourceConfig, resourceManagerConfig, bufferManager, StorageType.getStorage(resourceConfig), uberPage, mReadSemaphore, mWriteSempahore);
        Databases.putResourceManager(resourceFile, resourceManager);
        return resourceManager;
    });
}
Also used : PageReference(org.sirix.page.PageReference) Storage(org.sirix.io.Storage) UberPage(org.sirix.page.UberPage) Reader(org.sirix.io.Reader) ResourceManager(org.sirix.api.ResourceManager)

Aggregations

UberPage (org.sirix.page.UberPage)11 PageReference (org.sirix.page.PageReference)6 SirixIOException (org.sirix.exception.SirixIOException)3 IOException (java.io.IOException)2 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 DatabaseException (com.sleepycat.je.DatabaseException)1 OperationStatus (com.sleepycat.je.OperationStatus)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1 PostCommitHook (org.sirix.api.PostCommitHook)1 PreCommitHook (org.sirix.api.PreCommitHook)1 ResourceManager (org.sirix.api.ResourceManager)1 Reader (org.sirix.io.Reader)1 Storage (org.sirix.io.Storage)1 Writer (org.sirix.io.Writer)1 FileStorage (org.sirix.io.file.FileStorage)1 RAMStorage (org.sirix.io.ram.RAMStorage)1 Record (org.sirix.node.interfaces.Record)1