Java 类org.apache.hadoop.hbase.master.LoadBalancer 实例源码

项目:HIndex    文件:SecIndexLoadBalancer.java   
@Override
public void initialize() throws HBaseIOException {
  Class<? extends LoadBalancer> delegatorKlass =
      conf.getClass(Constants.INDEX_BALANCER_DELEGATOR_CLASS, StochasticLoadBalancer.class,
        LoadBalancer.class);
  this.delegator = ReflectionUtils.newInstance(delegatorKlass, conf);
  this.delegator.setClusterStatus(clusterStatus);
  this.delegator.setMasterServices(this.master);
  try {
    HTableDescriptor desc = null;
    Map<String, HTableDescriptor> tableDescriptors = this.master.getTableDescriptors().getAll();
    for (Entry<String, HTableDescriptor> entry : tableDescriptors.entrySet()) {
      desc = entry.getValue();
      if (desc.getValue(Constants.INDEX_SPEC_KEY) != null) {
        addIndexedTable(desc.getTableName());
      }
    }
  } catch (IOException e) {
    throw new HBaseIOException(e);
  }
}
项目:HIndex    文件:IndexMasterObserver.java   
@Override
public void postDeleteTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
    TableName tableName) throws IOException {
  LOG.info("Entered into postDeleteTableHandler of table " + tableName + '.');
  MasterServices master = ctx.getEnvironment().getMasterServices();
  TableName indexTableName = TableName.valueOf(IndexUtils.getIndexTableName(tableName));
  boolean indexTablePresent =
      master.getAssignmentManager().getZKTable().isTablePresent(indexTableName);
  // Not checking for disabled state because before deleting user table both user and index table
  // should be disabled.
  if ((!IndexUtils.isIndexTable(tableName)) && indexTablePresent) {
    LoadBalancer balancer = master.getAssignmentManager().getBalancer();
    if (balancer instanceof SecIndexLoadBalancer) {
      ((SecIndexLoadBalancer) balancer).removeIndexedTable(tableName);
    }
    DeleteTableHandler dth = new DeleteTableHandler(indexTableName, master, master);
    dth.prepare();
    dth.process();
  }
  LOG.info("Exiting from postDeleteTableHandler of table " + tableName + '.');
}
项目:HIndex    文件:TestScanWhenTTLExpired.java   
@BeforeClass
public static void before() throws Exception {
  Configuration conf = TESTING_UTIL.getConfiguration();
  conf.setInt("hbase.balancer.period", 60000);
  // Needed because some tests have splits happening on RS that are killed
  // We don't want to wait 3min for the master to figure it out
  conf.setInt("hbase.master.assignment.timeoutmonitor.timeout", 4000);
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setInt("hbase.hstore.compactionThreshold",5);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  TESTING_UTIL.startMiniCluster(NB_SERVERS);

}
项目:hbase    文件:BaseLoadBalancer.java   
@Override
public void setConf(Configuration conf) {
  this.config = conf;
  setSlop(conf);
  if (slop < 0) slop = 0;
  else if (slop > 1) slop = 1;

  if (overallSlop < 0) overallSlop = 0;
  else if (overallSlop > 1) overallSlop = 1;

  this.tablesOnMaster = LoadBalancer.isTablesOnMaster(this.config);
  this.onlySystemTablesOnMaster = LoadBalancer.isSystemTablesOnlyOnMaster(this.config);
  // If system tables on master, implies tablesOnMaster = true.
  if (this.onlySystemTablesOnMaster && !this.tablesOnMaster) {
    LOG.warn("Set " + TABLES_ON_MASTER + "=true because " + SYSTEM_TABLES_ON_MASTER + "=true");
    this.tablesOnMaster = true;
  }
  this.rackManager = new RackManager(getConf());
  if (useRegionFinder) {
    regionFinder.setConf(conf);
  }
  // Print out base configs. Don't print overallSlop since it for simple balancer exclusively.
  LOG.info("slop=" + this.slop + ", tablesOnMaster=" + this.tablesOnMaster +
    ", systemTablesOnMaster=" + this.onlySystemTablesOnMaster);
}
项目:hbase    文件:TestMultiParallel.java   
@BeforeClass public static void beforeClass() throws Exception {
  // Uncomment the following lines if more verbosity is needed for
  // debugging (see HBASE-12285 for details).
  //((Log4JLogger)RpcServer.LOG).getLogger().setLevel(Level.ALL);
  //((Log4JLogger)RpcClient.LOG).getLogger().setLevel(Level.ALL);
  //((Log4JLogger)ScannerCallable.LOG).getLogger().setLevel(Level.ALL);
  UTIL.getConfiguration().set(HConstants.RPC_CODEC_CONF_KEY,
      KeyValueCodec.class.getCanonicalName());
  UTIL.getConfiguration().setBoolean(LoadBalancer.TABLES_ON_MASTER, true);
  // We used to ask for system tables on Master exclusively but not needed by test and doesn't
  // work anyways -- so commented out.
  // UTIL.getConfiguration().setBoolean(LoadBalancer.SYSTEM_TABLES_ON_MASTER, true);
  UTIL.getConfiguration()
      .set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyMasterObserver.class.getName());
  UTIL.startMiniCluster(slaves);
  Table t = UTIL.createMultiRegionTable(TEST_TABLE, Bytes.toBytes(FAMILY));
  UTIL.waitTableEnabled(TEST_TABLE);
  t.close();
  CONNECTION = ConnectionFactory.createConnection(UTIL.getConfiguration());
  assertTrue(MyMasterObserver.start.get());
}
项目:hbase    文件:TestFavoredStochasticLoadBalancer.java   
@Test
public void testRoundRobinAssignment() throws Exception {

  TableName tableName = TableName.valueOf("testRoundRobinAssignment");
  HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
  admin.createTable(desc, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGION_NUM);
  TEST_UTIL.waitTableAvailable(tableName);
  TEST_UTIL.loadTable(admin.getConnection().getTable(tableName), HConstants.CATALOG_FAMILY);
  admin.flush(tableName);

  LoadBalancer balancer = master.getLoadBalancer();
  List<RegionInfo> regions = admin.getRegions(tableName);
  regions.addAll(admin.getTableRegions(TableName.META_TABLE_NAME));
  regions.addAll(admin.getTableRegions(TableName.NAMESPACE_TABLE_NAME));
  List<ServerName> servers = Lists.newArrayList(
    admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet());
  Map<ServerName, List<RegionInfo>> map = balancer.roundRobinAssignment(regions, servers);
  for (List<RegionInfo> regionInfos : map.values()) {
    regions.removeAll(regionInfos);
  }
  assertEquals("No region should be missed by balancer", 0, regions.size());
}
项目:hbase    文件:TestRegionServerReadRequestMetrics.java   
@BeforeClass
public static void setUpOnce() throws Exception {
  // Default starts one regionserver only.
  TEST_UTIL.getConfiguration().setBoolean(LoadBalancer.TABLES_ON_MASTER, true);
  // TEST_UTIL.getConfiguration().setBoolean(LoadBalancer.SYSTEM_TABLES_ON_MASTER, true);
  TEST_UTIL.startMiniCluster();
  admin = TEST_UTIL.getAdmin();
  serverNames = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS))
    .getLiveServerMetrics().keySet();
  table = createTable();
  putData();
  List<RegionInfo> regions = admin.getRegions(TABLE_NAME);
  assertEquals("Table " + TABLE_NAME + " should have 1 region", 1, regions.size());
  regionInfo = regions.get(0);

  for (Metric metric : Metric.values()) {
    requestsMap.put(metric, 0L);
    requestsMapPrev.put(metric, 0L);
  }
}
项目:hbase    文件:TestClusterId.java   
@Test
public void testRewritingClusterIdToPB() throws Exception {
  TEST_UTIL.startMiniZKCluster();
  TEST_UTIL.startMiniDFSCluster(1);
  TEST_UTIL.createRootDir();
  Path rootDir = FSUtils.getRootDir(TEST_UTIL.getConfiguration());
  FileSystem fs = rootDir.getFileSystem(TEST_UTIL.getConfiguration());
  Path filePath = new Path(rootDir, HConstants.CLUSTER_ID_FILE_NAME);
  FSDataOutputStream s = null;
  try {
    s = fs.create(filePath);
    s.writeUTF(UUID.randomUUID().toString());
  } finally {
    if (s != null) {
      s.close();
    }
  }
  TEST_UTIL.startMiniHBaseCluster(1, 1);
  HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
  int expected = LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration())? 2: 1;
  assertEquals(expected, master.getServerManager().getOnlineServersList().size());
}
项目:hbase    文件:RSGroupBasedLoadBalancer.java   
@Override
public Map<ServerName, List<RegionInfo>> roundRobinAssignment(
    List<RegionInfo> regions, List<ServerName> servers) throws HBaseIOException {
  Map<ServerName, List<RegionInfo>> assignments = Maps.newHashMap();
  ListMultimap<String,RegionInfo> regionMap = ArrayListMultimap.create();
  ListMultimap<String,ServerName> serverMap = ArrayListMultimap.create();
  generateGroupMaps(regions, servers, regionMap, serverMap);
  for(String groupKey : regionMap.keySet()) {
    if (regionMap.get(groupKey).size() > 0) {
      Map<ServerName, List<RegionInfo>> result =
          this.internalBalancer.roundRobinAssignment(
              regionMap.get(groupKey),
              serverMap.get(groupKey));
      if(result != null) {
        if(result.containsKey(LoadBalancer.BOGUS_SERVER_NAME) &&
            assignments.containsKey(LoadBalancer.BOGUS_SERVER_NAME)){
          assignments.get(LoadBalancer.BOGUS_SERVER_NAME).addAll(
            result.get(LoadBalancer.BOGUS_SERVER_NAME));
        } else {
          assignments.putAll(result);
        }
      }
    }
  }
  return assignments;
}
项目:hbase    文件:RSGroupBasedLoadBalancer.java   
private void generateGroupMaps(
  List<RegionInfo> regions,
  List<ServerName> servers,
  ListMultimap<String, RegionInfo> regionMap,
  ListMultimap<String, ServerName> serverMap) throws HBaseIOException {
  try {
    for (RegionInfo region : regions) {
      String groupName = rsGroupInfoManager.getRSGroupOfTable(region.getTable());
      if (groupName == null) {
        LOG.warn("Group for table "+region.getTable()+" is null");
      }
      regionMap.put(groupName, region);
    }
    for (String groupKey : regionMap.keySet()) {
      RSGroupInfo info = rsGroupInfoManager.getRSGroup(groupKey);
      serverMap.putAll(groupKey, filterOfflineServers(info, servers));
      if(serverMap.get(groupKey).size() < 1) {
        serverMap.put(groupKey, LoadBalancer.BOGUS_SERVER_NAME);
      }
    }
  } catch(IOException e) {
    throw new HBaseIOException("Failed to generate group maps", e);
  }
}
项目:hbase    文件:RSGroupBasedLoadBalancer.java   
@Override
public void initialize() throws HBaseIOException {
  try {
    if (rsGroupInfoManager == null) {
      List<RSGroupAdminEndpoint> cps =
        masterServices.getMasterCoprocessorHost().findCoprocessors(RSGroupAdminEndpoint.class);
      if (cps.size() != 1) {
        String msg = "Expected one implementation of GroupAdminEndpoint but found " + cps.size();
        LOG.error(msg);
        throw new HBaseIOException(msg);
      }
      rsGroupInfoManager = cps.get(0).getGroupInfoManager();
    }
  } catch (IOException e) {
    throw new HBaseIOException("Failed to initialize GroupInfoManagerImpl", e);
  }

  // Create the balancer
  Class<? extends LoadBalancer> balancerKlass = config.getClass(HBASE_RSGROUP_LOADBALANCER_CLASS,
      StochasticLoadBalancer.class, LoadBalancer.class);
  internalBalancer = ReflectionUtils.newInstance(balancerKlass, config);
  internalBalancer.setMasterServices(masterServices);
  internalBalancer.setClusterMetrics(clusterStatus);
  internalBalancer.setConf(config);
  internalBalancer.initialize();
}
项目:ditb    文件:LoadBalancerFactory.java   
/**
 * Create a loadbalancer from the given conf.
 * @param conf
 * @return A {@link LoadBalancer}
 */
