Package org.apache.ignite.internal.processors.cache.distributed.dht.topology

## Class GridClientPartitionTopology

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridClientPartitionTopology

All Implemented Interfaces:
  `GridDhtPartitionTopology`

    @GridToStringExclude
    public class GridClientPartitionTopology
    extends Object
    implements GridDhtPartitionTopology

Partition topology for node which does not have any local partitions.

### Constructor Summary

Constructors
`GridClientPartitionTopology​(GridCacheSharedContext<?,​?> cctx, DiscoCache discoCache, int grpId, int parts, Object similarAffKey, PartitionLossPolicy partLossPlc)`

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `afterExchange​(GridDhtPartitionsExchangeFuture exchFut)` Post-initializes this topology.
`void` `afterStateRestored​(AffinityTopologyVersion topVer)` Initializes local data structures after partitions are restored from persistence.
`List<List<ClusterNode>>` `allOwners()`
`void` `applyUpdateCounters()` Applies update counters collected during exchange on coordinator.
`void` `beforeExchange​(GridDhtPartitionsExchangeFuture exchFut, boolean initParts, boolean updateMoving)` Pre-initializes this topology.
`void` `collectUpdateCounters​(CachePartitionPartialCountersMap cntrMap)` Collects update counters collected during exchange.
`Collection<GridDhtLocalPartition>` `currentLocalPartitions()`
`boolean` `detectLostPartitions​(AffinityTopologyVersion affVer, GridDhtPartitionsExchangeFuture fut)` Checks if there is at least one owner for each partition in the cache topology for a local node.
`void` `finalizeUpdateCounters​(Set<Integer> parts)` Pre-processes partition update counters before exchange.
`GridDhtLocalPartition` `forceCreatePartition​(int p)` Unconditionally creates partition during restore of persisted partition state.
`CachePartitionFullCountersMap` `fullUpdateCounters()`
`@Nullable Map<Integer,​Long>` `globalPartSizes()`
`void` `globalPartSizes​(@Nullable Map<Integer,​Long> partSizes)`
`int` `groupId()`
`boolean` `hasMovingPartitions()`
`boolean` `holdsLock()`
`boolean` `initialized()`
`boolean` `initPartitionsWhenAffinityReady​(AffinityTopologyVersion affVer, GridDhtPartitionsExchangeFuture exchFut)`
`AffinityTopologyVersion` `lastTopologyChangeVersion()`
`long` `lastUpdateSequence()`
`GridDhtLocalPartition` `localPartition​(int p)`
`@Nullable GridDhtLocalPartition` `localPartition​(int p, AffinityTopologyVersion topVer, boolean create)`
`@Nullable GridDhtLocalPartition` `localPartition​(int p, AffinityTopologyVersion topVer, boolean create, boolean showRenting)`
`GridDhtPartitionMap` `localPartitionMap()`
`List<GridDhtLocalPartition>` `localPartitions()`
`CachePartitionPartialCountersMap` `localUpdateCounters​(boolean skipZeros)`
`Set<Integer>` `lostPartitions()`
`List<ClusterNode>` `moving​(int p)`
`@Nullable List<ClusterNode>` `nodes​(int p, AffinityAssignment affAssignment, List<ClusterNode> affNodes)`
`List<ClusterNode>` `nodes​(int p, AffinityTopologyVersion topVer)`
`void` `onExchangeDone​(GridDhtPartitionsExchangeFuture fut, AffinityAssignment assignment, boolean updateRebalanceVer)` Callback on exchange done.
`void` `onRemoved​(GridDhtCacheEntry e)`
`boolean` `own​(GridDhtLocalPartition part)`
`List<ClusterNode>` `owners​(int p)`
`List<ClusterNode>` `owners​(int p, AffinityTopologyVersion topVer)`
`void` `ownMoving()` Owns all moving partitions.
`GridDhtPartitionFullMap` `partitionMap​(boolean onlyActive)`
`int` `partitions()`
`@Nullable GridDhtPartitionMap` `partitions​(UUID nodeId)`
`Map<Integer,​Long>` `partitionSizes()`
`GridDhtPartitionState` `partitionState​(UUID nodeId, int part)`
`void` `printMemoryStats​(int threshold)` Prints memory stats.
`void` `readLock()` Locks the topology, usually during mapping on locks or transactions.
`void` `readUnlock()` Unlocks topology locked by `GridDhtPartitionTopology.readLock()` method.
`AffinityTopologyVersion` `readyTopologyVersion()`
`boolean` `rebalanceFinished​(AffinityTopologyVersion topVer)`
`void` `releasePartitions​(int... parts)`
`boolean` `rent​(int p)` Rents a partition and updates a partition map if the partition was switched to RENTING.
`void` `resetLostPartitions​(AffinityTopologyVersion affVer)` Resets the state of all LOST partitions to OWNING.
`Map<UUID,​Set<Integer>>` `resetOwners​(Map<Integer,​Set<UUID>> ownersByUpdCounters, Set<Integer> haveHist, GridDhtPartitionsExchangeFuture exchFut)` Calculates nodes and partitions which have non-actual state (based on LWM value) and must be rebalanced.
`@Nullable Object` `similarAffinityKey()`
`boolean` `stopping()`
`GridDhtTopologyFuture` `topologyVersionFuture()` Gets a future that will be completed when partition exchange map for this particular topology version is done.
`boolean` `tryFinishEviction​(GridDhtLocalPartition part)`
`boolean` `update​(@Nullable AffinityTopologyVersion exchangeVer, GridDhtPartitionFullMap partMap, @Nullable CachePartitionFullCountersMap cntrMap, Set<Integer> partsToReload, @Nullable Map<Integer,​Long> partSizes, @Nullable AffinityTopologyVersion msgTopVer, @Nullable GridDhtPartitionsExchangeFuture exchFut, @Nullable Set<Integer> lostParts)`
`boolean` `update​(@Nullable GridDhtPartitionExchangeId exchId, GridDhtPartitionMap parts, boolean force)`
`long` `updateSequence()`
`void` `updateTopologyVersion​(GridDhtTopologyFuture exchFut, DiscoCache discoCache, long updSeq, boolean stopping)` Updates topology version.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### GridClientPartitionTopology

    public GridClientPartitionTopology​(GridCacheSharedContext<?,​?> cctx,
                                       DiscoCache discoCache,
                                       int grpId,
                                       int parts,
                                       Object similarAffKey,
                                       PartitionLossPolicy partLossPlc)

