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

## Interface GridDhtPartitionTopology

All Known Implementing Classes:
  GridClientPartitionTopology, GridDhtPartitionTopologyImpl

    @GridToStringExclude
    public interface GridDhtPartitionTopology

Distributed Hash Table (DHT) partition topology.

### Method Summary

All Methods Instance Methods Abstract 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, 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()`
`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()`
`@Nullable GridDhtLocalPartition` `localPartition(int part)`
`@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 `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 resTopVer)` 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.
`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 exchangeResVer, 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 updateSeq, boolean stopping)` Updates topology version.

### Method Detail

#### partitions

    int partitions()

Returns:
  Total cache partitions.

#### readLock

    void readLock()

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

#### readUnlock

    void readUnlock()

Unlocks topology locked by `readLock()` method.

#### holdsLock

    boolean holdsLock()

Returns:
  `True` if locked by current thread.

#### updateTopologyVersion

    void updateTopologyVersion(GridDhtTopologyFuture exchFut,
                               DiscoCache discoCache,
                               long updateSeq,
                               boolean stopping)
                        throws IgniteInterruptedCheckedException

Updates topology version.

Parameters:
  `exchFut` - Exchange future.
  `discoCache` - Discovery data cache.
  `updateSeq` - Update sequence.
  `stopping` - Stopping flag.
Throws:
  `IgniteInterruptedCheckedException` - If interrupted.

#### initialized

    boolean initialized()

Returns:
  `True` If ready version initialized. `False` If not initialized.

#### readyTopologyVersion

    AffinityTopologyVersion readyTopologyVersion()

Returns:
  Result topology version of last finished exchange.

#### lastTopologyChangeVersion

    AffinityTopologyVersion lastTopologyChangeVersion()

Returns:
  Start topology version of last exchange.

#### topologyVersionFuture

    GridDhtTopologyFuture topologyVersionFuture()

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

Returns:
  Topology version ready future.

#### stopping

    boolean stopping()

Returns:
  `True` if cache is being stopped.

#### groupId

    int groupId()

Returns:
  Cache group ID.

#### beforeExchange

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

Pre-initializes this topology.

Parameters:
  `exchFut` - Exchange future.
  `affReady` - Affinity ready flag.
  `updateMoving` - `True` to initialize partition maps with moving partitions.
Throws:
  `IgniteCheckedException` - If failed.

#### initPartitionsWhenAffinityReady

    boolean initPartitionsWhenAffinityReady(AffinityTopologyVersion affVer,
                                            GridDhtPartitionsExchangeFuture exchFut)
                                     throws IgniteInterruptedCheckedException

Parameters:
  `affVer` - Affinity version.
  `exchFut` - Exchange future.
Returns:
  `True` if partitions must be refreshed.
Throws:
  `IgniteInterruptedCheckedException` - If interrupted.

#### afterStateRestored

    void afterStateRestored(AffinityTopologyVersion topVer)

Initializes local data structures after partitions are restored from persistence.

Parameters:
  `topVer` - Topology version.

#### afterExchange

    boolean afterExchange(GridDhtPartitionsExchangeFuture exchFut)
                   throws IgniteCheckedException

Post-initializes this topology.

Parameters:
  `exchFut` - Exchange future.
Returns:
  `True` if mapping was changed.
Throws:
  `IgniteCheckedException` - If failed.

#### localPartition

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

Parameters:
  `topVer` - Topology version at the time of creation.
  `p` - Partition ID.
  `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

    GridDhtLocalPartition forceCreatePartition(int p)
                                        throws IgniteCheckedException

Unconditionally creates partition during restore of persisted partition state.

Parameters:
  `p` - Partition ID.
Returns:
  Partition.
Throws:
  `IgniteCheckedException` - If failed.

#### localPartition

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

Parameters:
  `topVer` - Topology version at the time of creation.
  `p` - Partition ID.
  `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.

#### releasePartitions

    void releasePartitions(int... parts)

Parameters:
  `parts` - Partitions to release (should be reserved before).

#### localPartition

    @Nullable
    @Nullable GridDhtLocalPartition localPartition(int part)
                                                      throws GridDhtInvalidPartitionException

Parameters:
  `part` - Partition number.
Returns:
  Local partition.
Throws:
  `GridDhtInvalidPartitionException` - If partition is evicted or absent and does not belong to this node.

#### localPartitions

    List<GridDhtLocalPartition> localPartitions()

Returns:
  All local partitions by copying them into another list.

#### currentLocalPartitions

    Iterable<GridDhtLocalPartition> currentLocalPartitions()

Returns:
  All current active local partitions.

#### localPartitionMap

    GridDhtPartitionMap localPartitionMap()

Returns:
  Local IDs.

