Class TableLoadBalancer

java.lang.Object
org.apache.accumulo.core.spi.balancer.TableLoadBalancer
All Implemented Interfaces:
TabletBalancer
Direct Known Subclasses:
HostRegexTableLoadBalancer

public class TableLoadBalancer extends Object implements TabletBalancer
TabletBalancer that balances Tablets for a Table using the TabletBalancer defined by Property.TABLE_LOAD_BALANCER. This allows for different Tables to specify different TabletBalancer classes.

Note that in versions prior to 4.0 this class would pass all known TabletServers to the Table load balancers. In version 4.0 this changed with the introduction of the "table.custom.assignment.group" table property. If defined, this balancer passes the TabletServers that have the corresponding Property.TSERV_GROUP_NAME property to the Table load balancer.

Since:
2.1.0
  • Field Details

  • Constructor Details

    • TableLoadBalancer

      public TableLoadBalancer()
  • Method Details

    • init

      public void init(BalancerEnvironment balancerEnvironment)
      Description copied from interface: TabletBalancer
      Initialize the TabletBalancer. This gives the balancer the opportunity to read the configuration.
      Specified by:
      init in interface TabletBalancer
    • getLoadBalancerClassNameForTable

      protected String getLoadBalancerClassNameForTable(TableId table)
    • getResourceGroupNameForTable

      protected ResourceGroupId getResourceGroupNameForTable(TableId tid)
    • getBalancerForTable

      protected TabletBalancer getBalancerForTable(TableId tableId)
    • getAssignments

      public void getAssignments(TabletBalancer.AssignmentParameters params)
      Description copied from interface: TabletBalancer
      Assign tablets to tablet servers. This method is called whenever the manager finds tablets that are unassigned.
      Specified by:
      getAssignments in interface TabletBalancer
    • needsReassignment

      public boolean needsReassignment(TabletBalancer.CurrentAssignment currentAssignment)
      Description copied from interface: TabletBalancer

      The manager periodically scans all tablets looking for tablets that are assigned to dead tablet servers or unassigned. During the scan this method is also called for tablets that are currently assigned to a live tserver to see if they should be unassigned and reassigned. If this method returns true the tablet will be unloaded from the tablet sever and then later the tablet will be passed to TabletBalancer.getAssignments(AssignmentParameters).

      One example use case for this method is a balancer that partitions tablet servers into groups. If the balancers config is changed such that a table that was assigned to tablet server group A should now be assigned to tablet server B, then this method can return true for the tablets in that table assigned to tablet server group A. After those tablets are unloaded and passed to the TabletBalancer.getAssignments(AssignmentParameters) method it can reassign them to tablet server group B.

      Accumulo may instantiate this plugin in different processes and call this method. When the manager looks for tablets that needs reassignment it currently uses an Accumulo iterator to scan the metadata table and filter tablets. That iterator may run on multiple tablets servers and call this plugin. Keep this in mind when implementing this plugin and considering keeping state between calls to this method.

      This new method may be used instead of or in addition to TabletBalancer.balance(BalanceParameters)

      Specified by:
      needsReassignment in interface TabletBalancer
    • balance

      public long balance(TabletBalancer.BalanceParameters params)
      Description copied from interface: TabletBalancer
      Ask the balancer if any migrations are necessary. If the balancer is going to self-abort due to some environmental constraint (e.g. it requires some minimum number of tservers, or a maximum number of outstanding migrations), it should issue a log message to alert operators. The message should be at WARN normally and at ERROR if the balancer knows that the problem can not self correct. It should not issue these messages more than once a minute. This method will not be called when there are unassigned tablets.
      Specified by:
      balance in interface TabletBalancer
      Returns:
      the time, in milliseconds, to wait before re-balancing.