Review Board 1.6.3

HBASE-3305 Allow round-robin distribution for table created with multiple regions

Review Request #1271 - updated 3 years, 4 months ago

Ted Yu Reviewers
trunk hbase
HBASE-3305 stack, jgray
None hbase svn
Adopted round-robin assignment as default for regions specified when table is created.
Put unit tests for this change inside TestAdmin.testCreateTableWithRegions()
They passed.
trunk/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
Revision 1043216 New Change
... 48 lines hidden [Expand]
49
import org.apache.hadoop.hbase.Stoppable;
49
import org.apache.hadoop.hbase.Stoppable;
50
import org.apache.hadoop.hbase.catalog.CatalogTracker;
50
import org.apache.hadoop.hbase.catalog.CatalogTracker;
51
import org.apache.hadoop.hbase.catalog.MetaReader;
51
import org.apache.hadoop.hbase.catalog.MetaReader;
52
import org.apache.hadoop.hbase.catalog.RootLocationEditor;
52
import org.apache.hadoop.hbase.catalog.RootLocationEditor;
53
import org.apache.hadoop.hbase.client.Result;
53
import org.apache.hadoop.hbase.client.Result;
54
import org.apache.hadoop.hbase.executor.EventHandler.EventType;

   
55
import org.apache.hadoop.hbase.executor.ExecutorService;
54
import org.apache.hadoop.hbase.executor.ExecutorService;
56
import org.apache.hadoop.hbase.executor.RegionTransitionData;
55
import org.apache.hadoop.hbase.executor.RegionTransitionData;
57
import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
56
import org.apache.hadoop.hbase.executor.EventHandler.EventType;
58
import org.apache.hadoop.hbase.master.LoadBalancer.RegionPlan;
57
import org.apache.hadoop.hbase.master.LoadBalancer.RegionPlan;
59
import org.apache.hadoop.hbase.master.handler.ClosedRegionHandler;
58
import org.apache.hadoop.hbase.master.handler.ClosedRegionHandler;
60
import org.apache.hadoop.hbase.master.handler.OpenedRegionHandler;
59
import org.apache.hadoop.hbase.master.handler.OpenedRegionHandler;
61
import org.apache.hadoop.hbase.master.handler.ServerShutdownHandler;
60
import org.apache.hadoop.hbase.master.handler.ServerShutdownHandler;
62
import org.apache.hadoop.hbase.util.Bytes;
61
import org.apache.hadoop.hbase.util.Bytes;
63
import org.apache.hadoop.hbase.util.Pair;
62
import org.apache.hadoop.hbase.util.Pair;
64
import org.apache.hadoop.hbase.util.Threads;
63
import org.apache.hadoop.hbase.util.Threads;
65
import org.apache.hadoop.hbase.zookeeper.ZKAssign;
64
import org.apache.hadoop.hbase.zookeeper.ZKAssign;
66
import org.apache.hadoop.hbase.zookeeper.ZKTable;
65
import org.apache.hadoop.hbase.zookeeper.ZKTable;
67
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
66
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
68
import org.apache.hadoop.hbase.zookeeper.ZKUtil.NodeAndData;

   
69
import org.apache.hadoop.hbase.zookeeper.ZooKeeperListener;
67
import org.apache.hadoop.hbase.zookeeper.ZooKeeperListener;
70
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
68
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

   
69
import org.apache.hadoop.hbase.zookeeper.ZKUtil.NodeAndData;
71
import org.apache.hadoop.io.Writable;
70
import org.apache.hadoop.io.Writable;
72
import org.apache.hadoop.ipc.RemoteException;
71
import org.apache.hadoop.ipc.RemoteException;
73
import org.apache.zookeeper.AsyncCallback;
72
import org.apache.zookeeper.AsyncCallback;
74
import org.apache.zookeeper.KeeperException;
73
import org.apache.zookeeper.KeeperException;
75
import org.apache.zookeeper.KeeperException.NoNodeException;
74
import org.apache.zookeeper.KeeperException.NoNodeException;
... 1046 lines hidden [Expand]
public void assignRoot() throws KeeperException {
1122
    // Force assignment to a random server
1121
    // Force assignment to a random server
1123
    assign(HRegionInfo.FIRST_META_REGIONINFO, true);
1122
    assign(HRegionInfo.FIRST_META_REGIONINFO, true);
1124
  }
