Search in sources :

Example 1 with PageReference

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

the class BerkeleyReader method readUberPageReference.

@Override
public PageReference readUberPageReference() throws SirixIOException {
    final DatabaseEntry valueEntry = new DatabaseEntry();
    final DatabaseEntry keyEntry = new DatabaseEntry();
    TupleBinding.getPrimitiveBinding(Long.class).objectToEntry(-1l, keyEntry);
    try {
        final OperationStatus status = mDatabase.get(mTxn, keyEntry, valueEntry, LockMode.DEFAULT);
        PageReference uberPageReference = new PageReference();
        if (status == OperationStatus.SUCCESS) {
            uberPageReference.setKey(TupleBinding.getPrimitiveBinding(Long.class).entryToObject(valueEntry));
        }
        final UberPage page = (UberPage) read(uberPageReference, null);
        if (uberPageReference != null) {
            uberPageReference.setPage(page);
        }
        return uberPageReference;
    } catch (final DatabaseException e) {
        throw new SirixIOException(e);
    }
}
Also used : PageReference(org.sirix.page.PageReference) UberPage(org.sirix.page.UberPage) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) SirixIOException(org.sirix.exception.SirixIOException)

Example 2 with PageReference

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

the class FileReader method readUberPageReference.

@Override
public PageReference readUberPageReference() throws SirixIOException {
    final PageReference uberPageReference = new PageReference();
    try {
        // Read primary beacon.
        mFile.seek(0);
        uberPageReference.setKey(mFile.readLong());
        final UberPage page = (UberPage) read(uberPageReference, null);
        uberPageReference.setPage(page);
        return uberPageReference;
    } catch (final IOException e) {
        throw new SirixIOException(e);
    }
}
Also used : PageReference(org.sirix.page.PageReference) UberPage(org.sirix.page.UberPage) IOException(java.io.IOException) SirixIOException(org.sirix.exception.SirixIOException) SirixIOException(org.sirix.exception.SirixIOException)

Example 3 with PageReference

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

the class IOTestHelper method testReadWriteFirstRef.

/**
 * Test reading/writing the first reference.
 *
 * @param resourceConf {@link ResourceConfiguration} reference
 * @throws SirixException if something went wrong
 */
public static void testReadWriteFirstRef(final ResourceConfiguration resourceConf) throws SirixException {
    final Storage fac = StorageType.getStorage(resourceConf);
    final PageReference pageRef1 = new PageReference();
    final UberPage page1 = new UberPage();
    pageRef1.setPage(page1);
    // same instance check
    final Writer writer = fac.createWriter();
    writer.writeUberPageReference(pageRef1);
    final PageReference pageRef2 = writer.readUberPageReference();
    assertEquals(((UberPage) pageRef1.getPage()).getRevisionCount(), ((UberPage) pageRef2.getPage()).getRevisionCount());
    writer.close();
    // new instance check
    final Reader reader = fac.createReader();
    final PageReference pageRef3 = reader.readUberPageReference();
    assertEquals(((UberPage) pageRef1.getPage()).getRevisionCount(), ((UberPage) pageRef3.getPage()).getRevisionCount());
    reader.close();
    fac.close();
}
Also used : PageReference(org.sirix.page.PageReference) UberPage(org.sirix.page.UberPage)

Example 4 with PageReference

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

the class StorageTest method testFirstRef.

/**
 * Test method for {@link org.ByteHandler.io.bytepipe.IByteHandler#deserialize(byte[])} and for
 * {@link org.ByteHandler.io.bytepipe.IByteHandler#serialize(byte[])}.
 *
 * @throws SirixIOException
 */