public static LoadBalancer getLoadBalancer(Configuration conf) {

  // Create the balancer
  Class<? extends LoadBalancer> balancerKlass =
      conf.getClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, getDefaultLoadBalancerClass(),
        LoadBalancer.class);
  return ReflectionUtils.newInstance(balancerKlass, conf);

}
项目:ditb    文件:TestZooKeeper.java   
/**
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // Test we can first start the ZK cluster by itself
  Configuration conf = TEST_UTIL.getConfiguration();
  TEST_UTIL.startMiniDFSCluster(2);
  TEST_UTIL.startMiniZKCluster();
  conf.setBoolean("dfs.support.append", true);
  conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, MockLoadBalancer.class,
      LoadBalancer.class);
}
项目:pbase    文件:LoadBalancerFactory.java   
/**
 * Create a loadbalancer from the given conf.
 * @param conf
 * @return A {@link LoadBalancer}
 */
public static LoadBalancer getLoadBalancer(Configuration conf) {

  // Create the balancer
  Class<? extends LoadBalancer> balancerKlass =
      conf.getClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, StochasticLoadBalancer.class,
        LoadBalancer.class);
  return ReflectionUtils.newInstance(balancerKlass, conf);

}
项目:pbase    文件:ClusterStatusChore.java   
public ClusterStatusChore(HMaster master, LoadBalancer balancer) {
  super(master.getServerName() + "-ClusterStatusChore",
        master.getConfiguration().getInt("hbase.balancer.statusPeriod", 60000),
        master);
  this.master = master;
  this.balancer = balancer;
}
项目:pbase    文件:TestZooKeeper.java   
/**
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // Test we can first start the ZK cluster by itself
  Configuration conf = TEST_UTIL.getConfiguration();
  TEST_UTIL.startMiniDFSCluster(2);
  TEST_UTIL.startMiniZKCluster();
  conf.setBoolean("dfs.support.append", true);
  conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, MockLoadBalancer.class,
      LoadBalancer.class);
}
项目:HIndex    文件:LoadBalancerFactory.java   
/**
 * Create a loadbalancer from the given conf.
 * @param conf
 * @return A {@link LoadBalancer}
 */
