shishkovilja commented on code in PR #12487:
URL: https://github.com/apache/ignite/pull/12487#discussion_r2483737653


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java:
##########
@@ -361,7 +355,7 @@ public IgniteDhtPartitionHistorySuppliersMap 
partitionHistorySuppliers() {
     /**
      *
      */
-    public Set<Integer> partsToReload(UUID nodeId, int grpId) {
+    public Collection<Integer> partsToReload(UUID nodeId, int grpId) {
         if (partsToReload == null)

Review Comment:
   Let's replace method body by `F#emptyIfNull` call. Also it is actual for 
`#partitionSizes` method (if you add `F#emptyIfNull` for maps).



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/PartitionSizesMap.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.cache.distributed.dht.preloader;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.jetbrains.annotations.Nullable;
+
+/** Partition sizes map. */
+public class PartitionSizesMap implements Message {
+    /** Type code. */
+    public static final short TYPE_CODE = 509;
+
+    /** Partition sizes map. */
+    @Order(value = 0, method = "partitionSizesMap")
+    private @Nullable Map<Integer, Long> partsSizes;
+
+    /** Default constructor. */
+    public PartitionSizesMap() {
+        // No-op.
+    }
+
+    /**
+     * @param partsSizes Partition sizes map.
+     */
+    public PartitionSizesMap(Map<Integer, Long> partsSizes) {
+        this.partsSizes = partsSizes;
+    }
+
+    /**
+     * @return Partition sizes map.
+     */
+    public Map<Integer, Long> partitionSizes() {

Review Comment:
   Redundant method.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/PartitionSizesMap.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.cache.distributed.dht.preloader;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.jetbrains.annotations.Nullable;
+
+/** Partition sizes map. */
+public class PartitionSizesMap implements Message {
+    /** Type code. */
+    public static final short TYPE_CODE = 509;
+
+    /** Partition sizes map. */
+    @Order(value = 0, method = "partitionSizesMap")
+    private @Nullable Map<Integer, Long> partsSizes;
+
+    /** Default constructor. */
+    public PartitionSizesMap() {
+        // No-op.
+    }
+
+    /**
+     * @param partsSizes Partition sizes map.
+     */
+    public PartitionSizesMap(Map<Integer, Long> partsSizes) {
+        this.partsSizes = partsSizes;
+    }
+
+    /**
+     * @return Partition sizes map.
+     */
+    public Map<Integer, Long> partitionSizes() {
+        return partsSizes != null ? partsSizes : Collections.emptyMap();
+    }
+
+    /**
+     * Used only for serialization.
+     * Since the code generation framework currently does not support null 
values for primitive wrappers,
+     * we use {@link Long#MIN_VALUE} instead of null.
+     *
+     * @return Partition sizes map.
+     */
+    public @Nullable Map<Integer, Long> partitionSizesMap() {
+        if (partsSizes == null)
+            return null;
+
+        return partsSizes.entrySet().stream()
+            .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue() != 
null ? e.getValue() : Long.MIN_VALUE));
+    }
+
+    /**
+     * Used only for deserialization.
+     *
+     * @param partsSizes Partition sizes map.
+     */
+    public void partitionSizesMap(@Nullable Map<Integer, Long> partsSizes) {
+        if (partsSizes == null)

Review Comment:
   ```suggestion
           this.partsSizes = partsSizes == null ? null : 
               F.viewReadOnly(partsSizes, v -> v != Long.MIN_VALUE ? v : null);
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/PartitionSizesMap.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.cache.distributed.dht.preloader;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.jetbrains.annotations.Nullable;
+
+/** Partition sizes map. */
+public class PartitionSizesMap implements Message {
+    /** Type code. */
+    public static final short TYPE_CODE = 509;
+
+    /** Partition sizes map. */
+    @Order(value = 0, method = "partitionSizesMap")

Review Comment:
   ```suggestion
       @Order(value = 0, method = "partitionSizes")
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/IgniteDhtPartitionsToReloadMap.java:
##########
@@ -18,45 +18,46 @@
 
 package org.apache.ignite.internal.processors.cache.distributed.dht.preloader;
 
-import java.io.Serializable;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 import java.util.UUID;
+import org.apache.ignite.internal.Order;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.plugin.extensions.communication.Message;
 
 /**
  * Partition reload map.
  */
-public class IgniteDhtPartitionsToReloadMap implements Serializable {
-    /** */
-    private static final long serialVersionUID = 0L;
+public class IgniteDhtPartitionsToReloadMap implements Message {
+    /** Type code. */
+    public static final short TYPE_CODE = 508;
 
     /** */
-    private Map<UUID, Map<Integer, Set<Integer>>> map;
+    @Order(value = 0, method = "partitionsToReload")
+    private Map<UUID, CachePartitionsToReloadMap> map;
 
     /**
      * @param nodeId Node ID.
      * @param cacheId Cache ID.
      * @return Collection of partitions to reload.
      */
-    public synchronized Set<Integer> get(UUID nodeId, int cacheId) {
+    public synchronized Collection<Integer> get(UUID nodeId, int cacheId) {
         if (map == null)
             return Collections.emptySet();
 
-        Map<Integer, Set<Integer>> nodeMap = map.get(nodeId);
+        CachePartitionsToReloadMap nodeMap = map.get(nodeId);
 
         if (nodeMap == null)
             return Collections.emptySet();
 
-        Set<Integer> parts = nodeMap.get(cacheId);
+        PartitionsToReload partsToReload = nodeMap.get(cacheId);
 
-        if (parts == null)
+        if (partsToReload == null)
             return Collections.emptySet();
 
-        return parts;
+        return partsToReload.partitions();

Review Comment:
   ```suggestion
           return F.emptyIfNull(partsToReload.partitions());
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/PartitionSizesMap.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.cache.distributed.dht.preloader;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.jetbrains.annotations.Nullable;
+
+/** Partition sizes map. */
+public class PartitionSizesMap implements Message {
+    /** Type code. */
+    public static final short TYPE_CODE = 509;
+
+    /** Partition sizes map. */
+    @Order(value = 0, method = "partitionSizesMap")
+    private @Nullable Map<Integer, Long> partsSizes;
+
+    /** Default constructor. */
+    public PartitionSizesMap() {
+        // No-op.
+    }
+
+    /**
+     * @param partsSizes Partition sizes map.
+     */
+    public PartitionSizesMap(Map<Integer, Long> partsSizes) {
+        this.partsSizes = partsSizes;
+    }
+
+    /**
+     * @return Partition sizes map.
+     */
+    public Map<Integer, Long> partitionSizes() {
+        return partsSizes != null ? partsSizes : Collections.emptyMap();
+    }
+
+    /**
+     * Used only for serialization.
+     * Since the code generation framework currently does not support null 
values for primitive wrappers,
+     * we use {@link Long#MIN_VALUE} instead of null.
+     *
+     * @return Partition sizes map.
+     */
+    public @Nullable Map<Integer, Long> partitionSizesMap() {
+        if (partsSizes == null)

Review Comment:
   ```suggestion
           return partsSizes == null ? null : F.viewReadOnly(partsSizes, v -> v 
!= null ? v : Long.MIN_VALUE);
   ```



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java:
##########
@@ -4665,11 +4665,13 @@ private void 
updatePartitionFullMap(AffinityTopologyVersion resTopVer, GridDhtPa
                     CacheGroupContext grp = cctx.cache().cacheGroup(grpId);
 
                     if (grp != null) {
+                        PartitionSizesMap sizesMap = partsSizes.get(grpId);
+
                         grp.topology().update(resTopVer,
                             msg.partitions().get(grpId),
                             cntrMap,
                             msg.partsToReload(cctx.localNodeId(), grpId),
-                            partsSizes.getOrDefault(grpId, 
Collections.emptyMap()),
+                            sizesMap != null ? sizesMap.partitionSizes() : 
Collections.emptyMap(),

Review Comment:
   Let's add `F#emptyIfNull` for maps.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/PartitionSizesMap.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.cache.distributed.dht.preloader;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.jetbrains.annotations.Nullable;
+
+/** Partition sizes map. */
+public class PartitionSizesMap implements Message {
+    /** Type code. */
+    public static final short TYPE_CODE = 509;
+
+    /** Partition sizes map. */
+    @Order(value = 0, method = "partitionSizesMap")
+    private @Nullable Map<Integer, Long> partsSizes;
+
+    /** Default constructor. */
+    public PartitionSizesMap() {
+        // No-op.
+    }
+
+    /**
+     * @param partsSizes Partition sizes map.
+     */
+    public PartitionSizesMap(Map<Integer, Long> partsSizes) {
+        this.partsSizes = partsSizes;
+    }
+
+    /**
+     * @return Partition sizes map.
+     */
+    public Map<Integer, Long> partitionSizes() {
+        return partsSizes != null ? partsSizes : Collections.emptyMap();
+    }
+
+    /**
+     * Used only for serialization.
+     * Since the code generation framework currently does not support null 
values for primitive wrappers,
+     * we use {@link Long#MIN_VALUE} instead of null.
+     *
+     * @return Partition sizes map.
+     */
+    public @Nullable Map<Integer, Long> partitionSizesMap() {

Review Comment:
   ```suggestion
       public @Nullable Map<Integer, Long> partitionSizes() {
   ```



-- 
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