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