CompletableFuture<Boolean> deleteSegment(String segmentName, Duration timeout) {
        long traceId = LoggerHelpers.traceEnterWithContext(log, traceObjectId, "deleteSegment", segmentName);
        TimeoutTimer timer = new TimeoutTimer(timeout);

        // Find the Segment's Id.
        long segmentId = this.connector.containerMetadata.getStreamSegmentId(segmentName, true);
        CompletableFuture<Void> deleteSegment;
        if (isValidSegmentId(segmentId)) {
            // This segment is currently mapped in the ContainerMetadata.
            if (this.connector.containerMetadata.getStreamSegmentMetadata(segmentId).isDeleted()) {
                // ... but it is marked as Deleted, so nothing more we can do here.
                deleteSegment = CompletableFuture.completedFuture(null);
            } else {
                // Queue it up for deletion. This ensures that any component that is actively using it will be notified.
                deleteSegment = this.connector.getLazyDeleteSegment().apply(segmentId, timer.getRemaining());
            }
        } else {
            // This segment is not currently mapped in the ContainerMetadata. As such, it is safe to delete it directly.
            deleteSegment = this.connector.getDirectDeleteSegment().apply(segmentName, timer.getRemaining());
        }

        // It is OK if the previous action indicated the Segment was deleted. We still need to make sure that any traces
        // of this Segment are cleared from the Metadata Store as this invocation may be a retry of a previous partially
        // executed operation (where we only managed to delete the Segment, but not clear the Metadata).
        val result = Futures
                .exceptionallyExpecting(deleteSegment, ex -> ex instanceof StreamSegmentNotExistsException, null)
                .thenComposeAsync(ignored -> clearSegmentInfo(segmentName, timer.getRemaining()), this.executor);
        if (log.isTraceEnabled()) {
            deleteSegment.thenAccept(v -> LoggerHelpers.traceLeave(log, traceObjectId, "deleteSegment", traceId, segmentName));
        }

        return result;
    }
CompletableFuture < Boolean > deleteSegment ( String segmentName , Duration timeout ) { long traceId = LoggerHelpers . traceEnterWithContext ( log , traceObjectId , "deleteSegment" , segmentName ) ; TimeoutTimer timer = new TimeoutTimer ( timeout ) ; long segmentId = this . connector . containerMetadata . getStreamSegmentId ( segmentName , true ) ; CompletableFuture < Void > deleteSegment ; if ( isValidSegmentId ( segmentId ) ) { if ( this . connector . containerMetadata . getStreamSegmentMetadata ( segmentId ) . isDeleted ( ) ) { deleteSegment = CompletableFuture . completedFuture ( null ) ; } else { deleteSegment = this . connector . getLazyDeleteSegment ( ) . apply ( segmentId , timer . getRemaining ( ) ) ; } } else { deleteSegment = this . connector . getDirectDeleteSegment ( ) . apply ( segmentName , timer . getRemaining ( ) ) ; } val result = Futures . exceptionallyExpecting ( deleteSegment , ex -> ex instanceof StreamSegmentNotExistsException , null ) . thenComposeAsync ( ignored -> clearSegmentInfo ( segmentName , timer . getRemaining ( ) ) , this . executor ) ; if ( log . isTraceEnabled ( ) ) { deleteSegment . thenAccept ( v -> LoggerHelpers . traceLeave ( log , traceObjectId , "deleteSegment" , traceId , segmentName ) ) ; } return result ; }
Deletes a Segment and any associated information from the Metadata Store.
Notes:
- This method removes both the Segment and its Metadata Store entries.
- {@link #clearSegmentInfo} only removes Metadata Store entries.

This operation is made of multiple steps and is restart-able. If it was only able to execute partially before being
interrupted (by an unexpected exception or system crash), a reinvocation should be able to pick up from where it
left off previously. A partial invocation may leave the Segment in an undefined state, so it is highly recommended
that such an interrupted call be reinvoked until successful.

@param segmentName The case-sensitive Segment Name.
@param timeout     Timeout for the operation.
@return A CompletableFuture that, when completed normally, will contain a Boolean indicating whether  the Segment
has been deleted (true means there was a Segment to delete, false means there was no segment to delete). If the
operation failed, this will contain the exception that caused the failure.