コード例 #1
0
ファイル: IgfsServer.java プロジェクト: vladisav/ignite
  /**
   * Stops this server.
   *
   * @param cancel Cancel flag.
   */
  public void stop(boolean cancel) {
    // Skip if did not start.
    if (srvEndpoint == null) return;

    // Stop accepting new client connections.
    U.cancel(acceptWorker);

    U.join(acceptWorker, log);

    // Stop server handler, no more requests on existing connections will be processed.
    try {
      hnd.stop();
    } catch (IgniteCheckedException e) {
      U.error(log, "Failed to stop IGFS server handler (will close client connections anyway).", e);
    }

    // Stop existing client connections.
    for (ClientWorker worker : clientWorkers) U.cancel(worker);

    U.join(clientWorkers, log);

    // IpcServerEndpoint.getPort contract states return -1 if there is no port to be registered.
    if (srvEndpoint.getPort() >= 0)
      igfsCtx
          .kernalContext()
          .ports()
          .deregisterPort(srvEndpoint.getPort(), TCP, srvEndpoint.getClass());

    try {
      igfsCtx.kernalContext().resource().cleanupGeneric(srvEndpoint);
    } catch (IgniteCheckedException e) {
      U.error(log, "Failed to cleanup server endpoint.", e);
    }
  }
コード例 #2
0
ファイル: IgfsServer.java プロジェクト: vladisav/ignite
  /**
   * Starts this server.
   *
   * @throws IgniteCheckedException If failed.
   */
  public void start() throws IgniteCheckedException {
    srvEndpoint = createEndpoint(endpointCfg, mgmt);

    if (U.isWindows() && srvEndpoint instanceof IpcSharedMemoryServerEndpoint)
      throw new IgniteCheckedException(
          IpcSharedMemoryServerEndpoint.class.getSimpleName()
              + " should not be configured on Windows (configure "
              + IpcServerTcpEndpoint.class.getSimpleName()
              + ")");

    if (srvEndpoint instanceof IpcServerTcpEndpoint) {
      IpcServerTcpEndpoint srvEndpoint0 = (IpcServerTcpEndpoint) srvEndpoint;

      srvEndpoint0.setManagement(mgmt);

      if (srvEndpoint0.getHost() == null) {
        if (mgmt) {
          String locHostName = igfsCtx.kernalContext().config().getLocalHost();

          try {
            srvEndpoint0.setHost(U.resolveLocalHost(locHostName).getHostAddress());
          } catch (IOException e) {
            throw new IgniteCheckedException("Failed to resolve local host: " + locHostName, e);
          }
        } else
          // Bind non-management endpoint to 127.0.0.1 by default.
          srvEndpoint0.setHost("127.0.0.1");
      }
    }

    igfsCtx.kernalContext().resource().injectGeneric(srvEndpoint);

    srvEndpoint.start();

    // IpcServerEndpoint.getPort contract states return -1 if there is no port to be registered.
    if (srvEndpoint.getPort() >= 0)
      igfsCtx
          .kernalContext()
          .ports()
          .registerPort(srvEndpoint.getPort(), TCP, srvEndpoint.getClass());

    hnd = new IgfsIpcHandler(igfsCtx, endpointCfg, mgmt);

    // Start client accept worker.
    acceptWorker = new AcceptWorker();
  }
コード例 #3
0
ファイル: IgfsServer.java プロジェクト: vladisav/ignite
  /**
   * Constructs igfs server manager.
   *
   * @param igfsCtx IGFS context.
   * @param endpointCfg Endpoint configuration to start.
   * @param mgmt Management flag - if true, server is intended to be started for Visor.
   */
  public IgfsServer(IgfsContext igfsCtx, IgfsIpcEndpointConfiguration endpointCfg, boolean mgmt) {
    assert igfsCtx != null;
    assert endpointCfg != null;

    this.endpointCfg = endpointCfg;
    this.igfsCtx = igfsCtx;
    this.mgmt = mgmt;

    log = igfsCtx.kernalContext().log(IgfsServer.class);

    marsh = new IgfsMarshaller();
  }
