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

## Class GridDhtPartitionTopologyImpl

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

All Implemented Interfaces:
  GridDhtPartitionTopology

    @GridToStringExclude
    public class GridDhtPartitionTopologyImpl
    extends Object
    implements GridDhtPartitionTopology

Partition topology.

### Constructor Summary

Constructors
Constructor and Description
`GridDhtPartitionTopologyImpl(GridCacheSharedContext ctx, CacheGroupContext grp)`

### 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 affReady, boolean updateMoving)` Pre-initializes this topology.
`void` `collectUpdateCounters(CachePartitionPartialCountersMap cntrMap)` Collects update counters collected during exchange.
`Iterable<GridDhtLocalPartition>` `currentLocalPartitions()`
`boolean` `detectLostPartitions(AffinityTopologyVersion resTopVer, DiscoveryEvent discoEvt)` Checks if there is at least one owner for each partition in the cache topology.
`GridDhtLocalPartition` `forceCreatePartition(int p)` Unconditionally creates partition during restore of persisted partition state.
`CachePartitionFullCountersMap` `fullUpdateCounters()`
`Map<Integer,Long>` `globalPartSizes()`
`void` `globalPartSizes(Map<Integer,Long> partSizes)`
`int` `groupId()`
`boolean` `hasMovingPartitions()`
`boolean` `holdsLock()`
`boolean` `initPartitionsWhenAffinityReady(AffinityTopologyVersion affVer, GridDhtPartitionsExchangeFuture exchFut)`
`AffinityTopologyVersion` `lastTopologyChangeVersion()`
`GridDhtLocalPartition` `localPartition(int part)`
`GridDhtLocalPartition` `localPartition(int p, AffinityTopologyVersion topVer, boolean create)`
`GridDhtLocalPartition` `localPartition(int p, AffinityTopologyVersion topVer, boolean create, boolean showRenting)`
`GridDhtPartitionMap` `localPartitionMap()`
`List<GridDhtLocalPartition>` `localPartitions()`
`CachePartitionPartialCountersMap` `localUpdateCounters(boolean skipZeros, boolean finalizeCntrsBeforeCollecting)`
`Collection<Integer>` `lostPartitions()`
`List<ClusterNode>` `moving(int p)`
`MvccCoordinator` `mvccCoordinator()`
`List<ClusterNode>` `nodes(int p, AffinityAssignment affAssignment, List<ClusterNode> affNodes)`
`List<ClusterNode>` `nodes(int p, AffinityTopologyVersion topVer)`
`void` `onCacheStopped(int cacheId)`
`void` `onEvicted(GridDhtLocalPartition part, boolean updateSeq)`
`void` `onExchangeDone(GridDhtPartitionsExchangeFuture fut, AffinityAssignment assignment, boolean updateRebalanceVer)` Callback on exchange done.
`void` `onReconnected()`
`void` `onRemoved(GridDhtCacheEntry e)`
`boolean` `own(GridDhtLocalPartition part)`
`List<ClusterNode>` `owners(int p)`
`List<ClusterNode>` `owners(int p, AffinityTopologyVersion topVer)`
`void` `ownMoving(AffinityTopologyVersion topVer)` Owns all moving partitions for the given topology version.
`GridDhtPartitionFullMap` `partitionMap(boolean onlyActive)`
`int` `partitions()`
`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)`
`void` `resetLostPartitions(AffinityTopologyVersion resTopVer)` Resets the state of all LOST partitions to OWNING.
`Map<UUID,Set<Integer>>` `resetOwners(Map<Integer,Set<UUID>> ownersByUpdCounters, Set<Integer> haveHistory)` Calculates nodes and partitions which have non-actual state and must be rebalanced.
`boolean` `stopping()`
`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, CachePartitionFullCountersMap incomeCntrMap, Set<Integer> partsToReload, Map<Integer,Long> partSizes, AffinityTopologyVersion msgTopVer)`
`boolean` `update(GridDhtPartitionExchangeId exchId, GridDhtPartitionMap parts, boolean force)`
`long` `updateSequence()`
`void` `updateTopologyVersion(GridDhtTopologyFuture exchFut, DiscoCache discoCache, MvccCoordinator mvccCrd, 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

#### GridDhtPartitionTopologyImpl

    public GridDhtPartitionTopologyImpl(GridCacheSharedContext ctx,
                                        CacheGroupContext grp)

Parameters:
  `ctx` - Cache shared context.
  `grp` - Cache group.

### Method Detail

#### partitions

    public int partitions()

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

#### groupId

    public int groupId()

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

#### onReconnected

    public void onReconnected()

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

#### mvccCoordinator

    public MvccCoordinator mvccCoordinator()

Specified by:
  `mvccCoordinator` 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,
                                      @NotNull
                                      DiscoCache discoCache,
                                      MvccCoordinator mvccCrd,
                                      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.

#### 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)
                                            throws IgniteInterruptedCheckedException

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

#### beforeExchange

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

Pre-initializes this topology.

Specified by:
  `beforeExchange` in interface `GridDhtPartitionTopology`
Parameters:
  `exchFut` - Exchange future.
  `affReady` - Affinity ready flag.
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)

Post-initializes this topology.

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

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

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

#### releasePartitions

    public void releasePartitions(int... parts)

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

#### localPartition

    public GridDhtLocalPartition localPartition(int part)

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

#### localPartitions

    public List<GridDhtLocalPartition> localPartitions()

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

#### currentLocalPartitions

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

#### 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,
                          @Nullable
                          CachePartitionFullCountersMap incomeCntrMap,
                          Set<Integer> partsToReload,
                          @Nullable
                          Map<Integer,Long> partSizes,
                          @Nullable
                          AffinityTopologyVersion msgTopVer)

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.
  `incomeCntrMap` - Partition update counters.
  `partsToReload` - Set of partitions that need to be reloaded.
  `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'.
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
                          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(@Nullable
                               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 resTopVer,
                                        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:
  `resTopVer` - Exchange result version.
  `discoEvt` - Discovery event for which we detect lost partitions.
Returns:
  `True` if partitions state got updated.

#### resetLostPartitions

    public void resetLostPartitions(AffinityTopologyVersion resTopVer)

Resets the state of all LOST partitions to OWNING.

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

#### lostPartitions

    public Collection<Integer> lostPartitions()

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

#### resetOwners

    public Map<UUID,Set<Integer>> resetOwners(Map<Integer,Set<UUID>> ownersByUpdCounters,
                                              Set<Integer> haveHistory)

Calculates nodes and partitions which have non-actual state and must be rebalanced. State of all current owners that aren't contained in the given `ownersByUpdCounters` will be reset to MOVING.

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).
  `haveHistory` - Set of partitions which have WAL history to rebalance.
Returns:
  Map (nodeId, set of partitions that should be rebalanced fully by this node).

#### 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(AffinityTopologyVersion topVer)

Owns all moving partitions for the given topology version.

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

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

#### fullUpdateCounters

    public CachePartitionFullCountersMap fullUpdateCounters()

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

#### localUpdateCounters

    public CachePartitionPartialCountersMap localUpdateCounters(boolean skipZeros,
                                                                boolean finalizeCntrsBeforeCollecting)

Specified by:
  `localUpdateCounters` in interface `GridDhtPartitionTopology`
Parameters:
  `skipZeros` - `True` for adding zero counter to map.
  `finalizeCntrsBeforeCollecting` - `True` indicates that partition counters should be finalized.
Returns:
  Partition update counters.

#### partitionSizes

    public Map<Integer,Long> partitionSizes()

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

#### globalPartSizes

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

#### onCacheStopped

    public void onCacheStopped(int cacheId)

Parameters:
  `cacheId` - Cache ID.

#### printMemoryStats

    public void printMemoryStats(int threshold)

Prints memory stats.

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

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.7.5
Release Date | : June 4 2019