public static LoadBalancer getLoadBalancer(Configuration conf) {

  // Create the balancer
  Class<? extends LoadBalancer> balancerKlass =
      conf.getClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, StochasticLoadBalancer.class,
        LoadBalancer.class);
  return ReflectionUtils.newInstance(balancerKlass, conf);

}
项目:HIndex    文件:ClusterStatusChore.java   
public ClusterStatusChore(HMaster master, LoadBalancer balancer) {
  super(master.getServerName() + "-ClusterStatusChore",
        master.getConfiguration().getInt("hbase.balancer.statusPeriod", 60000),
        master);
  this.master = master;
  this.balancer = balancer;
}
项目:HIndex    文件:TestZooKeeper.java   
/**
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // Test we can first start the ZK cluster by itself
  Configuration conf = TEST_UTIL.getConfiguration();
  TEST_UTIL.startMiniDFSCluster(2);
  TEST_UTIL.startMiniZKCluster();
  conf.setBoolean("dfs.support.append", true);
  conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, MockLoadBalancer.class,
      LoadBalancer.class);
}
项目:HIndex    文件:IndexMasterObserver.java   
@Override
public void preCreateTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
    HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
  if (desc.getValue(Constants.INDEX_SPEC_KEY) != null) {
    LoadBalancer balancer =
        ctx.getEnvironment().getMasterServices().getAssignmentManager().getBalancer();
    if (balancer instanceof SecIndexLoadBalancer) {
      ((SecIndexLoadBalancer) balancer).addIndexedTable(desc.getTableName());
    }
  }
}
项目:HIndex    文件:IndexMasterObserver.java   
@Override
public void postAssign(ObserverContext<MasterCoprocessorEnvironment> ctx, HRegionInfo regionInfo)
    throws IOException {
  LOG.info("Entering into postAssign of region " + regionInfo.getRegionNameAsString() + '.');

  if (!IndexUtils.isIndexTable(regionInfo.getTable().getName())) {
    MasterServices master = ctx.getEnvironment().getMasterServices();
    LoadBalancer balancer = master.getAssignmentManager().getBalancer();
    AssignmentManager am = master.getAssignmentManager();
    RegionStates regionStates = am.getRegionStates();
    // waiting until user region is removed from transition.
    long timeout =
        master.getConfiguration()
            .getLong("hbase.bulk.assignment.waiton.empty.rit", 5 * 60 * 1000);
    try {
      am.waitOnRegionToClearRegionsInTransition(regionInfo, timeout);
    } catch (InterruptedException e) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Interrupted while region in assignment.");
      }
    }
    ServerName sn = regionStates.getRegionServerOfRegion(regionInfo);
    TableName indexTableName =
        TableName.valueOf(IndexUtils.getIndexTableName(regionInfo.getTableName()));
    List<HRegionInfo> tableRegions = regionStates.getRegionsOfTable(indexTableName);
    for (HRegionInfo hRegionInfo : tableRegions) {
      if (0 == Bytes.compareTo(hRegionInfo.getStartKey(), regionInfo.getStartKey())) {
        am.addPlan(hRegionInfo.getEncodedName(), new RegionPlan(hRegionInfo, null, sn));
        LOG.info("Assigning region " + hRegionInfo.getRegionNameAsString() + " to server " + sn
            + '.');
        balancer.regionOnline(hRegionInfo, sn);
        am.assign(hRegionInfo, true, false);
        break;
      }
    }
  }
  LOG.info("Exiting from postAssign " + regionInfo.getRegionNameAsString() + '.');
}
项目:HIndex    文件:TestValuePartitionInScan.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.hregion.scan.loadColumnFamiliesOnDemand", false);
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  UTIL.startMiniCluster(1);
  admin = new IndexAdmin(conf);
}
项目:HIndex    文件:TestSecIndexColocator.java   
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  UTIL.startMiniCluster(2);
  admin = new IndexAdmin(conf);
}
项目:HIndex    文件:TestSecIndexLoadBalancer.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  final int NUM_MASTERS = 1;
  final int NUM_RS = 4;
  Configuration conf = UTIL.getConfiguration();
  conf.setBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO,true);
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
  admin = new IndexAdmin(UTIL.getConfiguration());
}
项目:HIndex    文件:TestIndexMapReduceUtil.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  UTIL.startMiniCluster(1);
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.setBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO,true);
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set("index.data.block.encoding.algo", "PREFIX");
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  UTIL.startMiniCluster(1);
  admin = new IndexAdmin(conf);
}
项目:HIndex    文件:TestForComplexIssues.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, LocalIndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
}
项目:HIndex    文件:TestAcidGuaranteesForIndex.java   
public TestAcidGuaranteesForIndex() {
  // Set small flush size for minicluster so we exercise reseeking scanners
  Configuration conf = HBaseConfiguration.create();
  conf.set(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, String.valueOf(128 * 1024));
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  util = new HBaseTestingUtility(conf);
}
项目:HIndex    文件:TestIndexPutsWithRegionServerRestart.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, MockIndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  UTIL.startMiniCluster(1);
  admin = new IndexAdmin(conf);

}
项目:HIndex    文件:TestIndexRegionObserver.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, MockIndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  conf.setInt("hbase.hstore.compactionThreshold",5);
  UTIL.startMiniCluster(1);
  admin = new IndexAdmin(conf);
}
项目:HIndex    文件:TestIndexRegionObserverForScan.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  UTIL.startMiniCluster(1);
  admin = new IndexAdmin(conf);
}
项目:HIndex    文件:TestMultipleIndicesInScan.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  UTIL.startMiniCluster(1);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  admin = new IndexAdmin(conf);
}
项目:HIndex    文件:TestIndexHalfStoreFileReader.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  UTIL.startMiniCluster(1);
  admin = new IndexAdmin(conf);
}
项目:HIndex    文件:TestIndexHalfStoreFileReaderWithEncoding.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
  conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
  conf.setBoolean("hbase.use.secondary.index", true);
  conf.set("index.data.block.encoding.algo", "PREFIX");
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, SecIndexLoadBalancer.class,
    LoadBalancer.class);
  UTIL.startMiniCluster(1);
}
项目:hbase    文件:LoadBalancerFactory.java   
/**
 * Create a loadbalancer from the given conf.
 * @param conf
 * @return A {@link LoadBalancer}
 */
