hadoop rpc服务器未停止

nnvyjq4y  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(380)

我试图用hadoopipc在它们之间创建一个简单的父子进程。结果是程序执行并打印结果,但它没有退出。这是它的代码。

interface Protocol extends VersionedProtocol{
  public static final long versionID = 1L;
  IntWritable getInput();
}

public final class JavaProcess implements Protocol{
  Server server;

  public JavaProcess() {
  String rpcAddr = "localhost";
  int rpcPort = 8989;
  Configuration conf = new Configuration();
  try {
    server = RPC.getServer(this, rpcAddr, rpcPort, conf);
    server.start();

  } catch (IOException e) {
    e.printStackTrace();
  }
}

public int exec(Class klass) throws IOException,InterruptedException {
  String javaHome = System.getProperty("java.home");
  String javaBin = javaHome +
      File.separator + "bin" +
      File.separator + "java";
  String classpath = System.getProperty("java.class.path");
  String className = klass.getCanonicalName();

  ProcessBuilder builder = new ProcessBuilder(
      javaBin, "-cp", classpath, className);

  Process process = builder.start();
  int exit_code = process.waitFor();
  server.stop();

  System.out.println("completed process");
  return exit_code;
}

public static void main(String...args) throws IOException, InterruptedException{
  int status = new JavaProcess().exec(JavaProcessChild.class);
  System.out.println(status);
}

@Override
public IntWritable getInput() {
  return new IntWritable(10);
}

@Override
public long getProtocolVersion(String paramString, long paramLong)
    throws IOException {
  return Protocol.versionID;
 }
}

下面是子进程类。然而,我已经意识到,这是由于rpc.getserver()在服务器端,它的罪魁祸首。是已知的hadoop错误,还是我遗漏了什么?

public class JavaProcessChild{

  public static void main(String...args){
    Protocol umbilical = null;
    try {
       Configuration defaultConf = new Configuration();
       InetSocketAddress addr = new InetSocketAddress("localhost", 8989);
       umbilical = (Protocol) RPC.waitForProxy(Protocol.class, Protocol.versionID,
            addr, defaultConf);
       IntWritable input = umbilical.getInput();

       JavaProcessChild my = new JavaProcessChild();

      if(input!=null && input.equals(new IntWritable(10))){
        Thread.sleep(10000);
      }
      else{
        Thread.sleep(1000);
      }
    } catch (Throwable e) {
      e.printStackTrace();
   } finally{
      if(umbilical != null){
        RPC.stopProxy(umbilical);
      }
  }
}
}
3okqufwl

3okqufwl1#

我们通过邮件解决了这个问题。但我只想把我的两分钱给公众:
因此,没有死在那里的线程(因此没有让主线程完成)是 org.apache.hadoop.ipc.Server$Reader . 原因是,执行 readSelector.select(); 不可中断。如果仔细查看调试器或线程转储,它将永远等待该调用,即使主线程已经被清理。
两种可能的修复方法:
使reader线程成为deamon(不是很酷,因为选择器不会被正确地清理,但是进程将结束)
当中断线程池时,从外部显式关闭“readselector”
但是,这是hadoop中的一个bug,我没有时间查看jiras。也许这已经是固定的,在纱旧工控机是由protobuf和节俭无论如何取代。
顺便说一句,这取决于选择器的实现,我在debian/windows系统上观察到了这些僵尸,但在redhat/solaris上没有。
如果有人对hadoop1.0的补丁感兴趣,请发邮件给我。我将在不久的将来整理出jira的bug,并在这里编辑更多信息(也许这是固定的同时(无论如何)。

相关问题