Search in sources :

Example 26 with SegmentMetadata

use of io.pravega.segmentstore.server.SegmentMetadata in project pravega by pravega.

the class MetadataCleaner method evictUnusedSegments.

private CompletableFuture<Void> evictUnusedSegments(long lastSeqNo) {
    long traceId = LoggerHelpers.traceEnterWithContext(log, this.traceObjectId, "metadataCleanup", lastSeqNo);
    // Get candidates.
    Collection<SegmentMetadata> cleanupCandidates = this.metadata.getEvictionCandidates(lastSeqNo, this.config.getMaxConcurrentSegmentEvictionCount());
    // Serialize only those segments that are still alive (not deleted or merged - those will get removed anyway).
    val serializationTasks = cleanupCandidates.stream().filter(sm -> !sm.isDeleted() && !sm.isMerged()).map(sm -> this.metadataStore.updateSegmentInfo(sm, this.config.getSegmentMetadataExpiration())).collect(Collectors.toList());
    return Futures.allOf(serializationTasks).thenRunAsync(() -> {
        Collection<SegmentMetadata> evictedSegments = this.metadata.cleanup(cleanupCandidates, lastSeqNo);
        this.cleanupCallback.accept(evictedSegments);
        int evictedAttributes = this.metadata.cleanupExtendedAttributes(this.config.getMaxCachedExtendedAttributeCount(), lastSeqNo);
        LoggerHelpers.traceLeave(log, this.traceObjectId, "metadataCleanup", traceId, evictedSegments.size(), evictedAttributes);
    }, this.executor);
}
Also used : SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) lombok.val(lombok.val) LoggerHelpers(io.pravega.common.LoggerHelpers) Attributes(io.pravega.segmentstore.contracts.Attributes) NonNull(lombok.NonNull) Collection(java.util.Collection) lombok.val(lombok.val) CompletableFuture(java.util.concurrent.CompletableFuture) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) Collectors(java.util.stream.Collectors) CancellationToken(io.pravega.common.concurrent.CancellationToken) Objects(java.util.Objects) Consumer(java.util.function.Consumer) EvictableMetadata(io.pravega.segmentstore.server.EvictableMetadata) AtomicLong(java.util.concurrent.atomic.AtomicLong) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) Slf4j(lombok.extern.slf4j.Slf4j) AbstractThreadPoolService(io.pravega.common.concurrent.AbstractThreadPoolService) Duration(java.time.Duration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Futures(io.pravega.common.concurrent.Futures)

Example 27 with SegmentMetadata

use of io.pravega.segmentstore.server.SegmentMetadata in project pravega by pravega.

the class StreamSegmentContainer method deleteStreamSegment.

@Override
public CompletableFuture<Void> deleteStreamSegment(String streamSegmentName, Duration timeout) {
    ensureRunning();
    logRequest("deleteStreamSegment", streamSegmentName);
    this.metrics.deleteSegment();
    TimeoutTimer timer = new TimeoutTimer(timeout);
    long segmentId = this.metadata.getStreamSegmentId(streamSegmentName, false);
    SegmentMetadata toDelete = this.metadata.getStreamSegmentMetadata(segmentId);
    return this.metadataStore.deleteSegment(streamSegmentName, timer.getRemaining()).thenAccept(deleted -> {
        if (!deleted) {
            // No segment to delete, which likely means Segment does not exist.
            throw new CompletionException(new StreamSegmentNotExistsException(streamSegmentName));
        }
        if (toDelete != null) {
            // Notify any internal components that this Segment is no longer part of the metadata.
            notifyMetadataRemoved(Collections.singleton(toDelete));
        }
    });
}
Also used : UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) CompletionException(java.util.concurrent.CompletionException) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) TimeoutTimer(io.pravega.common.TimeoutTimer)

Example 28 with SegmentMetadata

use of io.pravega.segmentstore.server.SegmentMetadata in project pravega by pravega.

the class ContainerMetadataUpdateTransaction method getOrCreateSegmentUpdateTransaction.

