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