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


Java HConstants.CLUSTER_ID_FILE_NAME屬性代碼示例

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


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

示例1: checkClusterIdExists

/**
 * Checks that a cluster ID file exists in the HBase root directory
 * @param fs the root directory FileSystem
 * @param rootdir the HBase root directory in HDFS
 * @param wait how long to wait between retries
 * @return <code>true</code> if the file exists, otherwise <code>false</code>
 * @throws IOException if checking the FileSystem fails
 */
public static boolean checkClusterIdExists(FileSystem fs, Path rootdir,
    int wait) throws IOException {
  while (true) {
    try {
      Path filePath = new Path(rootdir, HConstants.CLUSTER_ID_FILE_NAME);
      return fs.exists(filePath);
    } catch (IOException ioe) {
      if (wait > 0) {
        LOG.warn("Unable to check cluster ID file in " + rootdir.toString() +
            ", retrying in "+wait+"msec: "+StringUtils.stringifyException(ioe));
        try {
          Thread.sleep(wait);
        } catch (InterruptedException e) {
          throw (InterruptedIOException)new InterruptedIOException().initCause(e);
        }
      } else {
        throw ioe;
      }
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:29,代碼來源:FSUtils.java

示例2: testRewritingClusterIdToPB

@Test
public void testRewritingClusterIdToPB() throws Exception {
  TEST_UTIL.startMiniZKCluster();
  TEST_UTIL.startMiniDFSCluster(1);
  TEST_UTIL.createRootDir();
  TEST_UTIL.getConfiguration().setBoolean("hbase.replication", true);
  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();
  assertEquals(1, master.getServerManager().getOnlineServersList().size());
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:22,代碼來源:TestClusterId.java

示例3: setClusterId

/**
 * Writes a new unique identifier for this cluster to the "hbase.id" file
 * in the HBase root directory
 * @param fs the root directory FileSystem
 * @param rootdir the path to the HBase root directory
 * @param clusterId the unique identifier to store
 * @param wait how long (in milliseconds) to wait between retries
 * @throws IOException if writing to the FileSystem fails and no wait value
 */
public static void setClusterId(FileSystem fs, Path rootdir, ClusterId clusterId,
    int wait) throws IOException {
  while (true) {
    try {
      Path idFile = new Path(rootdir, HConstants.CLUSTER_ID_FILE_NAME);
      Path tempIdFile = new Path(rootdir, HConstants.HBASE_TEMP_DIRECTORY +
        Path.SEPARATOR + HConstants.CLUSTER_ID_FILE_NAME);
      // Write the id file to a temporary location
      FSDataOutputStream s = fs.create(tempIdFile);
      try {
        s.write(clusterId.toByteArray());
        s.close();
        s = null;
        // Move the temporary file to its normal location. Throw an IOE if
        // the rename failed
        if (!fs.rename(tempIdFile, idFile)) {
          throw new IOException("Unable to move temp version file to " + idFile);
        }
      } finally {
        // Attempt to close the stream if still open on the way out
        try {
          if (s != null) s.close();
        } catch (IOException ignore) { }
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Created cluster ID file at " + idFile.toString() + " with ID: " + clusterId);
      }
      return;
    } catch (IOException ioe) {
      if (wait > 0) {
        LOG.warn("Unable to create cluster ID file in " + rootdir.toString() +
            ", retrying in " + wait + "msec: " + StringUtils.stringifyException(ioe));
        try {
          Thread.sleep(wait);
        } catch (InterruptedException e) {
          throw (InterruptedIOException)new InterruptedIOException().initCause(e);
        }
      } else {
        throw ioe;
      }
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:52,代碼來源:FSUtils.java


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