在hdfs中,“remoteexception”通常是什么意思?

9w11ddsr  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(401)

1) 有谁能帮助我了解“remoteexception”的概念吗?一般来说是什么意思?
2) 还有,不可预见的例外是什么意思?不确定它的意思是“如果这个远程异常 Package 了一个查找类型”

/**
   * If this remote exception wraps up one of the lookupTypes
   * then return this exception.
   * <p>
   * Unwraps any IOException.
   * 
   * @param lookupTypes the desired exception class.
   * @return IOException, which is either the lookupClass exception or this.
   */
  public IOException unwrapRemoteException(Class<?>... lookupTypes) {
    if(lookupTypes == null)
      return this;
    for(Class<?> lookupClass : lookupTypes) {
      if(!lookupClass.getName().equals(getClassName()))
        continue;
      try {
        return instantiateException(lookupClass.asSubclass(IOException.class));
      } catch(Exception e) {
        // cannot instantiate lookupClass, just return this
        return this;
      }
    }
    // wrapped up exception is not in lookupTypes, just return this
    return this;
  }

(hadoop\u hdfs\u开源:https://github.com/apache/hadoop)
提前谢谢!任何帮助都将不胜感激!

2izufjch

2izufjch1#

1) 有谁能帮助我了解“remoteexception”的概念吗?一般来说是什么意思?
在服务器端引发(创建)远程异常。服务器抛出这样的异常是因为客户端发送了无效的请求,或者服务器有内部错误或其他原因。服务器端的rpc服务器序列化了异常,并将其发送到客户端。客户端反序列化异常,并获取异常。
2) 还有,不可预见的例外是什么意思?
问题是“为什么我们需要 Package 异常”。首先,remoteexception是一个 Package 器,而不是真正的异常。服务器引发的真正异常可能是accesscontrolexception(用户没有previleage)、filenotfoundexception(无效请求)。我们把它们 Package 在一个remoteexception中。但为什么呢?因为代码更干净,可读性更强。
不确定它的意思是“如果这个远程异常 Package 了一个查找类型”
例如,在dfsclient.java中

public HdfsFileStatus getFileInfo(String src) throws IOException {
  checkOpen();
  try {
    return namenode.getFileInfo(src);
  } catch(RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   FileNotFoundException.class,
                                   UnresolvedPathException.class);
  }
}

如果 re 包裹 FileNotFoundException ,然后 getFileInfo 只返回 FileNotFoundException . 然后,用户可以看到一个更短更干净的异常消息。用户只需要知道文件没有找到,不关心它是否远程。
但是如果 re 包裹 SafeModeException 或者一些未知的异常。可能是某个服务器的内部错误或配置错误。我们扔掉 re (例外)没错。因此用户可以从远程(服务器端)知道错误,即使用户不知道错误所在 SafeModeException (或者一些未知的异常)。用户可以向技术支持部门寻求帮助。

相关问题