Search in sources :

Example 11 with SegmentHandle

use of io.pravega.segmentstore.storage.SegmentHandle in project pravega by pravega.

the class RollingStorage method delete.

@Override
public void delete(SegmentHandle handle) throws StreamSegmentException {
    val h = asReadableHandle(handle);
    long traceId = LoggerHelpers.traceEnter(log, "delete", handle);
    SegmentHandle headerHandle = h.getHeaderHandle();
    if (headerHandle == null) {
        // Directly delete the only SegmentChunk, and bubble up any exceptions if it doesn't exist.
        val subHandle = this.baseStorage.openWrite(h.lastChunk().getName());
        try {
            this.baseStorage.delete(subHandle);
            h.lastChunk().markInexistent();
            h.markDeleted();
        } catch (StreamSegmentNotExistsException ex) {
            h.lastChunk().markInexistent();
            h.markDeleted();
            throw ex;
        }
    } else {
        // them, after which we delete all SegmentChunks and finally the header file.
        if (!h.isSealed()) {
            val writeHandle = h.isReadOnly() ? (RollingSegmentHandle) openWrite(handle.getSegmentName()) : h;
            seal(writeHandle);
        }
        deleteChunks(h, s -> true);
        try {
            this.baseStorage.delete(headerHandle);
            h.markDeleted();
        } catch (StreamSegmentNotExistsException ex) {
            h.markDeleted();
            throw ex;
        }
    }
    LoggerHelpers.traceLeave(log, "delete", traceId, handle);
}
Also used : lombok.val(lombok.val) SegmentHandle(io.pravega.segmentstore.storage.SegmentHandle) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)

Aggregations

SegmentHandle (io.pravega.segmentstore.storage.SegmentHandle)11 lombok.val (lombok.val)6 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 BadOffsetException (io.pravega.segmentstore.contracts.BadOffsetException)2 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)2 Storage (io.pravega.segmentstore.storage.Storage)2 Exceptions (io.pravega.common.Exceptions)1 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)1 StreamSegmentException (io.pravega.segmentstore.contracts.StreamSegmentException)1 StreamSegmentExistsException (io.pravega.segmentstore.contracts.StreamSegmentExistsException)1 StreamSegmentSealedException (io.pravega.segmentstore.contracts.StreamSegmentSealedException)1 StreamSegmentTruncatedException (io.pravega.segmentstore.contracts.StreamSegmentTruncatedException)1 StreamingException (io.pravega.segmentstore.contracts.StreamingException)1 ContainerMetadata (io.pravega.segmentstore.server.ContainerMetadata)1 DataCorruptionException (io.pravega.segmentstore.server.DataCorruptionException)1 EvictableMetadata (io.pravega.segmentstore.server.EvictableMetadata)1 MetadataBuilder (io.pravega.segmentstore.server.MetadataBuilder)1 SegmentMetadata (io.pravega.segmentstore.server.SegmentMetadata)1 ServiceListeners (io.pravega.segmentstore.server.ServiceListeners)1