public static LoadBalancer getLoadBalancer(Configuration conf) {

  // Create the balancer
  Class<? extends LoadBalancer> balancerKlass =
      conf.getClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, getDefaultLoadBalancerClass(),
        LoadBalancer.class);
  return ReflectionUtils.newInstance(balancerKlass, conf);

}
项目:hbase    文件:BaseLoadBalancer.java   
/**
 * Used to assign a single region to a random server.
 */
@Override
public ServerName randomAssignment(RegionInfo regionInfo, List<ServerName> servers)
    throws HBaseIOException {
  metricsBalancer.incrMiscInvocations();
  if (servers != null && servers.contains(masterServerName)) {
    if (shouldBeOnMaster(regionInfo)) {
      return masterServerName;
    }
    if (!LoadBalancer.isTablesOnMaster(getConf())) {
      // Guarantee we do not put any regions on master
      servers = new ArrayList<>(servers);
      servers.remove(masterServerName);
    }
  }

  int numServers = servers == null ? 0 : servers.size();
  if (numServers == 0) {
    LOG.warn("Wanted to retain assignment but no servers to assign to");
    return null;
  }
  if (numServers == 1) { // Only one server, nothing fancy we can do here
    return servers.get(0);
  }
  List<ServerName> idleServers = findIdleServers(servers);
  if (idleServers.size() == 1) {
    return idleServers.get(0);
  }
  final List<ServerName> finalServers = idleServers.isEmpty() ?
          servers : idleServers;
  List<RegionInfo> regions = Lists.newArrayList(regionInfo);
  Cluster cluster = createCluster(finalServers, regions, false);
  return randomAssignment(cluster, regionInfo, finalServers);
}
项目:hbase    文件:HRegionServer.java   
/**
 * Load the replication executorService objects, if any
 */
