Package org.apache.druid.server
Class SegmentManager
- java.lang.Object
-
- org.apache.druid.server.SegmentManager
-
public class SegmentManager extends Object
This class is responsible for managing data sources and their states like timeline, total segment size, and number of segments. All public methods of this class must be thread-safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSegmentManager.DataSourceStateRepresent the state of a data source including the timeline, total segment size, and number of segments.
-
Constructor Summary
Constructors Constructor Description SegmentManager(SegmentLoader segmentLoader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddropSegment(org.apache.druid.timeline.DataSegment segment)Map<String,Long>getAverageRowCountForDatasource()Map<String,Long>getDataSourceCounts()Returns a map of dataSource to the number of segments managed by this segmentManager.Set<String>getDataSourceNames()Map<String,Long>getDataSourceSizes()Returns a map of dataSource to the total byte size of segments managed by this segmentManager.Optional<Stream<org.apache.druid.segment.join.table.ReferenceCountingIndexedTable>>getIndexedTables(org.apache.druid.query.planning.DataSourceAnalysis analysis)Returns the collection ofIndexedTablefor the entire timeline (since join conditions do not currently consider the queries intervals), if the timeline exists for each of its segments that are joinable.Map<String,SegmentRowCountDistribution>getRowCountDistribution()Optional<org.apache.druid.timeline.VersionedIntervalTimeline<String,org.apache.druid.segment.ReferenceCountingSegment>>getTimeline(org.apache.druid.query.planning.DataSourceAnalysis analysis)Returns the timeline for a datasource, if it exists.booleanhasIndexedTables(String dataSourceName)booleanloadSegment(org.apache.druid.timeline.DataSegment segment, boolean lazy, org.apache.druid.segment.SegmentLazyLoadFailCallback loadFailed)booleanloadSegment(org.apache.druid.timeline.DataSegment segment, boolean lazy, org.apache.druid.segment.SegmentLazyLoadFailCallback loadFailed, ExecutorService loadSegmentIntoPageCacheExec)Load a single segment.
-
-
-
Constructor Detail
-
SegmentManager
@Inject public SegmentManager(SegmentLoader segmentLoader)
-
-
Method Detail
-
getDataSourceSizes
public Map<String,Long> getDataSourceSizes()
Returns a map of dataSource to the total byte size of segments managed by this segmentManager. This method should be used carefully because the returned map might be different from the actual data source states.- Returns:
- a map of dataSources and their total byte sizes
-
getRowCountDistribution
public Map<String,SegmentRowCountDistribution> getRowCountDistribution()
-
getDataSourceCounts
public Map<String,Long> getDataSourceCounts()
Returns a map of dataSource to the number of segments managed by this segmentManager. This method should be carefully because the returned map might be different from the actual data source states.- Returns:
- a map of dataSources and number of segments
-
getTimeline
public Optional<org.apache.druid.timeline.VersionedIntervalTimeline<String,org.apache.druid.segment.ReferenceCountingSegment>> getTimeline(org.apache.druid.query.planning.DataSourceAnalysis analysis)
Returns the timeline for a datasource, if it exists. The analysis object passed in must represent a scan-based datasource of a single table.- Parameters:
analysis- data source analysis information- Returns:
- timeline, if it exists
- Throws:
IllegalStateException- if 'analysis' does not represent a scan-based datasource of a single table
-
getIndexedTables
public Optional<Stream<org.apache.druid.segment.join.table.ReferenceCountingIndexedTable>> getIndexedTables(org.apache.druid.query.planning.DataSourceAnalysis analysis)
Returns the collection ofIndexedTablefor the entire timeline (since join conditions do not currently consider the queries intervals), if the timeline exists for each of its segments that are joinable.
-
hasIndexedTables
public boolean hasIndexedTables(String dataSourceName)
-
loadSegment
public boolean loadSegment(org.apache.druid.timeline.DataSegment segment, boolean lazy, org.apache.druid.segment.SegmentLazyLoadFailCallback loadFailed) throws org.apache.druid.segment.loading.SegmentLoadingException- Throws:
org.apache.druid.segment.loading.SegmentLoadingException
-
loadSegment
public boolean loadSegment(org.apache.druid.timeline.DataSegment segment, boolean lazy, org.apache.druid.segment.SegmentLazyLoadFailCallback loadFailed, ExecutorService loadSegmentIntoPageCacheExec) throws org.apache.druid.segment.loading.SegmentLoadingExceptionLoad a single segment.- Parameters:
segment- segment to loadlazy- whether to lazy load columns metadataloadFailed- callBack to execute when segment lazy load failedloadSegmentIntoPageCacheExec- If null is specified, the default thread pool in segment loader to load segments into page cache on download will be used. You can specify a dedicated thread pool of larger capacity when this function is called during historical process bootstrap to speed up initial loading.- Returns:
- true if the segment was newly loaded, false if it was already loaded
- Throws:
org.apache.druid.segment.loading.SegmentLoadingException- if the segment cannot be loaded
-
dropSegment
public void dropSegment(org.apache.druid.timeline.DataSegment segment)
-
-