Java Code Examples for org.apache.hadoop.hbase.ServerName#getHostname()

The following examples show how to use org.apache.hadoop.hbase.ServerName#getHostname() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Get a unique key for the rpc stub to the given server.
 */
static String getStubKey(String serviceName, ServerName serverName, boolean hostnameCanChange) {
  // Sometimes, servers go down and they come back up with the same hostname but a different
  // IP address. Force a resolution of the rsHostname by trying to instantiate an
  // InetSocketAddress, and this way we will rightfully get a new stubKey.
  // Also, include the hostname in the key so as to take care of those cases where the
  // DNS name is different but IP address remains the same.
  String hostname = serverName.getHostname();
  int port = serverName.getPort();
  if (hostnameCanChange) {
    try {
      InetAddress ip = InetAddress.getByName(hostname);
      return serviceName + "@" + hostname + "-" + ip.getHostAddress() + ":" + port;
    } catch (UnknownHostException e) {
      LOG.warn("Can not resolve " + hostname + ", please check your network", e);
    }
  }
  return serviceName + "@" + hostname + ":" + port;
}
 
Example 2
Source File: FillDiskCommandAction.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected void localPerform() throws IOException {
  getLogger().info("Starting to execute FillDiskCommandAction");
  ServerName server = PolicyBasedChaosMonkey.selectRandomItem(getCurrentServers());
  String hostname = server.getHostname();

  try {
    clusterManager.execSudo(hostname, duration, getFillCommand());
  } catch (IOException ex) {
    getLogger().info("Potential timeout. We try to stop the dd process on target machine");
    clusterManager.execSudoWithRetries(hostname, timeout, getStopCommand());
    throw ex;
  } finally {
    clusterManager.execSudoWithRetries(hostname, timeout, getClearCommand());
    getLogger().info("Finished to execute FillDiskCommandAction");
  }
}
 
Example 3
Source File: LosePacketsCommandAction.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected void localPerform() throws IOException {
  getLogger().info("Starting to execute LosePacketsCommandAction");
  ServerName server = PolicyBasedChaosMonkey.selectRandomItem(getCurrentServers());
  String hostname = server.getHostname();

  try {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(ADD));
    Thread.sleep(duration);
  } catch (InterruptedException e) {
    getLogger().debug("Failed to run the command for the full duration", e);
  } finally {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(DELETE));
  }

  getLogger().info("Finished to execute LosePacketsCommandAction");
}
 
Example 4
Source File: ReorderPacketsCommandAction.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected void localPerform() throws IOException {
  getLogger().info("Starting to execute ReorderPacketsCommandAction");
  ServerName server = PolicyBasedChaosMonkey.selectRandomItem(getCurrentServers());
  String hostname = server.getHostname();

  try {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(ADD));
    Thread.sleep(duration);
  } catch (InterruptedException e) {
    getLogger().debug("Failed to run the command for the full duration", e);
  } finally {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(DELETE));
  }

  getLogger().info("Finished to execute ReorderPacketsCommandAction");
}
 
Example 5
Source File: CorruptPacketsCommandAction.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected void localPerform() throws IOException {
  getLogger().info("Starting to execute CorruptPacketsCommandAction");
  ServerName server = PolicyBasedChaosMonkey.selectRandomItem(getCurrentServers());
  String hostname = server.getHostname();

  try {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(ADD));
    Thread.sleep(duration);
  } catch (InterruptedException e) {
    getLogger().debug("Failed to run the command for the full duration", e);
  } finally {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(DELETE));
  }

  getLogger().info("Finished to execute CorruptPacketsCommandAction");
}
 
Example 6
Source File: DuplicatePacketsCommandAction.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected void localPerform() throws IOException {
  getLogger().info("Starting to execute DuplicatePacketsCommandAction");
  ServerName server = PolicyBasedChaosMonkey.selectRandomItem(getCurrentServers());
  String hostname = server.getHostname();

  try {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(ADD));
    Thread.sleep(duration);
  } catch (InterruptedException e) {
    getLogger().debug("Failed to run the command for the full duration", e);
  } finally {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(DELETE));
  }

  getLogger().info("Finished to execute DuplicatePacketsCommandAction");
}
 
Example 7
Source File: DelayPacketsCommandAction.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected void localPerform() throws IOException {
  getLogger().info("Starting to execute DelayPacketsCommandAction");
  ServerName server = PolicyBasedChaosMonkey.selectRandomItem(getCurrentServers());
  String hostname = server.getHostname();

  try {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(ADD));
    Thread.sleep(duration);
  } catch (InterruptedException e) {
    getLogger().debug("Failed to run the command for the full duration", e);
  } finally {
    clusterManager.execSudoWithRetries(hostname, timeout, getCommand(DELETE));
  }

  getLogger().info("Finished to execute DelayPacketsCommandAction");
}
 
