ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [10/14] ignite git commit: https://issues.apache.org/jira/browse/IGNITE-2329 - single get
Date Fri, 05 Feb 2016 12:25:46 GMT
https://issues.apache.org/jira/browse/IGNITE-2329 - single get


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

Branch: refs/heads/ignite-2329-1
Commit: f095126588a5f6d6263ebe8cf2ec963ce37e7d77
Parents: 7b98746
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Wed Feb 3 17:49:14 2016 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Wed Feb 3 17:49:14 2016 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheAdapter.java      |  8 ++--
 .../cache/distributed/dht/GridDhtGetFuture.java | 19 +++------
 .../distributed/dht/GridDhtGetSingleFuture.java |  3 ++
 .../org/apache/ignite/lang/IgniteBiTuple.java   |  6 ++-
 .../apache/ignite/lang/GridTupleSelfTest.java   | 42 +++++++++++++++++++-
 5 files changed, 59 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f0951265/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index ef7d30a..3356052 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -1852,9 +1852,11 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K,
V
                         ctx.affinity().affinityTopologyVersion() : ctx.shared().exchange().readyAffinityVersion())
:
                         tx.topologyVersion();
 
-                final Map<K1, V1> map = keys.size() == 1 ?
+                int keysSize = keys.size();
+
+                final Map<K1, V1> map = keysSize == 1 ?
                     (Map<K1, V1>)new IgniteBiTuple<>() :
-                    U.<K1, V1>newHashMap(keys.size());
+                    U.<K1, V1>newHashMap(keysSize);
 
                 final boolean storeEnabled = !skipVals && readThrough &&
ctx.readThrough();
 
@@ -1910,7 +1912,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K,
V
                                 if (tx == null || (!tx.implicit() && tx.isolation()
== READ_COMMITTED))
                                     ctx.evicts().touch(entry, topVer);
 
-                                if (keys.size() == 1)
+                                if (keysSize == 1)
                                     // Safe to return because no locks are required in READ_COMMITTED
mode.
                                     return new GridFinishedFuture<>(map);
                             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/f0951265/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java
