/** {@inheritDoc} */
  @Override
  public CacheQuery<T> timeout(long timeout) {
    A.ensure(timeout >= 0, "timeout >= 0");

    this.timeout = timeout;

    return this;
  }
  /** {@inheritDoc} */
  @Override
  public CacheQuery<T> pageSize(int pageSize) {
    A.ensure(pageSize > 0, "pageSize > 0");

    this.pageSize = pageSize;

    return this;
  }
  /** {@inheritDoc} */
  @Override
  public R get(long timeout, TimeUnit unit) throws IgniteCheckedException {
    A.ensure(timeout >= 0, "timeout cannot be negative: " + timeout);
    A.notNull(unit, "unit");

    try {
      return get0(unit.toNanos(timeout));
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();

      throw new IgniteInterruptedCheckedException(
          "Got interrupted while waiting for future to complete.", e);
    }
  }
예제 #4
0
  /**
   * Constructs LRU eviction policy with maximum size.
   *
   * @param max Maximum allowed size of cache before entry will start getting evicted.
   */
  public LruEvictionPolicy(int max) {
    A.ensure(max >= 0, "max >= 0");

    this.max = max;
  }
예제 #5
0
  /** {@inheritDoc} */
  @Override
  public void setMaxMemorySize(long maxMemSize) {
    A.ensure(maxMemSize >= 0, "maxMemSize >= 0");

    this.maxMemSize = maxMemSize;
  }
예제 #6
0
  /** {@inheritDoc} */
  @Override
  public void setBatchSize(int batchSize) {
    A.ensure(batchSize > 0, "batchSize > 0");

    this.batchSize = batchSize;
  }
예제 #7
0
  /**
   * Sets maximum allowed size of cache before entry will start getting evicted.
   *
   * @param max Maximum allowed size of cache before entry will start getting evicted.
   */
  @Override
  public void setMaxSize(int max) {
    A.ensure(max >= 0, "max >= 0");

    this.max = max;
  }
