alex-plekhanov commented on code in PR #10140:
URL: https://github.com/apache/ignite/pull/10140#discussion_r922047725


##########
modules/core/src/main/java/org/apache/ignite/client/ClientPartitionAwarenessMapperFactory.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.client;
+
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityKeyMapper;
+
+/**
+ * This factory is used on the client side and only when the partition 
awareness thin client feature is enabled. By default,
+ * on a new cache the RendezvousAffinityFunction will be used for calculating 
mappings 'key-to-partition' and 'partition-to-node'.
+ * The thin client will update all 'partitions-to-node' mappings on every a 
cache put/get request and the 'key-to-partition'

Review Comment:
   `on every a cache put/get` - not on every request, only when topology is 
changed



##########
modules/core/src/main/java/org/apache/ignite/client/ClientPartitionAwarenessMapperFactory.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.client;
+
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityKeyMapper;
+
+/**
+ * This factory is used on the client side and only when the partition 
awareness thin client feature is enabled. By default,
+ * on a new cache the RendezvousAffinityFunction will be used for calculating 
mappings 'key-to-partition' and 'partition-to-node'.
+ * The thin client will update all 'partitions-to-node' mappings on every a 
cache put/get request and the 'key-to-partition'
+ * mapping will be calculated on the client side.
+ * <p>
+ * The case described above will not be possible (and in turn partition 
awareness won't work) when a custom {@link AffinityFunction} or
+ * a {@link AffinityKeyMapper} was previously used for a cache creation. The 
partition awareness mapper factory is used to solve this
+ * issue. All 'partition-to-node' mappings will still be requested nad 
received from a server node, however, if a custom AffinityFunction

Review Comment:
   `nad` -> `and`



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCachePartitionsRequest.java:
##########
@@ -77,97 +78,68 @@ public ClientCachePartitionsRequest(BinaryRawReader reader) 
{
             if (cacheDesc == null)
                 continue;
 
-            ClientCachePartitionAwarenessGroup grp = processCache(ctx, groups, 
cacheGroupIds, affinityVer, cacheDesc);
+            ClientCachePartitionAwarenessGroup grp = processCache(ctx, 
affinityVer, cacheDesc);
 
-            // Cache already processed.
             if (grp == null)
                 continue;
 
-            groups.add(grp);
-            cacheGroupIds.put(cacheDesc.groupId(), grp);
+            ClientCachePartitionAwarenessGroup grp0 = grps.putIfAbsent(grp, 
grp);
+
+            if (grp0 != null)
+                grp0.addAll(Collections.singletonList(cacheDesc));
         }
 
-        Map<String, DynamicCacheDescriptor> allCaches = 
ctx.kernalContext().cache().cacheDescriptors();
+        Map<Integer, List<DynamicCacheDescriptor>> allCaches = 
ctx.kernalContext().cache().cacheDescriptors().values()

Review Comment:
   There is already `ctx.kernalContext().cache().cacheGroupDescriptors()` 
method, no need to grouping it manually.



##########
modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpIgniteClient.java:
##########
@@ -235,13 +235,17 @@ private TcpIgniteClient(ClientConfiguration cfg) throws 
ClientException {
         ensureCacheName(name);
 
         ch.request(ClientOperation.CACHE_DESTROY, req -> 
req.out().writeInt(ClientUtils.cacheId(name)));
+        ch.unregisterKeyPartitionMapperFactory(ClientUtils.cacheId(name));

Review Comment:
   This will only work if cache create and destroy were made on the same 
client. What if cache was destoyed on server for example?



##########
modules/core/src/main/java/org/apache/ignite/client/ClientPartitionAwarenessMapper.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.client;
+
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityKeyMapper;
+import org.apache.ignite.configuration.ClientConfiguration;
+
+/**
+ * This function calculates the cache key to a partition mapping for each 
cache key. It is used only for local calculation on a client side.
+ * <p>
+ * When the {@link ClientConfiguration#isPartitionAwarenessEnabled()} and the 
cache was created with a custom {@link AffinityFunction}
+ * or a {@link AffinityKeyMapper} this function will be used to calculate 
mappings. Be sure that a key maps to the same partition
+ * produced by the {@link AffinityFunction#partition(Object)} method.
+ *

Review Comment:
   Redundant NL



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cache/ClientCachePartitionsRequest.java:
##########
@@ -77,97 +78,68 @@ public ClientCachePartitionsRequest(BinaryRawReader reader) 
{
             if (cacheDesc == null)
                 continue;
 
-            ClientCachePartitionAwarenessGroup grp = processCache(ctx, groups, 
cacheGroupIds, affinityVer, cacheDesc);
+            ClientCachePartitionAwarenessGroup grp = processCache(ctx, 
affinityVer, cacheDesc);
 
-            // Cache already processed.
             if (grp == null)
                 continue;
 
-            groups.add(grp);
-            cacheGroupIds.put(cacheDesc.groupId(), grp);

Review Comment:
   Perhaps it worth to keep cacheGroupIds and check cacheGroupId for current 
cache before calculating it's mapping, to avoid double processing of mappings 
for cache groups from cacheIds.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to