org.apache.hadoop.hbase.ServerName#getStartcode ( )源码实例Demo

下面列出了org.apache.hadoop.hbase.ServerName#getStartcode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hbase   文件: AbstractFSWALProvider.java

/**
 * This function returns region server name from a log file name which is in one of the following
 * formats:
 * <ul>
 * <li>hdfs://&lt;name node&gt;/hbase/.logs/&lt;server name&gt;-splitting/...</li>
 * <li>hdfs://&lt;name node&gt;/hbase/.logs/&lt;server name&gt;/...</li>
 * </ul>
 * @return null if the passed in logFile isn't a valid WAL file path
 */
public static ServerName getServerNameFromWALDirectoryName(Path logFile) {
  String logDirName = logFile.getParent().getName();
  // We were passed the directory and not a file in it.
  if (logDirName.equals(HConstants.HREGION_LOGDIR_NAME)) {
    logDirName = logFile.getName();
  }
  ServerName serverName = null;
  if (logDirName.endsWith(SPLITTING_EXT)) {
    logDirName = logDirName.substring(0, logDirName.length() - SPLITTING_EXT.length());
  }
  try {
    serverName = ServerName.parseServerName(logDirName);
  } catch (IllegalArgumentException | IllegalStateException ex) {
    serverName = null;
    LOG.warn("Cannot parse a server name from path=" + logFile + "; " + ex.getMessage());
  }
  if (serverName != null && serverName.getStartcode() < 0) {
    LOG.warn("Invalid log file path=" + logFile);
    serverName = null;
  }
  return serverName;
}
 
源代码2 项目: hbase   文件: MockMasterServices.java

/**
 * Call this restart method only after running MockMasterServices#start()
 * The RSs can be differentiated by the port number, see
 * ServerName in MockMasterServices#start() method above.
 * Restart of region server will have new startcode in server name
 *
 * @param serverName Server name to be restarted
 */
public void restartRegionServer(ServerName serverName) throws IOException {
  List<ServerName> onlineServers = serverManager.getOnlineServersList();
  long startCode = -1;
  for (ServerName s : onlineServers) {
    if (s.getAddress().equals(serverName.getAddress())) {
      startCode = s.getStartcode() + 1;
      break;
    }
  }
  if (startCode == -1) {
    return;
  }
  ServerName sn = ServerName.valueOf(serverName.getAddress().toString(), startCode);
  serverManager.regionServerReport(sn, ServerMetricsBuilder.of(sn));
}
 
源代码3 项目: hbase   文件: ProtobufUtil.java

/**
 * Convert a ServerName to a protocol buffer ServerName
 *
 * @param serverName the ServerName to convert
 * @return the converted protocol buffer ServerName
 * @see #toServerName(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ServerName)
 */
public static HBaseProtos.ServerName toServerName(final ServerName serverName) {
  if (serverName == null) {
    return null;
  }
  HBaseProtos.ServerName.Builder builder =
    HBaseProtos.ServerName.newBuilder();
  builder.setHostName(serverName.getHostname());
  if (serverName.getPort() >= 0) {
    builder.setPort(serverName.getPort());
  }
  if (serverName.getStartcode() >= 0) {
    builder.setStartCode(serverName.getStartcode());
  }
  return builder.build();
}
 
源代码4 项目: hbase   文件: ClusterStatusListener.java

/**
 * Check if we know if a server is dead.
 *
 * @param sn the server name to check.
 * @return true if we know for sure that the server is dead, false otherwise.
 */
public boolean isDeadServer(ServerName sn) {
  if (sn.getStartcode() <= 0) {
    return false;
  }

  for (ServerName dead : deadServers) {
    if (dead.getStartcode() >= sn.getStartcode() &&
        dead.getPort() == sn.getPort() &&
        dead.getHostname().equals(sn.getHostname())) {
      return true;
    }
  }

  return false;
}
 
源代码5 项目: hbase   文件: ServerManager.java

/**
 * Check is a server of same host and port already exists,
 * if not, or the existed one got a smaller start code, record it.
 *
 * @param serverName the server to check and record
 * @param sl the server load on the server
 * @return true if the server is recorded, otherwise, false
 */
boolean checkAndRecordNewServer(final ServerName serverName, final ServerMetrics sl) {
  ServerName existingServer = null;
  synchronized (this.onlineServers) {
    existingServer = findServerWithSameHostnamePortWithLock(serverName);
    if (existingServer != null && (existingServer.getStartcode() > serverName.getStartcode())) {
      LOG.info("Server serverName=" + serverName + " rejected; we already have "
          + existingServer.toString() + " registered with same hostname and port");
      return false;
    }
    recordNewServerWithLock(serverName, sl);
  }

  // Tell our listeners that a server was added
  if (!this.listeners.isEmpty()) {
    for (ServerListener listener : this.listeners) {
      listener.serverAdded(serverName);
    }
  }

  // Note that we assume that same ts means same server, and don't expire in that case.
  //  TODO: ts can theoretically collide due to clock shifts, so this is a bit hacky.
  if (existingServer != null &&
      (existingServer.getStartcode() < serverName.getStartcode())) {
    LOG.info("Triggering server recovery; existingServer " +
        existingServer + " looks stale, new server:" + serverName);
    expireServer(existingServer);
  }
  return true;
}
 

public static StartcodeAgnosticServerName valueOf(final ServerName serverName) {
  return new StartcodeAgnosticServerName(serverName.getHostname(), serverName.getPort(),
      serverName.getStartcode());
}
 
源代码7 项目: hbase   文件: RegionMovedException.java

public RegionMovedException(ServerName serverName, long locationSeqNum) {
  this.hostname = serverName.getHostname();
  this.port = serverName.getPort();
  this.startCode = serverName.getStartcode();
  this.locationSeqNum = locationSeqNum;
}