Package org.apache.druid.metadata
Class SqlSegmentsMetadataManager
- java.lang.Object
-
- org.apache.druid.metadata.SqlSegmentsMetadataManager
-
- All Implemented Interfaces:
SegmentsMetadataManager
public class SqlSegmentsMetadataManager extends Object implements SegmentsMetadataManager
-
-
Constructor Summary
Constructors Constructor Description SqlSegmentsMetadataManager(com.fasterxml.jackson.databind.ObjectMapper jsonMapper, com.google.common.base.Supplier<SegmentsMetadataManagerConfig> config, com.google.common.base.Supplier<org.apache.druid.metadata.MetadataStorageTablesConfig> dbTables, SQLMetadataConnector connector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<ImmutableDruidDataSource>getImmutableDataSourcesWithAllUsedSegments()Returns a set ofImmutableDruidDataSourceobjects containing information about all used segments.ImmutableDruidDataSourcegetImmutableDataSourceWithUsedSegments(String dataSourceName)If there are used segments belonging to the given data source this method returns them as anImmutableDruidDataSourceobject.DataSourcesSnapshotgetSnapshotOfDataSourcesWithAllUsedSegments()Returns a snapshot of DruidDataSources and overshadowed segmentsList<org.joda.time.Interval>getUnusedSegmentIntervals(String dataSource, org.joda.time.DateTime minStartTime, org.joda.time.DateTime maxEndTime, int limit, org.joda.time.DateTime maxUsedStatusLastUpdatedTime)Returns a list of up tolimitunused segment intervals for the specified datasource.booleanisPollingDatabasePeriodically()Iterable<DataSegmentPlus>iterateAllUnusedSegmentsForDatasource(String datasource, org.joda.time.Interval interval, Integer limit, String lastSegmentId, SortOrder sortOrder)Retrieves segments and their associated metadata for a given datasource that are marked unused and that are *fully contained by* an optionally specified interval.com.google.common.base.Optional<Iterable<org.apache.druid.timeline.DataSegment>>iterateAllUsedNonOvershadowedSegmentsForDatasourceInterval(String datasource, org.joda.time.Interval interval, boolean requiresLatest)Returns an iterable to go over all used and non-overshadowed segments of given data sources over given interval.Iterable<org.apache.druid.timeline.DataSegment>iterateAllUsedSegments()Returns an iterable to go over all segments in all data sources.intmarkAsUnusedAllSegmentsInDataSource(String dataSource)Returns the number of segment entries in the database whose state was changed as the result of this call (that is, the segments were marked as unused).intmarkAsUnusedSegmentsInInterval(String dataSourceName, org.joda.time.Interval interval)intmarkAsUsedAllNonOvershadowedSegmentsInDataSource(String dataSource)Returns the number of segment entries in the database whose state was changed as the result of this call (that is, the segments were marked as used).intmarkAsUsedNonOvershadowedSegments(String dataSource, Set<String> segmentIds)intmarkAsUsedNonOvershadowedSegmentsInInterval(String dataSource, org.joda.time.Interval interval)booleanmarkSegmentAsUnused(org.apache.druid.timeline.SegmentId segmentId)This method does not updatedataSourcesSnapshot, see the comments indoPoll()about snapshot update.booleanmarkSegmentAsUsed(String segmentId)Returns true if the state of the segment entry is changed in the database as the result of this call (that is, the segment was marked as used), false otherwise.intmarkSegmentsAsUnused(Set<org.apache.druid.timeline.SegmentId> segmentIds)voidpoll()voidpopulateUsedFlagLastUpdatedAsync()Populates used_status_last_updated column in the segments table iteratively until there are no segments with a NULL value for that column.Set<String>retrieveAllDataSourceNames()Retrieves all data source names for which there are segment in the database, regardless of whether those segments are used or not.voidstart()Don't confuse this method withstartPollingDatabasePeriodically().voidstartPollingDatabasePeriodically()voidstop()Don't confuse this method withstopPollingDatabasePeriodically().voidstopAsyncUsedFlagLastUpdatedUpdate()voidstopPollingDatabasePeriodically()
-
-
-
Constructor Detail
-
SqlSegmentsMetadataManager
@Inject public SqlSegmentsMetadataManager(com.fasterxml.jackson.databind.ObjectMapper jsonMapper, com.google.common.base.Supplier<SegmentsMetadataManagerConfig> config, com.google.common.base.Supplier<org.apache.druid.metadata.MetadataStorageTablesConfig> dbTables, SQLMetadataConnector connector)
-
-
Method Detail
-
start
public void start()
Don't confuse this method withstartPollingDatabasePeriodically(). This is a lifecycle starting method to be executed just once for an instance of SqlSegmentsMetadataManager.
-
stop
public void stop()
Don't confuse this method withstopPollingDatabasePeriodically(). This is a lifecycle stopping method to be executed just once for an instance of SqlSegmentsMetadataManager.
-
startPollingDatabasePeriodically
public void startPollingDatabasePeriodically()
- Specified by:
startPollingDatabasePeriodicallyin interfaceSegmentsMetadataManager
-
stopAsyncUsedFlagLastUpdatedUpdate
public void stopAsyncUsedFlagLastUpdatedUpdate()
- Specified by:
stopAsyncUsedFlagLastUpdatedUpdatein interfaceSegmentsMetadataManager
-
populateUsedFlagLastUpdatedAsync
public void populateUsedFlagLastUpdatedAsync()
Description copied from interface:SegmentsMetadataManagerPopulates used_status_last_updated column in the segments table iteratively until there are no segments with a NULL value for that column.- Specified by:
populateUsedFlagLastUpdatedAsyncin interfaceSegmentsMetadataManager
-
isPollingDatabasePeriodically
public boolean isPollingDatabasePeriodically()
- Specified by:
isPollingDatabasePeriodicallyin interfaceSegmentsMetadataManager
-
stopPollingDatabasePeriodically
public void stopPollingDatabasePeriodically()
- Specified by:
stopPollingDatabasePeriodicallyin interfaceSegmentsMetadataManager
-
markSegmentAsUsed
public boolean markSegmentAsUsed(String segmentId)
Description copied from interface:SegmentsMetadataManagerReturns true if the state of the segment entry is changed in the database as the result of this call (that is, the segment was marked as used), false otherwise. If the call results in a database error, an exception is relayed to the caller.- Specified by:
markSegmentAsUsedin interfaceSegmentsMetadataManager
-
markAsUsedAllNonOvershadowedSegmentsInDataSource
public int markAsUsedAllNonOvershadowedSegmentsInDataSource(String dataSource)
Description copied from interface:SegmentsMetadataManagerReturns the number of segment entries in the database whose state was changed as the result of this call (that is, the segments were marked as used). If the call results in a database error, an exception is relayed to the caller.- Specified by:
markAsUsedAllNonOvershadowedSegmentsInDataSourcein interfaceSegmentsMetadataManager
-
markAsUsedNonOvershadowedSegmentsInInterval
public int markAsUsedNonOvershadowedSegmentsInInterval(String dataSource, org.joda.time.Interval interval)
- Specified by:
markAsUsedNonOvershadowedSegmentsInIntervalin interfaceSegmentsMetadataManager
-
markAsUsedNonOvershadowedSegments
public int markAsUsedNonOvershadowedSegments(String dataSource, Set<String> segmentIds) throws UnknownSegmentIdsException
- Specified by:
markAsUsedNonOvershadowedSegmentsin interfaceSegmentsMetadataManager- Throws:
UnknownSegmentIdsException
-
markAsUnusedAllSegmentsInDataSource
public int markAsUnusedAllSegmentsInDataSource(String dataSource)
Description copied from interface:SegmentsMetadataManagerReturns the number of segment entries in the database whose state was changed as the result of this call (that is, the segments were marked as unused). If the call results in a database error, an exception is relayed to the caller.- Specified by:
markAsUnusedAllSegmentsInDataSourcein interfaceSegmentsMetadataManager
-
markSegmentAsUnused
public boolean markSegmentAsUnused(org.apache.druid.timeline.SegmentId segmentId)
This method does not updatedataSourcesSnapshot, see the comments indoPoll()about snapshot update. The update of the segment's state will be reflected after the nextSqlSegmentsMetadataManager.DatabasePoll.- Specified by:
markSegmentAsUnusedin interfaceSegmentsMetadataManager
-
markSegmentsAsUnused
public int markSegmentsAsUnused(Set<org.apache.druid.timeline.SegmentId> segmentIds)
- Specified by:
markSegmentsAsUnusedin interfaceSegmentsMetadataManager
-
markAsUnusedSegmentsInInterval
public int markAsUnusedSegmentsInInterval(String dataSourceName, org.joda.time.Interval interval)
- Specified by:
markAsUnusedSegmentsInIntervalin interfaceSegmentsMetadataManager
-
getImmutableDataSourceWithUsedSegments
@Nullable public ImmutableDruidDataSource getImmutableDataSourceWithUsedSegments(String dataSourceName)
Description copied from interface:SegmentsMetadataManagerIf there are used segments belonging to the given data source this method returns them as anImmutableDruidDataSourceobject. If there are no used segments belonging to the given data source this method returns null.- Specified by:
getImmutableDataSourceWithUsedSegmentsin interfaceSegmentsMetadataManager
-
getImmutableDataSourcesWithAllUsedSegments
public Collection<ImmutableDruidDataSource> getImmutableDataSourcesWithAllUsedSegments()
Description copied from interface:SegmentsMetadataManagerReturns a set ofImmutableDruidDataSourceobjects containing information about all used segments.ImmutableDruidDataSourceobjects in the returned collection are unique. If there are no used segments, this method returns an empty collection.- Specified by:
getImmutableDataSourcesWithAllUsedSegmentsin interfaceSegmentsMetadataManager
-
getSnapshotOfDataSourcesWithAllUsedSegments
public DataSourcesSnapshot getSnapshotOfDataSourcesWithAllUsedSegments()
Description copied from interface:SegmentsMetadataManagerReturns a snapshot of DruidDataSources and overshadowed segments- Specified by:
getSnapshotOfDataSourcesWithAllUsedSegmentsin interfaceSegmentsMetadataManager
-
iterateAllUsedSegments
public Iterable<org.apache.druid.timeline.DataSegment> iterateAllUsedSegments()
Description copied from interface:SegmentsMetadataManagerReturns an iterable to go over all segments in all data sources. The order in which segments are iterated is unspecified. Note: the iteration may not be as trivially cheap as, for example, iteration over an ArrayList. Try (to some reasonable extent) to organize the code so that it iterates the returned iterable only once rather than several times.- Specified by:
iterateAllUsedSegmentsin interfaceSegmentsMetadataManager
-
iterateAllUsedNonOvershadowedSegmentsForDatasourceInterval
public com.google.common.base.Optional<Iterable<org.apache.druid.timeline.DataSegment>> iterateAllUsedNonOvershadowedSegmentsForDatasourceInterval(String datasource, org.joda.time.Interval interval, boolean requiresLatest)
Description copied from interface:SegmentsMetadataManagerReturns an iterable to go over all used and non-overshadowed segments of given data sources over given interval. The order in which segments are iterated is unspecified. Note: the iteration may not be as trivially cheap as, for example, iteration over an ArrayList. Try (to some reasonable extent) to organize the code so that it iterates the returned iterable only once rather than several times. If {@param requiresLatest} is true then a force metadatastore poll will be triggered. This can cause a longer response time but will ensure that the latest segment information (at the time this method is called) is returned. If {@param requiresLatest} is false then segment information from stale snapshot of up to the last periodic poll periodperiodicPollDelaywill be used.- Specified by:
iterateAllUsedNonOvershadowedSegmentsForDatasourceIntervalin interfaceSegmentsMetadataManager
-
iterateAllUnusedSegmentsForDatasource
public Iterable<DataSegmentPlus> iterateAllUnusedSegmentsForDatasource(String datasource, @Nullable org.joda.time.Interval interval, @Nullable Integer limit, @Nullable String lastSegmentId, @Nullable SortOrder sortOrder)
Retrieves segments and their associated metadata for a given datasource that are marked unused and that are *fully contained by* an optionally specified interval. If the interval specified is null, this method will retrieve all unused segments. This call does not return any information about realtime segments.- Specified by:
iterateAllUnusedSegmentsForDatasourcein interfaceSegmentsMetadataManager- Parameters:
datasource- The name of the datasourceinterval- an optional interval to search over.limit- an optional maximum number of results to return. If none is specified, the results are not limited.lastSegmentId- an optional last segment id from which to search for results. All segments returned are > this segment lexigraphically if sortOrder is null orSortOrder.ASC, or < this segment lexigraphically if sortOrder isSortOrder.DESC. If none is specified, no such filter is used.sortOrder- an optional order with which to return the matching segments by id, start time, end time. If none is specified, the order of the results is not guarenteed. Returns an iterable.
-
retrieveAllDataSourceNames
public Set<String> retrieveAllDataSourceNames()
Description copied from interface:SegmentsMetadataManagerRetrieves all data source names for which there are segment in the database, regardless of whether those segments are used or not. If there are no segments in the database, returns an empty set. Performance warning: this method makes a query into the database. This method might return a different set of data source names than may be observed viaSegmentsMetadataManager.getImmutableDataSourcesWithAllUsedSegments()method. This method will include a data source name even if there are no used segments belonging to it, whileSegmentsMetadataManager.getImmutableDataSourcesWithAllUsedSegments()won't return such a data source.- Specified by:
retrieveAllDataSourceNamesin interfaceSegmentsMetadataManager
-
poll
public void poll()
- Specified by:
pollin interfaceSegmentsMetadataManager
-
getUnusedSegmentIntervals
public List<org.joda.time.Interval> getUnusedSegmentIntervals(String dataSource, @Nullable org.joda.time.DateTime minStartTime, org.joda.time.DateTime maxEndTime, int limit, org.joda.time.DateTime maxUsedStatusLastUpdatedTime)
Description copied from interface:SegmentsMetadataManagerReturns a list of up tolimitunused segment intervals for the specified datasource. Segments are filtered based on the following criteria:- The start time of the segment must be no earlier than the specified
minStartTime(if not null).- The end time of the segment must be no later than the specified
maxEndTime.- The
used_status_last_updatedtime of the segment must be no later thanmaxUsedStatusLastUpdatedTime. Segments that have noused_status_last_updatedtime (due to an upgrade from legacy Druid) will havemaxUsedStatusLastUpdatedTimeignored.The list of intervals is ordered by segment start time and then by end time.
- Specified by:
getUnusedSegmentIntervalsin interfaceSegmentsMetadataManager
- The start time of the segment must be no earlier than the specified
-
-