Example 8
Source File: AbstractRpcClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
InetSocketAddress createAddr(ServerName sn) throws UnknownHostException {
  InetSocketAddress addr = new InetSocketAddress(sn.getHostname(), sn.getPort());
  if (addr.isUnresolved()) {
    throw new UnknownHostException("can not resolve " + sn.getServerName());
  }
  return addr;
}
 
Example 9
Source File: MCTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testMC_RS() throws Exception {
    // move each RS has one region
    splitTable("c".getBytes());
    ArrayList<ServerName> serverNameList = getServerNameList();
    assertTrue(serverNameList.size() >= 2);
    ArrayList<HRegionInfo> regionInfoList = getRegionInfoList(tableName);
    assertEquals(2, regionInfoList.size());
    HRegionInfo regionInfo1 = regionInfoList.get(0);
    HRegionInfo regionInfo2 = regionInfoList.get(1);
    ServerName serverName1 = serverNameList.get(0);
    ServerName serverName2 = serverNameList.get(1);
    move(regionInfo1, serverName1);
    move(regionInfo2, serverName2);

    // make 2 + 2 store files
    putData(table, "a".getBytes());
    admin.flush(tableName);
    putData(table, "b".getBytes());
    admin.flush(tableName);
    putData(table, "c".getBytes());
    admin.flush(tableName);
    putData(table, "d".getBytes());
    admin.flush(tableName);
    Thread.sleep(3000);
    assertEquals(2, getRegionLoad(regionInfo1, serverName1).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName2).getStorefiles());

    // run MC
    String regex = serverName1.getHostname() + "," + serverName1.getPort() + ".*";
    String[] argsParam = {"zookeeper", tableName, "--rs=" + regex, "--force-proceed", "--wait", "--test"};
    Args args = new ManagerArgs(argsParam);
    MC command = new MC(admin, args);
    command.run();
    assertRegionName(command);

    // should be 1 store file
    assertEquals(1, getRegionLoad(regionInfo1, serverName1).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName2).getStorefiles());
}
 
Example 10
Source File: MCTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testMC_RS() throws Exception {
    // move each RS has one region
    splitTable("c".getBytes());
    ArrayList<ServerName> serverNameList = getServerNameList();
    assertTrue(serverNameList.size() >= 2);
    ArrayList<HRegionInfo> regionInfoList = getRegionInfoList(tableName);
    assertEquals(2, regionInfoList.size());
    HRegionInfo regionInfo1 = regionInfoList.get(0);
    HRegionInfo regionInfo2 = regionInfoList.get(1);
    ServerName serverName1 = serverNameList.get(0);
    ServerName serverName2 = serverNameList.get(1);
    move(regionInfo1, serverName1);
    move(regionInfo2, serverName2);

    // make 2 + 2 store files
    putData(table, "a".getBytes());
    admin.flush(tableName);
    putData(table, "b".getBytes());
    admin.flush(tableName);
    putData(table, "c".getBytes());
    admin.flush(tableName);
    putData(table, "d".getBytes());
    admin.flush(tableName);
    Thread.sleep(3000);
    assertEquals(2, getRegionLoad(regionInfo1, serverName1).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName2).getStorefiles());

    // run MC
    String regex = serverName1.getHostname() + "," + serverName1.getPort() + ".*";
    String[] argsParam = {"zookeeper", tableName, "--rs=" + regex, "--force-proceed", "--wait", "--test"};
    Args args = new ManagerArgs(argsParam);
    MC command = new MC(admin, args);
    command.run();
    assertRegionName(command);

    // should be 1 store file
    assertEquals(1, getRegionLoad(regionInfo1, serverName1).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName2).getStorefiles());
}
 
