类org.apache.hadoop.util.PerformanceAdvisory源码实例Demo

下面列出了怎么用org.apache.hadoop.util.PerformanceAdvisory的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop   文件: DomainSocketFactory.java
public DomainSocketFactory(Conf conf) {
  final String feature;
  if (conf.isShortCircuitLocalReads() && (!conf.isUseLegacyBlockReaderLocal())) {
    feature = "The short-circuit local reads feature";
  } else if (conf.isDomainSocketDataTraffic()) {
    feature = "UNIX domain socket data traffic";
  } else {
    feature = null;
  }

  if (feature == null) {
    PerformanceAdvisory.LOG.debug(
        "Both short-circuit local reads and UNIX domain socket are disabled.");
  } else {
    if (conf.getDomainSocketPath().isEmpty()) {
      throw new HadoopIllegalArgumentException(feature + " is enabled but "
          + DFSConfigKeys.DFS_DOMAIN_SOCKET_PATH_KEY + " is not set.");
    } else if (DomainSocket.getLoadingFailureReason() != null) {
      LOG.warn(feature + " cannot be used because "
          + DomainSocket.getLoadingFailureReason());
    } else {
      LOG.debug(feature + " is enabled.");
    }
  }
}
 
源代码2 项目: big-c   文件: DomainSocketFactory.java
public DomainSocketFactory(Conf conf) {
  final String feature;
  if (conf.isShortCircuitLocalReads() && (!conf.isUseLegacyBlockReaderLocal())) {
    feature = "The short-circuit local reads feature";
  } else if (conf.isDomainSocketDataTraffic()) {
    feature = "UNIX domain socket data traffic";
  } else {
    feature = null;
  }

  if (feature == null) {
    PerformanceAdvisory.LOG.debug(
        "Both short-circuit local reads and UNIX domain socket are disabled.");
  } else {
    if (conf.getDomainSocketPath().isEmpty()) {
      throw new HadoopIllegalArgumentException(feature + " is enabled but "
          + DFSConfigKeys.DFS_DOMAIN_SOCKET_PATH_KEY + " is not set.");
    } else if (DomainSocket.getLoadingFailureReason() != null) {
      LOG.warn(feature + " cannot be used because "
          + DomainSocket.getLoadingFailureReason());
    } else {
      LOG.debug(feature + " is enabled.");
    }
  }
}
 
public JniBasedUnixGroupsMappingWithFallback() {
  if (NativeCodeLoader.isNativeCodeLoaded()) {
    this.impl = new JniBasedUnixGroupsMapping();
  } else {
    PerformanceAdvisory.LOG.debug("Falling back to shell based");
    this.impl = new ShellBasedUnixGroupsMapping();
  }
  if (LOG.isDebugEnabled()){
    LOG.debug("Group mapping impl=" + impl.getClass().getName());
  }
}
 
源代码4 项目: hadoop   文件: CryptoCodec.java
/**
 * Get crypto codec for specified algorithm/mode/padding.
 * 
 * @param conf
 *          the configuration
 * @param cipherSuite
 *          algorithm/mode/padding
 * @return CryptoCodec the codec object. Null value will be returned if no
 *         crypto codec classes with cipher suite configured.
 */
public static CryptoCodec getInstance(Configuration conf, 
    CipherSuite cipherSuite) {
  List<Class<? extends CryptoCodec>> klasses = getCodecClasses(
      conf, cipherSuite);
  if (klasses == null) {
    return null;
  }
  CryptoCodec codec = null;
  for (Class<? extends CryptoCodec> klass : klasses) {
    try {
      CryptoCodec c = ReflectionUtils.newInstance(klass, conf);
      if (c.getCipherSuite().getName().equals(cipherSuite.getName())) {
        if (codec == null) {
          PerformanceAdvisory.LOG.debug("Using crypto codec {}.",
              klass.getName());
          codec = c;
        }
      } else {
        PerformanceAdvisory.LOG.debug(
            "Crypto codec {} doesn't meet the cipher suite {}.",
            klass.getName(), cipherSuite.getName());
      }
    } catch (Exception e) {
      PerformanceAdvisory.LOG.debug("Crypto codec {} is not available.",
          klass.getName());
    }
  }
  
  return codec;
}
 
public JniBasedUnixGroupsMappingWithFallback() {
  if (NativeCodeLoader.isNativeCodeLoaded()) {
    this.impl = new JniBasedUnixGroupsMapping();
  } else {
    PerformanceAdvisory.LOG.debug("Falling back to shell based");
    this.impl = new ShellBasedUnixGroupsMapping();
  }
  if (LOG.isDebugEnabled()){
    LOG.debug("Group mapping impl=" + impl.getClass().getName());
  }
}
 