/**
 * Gets an UpdateableSegmentMetadata for the given Segment. If already registered, it returns that instance,
 * otherwise it creates and records a new Segment metadata.
 */
private SegmentMetadataUpdateTransaction getOrCreateSegmentUpdateTransaction(String segmentName, long segmentId) {
    SegmentMetadataUpdateTransaction sm = tryGetSegmentUpdateTransaction(segmentId);
    if (sm == null) {
        SegmentMetadata baseSegmentMetadata = createSegmentMetadata(segmentName, segmentId);
        sm = new SegmentMetadataUpdateTransaction(baseSegmentMetadata, this.recoveryMode);
        this.segmentUpdates.put(segmentId, sm);
    }
    return sm;
}
Also used : UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) StreamSegmentMetadata(io.pravega.segmentstore.server.containers.StreamSegmentMetadata)

Example 29 with SegmentMetadata

use of io.pravega.segmentstore.server.SegmentMetadata in project pravega by pravega.

the class ContainerMetadataUpdateTransaction method copySegmentMetadata.

private void copySegmentMetadata(Collection<StreamSegmentMetadata> newSegments, UpdateableContainerMetadata target) {
    for (SegmentMetadata newMetadata : newSegments) {
        // Update real metadata with all the information from the new metadata.
        UpdateableSegmentMetadata existingMetadata = target.mapStreamSegmentId(newMetadata.getName(), newMetadata.getId());
        existingMetadata.copyFrom(newMetadata);
    }
}
Also used : UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) StreamSegmentMetadata(io.pravega.segmentstore.server.containers.StreamSegmentMetadata) UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata)

Example 30 with SegmentMetadata

use of io.pravega.segmentstore.server.SegmentMetadata in project pravega by pravega.

the class ContainerMetadataUpdateTransaction method tryGetSegmentUpdateTransaction.

/**
 * Attempts to get a SegmentMetadataUpdateTransaction for an existing or new Segment.
 *
 * @param segmentId The Id of the Segment to retrieve.
 * @return An instance of SegmentMetadataUpdateTransaction, or null if no such segment exists.
 */
private SegmentMetadataUpdateTransaction tryGetSegmentUpdateTransaction(long segmentId) {
    SegmentMetadataUpdateTransaction sm = this.segmentUpdates.getOrDefault(segmentId, null);
    if (sm == null) {
        SegmentMetadata baseSegmentMetadata = this.baseMetadata.getStreamSegmentMetadata(segmentId);
        if (baseSegmentMetadata == null) {
            baseSegmentMetadata = this.newSegments.getOrDefault(segmentId, null);
        }
        if (baseSegmentMetadata != null) {
            sm = new SegmentMetadataUpdateTransaction(baseSegmentMetadata, this.recoveryMode);
            this.segmentUpdates.put(segmentId, sm);
        }
    }
    return sm;
}
Also used : UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) StreamSegmentMetadata(io.pravega.segmentstore.server.containers.StreamSegmentMetadata)

Aggregations

SegmentMetadata (io.pravega.segmentstore.server.SegmentMetadata)58 UpdateableSegmentMetadata (io.pravega.segmentstore.server.UpdateableSegmentMetadata)41 lombok.val (lombok.val)25 ArrayList (java.util.ArrayList)24 Test (org.junit.Test)23 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)20 Duration (java.time.Duration)18 HashMap (java.util.HashMap)18 CompletableFuture (java.util.concurrent.CompletableFuture)18 Futures (io.pravega.common.concurrent.Futures)17 Collectors (java.util.stream.Collectors)17 Cleanup (lombok.Cleanup)17 Exceptions (io.pravega.common.Exceptions)15 StreamSegmentMetadata (io.pravega.segmentstore.server.containers.StreamSegmentMetadata)15 AtomicLong (java.util.concurrent.atomic.AtomicLong)15 UpdateableContainerMetadata (io.pravega.segmentstore.server.UpdateableContainerMetadata)14 Collection (java.util.Collection)14 Map (java.util.Map)14 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)13 MetadataBuilder (io.pravega.segmentstore.server.MetadataBuilder)13