Example 11
Source File: MCTest.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testMC_RS() throws Exception {
    // move each RS has one region
    splitTable("c".getBytes());
    ArrayList<ServerName> serverNameList = getServerNameList();
    assertTrue(serverNameList.size() >= 2);
    ArrayList<HRegionInfo> regionInfoList = getRegionInfoList(tableName);
    assertEquals(2, regionInfoList.size());
    HRegionInfo regionInfo1 = regionInfoList.get(0);
    HRegionInfo regionInfo2 = regionInfoList.get(1);
    ServerName serverName1 = serverNameList.get(0);
    ServerName serverName2 = serverNameList.get(1);
    move(regionInfo1, serverName1);
    move(regionInfo2, serverName2);

    // make 2 + 2 store files
    putData(table, "a".getBytes());
    admin.flush(tableName);
    putData(table, "b".getBytes());
    admin.flush(tableName);
    putData(table, "c".getBytes());
    admin.flush(tableName);
    putData(table, "d".getBytes());
    admin.flush(tableName);
    Thread.sleep(3000);
    assertEquals(2, getRegionLoad(regionInfo1, serverName1).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName2).getStorefiles());

    // run MC
    String regex = serverName1.getHostname() + "," + serverName1.getPort() + ".*";
    String[] argsParam = {"zookeeper", tableName, "--rs=" + regex, "--force-proceed", "--wait", "--test"};
    Args args = new ManagerArgs(argsParam);
    MC command = new MC(admin, args);
    command.run();
    assertRegionName(command);

    // should be 1 store file
    assertEquals(1, getRegionLoad(regionInfo1, serverName1).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName2).getStorefiles());
}
 
Example 12
Source File: HFileSystem.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void reorderBlocks(Configuration conf, LocatedBlocks lbs, String src)
    throws IOException {

  ServerName sn = AbstractFSWALProvider.getServerNameFromWALDirectoryName(conf, src);
  if (sn == null) {
    // It's not an WAL
    return;
  }

  // Ok, so it's an WAL
  String hostName = sn.getHostname();
  if (LOG.isTraceEnabled()) {
    LOG.trace(src +
        " is an WAL file, so reordering blocks, last hostname will be:" + hostName);
  }

  // Just check for all blocks
  for (LocatedBlock lb : lbs.getLocatedBlocks()) {
    DatanodeInfo[] dnis = lb.getLocations();
    if (dnis != null && dnis.length > 1) {
      boolean found = false;
      for (int i = 0; i < dnis.length - 1 && !found; i++) {
        if (hostName.equals(dnis[i].getHostName())) {
          // advance the other locations by one and put this one at the last place.
          DatanodeInfo toLast = dnis[i];
          System.arraycopy(dnis, i + 1, dnis, i, dnis.length - i - 1);
          dnis[dnis.length - 1] = toLast;
          found = true;
        }
      }
    }
  }
}
 
Example 13
Source File: AddCPULoadAction.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected void localPerform() throws IOException {
  getLogger().info("Starting to execute AddCPULoadAction");
  ServerName server = PolicyBasedChaosMonkey.selectRandomItem(getCurrentServers());
  String hostname = server.getHostname();

  try {
    clusterManager.execSudo(hostname, timeout, getCommand());
  } catch (IOException ex){
    //This will always happen. We use timeout to kill a continuously running process
    //after the duration expires
  }
  getLogger().info("Finished to execute AddCPULoadAction");
}
 
Example 14
Source File: HBaseDataFragmenter.java    From pxf with Apache License 2.0 5 votes vote down vote up
private void addFragment(HRegionLocation location,
        byte[] userData) throws IOException {
    ServerName serverInfo = location.getServerName();
    String[] hosts = new String[] {serverInfo.getHostname()};
    HRegionInfo region = location.getRegionInfo();
    byte[] fragmentMetadata = prepareFragmentMetadata(region);
    Fragment fragment = new Fragment(context.getDataSource(), hosts, fragmentMetadata, userData);
    fragments.add(fragment);
}
 
Example 15
Source File: TestClientTimeouts.java    From hbase with Apache License 2.0 4 votes vote down vote up
RandomTimeoutRpcChannel(AbstractRpcClient<?> rpcClient, ServerName sn, User ticket,
    int rpcTimeout) throws UnknownHostException {
  super(rpcClient, new InetSocketAddress(sn.getHostname(), sn.getPort()), ticket, rpcTimeout);
}
 
Example 16
Source File: RegionMovedException.java    From hbase with Apache License 2.0 4 votes vote down vote up
public RegionMovedException(ServerName serverName, long locationSeqNum) {
  this.hostname = serverName.getHostname();
  this.port = serverName.getPort();
  this.startCode = serverName.getStartcode();
  this.locationSeqNum = locationSeqNum;
}
 
Example 17
Source File: TestClientTimeouts.java    From hbase with Apache License 2.0 4 votes vote down vote up
RandomTimeoutBlockingRpcChannel(BlockingRpcClient rpcClient, ServerName sn, User ticket,
    int rpcTimeout) {
  super(rpcClient, new InetSocketAddress(sn.getHostname(), sn.getPort()), ticket, rpcTimeout);
}
 
Example 18
Source File: StartcodeAgnosticServerName.java    From hbase with Apache License 2.0 4 votes vote down vote up
public static StartcodeAgnosticServerName valueOf(final ServerName serverName) {
  return new StartcodeAgnosticServerName(serverName.getHostname(), serverName.getPort(),
      serverName.getStartcode());
}
 
