示例#1
0
    @Override
    public void innerRun() {
      EventLogger.queueEnd(_event);

      if (_event instanceof LastMessageEvent) {
        LOGGER.trace("messageThread : LastMessageEvent arrived");
        _cell.messageArrived((MessageEvent) _event);
      } else if (_event instanceof RoutedMessageEvent) {
        LOGGER.trace("messageThread : RoutedMessageEvent arrived");
        _cell.messageArrived((RoutedMessageEvent) _event);
      } else if (_event instanceof MessageEvent) {
        MessageEvent msgEvent = (MessageEvent) _event;
        LOGGER.trace("messageThread : MessageEvent arrived");
        CellMessage msg;
        try {
          msg = msgEvent.getMessage().decode();
        } catch (SerializationException e) {
          CellMessage envelope = msgEvent.getMessage();
          LOGGER.error(
              String.format(
                  "Discarding a malformed message from %s with UOID %s and session [%s]: %s",
                  envelope.getSourcePath(),
                  envelope.getUOID(),
                  envelope.getSession(),
                  e.getMessage()),
              e);
          return;
        }

        CDC.setMessageContext(msg);
        try {
          LOGGER.trace("messageThread : delivering message: {}", msg);
          _cell.messageArrived(new MessageEvent(msg));
          LOGGER.trace("messageThread : delivering message done: {}", msg);
        } catch (RuntimeException e) {
          if (!msg.isReply()) {
            try {
              msg.revertDirection();
              msg.setMessageObject(e);
              sendMessage(msg);
            } catch (NoRouteToCellException f) {
              LOGGER.error("PANIC : Problem returning answer: {}", f);
            }
          }
          throw e;
        } finally {
          CDC.clearMessageContext();
        }
      }
    }
示例#2
0
 @Override
 public void run() {
   try (CDC ignored = CDC.reset(CellNucleus.this)) {
     innerRun();
   } catch (Throwable e) {
     Thread t = Thread.currentThread();
     t.getUncaughtExceptionHandler().uncaughtException(t, e);
   }
 }
示例#3
0
    @Override
    public void run() {
      synchronized (this) {
        _startTime = System.currentTimeMillis();
      }

      try {
        _cdc.restore();
        NDC.push("job=" + _id);
        _runnable.run();
      } finally {
        CDC.clear();
        synchronized (this) {
          _status = REMOVED;
        }
        synchronized (_lock) {
          _jobs.remove(_id);
          _activeJobs--;
          _lock.notifyAll();
        }
      }
    }
示例#4
0
  void shutdown(KillEvent event) {
    LOGGER.trace("Received {}", event);

    try (CDC ignored = CDC.reset(CellNucleus.this)) {
      _state = REMOVING;
      addToEventQueue(LAST_MESSAGE_EVENT);
      try {
        _cell.prepareRemoval(event);
      } catch (Throwable e) {
        Thread t = Thread.currentThread();
        t.getUncaughtExceptionHandler().uncaughtException(t, e);
      }

      shutdownPrivateExecutors();

      LOGGER.debug("Waiting for all threads in {} to finish", _threads);

      try {
        Collection<Thread> threads = getNonDaemonThreads(_threads);

        /* Some threads shut down asynchronously. Give them
         * one second before we start to kill them.
         */
        while (!joinThreads(threads, 1000)) {
          killThreads(threads);
        }
        _threads.destroy();
      } catch (IllegalThreadStateException e) {
        _threads.setDaemon(true);
      } catch (InterruptedException e) {
        LOGGER.warn("Interrupted while waiting for threads");
      }
      __cellGlue.destroy(CellNucleus.this);
      _state = DEAD;
    }
  }
示例#5
0
  /**
   * ask pool manager for a file
   *
   * <p>On successful reply from pool manager corresponding O request will be sent to the pool to
   * start a NFS mover.
   *
   * @throws ChimeraNFSException in case of NFS friendly errors ( like ACCESS )
   * @throws IOException in case of any other errors
   */
  @Override
  public Layout layoutGet(CompoundContext context, Inode nfsInode, int ioMode, stateid4 stateid)
      throws IOException {

    FsInode inode = _fileFileSystemProvider.inodeFromBytes(nfsInode.getFileId());
    CDC cdc = CDC.reset(_cellName, _domainName);
    try {
      NDC.push(inode.toString());
      NDC.push(context.getRpcCall().getTransport().getRemoteSocketAddress().toString());
      deviceid4 deviceid;
      if (inode.type() != FsInodeType.INODE || inode.getLevel() != 0) {
        /*
         * all non regular files ( AKA pnfs dot files ) provided by door itself.
         */
        deviceid = MDS_ID;
      } else {

        final InetSocketAddress remote =
            context.getRpcCall().getTransport().getRemoteSocketAddress();
        final PnfsId pnfsId = new PnfsId(inode.toString());
        final NFS4ProtocolInfo protocolInfo =
            new NFS4ProtocolInfo(remote, new org.dcache.chimera.nfs.v4.xdr.stateid4(stateid));

        Transfer.initSession();
        NfsTransfer transfer = _ioMessages.get(stateid);
        if (transfer == null) {
          transfer =
              new NfsTransfer(_pnfsHandler, context.getRpcCall().getCredential().getSubject());

          transfer.setProtocolInfo(protocolInfo);
          transfer.setCellName(this.getCellName());
          transfer.setDomainName(this.getCellDomainName());
          transfer.setBillingStub(_billingStub);
          transfer.setPoolStub(_poolManagerStub);
          transfer.setPoolManagerStub(_poolManagerStub);
          transfer.setPnfsId(pnfsId);
          transfer.setClientAddress(remote);
          transfer.readNameSpaceEntry();

          _ioMessages.put(stateid, transfer);

          PoolDS ds = getPool(transfer, ioMode);
          deviceid = ds.getDeviceId();
        } else {
          PoolDS ds = transfer.waitForRedirect(NFS_RETRY_PERIOD);
          deviceid = ds.getDeviceId();
        }
      }

      nfs_fh4 fh = new nfs_fh4(nfsInode.toNfsHandle());

      //  -1 is special value, which means entire file
      layout4 layout = Layout.getLayoutSegment(deviceid, fh, ioMode, 0, nfs4_prot.NFS4_UINT64_MAX);

      return new Layout(true, stateid, new layout4[] {layout});

    } catch (FileInCacheException e) {
      cleanStateAndKillMover(stateid);
      throw new ChimeraNFSException(nfsstat.NFSERR_IO, e.getMessage());
    } catch (CacheException e) {
      cleanStateAndKillMover(stateid);
      /*
       * error 243: file is broken on tape.
       * can't do a much. Tell it to client.
       */
      int status =
          e.getRc() == CacheException.BROKEN_ON_TAPE
              ? nfsstat.NFSERR_IO
              : nfsstat.NFSERR_LAYOUTTRYLATER;
      throw new ChimeraNFSException(status, e.getMessage());
    } catch (InterruptedException e) {
      cleanStateAndKillMover(stateid);
      throw new ChimeraNFSException(nfsstat.NFSERR_LAYOUTTRYLATER, e.getMessage());
    } finally {
      cdc.close();
    }
  }