當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerName.getStartcode方法代碼示例

本文整理匯總了Java中org.apache.hadoop.hbase.ServerName.getStartcode方法的典型用法代碼示例。如果您正苦於以下問題:Java ServerName.getStartcode方法的具體用法?Java ServerName.getStartcode怎麽用?Java ServerName.getStartcode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.hbase.ServerName的用法示例。


在下文中一共展示了ServerName.getStartcode方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getServerNameFromWALDirectoryName

import org.apache.hadoop.hbase.ServerName; //導入方法依賴的package包/類
/**
 * 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>
 * @param logFile
 * @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 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;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:33,代碼來源:DefaultWALProvider.java

示例2: isServerDeadAndNotProcessed

import org.apache.hadoop.hbase.ServerName; //導入方法依賴的package包/類
synchronized boolean isServerDeadAndNotProcessed(ServerName server) {
  if (server == null) return false;
  if (serverManager.isServerOnline(server)) {
    String hostAndPort = server.getHostAndPort();
    long startCode = server.getStartcode();
    Long deadCode = deadServers.get(hostAndPort);
    if (deadCode == null || startCode > deadCode.longValue()) {
      if (serverManager.isServerReachable(server)) {
        return false;
      }
      // The size of deadServers won't grow unbounded.
      deadServers.put(hostAndPort, Long.valueOf(startCode));
    }
    // Watch out! If the server is not dead, the region could
    // remain unassigned. That's why ServerManager#isServerReachable
    // should use some retry.
    //
    // We cache this info since it is very unlikely for that
    // instance to come back up later on. We don't want to expire
    // the server since we prefer to let it die naturally.
    LOG.warn("Couldn't reach online server " + server);
  }
  // Now, we know it's dead. Check if it's processed
  return !processedServers.containsKey(server);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:26,代碼來源:RegionStates.java

示例3: isDeadServer

import org.apache.hadoop.hbase.ServerName; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:22,代碼來源:ClusterStatusListener.java

示例4: checkAndRecordNewServer

import org.apache.hadoop.hbase.ServerName; //導入方法依賴的package包/類
/**
 * 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 sn 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 ServerLoad 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;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:38,代碼來源:ServerManager.java

示例5: isServerReachable

import org.apache.hadoop.hbase.ServerName; //導入方法依賴的package包/類
/**
 * Check if a region server is reachable and has the expected start code
 */
public boolean isServerReachable(ServerName server) {
  if (server == null) throw new NullPointerException("Passed server is null");


  RetryCounter retryCounter = pingRetryCounterFactory.create();
  while (retryCounter.shouldRetry()) {
    synchronized (this.onlineServers) {
      if (this.deadservers.isDeadServer(server)) {
        return false;
      }
    }
    try {
      PayloadCarryingRpcController controller = newRpcController();
      AdminService.BlockingInterface admin = getRsAdmin(server);
      if (admin != null) {
        ServerInfo info = ProtobufUtil.getServerInfo(controller, admin);
        return info != null && info.hasServerName()
          && server.getStartcode() == info.getServerName().getStartCode();
      }
    } catch (IOException ioe) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Couldn't reach " + server + ", try=" + retryCounter.getAttemptTimes() + " of "
            + retryCounter.getMaxAttempts(), ioe);
      }
      try {
        retryCounter.sleepUntilNextRetry();
      } catch(InterruptedException ie) {
        Thread.currentThread().interrupt();
        break;
      }
    }
  }
  return false;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:38,代碼來源:ServerManager.java

示例6: toServerName

import org.apache.hadoop.hbase.ServerName; //導入方法依賴的package包/類
/**
 * 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.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();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:22,代碼來源:ProtobufUtil.java

示例7: testHBaseFsck

import org.apache.hadoop.hbase.ServerName; //導入方法依賴的package包/類
@Test (timeout=180000)
public void testHBaseFsck() throws Exception {
  assertNoErrors(doFsck(conf, false));
  TableName table = TableName.valueOf("tableBadMetaAssign");
  HTableDescriptor desc = new HTableDescriptor(table);
  HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toString(FAM));
  desc.addFamily(hcd); // If a table has no CF's it doesn't get checked
  createTable(TEST_UTIL, desc, null);

  // We created 1 table, should be fine
  assertNoErrors(doFsck(conf, false));

  // Now let's mess it up and change the assignment in hbase:meta to
  // point to a different region server
  Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService);
  Scan scan = new Scan();
  scan.setStartRow(Bytes.toBytes(table+",,"));
  ResultScanner scanner = meta.getScanner(scan);
  HRegionInfo hri = null;

  Result res = scanner.next();
  ServerName currServer =
    ServerName.parseFrom(res.getValue(HConstants.CATALOG_FAMILY,
        HConstants.SERVER_QUALIFIER));
  long startCode = Bytes.toLong(res.getValue(HConstants.CATALOG_FAMILY,
      HConstants.STARTCODE_QUALIFIER));

  for (JVMClusterUtil.RegionServerThread rs :
      TEST_UTIL.getHBaseCluster().getRegionServerThreads()) {

    ServerName sn = rs.getRegionServer().getServerName();

    // When we find a diff RS, change the assignment and break
    if (!currServer.getHostAndPort().equals(sn.getHostAndPort()) ||
        startCode != sn.getStartcode()) {
      Put put = new Put(res.getRow());
      put.setDurability(Durability.SKIP_WAL);
      put.add(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
        Bytes.toBytes(sn.getHostAndPort()));
      put.add(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
        Bytes.toBytes(sn.getStartcode()));
      meta.put(put);
      hri = MetaTableAccessor.getHRegionInfo(res);
      break;
    }
  }

  // Try to fix the data
  assertErrors(doFsck(conf, true), new ERROR_CODE[]{
      ERROR_CODE.SERVER_DOES_NOT_MATCH_META});

  TEST_UTIL.getHBaseCluster().getMaster()
    .getAssignmentManager().waitForAssignment(hri);

  // Should be fixed now
  assertNoErrors(doFsck(conf, false));

  // comment needed - what is the purpose of this line
  Table t = connection.getTable(table, tableExecutorService);
  ResultScanner s = t.getScanner(new Scan());
  s.close();
  t.close();

  scanner.close();
  meta.close();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:67,代碼來源:TestHBaseFsck.java

示例8: RegionMovedException

import org.apache.hadoop.hbase.ServerName; //導入方法依賴的package包/類
public RegionMovedException(ServerName serverName, long locationSeqNum) {
  this.hostname = serverName.getHostname();
  this.port = serverName.getPort();
  this.startCode = serverName.getStartcode();
  this.locationSeqNum = locationSeqNum;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:7,代碼來源:RegionMovedException.java


注:本文中的org.apache.hadoop.hbase.ServerName.getStartcode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。