Permalink
Browse files

[MOD] Adapted for upcoming non-blocking commits and restore in case of

a failure during commit.
  • Loading branch information...
1 parent 6f1fedb commit 28af7e786e256ab92ebbafc0c6b63c11d8cde1d5 @JohannesLichtenberger JohannesLichtenberger committed Nov 17, 2013
View
37 bundles/sirix-core/src/main/java/org/sirix/access/PageReadTrxImpl.java
@@ -385,10 +385,10 @@
public Page load(final PageReference reference) throws SirixException {
assert reference.getLogKey() != null
|| reference.getKey() != Constants.NULL_ID;
- final Page page = mPageLog.isPresent() ? mPageLog.get().get(
+ Page page = mPageLog.isPresent() ? mPageLog.get().get(
reference.getLogKey()) : null;
if (page == null) {
- return mPageReader.read(reference.getKey(), impl).setDirty(true);
+ page = mPageReader.read(reference.getKey(), impl).setDirty(true);
}
return page;
}
@@ -574,13 +574,17 @@ final RevisionRootPage loadRevRoot(final @Nonnegative int revisionKey)
mUberPage.getIndirectPageReference(), revisionKey, -1,
PageKind.UBERPAGE);
try {
+ RevisionRootPage page = null;
if (mPageWriteTrx.isPresent()) {
- return (RevisionRootPage) mPageWriteTrx.get().mPageLog.get(reference
+ page = (RevisionRootPage) mPageWriteTrx.get().mPageLog.get(reference
.getLogKey());
}
- assert reference.getKey() != Constants.NULL_ID
- || reference.getLogKey() != null;
- return (RevisionRootPage) mPageCache.get(reference);
+ if (page == null) {
+ assert reference.getKey() != Constants.NULL_ID
+ || reference.getLogKey() != null;
+ page = (RevisionRootPage) mPageCache.get(reference);
+ }
+ return page;
} catch (final ExecutionException e) {
throw new SirixIOException(e.getCause());
}
@@ -631,7 +635,8 @@ private Page getPage(final PageReference reference, final PageKind pageKind)
try {
Page page = reference.getPage();
if (mPageWriteTrx.isPresent() || mPageLog.isPresent()) {
- reference.setLogKey(new IndirectPageLogKey(pageKind, -1, -1, 0));
+ final IndirectPageLogKey logKey = new IndirectPageLogKey(pageKind, -1, -1, 0);
+ reference.setLogKey(logKey);
}
if (page == null) {
page = mPageCache.get(reference);
@@ -713,8 +718,8 @@ public final UberPage getUberPage() {
refToRecordPage = pageReference.get();
} else {
assert mRootPage.getRevision() == i;
- final PageReference tmpRef = getPageReference(
- mRootPage, pageKind, index);
+ final PageReference tmpRef = getPageReference(mRootPage, pageKind,
+ index);
refToRecordPage = getPageReferenceForPage(tmpRef, recordPageKey,
index, pageKind);
}
@@ -723,7 +728,7 @@ public final UberPage getUberPage() {
.getPreviousReference();
refToRecordPage = reference.isPresent() ? reference.get() : null;
}
-
+
if (refToRecordPage != null
&& refToRecordPage.getKey() != Constants.NULL_ID) {
// Probably save page.
@@ -796,15 +801,17 @@ PageReference getPageReference(final RevisionRootPage revisionRoot,
final IndirectPage dereferenceIndirectPage(final PageReference reference)
throws SirixIOException {
try {
+ IndirectPage page = null;
+
if (mPageWriteTrx.isPresent()) {
- return (IndirectPage) mPageWriteTrx.get().mPageLog.get(reference
+ page = (IndirectPage) mPageWriteTrx.get().mPageLog.get(reference
.getLogKey());
}
- if (reference.getKey() != Constants.NULL_ID
- || reference.getLogKey() != null) {
- return (IndirectPage) mPageCache.get(reference);
+ if (page == null
+ && (reference.getKey() != Constants.NULL_ID || reference.getLogKey() != null)) {
+ page = (IndirectPage) mPageCache.get(reference);
}
- return null;
+ return page;
} catch (final ExecutionException e) {
throw new SirixIOException(e.getCause());
}
View
168 bundles/sirix-core/src/main/java/org/sirix/access/PageWriteTrxImpl.java
@@ -102,7 +102,9 @@
/** Page writer to serialize. */
private final Writer mPageWriter;
- /** Persistent BerkeleyDB page log for all page types != NodePage. */
+ /**
+ * Persistent BerkeleyDB page log for all page types != UnorderedKeyValuePage.
+ */
final Cache<IndirectPageLogKey, Page> mPageLog;
/** Cache to store the changes in this transaction log. */
@@ -156,8 +158,8 @@
* root of revision
* @param writer
* writer where this transaction should write to
- * @param id
- * ID
+ * @param trxId
+ * the transaction ID
* @param representRev
* revision represent
* @param lastStoredRev
@@ -166,7 +168,7 @@
* if an error occurs
*/
PageWriteTrxImpl(final SessionImpl session, final UberPage uberPage,
- final Writer writer, final @Nonnegative long id,
+ final Writer writer, final @Nonnegative long trxId,
final @Nonnegative int representRev,
final @Nonnegative int lastStoredRev,
final @Nonnegative int lastCommitedRev) throws SirixException {
@@ -218,12 +220,13 @@
// Page read trx.
mPageRtx = new PageReadTrxImpl(session, uberPage, representRev, writer,
- uberPage.isBootstrap() ? Optional.of(this) : Optional
- .<PageWriteTrxImpl> absent(),
+ Optional.of(this),
+ // uberPage.isBootstrap() ? Optional.of(this) : Optional
+ // .<PageWriteTrxImpl> absent(),
Optional.of(mIndexController));
mPageWriter = writer;
- mTransactionID = id;
+ mTransactionID = trxId;
final RevisionRootPage lastCommitedRoot = mPageRtx
.loadRevRoot(lastCommitedRev);
@@ -244,6 +247,10 @@
mPageLog.put(new IndirectPageLogKey(PageKind.NAMEPAGE, -1, -1, 0),
mPageRtx.getNamePage(revisionRoot));
+ mPageLog.put(new IndirectPageLogKey(PageKind.CASPAGE, -1, -1, 0),
+ mPageRtx.getCASPage(revisionRoot));
+ mPageLog.put(new IndirectPageLogKey(PageKind.PATHPAGE, -1, -1, 0),
+ mPageRtx.getPathPage(revisionRoot));
}
@Override
@@ -306,7 +313,8 @@ public Record createEntry(final Long key, final Record record,
recordKey = pathPage.incrementAndGetMaxNodeKey(index);
break;
case NAMEPAGE:
- final NamePage namePage = ((NamePage) mNewRoot.getNamePageReference().getPage());
+ final NamePage namePage = ((NamePage) mNewRoot.getNamePageReference()
+ .getPage());
recordKey = namePage.incrementAndGetMaxNodeKey(index);
break;
default:
@@ -511,75 +519,79 @@ public void commit(final @Nullable PageReference reference)
}
if (cont != null) {
- page = cont.getModified();
+ page = cont.getModified();
}
}
// If none is in the log.
- if (page == null) {
- // Test if one is instantiated, if so, get
- // the one from the reference.
- page = reference.getPage();
-
-// if (page == null) {
-// // Then try to get one from the page transaction log (indirect pages
-// // forming a tree below revision root pages).
-// final long key = reference.getKey();
-// if (key != Constants.NULL_ID
-// && (getUberPage().getRevision()
-// % mPageRtx.mSession.mResourceConfig.mRevisionsToRestore == 0)
-// && (mPageRtx.mSession.mResourceConfig.mRevisionKind == Versioning.INCREMENTAL
-// || mPageRtx.mSession.mResourceConfig.mRevisionKind == Versioning.DIFFERENTIAL)) {
-// /*
-// * Write the whole indirect page tree if it's a full dump, otherwise
-// * record pages which have to be emitted might not be addressable (the
-// * pages from earlier versions would still be reachable).
-// */
-// page = mPageRtx.getFromPageCache(reference);
-// page.setDirty(true);
-//
-// if (page instanceof KeyValuePage) {
-// // If it's a record page, reconstruct it first!
-// @SuppressWarnings("unchecked")
-// final KeyValuePage<Long, Record> recordPage = ((KeyValuePage<Long, Record>) page);
-// final PageKind recordPageKind = recordPage.getPageKind();
-// final long pageKey = recordPage.getPageKey();
-// switch (recordPageKind) {
-// case NAMEPAGE:
-// case CASPAGE:
-// case RECORDPAGE:
-// case PATHSUMMARYPAGE:
-// case PATHPAGE:
-// // Revision to commit is a full dump => get the full page and
-// // dump it (if it is dirty -- checked later).
-// page = mPageRtx
-// .<Long, Record, UnorderedKeyValuePage> getRecordPageContainer(
-// pageKey, index, recordPageKind).getComplete();
-// break;
-// default:
-// throw new IllegalStateException("Page kind not known!");
-// }
-//
-// if (page != null && !page.isDirty()) {
-// // Only write dirty pages which have been modified since the
-// // latest full dump (checked in the versioning algorithms
-// // through setting the dirty flag).
-// return;
-// }
-// }
-// }
-// }
- }
+// if (page == null) {
+// // Test if one is instantiated, if so, get
+// // the one from the reference.
+// page = reference.getPage();
+ //
+ // if (page == null) {
+ // // Then try to get one from the page transaction log (indirect pages
+ // // forming a tree below revision root pages).
+ // final long key = reference.getKey();
+ // if (key != Constants.NULL_ID
+ // && (getUberPage().getRevision()
+ // % mPageRtx.mSession.mResourceConfig.mRevisionsToRestore == 0)
+ // && (mPageRtx.mSession.mResourceConfig.mRevisionKind ==
+ // Versioning.INCREMENTAL
+ // || mPageRtx.mSession.mResourceConfig.mRevisionKind ==
+ // Versioning.DIFFERENTIAL)) {
+ // /*
+ // * Write the whole indirect page tree if it's a full dump, otherwise
+ // * record pages which have to be emitted might not be addressable (the
+ // * pages from earlier versions would still be reachable).
+ // */
+ // page = mPageRtx.getFromPageCache(reference);
+ // page.setDirty(true);
+ //
+ // if (page instanceof KeyValuePage) {
+ // // If it's a record page, reconstruct it first!
+ // @SuppressWarnings("unchecked")
+ // final KeyValuePage<Long, Record> recordPage = ((KeyValuePage<Long,
+ // Record>) page);
+ // final PageKind recordPageKind = recordPage.getPageKind();
+ // final long pageKey = recordPage.getPageKey();
+ // switch (recordPageKind) {
+ // case NAMEPAGE:
+ // case CASPAGE:
+ // case RECORDPAGE:
+ // case PATHSUMMARYPAGE:
+ // case PATHPAGE:
+ // // Revision to commit is a full dump => get the full page and
+ // // dump it (if it is dirty -- checked later).
+ // page = mPageRtx
+ // .<Long, Record, UnorderedKeyValuePage> getRecordPageContainer(
+ // pageKey, index, recordPageKind).getComplete();
+ // break;
+ // default:
+ // throw new IllegalStateException("Page kind not known!");
+ // }
+ //
+ // if (page != null && !page.isDirty()) {
+ // // Only write dirty pages which have been modified since the
+ // // latest full dump (checked in the versioning algorithms
+ // // through setting the dirty flag).
+ // return;
+ // }
+ // }
+ // }
+ // }
+ // }
if (page == null) {
return;
}
-// // Revision to commit is not a full dump => return immediately.
-// if (!page.isDirty()
-// && ((getUberPage().getRevision()
-// % mPageRtx.mSession.mResourceConfig.mRevisionsToRestore != 0) || mPageRtx.mSession.mResourceConfig.mRevisionKind == Versioning.FULL)) {
-// return;
-// }
+ // // Revision to commit is not a full dump => return immediately.
+ // if (!page.isDirty()
+ // && ((getUberPage().getRevision()
+ // % mPageRtx.mSession.mResourceConfig.mRevisionsToRestore != 0) ||
+ // mPageRtx.mSession.mResourceConfig.mRevisionKind == Versioning.FULL)) {
+ // return;
+ // }
reference.setPage(page);
@@ -831,7 +843,9 @@ private RevisionRootPage preparePreviousRevisionRootPage(
final @Nonnegative int baseRevision,
final @Nonnegative int representRevision) throws SirixIOException {
if (getUberPage().isBootstrap()) {
- return mPageRtx.loadRevRoot(baseRevision);
+ final RevisionRootPage revisionRootPage = mPageRtx.loadRevRoot(baseRevision);
+ mPageLog.put(new IndirectPageLogKey(PageKind.UBERPAGE, -1, Constants.UBPINP_LEVEL_PAGE_COUNT_EXPONENT.length, 0), revisionRootPage);
+ return revisionRootPage;
} else {
// Prepare revision root nodePageReference.
final RevisionRootPage revisionRootPage = new RevisionRootPage(
@@ -898,15 +912,6 @@ private PageReference prepareLeafOfTree(final PageReference startReference,
}
// Return reference to leaf of indirect tree.
- // reference
- // .setLogKey(new LogKey(
- // pageKind,
- // inpLevelPageCountExp.length,
- // parentOffset
- // * Constants.INP_REFERENCE_COUNT
- // + (int) (key - ((key >> inpLevelPageCountExp[inpLevelPageCountExp.length
- // - 1]) << inpLevelPageCountExp[inpLevelPageCountExp.length - 1]))));
- // reference.setKeyValuePageKey(key);
return reference;
}
@@ -1027,4 +1032,9 @@ public void putPageIntoKeyValueCache(final PageKind pageKind,
throw new IllegalStateException("page kind not known!");
}
}
+
+ public Page getFromPageLog(final IndirectPageLogKey key) {
+ checkNotNull(key);
+ return mPageLog.get(key);
+ }
}
View
28 bundles/sirix-core/src/main/java/org/sirix/access/conf/ResourceConfiguration.java
@@ -457,16 +457,10 @@ public static ResourceConfiguration deserialize(final File file)
builder.byteHandlerPipeline(pipeline).hashKind(hashing)
.versioningApproach(revisioning)
.revisionsToRestore(revisionToRestore).storageType(storage)
- .persistenter(persistenter);
- if (compression) {
- builder.useTextCompression();
- }
- if (pathSummary) {
- builder.buildPathSummary();
- }
- if (deweyIDsStored) {
- builder.useDeweyIDs();
- }
+ .persistenter(persistenter)
+ .useTextCompression(compression)
+ .buildPathSummary(pathSummary)
+ .useDeweyIDs(deweyIDsStored);
// Deserialized instance.
final ResourceConfiguration config = new ResourceConfiguration(builder);
@@ -530,7 +524,7 @@ public Builder(final String resource,
final DatabaseConfiguration config) {
mResource = checkNotNull(resource);
mDBConfig = checkNotNull(config);
- mPathSummary = false;
+ mPathSummary = true;
mByteHandler = new ByteHandlePipeline(new DeflateCompressor());
}
@@ -606,8 +600,8 @@ public Builder revisionsToRestore(final @Nonnegative int revisionsToRestore) {
*
* @return reference to the builder object
*/
- public Builder useDeweyIDs() {
- mUseDeweyIDs = true;
+ public Builder useDeweyIDs(boolean useDeweyIDs) {
+ mUseDeweyIDs = useDeweyIDs;
return this;
}
@@ -618,8 +612,8 @@ public Builder useDeweyIDs() {
* use text compression or not (default: yes)
* @return reference to the builder object
*/
- public Builder useTextCompression() {
- mCompression = true;
+ public Builder useTextCompression(boolean useTextCompression) {
+ mCompression = useTextCompression;
return this;
}
@@ -628,8 +622,8 @@ public Builder useTextCompression() {
*
* @return reference to the builder object
*/
- public Builder buildPathSummary() {
- mPathSummary = true;
+ public Builder buildPathSummary(boolean buildPathSummary) {
+ mPathSummary = buildPathSummary;
return this;
}
View
1 bundles/sirix-core/src/main/java/org/sirix/index/avltree/AVLTreeReader.java
@@ -100,7 +100,6 @@ private AVLTreeReader(final PageReadTrx pageReadTrx, final IndexType type,
mPageKind = PageKind.NAMEPAGE;
break;
default:
- mPageKind = null;
throw new IllegalStateException();
}
mClosed = false;
View
6 bundles/sirix-core/src/main/java/org/sirix/index/avltree/AVLTreeWriter.java
@@ -80,16 +80,16 @@ private AVLTreeWriter(
// Create CAS index tree if needed.
final CASPage casPage = pageWriteTrx.getCASPage(pageWriteTrx
.getActualRevisionRootPage());
- pageWriteTrx.putPageIntoCache(new IndirectPageLogKey(PageKind.PATHPAGE,
+ pageWriteTrx.putPageIntoCache(new IndirectPageLogKey(PageKind.CASPAGE,
-1, -1, 0), casPage);
casPage.createCASIndexTree(pageWriteTrx, index);
break;
case NAME:
// Create name index tree if needed.
final NamePage namePage = pageWriteTrx.getNamePage(pageWriteTrx
.getActualRevisionRootPage());
- pageWriteTrx.putPageIntoCache(new IndirectPageLogKey(PageKind.PATHPAGE,
- -1, -1, 0), namePage);
+// pageWriteTrx.putPageIntoCache(new IndirectPageLogKey(PageKind.NAMEPAGE,
+// -1, -1, 0), namePage);
namePage.createNameIndexTree(pageWriteTrx, index);
break;
}
View
1 bundles/sirix-core/src/main/java/org/sirix/index/cas/CASIndexBuilder.java
@@ -84,6 +84,7 @@ private VisitResult process(final ImmutableNode node) {
setNodeReferences(node, new NodeReferences(), value);
}
}
+ mRtx.moveTo(node.getNodeKey());
} catch (final PathException | SirixIOException e) {
LOGGER.error(e.getMessage(), e);
}
View
185 bundles/sirix-core/src/main/java/org/sirix/node/Kind.java
@@ -29,10 +29,11 @@
import static org.sirix.node.Utils.getVarLong;
import static org.sirix.node.Utils.putVarLong;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -81,7 +82,7 @@
/** Node kind is element. */
ELEMENT((byte) 1, ElementNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
// Node delegate.
@@ -125,7 +126,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
final ElementNode node = (ElementNode) record;
@@ -149,7 +150,7 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node kind is attribute. */
ATTRIBUTE((byte) 2, AttributeNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
// Node delegate.
@@ -182,7 +183,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
final AttributeNode node = (AttributeNode) record;
@@ -196,7 +197,7 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node kind is namespace. */
NAMESPACE((byte) 13, NamespaceNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
// Node delegate.
@@ -221,7 +222,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
final NamespaceNode node = (NamespaceNode) record;
@@ -234,7 +235,7 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node kind is text. */
TEXT((byte) 3, TextNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
// Node delegate.
@@ -259,7 +260,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
final TextNode node = (TextNode) record;
@@ -276,7 +277,7 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node kind is processing instruction. */
PROCESSING_INSTRUCTION((byte) 7, PINode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
// Node delegate.
@@ -301,7 +302,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
final PINode node = (PINode) record;
@@ -316,7 +317,7 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node kind is comment. */
COMMENT((byte) 8, CommentNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
// Node delegate.
@@ -341,7 +342,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
final CommentNode node = (CommentNode) record;
@@ -359,7 +360,7 @@ public void serialize(final DataOutputStream sink, final Record record,
// Virtualize document root node?
DOCUMENT((byte) 9, DocumentRootNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
final NodeDelegate nodeDel = new NodeDelegate(
@@ -374,7 +375,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream pSink, final Record precord,
+ public void serialize(final DataOutput pSink, final Record precord,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
final DocumentRootNode node = (DocumentRootNode) precord;
@@ -389,14 +390,14 @@ public void serialize(final DataOutputStream pSink, final Record precord,
/** Whitespace text. */
WHITESPACE((byte) 4, null) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@@ -405,31 +406,29 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node kind is deleted node. */
DELETE((byte) 5, DeletedNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
final NodeDelegate delegate = new NodeDelegate(recordID, 0, 0, 0,
Optional.<SirixDeweyID> absent());
return new DeletedNode(delegate);
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx) {
- // DeletedNode node = (DeletedNode) record;
- // putVarLong(sink, node.getNodeKey());
}
},
/** NullNode to support the Null Object pattern. */
NULL((byte) 6, NullNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final DataOutputStream ink, final Record record,
+ public void serialize(final DataOutput ink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@@ -438,14 +437,14 @@ public void serialize(final DataOutputStream ink, final Record record,
/** Dumb node for testing. */
DUMB((byte) 20, DumbNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
// final long nodeKey = getVarLong(source);
return new DumbNode(recordID);
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx) {
// putVarLong(sink, record.getNodeKey());
}
@@ -454,13 +453,13 @@ public void serialize(final DataOutputStream sink, final Record record,
/** AtomicKind. */
ATOMIC((byte) 15, AtomicValue.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@@ -469,7 +468,7 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node kind is path node. */
PATH((byte) 16, PathNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
// Node delegate.
@@ -487,7 +486,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
final PathNode node = (PathNode) record;
@@ -504,7 +503,7 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node kind is a CAS-AVL node. */
CASAVL((byte) 17, AVLNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
final int valueSize = source.readInt();
@@ -541,7 +540,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
@SuppressWarnings("unchecked")
@@ -591,7 +590,7 @@ private Type resolveType(final String s) {
/** Node kind is a PATH-AVL node. */
PATHAVL((byte) 18, AVLNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
final long key = getVarLong(source);
@@ -615,7 +614,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
@SuppressWarnings("unchecked")
@@ -638,15 +637,15 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node kind is a PATH-AVL node. */
NAMEAVL((byte) 19, AVLNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
final byte[] nspBytes = new byte[source.readInt()];
- source.read(nspBytes);
+ source.readFully(nspBytes);
final byte[] prefixBytes = new byte[source.readInt()];
- source.read(prefixBytes);
+ source.readFully(prefixBytes);
final byte[] localNameBytes = new byte[source.readInt()];
- source.read(localNameBytes);
+ source.readFully(localNameBytes);
final QNm name = new QNm(
new String(nspBytes, Constants.DEFAULT_ENCODING), new String(
prefixBytes, Constants.DEFAULT_ENCODING), new String(
@@ -671,7 +670,7 @@ public Record deserialize(final DataInputStream source,
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
@SuppressWarnings("unchecked")
@@ -702,13 +701,13 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node includes a deweyID <=> nodeKey mapping. */
DEWEYIDMAPPING((byte) 23, DeweyIDMappingNode.class) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx) {
throw new UnsupportedOperationException();
}
@@ -717,14 +716,14 @@ public void serialize(final DataOutputStream sink, final Record record,
/** Node type not known. */
UNKNOWN((byte) 22, null) {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx)
throws IOException {
throw new UnsupportedOperationException();
}
@Override
- public void serialize(final DataOutputStream sink, final Record record,
+ public void serialize(final DataOutput sink, final Record record,
final @Nullable Record nextRecord, final PageReadTrx pageReadTrx)
throws IOException {
throw new UnsupportedOperationException();
@@ -813,7 +812,7 @@ public static Kind getKind(final Class<? extends Record> clazz) {
* @return {@link NodeDelegate} instance
*/
private static final NodeDelegate deserializeNodeDelegateWithoutIDs(
- final DataInputStream source, final @Nonnegative long recordID,
+ final DataInput source, final @Nonnegative long recordID,
final PageReadTrx pageReadTrx) throws IOException {
final long nodeKey = recordID;
final long parentKey = nodeKey - getVarLong(source);
@@ -833,7 +832,7 @@ private static final NodeDelegate deserializeNodeDelegateWithoutIDs(
* @return {@link NodeDelegate} instance
*/
private static final NodeDelegate deserializeNodeDelegate(
- final DataInputStream source, final @Nonnegative long recordID,
+ final DataInput source, final @Nonnegative long recordID,
final PageReadTrx pageReadTrx) throws IOException {
final long nodeKey = recordID;
final long parentKey = nodeKey - getVarLong(source);
@@ -863,58 +862,60 @@ private static final NodeDelegate deserializeNodeDelegate(
* @param {@link ResourceConfiguration} instance
*/
private static final void serializeDelegate(final NodeDelegate nodeDel,
- final Node nextNode, final DataOutputStream sink,
- final PageReadTrx pageReadTrx) throws IOException {
+ final Node nextNode, final DataOutput sink, final PageReadTrx pageReadTrx)
+ throws IOException {
putVarLong(sink, nodeDel.getNodeKey() - nodeDel.getParentKey());
sink.writeLong(nodeDel.getHash());
putVarLong(sink, nodeDel.getRevision());
if (pageReadTrx.getSession().getResourceConfig().mDeweyIDsStored) {
final Optional<SirixDeweyID> id = nodeDel.getDeweyID();
if (id.isPresent()) {
- // if (prevNode != null && prevNode.getDeweyID().isPresent()) {
- // final byte[] prevDeweyID = prevNode.getDeweyID().get().toBytes();
- // final byte[] deweyID = nodeDel.getDeweyID().get().toBytes();
- // if (prevDeweyID.length <= deweyID.length) {
- // int i = 0;
- // for (; i < prevDeweyID.length; i++) {
- // if (prevDeweyID[i] != deweyID[i]) {
- // break;
- // }
- // }
- // writeDeweyID(sink, deweyID, i);
- // } else {
- // int i = 0;
- // for (; i < deweyID.length; i++) {
- // if (prevDeweyID[i] != deweyID[i]) {
- // break;
- // }
- // }
- // writeDeweyID(sink, prevDeweyID, i);
- // }
- // } else {
- final byte[] deweyID = nodeDel.getDeweyID().get().toBytes();
- sink.writeByte(deweyID.length);
- sink.write(deweyID);
- // }
+// if (nextNode != null && nextNode.getDeweyID().isPresent()) {
+// final byte[] prevDeweyID = nodeDel.getDeweyID().get().toBytes();
+// final byte[] deweyID = nextNode.getDeweyID().get().toBytes();
+// final boolean isCurrLengthLessThanOrEqual = prevDeweyID.length <= deweyID.length;
+// sink.writeByte(isCurrLengthLessThanOrEqual ? (byte) 1 : (byte) 0);
+// if (isCurrLengthLessThanOrEqual) {
+// int i = 0;
+// for (; i < prevDeweyID.length; i++) {
+// if (prevDeweyID[i] != deweyID[i]) {
+// break;
+// }
+// }
+// writeDeweyID(sink, deweyID, i);
+// } else {
+// int i = 0;
+// for (; i < deweyID.length; i++) {
+// if (prevDeweyID[i] != deweyID[i]) {
+// break;
+// }
+// }
+// writeDeweyID(sink, prevDeweyID, i);
+// }
+// } else {
+ final byte[] deweyID = nodeDel.getDeweyID().get().toBytes();
+ sink.writeByte(deweyID.length);
+ sink.write(deweyID);
+// }
}
}
}
- // /**
- // * Write the deweyID.
- // *
- // * @param sink
- // * to write to
- // * @param deweyID
- // * deweyID in bytes
- // * @param i
- // * the index from which to start the copy of the array
- // */
- // private static void writeDeweyID(final DataOutputStream sink,
- // final byte[] deweyID, final @Nonnegative int i) throws IOException {
- // sink.writeByte(deweyID.length - i - 1);
- // sink.write(Arrays.copyOfRange(deweyID, i, deweyID.length));
- // }
+ /**
+ * Write the deweyID.
+ *
+ * @param sink
+ * to write to
+ * @param deweyID
+ * deweyID in bytes
+ * @param i
+ * the index from which to start the copy of the array
+ */
+ private static void writeDeweyID(final DataOutput sink, final byte[] deweyID,
+ final @Nonnegative int i) throws IOException {
+ sink.writeByte(deweyID.length - i - 1);
+ sink.write(Arrays.copyOfRange(deweyID, i, deweyID.length));
+ }
/**
* Serializing the {@link StructNodeDelegate} instance.
@@ -925,7 +926,7 @@ private static final void serializeDelegate(final NodeDelegate nodeDel,
* to serialize to
*/
private static final void serializeStrucDelegate(
- final StructNodeDelegate nodeDel, final DataOutputStream sink)
+ final StructNodeDelegate nodeDel, final DataOutput sink)
throws IOException {
putVarLong(sink, nodeDel.getNodeKey() - nodeDel.getRightSiblingKey());
putVarLong(sink, nodeDel.getNodeKey() - nodeDel.getLeftSiblingKey());
@@ -944,7 +945,7 @@ private static final void serializeStrucDelegate(
* @return {@link StructNodeDelegate} instance
*/
private static final StructNodeDelegate deserializeStructDel(
- final NodeDelegate nodeDel, final DataInputStream source)
+ final NodeDelegate nodeDel, final DataInput source)
throws IOException {
final long currKey = nodeDel.getNodeKey();
final long rightSibl = currKey - getVarLong(source);
@@ -966,7 +967,7 @@ private static final StructNodeDelegate deserializeStructDel(
* @return {@link NameNodeDelegate} instance
*/
private static final NameNodeDelegate deserializeNameDelegate(
- final NodeDelegate nodeDel, final DataInputStream source)
+ final NodeDelegate nodeDel, final DataInput source)
throws IOException {
final int uriKey = source.readInt();
int prefixKey = source.readInt();
@@ -984,7 +985,7 @@ private static final NameNodeDelegate deserializeNameDelegate(
* to serialize to
*/
private static final void serializeNameDelegate(
- final NameNodeDelegate nameDel, final DataOutputStream sink)
+ final NameNodeDelegate nameDel, final DataOutput sink)
throws IOException {
sink.writeInt(nameDel.getURIKey());
sink.writeInt(nameDel.getPrefixKey());
@@ -1001,7 +1002,7 @@ private static final void serializeNameDelegate(
* to serialize to
*/
private static final void serializeValDelegate(
- final ValNodeDelegate valueDel, final DataOutputStream sink)
+ final ValNodeDelegate valueDel, final DataOutput sink)
throws IOException {
final boolean isCompressed = valueDel.isCompressed();
sink.writeByte(isCompressed ? (byte) 1 : (byte) 0);
View
8 bundles/sirix-core/src/main/java/org/sirix/node/NodePersistenter.java
@@ -1,7 +1,7 @@
package org.sirix.node;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import javax.annotation.Nonnegative;
@@ -19,15 +19,15 @@
*/
public final class NodePersistenter implements RecordPersistenter {
@Override
- public Record deserialize(final DataInputStream source,
+ public Record deserialize(final DataInput source,
final @Nonnegative long recordID, final PageReadTrx pageReadTrx) throws IOException {
final byte id = source.readByte();
final Kind enumKind = Kind.getKind(id);
return enumKind.deserialize(source, recordID, pageReadTrx);
}
@Override
- public void serialize(final DataOutputStream sink,
+ public void serialize(final DataOutput sink,
final Record record, final @Nullable Record nextRecord,
final PageReadTrx pageReadTrx) throws IOException {
final Kind nodeKind = (Kind) record.getKind();
View
12 bundles/sirix-core/src/main/java/org/sirix/node/interfaces/RecordPersistenter.java
@@ -1,7 +1,7 @@
package org.sirix.node.interfaces;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import javax.annotation.Nonnegative;
@@ -35,8 +35,8 @@
* if an I/O error occurs during deserialization
*/
@Nonnull
- Record deserialize(DataInputStream source, @Nonnegative long recordID,
- @Nonnull PageReadTrx pageReadTrx) throws IOException;
+ Record deserialize(DataInput source, @Nonnegative long recordID,
+ PageReadTrx pageReadTrx) throws IOException;
/**
* Serialize a record from a {@link ByteArrayDataOutput} instance.
@@ -55,6 +55,6 @@ Record deserialize(DataInputStream source, @Nonnegative long recordID,
* @throws IOException
* if an I/O error occurs during serialization
*/
- void serialize(DataOutputStream sink, @Nonnull Record record,
- @Nonnull Record previousRecord, @Nonnull PageReadTrx pageReadTrx) throws IOException;
+ void serialize(DataOutput sink, Record record,
+ Record previousRecord, PageReadTrx pageReadTrx) throws IOException;
}
View
1 bundles/sirix-core/src/main/java/org/sirix/page/NamePage.java
@@ -29,7 +29,6 @@
import java.io.DataInputStream;
import java.io.DataOutput;
-import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
View
20 bundles/sirix-core/src/main/java/org/sirix/page/UnorderedKeyValuePage.java
@@ -36,9 +36,13 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
@@ -51,6 +55,7 @@
import org.sirix.api.PageWriteTrx;
import org.sirix.exception.SirixException;
import org.sirix.exception.SirixIOException;
+import org.sirix.node.interfaces.Node;
import org.sirix.node.interfaces.Record;
import org.sirix.node.interfaces.RecordPersistenter;
import org.sirix.page.interfaces.KeyValuePage;
@@ -313,13 +318,28 @@ public boolean equals(final @Nullable Object obj) {
// Add references to OverflowPages.
private void addReferences() throws IOException {
+// // Sort entries which have deweyIDs.
+// final List<Map.Entry<Long, Record>> entries = new ArrayList<Map.Entry<Long, Record>>(
+// mRecords.entrySet());
+// if (mPageReadTrx.getSession().getResourceConfig().mDeweyIDsStored) {
+// Collections.sort(entries, new Comparator<Map.Entry<Long, Record>>() {
+// public int compare(Map.Entry<Long, Record> a, Map.Entry<Long, Record> b) {
+// if (a.getValue() instanceof Node && b.getValue() instanceof Node) {
+// return ((Node) a.getValue()).getDeweyID().get().compareTo(((Node) b.getValue()).getDeweyID().get());
+// }
+// return -1;
+// }
+// });
+// }
+
final PeekingIterator<Entry<Long, Record>> it = Iterators
.peekingIterator(mRecords.entrySet().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();
Entry<Long, Record> nextEntry = null;
try {
View
4 bundles/sirix-core/src/test/java/org/sirix/Holder.java
@@ -76,7 +76,7 @@ public static Holder generateDeweyIDSession() throws SirixException {
}
final Database database = Databases.openDatabase(PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(
- TestHelper.RESOURCE, PATHS.PATH1.getConfig()).useDeweyIDs().build());
+ TestHelper.RESOURCE, PATHS.PATH1.getConfig()).useDeweyIDs(true).build());
final Session session = database
.getSession(new SessionConfiguration.Builder(TestHelper.RESOURCE)
.build());
@@ -101,7 +101,7 @@ public static Holder generatePathSummarySession() throws SirixException {
}
final Database database = Databases.openDatabase(PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(
- TestHelper.RESOURCE, PATHS.PATH1.getConfig()).buildPathSummary().build());
+ TestHelper.RESOURCE, PATHS.PATH1.getConfig()).buildPathSummary(true).build());
final Session session = database
.getSession(new SessionConfiguration.Builder(TestHelper.RESOURCE)
.build());
View
12 bundles/sirix-examples/src/main/java/org/sirix/examples/XQueryUsage.java
@@ -58,12 +58,12 @@
*/
public static void main(final String[] args) throws SirixException {
try {
- loadDocumentAndQuery();
- System.out.println();
- loadDocumentAndUpdate();
- System.out.println();
- loadCollectionAndQuery();
- System.out.println();
+// loadDocumentAndQuery();
+// System.out.println();
+// loadDocumentAndUpdate();
+// System.out.println();
+// loadCollectionAndQuery();
+// System.out.println();
loadDocumentAndQueryTemporal();
} catch (IOException e) {
System.err.print("I/O error: ");
View
10 bundles/sirix-xquery/src/main/java/org/sirix/xquery/node/DBCollection.java
@@ -147,8 +147,8 @@ public DBNode add(final String resName, SubtreeParser parser)
final String resource = new StringBuilder(2).append("resource")
.append(mDatabase.listResources().length + 1).toString();
mDatabase.createResource(ResourceConfiguration
- .newBuilder(resource, mDatabase.getDatabaseConfig()).useDeweyIDs()
- .useTextCompression().buildPathSummary().build());
+ .newBuilder(resource, mDatabase.getDatabaseConfig()).useDeweyIDs(true)
+ .useTextCompression(true).buildPathSummary(true).build());
final Session session = mDatabase.getSession(SessionConfiguration
.newBuilder(resource).build());
final NodeWriteTrx wtx = session.beginNodeWriteTrx();
@@ -180,8 +180,8 @@ public DBNode add(SubtreeParser parser)
final String resource = new StringBuilder(2).append("resource")
.append(mDatabase.listResources().length + 1).toString();
mDatabase.createResource(ResourceConfiguration
- .newBuilder(resource, mDatabase.getDatabaseConfig()).useDeweyIDs()
- .useTextCompression().buildPathSummary().build());
+ .newBuilder(resource, mDatabase.getDatabaseConfig()).useDeweyIDs(true)
+ .useTextCompression(true).buildPathSummary(true).build());
final Session session = mDatabase.getSession(SessionConfiguration
.newBuilder(resource).build());
final NodeWriteTrx wtx = session.beginNodeWriteTrx();
@@ -210,7 +210,7 @@ public DBNode add(final String resource, final XMLEventReader reader)
throws OperationNotSupportedException, DocumentException {
try {
mDatabase.createResource(ResourceConfiguration
- .newBuilder(resource, mDatabase.getDatabaseConfig()).useDeweyIDs()
+ .newBuilder(resource, mDatabase.getDatabaseConfig()).useDeweyIDs(true)
.build());
final Session session = mDatabase.getSession(SessionConfiguration
.newBuilder(resource).build());
View
6 bundles/sirix-xquery/src/main/java/org/sirix/xquery/node/DBStore.java
@@ -209,7 +209,8 @@ public File getLocation() {
: new StringBuilder(3).append("resource")
.append(database.listResources().length + 1).toString();
database.createResource(ResourceConfiguration.newBuilder(resName, dbConf)
- .useDeweyIDs().useTextCompression().buildPathSummary().storageType(mStorageType).build());
+ .useDeweyIDs(true).useTextCompression(true).buildPathSummary(true)
+ .storageType(mStorageType).build());
final Session session = database
.getSession(new SessionConfiguration.Builder(resName).build());
final NodeWriteTrx wtx = session.beginNodeWriteTrx();
@@ -256,7 +257,8 @@ public File getLocation() {
public Void call() throws DocumentException, SirixException {
database.createResource(ResourceConfiguration
.newBuilder(resource, dbConf).storageType(mStorageType)
- .useDeweyIDs().useTextCompression().buildPathSummary().build());
+ .useDeweyIDs(true).useTextCompression(true).buildPathSummary(true)
+ .build());
final Session session = database
.getSession(new SessionConfiguration.Builder(resource)
.build());

0 comments on commit 28af7e7

Please sign in to comment.