Search in sources :

Example 11 with Segment

use of com.enonic.xp.blob.Segment in project xp by enonic.

the class SegmentVacuumCommand method execute.

public VacuumTaskResult.Builder execute() {
    List<Segment> toBeRemoved = new ArrayList<>();
    blobStore.listSegments().forEach(segment -> {
        final RepositoryId repositoryId = RepositorySegmentUtils.toRepositoryId(segment);
        if (isRepositoryToKeep(repositoryId)) {
            result.inUse();
        } else {
            toBeRemoved.add(segment);
        }
        result.processed();
    });
    toBeRemoved.forEach(segment -> {
        try {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Deleting segment [" + segment + "]");
            }
            blobStore.deleteSegment(segment);
            result.deleted();
        } catch (Exception e) {
            LOG.error("Failed to delete segment [" + segment + "]", e);
            result.failed();
        }
    });
    return result;
}
Also used : ArrayList(java.util.ArrayList) RepositoryId(com.enonic.xp.repository.RepositoryId) Segment(com.enonic.xp.blob.Segment)

Example 12 with Segment

use of com.enonic.xp.blob.Segment in project xp by enonic.

the class AbstractDumpReader method get.

@Override
public NodeVersion get(final RepositoryId repositoryId, final NodeVersionKey nodeVersionKey) {
    final Segment nodeSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_NODE_SEGMENT_LEVEL);
    final DumpBlobRecord dataRecord = this.dumpBlobStore.getRecord(nodeSegment, nodeVersionKey.getNodeBlobKey());
    final Segment indexConfigSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_INDEX_CONFIG_SEGMENT_LEVEL);
    final DumpBlobRecord indexConfigRecord = this.dumpBlobStore.getRecord(indexConfigSegment, nodeVersionKey.getIndexConfigBlobKey());
    final Segment accessControlSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_ACCESS_CONTROL_SEGMENT_LEVEL);
    final DumpBlobRecord accessControlRecord = this.dumpBlobStore.getRecord(accessControlSegment, nodeVersionKey.getAccessControlBlobKey());
    return this.factory.create(dataRecord.getBytes(), indexConfigRecord.getBytes(), accessControlRecord.getBytes());
}
Also used : DumpBlobRecord(com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord) Segment(com.enonic.xp.blob.Segment)

Example 13 with Segment

use of com.enonic.xp.blob.Segment in project xp by enonic.

the class AbstractEntryProcessor method validateOrAddBinary.

void validateOrAddBinary(final NodeVersion nodeVersion, final EntryLoadResult.Builder result) {
    nodeVersion.getAttachedBinaries().forEach(binary -> {
        final Segment segment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.BINARY_SEGMENT_LEVEL);
        final BlobRecord existingRecord = this.blobStore.getRecord(segment, BlobKey.from(binary.getBlobKey()));
        if (existingRecord == null) {
            try {
                final ByteSource dumpBinary = this.dumpReader.getBinary(repositoryId, binary.getBlobKey());
                this.blobStore.addRecord(segment, dumpBinary);
            } catch (RepoLoadException e) {
                reportBinaryError(nodeVersion, result, binary, e);
            }
        }
    });
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) RepoLoadException(com.enonic.xp.repo.impl.dump.RepoLoadException) ByteSource(com.google.common.io.ByteSource) Segment(com.enonic.xp.blob.Segment)

Example 14 with Segment

use of com.enonic.xp.blob.Segment in project xp by enonic.

the class IndexAccessSegmentsDumpUpgrader method upgradeVersionDumpEntry.