Example 19
Source File: MCTest.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Test
public void testMC_LocalityMultipleRSs() throws Exception {
    // fixme Data locality is not correct in HBaseTestingUtility
    if (miniCluster) return;

    // move each RS has one region
    splitTable("c".getBytes());
    ArrayList<ServerName> serverNameList = getServerNameList();
    assertTrue(serverNameList.size() >= 2);
    ArrayList<HRegionInfo> regionInfoList = getRegionInfoList(tableName);
    assertEquals(2, regionInfoList.size());
    HRegionInfo regionInfo1 = regionInfoList.get(0);
    HRegionInfo regionInfo2 = regionInfoList.get(1);
    ServerName serverName1 = serverNameList.get(0);
    ServerName serverName2 = serverNameList.get(1);
    move(regionInfo1, serverName1);
    move(regionInfo2, serverName2);

    // make 2 + 2 store files
    putData(table, "a".getBytes());
    admin.flush(tableName);
    putData(table, "b".getBytes());
    admin.flush(tableName);
    putData(table, "c".getBytes());
    admin.flush(tableName);
    putData(table, "d".getBytes());
    admin.flush(tableName);
    Thread.sleep(3000);
    assertEquals(2, getRegionLoad(regionInfo1, serverName1).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName2).getStorefiles());

    // Data locality of regionInfo1 is 0%, data locality of regionInfo2 is 0%
    move(regionInfo1, serverName2);
    move(regionInfo2, serverName1);
    assertEquals(2, getRegionLoad(regionInfo1, serverName2).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName1).getStorefiles());

    // run MC
    String regex;
    if (miniCluster) regex = serverName1.getHostname() + "," + serverName1.getPort() + ".*";
    else regex = serverName1.getHostname() + ".*";
    String[] argsParam = {"zookeeper", tableName, "--locality=100", "--rs=" + regex,
        "--force-proceed", "--wait", "--test"};
    Args args = new ManagerArgs(argsParam);
    MC command = new MC(admin, args);
    command.run();

    // should be 1 store file
    assertEquals(2, getRegionLoad(regionInfo1, serverName2).getStorefiles());
    assertEquals(1, getRegionLoad(regionInfo2, serverName1).getStorefiles());
}
 
Example 20
Source File: MCTest.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
@Test
public void testMC_LocalityMultipleRSs() throws Exception {
    // fixme Data locality is not correct in HBaseTestingUtility
    if (miniCluster) return;

    // move each RS has one region
    splitTable("c".getBytes());
    ArrayList<ServerName> serverNameList = getServerNameList();
    assertTrue(serverNameList.size() >= 2);
    ArrayList<HRegionInfo> regionInfoList = getRegionInfoList(tableName);
    assertEquals(2, regionInfoList.size());
    HRegionInfo regionInfo1 = regionInfoList.get(0);
    HRegionInfo regionInfo2 = regionInfoList.get(1);
    ServerName serverName1 = serverNameList.get(0);
    ServerName serverName2 = serverNameList.get(1);
    move(regionInfo1, serverName1);
    move(regionInfo2, serverName2);

    // make 2 + 2 store files
    putData(table, "a".getBytes());
    admin.flush(tableName);
    putData(table, "b".getBytes());
    admin.flush(tableName);
    putData(table, "c".getBytes());
    admin.flush(tableName);
    putData(table, "d".getBytes());
    admin.flush(tableName);
    Thread.sleep(3000);
    assertEquals(2, getRegionLoad(regionInfo1, serverName1).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName2).getStorefiles());

    // Data locality of regionInfo1 is 0%, data locality of regionInfo2 is 0%
    move(regionInfo1, serverName2);
    move(regionInfo2, serverName1);
    assertEquals(2, getRegionLoad(regionInfo1, serverName2).getStorefiles());
    assertEquals(2, getRegionLoad(regionInfo2, serverName1).getStorefiles());

    // run MC
    String regex;
    if (miniCluster) regex = serverName1.getHostname() + "," + serverName1.getPort() + ".*";
    else regex = serverName1.getHostname() + ".*";
    String[] argsParam = {"zookeeper", tableName, "--locality=100", "--rs=" + regex,
        "--force-proceed", "--wait", "--test"};
    Args args = new ManagerArgs(argsParam);
    MC command = new MC(admin, args);
    command.run();

    // should be 1 store file
    assertEquals(2, getRegionLoad(regionInfo1, serverName2).getStorefiles());
    assertEquals(1, getRegionLoad(regionInfo2, serverName1).getStorefiles());
}