Class DiskBalancer

java.lang.Object
org.apache.hadoop.hdfs.server.datanode.DiskBalancer

@Private public class DiskBalancer extends Object
Worker class for Disk Balancer.

Here is the high level logic executed by this class. Users can submit disk balancing plans using submitPlan calls. After a set of sanity checks the plan is admitted and put into workMap.

The executePlan launches a thread that picks up work from workMap and hands it over to the BlockMover#copyBlocks function.

Constraints :

Only one plan can be executing in a datanode at any given time. This is ensured by checking the future handle of the worker thread in submitPlan.

  • Field Details

    • LOG

      @VisibleForTesting public static final org.slf4j.Logger LOG
  • Constructor Details

    • DiskBalancer

      public DiskBalancer(String dataNodeUUID, org.apache.hadoop.conf.Configuration conf, DiskBalancer.BlockMover blockMover)
      Constructs a Disk Balancer object. This object takes care of reading a NodePlan and executing it against a set of volumes.
      Parameters:
      dataNodeUUID - - Data node UUID
      conf - - Hdfs Config
      blockMover - - Object that supports moving blocks.
  • Method Details

    • shutdown

      public void shutdown()
      Shutdown disk balancer services.
    • submitPlan

      public void submitPlan(String planId, long planVersion, String planFileName, String planData, boolean force) throws DiskBalancerException
      Takes a client submitted plan and converts into a set of work items that can be executed by the blockMover.
      Parameters:
      planId - - A SHA-1 of the plan string
      planVersion - - version of the plan string - for future use.
      planFileName - - Plan file name
      planData - - Plan data in json format
      force - - Skip some validations and execute the plan file.
      Throws:
      DiskBalancerException
    • queryWorkStatus

      public org.apache.hadoop.hdfs.server.datanode.DiskBalancerWorkStatus queryWorkStatus() throws DiskBalancerException
      Returns the current work status of a previously submitted Plan.
      Returns:
      DiskBalancerWorkStatus.
      Throws:
      DiskBalancerException
    • cancelPlan

      public void cancelPlan(String planID) throws DiskBalancerException
      Cancels a running plan.
      Parameters:
      planID - - Hash of the plan to cancel.
      Throws:
      DiskBalancerException
    • getVolumeNames

      public String getVolumeNames() throws DiskBalancerException
      Returns a volume ID to Volume base path map.
      Returns:
      Json string of the volume map.
      Throws:
      DiskBalancerException
    • getBandwidth

      public long getBandwidth() throws DiskBalancerException
      Returns the current bandwidth.
      Returns:
      string representation of bandwidth.
      Throws:
      DiskBalancerException
    • setDiskBalancerEnabled

      public void setDiskBalancerEnabled(boolean diskBalancerEnabled)
      Sets Disk balancer is to enable or not to enable.
      Parameters:
      diskBalancerEnabled - true, enable diskBalancer, otherwise false to disable it.
    • isDiskBalancerEnabled

      @VisibleForTesting public boolean isDiskBalancerEnabled()
      Returns the value indicating if diskBalancer is enabled.
      Returns:
      boolean.
    • setPlanValidityInterval

      public void setPlanValidityInterval(long planValidityInterval)
      Sets maximum amount of time disk balancer plan is valid.
      Parameters:
      planValidityInterval - - maximum amount of time in the unit of milliseconds.
    • getPlanValidityInterval

      @VisibleForTesting public long getPlanValidityInterval()
      Gets maximum amount of time disk balancer plan is valid.
      Returns:
      the maximum amount of time in milliseconds.
    • getPlanValidityIntervalInConfig

      @VisibleForTesting public long getPlanValidityIntervalInConfig()
      Gets maximum amount of time disk balancer plan is valid in config.
      Returns:
      the maximum amount of time in milliseconds.