源代码6 项目: big-c   文件: CryptoCodec.java
/**
 * Get crypto codec for specified algorithm/mode/padding.
 * 
 * @param conf
 *          the configuration
 * @param cipherSuite
 *          algorithm/mode/padding
 * @return CryptoCodec the codec object. Null value will be returned if no
 *         crypto codec classes with cipher suite configured.
 */
public static CryptoCodec getInstance(Configuration conf, 
    CipherSuite cipherSuite) {
  List<Class<? extends CryptoCodec>> klasses = getCodecClasses(
      conf, cipherSuite);
  if (klasses == null) {
    return null;
  }
  CryptoCodec codec = null;
  for (Class<? extends CryptoCodec> klass : klasses) {
    try {
      CryptoCodec c = ReflectionUtils.newInstance(klass, conf);
      if (c.getCipherSuite().getName().equals(cipherSuite.getName())) {
        if (codec == null) {
          PerformanceAdvisory.LOG.debug("Using crypto codec {}.",
              klass.getName());
          codec = c;
        }
      } else {
        PerformanceAdvisory.LOG.debug(
            "Crypto codec {} doesn't meet the cipher suite {}.",
            klass.getName(), cipherSuite.getName());
      }
    } catch (Exception e) {
      PerformanceAdvisory.LOG.debug("Crypto codec {} is not available.",
          klass.getName());
    }
  }
  
  return codec;
}
 
源代码7 项目: hadoop   文件: BlockReaderFactory.java
/**
 * Get {@link BlockReaderLocalLegacy} for short circuited local reads.
 * This block reader implements the path-based style of local reads
 * first introduced in HDFS-2246.
 */
private BlockReader getLegacyBlockReaderLocal() throws IOException {
  if (LOG.isTraceEnabled()) {
    LOG.trace(this + ": trying to construct BlockReaderLocalLegacy");
  }
  if (!DFSClient.isLocalAddress(inetSocketAddress)) {
    if (LOG.isTraceEnabled()) {
      LOG.trace(this + ": can't construct BlockReaderLocalLegacy because " +
          "the address " + inetSocketAddress + " is not local");
    }
    return null;
  }
  if (clientContext.getDisableLegacyBlockReaderLocal()) {
    PerformanceAdvisory.LOG.debug(this + ": can't construct " +
        "BlockReaderLocalLegacy because " +
        "disableLegacyBlockReaderLocal is set.");
    return null;
  }
  IOException ioe = null;
  try {
    return BlockReaderLocalLegacy.newBlockReader(conf,
        userGroupInformation, configuration, fileName, block, token,
        datanode, startOffset, length, storageType);
  } catch (RemoteException remoteException) {
    ioe = remoteException.unwrapRemoteException(
              InvalidToken.class, AccessControlException.class);
  } catch (IOException e) {
    ioe = e;
  }
  if ((!(ioe instanceof AccessControlException)) &&
      isSecurityException(ioe)) {
    // Handle security exceptions.
    // We do not handle AccessControlException here, since
    // BlockReaderLocalLegacy#newBlockReader uses that exception to indicate
    // that the user is not in dfs.block.local-path-access.user, a condition
    // which requires us to disable legacy SCR.
    throw ioe;
  }
  LOG.warn(this + ": error creating legacy BlockReaderLocal.  " +
      "Disabling legacy local reads.", ioe);
  clientContext.setDisableLegacyBlockReaderLocal();
  return null;
}
 
源代码8 项目: hadoop   文件: BlockReaderFactory.java
private BlockReader getBlockReaderLocal() throws InvalidToken {
  if (LOG.isTraceEnabled()) {
    LOG.trace(this + ": trying to construct a BlockReaderLocal " +
        "for short-circuit reads.");
  }
  if (pathInfo == null) {
    pathInfo = clientContext.getDomainSocketFactory().
                    getPathInfo(inetSocketAddress, conf);
  }
  if (!pathInfo.getPathState().getUsableForShortCircuit()) {
    PerformanceAdvisory.LOG.debug(this + ": " + pathInfo + " is not " +
        "usable for short circuit; giving up on BlockReaderLocal.");
    return null;
  }
  ShortCircuitCache cache = clientContext.getShortCircuitCache();
  ExtendedBlockId key = new ExtendedBlockId(block.getBlockId(), block.getBlockPoolId());
  ShortCircuitReplicaInfo info = cache.fetchOrCreate(key, this);
  InvalidToken exc = info.getInvalidTokenException();
  if (exc != null) {
    if (LOG.isTraceEnabled()) {
      LOG.trace(this + ": got InvalidToken exception while trying to " +
          "construct BlockReaderLocal via " + pathInfo.getPath());
    }
    throw exc;
  }
  if (info.getReplica() == null) {
    if (LOG.isTraceEnabled()) {
      PerformanceAdvisory.LOG.debug(this + ": failed to get " +
          "ShortCircuitReplica. Cannot construct " +
          "BlockReaderLocal via " + pathInfo.getPath());
    }
    return null;
  }
  return new BlockReaderLocal.Builder(conf).
      setFilename(fileName).
      setBlock(block).
      setStartOffset(startOffset).
      setShortCircuitReplica(info.getReplica()).
      setVerifyChecksum(verifyChecksum).
      setCachingStrategy(cachingStrategy).
      setStorageType(storageType).
      build();
}
 
