You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2019/09/17 06:33:24 UTC

[ignite] branch master updated: IGNITE-12147 Thin client: Fixed partitions response for caches with not applicable affinity awareness - Fixes #6847.

This is an automated email from the ASF dual-hosted git repository.

alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 47cb9b0  IGNITE-12147 Thin client: Fixed partitions response for caches with not applicable affinity awareness - Fixes #6847.
47cb9b0 is described below

commit 47cb9b09e6df7db1458a0a3610129ac2167cad23
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Tue Sep 17 09:27:34 2019 +0300

    IGNITE-12147 Thin client: Fixed partitions response for caches with not applicable affinity awareness - Fixes #6847.
---
 .../client/cache/ClientCachePartitionsRequest.java | 21 ++++++------
 .../Client/Cache/AffinityAwarenessTest.cs          | 37 ++++++++++++++++++++++
 .../Impl/Client/ClientFailoverSocket.cs            | 16 ++++++++++
 3 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCachePartitionsRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCachePartitionsRequest.java
index d1c943a..5141e26 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCachePartitionsRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCachePartitionsRequest.java
@@ -77,18 +77,14 @@ public class ClientCachePartitionsRequest extends ClientRequest {
             if (cacheDesc == null)
                 continue;
 
-            ClientCachePartitionMapping mapping = processCache(ctx, groups, cacheGroupIds, affinityVer, cacheDesc);
+            ClientCacheAffinityAwarenessGroup grp = processCache(ctx, groups, cacheGroupIds, affinityVer, cacheDesc);
 
             // Cache already processed.
-            if (mapping == null)
+            if (grp == null)
                 continue;
 
-            // Mapping is new and is not contained in the current list.
-            CacheObjectBinaryProcessorImpl proc = (CacheObjectBinaryProcessorImpl)ctx.kernalContext().cacheObjects();
-            ClientCacheAffinityAwarenessGroup group = new ClientCacheAffinityAwarenessGroup(proc, mapping, cacheDesc);
-
-            groups.add(group);
-            cacheGroupIds.put(cacheDesc.groupId(), group);
+            groups.add(grp);
+            cacheGroupIds.put(cacheDesc.groupId(), grp);
         }
 
         Map<String, DynamicCacheDescriptor> allCaches = ctx.kernalContext().cache().cacheDescriptors();
@@ -112,9 +108,10 @@ public class ClientCachePartitionsRequest extends ClientRequest {
      * @param cacheGroupIds Map of known group IDs.
      * @param affinityVer Affinity topology version.
      * @param cacheDesc Cache descriptor.
-     * @return Null if cache was processed and new client cache partition mapping if it does not belong to any existent.
+     * @return Null if cache was processed and new client cache affinity awareness group if it does not belong to any
+     * existent.
      */
-    private static ClientCachePartitionMapping processCache(
+    private static ClientCacheAffinityAwarenessGroup processCache(
         ClientConnectionContext ctx,
         List<ClientCacheAffinityAwarenessGroup> groups,
         Map<Integer, ClientCacheAffinityAwarenessGroup> cacheGroupIds,
@@ -151,7 +148,9 @@ public class ClientCachePartitionsRequest extends ClientRequest {
             return null;
         }
 
-        return mapping;
+        CacheObjectBinaryProcessorImpl proc = (CacheObjectBinaryProcessorImpl)ctx.kernalContext().cacheObjects();
+
+        return new ClientCacheAffinityAwarenessGroup(proc, mapping, cacheDesc);
     }
 
     /**
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/AffinityAwarenessTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/AffinityAwarenessTest.cs
index b800667..416925f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/AffinityAwarenessTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/AffinityAwarenessTest.cs
@@ -270,6 +270,43 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
             Assert.AreEqual(expectedRequests, requests);
         }
 
+
+        [Test]
+        public void ReplicatedCacheGet_RepeatedCall_DoesNotRequestAffinityMapping()
+        {
+            // Test cache for which affinity awareness is not applicable.
+            var cfg = new CacheClientConfiguration("replicated_cache") {CacheMode = CacheMode.Replicated};
+            var cache = Client.CreateCache<int, int>(cfg);
+
+            // Init the replicated cache and start the new one to enforce partition mapping request.
+            cache.PutAll(Enumerable.Range(1, 3).ToDictionary(x => x, x => x));
+            Client.CreateCache<int, int>("repeat-call-test-replicated");
+            ClearLoggers();
+
+            cache.Get(1);
+            cache.Get(2);
+            cache.Get(3);
+
+            var reqs = _loggers
+                .Select(l => new {Logger = l, Requests = GetCacheRequestNames(l).ToArray()})
+                .Where(r => r.Requests.Length > 0)
+                .ToArray();
+
+            // All requests should go to a single (default) node, because affinity awareness is not applicable.
+            Assert.AreEqual(1, reqs.Length);
+
+            // There should be only one partitions request.
+            var expectedRequests = new[]
+            {
+                "Partitions",
+                "Get",
+                "Get",
+                "Get"
+            };
+
+            Assert.AreEqual(expectedRequests, reqs[0].Requests);
+        }
+
         [Test]
         public void CacheGet_AffinityAwarenessDisabled_RequestIsRoutedToDefaultNode()
         {
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientFailoverSocket.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientFailoverSocket.cs
index a230a33..9b97db0 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientFailoverSocket.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientFailoverSocket.cs
@@ -212,6 +212,11 @@ namespace Apache.Ignite.Core.Impl.Client
                 return null;
             }
 
+            if (cachePartMap == null)
+            {
+                return null;
+            }
+
             var partition = GetPartition(key, cachePartMap.PartitionNodeIds.Count, cachePartMap.KeyConfiguration);
             var nodeId = cachePartMap.PartitionNodeIds[partition];
 
@@ -402,6 +407,17 @@ namespace Apache.Ignite.Core.Impl.Client
             {
                 var grp = new ClientCacheAffinityAwarenessGroup(s);
 
+                if (grp.PartitionMap == null)
+                {
+                    // Partition awareness is not applicable for these caches.
+                    foreach (var cache in grp.Caches)
+                    {
+                        mapping[cache.Key] = null;
+                    }
+
+                    continue;
+                }
+
                 // Count partitions to avoid reallocating array.
                 int maxPartNum = 0;
                 foreach (var partMap in grp.PartitionMap)