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>
Segment
that is also aReferenceCountingSegment
, allowing query engines that operate directly on segments to track references so that dropping aSegment
can be done safely to ensure there are no in-flight queries. Extensions can extend this class for populatingVersionedIntervalTimeline
with a custom implementation through SegmentLoader.
-
-
Field Summary
-
Fields inherited from class org.apache.druid.segment.ReferenceCountingCloseableObject
baseObject, referents
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ReferenceCountingSegment(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 aCloseable
that decrements the reference count when closed.<T> T
as(Class<T> clazz)
Request an implementation of a particular interface.QueryableIndex
asQueryableIndex()
StorageAdapter
asStorageAdapter()
short
getAtomicUpdateGroupSize()
Return the size of atomicUpdateGroup.Segment
getBaseSegment()
org.joda.time.Interval
getDataInterval()
int
getEndRootPartitionId()
See doc ofOvershadowable.getStartRootPartitionId()
.SegmentId
getId()
short
getMinorVersion()
int
getStartRootPartitionId()
All overshadowables have root partition range.String
getVersion()
boolean
overshadows(ReferenceCountingSegment other)
Returns true if this overshadowable overshadows the other.static ReferenceCountingSegment
wrapRootGenerationSegment(Segment baseSegment)
static ReferenceCountingSegment
wrapSegment(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:
getDataInterval
in interfaceSegment
-
asQueryableIndex
@Nullable public QueryableIndex asQueryableIndex()
- Specified by:
asQueryableIndex
in interfaceSegment
-
asStorageAdapter
@Nullable public StorageAdapter asStorageAdapter()
- Specified by:
asStorageAdapter
in interfaceSegment
-
overshadows
public boolean overshadows(ReferenceCountingSegment other)
Description copied from interface:Overshadowable
Returns true if this overshadowable overshadows the other.- Specified by:
overshadows
in interfaceOvershadowable<ReferenceCountingSegment>
-
getStartRootPartitionId
public int getStartRootPartitionId()
Description copied from interface:Overshadowable
All 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:
getStartRootPartitionId
in interfaceOvershadowable<ReferenceCountingSegment>
-
getEndRootPartitionId
public int getEndRootPartitionId()
Description copied from interface:Overshadowable
See doc ofOvershadowable.getStartRootPartitionId()
.- Specified by:
getEndRootPartitionId
in interfaceOvershadowable<ReferenceCountingSegment>
-
getVersion
public String getVersion()
- Specified by:
getVersion
in interfaceOvershadowable<ReferenceCountingSegment>
-
getMinorVersion
public short getMinorVersion()
- Specified by:
getMinorVersion
in interfaceOvershadowable<ReferenceCountingSegment>
-
getAtomicUpdateGroupSize
public short getAtomicUpdateGroupSize()
Description copied from interface:Overshadowable
Return the size of atomicUpdateGroup. An atomicUpdateGroup is a set of segments which should be updated all together atomically inVersionedIntervalTimeline
.- Specified by:
getAtomicUpdateGroupSize
in interfaceOvershadowable<ReferenceCountingSegment>
-
acquireReferences
public Optional<Closeable> acquireReferences()
Description copied from interface:ReferenceCountedObject
This method is expected to increment a reference count and provide aCloseable
that 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 theCloseable
it creates to throw exceptions. For callers: if this method returns non-empty, IT MUST BE CLOSED, else reference counts can potentially leak.- Specified by:
acquireReferences
in interfaceReferenceCountedObject
-
as
public <T> T as(Class<T> clazz)
Description copied from interface:Segment
Request an implementation of a particular interface. If the passed-in interface isQueryableIndex
orStorageAdapter
, 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 thanQueryableIndex
orStorageAdapter
are limited to using those classes within the extension. This means that one extension cannot rely on the `Segment.as` behavior of another extension.
-
-