1123
  }
1125

   
1124

   
1126
  /**
1125
  /**

   
1126
   * Assigns list of user regions in round-robin fashion, if any exist.

   
1127
   * <p>

   
1128
   * This is a synchronous call and will return once every region has been

   
1129
   * assigned.  If anything fails, an exception is thrown

   
1130
   * @throws InterruptedException

   
1131
   * @throws IOException

   
1132
   */

   
1133
  public void assignUserRegions(List<HRegionInfo> regions, List<HServerInfo> servers) throws IOException, InterruptedException {

   
1134
    if (regions == null)

   
1135
      return;

   
1136
    Map<HServerInfo, List<HRegionInfo>> bulkPlan = null;

   
1137
    // Generate a round-robin bulk assignment plan

   
1138
    bulkPlan = LoadBalancer.roundRobinAssignment(regions, servers);

   
1139
    LOG.info("Bulk assigning " + regions.size() + " region(s) round-robin across " +

   
1140
               servers.size() + " server(s)");

   
1141
    // Use fixed count thread pool assigning.

   
1142
    BulkAssigner ba = new BulkStartupAssigner(this.master, bulkPlan, this);

   
1143
    ba.bulkAssign();

   
1144
    LOG.info("Bulk assigning done");

   
1145
  }

   
1146

   

   
1147
  /**
1127
   * Assigns all user regions, if any exist.  Used during cluster startup.
1148
   * Assigns all user regions, if any exist.  Used during cluster startup.
1128
   * <p>
1149
   * <p>
1129
   * This is a synchronous call and will return once every region has been
1150
   * This is a synchronous call and will return once every region has been
1130
   * assigned.  If anything fails, an exception is thrown and the cluster
1151
   * assigned.  If anything fails, an exception is thrown and the cluster
1131
   * should be shutdown.
1152
   * should be shutdown.
... 16 lines hidden [Expand]
public void assignAllUserRegions() throws IOException, InterruptedException {
1148
    Map<HServerInfo, List<HRegionInfo>> bulkPlan = null;
1169
    Map<HServerInfo, List<HRegionInfo>> bulkPlan = null;
1149
    if (retainAssignment) {
1170
    if (retainAssignment) {
1150
      // Reuse existing assignment info
1171
      // Reuse existing assignment info
1151
      bulkPlan = LoadBalancer.retainAssignment(allRegions, servers);
1172
      bulkPlan = LoadBalancer.retainAssignment(allRegions, servers);
1152
    } else {
1173
    } else {
1153
      // Generate a round-robin bulk assignment plan
1174
      // assign regions in round-robin fashion
1154
      bulkPlan = LoadBalancer.roundRobinAssignment(
1175
      assignUserRegions(new ArrayList<HRegionInfo>(allRegions.keySet()), servers);
1155
          new ArrayList<HRegionInfo>(allRegions.keySet()), servers);
1176
      return;
1156
    }
1177
    }
1157
    LOG.info("Bulk assigning " + allRegions.size() + " region(s) across " +
1178
    LOG.info("Bulk assigning " + allRegions.size() + " region(s) across " +
1158
      servers.size() + " server(s), retainAssignment=" + retainAssignment);
1179
      servers.size() + " server(s), retainAssignment=" + retainAssignment);
1159

   
1180

   
1160
    // Use fixed count thread pool assigning.
1181
    // Use fixed count thread pool assigning.
... 696 lines hidden [Expand]
trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
Revision 1043216 New Change
 
trunk/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java
Revision 1043216 New Change
 
trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
Revision 1043216 New Change
 
  1. trunk/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java: Loading...
  2. trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java: Loading...
  3. trunk/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java: Loading...
  4. trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java: Loading...