Class CostBalancerStrategy

    • Constructor Detail

      • CostBalancerStrategy

        public CostBalancerStrategy​(com.google.common.util.concurrent.ListeningExecutorService exec)
    • Method Detail

      • computeJointSegmentsCost

        public static double computeJointSegmentsCost​(org.apache.druid.timeline.DataSegment segment,
                                                      Iterable<org.apache.druid.timeline.DataSegment> segmentSet)
      • computeJointSegmentsCost

        public static double computeJointSegmentsCost​(org.apache.druid.timeline.DataSegment segmentA,
                                                      org.apache.druid.timeline.DataSegment segmentB)
        This defines the unnormalized cost function between two segments. See https://github.com/apache/druid/pull/2972 for more details about the cost function. intervalCost: segments close together are more likely to be queried together multiplier: if two segments belong to the same data source, they are more likely to be involved in the same queries
        Parameters:
        segmentA - The first DataSegment.
        segmentB - The second DataSegment.
        Returns:
        the joint cost of placing the two DataSegments together on one node.
      • intervalCost

        public static double intervalCost​(org.joda.time.Interval intervalA,
                                          org.joda.time.Interval intervalB)
      • intervalCost

        public static double intervalCost​(double x1,
                                          double y0,
                                          double y1)
        Computes the joint cost of two intervals X = [x_0 = 0, x_1) and Y = [y_0, y_1) cost(X, Y) = \int_{x_0}^{x_1} \int_{y_0}^{y_1} e^{-\lambda |x-y|}dxdy $$ lambda = 1 in this particular implementation Other values of lambda can be calculated by multiplying inputs by lambda and multiplying the result by 1 / lambda ^ 2 Interval start and end are all relative to x_0. Therefore this function assumes x_0 = 0, x1 >= 0, and y1 > y0
        Parameters:
        x1 - end of interval X
        y0 - start of interval Y
        y1 - end o interval Y
        Returns:
        joint cost of X and Y
      • findServersToLoadSegment

        public Iterator<ServerHolder> findServersToLoadSegment​(org.apache.druid.timeline.DataSegment segmentToLoad,
                                                               List<ServerHolder> serverHolders)
        Description copied from interface: BalancerStrategy
        Finds the best servers to load the given segment. This method can be used both for placing the first copy of a segment in a tier or a replica of an already available segment.
        Specified by:
        findServersToLoadSegment in interface BalancerStrategy
        Returns:
        Iterator over the best servers (in order of preference) to load the segment.
      • findDestinationServerToMoveSegment

        public ServerHolder findDestinationServerToMoveSegment​(org.apache.druid.timeline.DataSegment segmentToMove,
                                                               ServerHolder sourceServer,
                                                               List<ServerHolder> serverHolders)
        Description copied from interface: BalancerStrategy
        Finds the best server from the list of destinationServers to load the segmentToMove, if it is moved from the sourceServer.

        In order to avoid unnecessary moves when the segment is already optimally placed, include the sourceServer in the list of destinationServers.

        Specified by:
        findDestinationServerToMoveSegment in interface BalancerStrategy
        Returns:
        The server to move to, or null if the segment is already optimally placed.
      • computePlacementCost

        protected double computePlacementCost​(org.apache.druid.timeline.DataSegment proposalSegment,
                                              ServerHolder server)
        Computes the cost of placing a segment on this server.