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

The following examples show how to use org.apache.hadoop.hbase.ServerName#valueOf() . 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: TransactionProcessorTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, tableName + ".hlog");
  HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
  WAL hLog = walFactory.getWAL(info);
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
      new LocalRegionServerServices(conf, ServerName.valueOf(
          InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
 
Example 2
Source File: TestReplicationSource.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRecoveredReplicationSourceShipperGetPosition() throws Exception {
  String walGroupId = "fake-wal-group-id";
  ServerName serverName = ServerName.valueOf("www.example.com", 12006, 1524679704418L);
  ServerName deadServer = ServerName.valueOf("www.deadServer.com", 12006, 1524679704419L);
  PriorityBlockingQueue<Path> queue = new PriorityBlockingQueue<>();
  queue.put(new Path("/www/html/test"));
  RecoveredReplicationSource source = Mockito.mock(RecoveredReplicationSource.class);
  Server server = Mockito.mock(Server.class);
  Mockito.when(server.getServerName()).thenReturn(serverName);
  Mockito.when(source.getServer()).thenReturn(server);
  Mockito.when(source.getServerWALsBelongTo()).thenReturn(deadServer);
  ReplicationQueueStorage storage = Mockito.mock(ReplicationQueueStorage.class);
  Mockito.when(storage.getWALPosition(Mockito.eq(serverName), Mockito.any(), Mockito.any()))
      .thenReturn(1001L);
  Mockito.when(storage.getWALPosition(Mockito.eq(deadServer), Mockito.any(), Mockito.any()))
      .thenReturn(-1L);
  conf.setInt("replication.source.maxretriesmultiplier", -1);
  RecoveredReplicationSourceShipper shipper =
      new RecoveredReplicationSourceShipper(conf, walGroupId, queue, source, storage);
  Assert.assertEquals(1001L, shipper.getStartPosition());
  conf.unset("replication.source.maxretriesmultiplier");
}
 
Example 3
Source File: TransactionProcessorTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, null, tableName + ".hlog");
  WAL hLog = walFactory.getWAL(new byte[]{1});
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
                     new LocalRegionServerServices(conf, ServerName.valueOf(
                       InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
 
Example 4
Source File: TestStartcodeAgnosticServerName.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartCodeServerName() {
  ServerName sn = ServerName.valueOf("www.example.org", 1234, 5678);
  StartcodeAgnosticServerName snStartCode =
      new StartcodeAgnosticServerName("www.example.org", 1234, 5678);

  assertTrue(ServerName.isSameAddress(sn, snStartCode));
  assertTrue(snStartCode.equals(sn));
  assertTrue(sn.equals(snStartCode));
  assertEquals(0, snStartCode.compareTo(sn));

  StartcodeAgnosticServerName snStartCodeFNPort =
      new StartcodeAgnosticServerName("www.example.org", 1234, ServerName.NON_STARTCODE);
  assertTrue(ServerName.isSameAddress(snStartCodeFNPort, snStartCode));
  assertTrue(snStartCode.equals(snStartCodeFNPort));
  assertTrue(snStartCodeFNPort.equals(snStartCode));
  assertEquals(0, snStartCode.compareTo(snStartCodeFNPort));
}
 
Example 5
Source File: TestSplitLogManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskErr() throws Exception {
  LOG.info("TestTaskErr - cleanup task node once in ERR state");

  conf.setInt("hbase.splitlog.max.resubmit", 0);
  slm = new SplitLogManager(master, conf);
  TaskBatch batch = new TaskBatch();

  String tasknode = submitTaskAndWait(batch, "foo/1");
  final ServerName worker1 = ServerName.valueOf("worker1,1,1");
  SplitLogTask slt = new SplitLogTask.Err(worker1);
  ZKUtil.setData(zkw, tasknode, slt.toByteArray());

  synchronized (batch) {
    while (batch.installed != batch.error) {
      batch.wait();
    }
  }
  waitForCounter(tot_mgr_task_deleted, 0, 1, to/2);
  assertTrue(ZKUtil.checkExists(zkw, tasknode) == -1);
  conf.setInt("hbase.splitlog.max.resubmit", ZKSplitLogManagerCoordination.DEFAULT_MAX_RESUBMIT);
}
 
Example 6
Source File: ServerManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Assumes onlineServers is locked.
 * @return ServerName with matching hostname and port.
 */
private ServerName findServerWithSameHostnamePortWithLock(
    final ServerName serverName) {
  ServerName end = ServerName.valueOf(serverName.getHostname(), serverName.getPort(),
      Long.MAX_VALUE);

  ServerName r = onlineServers.lowerKey(end);
  if (r != null) {
    if (ServerName.isSameAddress(r, serverName)) {
      return r;
    }
  }
  return null;
}
 
Example 7
Source File: TestMasterAddressTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteIfEquals() throws Exception {
  final ServerName sn = ServerName.valueOf("localhost", 1234, System.currentTimeMillis());
  final MasterAddressTracker addressTracker = setupMasterTracker(sn, 1772);
  try {
    assertFalse("shouldn't have deleted wrong master server.",
        MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), "some other string."));
  } finally {
    assertTrue("Couldn't clean up master",
        MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), sn.toString()));
  }
}
 