#### partitionState

    GridDhtPartitionState partitionState(UUID nodeId,
                                         int part)

Parameters:
  `nodeId` - Node ID.
  `part` - Partition.
Returns:
  Partition state.

#### updateSequence

    long updateSequence()

Returns:
  Current update sequence.

#### nodes

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

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

#### nodes

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

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.

#### owners

    List<ClusterNode> owners(int p)

Parameters:
  `p` - Partition ID.
Returns:
  Collection of all nodes who `own` this partition.

#### allOwners

    List<List<ClusterNode>> allOwners()

Returns:
  List indexed by partition number, each list element is collection of all nodes who owns corresponding partition.

#### owners

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

Parameters:
  `p` - Partition ID.
  `topVer` - Topology version.
Returns:
  Collection of all nodes who `own` this partition.

#### moving

    List<ClusterNode> moving(int p)

Parameters:
  `p` - Partition ID.
Returns:
  Collection of all nodes who `are preloading` this partition.

#### partitionMap

    GridDhtPartitionFullMap partitionMap(boolean onlyActive)

Parameters:
  `onlyActive` - If `true`, then only `active` partitions will be returned.
Returns:
  Node IDs mapped to partitions.

#### hasMovingPartitions

    boolean hasMovingPartitions()

Returns:
  `True` If one of cache nodes has partitions in `GridDhtPartitionState.MOVING` state.

#### onRemoved

    void onRemoved(GridDhtCacheEntry e)

Parameters:
  `e` - Entry removed from cache.

#### update

    boolean update(@Nullable
                   @Nullable AffinityTopologyVersion exchangeResVer,
                   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)

Parameters:
  `exchangeResVer` - 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.

#### update

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

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

#### collectUpdateCounters

    void collectUpdateCounters(CachePartitionPartialCountersMap cntrMap)

Collects update counters collected during exchange. Called on coordinator.

Parameters:
  `cntrMap` - Counters map.

#### applyUpdateCounters

    void applyUpdateCounters()

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

#### detectLostPartitions

    boolean detectLostPartitions(AffinityTopologyVersion resTopVer,
                                 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.

Parameters:
  `resTopVer` - Exchange result version.
  `fut` - Exchange futute for topology events to detect.
Returns:
  `True` if partitions state got updated.

#### resetLostPartitions

    void resetLostPartitions(AffinityTopologyVersion resTopVer)

Resets the state of all LOST partitions to OWNING.

Parameters:
  `resTopVer` - Exchange result version.

#### lostPartitions

    Set<Integer> lostPartitions()

Returns:
  Collection of lost partitions, if any.

#### finalizeUpdateCounters

    void finalizeUpdateCounters(Set<Integer> parts)

Pre-processes partition update counters before exchange.

Parameters:
  `parts` - Partitions.

#### fullUpdateCounters

    CachePartitionFullCountersMap fullUpdateCounters()

Returns:
  Partition update counters.

#### localUpdateCounters

    CachePartitionPartialCountersMap localUpdateCounters(boolean skipZeros)

Parameters:
  `skipZeros` - `True` to exclude zero counters from map.
Returns:
  Partition update counters.

#### partitionSizes

    Map<Integer,Long> partitionSizes()

Returns:
  Partition cache sizes.

#### own

    boolean own(GridDhtLocalPartition part)

Parameters:
  `part` - Partition to own.
Returns:
  `True` if owned.

#### ownMoving

    void ownMoving()

Owns all moving partitions.

#### tryFinishEviction

    boolean tryFinishEviction(GridDhtLocalPartition part)

Parameters:
  `part` - Evicted partition.
Returns:
  `True` if a partition was destroyed by this call.

#### partitions

    @Nullable
    @Nullable GridDhtPartitionMap partitions(UUID nodeId)

Parameters:
  `nodeId` - Node to get partitions for.
Returns:
  Partitions for node.

#### printMemoryStats

    void printMemoryStats(int threshold)

Prints memory stats.

Parameters:
  `threshold` - Threshold for number of entries.

#### globalPartSizes

    Map<Integer,Long> globalPartSizes()

Returns:
  Sizes of up-to-date partition versions in topology.

#### globalPartSizes

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

Parameters:
  `partSizes` - Sizes of up-to-date partition versions in topology.

#### rebalanceFinished

    boolean rebalanceFinished(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  `True` if rebalance process finished.

#### resetOwners

    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.

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

#### onExchangeDone

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

Callback on exchange done.

Parameters:
  `assignment` - New affinity assignment.
  `updateRebalanceVer` - `True` if need check rebalance state.

#### rent

    boolean rent(int p)

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

Parameters:
  `p` - Partition ID.
Returns:
  `True` if the partition was switched to RENTING.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.13.0
Release Date | : April 20 2022