Interface GridDhtPartitionTopology

    • 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.
      • 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.
      • afterStateRestored

        void afterStateRestored​(AffinityTopologyVersion topVer)
        Initializes local data structures after partitions are restored from persistence.
        Parameters:
        topVer - Topology version.
      • releasePartitions

        void releasePartitions​(int... parts)
        Parameters:
        parts - Partitions to release (should be reserved before).
      • localPartitions

        List<GridDhtLocalPartition> localPartitions()
        Returns:
        All local partitions by copying them into another list.
      • 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.
      • 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.