Example 8
Source File: FavoredNodesManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
private synchronized void addToReplicaLoad(RegionInfo hri, List<ServerName> servers) {
  ServerName serverToUse =
    ServerName.valueOf(servers.get(PRIMARY.ordinal()).getAddress().toString(), NON_STARTCODE);
  List<RegionInfo> regionList = primaryRSToRegionMap.get(serverToUse);
  if (regionList == null) {
    regionList = new ArrayList<>();
  }
  regionList.add(hri);
  primaryRSToRegionMap.put(serverToUse, regionList);

  serverToUse = ServerName
      .valueOf(servers.get(SECONDARY.ordinal()).getAddress(), NON_STARTCODE);
  regionList = secondaryRSToRegionMap.get(serverToUse);
  if (regionList == null) {
    regionList = new ArrayList<>();
  }
  regionList.add(hri);
  secondaryRSToRegionMap.put(serverToUse, regionList);

  serverToUse = ServerName.valueOf(servers.get(TERTIARY.ordinal()).getAddress(),
    NON_STARTCODE);
  regionList = teritiaryRSToRegionMap.get(serverToUse);
  if (regionList == null) {
    regionList = new ArrayList<>();
  }
  regionList.add(hri);
  teritiaryRSToRegionMap.put(serverToUse, regionList);
}
 
Example 9
Source File: TestMasterAddressTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoBackups() throws Exception {
  final ServerName sn = ServerName.valueOf("localhost", 1234, System.currentTimeMillis());
  final MasterAddressTracker addressTracker = setupMasterTracker(sn, 1772);
  try {
    assertEquals("Should receive 0 for backup not found.", 0,
        addressTracker.getBackupMasterInfoPort(
            ServerName.valueOf("doesnotexist.example.com", 1234, System.currentTimeMillis())));
  } finally {
    assertTrue("Couldn't clean up master",
        MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), sn.toString()));
  }
}
 
Example 10
Source File: TestSimpleRegionNormalizer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("MockitoCast")
private void setupMocksForNormalizer(Map<byte[], Integer> regionSizes,
  List<RegionInfo> regionInfoList) {
  masterServices = Mockito.mock(MasterServices.class, RETURNS_DEEP_STUBS);

  // for simplicity all regions are assumed to be on one server; doesn't matter to us
  ServerName sn = ServerName.valueOf("localhost", 0, 0L);
  when(masterServices.getAssignmentManager().getRegionStates()
    .getRegionsOfTable(any())).thenReturn(regionInfoList);
  when(masterServices.getAssignmentManager().getRegionStates()
    .getRegionServerOfRegion(any())).thenReturn(sn);
  when(masterServices.getAssignmentManager().getRegionStates()
    .getRegionState(any(RegionInfo.class))).thenReturn(
      RegionState.createForTesting(null, RegionState.State.OPEN));

  for (Map.Entry<byte[], Integer> region : regionSizes.entrySet()) {
    RegionMetrics regionLoad = Mockito.mock(RegionMetrics.class);
    when(regionLoad.getRegionName()).thenReturn(region.getKey());
    when(regionLoad.getStoreFileSize())
      .thenReturn(new Size(region.getValue(), Size.Unit.MEGABYTE));

    // this is possibly broken with jdk9, unclear if false positive or not
    // suppress it for now, fix it when we get to running tests on 9
    // see: http://errorprone.info/bugpattern/MockitoCast
    when((Object) masterServices.getServerManager().getLoad(sn)
      .getRegionMetrics().get(region.getKey())).thenReturn(regionLoad);
  }

  when(masterServices.isSplitOrMergeEnabled(any())).thenReturn(true);

  normalizer = new SimpleRegionNormalizer();
  normalizer.setConf(conf);
  normalizer.setMasterServices(masterServices);
}
 
Example 11
Source File: DrainingServerTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void nodeDeleted(final String path) {
  if(path.startsWith(watcher.getZNodePaths().drainingZNode)) {
    final ServerName sn = ServerName.valueOf(ZKUtil.getNodeName(path));
    LOG.info("Draining RS node deleted, removing from list [" +
        sn + "]");
    remove(sn);
  }
}
 
Example 12
Source File: TestHeapMemoryManager.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public ServerName getServerName() {
  return ServerName.valueOf("server1",4000,12345);
}
 
Example 13
Source File: TestTokenAuthentication.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public ServerName getServerName() {
  return ServerName.valueOf(isa.getHostName(), isa.getPort(), startcode);
}
 