Parameters:
  `cctx` - Context.
  `discoCache` - Discovery data cache.
  `grpId` - Group ID.
  `parts` - Number of partitions in the group.
  `similarAffKey` - Key to find caches with similar affinity.
  `partLossPlc` - Loss policy.

### Method Detail

#### partitions

    public int partitions()

Specified by:
  `partitions` in interface `GridDhtPartitionTopology`
Returns:
  Total cache partitions.

#### similarAffinityKey

    @Nullable
    public @Nullable Object similarAffinityKey()

Returns:
  Key to find caches with similar affinity.

#### groupId

    public int groupId()

Specified by:
  `groupId` in interface `GridDhtPartitionTopology`
Returns:
  Cache group ID.

#### readLock

    public void readLock()

Locks the topology, usually during mapping on locks or transactions.

Specified by:
  `readLock` in interface `GridDhtPartitionTopology`

#### readUnlock

    public void readUnlock()

Unlocks topology locked by `GridDhtPartitionTopology.readLock()` method.

Specified by:
  `readUnlock` in interface `GridDhtPartitionTopology`

#### holdsLock

    public boolean holdsLock()

Specified by:
  `holdsLock` in interface `GridDhtPartitionTopology`
Returns:
  `True` if locked by current thread.

#### updateTopologyVersion

    public void updateTopologyVersion​(GridDhtTopologyFuture exchFut,
                                      DiscoCache discoCache,
                                      long updSeq,
                                      boolean stopping)
                               throws IgniteInterruptedCheckedException

Updates topology version.

Specified by:
  `updateTopologyVersion` in interface `GridDhtPartitionTopology`
