Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8CBA017495 for ; Tue, 15 Sep 2015 08:11:56 +0000 (UTC) Received: (qmail 49022 invoked by uid 500); 15 Sep 2015 08:11:22 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 48968 invoked by uid 500); 15 Sep 2015 08:11:22 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 48020 invoked by uid 99); 15 Sep 2015 08:11:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Sep 2015 08:11:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A3175DFF0D; Tue, 15 Sep 2015 08:11:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Tue, 15 Sep 2015 08:11:48 -0000 Message-Id: In-Reply-To: <8e8e854a9f044ead89f0faa38c32413e@git.apache.org> References: <8e8e854a9f044ead89f0faa38c32413e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [28/50] [abbrv] ignite git commit: IGNITE-1197 - Fixed unswap iterator 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-1282 Commit: cb9b76620167cc8b71b333615e6406dd98dc6d7a Parents: 866fb41 Author: Yakov Zhdanov Authored: Mon Sep 14 16:34:28 2015 -0700 Committer: Alexey Goncharuk 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, return new Iterator() { /** */ - GridDhtCacheEntry lastEntry; + private GridDhtCacheEntry lastEntry; - @Override public boolean hasNext() { - return it.hasNext(); + { + lastEntry = advance(); } - @Override public GridDhtCacheEntry next() { - Map.Entry entry = it.next(); + private GridDhtCacheEntry advance() { + if (it.hasNext()) { + Map.Entry 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); } };