コード例 #4
0
  /**
   * Send delete message to all meta cache nodes in the grid.
   *
   * @param msg Message to send.
   */
  private void sendDeleteMessage(IgfsDeleteMessage msg) {
    assert msg != null;

    Collection<ClusterNode> nodes = meta.metaCacheNodes();

    for (ClusterNode node : nodes) {
      try {
        igfsCtx.send(node, topic, msg, GridIoPolicy.SYSTEM_POOL);
      } catch (IgniteCheckedException e) {
        U.warn(
            log,
            "Failed to send IGFS delete message to node [nodeId="
                + node.id()
                + ", msg="
                + msg
                + ", err="
                + e.getMessage()
                + ']');
      }
    }
  }
コード例 #5
0
ファイル: IgfsServer.java プロジェクト: vladisav/ignite
  /**
   * Create server IPC endpoint.
   *
   * @param endpointCfg Endpoint configuration.
   * @param mgmt Management flag.
   * @return Server endpoint.
   * @throws IgniteCheckedException If failed.
   */
  private IpcServerEndpoint createEndpoint(IgfsIpcEndpointConfiguration endpointCfg, boolean mgmt)
      throws IgniteCheckedException {
    A.notNull(endpointCfg, "endpointCfg");

    IgfsIpcEndpointType typ = endpointCfg.getType();

    if (typ == null)
      throw new IgniteCheckedException("Failed to create server endpoint (type is not specified)");

    switch (typ) {
      case SHMEM:
        {
          IpcSharedMemoryServerEndpoint endpoint =
              new IpcSharedMemoryServerEndpoint(
                  igfsCtx.kernalContext().config().getWorkDirectory());

          endpoint.setPort(endpointCfg.getPort());
          endpoint.setSize(endpointCfg.getMemorySize());
          endpoint.setTokenDirectoryPath(endpointCfg.getTokenDirectoryPath());

          return endpoint;
        }
      case TCP:
        {
          IpcServerTcpEndpoint endpoint = new IpcServerTcpEndpoint();

          endpoint.setHost(endpointCfg.getHost());
          endpoint.setPort(endpointCfg.getPort());
          endpoint.setManagement(mgmt);

          return endpoint;
        }
      default:
        throw new IgniteCheckedException(
            "Failed to create server endpoint (type is unknown): " + typ);
    }
  }
コード例 #6
0
  /**
   * Remove particular entry from the TRASH directory.
   *
   * @param name Entry name.
   * @param id Entry ID.
   * @return {@code True} in case the entry really was deleted form the file system by this call.
   * @throws IgniteCheckedException If failed.
   */
  private boolean delete(String name, IgniteUuid id) throws IgniteCheckedException {
    assert name != null;
    assert id != null;

    while (true) {
      IgfsFileInfo info = meta.info(id);

      if (info != null) {
        if (info.isDirectory()) {
          deleteDirectory(TRASH_ID, id);

          if (meta.delete(TRASH_ID, name, id)) return true;
        } else {
          assert info.isFile();

          // Delete file content first.
          // In case this node crashes, other node will re-delete the file.
          data.delete(info).get();

          boolean ret = meta.delete(TRASH_ID, name, id);

          if (evts.isRecordable(EVT_IGFS_FILE_PURGED)) {
            if (info.path() != null)
              evts.record(
                  new IgfsEvent(
                      info.path(),
                      igfsCtx.kernalContext().discovery().localNode(),
                      EVT_IGFS_FILE_PURGED));
            else LT.warn(log, null, "Removing file without path info: " + info);
          }

          return ret;
        }
      } else return false; // Entry was deleted concurrently.
    }
  }
コード例 #7
0
  /**
   * Constructor.
   *
   * @param igfsCtx IGFS context.
   */
  IgfsDeleteWorker(IgfsContext igfsCtx) {
    super(
        "igfs-delete-worker%"
            + igfsCtx.igfs().name()
            + "%"
            + igfsCtx.kernalContext().localNodeId()
            + "%");

    this.igfsCtx = igfsCtx;

    meta = igfsCtx.meta();
    data = igfsCtx.data();

    evts = igfsCtx.kernalContext().event();

    String igfsName = igfsCtx.igfs().name();

    topic = F.isEmpty(igfsName) ? TOPIC_IGFS : TOPIC_IGFS.topic(igfsName);

    assert meta != null;
    assert data != null;

    log = igfsCtx.kernalContext().log(IgfsDeleteWorker.class);
  }