ignite-5999 : Fixed calculation of moving partitions count.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a2a90268 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a2a90268 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a2a90268 Branch: refs/heads/ignite-5896 Commit: a2a90268410340506aa9468f13c045dae78dc40a Parents: 872a959 Author: Ilya Lantukh <[email protected]> Authored: Fri Sep 1 14:25:34 2017 +0300 Committer: Andrey Gura <[email protected]> Committed: Mon Sep 4 17:46:23 2017 +0300 ---------------------------------------------------------------------- .../dht/preloader/GridDhtPartitionMap.java | 24 ++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/a2a90268/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java index 410caf6..5173a01 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionMap.java @@ -24,6 +24,7 @@ import java.io.ObjectOutput; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState; @@ -55,6 +56,10 @@ public class GridDhtPartitionMap implements Comparable<GridDhtPartitionMap>, Ext /** */ private volatile int moving; + /** */ + private static final AtomicIntegerFieldUpdater<GridDhtPartitionMap> MOVING_FIELD_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(GridDhtPartitionMap.class, "moving"); + /** * Empty constructor required for {@link Externalizable}. */ @@ -82,6 +87,16 @@ public class GridDhtPartitionMap implements Comparable<GridDhtPartitionMap>, Ext this.top = top; map = new GridPartitionStateMap(m, onlyActive); + + int moving0 = 0; + + for (GridDhtPartitionState state : map.values()) { + if (state == MOVING) + moving0++; + } + + if (moving0 > 0) + MOVING_FIELD_UPDATER.set(this, moving0); } /** @@ -121,11 +136,12 @@ public class GridDhtPartitionMap implements Comparable<GridDhtPartitionMap>, Ext public void put(Integer part, GridDhtPartitionState state) { GridDhtPartitionState old = map.put(part, state); - if (old == MOVING) - moving--; + if (old == MOVING && state != MOVING) + MOVING_FIELD_UPDATER.decrementAndGet(this); + else if (old != MOVING && state == MOVING) + MOVING_FIELD_UPDATER.incrementAndGet(this); - if (state == MOVING) - moving++; + assert moving >= 0 : moving; } /**
