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

## Class GridClientPartitionTopology

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.distributed.dht.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
Constructor and Description
`GridClientPartitionTopology(GridCacheSharedContext cctx, int grpId, GridDhtPartitionsExchangeFuture exchFut, Object similarAffKey)`

### Method Summary

Methods
`boolean` `afterExchange(GridDhtPartitionsExchangeFuture exchFut)` Post-initializes this topology.
`void` `applyUpdateCounters(Map<Integer,T2<Long,Long>> cntrMap)`
`void` `beforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean initParts)` Pre-initializes this topology.
`Collection<GridDhtLocalPartition>` `currentLocalPartitions()`
`boolean` `detectLostPartitions(DiscoveryEvent discoEvt)` Checks if there is at least one owner for each partition in the cache topology.
`int` `groupId()`
`boolean` `hasMovingPartitions()`
`void` `initPartitions(GridDhtPartitionsExchangeFuture exchFut)`
`long` `lastUpdateSequence()`
`GridDhtLocalPartition` `localPartition(int p)`
`GridDhtLocalPartition` `localPartition(int p, AffinityTopologyVersion topVer, boolean create)`
`GridDhtLocalPartition` `localPartition(int p, AffinityTopologyVersion topVer, boolean create, boolean showRenting)`
`GridDhtPartitionMap` `localPartitionMap()`
`List<GridDhtLocalPartition>` `localPartitions()`
`Collection<Integer>` `lostPartitions()`
`List<ClusterNode>` `moving(int p)`
`List<ClusterNode>` `nodes(int p, AffinityAssignment affAssignment, List<ClusterNode> affNodes)`
`List<ClusterNode>` `nodes(int p, AffinityTopologyVersion topVer)`
`void` `onEvicted(GridDhtLocalPartition part, boolean updateSeq)`
`void` `onExchangeDone(AffinityAssignment assignment)` Callback on exchange done.
`void` `onRemoved(GridDhtCacheEntry e)`
`boolean` `own(GridDhtLocalPartition part)`
`List<ClusterNode>` `owners(int p)`
`List<ClusterNode>` `owners(int p, AffinityTopologyVersion topVer)`
`GridDhtPartitionFullMap` `partitionMap(boolean onlyActive)`
`GridDhtPartitionMap` `partitions(UUID nodeId)`
`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.
`boolean` `rebalanceFinished(AffinityTopologyVersion topVer)`
`void` `releasePartitions(int... parts)`
`void` `resetLostPartitions()` Resets the state of all LOST partitions to OWNING.
`Set<UUID>` `setOwners(int p, Set<UUID> owners, boolean haveHistory, boolean updateSeq)` Make nodes from provided set owners for a given partition.
`Object` `similarAffinityKey()`
`boolean` `stopping()`
`AffinityTopologyVersion` `topologyVersion()` Topology version.
`GridDhtTopologyFuture` `topologyVersionFuture()` Gets a future that will be completed when partition exchange map for this particular topology version is done.
`boolean` `update(AffinityTopologyVersion exchangeVer, GridDhtPartitionFullMap partMap, Map<Integer,T2<Long,Long>> cntrMap, Set<Integer> partsToReload)`
`boolean` `update(GridDhtPartitionExchangeId exchId, GridDhtPartitionMap parts)`
`Map<Integer,T2<Long,Long>>` `updateCounters(boolean skipZeros)`
`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,
                               int grpId,
                               GridDhtPartitionsExchangeFuture exchFut,
                               Object similarAffKey)

Parameters:
  `cctx` - Context.
  `grpId` - Group ID.
  `exchFut` - Exchange ID.
  `similarAffKey` - Key to find caches with similar affinity.

### Method Detail

#### similarAffinityKey

    @Nullable
    public 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`

#### 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.

#### topologyVersion

    public AffinityTopologyVersion topologyVersion()

Topology version.

Specified by:
  `topologyVersion` in interface `GridDhtPartitionTopology`
Returns:
  Topology version.

#### 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.

#### initPartitions

    public void initPartitions(GridDhtPartitionsExchangeFuture exchFut)

Specified by:
  `initPartitions` in interface `GridDhtPartitionTopology`
Parameters:
  `exchFut` - Exchange future.

#### beforeExchange

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

Pre-initializes this topology.

Specified by:
  `beforeExchange` in interface `GridDhtPartitionTopology`
Parameters:
  `exchFut` - Exchange future.
  `initParts` - Affinity ready flag.
Throws:
  `IgniteCheckedException` - If failed.

#### 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 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 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.

#### 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 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.

#### 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.

#### 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
                 AffinityTopologyVersion exchangeVer,
                 GridDhtPartitionFullMap partMap,
                 Map<Integer,T2<Long,Long>> cntrMap,
                 Set<Integer> partsToReload)

Specified by:
  `update` in interface `GridDhtPartitionTopology`
Parameters:
  `exchangeVer` - Exchange version.
  `partMap` - Update partition map.
  `cntrMap` - Partition update counters.
Returns:
  `True` if local state was changed.

#### applyUpdateCounters

    public void applyUpdateCounters(Map<Integer,T2<Long,Long>> cntrMap)

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

#### update

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

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

#### onExchangeDone

    public void onExchangeDone(AffinityAssignment assignment)

Callback on exchange done.

Specified by:
  `onExchangeDone` in interface `GridDhtPartitionTopology`
Parameters:
  `assignment` - New affinity assignment.

#### detectLostPartitions

    public boolean detectLostPartitions(DiscoveryEvent discoEvt)

Checks if there is at least one owner for each partition in the cache topology. If not, marks such a partition as LOST.

This method should be called on topology coordinator after all partition messages are received.

Specified by:
  `detectLostPartitions` in interface `GridDhtPartitionTopology`
Parameters:
  `discoEvt` - Discovery event for which we detect lost partitions.
Returns:
  `True` if partitions state got updated.

#### resetLostPartitions

    public void resetLostPartitions()

Resets the state of all LOST partitions to OWNING.

Specified by:
  `resetLostPartitions` in interface `GridDhtPartitionTopology`

#### lostPartitions

    public Collection<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.

#### onEvicted

    public void onEvicted(GridDhtLocalPartition part,
                 boolean updateSeq)

Specified by:
  `onEvicted` in interface `GridDhtPartitionTopology`
Parameters:
  `part` - Evicted partition.
  `updateSeq` - Update sequence increment flag.

#### partitions

    @Nullable
    public GridDhtPartitionMap partitions(UUID nodeId)

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

#### setOwners

    public Set<UUID> setOwners(int p,
                      Set<UUID> owners,
                      boolean haveHistory,
                      boolean updateSeq)

Make nodes from provided set owners for a given partition. State of all current owners that aren't contained in the set will be reset to MOVING.

Specified by:
  `setOwners` in interface `GridDhtPartitionTopology`
Parameters:
  `p` - Partition ID.
  `owners` - Set of new owners.
  `updateSeq` - If should increment sequence when updated.
Returns:
  Set of node IDs that should reload partitions.

#### updateCounters

    public Map<Integer,T2<Long,Long>> updateCounters(boolean skipZeros)

Specified by:
  `updateCounters` in interface `GridDhtPartitionTopology`
Parameters:
  `skipZeros` - If `true` then filters out zero counters.
Returns:
  Partition update counters.

#### 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.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.1.0
Release Date | : July 20 2017