private static void createNewReplicationInstance(Configuration conf, HRegionServer server,
    FileSystem walFs, Path walDir, Path oldWALDir, WALProvider walProvider) throws IOException {
  if ((server instanceof HMaster) &&
    (!LoadBalancer.isTablesOnMaster(conf) || LoadBalancer.isSystemTablesOnlyOnMaster(conf))) {
    return;
  }

  // read in the name of the source replication class from the config file.
  String sourceClassname = conf.get(HConstants.REPLICATION_SOURCE_SERVICE_CLASSNAME,
    HConstants.REPLICATION_SERVICE_CLASSNAME_DEFAULT);

  // read in the name of the sink replication class from the config file.
  String sinkClassname = conf.get(HConstants.REPLICATION_SINK_SERVICE_CLASSNAME,
    HConstants.REPLICATION_SERVICE_CLASSNAME_DEFAULT);

  // If both the sink and the source class names are the same, then instantiate
  // only one object.
  if (sourceClassname.equals(sinkClassname)) {
    server.replicationSourceHandler = newReplicationInstance(sourceClassname,
      ReplicationSourceService.class, conf, server, walFs, walDir, oldWALDir, walProvider);
    server.replicationSinkHandler = (ReplicationSinkService) server.replicationSourceHandler;
  } else {
    server.replicationSourceHandler = newReplicationInstance(sourceClassname,
      ReplicationSourceService.class, conf, server, walFs, walDir, oldWALDir, walProvider);
    server.replicationSinkHandler = newReplicationInstance(sinkClassname,
      ReplicationSinkService.class, conf, server, walFs, walDir, oldWALDir, walProvider);
  }
}
项目:hbase    文件:TestZooKeeper.java   
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // Test we can first start the ZK cluster by itself
  Configuration conf = TEST_UTIL.getConfiguration();
  TEST_UTIL.startMiniDFSCluster(2);
  TEST_UTIL.startMiniZKCluster();
  conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, MockLoadBalancer.class,
      LoadBalancer.class);
}
项目:hbase    文件:TestAdmin1.java   
protected void verifyRoundRobinDistribution(ClusterConnection c, RegionLocator regionLocator, int
    expectedRegions) throws IOException {
  int numRS = c.getCurrentNrHRS();
  List<HRegionLocation> regions = regionLocator.getAllRegionLocations();
  Map<ServerName, List<RegionInfo>> server2Regions = new HashMap<>();
  for (HRegionLocation loc : regions) {
    ServerName server = loc.getServerName();
    List<RegionInfo> regs = server2Regions.get(server);
    if (regs == null) {
      regs = new ArrayList<>();
      server2Regions.put(server, regs);
    }
    regs.add(loc.getRegionInfo());
  }
  boolean tablesOnMaster = LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration());
  if (tablesOnMaster) {
    // Ignore the master region server,
    // which contains less regions by intention.
    numRS--;
  }
  float average = (float) expectedRegions/numRS;
  int min = (int)Math.floor(average);
  int max = (int)Math.ceil(average);
  for (List<RegionInfo> regionList : server2Regions.values()) {
    assertTrue("numRS=" + numRS + ", min=" + min + ", max=" + max +
      ", size=" + regionList.size() + ", tablesOnMaster=" + tablesOnMaster,
    regionList.size() == min || regionList.size() == max);
  }
}
项目:hbase    文件:TestFromClientSide.java   
/**
 * test of that unmanaged HConnections are able to reconnect
 * properly (see HBASE-5058)
 */
@Test
public void testUnmanagedHConnectionReconnect() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY);
  Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
  Table t = conn.getTable(tableName);
  try (Admin admin = conn.getAdmin()) {
    assertTrue(admin.tableExists(tableName));
    assertTrue(t.get(new Get(ROW)).isEmpty());
  }

  // stop the master
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  cluster.stopMaster(0, false);
  cluster.waitOnMaster(0);

  // start up a new master
  cluster.startMaster();
  assertTrue(cluster.waitForActiveAndReadyMaster());

  // test that the same unmanaged connection works with a new
  // Admin and can connect to the new master;
  boolean tablesOnMaster = LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration());
  try (Admin admin = conn.getAdmin()) {
    assertTrue(admin.tableExists(tableName));
    assertTrue(admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS))
        .getLiveServerMetrics().size() == SLAVES + (tablesOnMaster ? 1 : 0));
  }
}