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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGridDhtPartitionTopologyImpl.PartitionFactoryPartition factory used for (re-)creating partitions during their lifecycle.
-
Constructor Summary
Constructors Constructor Description GridDhtPartitionTopologyImpl(GridCacheSharedContext ctx, CacheGroupContext grp)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanafterExchange(GridDhtPartitionsExchangeFuture exchFut)Post-initializes this topology.voidafterStateRestored(AffinityTopologyVersion topVer)Initializes local data structures after partitions are restored from persistence.List<List<ClusterNode>>allOwners()voidapplyUpdateCounters()Applies update counters collected during exchange on coordinator.voidbeforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean affReady, boolean updateMoving)Pre-initializes this topology.voidcollectUpdateCounters(CachePartitionPartialCountersMap cntrMap)Collects update counters collected during exchange.Iterable<GridDhtLocalPartition>currentLocalPartitions()booleandetectLostPartitions(AffinityTopologyVersion resTopVer, GridDhtPartitionsExchangeFuture fut)Checks if there is at least one owner for each partition in the cache topology for a local node.voidfinalizeUpdateCounters(Set<Integer> parts)Pre-processes partition update counters before exchange.GridDhtLocalPartitionforceCreatePartition(int p)Unconditionally creates partition during restore of persisted partition state.CachePartitionFullCountersMapfullUpdateCounters()GridDhtLocalPartitiongetOrCreatePartition(int p)Creates partition with idpif it doesn't exist or evicted.Map<Integer,Long>globalPartSizes()voidglobalPartSizes(@Nullable Map<Integer,Long> partSizes)intgroupId()booleanhasMovingPartitions()booleanholdsLock()booleaninitialized()booleaninitPartitionsWhenAffinityReady(AffinityTopologyVersion affVer, GridDhtPartitionsExchangeFuture exchFut)AffinityTopologyVersionlastTopologyChangeVersion()GridDhtLocalPartitionlocalPartition(int part)@Nullable GridDhtLocalPartitionlocalPartition(int p, AffinityTopologyVersion topVer, boolean create)@Nullable GridDhtLocalPartitionlocalPartition(int p, AffinityTopologyVersion topVer, boolean create, boolean showRenting)GridDhtPartitionMaplocalPartitionMap()List<GridDhtLocalPartition>localPartitions()CachePartitionPartialCountersMaplocalUpdateCounters(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)voidonCacheStopped(int cacheId)voidonExchangeDone(@Nullable GridDhtPartitionsExchangeFuture fut, AffinityAssignment assignment, boolean updateRebalanceVer)Callback on exchange done.voidonReconnected()voidonRemoved(GridDhtCacheEntry e)booleanown(GridDhtLocalPartition part)List<ClusterNode>owners(int p)List<ClusterNode>owners(int p, AffinityTopologyVersion topVer)voidownMoving()Owns all moving partitions.voidpartitionFactory(GridDhtPartitionTopologyImpl.PartitionFactory factory)Set partition factory to use.GridDhtPartitionFullMappartitionMap(boolean onlyActive)intpartitions()@Nullable GridDhtPartitionMappartitions(UUID nodeId)Map<Integer,Long>partitionSizes()GridDhtPartitionStatepartitionState(UUID nodeId, int part)voidprintMemoryStats(int threshold)Prints memory stats.voidreadLock()Locks the topology, usually during mapping on locks or transactions.voidreadUnlock()Unlocks topology locked byGridDhtPartitionTopology.readLock()method.AffinityTopologyVersionreadyTopologyVersion()booleanrebalanceFinished(AffinityTopologyVersion topVer)voidreleasePartitions(int... parts)booleanrent(int p)Rents a partition and updates a partition map if the partition was switched to RENTING.voidresetLostPartitions(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.booleanstopping()GridDhtTopologyFuturetopologyVersionFuture()Gets a future that will be completed when partition exchange map for this particular topology version is done.booleantryFinishEviction(GridDhtLocalPartition part)booleanupdate(@Nullable AffinityTopologyVersion exchangeVer, GridDhtPartitionFullMap partMap, @Nullable CachePartitionFullCountersMap incomeCntrMap, Set<Integer> partsToReload, @Nullable Map<Integer,Long> partSizes, @Nullable AffinityTopologyVersion msgTopVer, @Nullable GridDhtPartitionsExchangeFuture exchFut, @Nullable Set<Integer> lostParts)booleanupdate(@Nullable GridDhtPartitionExchangeId exchId, GridDhtPartitionMap parts, boolean force)longupdateSequence()voidupdateTopologyVersion(GridDhtTopologyFuture exchFut, @NotNull DiscoCache discoCache, long updSeq, boolean stopping)Updates topology version.
-
-
-
Constructor Detail
-
GridDhtPartitionTopologyImpl
public GridDhtPartitionTopologyImpl(GridCacheSharedContext ctx, CacheGroupContext grp)
- Parameters:
ctx- Cache shared context.grp- Cache group.
-
-
Method Detail
-
partitionFactory
public void partitionFactory(GridDhtPartitionTopologyImpl.PartitionFactory factory)
Set partition factory to use. Currently is used for tests.- Parameters:
factory- Factory.
-
partitions
public int partitions()
- Specified by:
partitionsin interfaceGridDhtPartitionTopology- Returns:
- Total cache partitions.
-
groupId
public int groupId()
- Specified by:
groupIdin interfaceGridDhtPartitionTopology- Returns:
- Cache group ID.
-
onReconnected
public void onReconnected()
-
readLock
public void readLock()
Locks the topology, usually during mapping on locks or transactions.- Specified by:
readLockin interfaceGridDhtPartitionTopology
-
readUnlock
public void readUnlock()
Unlocks topology locked byGridDhtPartitionTopology.readLock()method.- Specified by:
readUnlockin interfaceGridDhtPartitionTopology
-
holdsLock
public boolean holdsLock()
- Specified by:
holdsLockin interfaceGridDhtPartitionTopology- Returns:
Trueif locked by current thread.
-
updateTopologyVersion
public void updateTopologyVersion(GridDhtTopologyFuture exchFut, @NotNull @NotNull DiscoCache discoCache, long updSeq, boolean stopping) throws IgniteInterruptedCheckedException
Updates topology version.- Specified by:
updateTopologyVersionin interfaceGridDhtPartitionTopology- Parameters:
exchFut- Exchange future.discoCache- Discovery data cache.updSeq- Update sequence.stopping- Stopping flag.- Throws:
IgniteInterruptedCheckedException- If interrupted.
-
initialized
public boolean initialized()
- Specified by:
initializedin interfaceGridDhtPartitionTopology- Returns:
TrueIf ready version initialized.FalseIf not initialized.
-
readyTopologyVersion
public AffinityTopologyVersion readyTopologyVersion()
- Specified by:
readyTopologyVersionin interfaceGridDhtPartitionTopology- Returns:
- Result topology version of last finished exchange.
-
lastTopologyChangeVersion
public AffinityTopologyVersion lastTopologyChangeVersion()
- Specified by:
lastTopologyChangeVersionin interfaceGridDhtPartitionTopology- 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:
topologyVersionFuturein interfaceGridDhtPartitionTopology- Returns:
- Topology version ready future.
-
stopping
public boolean stopping()
- Specified by:
stoppingin interfaceGridDhtPartitionTopology- Returns:
Trueif cache is being stopped.
-
initPartitionsWhenAffinityReady
public boolean initPartitionsWhenAffinityReady(AffinityTopologyVersion affVer, GridDhtPartitionsExchangeFuture exchFut) throws IgniteInterruptedCheckedException
- Specified by:
initPartitionsWhenAffinityReadyin interfaceGridDhtPartitionTopology- Parameters:
affVer- Affinity version.exchFut- Exchange future.- Returns:
Trueif 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:
beforeExchangein interfaceGridDhtPartitionTopology- Parameters:
exchFut- Exchange future.affReady- Affinity ready flag.updateMoving-Trueto 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:
afterStateRestoredin interfaceGridDhtPartitionTopology- Parameters:
topVer- Topology version.
-
afterExchange
public boolean afterExchange(GridDhtPartitionsExchangeFuture exchFut)
Post-initializes this topology.- Specified by:
afterExchangein interfaceGridDhtPartitionTopology- Parameters:
exchFut- Exchange future.- Returns:
Trueif mapping was changed.
-
localPartition
@Nullable public @Nullable GridDhtLocalPartition localPartition(int p, AffinityTopologyVersion topVer, boolean create) throws GridDhtInvalidPartitionException
- Specified by:
localPartitionin interfaceGridDhtPartitionTopology- Parameters:
p- Partition ID.topVer- Topology version at the time of creation.create- Iftrue, 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:
localPartitionin interfaceGridDhtPartitionTopology- Parameters:
p- Partition ID.topVer- Topology version at the time of creation.create- Iftrue, 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.
-
getOrCreatePartition
public GridDhtLocalPartition getOrCreatePartition(int p)
Creates partition with idpif it doesn't exist or evicted. In other case returns existing partition.- Parameters:
p- Partition number.- Returns:
- Partition.
-
forceCreatePartition
public GridDhtLocalPartition forceCreatePartition(int p) throws IgniteCheckedException
Unconditionally creates partition during restore of persisted partition state.- Specified by:
forceCreatePartitionin interfaceGridDhtPartitionTopology- Parameters:
p- Partition ID.- Returns:
- Partition.
- Throws:
IgniteCheckedException- If failed.
-
releasePartitions
public void releasePartitions(int... parts)
- Specified by:
releasePartitionsin interfaceGridDhtPartitionTopology- Parameters:
parts- Partitions to release (should be reserved before).
-
localPartition
public GridDhtLocalPartition localPartition(int part)
- Specified by:
localPartitionin interfaceGridDhtPartitionTopology- Parameters:
part- Partition number.- Returns:
- Local partition.
-
localPartitions
public List<GridDhtLocalPartition> localPartitions()
- Specified by:
localPartitionsin interfaceGridDhtPartitionTopology- Returns:
- All local partitions by copying them into another list.
-
currentLocalPartitions
public Iterable<GridDhtLocalPartition> currentLocalPartitions()
- Specified by:
currentLocalPartitionsin interfaceGridDhtPartitionTopology- Returns:
- All current active local partitions.
-
onRemoved
public void onRemoved(GridDhtCacheEntry e)
- Specified by:
onRemovedin interfaceGridDhtPartitionTopology- Parameters:
e- Entry removed from cache.
-
localPartitionMap
public GridDhtPartitionMap localPartitionMap()
- Specified by:
localPartitionMapin interfaceGridDhtPartitionTopology- Returns:
- Local IDs.
-
partitionState
public GridDhtPartitionState partitionState(UUID nodeId, int part)
- Specified by:
partitionStatein interfaceGridDhtPartitionTopology- 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:
nodesin interfaceGridDhtPartitionTopology- 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:
nodesin interfaceGridDhtPartitionTopology- 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:
ownersin interfaceGridDhtPartitionTopology- Parameters:
p- Partition ID.topVer- Topology version.- Returns:
- Collection of all nodes who
ownthis partition.
-
owners
public List<ClusterNode> owners(int p)
- Specified by:
ownersin interfaceGridDhtPartitionTopology- Parameters:
p- Partition ID.- Returns:
- Collection of all nodes who
ownthis partition.
-
allOwners
public List<List<ClusterNode>> allOwners()
- Specified by:
allOwnersin interfaceGridDhtPartitionTopology- 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:
movingin interfaceGridDhtPartitionTopology- Parameters:
p- Partition ID.- Returns:
- Collection of all nodes who
are preloadingthis partition.
-
updateSequence
public long updateSequence()
- Specified by:
updateSequencein interfaceGridDhtPartitionTopology- Returns:
- Current update sequence.
-
partitionMap
public GridDhtPartitionFullMap partitionMap(boolean onlyActive)
- Specified by:
partitionMapin interfaceGridDhtPartitionTopology- Parameters:
onlyActive- Iftrue, then onlyactivepartitions will be returned.- Returns:
- Node IDs mapped to partitions.
-
update
public boolean update(@Nullable @Nullable AffinityTopologyVersion exchangeVer, GridDhtPartitionFullMap partMap, @Nullable @Nullable CachePartitionFullCountersMap incomeCntrMap, Set<Integer> partsToReload, @Nullable @Nullable Map<Integer,Long> partSizes, @Nullable @Nullable AffinityTopologyVersion msgTopVer, @Nullable @Nullable GridDhtPartitionsExchangeFuture exchFut, @Nullable @Nullable Set<Integer> lostParts)- Specified by:
updatein interfaceGridDhtPartitionTopology- Parameters:
exchangeVer- Result topology version for exchange. Value should be greater than previously passed. Null value means full map received is not related to exchangepartMap- Update partition map.incomeCntrMap- 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:
Trueif local state was changed.
-
collectUpdateCounters
public void collectUpdateCounters(CachePartitionPartialCountersMap cntrMap)
Collects update counters collected during exchange. Called on coordinator.- Specified by:
collectUpdateCountersin interfaceGridDhtPartitionTopology- Parameters:
cntrMap- Counters map.
-
applyUpdateCounters
public void applyUpdateCounters()
Applies update counters collected during exchange on coordinator. Called on coordinator.- Specified by:
applyUpdateCountersin interfaceGridDhtPartitionTopology
-
update
public boolean update(@Nullable @Nullable GridDhtPartitionExchangeId exchId, GridDhtPartitionMap parts, boolean force)- Specified by:
updatein interfaceGridDhtPartitionTopology- Parameters:
exchId- Exchange ID.parts- Partitions.force-Trueto skip stale update check.- Returns:
Trueif local state was changed.
-
onExchangeDone
public void onExchangeDone(@Nullable @Nullable GridDhtPartitionsExchangeFuture fut, AffinityAssignment assignment, boolean updateRebalanceVer)Callback on exchange done.- Specified by:
onExchangeDonein interfaceGridDhtPartitionTopologyassignment- New affinity assignment.updateRebalanceVer-Trueif need check rebalance state.
-
detectLostPartitions
public 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.- Specified by:
detectLostPartitionsin interfaceGridDhtPartitionTopology- Parameters:
resTopVer- Exchange result version.fut- Exchange futute for topology events to detect.- Returns:
Trueif partitions state got updated.
-
resetLostPartitions
public void resetLostPartitions(AffinityTopologyVersion resTopVer)
Resets the state of all LOST partitions to OWNING.- Specified by:
resetLostPartitionsin interfaceGridDhtPartitionTopology- Parameters:
resTopVer- Exchange result version.
-
lostPartitions
public Set<Integer> lostPartitions()
- Specified by:
lostPartitionsin interfaceGridDhtPartitionTopology- Returns:
- Collection of lost partitions, if any.
-
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 givenownersByUpdCounterswill be reset to MOVING. Called on coordinator during assignment of partition states.- Specified by:
resetOwnersin interfaceGridDhtPartitionTopology- 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).
-
own
public boolean own(GridDhtLocalPartition part)
- Specified by:
ownin interfaceGridDhtPartitionTopology- Parameters:
part- Partition to own.- Returns:
Trueif owned.
-
ownMoving
public void ownMoving()
Owns all moving partitions.- Specified by:
ownMovingin interfaceGridDhtPartitionTopology
-
tryFinishEviction
public boolean tryFinishEviction(GridDhtLocalPartition part)
- Specified by:
tryFinishEvictionin interfaceGridDhtPartitionTopology- Parameters:
part- Evicted partition.- Returns:
Trueif a partition was destroyed by this call.
-
partitions
@Nullable public @Nullable GridDhtPartitionMap partitions(UUID nodeId)
- Specified by:
partitionsin interfaceGridDhtPartitionTopology- Parameters:
nodeId- Node to get partitions for.- Returns:
- Partitions for node.
-
finalizeUpdateCounters
public void finalizeUpdateCounters(Set<Integer> parts)
Pre-processes partition update counters before exchange.- Specified by:
finalizeUpdateCountersin interfaceGridDhtPartitionTopology- Parameters:
parts- Partitions.
-
fullUpdateCounters
public CachePartitionFullCountersMap fullUpdateCounters()
- Specified by:
fullUpdateCountersin interfaceGridDhtPartitionTopology- Returns:
- Partition update counters.
-
localUpdateCounters
public CachePartitionPartialCountersMap localUpdateCounters(boolean skipZeros)
- Specified by:
localUpdateCountersin interfaceGridDhtPartitionTopology- Parameters:
skipZeros-Trueto exclude zero counters from map.- Returns:
- Partition update counters.
-
partitionSizes
public Map<Integer,Long> partitionSizes()
- Specified by:
partitionSizesin interfaceGridDhtPartitionTopology- Returns:
- Partition cache sizes.
-
globalPartSizes
public Map<Integer,Long> globalPartSizes()
- Specified by:
globalPartSizesin interfaceGridDhtPartitionTopology- Returns:
- Sizes of up-to-date partition versions in topology.
-
globalPartSizes
public void globalPartSizes(@Nullable @Nullable Map<Integer,Long> partSizes)- Specified by:
globalPartSizesin interfaceGridDhtPartitionTopology- Parameters:
partSizes- Sizes of up-to-date partition versions in topology.
-
rebalanceFinished
public boolean rebalanceFinished(AffinityTopologyVersion topVer)
- Specified by:
rebalanceFinishedin interfaceGridDhtPartitionTopology- Parameters:
topVer- Topology version.- Returns:
Trueif rebalance process finished.
-
hasMovingPartitions
public boolean hasMovingPartitions()
- Specified by:
hasMovingPartitionsin interfaceGridDhtPartitionTopology- Returns:
TrueIf one of cache nodes has partitions inGridDhtPartitionState.MOVINGstate.
-
onCacheStopped
public void onCacheStopped(int cacheId)
- Parameters:
cacheId- Cache ID.
-
printMemoryStats
public void printMemoryStats(int threshold)
Prints memory stats.- Specified by:
printMemoryStatsin interfaceGridDhtPartitionTopology- 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:
rentin interfaceGridDhtPartitionTopology- Parameters:
p- Partition ID.- Returns:
Trueif the partition was switched to RENTING.
-
-