Class ServerHolder

java.lang.Object
org.apache.druid.server.coordinator.ServerHolder
All Implemented Interfaces:
Comparable<ServerHolder>

public class ServerHolder extends Object implements Comparable<ServerHolder>
Encapsulates the state of a DruidServer during a single coordinator run.

ServerHolders are naturally ordered by available size, servers with more available size first.

  • Constructor Details

    • ServerHolder

      public ServerHolder(ImmutableDruidServer server, LoadQueuePeon peon)
    • ServerHolder

      public ServerHolder(ImmutableDruidServer server, LoadQueuePeon peon, boolean isDecommissioning)
    • ServerHolder

      public ServerHolder(ImmutableDruidServer server, LoadQueuePeon peon, boolean isDecommissioning, int maxSegmentsInLoadQueue, int maxLifetimeInQueue)
    • ServerHolder

      public ServerHolder(ImmutableDruidServer server, LoadQueuePeon peon, boolean isDecommissioning, boolean isUnmanaged, int maxSegmentsInLoadQueue, int maxLifetimeInQueue)
      Creates a new ServerHolder valid for a single coordinator run.
      Parameters:
      server - Underlying Druid server
      peon - Load queue peon for this server
      isDecommissioning - Whether the server is decommissioning
      isUnmanaged - Whether this server is unmanaged and should not participate in segment assignment, drop or balancing.
      maxSegmentsInLoadQueue - Max number of segments that can be present in the load queue at any point. If this is 0, the load queue can have an unlimited number of segments.
      maxLifetimeInQueue - Number of coordinator runs after a which a segment in load/drop queue is considered to be stuck.
  • Method Details

    • getServer

      public ImmutableDruidServer getServer()
    • getPeon

      public LoadQueuePeon getPeon()
    • getMaxSize

      public long getMaxSize()
    • getSizeUsed

      public long getSizeUsed()
      Total projected disk usage of this server in bytes.

      The total size:

      1. INCLUDES segments loaded on this server
      2. INCLUDES segments loading on this server (actions: LOAD/REPLICATE)
      3. INCLUDES segments moving to this server (action: MOVE_TO)
      4. INCLUDES segments moving from this server (action: MOVE_FROM). This is because these segments have only been marked for drop. We include the size of these segments to avoid over-assigning the server in case the corresponding MOVE_TO operation gets delayed or fails.
      5. EXCLUDES segments dropping from this server (action: DROP). Excluding these segments cannot result in over-assignment because drops are always processed before loads.
    • getPercentUsed

      public double getPercentUsed()
    • isDecommissioning

      public boolean isDecommissioning()
    • isUnmanaged

      public boolean isUnmanaged()
      Returns true if this server is unmanaged and should not participate in segment assignment, drop or balancing.
    • isLoadQueueFull

      public boolean isLoadQueueFull()
    • getAvailableSize

      public long getAvailableSize()
    • canLoadSegment

      public boolean canLoadSegment(DataSegment segment)
      Checks if the server can load the given segment.

      A load is possible only if the server meets all of the following criteria:

      • is not being decommissioned
      • is not already serving the segment
      • is not performing any other action on the segment
      • has not already exceeded the load queue limit in this run
      • has available disk space
    • getActionOnSegment

      public SegmentAction getActionOnSegment(DataSegment segment)
    • getQueuedSegments

      public Map<DataSegment,SegmentAction> getQueuedSegments()
      Segments queued for load, drop or move on this server.
      • Contains segments present in the queue when the current coordinator run started.
      • Contains segments added to the queue during the current run.
      • Maps replicating segments to LOAD rather than REPLICATE for simplicity.
      • Does not contain segments whose actions were cancelled.
    • getProjectedSegmentCounts

      public SegmentCountsPerInterval getProjectedSegmentCounts()
      Counts for segments that are expected to be loaded on this server once all the operations in progress have completed.
    • getProjectedSegments

      public Set<DataSegment> getProjectedSegments()
      Segments that are expected to be loaded on this server once all the operations in progress have completed.
    • isProjectedSegment

      public boolean isProjectedSegment(DataSegment segment)
    • getLoadingSegments

      public List<DataSegment> getLoadingSegments()
      Segments that are currently in the queue for being loaded on this server. This does not include segments that are being moved to this server.
    • getServedSegments

      public Collection<DataSegment> getServedSegments()
      Segments that are currently loaded on this server.
    • isServingSegment

      public boolean isServingSegment(DataSegment segment)
      Returns true if this server has the segment loaded and is not dropping it.
    • isLoadingSegment

      public boolean isLoadingSegment(DataSegment segment)
    • isDroppingSegment

      public boolean isDroppingSegment(DataSegment segment)
    • getNumMovingSegments

      public int getNumMovingSegments()
    • getNumLoadingReplicas

      public int getNumLoadingReplicas()
    • getNumQueuedSegments

      public int getNumQueuedSegments()
    • startOperation

      public boolean startOperation(SegmentAction action, DataSegment segment)
    • cancelOperation

      public boolean cancelOperation(SegmentAction action, DataSegment segment)
    • isRealtimeServer

      public boolean isRealtimeServer()
    • compareTo

      public int compareTo(ServerHolder serverHolder)
      Specified by:
      compareTo in interface Comparable<ServerHolder>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object