Parameters:
  `exchFut` - Exchange future.
  `discoCache` - Discovery data cache.
  `updSeq` - Update sequence.
  `stopping` - Stopping flag.
Throws:
  `IgniteInterruptedCheckedException` - If interrupted.

#### initialized

    public boolean initialized()

Specified by:
  `initialized` in interface `GridDhtPartitionTopology`
Returns:
  `True` If ready version initialized. `False` If not initialized.

#### readyTopologyVersion

    public AffinityTopologyVersion readyTopologyVersion()

Specified by:
  `readyTopologyVersion` in interface `GridDhtPartitionTopology`
Returns:
  Result topology version of last finished exchange.

#### lastTopologyChangeVersion

    public AffinityTopologyVersion lastTopologyChangeVersion()

Specified by:
  `lastTopologyChangeVersion` in interface `GridDhtPartitionTopology`
Returns:
  Start topology version of last exchange.

#### topologyVersionFuture

    public GridDhtTopologyFuture topologyVersionFuture()

Gets a future that will be completed when partition exchange map for this particular topology version is done.

Specified by:
  `topologyVersionFuture` in interface `GridDhtPartitionTopology`
Returns:
  Topology version ready future.

#### stopping

    public boolean stopping()

Specified by:
  `stopping` in interface `GridDhtPartitionTopology`
Returns:
  `True` if cache is being stopped.

#### initPartitionsWhenAffinityReady

    public boolean initPartitionsWhenAffinityReady​(AffinityTopologyVersion affVer,
                                                   GridDhtPartitionsExchangeFuture exchFut)

Specified by:
  `initPartitionsWhenAffinityReady` in interface `GridDhtPartitionTopology`
Parameters:
  `affVer` - Affinity version.
  `exchFut` - Exchange future.
Returns:
  `True` if partitions must be refreshed.

#### beforeExchange

    public void beforeExchange​(GridDhtPartitionsExchangeFuture exchFut,
                               boolean initParts,
                               boolean updateMoving)
                        throws IgniteCheckedException

Pre-initializes this topology.

Specified by:
  `beforeExchange` in interface `GridDhtPartitionTopology`
Parameters:
  `exchFut` - Exchange future.
  `initParts` - Affinity ready flag.
  `updateMoving` - `True` to initialize partition maps with moving partitions.
Throws:
  `IgniteCheckedException` - If failed.

#### afterStateRestored

    public void afterStateRestored​(AffinityTopologyVersion topVer)

Initializes local data structures after partitions are restored from persistence.

Specified by:
  `afterStateRestored` in interface `GridDhtPartitionTopology`
Parameters:
  `topVer` - Topology version.

#### afterExchange

    public boolean afterExchange​(GridDhtPartitionsExchangeFuture exchFut)
                          throws IgniteCheckedException

Post-initializes this topology.

Specified by:
  `afterExchange` in interface `GridDhtPartitionTopology`
Parameters:
  `exchFut` - Exchange future.
Returns:
  `True` if mapping was changed.
Throws:
  `IgniteCheckedException` - If failed.

#### localPartition

    @Nullable
    public @Nullable GridDhtLocalPartition localPartition​(int p,
                                                          AffinityTopologyVersion topVer,
                                                          boolean create)
                                                   throws GridDhtInvalidPartitionException

Specified by:
  `localPartition` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
  `topVer` - Topology version at the time of creation.
  `create` - If `true`, then partition will be created if it's not there.
Returns:
  Local partition.
Throws:
  `GridDhtInvalidPartitionException` - If partition is evicted or absent and does not belong to this node.

#### localPartition

    @Nullable
    public @Nullable GridDhtLocalPartition localPartition​(int p,
                                                          AffinityTopologyVersion topVer,
                                                          boolean create,
                                                          boolean showRenting)
                                                   throws GridDhtInvalidPartitionException

Specified by:
  `localPartition` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
  `topVer` - Topology version at the time of creation.
  `create` - If `true`, then partition will be created if it's not there.
Returns:
  Local partition.
