ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject ignite git commit: IGNITE-1197 - Fixed unswap iterator
Date Mon, 14 Sep 2015 23:36:32 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1.4 866fb4152 -> cb9b76620


IGNITE-1197 - Fixed unswap iterator


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

Branch: refs/heads/ignite-1.4
Commit: cb9b76620167cc8b71b333615e6406dd98dc6d7a
Parents: 866fb41
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Mon Sep 14 16:34:28 2015 -0700
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Mon Sep 14 16:36:04 2015 -0700

----------------------------------------------------------------------
 .../distributed/dht/GridDhtLocalPartition.java  | 63 ++++++++++++++------
 1 file changed, 44 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/cb9b7662/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 215a1b5..a58451f 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
@@ -21,6 +21,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -707,38 +708,62 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
 
         return new Iterator<GridDhtCacheEntry>() {
             /** */
-            GridDhtCacheEntry lastEntry;
+            private GridDhtCacheEntry lastEntry;
 
-            @Override public boolean hasNext() {
-                return it.hasNext();
+            {
+                lastEntry = advance();
             }
 
-            @Override public GridDhtCacheEntry next() {
-                Map.Entry<byte[], GridCacheSwapEntry> entry = it.next();
+            private GridDhtCacheEntry advance() {
+                if (it.hasNext()) {
+                    Map.Entry<byte[], GridCacheSwapEntry> entry = it.next();
 
-                byte[] keyBytes = entry.getKey();
+                    byte[] keyBytes = entry.getKey();
 
-                while (true) {
-                    try {
-                        KeyCacheObject key = cctx.toCacheKeyObject(keyBytes);
+                    while (true) {
+                        try {
+                            KeyCacheObject key = cctx.toCacheKeyObject(keyBytes);
 
-                        lastEntry = (GridDhtCacheEntry)cctx.cache().entryEx(key, false);
+                            lastEntry = (GridDhtCacheEntry)cctx.cache().entryEx(key, false);
 
-                        lastEntry.unswap(true);
+                            lastEntry.unswap(true);
 
-                        return lastEntry;
-                    }
-                    catch (GridCacheEntryRemovedException e) {
-                        if (log.isDebugEnabled())
-                            log.debug("Got removed entry: " + lastEntry);
-                    }
-                    catch (IgniteCheckedException e) {
-                        throw new CacheException(e);
+                            return lastEntry;
+                        }
+                        catch (GridCacheEntryRemovedException e) {
+                            if (log.isDebugEnabled())
+                                log.debug("Got removed entry: " + lastEntry);
+                        }
+                        catch (IgniteCheckedException e) {
+                            throw new CacheException(e);
+                        }
+                        catch (GridDhtInvalidPartitionException e) {
+                            if (log.isDebugEnabled())
+                                log.debug("Got invalid partition exception: " + e);
+
+                            return null;
+                        }
                     }
                 }
+
+                return null;
+            }
+
+            @Override public boolean hasNext() {
+                return lastEntry != null;
+            }
+
+            @Override public GridDhtCacheEntry next() {
+                if (lastEntry == null)
+                    throw new NoSuchElementException();
+
+                return lastEntry;
             }
 
             @Override public void remove() {
+                if (lastEntry == null)
+                    throw new NoSuchElementException();
+
                 map.remove(lastEntry.key(), lastEntry);
             }
         };


Mime
View raw message