源代码9 项目: hadoop   文件: BlockReaderFactory.java
/**
 * Get a RemoteBlockReader that communicates over a UNIX domain socket.
 *
 * @return The new BlockReader, or null if we failed to create the block
 * reader.
 *
 * @throws InvalidToken    If the block token was invalid.
 * Potentially other security-related execptions.
 */
private BlockReader getRemoteBlockReaderFromDomain() throws IOException {
  if (pathInfo == null) {
    pathInfo = clientContext.getDomainSocketFactory().
                    getPathInfo(inetSocketAddress, conf);
  }
  if (!pathInfo.getPathState().getUsableForDataTransfer()) {
    PerformanceAdvisory.LOG.debug(this + ": not trying to create a " +
        "remote block reader because the UNIX domain socket at " +
        pathInfo + " is not usable.");
    return null;
  }
  if (LOG.isTraceEnabled()) {
    LOG.trace(this + ": trying to create a remote block reader from the " +
        "UNIX domain socket at " + pathInfo.getPath());
  }

  while (true) {
    BlockReaderPeer curPeer = nextDomainPeer();
    if (curPeer == null) break;
    if (curPeer.fromCache) remainingCacheTries--;
    DomainPeer peer = (DomainPeer)curPeer.peer;
    BlockReader blockReader = null;
    try {
      blockReader = getRemoteBlockReader(peer);
      return blockReader;
    } catch (IOException ioe) {
      IOUtils.cleanup(LOG, peer);
      if (isSecurityException(ioe)) {
        if (LOG.isTraceEnabled()) {
          LOG.trace(this + ": got security exception while constructing " +
              "a remote block reader from the unix domain socket at " +
              pathInfo.getPath(), ioe);
        }
        throw ioe;
      }
      if (curPeer.fromCache) {
        // Handle an I/O error we got when using a cached peer.  These are
        // considered less serious, because the underlying socket may be stale.
        if (LOG.isDebugEnabled()) {
          LOG.debug("Closed potentially stale domain peer " + peer, ioe);
        }
      } else {
        // Handle an I/O error we got when using a newly created domain peer.
        // We temporarily disable the domain socket path for a few minutes in
        // this case, to prevent wasting more time on it.
        LOG.warn("I/O error constructing remote block reader.  Disabling " +
            "domain socket " + peer.getDomainSocket(), ioe);
        clientContext.getDomainSocketFactory()
            .disableDomainSocketPath(pathInfo.getPath());
        return null;
      }
    } finally {
      if (blockReader == null) {
        IOUtils.cleanup(LOG, peer);
      }
    }
  }
  return null;
}
 
源代码10 项目: big-c   文件: BlockReaderFactory.java
/**
 * Get {@link BlockReaderLocalLegacy} for short circuited local reads.
 * This block reader implements the path-based style of local reads
 * first introduced in HDFS-2246.
 */
private BlockReader getLegacyBlockReaderLocal() throws IOException {
  if (LOG.isTraceEnabled()) {
    LOG.trace(this + ": trying to construct BlockReaderLocalLegacy");
  }
  if (!DFSClient.isLocalAddress(inetSocketAddress)) {
    if (LOG.isTraceEnabled()) {
      LOG.trace(this + ": can't construct BlockReaderLocalLegacy because " +
          "the address " + inetSocketAddress + " is not local");
    }
    return null;
  }
  if (clientContext.getDisableLegacyBlockReaderLocal()) {
    PerformanceAdvisory.LOG.debug(this + ": can't construct " +
        "BlockReaderLocalLegacy because " +
        "disableLegacyBlockReaderLocal is set.");
    return null;
  }
  IOException ioe = null;
  try {
    return BlockReaderLocalLegacy.newBlockReader(conf,
        userGroupInformation, configuration, fileName, block, token,
        datanode, startOffset, length, storageType);
  } catch (RemoteException remoteException) {
    ioe = remoteException.unwrapRemoteException(
              InvalidToken.class, AccessControlException.class);
  } catch (IOException e) {
    ioe = e;
  }
  if ((!(ioe instanceof AccessControlException)) &&
      isSecurityException(ioe)) {
    // Handle security exceptions.
    // We do not handle AccessControlException here, since
    // BlockReaderLocalLegacy#newBlockReader uses that exception to indicate
    // that the user is not in dfs.block.local-path-access.user, a condition
    // which requires us to disable legacy SCR.
    throw ioe;
  }
  LOG.warn(this + ": error creating legacy BlockReaderLocal.  " +
      "Disabling legacy local reads.", ioe);
  clientContext.setDisableLegacyBlockReaderLocal();
  return null;
}
 