Throws:
  `GridDhtInvalidPartitionException` - If partition is evicted or absent and does not belong to this node.

#### forceCreatePartition

    public GridDhtLocalPartition forceCreatePartition​(int p)
                                               throws IgniteCheckedException

Unconditionally creates partition during restore of persisted partition state.

Specified by:
  `forceCreatePartition` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
Returns:
  Partition.
Throws:
  `IgniteCheckedException` - If failed.

#### localPartition

    public GridDhtLocalPartition localPartition​(int p)

Specified by:
  `localPartition` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition number.
Returns:
  Local partition.

#### releasePartitions

    public void releasePartitions​(int... parts)

Specified by:
  `releasePartitions` in interface `GridDhtPartitionTopology`
Parameters:
  `parts` - Partitions to release (should be reserved before).

#### localPartitions

    public List<GridDhtLocalPartition> localPartitions()

Specified by:
  `localPartitions` in interface `GridDhtPartitionTopology`
Returns:
  All local partitions by copying them into another list.

#### currentLocalPartitions

    public Collection<GridDhtLocalPartition> currentLocalPartitions()

Specified by:
  `currentLocalPartitions` in interface `GridDhtPartitionTopology`
Returns:
  All current active local partitions.

#### onRemoved

    public void onRemoved​(GridDhtCacheEntry e)

Specified by:
  `onRemoved` in interface `GridDhtPartitionTopology`
Parameters:
  `e` - Entry removed from cache.

#### localPartitionMap

    public GridDhtPartitionMap localPartitionMap()

Specified by:
  `localPartitionMap` in interface `GridDhtPartitionTopology`
Returns:
  Local IDs.

#### partitionState

    public GridDhtPartitionState partitionState​(UUID nodeId,
                                                int part)

Specified by:
  `partitionState` in interface `GridDhtPartitionTopology`
Parameters:
  `nodeId` - Node ID.
  `part` - Partition.
Returns:
  Partition state.

#### nodes

    @Nullable
    public @Nullable List<ClusterNode> nodes​(int p,
                                             AffinityAssignment affAssignment,
                                             List<ClusterNode> affNodes)

Specified by:
  `nodes` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
  `affAssignment` - Assignments.
  `affNodes` - Node assigned for given partition by affinity.
Returns:
  Collection of all nodes responsible for this partition with primary node being first. The first N elements of this collection (with N being 1 + backups) are actual DHT affinity nodes, other nodes are current additional owners of the partition after topology change.

#### nodes

    public List<ClusterNode> nodes​(int p,
                                   AffinityTopologyVersion topVer)

Specified by:
  `nodes` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
  `topVer` - Topology version.
Returns:
  Collection of all nodes responsible for this partition with primary node being first.

#### owners

    public List<ClusterNode> owners​(int p,
                                    AffinityTopologyVersion topVer)

Specified by:
  `owners` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
  `topVer` - Topology version.
Returns:
  Collection of all nodes who `own` this partition.

#### owners

    public List<ClusterNode> owners​(int p)

Specified by:
  `owners` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
Returns:
  Collection of all nodes who `own` this partition.

#### allOwners

    public List<List<ClusterNode>> allOwners()

Specified by:
  `allOwners` in interface `GridDhtPartitionTopology`
Returns:
  List indexed by partition number, each list element is collection of all nodes who owns corresponding partition.

#### moving

    public List<ClusterNode> moving​(int p)

Specified by:
  `moving` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
Returns:
  Collection of all nodes who `are preloading` this partition.

#### updateSequence

    public long updateSequence()

Specified by:
  `updateSequence` in interface `GridDhtPartitionTopology`
Returns:
  Current update sequence.

#### lastUpdateSequence

    public long lastUpdateSequence()

Returns:
  Last update sequence.

#### partitionMap

    public GridDhtPartitionFullMap partitionMap​(boolean onlyActive)

Specified by:
  `partitionMap` in interface `GridDhtPartitionTopology`
Parameters:
  `onlyActive` - If `true`, then only `active` partitions will be returned.
Returns:
  Node IDs mapped to partitions.

