ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] ptupitsyn commented on a change in pull request #6980: IGNITE-11898 Java Thin: Implement Best Effort Affinity
Date Wed, 16 Oct 2019 10:25:43 GMT
ptupitsyn commented on a change in pull request #6980: IGNITE-11898 Java Thin: Implement Best
Effort Affinity
URL: https://github.com/apache/ignite/pull/6980#discussion_r335391882
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientCacheAffinityMapping.java
 ##########
 @@ -0,0 +1,264 @@
+/*
+ * 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.internal.client.thin;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.internal.binary.BinaryObjectExImpl;
+import org.apache.ignite.internal.binary.BinaryReaderExImpl;
+import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+/**
+ * Affinity mapping (partition to nodes) for each cache.
+ */
+public class ClientCacheAffinityMapping {
+    /** Topology version. */
+    private final AffinityTopologyVersion topVer;
+
+    /** Affinity information for each cache. */
+    private final Map<Integer, CacheAffinityInfo> cacheAffinity = new HashMap<>();
+
+    /** Unmodifiable collection of cache IDs. To preserve instance immutability. */
+    private final Collection<Integer> cacheIds = Collections.unmodifiableCollection(cacheAffinity.keySet());
+
+    /**
+     * @param topVer Topology version.
+     */
+    private ClientCacheAffinityMapping(AffinityTopologyVersion topVer) {
+        this.topVer = topVer;
+    }
+
+    /**
+     * Gets topology version.
+     */
+    public AffinityTopologyVersion topologyVersion() {
+        return topVer;
+    }
+
+    /**
+     * Gets cache IDs.
+     */
+    public Collection<Integer> cacheIds() {
+        return cacheIds;
+    }
+
+    /**
+     * Calculates affinity node for given cache and key.
+     *
+     * @param binary Binary data processor (needed to extract affinity field from the key).
+     * @param cacheId Cache ID.
+     * @param key Key.
+     * @return Affinity node id or {@code null} if affinity node can't be determined for
given cache and key.
+     */
+    public UUID affinityNode(IgniteBinary binary, int cacheId, Object key) {
+        CacheAffinityInfo affinityInfo = cacheAffinity.get(cacheId);
+
+        if (affinityInfo == null || affinityInfo.keyCfg == null || affinityInfo.partMapping
== null)
+            return null;
+
+        Object binaryKey = binary.toBinary(key);
 
 Review comment:
   This seems to be very inefficient: `toBinary` does `marshal` to `byte[]` then `unmarshal`
back. For simple keys (numbers and strings - most common case) this conversion is unnecessary,
we can get the hash directly. I think we should check for simple types first, and only then
deal with user-defined classes.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message