Search in sources :

Example 1 with BlobKey

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

the class FileBlobRecordTest method lastModified.

@Test
public void lastModified() throws Exception {
    final BlobKey key = BlobKey.from("test");
    final Path file = Files.createFile(this.temporaryFolder.resolve("test"));
    final FileBlobRecord record = new FileBlobRecord(key, file);
    assertEquals(Files.getLastModifiedTime(file).toMillis(), record.lastModified());
}
Also used : Path(java.nio.file.Path) BlobKey(com.enonic.xp.blob.BlobKey) Test(org.junit.jupiter.api.Test)

Example 2 with BlobKey

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

the class FileBlobRecordTest method testAccessors.

@Test
public void testAccessors() throws Exception {
    final BlobKey key = BlobKey.from("test");
    final Path file = Files.createFile(this.temporaryFolder.resolve("test"));
    final FileBlobRecord record = new FileBlobRecord(key, file);
    assertSame(key, record.getKey());
    assertNotNull(record.getBytes());
    assertEquals(0, record.getLength());
}
Also used : Path(java.nio.file.Path) BlobKey(com.enonic.xp.blob.BlobKey) Test(org.junit.jupiter.api.Test)

Example 3 with BlobKey

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

the class FileBlobStoreTest method getRecord.

@Test
public void getRecord() {
    final BlobKey key = createRecord("hello").getKey();
    final BlobRecord record = this.blobStore.getRecord(this.segment, key);
    assertNotNull(record);
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) BlobKey(com.enonic.xp.blob.BlobKey) Test(org.junit.jupiter.api.Test)

Example 4 with BlobKey

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

the class AbstractDumpBlobStore method addRecord.

@Override
public BlobKey addRecord(final Segment segment, final ByteSource in) throws BlobStoreException {
    try {
        final BlobKey blobKey = BlobKey.from(in);
        writeRecord(segment, blobKey, in);
        return blobKey;
    } catch (final IOException e) {
        throw new BlobStoreException("Failed to add blob", e);
    }
}
Also used : BlobKey(com.enonic.xp.blob.BlobKey) IOException(java.io.IOException) BlobStoreException(com.enonic.xp.blob.BlobStoreException)

Example 5 with BlobKey

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

the class VersionTableVacuumCommand method doProcessRepository.

private void doProcessRepository(final Repository repository) {
    int counter = 0;
    NodeVersionId lastVersionId = null;
    NodeVersionQuery query = createQuery(lastVersionId);
    NodeVersionQueryResult versionsResult = nodeService.findVersions(query);
    long hits = versionsResult.getHits();
    final long totalHits = versionsResult.getTotalHits();
    if (listener != null) {
        listener.stepBegin(repository.getId().toString(), totalHits);
    }
    while (hits > 0) {
        final List<NodeVersionId> versionsToDelete = new ArrayList<>();
        final Set<BlobKey> nodeBlobToCheckSet = new HashSet<>();
        final Set<BlobKey> binaryBlobToCheckSet = new HashSet<>();
        final NodeVersionsMetadata versions = versionsResult.getNodeVersionsMetadata();
        for (NodeVersionMetadata version : versions) {
            final boolean toDelete = processVersion(repository, version);
            if (toDelete) {
                result.deleted();
                versionsToDelete.add(version.getNodeVersionId());
                nodeBlobToCheckSet.add(version.getNodeVersionKey().getNodeBlobKey());
                binaryBlobToCheckSet.addAll(version.getBinaryBlobKeys().getSet());
            } else {
                result.inUse();
            }
            lastVersionId = version.getNodeVersionId();
            counter++;
        }
        versionService.delete(versionsToDelete, InternalContext.from(ContextAccessor.current()));
        nodeBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.NODE_BLOB_KEY)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.NODE_SEGMENT_LEVEL, blobKey));
        binaryBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.BINARY_BLOB_KEYS)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.BINARY_SEGMENT_LEVEL, blobKey));
        query = createQuery(lastVersionId);
        versionsResult = nodeService.findVersions(query);
        hits = versionsResult.getHits();
    }
    if (listener != null) {
        listener.processed(counter);
    }
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) IsBlobUsedByVersionCommand(com.enonic.xp.repo.impl.vacuum.blob.IsBlobUsedByVersionCommand) RepositoryService(com.enonic.xp.repository.RepositoryService) Node(com.enonic.xp.node.Node) VersionService(com.enonic.xp.repo.impl.version.VersionService) LoggerFactory(org.slf4j.LoggerFactory) NodeConstants(com.enonic.xp.repo.impl.node.NodeConstants) Segment(com.enonic.xp.blob.Segment) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) BlobKey(com.enonic.xp.blob.BlobKey) Branch(com.enonic.xp.branch.Branch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SegmentLevel(com.enonic.xp.blob.SegmentLevel) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) BlobStore(com.enonic.xp.blob.BlobStore) NodeService(com.enonic.xp.node.NodeService) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) ContextBuilder(com.enonic.xp.context.ContextBuilder) RangeFilter(com.enonic.xp.query.filter.RangeFilter) VersionIndexPath(com.enonic.xp.repo.impl.version.VersionIndexPath) VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) Logger(org.slf4j.Logger) IndexPath(com.enonic.xp.index.IndexPath) RepositorySegmentUtils(com.enonic.xp.repository.RepositorySegmentUtils) InternalContext(com.enonic.xp.repo.impl.InternalContext) Set(java.util.Set) ValueFactory(com.enonic.xp.data.ValueFactory) Instant(java.time.Instant) NodeId(com.enonic.xp.node.NodeId) VacuumListener(com.enonic.xp.vacuum.VacuumListener) OrderExpr(com.enonic.xp.query.expr.OrderExpr) List(java.util.List) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) VacuumTaskParams(com.enonic.xp.repo.impl.vacuum.VacuumTaskParams) Repository(com.enonic.xp.repository.Repository) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) ArrayList(java.util.ArrayList) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) BlobKey(com.enonic.xp.blob.BlobKey) HashSet(java.util.HashSet)

Aggregations

BlobKey (com.enonic.xp.blob.BlobKey)9 Test (org.junit.jupiter.api.Test)3 Segment (com.enonic.xp.blob.Segment)2 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)2 Path (java.nio.file.Path)2 BlobRecord (com.enonic.xp.blob.BlobRecord)1 BlobStore (com.enonic.xp.blob.BlobStore)1 BlobStoreException (com.enonic.xp.blob.BlobStoreException)1 SegmentLevel (com.enonic.xp.blob.SegmentLevel)1 Branch (com.enonic.xp.branch.Branch)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 ValueFactory (com.enonic.xp.data.ValueFactory)1 IndexPath (com.enonic.xp.index.IndexPath)1 Node (com.enonic.xp.node.Node)1 NodeId (com.enonic.xp.node.NodeId)1 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)1 NodeService (com.enonic.xp.node.NodeService)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 NodeVersionId (com.enonic.xp.node.NodeVersionId)1