@ GET @ Path ( "/{dataSourceName}/handoffComplete" ) @ Produces ( MediaType . APPLICATION_JSON ) @ ResourceFilters ( DatasourceResourceFilter . class ) public Response isHandOffComplete ( @ PathParam ( "dataSourceName" ) String dataSourceName , @ QueryParam ( "interval" ) final String interval , @ QueryParam ( "partitionNumber" ) final int partitionNumber , @ QueryParam ( "version" ) final String version ) { try { final List < Rule > rules = databaseRuleManager . getRulesWithDefault ( dataSourceName ) ; final Interval theInterval = Intervals . of ( interval ) ; final SegmentDescriptor descriptor = new SegmentDescriptor ( theInterval , version , partitionNumber ) ; final DateTime now = DateTimes . nowUtc ( ) ; // dropped means a segment will never be handed off, i.e it completed hand off // init to true, reset to false only if this segment can be loaded by rules boolean dropped = true ; for ( Rule rule : rules ) { if ( rule . appliesTo ( theInterval , now ) ) { if ( rule instanceof LoadRule ) { dropped = false ; } break ; } } if ( dropped ) { return Response . ok ( true ) . build ( ) ; } TimelineLookup < String , SegmentLoadInfo > timeline = serverInventoryView . getTimeline ( new TableDataSource ( dataSourceName ) ) ; if ( timeline == null ) { log . debug ( "No timeline found for datasource[%s]" , dataSourceName ) ; return Response . ok ( false ) . build ( ) ; } Iterable < TimelineObjectHolder < String , SegmentLoadInfo > > lookup = timeline . lookupWithIncompletePartitions ( theInterval ) ; FunctionalIterable < ImmutableSegmentLoadInfo > loadInfoIterable = FunctionalIterable . create ( lookup ) . transformCat ( ( TimelineObjectHolder < String , SegmentLoadInfo > input ) -> Iterables . transform ( input . getObject ( ) , ( PartitionChunk < SegmentLoadInfo > chunk ) -> chunk . getObject ( ) . toImmutableSegmentLoadInfo ( ) ) ) ; if ( isSegmentLoaded ( loadInfoIterable , descriptor ) ) { return Response . ok ( true ) . build ( ) ; } return Response . ok ( false ) . build ( ) ; } catch ( Exception e ) { log . error ( e , "Error while handling hand off check request" ) ; return Response . serverError ( ) . entity ( ImmutableMap . of ( "error" , e . toString ( ) ) ) . build ( ) ; } }
Used by the realtime tasks to learn whether a segment is handed off or not . It returns true when the segment will never be handed off or is already handed off . Otherwise it returns false .