Search in sources :

Example 1 with Versioning

use of org.sirix.settings.Versioning in project sirix by sirixdb.

the class PageReadTrxImpl method getRecordPageContainer.

@Override
public <K extends Comparable<? super K>, V extends Record, T extends KeyValuePage<K, V>> PageContainer getRecordPageContainer(@Nonnegative final Long recordPageKey, final int index, final PageKind pageKind) throws SirixIOException {
    assertNotClosed();
    checkArgument(recordPageKey >= 0, "recordPageKey must not be negative!");
    final Optional<PageReference> pageReferenceToRecordPage = getLeafPageReference(checkNotNull(recordPageKey), index, checkNotNull(pageKind));
    if (!pageReferenceToRecordPage.isPresent()) {
        return PageContainer.emptyInstance();
    }
    // Try to get from resource buffer manager.
    final PageContainer recordPageContainerFromBuffer = mResourceBufferManager.getRecordPageCache().get(pageReferenceToRecordPage.get());
    if (recordPageContainerFromBuffer != null) {
        return recordPageContainerFromBuffer;
    }
    // Load list of page "fragments" from persistent storage.
    final List<T> pages = getSnapshotPages(pageReferenceToRecordPage.get());
    if (pages.isEmpty()) {
        return PageContainer.emptyInstance();
    }
    final int mileStoneRevision = mResourceConfig.mRevisionsToRestore;
    final Versioning revisioning = mResourceConfig.mRevisionKind;
    final Page completePage = revisioning.combineRecordPages(pages, mileStoneRevision, this);
    final PageContainer recordPageContainer = new PageContainer(completePage, clone(completePage));
    if (mTrxIntentLog == null)
        mResourceBufferManager.getRecordPageCache().put(pageReferenceToRecordPage.get(), recordPageContainer);
    return recordPageContainer;
}
Also used : PageReference(org.sirix.page.PageReference) PageContainer(org.sirix.cache.PageContainer) Versioning(org.sirix.settings.Versioning) 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)

Example 2 with Versioning

use of org.sirix.settings.Versioning in project sirix by sirixdb.

the class PageWriteTrxImpl method dereferenceRecordPageForModification.

/**
 * Dereference record page reference.
 *
 * @param reference reference to leaf, that is the record page
 * @return dereferenced page
 */
private PageContainer dereferenceRecordPageForModification(final PageReference reference) {
    final List<UnorderedKeyValuePage> revs = mPageRtx.getSnapshotPages(reference);
    final Versioning revisioning = mPageRtx.mResourceManager.getResourceConfig().mRevisionKind;
    final int mileStoneRevision = mPageRtx.mResourceManager.getResourceConfig().mRevisionsToRestore;
    return revisioning.combineRecordPagesForModification(revs, mileStoneRevision, mPageRtx, reference);
}
Also used : Versioning(org.sirix.settings.Versioning) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage)

Example 3 with Versioning

use of org.sirix.settings.Versioning in project sirix by sirixdb.

the class ResourceConfiguration method deserialize.

/**
 * Deserializing a Resource configuration from a JSON-file from the persistent storage.
 *
 * @param file where the resource lies in.
 * @return a complete {@link ResourceConfiguration} instance
 * @throws SirixIOException if an I/O error occurs
 */