Example 14
Source File: TestUtils.java    From hbase with Apache License 2.0 4 votes vote down vote up
public static ClusterMetrics createDummyClusterMetrics() {
  Map<ServerName, ServerMetrics> serverMetricsMap = new HashMap<>();

  // host1
  List<RegionMetrics> regionMetricsList = new ArrayList<>();
  List<UserMetrics> userMetricsList = new ArrayList<>();
  userMetricsList.add(createUserMetrics("FOO",1,2, 4));
  userMetricsList.add(createUserMetrics("BAR",2,3, 3));
  regionMetricsList.add(createRegionMetrics(
    "table1,,1.00000000000000000000000000000000.",
    100, 50, 100,
    new Size(100, Size.Unit.MEGABYTE), new Size(200, Size.Unit.MEGABYTE), 1,
    new Size(100, Size.Unit.MEGABYTE), 0.1f, 100, 100, "2019-07-22 00:00:00"));
  regionMetricsList.add(createRegionMetrics(
    "table2,1,2.00000000000000000000000000000001.",
    200, 100, 200,
    new Size(200, Size.Unit.MEGABYTE), new Size(400, Size.Unit.MEGABYTE), 2,
    new Size(200, Size.Unit.MEGABYTE), 0.2f, 50, 200, "2019-07-22 00:00:01"));
  regionMetricsList.add(createRegionMetrics(
    "namespace:table3,,3_0001.00000000000000000000000000000002.",
    300, 150, 300,
    new Size(300, Size.Unit.MEGABYTE), new Size(600, Size.Unit.MEGABYTE), 3,
    new Size(300, Size.Unit.MEGABYTE), 0.3f, 100, 300, "2019-07-22 00:00:02"));

  ServerName host1 = ServerName.valueOf("host1.apache.com", 1000, 1);
  serverMetricsMap.put(host1, createServerMetrics(host1, 100,
    new Size(100, Size.Unit.MEGABYTE), new Size(200, Size.Unit.MEGABYTE), 100,
    regionMetricsList, userMetricsList));

  // host2
  regionMetricsList.clear();
  userMetricsList.clear();
  userMetricsList.add(createUserMetrics("FOO",5,7, 3));
  userMetricsList.add(createUserMetrics("BAR",4,8, 4));
  regionMetricsList.add(createRegionMetrics(
    "table1,1,4.00000000000000000000000000000003.",
    100, 50, 100,
    new Size(100, Size.Unit.MEGABYTE), new Size(200, Size.Unit.MEGABYTE), 1,
    new Size(100, Size.Unit.MEGABYTE), 0.4f, 50, 100, "2019-07-22 00:00:03"));
  regionMetricsList.add(createRegionMetrics(
    "table2,,5.00000000000000000000000000000004.",
    200, 100, 200,
    new Size(200, Size.Unit.MEGABYTE), new Size(400, Size.Unit.MEGABYTE), 2,
    new Size(200, Size.Unit.MEGABYTE), 0.5f, 150, 200, "2019-07-22 00:00:04"));
  regionMetricsList.add(createRegionMetrics(
    "namespace:table3,,6.00000000000000000000000000000005.",
    300, 150, 300,
    new Size(300, Size.Unit.MEGABYTE), new Size(600, Size.Unit.MEGABYTE), 3,
    new Size(300, Size.Unit.MEGABYTE), 0.6f, 200, 300, "2019-07-22 00:00:05"));

  ServerName host2 = ServerName.valueOf("host2.apache.com", 1001, 2);
  serverMetricsMap.put(host2, createServerMetrics(host2, 200,
    new Size(16, Size.Unit.GIGABYTE), new Size(32, Size.Unit.GIGABYTE), 200,
    regionMetricsList, userMetricsList));

  ServerName host3 = ServerName.valueOf("host3.apache.com", 1002, 3);
  return ClusterMetricsBuilder.newBuilder()
    .setHBaseVersion("3.0.0-SNAPSHOT")
    .setClusterId("01234567-89ab-cdef-0123-456789abcdef")
    .setLiveServerMetrics(serverMetricsMap)
    .setDeadServerNames(Collections.singletonList(host3))
    .setRegionsInTransition(Collections.singletonList(
      new RegionState(RegionInfoBuilder.newBuilder(TableName.valueOf("table4"))
        .setStartKey(new byte [0])
        .setEndKey(new byte [0])
        .setOffline(true)
        .setReplicaId(0)
        .setRegionId(0)
        .setSplit(false)
        .build(),
        RegionState.State.OFFLINE, host3)))
    .build();
}
 
Example 15
Source File: TestHFileCleaner.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public ServerName getServerName() {
  return ServerName.valueOf("regionserver,60020,000000");
}
 
Example 16
Source File: TestZKReplicationQueueStorage.java    From hbase with Apache License 2.0 4 votes vote down vote up
private ServerName getServerName(int i) {
  return ServerName.valueOf("127.0.0.1", 8000 + i, 10000 + i);
}
 
Example 17
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
public static ServerName create(String serverNameStr) {
    return ServerName.valueOf(serverNameStr);
}
 
Example 18
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
public static ServerName create(String serverNameStr) {
    return ServerName.valueOf(serverNameStr);
}
 
Example 19
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 4 votes vote down vote up
public static ServerName create(String serverNameStr) {
    return ServerName.valueOf(serverNameStr);
}
 
Example 20
Source File: TestReplicationSourceManager.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public ServerName getServerName() {
  return ServerName.valueOf(hostname, 1234, 1L);
}