Пример #1
0
  /**
   * @param key Key.
   * @param val Value.
   * @param ver Cache version.
   * @param p Optional predicate.
   * @param topVer Topology version.
   * @param replicate Replication flag.
   * @param plc Expiry policy.
   */
  private void loadEntry(
      KeyCacheObject key,
      Object val,
      GridCacheVersion ver,
      @Nullable IgniteBiPredicate<K, V> p,
      AffinityTopologyVersion topVer,
      boolean replicate,
      @Nullable ExpiryPolicy plc) {
    if (p != null && !p.apply(key.<K>value(ctx.cacheObjectContext(), false), (V) val)) return;

    try {
      GridDhtLocalPartition part =
          top.localPartition(ctx.affinity().partition(key), AffinityTopologyVersion.NONE, true);

      // Reserve to make sure that partition does not get unloaded.
      if (part.reserve()) {
        GridCacheEntryEx entry = null;

        try {
          long ttl = CU.ttlForLoad(plc);

          if (ttl == CU.TTL_ZERO) return;

          CacheObject cacheVal = ctx.toCacheObject(val);

          entry = entryEx(key, false);

          entry.initialValue(
              cacheVal,
              ver,
              ttl,
              CU.EXPIRE_TIME_CALCULATE,
              false,
              topVer,
              replicate ? DR_LOAD : DR_NONE,
              false);
        } catch (IgniteCheckedException e) {
          throw new IgniteException("Failed to put cache value: " + entry, e);
        } catch (GridCacheEntryRemovedException ignore) {
          if (log.isDebugEnabled())
            log.debug("Got removed entry during loadCache (will ignore): " + entry);
        } finally {
          if (entry != null) entry.context().evicts().touch(entry, topVer);

          part.release();
        }
      } else if (log.isDebugEnabled())
        log.debug("Will node load entry into cache (partition is invalid): " + part);
    } catch (GridDhtInvalidPartitionException e) {
      if (log.isDebugEnabled())
        log.debug(
            "Ignoring entry for partition that does not belong [key="
                + key
                + ", val="
                + val
                + ", err="
                + e
                + ']');
    }
  }
Пример #2
0
    /**
     * @param row Row.
     * @return If this row was accepted.
     */
    @SuppressWarnings("unchecked")
    @Override
    protected boolean accept(GridH2Row row) {
      if (row instanceof GridH2AbstractKeyValueRow) {
        if (((GridH2AbstractKeyValueRow) row).expirationTime() <= time) return false;
      }

      if (fltr == null) return true;

      Object key = row.getValue(keyCol).getObject();
      Object val = row.getValue(valCol).getObject();

      assert key != null;
      assert val != null;

      return fltr.apply(key, val);
    }