Class ReferenceCountedSegmentProvider

java.lang.Object
org.apache.druid.segment.ReferenceCountingCloseableObject<Segment>
org.apache.druid.segment.ReferenceCountedSegmentProvider
All Implemented Interfaces:
Closeable, AutoCloseable, ReferenceCountedObjectProvider<Segment>

public class ReferenceCountedSegmentProvider extends ReferenceCountingCloseableObject<Segment> implements ReferenceCountedObjectProvider<Segment>
Helper object to assist in managing Segment storage lifecycle. Provides access to the Segment tracked with reference counting, releasing the reference on close. Closing this provider closes the underlying Segment once all references are returned, ensuring that a segment cannot be dropped while it is actively being used.
  • Constructor Details

    • ReferenceCountedSegmentProvider

      public ReferenceCountedSegmentProvider(Segment baseSegment)
  • Method Details

    • of

      public static ReferenceCountedSegmentProvider of(Segment segment)
    • unmanaged

      public static Optional<Segment> unmanaged(Segment segment)
      Make a wrapper for a Segment that does not close the underlying segment on close
    • wrapCloseable

      public static Optional<Segment> wrapCloseable(ReferenceCountedSegmentProvider.LeafReference segment, Closeable closeable)
    • getBaseSegment

      @Nullable public Segment getBaseSegment()
    • acquireReference

      public Optional<Segment> acquireReference()
      Description copied from interface: ReferenceCountedObjectProvider
      This method increments a reference count and provides a Closeable that decrements the reference count when closed. The object returned by this method may or may not be thread-safe, it is best to check with the implementation.

      IMPORTANT NOTE: to fulfill the contract of this method, implementors must return a closeable to indicate that the reference can be acquired, even if there is nothing to close. Implementors should ideally avoid allowing this method to throw exceptions, but callers are responsible for closing the returned object should any operations on it throw exceptions.

      For callers: if this method returns non-empty, IT MUST BE CLOSED, else reference counts can potentially leak.

      Specified by:
      acquireReference in interface ReferenceCountedObjectProvider<Segment>