/**
   * Opens the connection to the worker. And start the heartbeat thread.
   *
   * @throws IOException if a non-Tachyon exception occurs
   */
  private synchronized void connectOperation() throws IOException {
    if (!mConnected) {
      LOG.info("Connecting to {} worker @ {}", (mIsLocal ? "local" : "remote"), mAddress);

      TProtocol binaryProtocol =
          new TBinaryProtocol(AuthenticationUtils.getClientTransport(mTachyonConf, mAddress));
      mProtocol = new TMultiplexedProtocol(binaryProtocol, getServiceName());
      mClient = new BlockWorkerClientService.Client(mProtocol);

      try {
        mProtocol.getTransport().open();
      } catch (TTransportException e) {
        LOG.error(e.getMessage(), e);
        return;
      }
      mConnected = true;

      // only start the heartbeat thread if the connection is successful and if there is not
      // another heartbeat thread running
      if (mHeartbeat == null || mHeartbeat.isCancelled() || mHeartbeat.isDone()) {
        final int interval = mTachyonConf.getInt(Constants.USER_HEARTBEAT_INTERVAL_MS);
        mHeartbeat =
            mExecutorService.submit(
                new HeartbeatThread(HeartbeatContext.WORKER_CLIENT, mHeartbeatExecutor, interval));
      }
    }
  }
Example #2
0
 /**
  * Helper method to create a {@link org.apache.thrift.server.TThreadPoolServer} for handling
  * incoming RPC requests.
  *
  * @return a thrift server
  */
 private TThreadPoolServer createThriftServer() {
   int minWorkerThreads = mTachyonConf.getInt(Constants.WORKER_WORKER_BLOCK_THREADS_MIN);
   int maxWorkerThreads = mTachyonConf.getInt(Constants.WORKER_WORKER_BLOCK_THREADS_MAX);
   BlockWorkerClientService.Processor<BlockWorkerClientServiceHandler> processor =
       new BlockWorkerClientService.Processor<BlockWorkerClientServiceHandler>(mServiceHandler);
   TTransportFactory tTransportFactory;
   try {
     tTransportFactory = AuthenticationUtils.getServerTransportFactory(mTachyonConf);
   } catch (IOException ioe) {
     throw Throwables.propagate(ioe);
   }
   Args args =
       new TThreadPoolServer.Args(mThriftServerSocket)
           .minWorkerThreads(minWorkerThreads)
           .maxWorkerThreads(maxWorkerThreads)
           .processor(processor)
           .transportFactory(tTransportFactory)
           .protocolFactory(new TBinaryProtocol.Factory(true, true));
   if (WorkerContext.getConf().getBoolean(Constants.IN_TEST_MODE)) {
     args.stopTimeoutVal = 0;
   } else {
     args.stopTimeoutVal = Constants.THRIFT_STOP_TIMEOUT_SECONDS;
   }
   return new TThreadPoolServer(args);
 }
Example #3
0
  /**
   * Helper method to create a {@link org.apache.thrift.server.TThreadPoolServer} for handling
   * incoming RPC requests.
   *
   * @return a thrift server
   */
  private TThreadPoolServer createThriftServer() {
    int minWorkerThreads = mTachyonConf.getInt(Constants.WORKER_WORKER_BLOCK_THREADS_MIN);
    int maxWorkerThreads = mTachyonConf.getInt(Constants.WORKER_WORKER_BLOCK_THREADS_MAX);
    TMultiplexedProcessor processor = new TMultiplexedProcessor();

    registerServices(processor, mBlockWorker.getServices());
    registerServices(processor, mFileSystemWorker.getServices());
    // register additional workers for RPC service
    for (Worker worker : mAdditionalWorkers) {
      registerServices(processor, worker.getServices());
    }

    // Return a TTransportFactory based on the authentication type
    TTransportFactory tTransportFactory;
    try {
      tTransportFactory = AuthenticationUtils.getServerTransportFactory(mTachyonConf);
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
    TThreadPoolServer.Args args =
        new TThreadPoolServer.Args(mThriftServerSocket)
            .minWorkerThreads(minWorkerThreads)
            .maxWorkerThreads(maxWorkerThreads)
            .processor(processor)
            .transportFactory(tTransportFactory)
            .protocolFactory(new TBinaryProtocol.Factory(true, true));
    if (WorkerContext.getConf().getBoolean(Constants.IN_TEST_MODE)) {
      args.stopTimeoutVal = 0;
    } else {
      args.stopTimeoutVal = Constants.THRIFT_STOP_TIMEOUT_SECONDS;
    }
    return new TThreadPoolServer(args);
  }