@Test(dataProvider = "instantiateStorages")
public void testFirstRef(final Class<Storage> clazz, final Storage[] storages) throws SirixException {
    for (final Storage handler : storages) {
        try {
            final PageReference pageRef1 = new PageReference();
            final UberPage page1 = new UberPage();
            pageRef1.setPage(page1);
            // same instance check
            final PageReference pageRef2;
            try (final Writer writer = handler.createWriter()) {
                pageRef2 = writer.writeUberPageReference(pageRef1).readUberPageReference();
                assertEquals(new StringBuilder("Check for ").append(handler.getClass()).append(" failed.").toString(), ((UberPage) pageRef1.getPage()).getRevisionCount(), ((UberPage) pageRef2.getPage()).getRevisionCount());
            }
            // new instance check
            try (final Reader reader = handler.createReader()) {
                final PageReference pageRef3 = reader.readUberPageReference();
                assertEquals(new StringBuilder("Check for ").append(handler.getClass()).append(" failed.").toString(), pageRef2.getKey(), pageRef3.getKey());
                assertEquals(new StringBuilder("Check for ").append(handler.getClass()).append(" failed.").toString(), ((UberPage) pageRef2.getPage()).getRevisionCount(), ((UberPage) pageRef3.getPage()).getRevisionCount());
            }
        } finally {
            handler.close();
        }
    }
}
Also used : PageReference(org.sirix.page.PageReference) FileStorage(org.sirix.io.file.FileStorage) RAMStorage(org.sirix.io.ram.RAMStorage) UberPage(org.sirix.page.UberPage) Test(org.testng.annotations.Test)

Example 5 with PageReference

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

the class PageReadTrxImpl method getPageReferenceForPage.

/**
 * Find reference pointing to leaf page of an indirect tree.
 *
 * @param startReference start reference pointing to the indirect tree
 * @param recordPageKey key to look up in the indirect tree
 * @return reference denoted by key pointing to the leaf page
 *
 * @throws SirixIOException if an I/O error occurs
 */
@Nullable
@Override
public final PageReference getPageReferenceForPage(final PageReference startReference, @Nonnegative final long recordPageKey, final int index, final PageKind pageKind) throws SirixIOException {
    assertNotClosed();
    // Initial state pointing to the indirect page of level 0.
    PageReference reference = checkNotNull(startReference);
    checkArgument(recordPageKey >= 0, "key must be >= 0!");
    checkNotNull(pageKind);
    int offset = 0;
    long levelKey = recordPageKey;
    final int[] inpLevelPageCountExp = mUberPage.getPageCountExp(pageKind);
    // Iterate through all levels.
    for (int level = 0, height = inpLevelPageCountExp.length; level < height; level++) {
        final Page derefPage = dereferenceIndirectPageReference(reference);
        if (derefPage == null) {
            reference = null;
            break;
        } else {
            offset = (int) (levelKey >> inpLevelPageCountExp[level]);
            levelKey -= offset << inpLevelPageCountExp[level];
            try {
                // assert offset >= 0 && offset < mUberPage.getPageReferenceCount(pageKind);
                reference = derefPage.getReference(offset);
            } catch (final IndexOutOfBoundsException e) {
                throw new SirixIOException("Node key isn't supported, it's too big!");
            }
        }
    }
    // Return reference to leaf of indirect tree.
    return reference;
}
Also used : PageReference(org.sirix.page.PageReference) KeyValuePage(org.sirix.page.interfaces.KeyValuePage) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) CASPage(org.sirix.page.CASPage) Page(org.sirix.page.interfaces.Page) RevisionRootPage(org.sirix.page.RevisionRootPage) NamePage(org.sirix.page.NamePage) PathSummaryPage(org.sirix.page.PathSummaryPage) UberPage(org.sirix.page.UberPage) PathPage(org.sirix.page.PathPage) IndirectPage(org.sirix.page.IndirectPage) SirixIOException(org.sirix.exception.SirixIOException) Nullable(javax.annotation.Nullable)

Aggregations

PageReference (org.sirix.page.PageReference)15 UberPage (org.sirix.page.UberPage)8 SirixIOException (org.sirix.exception.SirixIOException)5 PageContainer (org.sirix.cache.PageContainer)4 RevisionRootPage (org.sirix.page.RevisionRootPage)4 IndirectPage (org.sirix.page.IndirectPage)3 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)3 IOException (java.io.IOException)2 CASPage (org.sirix.page.CASPage)2 NamePage (org.sirix.page.NamePage)2 PathPage (org.sirix.page.PathPage)2 PathSummaryPage (org.sirix.page.PathSummaryPage)2 KeyValuePage (org.sirix.page.interfaces.KeyValuePage)2 Page (org.sirix.page.interfaces.Page)2 MoreObjects (com.google.common.base.MoreObjects)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 DatabaseException (com.sleepycat.je.DatabaseException)1 OperationStatus (com.sleepycat.je.OperationStatus)1 FileOutputStream (java.io.FileOutputStream)1