#### update

    public boolean update​(@Nullable
                          @Nullable AffinityTopologyVersion exchangeVer,
                          GridDhtPartitionFullMap partMap,
                          @Nullable
                          @Nullable CachePartitionFullCountersMap cntrMap,
                          Set<Integer> partsToReload,
                          @Nullable
                          @Nullable Map<Integer,​Long> partSizes,
                          @Nullable
                          @Nullable AffinityTopologyVersion msgTopVer,
                          @Nullable
                          @Nullable GridDhtPartitionsExchangeFuture exchFut,
                          @Nullable
                          @Nullable Set<Integer> lostParts)

Specified by:
  `update` in interface `GridDhtPartitionTopology`
Parameters:
  `exchangeVer` - Result topology version for exchange. Value should be greater than previously passed. Null value means full map received is not related to exchange
  `partMap` - Update partition map.
  `cntrMap` - Partition update counters.
  `partsToReload` - Set of partitions that need to be reloaded.
  `partSizes` - Global partition sizes.
  `msgTopVer` - Topology version from incoming message. This value is not null only for case message is not related to exchange. Value should be not less than previous 'Topology version from exchange'.
  `exchFut` - Future which is not null for initial partition update on exchange.
  `lostParts` - Lost partitions.
Returns:
  `True` if local state was changed.

#### collectUpdateCounters

    public void collectUpdateCounters​(CachePartitionPartialCountersMap cntrMap)

Collects update counters collected during exchange. Called on coordinator.

Specified by:
  `collectUpdateCounters` in interface `GridDhtPartitionTopology`
Parameters:
  `cntrMap` - Counters map.

#### applyUpdateCounters

    public void applyUpdateCounters()

Applies update counters collected during exchange on coordinator. Called on coordinator.

Specified by:
  `applyUpdateCounters` in interface `GridDhtPartitionTopology`

#### update

    public boolean update​(@Nullable
                          @Nullable GridDhtPartitionExchangeId exchId,
                          GridDhtPartitionMap parts,
                          boolean force)

Specified by:
  `update` in interface `GridDhtPartitionTopology`
Parameters:
  `exchId` - Exchange ID.
  `parts` - Partitions.
  `force` - `True` to skip stale update check.
Returns:
  `True` if local state was changed.

#### onExchangeDone

    public void onExchangeDone​(GridDhtPartitionsExchangeFuture fut,
                               AffinityAssignment assignment,
                               boolean updateRebalanceVer)

Callback on exchange done.

Specified by:
  `onExchangeDone` in interface `GridDhtPartitionTopology`
  `assignment` - New affinity assignment.
  `updateRebalanceVer` - `True` if need check rebalance state.

#### detectLostPartitions

    public boolean detectLostPartitions​(AffinityTopologyVersion affVer,
                                        GridDhtPartitionsExchangeFuture fut)

Checks if there is at least one owner for each partition in the cache topology for a local node. If not marks such a partition as LOST or OWNING depending on a policy.

Specified by:
  `detectLostPartitions` in interface `GridDhtPartitionTopology`
Parameters:
  `affVer` - Exchange result version.
  `fut` - Exchange futute for topology events to detect.
Returns:
  `True` if partitions state got updated.

#### resetLostPartitions

    public void resetLostPartitions​(AffinityTopologyVersion affVer)

Resets the state of all LOST partitions to OWNING.

Specified by:
  `resetLostPartitions` in interface `GridDhtPartitionTopology`
Parameters:
  `affVer` - Exchange result version.

#### lostPartitions

    public Set<Integer> lostPartitions()

Specified by:
  `lostPartitions` in interface `GridDhtPartitionTopology`
Returns:
  Collection of lost partitions, if any.

#### own

    public boolean own​(GridDhtLocalPartition part)

Specified by:
  `own` in interface `GridDhtPartitionTopology`
Parameters:
  `part` - Partition to own.
Returns:
  `True` if owned.

#### ownMoving

    public void ownMoving()

Owns all moving partitions.

Specified by:
  `ownMoving` in interface `GridDhtPartitionTopology`

