Beispiel #1
0
  /** {@inheritDoc} */
  @Override
  public void start0() throws GridException {
    aff =
        new GridAffinityAssignmentCache(
            cctx,
            cctx.namex(),
            cctx.config().getAffinity(),
            cctx.config().getAffinityMapper(),
            cctx.config().getBackups());

    // Generate internal keys for partitions.
    int partCnt = partitions();

    partAffKeys = new GridPartitionLockKey[partCnt];

    Collection<Integer> found = new HashSet<>();

    long affKey = 0;

    while (true) {
      GridPartitionLockKey key = new GridPartitionLockKey(affKey);

      int part = aff.partition(key);

      if (found.add(part)) {
        // This is a key for not yet calculated partition.
        key.partitionId(part);

        partAffKeys[part] = key;

        if (found.size() == partCnt) break;
      }

      affKey++;

      if (affKey > partCnt * MAX_PARTITION_KEY_ATTEMPT_RATIO)
        throw new IllegalStateException(
            "Failed to calculate partition affinity keys for given affinity "
                + "function [attemptCnt="
                + affKey
                + ", found="
                + found
                + ", cacheName="
                + cctx.name()
                + ']');
    }
  }
Beispiel #2
0
 /** {@inheritDoc} */
 @Override
 protected void onKernalStart0() throws GridException {
   if (cctx.isLocal())
     // No discovery event needed for local affinity.
     aff.calculate(1, null);
 }
Beispiel #3
0
 /** @return Affinity-ready topology version. */
 public long affinityTopologyVersion() {
   return aff.lastVersion();
 }
Beispiel #4
0
  /**
   * @param part Partition.
   * @param topVer Topology version.
   * @return Affinity nodes.
   */
  public Collection<GridNode> nodes(int part, long topVer) {
    if (cctx.isLocal()) topVer = 1;

    return aff.nodes(part, topVer);
  }
Beispiel #5
0
  /**
   * @param nodeId Node ID.
   * @param topVer Topology version to calculate affinity.
   * @return Partitions for which given node is backup.
   */
  public Set<Integer> backupPartitions(UUID nodeId, long topVer) {
    if (cctx.isLocal()) topVer = 1;

    return aff.backupPartitions(nodeId, topVer);
  }
Beispiel #6
0
 /** @return Partition count. */
 public int partitions() {
   return aff.partitions();
 }
Beispiel #7
0
 /**
  * NOTE: Use this method always when you need to calculate partition id for a key provided by
  * user. It's required since we should apply affinity mapper logic in order to find a key that
  * will eventually be passed to affinity function.
  *
  * @param key Key.
  * @return Partition.
  */
 public <T> int partition(T key) {
   return aff.partition(key);
 }
Beispiel #8
0
  /**
   * Calculates affinity cache for given topology version.
   *
   * @param topVer Topology version to calculate affinity for.
   * @param discoEvt Discovery event that causes this topology change.
   */
  public List<List<GridNode>> calculateAffinity(long topVer, GridDiscoveryEvent discoEvt) {
    assert !cctx.isLocal();

    return aff.calculate(topVer, discoEvt);
  }
Beispiel #9
0
  /**
   * @param topVer Topology version.
   * @return Affinity assignments.
   */
  public List<List<GridNode>> assignments(long topVer) {
    if (cctx.isLocal()) topVer = 1;

    return aff.assignments(topVer);
  }
Beispiel #10
0
  /**
   * Initializes affinity for joined node.
   *
   * @param topVer Topology version.
   * @param affAssignment Affinity assignment for this topology version.
   */
  public void initializeAffinity(long topVer, List<List<GridNode>> affAssignment) {
    assert !cctx.isLocal();

    aff.initialize(topVer, affAssignment);
  }
Beispiel #11
0
  /**
   * Clean up outdated cache items.
   *
   * @param topVer Actual topology version, older versions will be removed.
   */
  public void cleanUpCache(long topVer) {
    assert !cctx.isLocal();

    aff.cleanUpCache(topVer);
  }
Beispiel #12
0
  /**
   * Gets affinity ready future, a future that will be completed after affinity with given topology
   * version is calculated.
   *
   * @param topVer Topology version to affinity for.
   * @return Affinity ready future.
   */
  public GridFuture<Long> affinityReadyFuture(long topVer) {
    assert !cctx.isLocal();

    return aff.readyFuture(topVer);
  }