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;
}
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();
}
}
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);
}
}
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;
}
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;
}
Aggregations