ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [6/6] incubator-ignite git commit: ignite-484-1 - tryEvict fix + minor refactor
Date Sun, 14 Jun 2015 17:59:43 GMT
ignite-484-1 - tryEvict fix + minor refactor


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/7e3f924b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7e3f924b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7e3f924b

Branch: refs/heads/ignite-484-1
Commit: 7e3f924b2f6f2dcc0a942cdc569b7e27647de5cb
Parents: d7a18c4
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Sun Jun 14 20:59:24 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Sun Jun 14 20:59:24 2015 +0300

----------------------------------------------------------------------
 .../distributed/dht/GridDhtLocalPartition.java  | 12 ++++++----
 .../dht/GridDhtPartitionsReservation.java       | 25 +++++++++++++-------
 .../IgniteCacheQueryNodeRestartSelfTest2.java   |  2 +-
 3 files changed, 25 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3f924b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index 018ffd6..5938fc8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -137,7 +137,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
      * Adds group reservation to this partition.
      *
      * @param r Reservation.
-     * @return {@code true} If reservation added successfully.
+     * @return {@code false} If such reservation already added.
      */
     public boolean addReservation(GridDhtPartitionsReservation r) {
         assert state.getReference() != EVICTED : "we can reserve only active partitions";
@@ -509,7 +509,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
 
         for (GridDhtPartitionsReservation reservation : reservations) {
             if (!reservation.canEvict())
-                reserved = true;
+                reserved = true; // Calling all the reservations to allow them unregister
themselves.
         }
 
         return reserved;
@@ -520,11 +520,13 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
      * @return {@code True} if entry has been transitioned to state EVICTED.
      */
     boolean tryEvict(boolean updateSeq) {
+        if (state.getReference() != RENTING || state.getStamp() != 0 || groupReserved())
+            return false;
+
         // Attempt to evict partition entries from cache.
-        if (state.getReference() == RENTING && state.getStamp() == 0 && !groupReserved())
-            clearAll();
+        clearAll();
 
-        if (map.isEmpty() && !groupReserved() && state.compareAndSet(RENTING,
EVICTED, 0, 0)) {
+        if (map.isEmpty() && state.compareAndSet(RENTING, EVICTED, 0, 0)) {
             if (log.isDebugEnabled())
                 log.debug("Evicted partition: " + this);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3f924b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java
index 71a1859..a32946a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java
@@ -46,10 +46,10 @@ public class GridDhtPartitionsReservation implements GridReservable {
     private final AtomicReference<GridDhtLocalPartition[]> parts = new AtomicReference<>();
 
     /** */
-    private final AtomicInteger reservations = new AtomicInteger();
+    private final AtomicReference<CI1<GridDhtPartitionsReservation>> unpublish
= new AtomicReference<>();
 
     /** */
-    private volatile CI1<GridDhtPartitionsReservation> unpublish;
+    private final AtomicInteger reservations = new AtomicInteger();
 
     /**
      * @param topVer AffinityTopologyVersion version.
@@ -123,6 +123,8 @@ public class GridDhtPartitionsReservation implements GridReservable {
         if (!this.parts.compareAndSet(null, arr))
             throw new IllegalStateException("Partitions can be registered only once.");
 
+        assert reservations.get() != -1 : "all the partitions must be reserved before register,
we can't be invalidated";
+
         return true;
     }
 
@@ -133,9 +135,9 @@ public class GridDhtPartitionsReservation implements GridReservable {
      */
     public void onPublish(CI1<GridDhtPartitionsReservation> unpublish) {
         assert unpublish != null;
-        assert this.unpublish == null;
 
-        this.unpublish = unpublish;
+        if (!this.unpublish.compareAndSet(null, unpublish))
+            throw new IllegalStateException("Unpublishing closure can be set only once.");
 
         if (reservations.get() == -1)
             unregister();
@@ -202,12 +204,13 @@ public class GridDhtPartitionsReservation implements GridReservable
{
     }
 
     /**
-     * Unregisters this reservation from all the partitions.
+     * Unregisters from all the partitions and unpublishes this reservation.
      */
     private void unregister() {
         GridDhtLocalPartition[] arr = parts.get();
 
-        if (!F.isEmpty(arr) && unpublish != null && parts.compareAndSet(arr,
EMPTY)) {
+        // Unregister from partitions.
+        if (!F.isEmpty(arr) && parts.compareAndSet(arr, EMPTY)) {
             // Reverse order makes sure that addReservation on the same topVer reservation
will fail on the first partition.
             for (int i = arr.length - 1; i >= 0; i--) {
                 GridDhtLocalPartition part = arr[i];
@@ -216,9 +219,13 @@ public class GridDhtPartitionsReservation implements GridReservable {
 
                 tryEvict(part);
             }
-
-            unpublish.apply(this);
         }
+
+        // Unpublish.
+        CI1<GridDhtPartitionsReservation> u = unpublish.get();
+
+        if (u != null && unpublish.compareAndSet(u, null))
+            u.apply(this);
     }
 
     /**
@@ -231,6 +238,8 @@ public class GridDhtPartitionsReservation implements GridReservable {
      * @return {@code true} If this reservation is NOT reserved and partition CAN be evicted.
      */
     public boolean canEvict() {
+        assert parts.get() != null : "all parts must be reserved before registration";
+
         int r = reservations.get();
 
         assert r >= -1 : r;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3f924b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java
index 746cc45..e65cc13 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java
@@ -180,7 +180,7 @@ public class IgniteCacheQueryNodeRestartSelfTest2 extends GridCommonAbstractTest
         int qryThreadNum = 4;
         int restartThreadsNum = 2; // 4 + 2 = 6 nodes
         final int nodeLifeTime = 2 * 1000;
-        final int logFreq = 50;
+        final int logFreq = 10;
 
         startGridsMultiThreaded(GRID_CNT);
 


Mime
View raw message