index d55ede5..fa753b0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java
@@ -211,7 +211,7 @@ public final class GridDhtGetFuture<K, V> extends GridCompoundIdentityFuture<Col
         GridDhtFuture<Object> fut = cctx.dht().dhtPreloader().request(keys.keySet(),
topVer);
 
         if (fut != null) {
-            if (F.isEmpty(fut.invalidPartitions())) {
+            if (!F.isEmpty(fut.invalidPartitions())) {
                 if (retries == null)
                     retries = new HashSet<>();
 
@@ -452,18 +452,8 @@ public final class GridDhtGetFuture<K, V> extends GridCompoundIdentityFuture<Col
         if (fut.isDone()) {
             if (fut.error() != null)
                 onDone(fut.error());
-            else {
-                Map<KeyCacheObject, T2<CacheObject, GridCacheVersion>> map =
null;
-
-                try {
-                    map = fut.get();
-                }
-                catch (IgniteCheckedException e) {
-                    assert false; // Should never happen.
-                }
-
-                return new GridFinishedFuture<>(toEntryInfos(map));
-            }
+            else
+                return new GridFinishedFuture<>(toEntryInfos(fut.result()));
         }
 
         return new GridEmbeddedFuture<>(
@@ -488,6 +478,9 @@ public final class GridDhtGetFuture<K, V> extends GridCompoundIdentityFuture<Col
      * @return List of infos.
      */
     private Collection<GridCacheEntryInfo> toEntryInfos(Map<KeyCacheObject, T2<CacheObject,
GridCacheVersion>> map) {
+        if (map.isEmpty())
+            return Collections.emptyList();
+
         Collection<GridCacheEntryInfo> infos = new ArrayList<>(map.size());
 
         for (Map.Entry<KeyCacheObject, T2<CacheObject, GridCacheVersion>> entry
: map.entrySet()) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/f0951265/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java
index 4439307..b0e346d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetSingleFuture.java
@@ -450,6 +450,9 @@ public final class GridDhtGetSingleFuture<K, V> extends GridFutureAdapter<GridCa
      * @return List of infos.
      */
     private GridCacheEntryInfo toEntryInfo(Map<KeyCacheObject, T2<CacheObject, GridCacheVersion>>
map) {
+        if (map.isEmpty())
+            return null;
+
         Map.Entry<KeyCacheObject, T2<CacheObject, GridCacheVersion>> e = F.firstEntry(map);
 
         if (e != null) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/f0951265/modules/core/src/main/java/org/apache/ignite/lang/IgniteBiTuple.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteBiTuple.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteBiTuple.java
index 6098007..89e5f16 100644
--- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteBiTuple.java
+++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteBiTuple.java
@@ -250,7 +250,9 @@ public class IgniteBiTuple<V1, V2> implements Map<V1, V2>,
Map.Entry<V1, V2>,
 
     /** {@inheritDoc} */
     @Override public Set<Map.Entry<V1, V2>> entrySet() {
-        return Collections.<Entry<V1, V2>>singleton(this);
+        return isEmpty() ?
+            Collections.<Entry<V1,V2>>emptySet() :
+            Collections.<Entry<V1, V2>>singleton(this);
     }
 
     /** {@inheritDoc} */
@@ -301,4 +303,4 @@ public class IgniteBiTuple<V1, V2> implements Map<V1, V2>,
Map.Entry<V1, V2>,
     @Override public String toString() {
         return S.toString(IgniteBiTuple.class, this);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f0951265/modules/core/src/test/java/org/apache/ignite/lang/GridTupleSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/lang/GridTupleSelfTest.java b/modules/core/src/test/java/org/apache/ignite/lang/GridTupleSelfTest.java
index a21ed30..5865cad 100644
--- a/modules/core/src/test/java/org/apache/ignite/lang/GridTupleSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/lang/GridTupleSelfTest.java
@@ -20,10 +20,12 @@ package org.apache.ignite.lang;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.NoSuchElementException;
 import org.apache.ignite.internal.util.lang.GridTuple;
 import org.apache.ignite.internal.util.lang.GridTuple3;
 import org.apache.ignite.internal.util.lang.GridTupleV;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.testframework.junits.common.GridCommonTest;
 
@@ -102,6 +104,44 @@ public class GridTupleSelfTest extends GridCommonAbstractTest {
     /**
      * JUnit.
      */
+    public void testGridTuple2AsMap() {
+        String str1 = "A test string 1";
+        String str2 = "A test string 2";
+
+        IgniteBiTuple<String, String> tpl = new IgniteBiTuple<>();
+
+        tpl.put(str1, str2);
+
+        assertEquals(str2, tpl.get(str1));
+        assertEquals(1, tpl.size());
+
+        assert tpl.containsKey(str1);
+        assert tpl.containsValue(str2);
+
+        Iterator<Map.Entry<String, String>> it = tpl.entrySet().iterator();
+
+        assert it.hasNext();
+
+        Map.Entry<String, String> next = it.next();
+
+        assertEquals(str1, next.getKey());
+        assertEquals(str2, next.getValue());
+
+        assert !it.hasNext();
+
+        next = F.firstEntry(tpl);
+
+        assertEquals(str1, next.getKey());
+        assertEquals(str2, next.getValue());
+
+        tpl = new IgniteBiTuple<>();
+
+        assert !tpl.entrySet().iterator().hasNext();
+    }
+
+    /**
+     * JUnit.
+     */
     public void testGridTuple3AsIterable() {
         String str1 = "A test string 1";
         String str2 = "A test string 2";
@@ -166,4 +206,4 @@ public class GridTupleSelfTest extends GridCommonAbstractTest {
             info("Caught expected exception: " + e);
         }
     }
-}
\ No newline at end of file
+}


Mime
View raw message