Java Code Examples for org.apache.hadoop.hbase.HConstants#HBASE_DIR

The following examples show how to use org.apache.hadoop.hbase.HConstants#HBASE_DIR . 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: ServerCommandLine.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Print into log some of the important hbase attributes.
 */
private static void logHBaseConfigs(Configuration conf) {
  final String [] keys = new String [] {
    // Expand this list as you see fit.
    "hbase.tmp.dir",
    HConstants.HBASE_DIR,
    HConstants.CLUSTER_DISTRIBUTED,
    HConstants.ZOOKEEPER_QUORUM,

  };
  for (String key: keys) {
    LOG.info(key + ": " + conf.get(key));
  }
}
 
Example 2
Source File: CommonFSUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies root directory path is a valid URI with a scheme
 *
 * @param root root directory path
 * @return Passed <code>root</code> argument.
 * @throws IOException if not a valid URI with a scheme
 */
public static Path validateRootPath(Path root) throws IOException {
  try {
    URI rootURI = new URI(root.toString());
    String scheme = rootURI.getScheme();
    if (scheme == null) {
      throw new IOException("Root directory does not have a scheme");
    }
    return root;
  } catch (URISyntaxException e) {
    throw new IOException("Root directory path is not a valid " +
      "URI -- check your " + HConstants.HBASE_DIR + " configuration", e);
  }
}
 
Example 3
Source File: AbstractFSWALProvider.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Pulls a ServerName out of a Path generated according to our layout rules. In the below layouts,
 * this method ignores the format of the logfile component. Current format: [base directory for
 * hbase]/hbase/.logs/ServerName/logfile or [base directory for
 * hbase]/hbase/.logs/ServerName-splitting/logfile Expected to work for individual log files and
 * server-specific directories.
 * @return null if it's not a log file. Returns the ServerName of the region server that created
 *         this log file otherwise.
 */
public static ServerName getServerNameFromWALDirectoryName(Configuration conf, String path)
    throws IOException {
  if (path == null || path.length() <= HConstants.HREGION_LOGDIR_NAME.length()) {
    return null;
  }

  if (conf == null) {
    throw new IllegalArgumentException("parameter conf must be set");
  }

  final String rootDir = conf.get(HConstants.HBASE_DIR);
  if (rootDir == null || rootDir.isEmpty()) {
    throw new IllegalArgumentException(HConstants.HBASE_DIR + " key not found in conf.");
  }

  final StringBuilder startPathSB = new StringBuilder(rootDir);
  if (!rootDir.endsWith("/")) {
    startPathSB.append('/');
  }
  startPathSB.append(HConstants.HREGION_LOGDIR_NAME);
  if (!HConstants.HREGION_LOGDIR_NAME.endsWith("/")) {
    startPathSB.append('/');
  }
  final String startPath = startPathSB.toString();

  String fullPath;
  try {
    fullPath = FileSystem.get(conf).makeQualified(new Path(path)).toString();
  } catch (IllegalArgumentException e) {
    LOG.info("Call to makeQualified failed on " + path + " " + e.getMessage());
    return null;
  }

  if (!fullPath.startsWith(startPath)) {
    return null;
  }

  final String serverNameAndFile = fullPath.substring(startPath.length());

  if (serverNameAndFile.indexOf('/') < "a,0,0".length()) {
    // Either it's a file (not a directory) or it's not a ServerName format
    return null;
  }

  Path p = new Path(path);
  return getServerNameFromWALDirectoryName(p);
}
 
Example 4
Source File: MasterFileSystem.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Get the rootdir. Make sure its wholesome and exists before returning.
 * @return hbase.rootdir (after checks for existence and bootstrapping if needed populating the
 *         directory with necessary bootup files).
 */
private void checkRootDir(final Path rd, final Configuration c, final FileSystem fs)
  throws IOException {
  int threadWakeFrequency = c.getInt(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000);
  // If FS is in safe mode wait till out of it.
  FSUtils.waitOnSafeMode(c, threadWakeFrequency);

  // Filesystem is good. Go ahead and check for hbase.rootdir.
  FileStatus status;
  try {
    status = fs.getFileStatus(rd);
  } catch (FileNotFoundException e) {
    status = null;
  }
  int versionFileWriteAttempts = c.getInt(HConstants.VERSION_FILE_WRITE_ATTEMPTS,
    HConstants.DEFAULT_VERSION_FILE_WRITE_ATTEMPTS);
  try {
    if (status == null) {
      if (!fs.mkdirs(rd)) {
        throw new IOException("Can not create configured '" + HConstants.HBASE_DIR + "' " + rd);
      }
      // DFS leaves safe mode with 0 DNs when there are 0 blocks.
      // We used to handle this by checking the current DN count and waiting until
      // it is nonzero. With security, the check for datanode count doesn't work --
      // it is a privileged op. So instead we adopt the strategy of the jobtracker
      // and simply retry file creation during bootstrap indefinitely. As soon as
      // there is one datanode it will succeed. Permission problems should have
      // already been caught by mkdirs above.
      FSUtils.setVersion(fs, rd, threadWakeFrequency, versionFileWriteAttempts);
    } else {
      if (!status.isDirectory()) {
        throw new IllegalArgumentException(
          "Configured '" + HConstants.HBASE_DIR + "' " + rd + " is not a directory.");
      }
      // as above
      FSUtils.checkVersion(fs, rd, true, threadWakeFrequency, versionFileWriteAttempts);
    }
  } catch (DeserializationException de) {
    LOG.error(HBaseMarkers.FATAL, "Please fix invalid configuration for '{}' {}",
      HConstants.HBASE_DIR, rd, de);
    throw new IOException(de);
  } catch (IllegalArgumentException iae) {
    LOG.error(HBaseMarkers.FATAL, "Please fix invalid configuration for '{}' {}",
      HConstants.HBASE_DIR, rd, iae);
    throw iae;
  }
  // Make sure cluster ID exists
  if (!FSUtils.checkClusterIdExists(fs, rd, threadWakeFrequency)) {
    FSUtils.setClusterId(fs, rd, new ClusterId(), threadWakeFrequency);
  }
  clusterId = FSUtils.getClusterId(fs, rd);
}