Package org.apache.druid.segment
Class ReferenceCountingSegment
- java.lang.Object
-
- org.apache.druid.segment.ReferenceCountingCloseableObject<Segment>
-
- org.apache.druid.segment.ReferenceCountingSegment
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ReferenceCountedObject,Segment,SegmentReference,Overshadowable<ReferenceCountingSegment>
public class ReferenceCountingSegment extends ReferenceCountingCloseableObject<Segment> implements SegmentReference, Overshadowable<ReferenceCountingSegment>
Segmentthat is also aReferenceCountingSegment, allowing query engines that operate directly on segments to track references so that dropping aSegmentcan be done safely to ensure there are no in-flight queries. Extensions can extend this class for populatingVersionedIntervalTimelinewith a custom implementation through SegmentLoader.
-
-
Field Summary
-
Fields inherited from class org.apache.druid.segment.ReferenceCountingCloseableObject
baseObject, referents
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedReferenceCountingSegment(Segment baseSegment, int startRootPartitionId, int endRootPartitionId, short minorVersion, short atomicUpdateGroupSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<Closeable>acquireReferences()This method is expected to increment a reference count and provide aCloseablethat decrements the reference count when closed.<T> Tas(Class<T> clazz)Request an implementation of a particular interface.QueryableIndexasQueryableIndex()StorageAdapterasStorageAdapter()shortgetAtomicUpdateGroupSize()Return the size of atomicUpdateGroup.SegmentgetBaseSegment()org.joda.time.IntervalgetDataInterval()intgetEndRootPartitionId()See doc ofOvershadowable.getStartRootPartitionId().SegmentIdgetId()shortgetMinorVersion()intgetStartRootPartitionId()All overshadowables have root partition range.StringgetVersion()booleanovershadows(ReferenceCountingSegment other)Returns true if this overshadowable overshadows the other.static ReferenceCountingSegmentwrapRootGenerationSegment(Segment baseSegment)static ReferenceCountingSegmentwrapSegment(Segment baseSegment, ShardSpec shardSpec)-
Methods inherited from class org.apache.druid.segment.ReferenceCountingCloseableObject
close, decrement, decrementOnceCloseable, getNumReferences, increment, incrementReferenceAndDecrementOnceCloseable, isClosed
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.druid.timeline.Overshadowable
containsRootPartition, hasData
-
-
-
-
Constructor Detail
-
ReferenceCountingSegment
protected ReferenceCountingSegment(Segment baseSegment, int startRootPartitionId, int endRootPartitionId, short minorVersion, short atomicUpdateGroupSize)
-
-
Method Detail
-
wrapRootGenerationSegment
public static ReferenceCountingSegment wrapRootGenerationSegment(Segment baseSegment)
-
wrapSegment
public static ReferenceCountingSegment wrapSegment(Segment baseSegment, ShardSpec shardSpec)
-
getDataInterval
@Nullable public org.joda.time.Interval getDataInterval()
- Specified by:
getDataIntervalin interfaceSegment
-
asQueryableIndex
@Nullable public QueryableIndex asQueryableIndex()
- Specified by:
asQueryableIndexin interfaceSegment
-
asStorageAdapter
@Nullable public StorageAdapter asStorageAdapter()
- Specified by:
asStorageAdapterin interfaceSegment
-
overshadows
public boolean overshadows(ReferenceCountingSegment other)
Description copied from interface:OvershadowableReturns true if this overshadowable overshadows the other.- Specified by:
overshadowsin interfaceOvershadowable<ReferenceCountingSegment>
-
getStartRootPartitionId
public int getStartRootPartitionId()
Description copied from interface:OvershadowableAll overshadowables have root partition range. First-generation overshadowables have (partitionId, partitionId + 1) as their root partition range. Non-first-generation overshadowables are the overshadowables that overwrite first or non-first generation overshadowables, and they have the merged root partition range of all overwritten first-generation overshadowables. Note that first-generation overshadowables can be overwritten by a single non-first-generation overshadowable if they have consecutive partitionId. Non-first-generation overshadowables can be overwritten by another if their root partition ranges are consecutive.- Specified by:
getStartRootPartitionIdin interfaceOvershadowable<ReferenceCountingSegment>
-
getEndRootPartitionId
public int getEndRootPartitionId()
Description copied from interface:OvershadowableSee doc ofOvershadowable.getStartRootPartitionId().- Specified by:
getEndRootPartitionIdin interfaceOvershadowable<ReferenceCountingSegment>
-
getVersion
public String getVersion()
- Specified by:
getVersionin interfaceOvershadowable<ReferenceCountingSegment>
-
getMinorVersion
public short getMinorVersion()
- Specified by:
getMinorVersionin interfaceOvershadowable<ReferenceCountingSegment>
-
getAtomicUpdateGroupSize
public short getAtomicUpdateGroupSize()
Description copied from interface:OvershadowableReturn the size of atomicUpdateGroup. An atomicUpdateGroup is a set of segments which should be updated all together atomically inVersionedIntervalTimeline.- Specified by:
getAtomicUpdateGroupSizein interfaceOvershadowable<ReferenceCountingSegment>
-
acquireReferences
public Optional<Closeable> acquireReferences()
Description copied from interface:ReferenceCountedObjectThis method is expected to increment a reference count and provide aCloseablethat decrements the reference count when closed. This is likely just a wrapper aroundReferenceCountingCloseableObject.incrementReferenceAndDecrementOnceCloseable(), but may also include any other associated references which should be incremented when this method is called, and decremented/released by the closeable. 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 avoid allowing this method or theCloseableit creates to throw exceptions. For callers: if this method returns non-empty, IT MUST BE CLOSED, else reference counts can potentially leak.- Specified by:
acquireReferencesin interfaceReferenceCountedObject
-
as
public <T> T as(Class<T> clazz)
Description copied from interface:SegmentRequest an implementation of a particular interface. If the passed-in interface isQueryableIndexorStorageAdapter, then this method behaves identically toSegment.asQueryableIndex()orSegment.asStorageAdapter(). Other interfaces are only expected to be requested by callers that have specific knowledge of extra features provided by specific segment types. For example, an extension might provide a custom Segment type that can offer both StorageAdapter and some new interface. That extension can also offer a Query that uses that new interface. Implementations which accept classes other thanQueryableIndexorStorageAdapterare limited to using those classes within the extension. This means that one extension cannot rely on the `Segment.as` behavior of another extension.
-
-