private Pre6VersionDumpEntryJson upgradeVersionDumpEntry(final RepositoryId repositoryId, final Pre4VersionDumpEntryJson versionDumpEntry) {
    // Retrieves the existing node version
    final Segment nodeDataSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_NODE_SEGMENT_LEVEL);
    final BlobKey nodeBlobKey = BlobKey.from(versionDumpEntry.getBlobKey());
    final DumpBlobRecord nodeBlobRecord = dumpReader.getDumpBlobStore().getRecord(nodeDataSegment, nodeBlobKey);
    final Pre4NodeVersionJson nodeVersion = getNodeVersion(nodeBlobRecord);
    // Serializes the new index config blob
    final byte[] serializedIndexConfig = serialize(nodeVersion.getIndexConfigDocument());
    final Segment indexConfigSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_INDEX_CONFIG_SEGMENT_LEVEL);
    final BlobKey indexConfigBlobKey = addRecord(indexConfigSegment, serializedIndexConfig);
    // Serializes the new access control blob
    final byte[] serializedAccessControl = serializeAccessControl(nodeVersion);
    final Segment accessControlSegment = RepositorySegmentUtils.toSegment(repositoryId, DumpConstants.DUMP_ACCESS_CONTROL_SEGMENT_LEVEL);
    final BlobKey accessControlBlobKey = addRecord(accessControlSegment, serializedAccessControl);
    // Return the new version dump entry
    return Pre6VersionDumpEntryJson.create().nodePath(versionDumpEntry.getNodePath()).timestamp(versionDumpEntry.getTimestamp()).version(versionDumpEntry.getVersion()).nodeBlobKey(versionDumpEntry.getBlobKey()).indexConfigBlobKey(indexConfigBlobKey.toString()).accessControlBlobKey(accessControlBlobKey.toString()).nodeState(versionDumpEntry.getNodeState()).build();
}
Also used : Pre4NodeVersionJson(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4NodeVersionJson) BlobKey(com.enonic.xp.blob.BlobKey) DumpBlobRecord(com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord) Segment(com.enonic.xp.blob.Segment)

Example 15 with Segment

use of com.enonic.xp.blob.Segment in project xp by enonic.

the class NodeVersionServiceImpl method store.

@Override
public NodeVersionKey store(final NodeVersion nodeVersion, final InternalContext context) {
    final Segment nodeSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.NODE_SEGMENT_LEVEL);
    final byte[] nodeJsonString = this.nodeVersionJsonSerializer.toNodeString(nodeVersion);
    final BlobRecord nodeBlobRecord = blobStore.addRecord(nodeSegment, ByteSource.wrap(nodeJsonString));
    final Segment indexConfigSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.INDEX_CONFIG_SEGMENT_LEVEL);
    final byte[] indexConfigDocumentString = this.nodeVersionJsonSerializer.toIndexConfigDocumentString(nodeVersion);
    final BlobRecord indexConfigBlobRecord = blobStore.addRecord(indexConfigSegment, ByteSource.wrap(indexConfigDocumentString));
    final Segment accessControlSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.ACCESS_CONTROL_SEGMENT_LEVEL);
    final byte[] accessControlString = this.nodeVersionJsonSerializer.toAccessControlString(nodeVersion);
    final BlobRecord accessControlBlobRecord = blobStore.addRecord(accessControlSegment, ByteSource.wrap(accessControlString));
    return NodeVersionKey.from(nodeBlobRecord.getKey(), indexConfigBlobRecord.getKey(), accessControlBlobRecord.getKey());
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) Segment(com.enonic.xp.blob.Segment)

Aggregations

Segment (com.enonic.xp.blob.Segment)28 BlobRecord (com.enonic.xp.blob.BlobRecord)20 Test (org.junit.jupiter.api.Test)15 ByteSource (com.google.common.io.ByteSource)11 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)3 BlobStore (com.enonic.xp.blob.BlobStore)2 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 MemoryBlobRecord (com.enonic.xp.internal.blobstore.MemoryBlobRecord)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 Node (com.enonic.xp.node.Node)2 RepoDumpException (com.enonic.xp.repo.impl.dump.RepoDumpException)2 RepoLoadException (com.enonic.xp.repo.impl.dump.RepoLoadException)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 BlobKey (com.enonic.xp.blob.BlobKey)1 CachingBlobStore (com.enonic.xp.blob.CachingBlobStore)1 CachedBlobStore (com.enonic.xp.internal.blobstore.cache.CachedBlobStore)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 Pre4NodeVersionJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4NodeVersionJson)1 RepositoryExeption (com.enonic.xp.repository.RepositoryExeption)1