Search in sources :

Example 1 with Record

use of org.sirix.node.interfaces.Record in project sirix by sirixdb.

the class PageTest method instantiatePages.

/**
 * Providing different implementations of the {@link Page} as Dataprovider to the test class.
 *
 * @return different classes of the {@link ByteHandler}
 * @throws SirixIOException if an I/O error occurs
 */
@DataProvider(name = "instantiatePages")
public Object[][] instantiatePages() throws SirixIOException {
    // IndirectPage setup.
    final IndirectPage indirectPage = new IndirectPage();
    // RevisionRootPage setup.
    // final RevisionRootPage revRootPage = new RevisionRootPage();
    // NodePage setup.
    final UnorderedKeyValuePage nodePage = new UnorderedKeyValuePage(TestHelper.random.nextInt(Integer.MAX_VALUE), PageKind.RECORDPAGE, Constants.NULL_ID_LONG, mPageReadTrx);
    for (int i = 0; i < Constants.NDP_NODE_COUNT - 1; i++) {
        final Record record = TestHelper.generateOne();
        nodePage.setEntry(record.getNodeKey(), record);
    }
    // NamePage setup.
    final NamePage namePage = new NamePage();
    namePage.setName(TestHelper.random.nextInt(), new String(TestHelper.generateRandomBytes(256)), Kind.ELEMENT);
    // ValuePage setup.
    final PathPage valuePage = new PathPage();
    // PathSummaryPage setup.
    final PathSummaryPage pathSummaryPage = new PathSummaryPage();
    Object[][] returnVal = { { Page.class, new Page[] { indirectPage, namePage, valuePage, pathSummaryPage } } };
    return returnVal;
}
Also used : Record(org.sirix.node.interfaces.Record) Page(org.sirix.page.interfaces.Page) DataProvider(org.testng.annotations.DataProvider)

Example 2 with Record

use of org.sirix.node.interfaces.Record 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 3 with Record

use of org.sirix.node.interfaces.Record in project sirix by sirixdb.

the class PageWriteTrxImpl method getRecord.

@Override
public Optional<Record> getRecord(@Nonnegative final long recordKey, final PageKind pageKind, @Nonnegative final int index) throws SirixIOException {
    mPageRtx.assertNotClosed();
    checkArgument(recordKey >= Fixed.NULL_NODE_KEY.getStandardProperty());
    checkNotNull(pageKind);
    // Calculate page.
    final long recordPageKey = mPageRtx.pageKey(recordKey);
    final PageContainer pageCont = prepareRecordPage(recordPageKey, index, pageKind);
    if (pageCont.equals(PageContainer.emptyInstance())) {
        return mPageRtx.getRecord(recordKey, pageKind, index);
    } else {
        Record node = ((UnorderedKeyValuePage) pageCont.getModified()).getValue(recordKey);
        if (node == null) {
            node = ((UnorderedKeyValuePage) pageCont.getComplete()).getValue(recordKey);
        }
        return mPageRtx.checkItemIfDeleted(node);
    }
}
Also used : PageContainer(org.sirix.cache.PageContainer) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage)

Example 4 with Record

use of org.sirix.node.interfaces.Record in project sirix by sirixdb.

the class XdmResourceManager method beginPageWriteTrx.

@Override
public synchronized PageWriteTrx<Long, Record, UnorderedKeyValuePage> beginPageWriteTrx(@Nonnegative final int revision) throws SirixException {
    assertAccess(revision);
    // Make sure not to exceed available number of write transactions.
    try {
        if (!mWriteSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
            throw new SirixUsageException("No write transaction available, please close the write transaction first.");
        }
    } catch (final InterruptedException e) {
        throw new SirixThreadedException(e);
    }
    final long currentPageTrxID = mPageTrxIDCounter.incrementAndGet();
    final int lastRev = mLastCommittedUberPage.get().getRevisionNumber();
    final PageWriteTrx<Long, Record, UnorderedKeyValuePage> pageWtx = createPageWriteTransaction(currentPageTrxID, lastRev, lastRev, Abort.NO);
    // Remember page transaction for debugging and safe close.
    if (mPageTrxMap.put(currentPageTrxID, pageWtx) != null) {
        throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
    }
    return pageWtx;
}
Also used : SirixThreadedException(org.sirix.exception.SirixThreadedException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixUsageException(org.sirix.exception.SirixUsageException)

Example 5 with Record

use of org.sirix.node.interfaces.Record in project sirix by sirixdb.

the class UnorderedKeyValuePage method addReferences.

// Add references to OverflowPages.
private void addReferences() throws IOException {
    final boolean storeDeweyIDs = mPageReadTrx.getResourceManager().getResourceConfig().mDeweyIDsStored;
    final List<Entry<Long, Record>> entries = sort();
    final Iterator<Entry<Long, Record>> it = entries.iterator();
    while (it.hasNext()) {
        final Entry<Long, Record> entry = it.next();
        final Record record = entry.getValue();
        final long recordID = record.getNodeKey();
        if (mSlots.get(recordID) == null) {
            // Must be either a normal record or one which requires an
            // Overflow page.
            final ByteArrayOutputStream output = new ByteArrayOutputStream();
            final DataOutput out = new DataOutputStream(output);
            mPersistenter.serialize(out, record, mPageReadTrx);
            final byte[] data = output.toByteArray();
            if (data.length > PageConstants.MAX_RECORD_SIZE) {
                final PageReference reference = new PageReference();
                reference.setPage(new OverflowPage(data));
                mReferences.put(recordID, reference);
            } else {
                if (storeDeweyIDs && mPersistenter instanceof NodePersistenter && record instanceof Node && ((Node) record).getDeweyID().isPresent() && record.getNodeKey() != 0)
                    mDeweyIDs.put(((Node) record).getDeweyID().get(), record.getNodeKey());
                mSlots.put(recordID, data);
            }
        }
    }
    mAddedReferences = true;
}
Also used : DataOutput(java.io.DataOutput) DataOutputStream(java.io.DataOutputStream) Node(org.sirix.node.interfaces.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NodePersistenter(org.sirix.node.interfaces.NodePersistenter) Entry(java.util.Map.Entry) Utils.getVarLong(org.sirix.node.Utils.getVarLong) Utils.putVarLong(org.sirix.node.Utils.putVarLong) Record(org.sirix.node.interfaces.Record)

Aggregations

Record (org.sirix.node.interfaces.Record)11 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)8 PageContainer (org.sirix.cache.PageContainer)5 SirixIOException (org.sirix.exception.SirixIOException)3 Node (org.sirix.node.interfaces.Node)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 SirixThreadedException (org.sirix.exception.SirixThreadedException)2 SirixUsageException (org.sirix.exception.SirixUsageException)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutput (java.io.DataOutput)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Entry (java.util.Map.Entry)1 ExecutionException (java.util.concurrent.ExecutionException)1 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)1 IndexLogKey (org.sirix.cache.IndexLogKey)1