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