Class IndexerSQLMetadataStorageCoordinator
- All Implemented Interfaces:
IndexerMetadataStorageCoordinator
-
Constructor Summary
ConstructorsConstructorDescriptionIndexerSQLMetadataStorageCoordinator(SegmentMetadataTransactionFactory transactionFactory, com.fasterxml.jackson.databind.ObjectMapper jsonMapper, MetadataStorageTablesConfig dbTables, SQLMetadataConnector connector, SegmentSchemaManager segmentSchemaManager, CentralizedDatasourceSchemaConfig centralizedDatasourceSchemaConfig) -
Method Summary
Modifier and TypeMethodDescriptionallocatePendingSegment(String dataSource, org.joda.time.Interval interval, boolean skipSegmentLineageCheck, SegmentCreateRequest createRequest) Allocate a new pending segment in the pending segments table.allocatePendingSegments(String dataSource, org.joda.time.Interval allocateInterval, boolean skipSegmentLineageCheck, List<SegmentCreateRequest> requests, boolean reduceMetadataIO) Allocates pending segments for the given requests in the pending segments table.commitAppendSegments(Set<DataSegment> appendSegments, Map<DataSegment, ReplaceTaskLock> appendSegmentToReplaceLock, String taskAllocatorId, SegmentSchemaMapping segmentSchemaMapping) Commits segments and corresponding schema created by an APPEND task.commitAppendSegmentsAndMetadata(Set<DataSegment> appendSegments, Map<DataSegment, ReplaceTaskLock> appendSegmentToReplaceLock, String supervisorId, DataSourceMetadata startMetadata, DataSourceMetadata endMetadata, String taskAllocatorId, SegmentSchemaMapping segmentSchemaMapping) Commits segments created by an APPEND task.commitMetadataOnly(String supervisorId, String dataSource, DataSourceMetadata startMetadata, DataSourceMetadata endMetadata) Similar toIndexerMetadataStorageCoordinator.commitSegments(java.util.Set<org.apache.druid.timeline.DataSegment>, org.apache.druid.segment.SegmentSchemaMapping), but meant for streaming ingestion tasks for handling the case where the task ingested no records and created no segments, but still needs to update the metadata with the progress that the task made.commitReplaceSegments(Set<DataSegment> replaceSegments, Set<ReplaceTaskLock> locksHeldByReplaceTask, SegmentSchemaMapping segmentSchemaMapping) Commits segments and corresponding schema created by a REPLACE task.commitSegments(Set<DataSegment> segments, SegmentSchemaMapping segmentSchemaMapping) Attempts to insert a set of segments and corresponding schema to the metadata storage.commitSegmentsAndMetadata(Set<DataSegment> segments, String supervisorId, DataSourceMetadata startMetadata, DataSourceMetadata endMetadata, SegmentSchemaMapping segmentSchemaMapping) Attempts to insert a set of segments and corresponding schema to the metadata storage.booleandeleteDataSourceMetadata(String supervisorId) Removes entry forsupervisorIdfrom the dataSource metadata table.intdeletePendingSegments(String dataSource) Delete all pending segments belonging to the given data source from the pending segments table.intdeletePendingSegmentsCreatedInInterval(String dataSource, org.joda.time.Interval deleteInterval) Delete pending segments created in the given interval belonging to the given data source from the pending segments table.intdeletePendingSegmentsForTaskAllocatorId(String datasource, String taskAllocatorId) Delete pending segment for a give task group after all the tasks belonging to it have completed.intdeleteSegments(Set<DataSegment> segments) Deletes unused segments from the metadata store.intdeleteUpgradeSegmentsForTask(String taskId) Delete entries from the upgrade segments table after the corresponding replace task has endedgetPendingSegments(String datasource, org.joda.time.Interval interval) Fetches all the pending segments of the datasource that overlap with a given interval.getSegmentTimelineForAllocation(String dataSource, org.joda.time.Interval interval, boolean reduceMetadataIO) Return a segment timeline of all used segments including overshadowed ones for a given datasource and interval if skipSegmentPayloadFetchForAllocation is set to true, do not fetch all the segment payloads for allocation Instead fetch all the ids and numCorePartitions using exactly one segment per version per interval return a dummy DataSegment for each id that holds only the SegmentId and a NumberedShardSpec with numCorePartitionsList<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.booleaninsertDataSourceMetadata(String supervisorId, DataSourceMetadata metadata) InsertDataSourceMetadataentry forsupervisorId.protected Set<DataSegment>insertSegments(SegmentMetadataTransaction transaction, Set<DataSegment> segments, SegmentSchemaMapping segmentSchemaMapping) iterateAllUnusedSegmentsForDatasource(String datasource, org.joda.time.Interval interval, Integer limit, String lastSegmentId, SortOrder sortOrder) Returns a list of unused segments and their associated metadata for a given datasource over an optional interval.intmarkAllNonOvershadowedSegmentsAsUsed(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).intmarkAllSegmentsAsUnused(String dataSource) Marks all the segments in given datasource as unused.intmarkNonOvershadowedSegmentsAsUsed(String dataSource, Set<SegmentId> segmentIds) Marks the given segment IDs as "used" only if there are not already overshadowed by other used segments.intmarkNonOvershadowedSegmentsAsUsed(String dataSource, org.joda.time.Interval interval, List<String> versions) Marks non-overshadowed unused segments for the given interval and optional list of versions as used.booleanmarkSegmentAsUnused(SegmentId segmentId) Marks the segment as unused.booleanmarkSegmentAsUsed(SegmentId 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(String dataSource, Set<SegmentId> segmentIds) Marks the given segments as unused.intmarkSegmentsWithinIntervalAsUnused(String dataSource, org.joda.time.Interval interval, List<String> versions) Marks segments that are fully contained in the given interval as unused.intremoveDataSourceMetadataOlderThan(long timestamp, @NotNull Set<String> excludeSupervisorIds) Remove supervisors' datasource metadata created before the given timestamp and not in given excludeSupervisorIds set.booleanresetDataSourceMetadata(String supervisorId, DataSourceMetadata dataSourceMetadata) ResetsDataSourceMetadataentry forsupervisorIdto the one supplied.retrieveAllUsedSegments(String dataSource, Segments visibility) Retrieves all published used segments for the given data source.retrieveDataSourceMetadata(String supervisorId) Read dataSource metadata for the given supervisorId.retrieveSegmentForId(SegmentId segmentId) Retrieve the segment for a given id from the metadata store.retrieveSegmentsById(String dataSource, Set<String> segmentIds) Retrieves segments for the given IDs, regardless of their visibility (visible, overshadowed or unused).List<org.joda.time.Interval>retrieveUnusedSegmentIntervals(String dataSource, int limit) Retrieves intervals of the specified datasource that contain any unused segments.retrieveUnusedSegmentsForInterval(String dataSource, org.joda.time.Interval interval, List<String> versions, Integer limit, org.joda.time.DateTime maxUsedStatusLastUpdatedTime) Retrieve all published segments which include ONLY data within the given interval and are marked as unused from the metadata store.retrieveUnusedSegmentsWithExactInterval(String dataSource, org.joda.time.Interval interval, org.joda.time.DateTime maxUpdatedTime, int limit) Retrieves unused segments from the metadata store that match the given interval exactly.retrieveUpgradedFromSegmentIds(String dataSource, Set<String> segmentIds) Map from a segment ID to the segment ID from which it was upgraded There should be no entry in the map for an original non-upgraded segmentretrieveUpgradedToSegmentIds(String dataSource, Set<String> segmentIds) Map from a segment ID to a set containing 1) all segment IDs that were upgraded from it AND are still present in the metadata store 2) the segment ID itself if and only if it is still present in the metadata storeretrieveUsedSegmentForId(SegmentId segmentId) retrieveUsedSegmentsAndCreatedDates(String dataSource, List<org.joda.time.Interval> intervals) Retrieve all published segments which are marked as used and the created_date of these segments belonging to the given data source and list of intervals from the metadata store.retrieveUsedSegmentsForIntervals(String dataSource, List<org.joda.time.Interval> intervals, Segments visibility) Retrieves all published segments that have partial or complete overlap with the given intervals and are marked as used.voidstart()protected SegmentPublishResultupdateDataSourceMetadataInTransaction(SegmentMetadataTransaction transaction, String supervisorId, String dataSource, DataSourceMetadata startMetadata, DataSourceMetadata endMetadata) Compare-and-swapDataSourceMetadatafor a datasource in a transaction.voidupdateSegmentMetadata(Set<DataSegment> segments) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.druid.indexing.overlord.IndexerMetadataStorageCoordinator
retrieveUnusedSegmentsForInterval, retrieveUsedSegmentsForInterval
-
Constructor Details
-
IndexerSQLMetadataStorageCoordinator
@Inject public IndexerSQLMetadataStorageCoordinator(SegmentMetadataTransactionFactory transactionFactory, com.fasterxml.jackson.databind.ObjectMapper jsonMapper, MetadataStorageTablesConfig dbTables, SQLMetadataConnector connector, SegmentSchemaManager segmentSchemaManager, CentralizedDatasourceSchemaConfig centralizedDatasourceSchemaConfig)
-
-
Method Details
-
start
public void start() -
retrieveAllDatasourceNames
- Specified by:
retrieveAllDatasourceNamesin interfaceIndexerMetadataStorageCoordinator- Returns:
- Set of all datasource names for which there are used or unused segments present in the metadata store.
-
retrieveUnusedSegmentIntervals
Description copied from interface:IndexerMetadataStorageCoordinatorRetrieves intervals of the specified datasource that contain any unused segments. There is no guarantee on the order of intervals in the list or on whether the limited list contains the earliest or latest intervals of the datasource.- Specified by:
retrieveUnusedSegmentIntervalsin interfaceIndexerMetadataStorageCoordinator- Returns:
- Unsorted list of unused segment intervals containing upto
limitentries.
-
retrieveUsedSegmentsForIntervals
public Set<DataSegment> retrieveUsedSegmentsForIntervals(String dataSource, List<org.joda.time.Interval> intervals, Segments visibility) Description copied from interface:IndexerMetadataStorageCoordinatorRetrieves all published segments that have partial or complete overlap with the given intervals and are marked as used.- Specified by:
retrieveUsedSegmentsForIntervalsin interfaceIndexerMetadataStorageCoordinator
-
retrieveAllUsedSegments
Description copied from interface:IndexerMetadataStorageCoordinatorRetrieves all published used segments for the given data source.- Specified by:
retrieveAllUsedSegmentsin interfaceIndexerMetadataStorageCoordinator- See Also:
-
retrieveUsedSegmentsAndCreatedDates
public List<Pair<DataSegment,String>> retrieveUsedSegmentsAndCreatedDates(String dataSource, List<org.joda.time.Interval> intervals) Description copied from interface:IndexerMetadataStorageCoordinatorRetrieve all published segments which are marked as used and the created_date of these segments belonging to the given data source and list of intervals from the metadata store.Unlike other similar methods in this interface, this method doesn't accept a
Segments"visibility" parameter. The returned collection may include overshadowed segments and their created_dates, as ifSegments.INCLUDING_OVERSHADOWEDwas passed. It's the responsibility of the caller to filter out overshadowed ones if needed.- Specified by:
retrieveUsedSegmentsAndCreatedDatesin interfaceIndexerMetadataStorageCoordinator- Parameters:
dataSource- The data source to queryintervals- The list of interval to query- Returns:
- The DataSegments and the related created_date of segments
-
retrieveUnusedSegmentsForInterval
public List<DataSegment> retrieveUnusedSegmentsForInterval(String dataSource, org.joda.time.Interval interval, @Nullable List<String> versions, @Nullable Integer limit, @Nullable org.joda.time.DateTime maxUsedStatusLastUpdatedTime) Description copied from interface:IndexerMetadataStorageCoordinatorRetrieve all published segments which include ONLY data within the given interval and are marked as unused from the metadata store.- Specified by:
retrieveUnusedSegmentsForIntervalin interfaceIndexerMetadataStorageCoordinator- Parameters:
dataSource- The data source the segments belong tointerval- Filter the data segments to ones that include data in this interval exclusively.versions- An optional list of segment versions to retrieve in the giveninterval. If unspecified, all versions of unused segments in theintervalmust be retrieved. If an empty list is passed, no segments are retrieved.limit- The maximum number of unused segments to retreive. If null, no limit is applied.maxUsedStatusLastUpdatedTime- The maximumused_status_last_updatedtime. Any unused segment inintervalwithused_status_last_updatedno later than this time will be included in the kill task. Segments withoutused_status_last_updatedtime (due to an upgrade from legacy Druid) will havemaxUsedStatusLastUpdatedTimeignored- Returns:
- DataSegments which include ONLY data within the requested interval and are marked as unused. Segments NOT returned here may include data in the interval
-
retrieveUnusedSegmentsWithExactInterval
public List<DataSegment> retrieveUnusedSegmentsWithExactInterval(String dataSource, org.joda.time.Interval interval, org.joda.time.DateTime maxUpdatedTime, int limit) Description copied from interface:IndexerMetadataStorageCoordinatorRetrieves unused segments from the metadata store that match the given interval exactly. There is no guarantee on the order of segments in the list or on whether the limited list contains the highest or lowest segment IDs in the interval.- Specified by:
retrieveUnusedSegmentsWithExactIntervalin interfaceIndexerMetadataStorageCoordinatorinterval- Returned segments must exactly match this interval.maxUpdatedTime- Returned segments must have aused_status_last_updatedwhich is either null or earlier than this value.limit- Maximum number of segments to return.- Returns:
- Unsorted list of unused segments that match the given parameters.
-
retrieveSegmentsById
Description copied from interface:IndexerMetadataStorageCoordinatorRetrieves segments for the given IDs, regardless of their visibility (visible, overshadowed or unused).- Specified by:
retrieveSegmentsByIdin interfaceIndexerMetadataStorageCoordinator
-
markSegmentsWithinIntervalAsUnused
public int markSegmentsWithinIntervalAsUnused(String dataSource, org.joda.time.Interval interval, @Nullable List<String> versions) Description copied from interface:IndexerMetadataStorageCoordinatorMarks segments that are fully contained in the given interval as unused.- Specified by:
markSegmentsWithinIntervalAsUnusedin interfaceIndexerMetadataStorageCoordinatorversions- Optional list of segment versions eligible for update. If this list is passed as null, all segment versions are eligible for updated. If passed as empty, no segment is updated.- Returns:
- Number of segments updated
-
markSegmentAsUnused
Description copied from interface:IndexerMetadataStorageCoordinatorMarks the segment as unused.- Specified by:
markSegmentAsUnusedin interfaceIndexerMetadataStorageCoordinator- Returns:
- true if the segment was updated, false otherwise
-
markSegmentsAsUnused
Description copied from interface:IndexerMetadataStorageCoordinatorMarks the given segments as unused.- Specified by:
markSegmentsAsUnusedin interfaceIndexerMetadataStorageCoordinator- Returns:
- Number of segments updated
-
markAllSegmentsAsUnused
Description copied from interface:IndexerMetadataStorageCoordinatorMarks all the segments in given datasource as unused.- Specified by:
markAllSegmentsAsUnusedin interfaceIndexerMetadataStorageCoordinator- Returns:
- Number of updated segments
-
markSegmentAsUsed
Description copied from interface:IndexerMetadataStorageCoordinatorReturns 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 interfaceIndexerMetadataStorageCoordinator
-
markNonOvershadowedSegmentsAsUsed
Description copied from interface:IndexerMetadataStorageCoordinatorMarks the given segment IDs as "used" only if there are not already overshadowed by other used segments. Qualifying segment IDs that are already marked as "used" are not updated.- Specified by:
markNonOvershadowedSegmentsAsUsedin interfaceIndexerMetadataStorageCoordinator- Returns:
- Number of segments updated
-
markNonOvershadowedSegmentsAsUsed
public int markNonOvershadowedSegmentsAsUsed(String dataSource, org.joda.time.Interval interval, @Nullable List<String> versions) Description copied from interface:IndexerMetadataStorageCoordinatorMarks non-overshadowed unused segments for the given interval and optional list of versions as used. If versions are not specified, all versions of non-overshadowed unused segments in the interval will be marked as used. If an empty list of versions is passed, no segments are marked as used.- Specified by:
markNonOvershadowedSegmentsAsUsedin interfaceIndexerMetadataStorageCoordinator- Returns:
- Number of segments updated in the metadata store
-
markAllNonOvershadowedSegmentsAsUsed
Description copied from interface:IndexerMetadataStorageCoordinatorReturns 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:
markAllNonOvershadowedSegmentsAsUsedin interfaceIndexerMetadataStorageCoordinator- Returns:
- Number of segments updated in the metadata store
-
iterateAllUnusedSegmentsForDatasource
public List<DataSegmentPlus> iterateAllUnusedSegmentsForDatasource(String datasource, @Nullable org.joda.time.Interval interval, @Nullable Integer limit, @Nullable String lastSegmentId, @Nullable SortOrder sortOrder) Description copied from interface:IndexerMetadataStorageCoordinatorReturns a list of unused segments and their associated metadata for a given datasource over an optional interval. The order in which segments are iterated is from earliest start-time, with ties being broken with earliest end-time first. 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:
iterateAllUnusedSegmentsForDatasourcein interfaceIndexerMetadataStorageCoordinator- Parameters:
datasource- the name of the datasource.interval- an optional interval to search over. If none is specified,Intervals.ETERNITYlimit- 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.
-
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:IndexerMetadataStorageCoordinatorReturns 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.- Specified by:
getUnusedSegmentIntervalsin interfaceIndexerMetadataStorageCoordinator- Returns:
- list of intervals ordered by segment start time and then by end time. Note that the list may contain duplicate intervals.
- The start time of the segment must be no earlier than the specified
-
commitSegments
public Set<DataSegment> commitSegments(Set<DataSegment> segments, @Nullable SegmentSchemaMapping segmentSchemaMapping) Description copied from interface:IndexerMetadataStorageCoordinatorAttempts to insert a set of segments and corresponding schema to the metadata storage. Returns the set of segments actually added (segments with identifiers already in the metadata storage will not be added).- Specified by:
commitSegmentsin interfaceIndexerMetadataStorageCoordinator- Parameters:
segments- set of segments to addsegmentSchemaMapping- segment schema information to add- Returns:
- set of segments actually added
-
commitSegmentsAndMetadata
public SegmentPublishResult commitSegmentsAndMetadata(Set<DataSegment> segments, @Nullable String supervisorId, @Nullable DataSourceMetadata startMetadata, @Nullable DataSourceMetadata endMetadata, @Nullable SegmentSchemaMapping segmentSchemaMapping) Description copied from interface:IndexerMetadataStorageCoordinatorAttempts to insert a set of segments and corresponding schema to the metadata storage. Returns the set of segments actually added (segments with identifiers already in the metadata storage will not be added). If startMetadata and endMetadata are set, this insertion will be atomic with a compare-and-swap on dataSource commit metadata.If segmentsToDrop is not null and not empty, this insertion will be atomic with a insert-and-drop on inserting and dropping .
- Specified by:
commitSegmentsAndMetadatain interfaceIndexerMetadataStorageCoordinator- Parameters:
segments- set of segments to add, must all be from the same dataSourcesupervisorId- supervisorID which is committing the segments. Cannot be null ifstartMetadataandendMetadataare both non-null.startMetadata- dataSource metadata pre-insert must match this startMetadata according toDataSourceMetadata.matches(DataSourceMetadata). If null, this insert will not involve a metadata transactionendMetadata- dataSource metadata post-insert will have this endMetadata merged in withDataSourceMetadata.plus(DataSourceMetadata). If null, this insert will not involve a metadata transactionsegmentSchemaMapping- segment schema information to persist.- Returns:
- segment publish result indicating transaction success or failure, and set of segments actually published. This method must only return a failure code if it is sure that the transaction did not happen. If it is not sure, it must throw an exception instead.
-
commitReplaceSegments
public SegmentPublishResult commitReplaceSegments(Set<DataSegment> replaceSegments, Set<ReplaceTaskLock> locksHeldByReplaceTask, @Nullable SegmentSchemaMapping segmentSchemaMapping) Description copied from interface:IndexerMetadataStorageCoordinatorCommits segments and corresponding schema created by a REPLACE task. This method also handles the segment upgrade scenarios that may result from concurrent append and replace.- If an APPEND task committed a segment to an interval locked by this task,
the append segment is upgraded to the version of the corresponding lock.
This is done with the help of entries created in the upgrade_segments table
in
IndexerMetadataStorageCoordinator.commitAppendSegments(java.util.Set<org.apache.druid.timeline.DataSegment>, java.util.Map<org.apache.druid.timeline.DataSegment, org.apache.druid.metadata.ReplaceTaskLock>, java.lang.String, org.apache.druid.segment.SegmentSchemaMapping)
- Specified by:
commitReplaceSegmentsin interfaceIndexerMetadataStorageCoordinator- Parameters:
replaceSegments- All segments created by a REPLACE task that must be committed in a single transaction.locksHeldByReplaceTask- All active non-revoked REPLACE locks held by the tasksegmentSchemaMapping- Segment schema to add.
- If an APPEND task committed a segment to an interval locked by this task,
the append segment is upgraded to the version of the corresponding lock.
This is done with the help of entries created in the upgrade_segments table
in
-
commitAppendSegments
public SegmentPublishResult commitAppendSegments(Set<DataSegment> appendSegments, Map<DataSegment, ReplaceTaskLock> appendSegmentToReplaceLock, String taskAllocatorId, @Nullable SegmentSchemaMapping segmentSchemaMapping) Description copied from interface:IndexerMetadataStorageCoordinatorCommits segments and corresponding schema created by an APPEND task. This method also handles segment upgrade scenarios that may result from concurrent append and replace.- If a REPLACE task committed a segment that overlaps with any of the appendSegments while this APPEND task was in progress, the appendSegments are upgraded to the version of the replace segment.
- If an appendSegment is covered by a currently active REPLACE lock, then an entry is created for it in the upgrade_segments table, so that when the REPLACE task finishes, it can upgrade the appendSegment as required.
- Specified by:
commitAppendSegmentsin interfaceIndexerMetadataStorageCoordinator- Parameters:
appendSegments- All segments created by an APPEND task that must be committed in a single transaction.appendSegmentToReplaceLock- Map from append segment to the currently active REPLACE lock (if any) covering ittaskAllocatorId- allocator id of the task committing the segments to be appendedsegmentSchemaMapping- schema of append segments
-
commitAppendSegmentsAndMetadata
public SegmentPublishResult commitAppendSegmentsAndMetadata(Set<DataSegment> appendSegments, Map<DataSegment, ReplaceTaskLock> appendSegmentToReplaceLock, String supervisorId, DataSourceMetadata startMetadata, DataSourceMetadata endMetadata, String taskAllocatorId, @Nullable SegmentSchemaMapping segmentSchemaMapping) Description copied from interface:IndexerMetadataStorageCoordinatorCommits segments created by an APPEND task. This method also handles segment upgrade scenarios that may result from concurrent append and replace. Also commits start and endDataSourceMetadata.- Specified by:
commitAppendSegmentsAndMetadatain interfaceIndexerMetadataStorageCoordinator- See Also:
-
IndexerMetadataStorageCoordinator.commitAppendSegments(java.util.Set<org.apache.druid.timeline.DataSegment>, java.util.Map<org.apache.druid.timeline.DataSegment, org.apache.druid.metadata.ReplaceTaskLock>, java.lang.String, org.apache.druid.segment.SegmentSchemaMapping)IndexerMetadataStorageCoordinator.commitSegmentsAndMetadata(java.util.Set<org.apache.druid.timeline.DataSegment>, java.lang.String, org.apache.druid.indexing.overlord.DataSourceMetadata, org.apache.druid.indexing.overlord.DataSourceMetadata, org.apache.druid.segment.SegmentSchemaMapping)
-
commitMetadataOnly
public SegmentPublishResult commitMetadataOnly(String supervisorId, String dataSource, DataSourceMetadata startMetadata, DataSourceMetadata endMetadata) Description copied from interface:IndexerMetadataStorageCoordinatorSimilar toIndexerMetadataStorageCoordinator.commitSegments(java.util.Set<org.apache.druid.timeline.DataSegment>, org.apache.druid.segment.SegmentSchemaMapping), but meant for streaming ingestion tasks for handling the case where the task ingested no records and created no segments, but still needs to update the metadata with the progress that the task made.The metadata should undergo the same validation checks as performed by
IndexerMetadataStorageCoordinator.commitSegments(java.util.Set<org.apache.druid.timeline.DataSegment>, org.apache.druid.segment.SegmentSchemaMapping).- Specified by:
commitMetadataOnlyin interfaceIndexerMetadataStorageCoordinator- Parameters:
supervisorId- the supervisorIddataSource- the dataSourcestartMetadata- dataSource metadata pre-insert must match this startMetadata according toDataSourceMetadata.matches(DataSourceMetadata).endMetadata- dataSource metadata post-insert will have this endMetadata merged in withDataSourceMetadata.plus(DataSourceMetadata).- Returns:
- segment publish result indicating transaction success or failure. This method must only return a failure code if it is sure that the transaction did not happen. If it is not sure, it must throw an exception instead.
-
allocatePendingSegments
public Map<SegmentCreateRequest,SegmentIdWithShardSpec> allocatePendingSegments(String dataSource, org.joda.time.Interval allocateInterval, boolean skipSegmentLineageCheck, List<SegmentCreateRequest> requests, boolean reduceMetadataIO) Description copied from interface:IndexerMetadataStorageCoordinatorAllocates pending segments for the given requests in the pending segments table. The segment id allocated for a request will not be given out again unless a request is made with the sameSegmentCreateRequest.- Specified by:
allocatePendingSegmentsin interfaceIndexerMetadataStorageCoordinator- Parameters:
dataSource- dataSource for which to allocate a segmentallocateInterval- interval for which to allocate a segmentskipSegmentLineageCheck- if true, perform lineage validation using previousSegmentId for this sequence. Should be set to false if replica tasks would index events in same orderrequests- Requests for which to allocate segments. All the requests must share the same partition space.reduceMetadataIO- If true, try to use the segment ids instead of fetching every segment payload from the metadata store- Returns:
- Map from request to allocated segment id. The map does not contain entries for failed requests.
-
allocatePendingSegment
@Nullable public SegmentIdWithShardSpec allocatePendingSegment(String dataSource, org.joda.time.Interval interval, boolean skipSegmentLineageCheck, SegmentCreateRequest createRequest) Description copied from interface:IndexerMetadataStorageCoordinatorAllocate a new pending segment in the pending segments table. This segment identifier will never be given out again, unless another call is made with the same dataSource, sequenceName, and previousSegmentId. The sequenceName and previousSegmentId parameters are meant to make it easy for two independent ingestion tasks to produce the same series of segments. Note that a segment sequence may include segments with a variety of different intervals and versions.- Specified by:
allocatePendingSegmentin interfaceIndexerMetadataStorageCoordinator- Parameters:
dataSource- dataSource for which to allocate a segmentinterval- interval for which to allocate a segmentskipSegmentLineageCheck- if true, perform lineage validation using previousSegmentId for this sequence. Should be set to false if replica tasks would index events in same order- Returns:
- the pending segment identifier, or null if it was impossible to allocate a new segment
-
getSegmentTimelineForAllocation
public SegmentTimeline getSegmentTimelineForAllocation(String dataSource, org.joda.time.Interval interval, boolean reduceMetadataIO) Description copied from interface:IndexerMetadataStorageCoordinatorReturn a segment timeline of all used segments including overshadowed ones for a given datasource and interval if skipSegmentPayloadFetchForAllocation is set to true, do not fetch all the segment payloads for allocation Instead fetch all the ids and numCorePartitions using exactly one segment per version per interval return a dummy DataSegment for each id that holds only the SegmentId and a NumberedShardSpec with numCorePartitions- Specified by:
getSegmentTimelineForAllocationin interfaceIndexerMetadataStorageCoordinator
-
deletePendingSegmentsCreatedInInterval
public int deletePendingSegmentsCreatedInInterval(String dataSource, org.joda.time.Interval deleteInterval) Description copied from interface:IndexerMetadataStorageCoordinatorDelete pending segments created in the given interval belonging to the given data source from the pending segments table. Thecreated_datefield of the pending segments table is checked to find segments to be deleted.Note that the semantic of the interval (for `created_date`s) is different from the semantic of the interval parameters in some other methods in this class, such as
IndexerMetadataStorageCoordinator.retrieveUsedSegmentsForInterval(java.lang.String, org.joda.time.Interval, org.apache.druid.indexing.overlord.Segments)(where the interval is about the time column value in rows belonging to the segment).- Specified by:
deletePendingSegmentsCreatedInIntervalin interfaceIndexerMetadataStorageCoordinator- Parameters:
dataSource- dataSourcedeleteInterval- interval to check thecreated_dateof pendingSegments- Returns:
- number of deleted pending segments
-
deletePendingSegments
Description copied from interface:IndexerMetadataStorageCoordinatorDelete all pending segments belonging to the given data source from the pending segments table.- Specified by:
deletePendingSegmentsin interfaceIndexerMetadataStorageCoordinator- Returns:
- number of deleted pending segments
- See Also:
-
insertSegments
protected Set<DataSegment> insertSegments(SegmentMetadataTransaction transaction, Set<DataSegment> segments, @Nullable SegmentSchemaMapping segmentSchemaMapping) throws Exception - Throws:
Exception
-
retrieveDataSourceMetadata
Read dataSource metadata for the given supervisorId. Returns null if there is no metadata.- Specified by:
retrieveDataSourceMetadatain interfaceIndexerMetadataStorageCoordinator
-
updateDataSourceMetadataInTransaction
protected SegmentPublishResult updateDataSourceMetadataInTransaction(SegmentMetadataTransaction transaction, String supervisorId, String dataSource, DataSourceMetadata startMetadata, DataSourceMetadata endMetadata) throws IOException Compare-and-swapDataSourceMetadatafor a datasource in a transaction. This method updates the metadata for the given datasource only if the currently persisted entrymatchesthestartMetadata. If the current entry in the DBmatchestheendMetadata, this method returns immediately with success.- Parameters:
supervisorId- The supervisor ID. Used as the PK for the corresponding metadata entry in the DB.dataSource- The dataSource. Currently used only for logging purposes.startMetadata- Current entry in the DB mustmatchthis value.endMetadata- The updated entry will be equal to the current entryplusthis value.- Returns:
- Successful
SegmentPublishResultif the metadata in the DB was successfully updated, or if the current entry already matches endMetadata. Otherwise, returns a failedSegmentPublishResult(retryable or not). - Throws:
IOException- if an error occurred while serializing or deserializing.NullPointerException- if any of the arguments is null.
-
deleteDataSourceMetadata
Description copied from interface:IndexerMetadataStorageCoordinatorRemoves entry forsupervisorIdfrom the dataSource metadata table.- Specified by:
deleteDataSourceMetadatain interfaceIndexerMetadataStorageCoordinator- Parameters:
supervisorId- identifier- Returns:
- true if the entry was deleted, false otherwise
-
resetDataSourceMetadata
public boolean resetDataSourceMetadata(String supervisorId, DataSourceMetadata dataSourceMetadata) throws IOException Description copied from interface:IndexerMetadataStorageCoordinatorResetsDataSourceMetadataentry forsupervisorIdto the one supplied.- Specified by:
resetDataSourceMetadatain interfaceIndexerMetadataStorageCoordinator- Parameters:
supervisorId- identifierdataSourceMetadata- value to set- Returns:
- true if the entry was reset, false otherwise
- Throws:
IOException
-
updateSegmentMetadata
- Specified by:
updateSegmentMetadatain interfaceIndexerMetadataStorageCoordinator
-
deleteSegments
Description copied from interface:IndexerMetadataStorageCoordinatorDeletes unused segments from the metadata store.- Specified by:
deleteSegmentsin interfaceIndexerMetadataStorageCoordinator- Returns:
- Number of segments actually deleted.
-
insertDataSourceMetadata
Description copied from interface:IndexerMetadataStorageCoordinatorInsertDataSourceMetadataentry forsupervisorId.- Specified by:
insertDataSourceMetadatain interfaceIndexerMetadataStorageCoordinator- Parameters:
supervisorId- identifiermetadata- value to set- Returns:
- true if the entry was inserted, false otherwise
-
removeDataSourceMetadataOlderThan
public int removeDataSourceMetadataOlderThan(long timestamp, @NotNull @NotNull Set<String> excludeSupervisorIds) Description copied from interface:IndexerMetadataStorageCoordinatorRemove supervisors' datasource metadata created before the given timestamp and not in given excludeSupervisorIds set.- Specified by:
removeDataSourceMetadataOlderThanin interfaceIndexerMetadataStorageCoordinator- Parameters:
timestamp- timestamp in millisecondsexcludeSupervisorIds- set of supervisor ids to exclude from removal- Returns:
- number of datasource metadata removed
-
retrieveSegmentForId
Description copied from interface:IndexerMetadataStorageCoordinatorRetrieve the segment for a given id from the metadata store. Return null if no such segment exists
The retrieval also considers the set of unused segments in the metadata store. Unused segments could be deleted by a kill task at any time and might lead to unexpected behaviour. This option exists mainly to provide a consistent view of the metadata, for example, in calls from MSQ controller and worker and would generally not be required.- Specified by:
retrieveSegmentForIdin interfaceIndexerMetadataStorageCoordinator
-
retrieveUsedSegmentForId
- Specified by:
retrieveUsedSegmentForIdin interfaceIndexerMetadataStorageCoordinator
-
deletePendingSegmentsForTaskAllocatorId
Description copied from interface:IndexerMetadataStorageCoordinatorDelete pending segment for a give task group after all the tasks belonging to it have completed.- Specified by:
deletePendingSegmentsForTaskAllocatorIdin interfaceIndexerMetadataStorageCoordinator- Parameters:
datasource- datasource of the tasktaskAllocatorId- task id / task group / replica group for an appending task- Returns:
- number of pending segments deleted from the metadata store
-
getPendingSegments
public List<PendingSegmentRecord> getPendingSegments(String datasource, org.joda.time.Interval interval) Description copied from interface:IndexerMetadataStorageCoordinatorFetches all the pending segments of the datasource that overlap with a given interval.- Specified by:
getPendingSegmentsin interfaceIndexerMetadataStorageCoordinator- Parameters:
datasource- datasource to be queriedinterval- interval with which segments overlap- Returns:
- List of pending segment records
-
deleteUpgradeSegmentsForTask
Description copied from interface:IndexerMetadataStorageCoordinatorDelete entries from the upgrade segments table after the corresponding replace task has ended- Specified by:
deleteUpgradeSegmentsForTaskin interfaceIndexerMetadataStorageCoordinator- Parameters:
taskId- - id of the task with replace locks- Returns:
- number of deleted entries from the metadata store
-
retrieveUpgradedFromSegmentIds
Description copied from interface:IndexerMetadataStorageCoordinatorMap from a segment ID to the segment ID from which it was upgraded There should be no entry in the map for an original non-upgraded segment- Specified by:
retrieveUpgradedFromSegmentIdsin interfaceIndexerMetadataStorageCoordinator- Parameters:
dataSource- data sourcesegmentIds- ids of segments
-
retrieveUpgradedToSegmentIds
public Map<String,Set<String>> retrieveUpgradedToSegmentIds(String dataSource, Set<String> segmentIds) Description copied from interface:IndexerMetadataStorageCoordinatorMap from a segment ID to a set containing 1) all segment IDs that were upgraded from it AND are still present in the metadata store 2) the segment ID itself if and only if it is still present in the metadata store- Specified by:
retrieveUpgradedToSegmentIdsin interfaceIndexerMetadataStorageCoordinator- Parameters:
dataSource- data sourcesegmentIds- ids of the first segments which had the corresponding load spec
-