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 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()Map<Integer,Long>globalPartSizes()voidglobalPartSizes(@Nullable Map<Integer,Long> partSizes)intgroupId()booleanhasMovingPartitions()booleanholdsLock()booleaninitialized()booleaninitPartitionsWhenAffinityReady(AffinityTopologyVersion affVer, GridDhtPartitionsExchangeFuture exchFut)AffinityTopologyVersionlastTopologyChangeVersion()@Nullable 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)voidonExchangeDone(GridDhtPartitionsExchangeFuture fut, AffinityAssignment assignment, boolean updateRebalanceVer)Callback on exchange done.voidonRemoved(GridDhtCacheEntry e)booleanown(GridDhtLocalPartition part)List<ClusterNode>owners(int p)List<ClusterNode>owners(int p, AffinityTopologyVersion topVer)voidownMoving()Owns all moving partitions.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 byreadLock()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 exchangeResVer, GridDhtPartitionFullMap partMap, @Nullable CachePartitionFullCountersMap cntrMap, 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, 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 byreadLock()method.
-
holdsLock
boolean holdsLock()
- Returns:
Trueif 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:
TrueIf ready version initialized.FalseIf 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:
Trueif 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-Trueto 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:
Trueif 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:
Trueif 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- 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.
-
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- 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.
-
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
ownthis 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
ownthis partition.
-
moving
List<ClusterNode> moving(int p)
- Parameters:
p- Partition ID.- Returns:
- Collection of all nodes who
are preloadingthis partition.
-
partitionMap
GridDhtPartitionFullMap partitionMap(boolean onlyActive)
- Parameters:
onlyActive- Iftrue, then onlyactivepartitions will be returned.- Returns:
- Node IDs mapped to partitions.
-
hasMovingPartitions
boolean hasMovingPartitions()
- Returns:
TrueIf one of cache nodes has partitions inGridDhtPartitionState.MOVINGstate.
-
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 exchangepartMap- 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:
Trueif local state was changed.
-
update
boolean update(@Nullable @Nullable GridDhtPartitionExchangeId exchId, GridDhtPartitionMap parts, boolean force)- Parameters:
exchId- Exchange ID.parts- Partitions.force-Trueto skip stale update check.- Returns:
Trueif 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:
Trueif partitions state got updated.
-
resetLostPartitions
void resetLostPartitions(AffinityTopologyVersion resTopVer)
Resets the state of all LOST partitions to OWNING.- Parameters:
resTopVer- Exchange result version.
-
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-Trueto exclude zero counters from map.- Returns:
- Partition update counters.
-
own
boolean own(GridDhtLocalPartition part)
- Parameters:
part- Partition to own.- Returns:
Trueif owned.
-
ownMoving
void ownMoving()
Owns all moving partitions.
-
tryFinishEviction
boolean tryFinishEviction(GridDhtLocalPartition part)
- Parameters:
part- Evicted partition.- Returns:
Trueif 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:
Trueif 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 givenownersByUpdCounterswill 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-Trueif 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:
Trueif the partition was switched to RENTING.
-
-