Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-297 344be3474 -> aca9f9827


IGNITE-223 Performance problem in GridCacheSwapManager.readAndRemove()


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

Branch: refs/heads/ignite-297
Commit: 76b3c470539bf37962e5caa5eadacd456c52d911
Parents: 7a2a620
Author: sevdokimov <sevdoki...@gridgain.com>
Authored: Wed Feb 11 14:51:25 2015 +0300
Committer: sevdokimov <sevdoki...@gridgain.com>
Committed: Wed Feb 11 14:51:25 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheSwapManager.java  | 61 ++++++++++----------
 1 file changed, 32 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/76b3c470/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index 01f3a80..354070c 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -737,16 +737,14 @@ public class GridCacheSwapManager<K, V> extends 
GridCacheManagerAdapter<K, V> {
 
         final GridCacheQueryManager<K, V> qryMgr = cctx.queries();
 
-        Collection<K> keysList = new ArrayList<>(keys);
+        Collection<? extends K> unprocessedKeys;
         final Collection<GridCacheBatchSwapEntry<K, V>> res = new 
ArrayList<>(keys.size());
 
         // First try removing from offheap.
         if (offheapEnabled) {
-            Iterator<K> iter = keysList.iterator();
-
-            while (iter.hasNext()) {
-                K key = iter.next();
+            Collection<K> unprocessedKeysList = new ArrayList<>(keys.size());
 
+            for (K key : keys) {
                 int part = cctx.affinity().partition(key);
 
                 byte[] keyBytes = CU.marshal(cctx.shared(), key);
@@ -756,45 +754,50 @@ public class GridCacheSwapManager<K, V> extends 
GridCacheManagerAdapter<K, V> {
                 if (entryBytes != null) {
                     GridCacheSwapEntry<V> entry = 
swapEntry(unmarshalSwapEntry(entryBytes));
 
-                    if (entry == null)
-                        continue;
-
-                    iter.remove();
+                    if (entry != null) {
+                        // Always fire this event, since preloading depends on 
it.
+                        onOffHeaped(part, key, keyBytes, entry);
 
-                    // Always fire this event, since preloading depends on it.
-                    onOffHeaped(part, key, keyBytes, entry);
+                        if 
(cctx.events().isRecordable(EVT_CACHE_OBJECT_FROM_OFFHEAP))
+                            cctx.events().addEvent(part, key, cctx.nodeId(), 
(IgniteUuid)null, null,
+                                EVT_CACHE_OBJECT_FROM_OFFHEAP, null, false, 
null, true, null, null, null);
 
-                    if 
(cctx.events().isRecordable(EVT_CACHE_OBJECT_FROM_OFFHEAP))
-                        cctx.events().addEvent(part, key, cctx.nodeId(), 
(IgniteUuid)null, null,
-                            EVT_CACHE_OBJECT_FROM_OFFHEAP, null, false, null, 
true, null, null, null);
+                        if (qryMgr != null)
+                            qryMgr.onUnswap(key, entry.value(), 
entry.valueBytes());
 
-                    if (qryMgr != null)
-                        qryMgr.onUnswap(key, entry.value(), 
entry.valueBytes());
+                        GridCacheBatchSwapEntry<K, V> unswapped = new 
GridCacheBatchSwapEntry<>(key,
+                            keyBytes,
+                            part,
+                            ByteBuffer.wrap(entry.valueBytes()),
+                            entry.valueIsByteArray(),
+                            entry.version(), entry.ttl(),
+                            entry.expireTime(),
+                            entry.keyClassLoaderId(),
+                            entry.valueClassLoaderId());
 
-                    GridCacheBatchSwapEntry<K, V> unswapped = new 
GridCacheBatchSwapEntry<>(key,
-                        keyBytes,
-                        part,
-                        ByteBuffer.wrap(entry.valueBytes()),
-                        entry.valueIsByteArray(),
-                        entry.version(), entry.ttl(),
-                        entry.expireTime(),
-                        entry.keyClassLoaderId(),
-                        entry.valueClassLoaderId());
+                        unswapped.value(entry.value());
 
-                    unswapped.value(entry.value());
+                        res.add(unswapped);
 
-                    res.add(unswapped);
+                        continue;
+                    }
                 }
+
+                unprocessedKeysList.add(key);
             }
 
-            if (!swapEnabled || keysList.isEmpty())
+            unprocessedKeys = unprocessedKeysList;
+
+            if (!swapEnabled || unprocessedKeys.isEmpty())
                 return res;
         }
+        else
+            unprocessedKeys = keys;
 
         // Swap is enabled.
         final GridTuple<IgniteCheckedException> err = F.t1();
 
-        Collection<SwapKey> converted = new 
ArrayList<>(F.viewReadOnly(keysList, new C1<K, SwapKey>() {
+        Collection<SwapKey> converted = new 
ArrayList<>(F.viewReadOnly(unprocessedKeys, new C1<K, SwapKey>() {
             @Override public SwapKey apply(K key) {
                 try {
                     return new SwapKey(key, cctx.affinity().partition(key), 
CU.marshal(cctx.shared(), key));

Reply via email to