예제 #8
0
  /**
   * @param name URI passed to constructor.
   * @param cfg Configuration passed to constructor.
   * @throws IOException If initialization failed.
   */
  @SuppressWarnings("ConstantConditions")
  private void initialize(URI name, Configuration cfg) throws IOException {
    enterBusy();

    try {
      if (rmtClient != null)
        throw new IOException("File system is already initialized: " + rmtClient);

      A.notNull(name, "name");
      A.notNull(cfg, "cfg");

      if (!IGFS_SCHEME.equals(name.getScheme()))
        throw new IOException(
            "Illegal file system URI [expected="
                + IGFS_SCHEME
                + "://[name]/[optional_path], actual="
                + name
                + ']');

      uriAuthority = name.getAuthority();

      // Override sequential reads before prefetch if needed.
      seqReadsBeforePrefetch =
          parameter(cfg, PARAM_IGFS_SEQ_READS_BEFORE_PREFETCH, uriAuthority, 0);

      if (seqReadsBeforePrefetch > 0) seqReadsBeforePrefetchOverride = true;

      // In Ignite replication factor is controlled by data cache affinity.
      // We use replication factor to force the whole file to be stored on local node.
      dfltReplication = (short) cfg.getInt("dfs.replication", 3);

      // Get file colocation control flag.
      colocateFileWrites = parameter(cfg, PARAM_IGFS_COLOCATED_WRITES, uriAuthority, false);
      preferLocFileWrites = cfg.getBoolean(PARAM_IGFS_PREFER_LOCAL_WRITES, false);

      // Get log directory.
      String logDirCfg = parameter(cfg, PARAM_IGFS_LOG_DIR, uriAuthority, DFLT_IGFS_LOG_DIR);

      File logDirFile = U.resolveIgnitePath(logDirCfg);

      String logDir = logDirFile != null ? logDirFile.getAbsolutePath() : null;

      rmtClient = new HadoopIgfsWrapper(uriAuthority, logDir, cfg, LOG, user);

      // Handshake.
      IgfsHandshakeResponse handshake = rmtClient.handshake(logDir);

      grpBlockSize = handshake.blockSize();

      IgfsPaths paths = handshake.secondaryPaths();

      Boolean logEnabled = parameter(cfg, PARAM_IGFS_LOG_ENABLED, uriAuthority, false);

      if (handshake.sampling() != null ? handshake.sampling() : logEnabled) {
        // Initiate client logger.
        if (logDir == null) throw new IOException("Failed to resolve log directory: " + logDirCfg);

        Integer batchSize =
            parameter(cfg, PARAM_IGFS_LOG_BATCH_SIZE, uriAuthority, DFLT_IGFS_LOG_BATCH_SIZE);

        clientLog = IgfsLogger.logger(uriAuthority, handshake.igfsName(), logDir, batchSize);
      } else clientLog = IgfsLogger.disabledLogger();

      try {
        modeRslvr = new IgfsModeResolver(paths.defaultMode(), paths.pathModes());
      } catch (IgniteCheckedException ice) {
        throw new IOException(ice);
      }

      boolean initSecondary = paths.defaultMode() == PROXY;

      if (!initSecondary && paths.pathModes() != null) {
        for (T2<IgfsPath, IgfsMode> pathMode : paths.pathModes()) {
          IgfsMode mode = pathMode.getValue();

          if (mode == PROXY) {
            initSecondary = true;

            break;
          }
        }
      }

      if (initSecondary) {
        try {
          factory = (HadoopFileSystemFactory) paths.getPayload(getClass().getClassLoader());
        } catch (IgniteCheckedException e) {
          throw new IOException("Failed to get secondary file system factory.", e);
        }

        if (factory == null)
          throw new IOException(
              "Failed to get secondary file system factory (did you set "
                  + IgniteHadoopIgfsSecondaryFileSystem.class.getName()
                  + " as \"secondaryFIleSystem\" in "
                  + FileSystemConfiguration.class.getName()
                  + "?)");

        assert factory != null;

        if (factory instanceof LifecycleAware) ((LifecycleAware) factory).start();

        try {
          FileSystem secFs = factory.get(user);

          secondaryUri = secFs.getUri();

          A.ensure(secondaryUri != null, "Secondary file system uri should not be null.");
        } catch (IOException e) {
          throw new IOException(
              "Failed to connect to the secondary file system: " + secondaryUri, e);
        }
      }
    } finally {
      leaveBusy();
    }
  }
  /**
   * Constructs random eviction policy with maximum size.
   *
   * @param max Maximum allowed size of cache before entry will start getting evicted.
   */
  public RandomEvictionPolicy(int max) {
    A.ensure(max > 0, "max > 0");

    this.max = max;
  }
예제 #10
0
  /**
   * Sets given values starting at {@code 0} position.
   *
   * @param v Values to set.
   */
  public void set(Object... v) {
    A.ensure(v.length <= vals.length, "v.length <= vals.length");

    if (v.length > 0) System.arraycopy(v, 0, vals, 0, v.length);
  }
예제 #11
0
  /**
   * Sets value at given index.
   *
   * @param i Index to set.
   * @param v Value to set.
   * @param <V> Value type.
   */
  public <V> void set(int i, V v) {
    A.ensure(i < vals.length, "i < vals.length");

    vals[i] = v;
  }
예제 #12
0
  /**
   * Retrieves value at given index.
   *
   * @param i Index of the value to get.
   * @param <V> Value type.
   * @return Value at given index.
   */
  @SuppressWarnings({"unchecked"})
  public <V> V get(int i) {
    A.ensure(i < vals.length, "i < vals.length");

    return (V) vals[i];
  }
예제 #13
0
  /**
   * Initializes tuple with given object count.
   *
   * @param cnt Count of objects to be stored in the tuple.
   */
  public GridTupleV(int cnt) {
    A.ensure(cnt > 0, "cnt > 0");

    vals = new Object[cnt];
  }
예제 #14
0
  /**
   * Sets given values starting at provided position in the tuple.
   *
   * @param pos Position to start from.
   * @param v Values to set.
   */
  public void set(int pos, Object... v) {
    A.ensure(pos > 0, "pos > 0");
    A.ensure(v.length + pos <= vals.length, "v.length + pos <= vals.length");

    if (v.length > 0) System.arraycopy(v, 0, vals, pos, v.length);
  }