源代码11 项目: big-c   文件: BlockReaderFactory.java
private BlockReader getBlockReaderLocal() throws InvalidToken {
  if (LOG.isTraceEnabled()) {
    LOG.trace(this + ": trying to construct a BlockReaderLocal " +
        "for short-circuit reads.");
  }
  if (pathInfo == null) {
    pathInfo = clientContext.getDomainSocketFactory().
                    getPathInfo(inetSocketAddress, conf);
  }
  if (!pathInfo.getPathState().getUsableForShortCircuit()) {
    PerformanceAdvisory.LOG.debug(this + ": " + pathInfo + " is not " +
        "usable for short circuit; giving up on BlockReaderLocal.");
    return null;
  }
  ShortCircuitCache cache = clientContext.getShortCircuitCache();
  ExtendedBlockId key = new ExtendedBlockId(block.getBlockId(), block.getBlockPoolId());
  ShortCircuitReplicaInfo info = cache.fetchOrCreate(key, this);
  InvalidToken exc = info.getInvalidTokenException();
  if (exc != null) {
    if (LOG.isTraceEnabled()) {
      LOG.trace(this + ": got InvalidToken exception while trying to " +
          "construct BlockReaderLocal via " + pathInfo.getPath());
    }
    throw exc;
  }
  if (info.getReplica() == null) {
    if (LOG.isTraceEnabled()) {
      PerformanceAdvisory.LOG.debug(this + ": failed to get " +
          "ShortCircuitReplica. Cannot construct " +
          "BlockReaderLocal via " + pathInfo.getPath());
    }
    return null;
  }
  return new BlockReaderLocal.Builder(conf).
      setFilename(fileName).
      setBlock(block).
      setStartOffset(startOffset).
      setShortCircuitReplica(info.getReplica()).
      setVerifyChecksum(verifyChecksum).
      setCachingStrategy(cachingStrategy).
      setStorageType(storageType).
      build();
}
 
源代码12 项目: big-c   文件: BlockReaderFactory.java
/**
 * Get a RemoteBlockReader that communicates over a UNIX domain socket.
 *
 * @return The new BlockReader, or null if we failed to create the block
 * reader.
 *
 * @throws InvalidToken    If the block token was invalid.
 * Potentially other security-related execptions.
 */
private BlockReader getRemoteBlockReaderFromDomain() throws IOException {
  if (pathInfo == null) {
    pathInfo = clientContext.getDomainSocketFactory().
                    getPathInfo(inetSocketAddress, conf);
  }
  if (!pathInfo.getPathState().getUsableForDataTransfer()) {
    PerformanceAdvisory.LOG.debug(this + ": not trying to create a " +
        "remote block reader because the UNIX domain socket at " +
        pathInfo + " is not usable.");
    return null;
  }
  if (LOG.isTraceEnabled()) {
    LOG.trace(this + ": trying to create a remote block reader from the " +
        "UNIX domain socket at " + pathInfo.getPath());
  }

  while (true) {
    BlockReaderPeer curPeer = nextDomainPeer();
    if (curPeer == null) break;
    if (curPeer.fromCache) remainingCacheTries--;
    DomainPeer peer = (DomainPeer)curPeer.peer;
    BlockReader blockReader = null;
    try {
      blockReader = getRemoteBlockReader(peer);
      return blockReader;
    } catch (IOException ioe) {
      IOUtils.cleanup(LOG, peer);
      if (isSecurityException(ioe)) {
        if (LOG.isTraceEnabled()) {
          LOG.trace(this + ": got security exception while constructing " +
              "a remote block reader from the unix domain socket at " +
              pathInfo.getPath(), ioe);
        }
        throw ioe;
      }
      if (curPeer.fromCache) {
        // Handle an I/O error we got when using a cached peer.  These are
        // considered less serious, because the underlying socket may be stale.
        if (LOG.isDebugEnabled()) {
          LOG.debug("Closed potentially stale domain peer " + peer, ioe);
        }
      } else {
        // Handle an I/O error we got when using a newly created domain peer.
        // We temporarily disable the domain socket path for a few minutes in
        // this case, to prevent wasting more time on it.
        LOG.warn("I/O error constructing remote block reader.  Disabling " +
            "domain socket " + peer.getDomainSocket(), ioe);
        clientContext.getDomainSocketFactory()
            .disableDomainSocketPath(pathInfo.getPath());
        return null;
      }
    } finally {
      if (blockReader == null) {
        IOUtils.cleanup(LOG, peer);
      }
    }
  }
  return null;
}
 
 类所在包
 类方法
 同包方法