You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2019/01/22 11:20:35 UTC

[GitHub] ascherbakoff commented on a change in pull request #5874: IGNITE-10877 Affinity run compatibility job fixes.

ascherbakoff commented on a change in pull request #5874: IGNITE-10877 Affinity run compatibility job fixes.
URL: https://github.com/apache/ignite/pull/5874#discussion_r249736258
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentV2.java
 ##########
 @@ -0,0 +1,334 @@
+/*
+ * 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.processors.affinity;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.dto.IgniteDataTransferObject;
+import org.apache.ignite.internal.util.BitSetIntSet;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+/**
+ * Cached affinity calculations V2.
+ * It supports adaptive usage of BitSets instead of HashSets.
+ */
+@SuppressWarnings("ForLoopReplaceableByForEach")
+public class GridAffinityAssignmentV2 extends IgniteDataTransferObject implements AffinityAssignment {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Topology version. */
+    private AffinityTopologyVersion topVer;
+
+    /** Collection of calculated affinity nodes. */
+    private List<List<ClusterNode>> assignment;
+
+    /** Map of primary node partitions. */
+    private Map<UUID, Set<Integer>> primary;
+
+    /** Map of backup node partitions. */
+    private Map<UUID, Set<Integer>> backup;
+
+    /** Assignment node IDs */
+    private transient volatile List<Collection<UUID>> assignmentIds;
+
+    /** Nodes having primary or backup partition assignments. */
+    private transient volatile Set<ClusterNode> nodes;
+
+    /** Nodes having primary partitions assignments. */
+    private transient volatile Set<ClusterNode> primaryPartsNodes;
+
+    /** */
+    private transient List<List<ClusterNode>> idealAssignment;
+
+    /**
+     * Default constructor for deserialization.
+     */
+    public GridAffinityAssignmentV2() {
+
+    }
+
+    /**
+     * Constructs cached affinity calculations item.
+     *
+     * @param topVer Topology version.
+     */
+    GridAffinityAssignmentV2(AffinityTopologyVersion topVer) {
+        this.topVer = topVer;
+        primary = Collections.emptyMap();
+        backup = Collections.emptyMap();
+    }
+
+    /**
+     * @param topVer Topology version.
+     * @param assignment Assignment.
+     * @param idealAssignment Ideal assignment.
+     */
+    public GridAffinityAssignmentV2(AffinityTopologyVersion topVer,
+        List<List<ClusterNode>> assignment,
+        List<List<ClusterNode>> idealAssignment
+    ) {
+        assert topVer != null;
+        assert assignment != null;
+        assert idealAssignment != null;
+
+        this.topVer = topVer;
+        this.assignment = Collections.unmodifiableList(assignment);
+        this.idealAssignment = Collections.unmodifiableList(
+            idealAssignment.equals(assignment) ? assignment : idealAssignment
+        );
+
+        // Temporary mirrors with modifiable partition's collections.
+        Map<UUID, Set<Integer>> tmpPrimary = new HashMap<>();
+        Map<UUID, Set<Integer>> tmpBackup = new HashMap<>();
+        boolean isPrimary;
+
+        for (int partsCnt = assignment.size(), p = 0; p < partsCnt; p++) {
+            isPrimary = true;
+
+            for (ClusterNode node : assignment.get(p)) {
+                UUID id = node.id();
+
+                Map<UUID, Set<Integer>> tmp = isPrimary ? tmpPrimary : tmpBackup;
+
+                /*
+                    https://issues.apache.org/jira/browse/IGNITE-4554 BitSet performs better than HashSet at most cases.
+                    However with 65k partition and high number of nodes (700+) BitSet is loosing HashSet.
+                    We need to replace it with sparse bitsets.
+                 */
+                tmp.computeIfAbsent(id, uuid ->
+                    !IGNITE_DISABLE_AFFINITY_MEMORY_OPTIMIZATION ? new BitSetIntSet() : new HashSet<>()
 
 Review comment:
   Missing 
   partAssignments = assignment.get(p)
   U.newHashSet(partAssignments.size())

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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