public static ResourceConfiguration deserialize(final Path file) throws SirixIOException {
    try {
        final Path configFile = file.resolve(ResourcePaths.CONFIG_BINARY.getFile());
        final FileReader fileReader = new FileReader(configFile.toFile());
        final JsonReader jsonReader = new JsonReader(fileReader);
        jsonReader.beginObject();
        // Versioning.
        String name = jsonReader.nextName();
        assert name.equals(JSONNAMES[0]);
        jsonReader.beginObject();
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[1]);
        final Versioning revisioning = Versioning.valueOf(jsonReader.nextString());
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[2]);
        final int revisionToRestore = jsonReader.nextInt();
        jsonReader.endObject();
        // ByteHandlers.
        final List<ByteHandler> handlerList = new ArrayList<>();
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[3]);
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            final Class<?> handlerClazz = Class.forName(jsonReader.nextString());
            final Constructor<?> handlerCons = handlerClazz.getConstructors()[0];
            handlerList.add((ByteHandler) handlerCons.newInstance());
        }
        jsonReader.endArray();
        final ByteHandlePipeline pipeline = new ByteHandlePipeline(handlerList.toArray(new ByteHandler[handlerList.size()]));
        // Storage type.
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[4]);
        final StorageType storage = StorageType.valueOf(jsonReader.nextString());
        // Hashing type.
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[5]);
        final HashKind hashing = HashKind.valueOf(jsonReader.nextString());
        // Text compression.
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[6]);
        final boolean compression = jsonReader.nextBoolean();
        // Path summary.
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[7]);
        final boolean pathSummary = jsonReader.nextBoolean();
        // Unique ID.
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[8]);
        final int ID = jsonReader.nextInt();
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[9]);
        final boolean deweyIDsStored = jsonReader.nextBoolean();
        name = jsonReader.nextName();
        assert name.equals(JSONNAMES[10]);
        final Class<?> persistenterClazz = Class.forName(jsonReader.nextString());
        final Constructor<?> persistenterConstr = persistenterClazz.getConstructors()[0];
        final RecordPersistenter persistenter = (RecordPersistenter) persistenterConstr.newInstance();
        jsonReader.endObject();
        jsonReader.close();
        fileReader.close();
        // Deserialize database config.
        final DatabaseConfiguration dbConfig = DatabaseConfiguration.deserialize(file.getParent().getParent());
        // Builder.
        final ResourceConfiguration.Builder builder = new ResourceConfiguration.Builder(file.getFileName().toString(), dbConfig);
        builder.byteHandlerPipeline(pipeline).hashKind(hashing).versioningApproach(revisioning).revisionsToRestore(revisionToRestore).storageType(storage).persistenter(persistenter).useTextCompression(compression).buildPathSummary(pathSummary).useDeweyIDs(deweyIDsStored);
        // Deserialized instance.
        final ResourceConfiguration config = new ResourceConfiguration(builder);
        return config.setID(ID);
    } catch (IOException | ClassNotFoundException | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new SirixIOException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) HashKind(org.sirix.access.HashKind) ByteHandler(org.sirix.io.bytepipe.ByteHandler) SirixIOException(org.sirix.exception.SirixIOException) JsonReader(com.google.gson.stream.JsonReader) FileReader(java.io.FileReader) ByteHandlePipeline(org.sirix.io.bytepipe.ByteHandlePipeline) Path(java.nio.file.Path) StorageType(org.sirix.io.StorageType) SirixIOException(org.sirix.exception.SirixIOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Versioning(org.sirix.settings.Versioning) RecordPersistenter(org.sirix.node.interfaces.RecordPersistenter)

Aggregations

Versioning (org.sirix.settings.Versioning)3 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)2 JsonReader (com.google.gson.stream.JsonReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashKind (org.sirix.access.HashKind)1 PageContainer (org.sirix.cache.PageContainer)1 SirixIOException (org.sirix.exception.SirixIOException)1 StorageType (org.sirix.io.StorageType)1 ByteHandlePipeline (org.sirix.io.bytepipe.ByteHandlePipeline)1 ByteHandler (org.sirix.io.bytepipe.ByteHandler)1 RecordPersistenter (org.sirix.node.interfaces.RecordPersistenter)1 CASPage (org.sirix.page.CASPage)1 IndirectPage (org.sirix.page.IndirectPage)1 NamePage (org.sirix.page.NamePage)1 PageReference (org.sirix.page.PageReference)1 PathPage (org.sirix.page.PathPage)1