#### tryFinishEviction

    public boolean tryFinishEviction​(GridDhtLocalPartition part)

Specified by:
  `tryFinishEviction` in interface `GridDhtPartitionTopology`
Parameters:
  `part` - Evicted partition.
Returns:
  `True` if a partition was destroyed by this call.

#### partitions

    @Nullable
    public @Nullable GridDhtPartitionMap partitions​(UUID nodeId)

Specified by:
  `partitions` in interface `GridDhtPartitionTopology`
Parameters:
  `nodeId` - Node to get partitions for.
Returns:
  Partitions for node.

#### resetOwners

    public Map<UUID,​Set<Integer>> resetOwners​(Map<Integer,​Set<UUID>> ownersByUpdCounters,
                                                    Set<Integer> haveHist,
                                                    GridDhtPartitionsExchangeFuture exchFut)

Calculates nodes and partitions which have non-actual state (based on LWM value) and must be rebalanced. State of all current owners that aren't contained in the given `ownersByUpdCounters` will be reset to MOVING. Called on coordinator during assignment of partition states.

Specified by:
  `resetOwners` in interface `GridDhtPartitionTopology`
Parameters:
  `ownersByUpdCounters` - Map (partition, set of node IDs that have most actual state about partition (update counter is maximal) and should hold OWNING state for such partition).
  `haveHist` - Set of partitions which have WAL history to rebalance.
  `exchFut` - Exchange future for operation.
Returns:
  Map (nodeId, set of partitions that should be rebalanced fully by this node).

#### fullUpdateCounters

    public CachePartitionFullCountersMap fullUpdateCounters()

Specified by:
  `fullUpdateCounters` in interface `GridDhtPartitionTopology`
Returns:
  Partition update counters.

#### localUpdateCounters

    public CachePartitionPartialCountersMap localUpdateCounters​(boolean skipZeros)

Specified by:
  `localUpdateCounters` in interface `GridDhtPartitionTopology`
Parameters:
  `skipZeros` - `True` to exclude zero counters from map.
Returns:
  Partition update counters.

#### finalizeUpdateCounters

    public void finalizeUpdateCounters​(Set<Integer> parts)

Pre-processes partition update counters before exchange.

Specified by:
  `finalizeUpdateCounters` in interface `GridDhtPartitionTopology`
Parameters:
  `parts` - Partitions.

#### partitionSizes

    public Map<Integer,​Long> partitionSizes()

Specified by:
  `partitionSizes` in interface `GridDhtPartitionTopology`
Returns:
  Partition cache sizes.

#### globalPartSizes

    @Nullable
    public @Nullable Map<Integer,​Long> globalPartSizes()

Specified by:
  `globalPartSizes` in interface `GridDhtPartitionTopology`
Returns:
  Sizes of up-to-date partition versions in topology.

#### globalPartSizes

    public void globalPartSizes​(@Nullable
                                @Nullable Map<Integer,​Long> partSizes)

Specified by:
  `globalPartSizes` in interface `GridDhtPartitionTopology`
Parameters:
  `partSizes` - Sizes of up-to-date partition versions in topology.

#### rebalanceFinished

    public boolean rebalanceFinished​(AffinityTopologyVersion topVer)

Specified by:
  `rebalanceFinished` in interface `GridDhtPartitionTopology`
Parameters:
  `topVer` - Topology version.
Returns:
  `True` if rebalance process finished.

#### hasMovingPartitions

    public boolean hasMovingPartitions()

Specified by:
  `hasMovingPartitions` in interface `GridDhtPartitionTopology`
Returns:
  `True` If one of cache nodes has partitions in `GridDhtPartitionState.MOVING` state.

#### printMemoryStats

    public void printMemoryStats​(int threshold)

Prints memory stats.

Specified by:
  `printMemoryStats` in interface `GridDhtPartitionTopology`
Parameters:
  `threshold` - Threshold for number of entries.

#### rent

    public boolean rent​(int p)

Rents a partition and updates a partition map if the partition was switched to RENTING.

Specified by:
  `rent` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
Returns:
  `True` if the partition was switched to RENTING.