ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] Mmuzaf commented on a change in pull request #6785: IGNITE-12080 Add extended logging for rebalance.
Date Tue, 20 Aug 2019 17:56:35 GMT
Mmuzaf commented on a change in pull request #6785: IGNITE-12080 Add extended logging for rebalance.
URL: https://github.com/apache/ignite/pull/6785#discussion_r315825471
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/RebalanceStatisticsUtils.java
 ##########
 @@ -0,0 +1,686 @@
+/*
+ * 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 org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.processors.affinity.AffinityAssignment;
+import org.apache.ignite.internal.processors.cache.CacheGroupContext;
+import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander.RebalanceFuture;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.StringJoiner;
+import java.util.TreeMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.ToLongFunction;
+import java.util.stream.Stream;
+
+import static java.lang.String.valueOf;
+import static java.lang.System.currentTimeMillis;
+import static java.time.ZoneId.systemDefault;
+import static java.time.format.DateTimeFormatter.ofPattern;
+import static java.util.Comparator.comparingInt;
+import static java.util.Comparator.comparingLong;
+import static java.util.Objects.nonNull;
+import static java.util.function.Function.identity;
+import static java.util.stream.Collector.of;
+import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.Collectors.mapping;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_QUIET;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_WRITE_REBALANCE_PARTITION_STATISTICS;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_WRITE_REBALANCE_STATISTICS;
+import static org.apache.ignite.IgniteSystemProperties.getBoolean;
+
+/**
+ * Utility class for rebalance statistics.
+ */
+class RebalanceStatisticsUtils {
+    /** To format the date and time. */
+    private static final DateTimeFormatter REBALANCE_STATISTICS_DTF = ofPattern("YYYY-MM-dd
HH:mm:ss,SSS");
+
+    /** Text for successful or not rebalances. */
+    private static final String SUCCESSFUL_OR_NOT_REBALANCE_TEXT = "including successful
and not rebalances";
+
+    /** Text successful rebalance. */
+    private static final String SUCCESSFUL_REBALANCE_TEXT = "successful rebalance";
+
+    /**
+     * Private constructor.
+     */
+    private RebalanceStatisticsUtils() {
+        throw new RuntimeException("don't create");
+    }
+
+    /** Rebalance future statistics. */
+    static class RebalanceFutureStatistics {
+        /** Start rebalance time in mills. */
+        private final long startTime = currentTimeMillis();
+
+        /** End rebalance time in mills. */
+        private volatile long endTime = startTime;
+
+        /** First key - topic id. Second key - supplier node. */
+        private final Map<Integer, Map<ClusterNode, RebalanceMessageStatistics>>
msgStats = new ConcurrentHashMap<>();
+
+        /** Is needed or not to print rebalance statistics. */
+        private final boolean printRebalanceStatistics = printRebalanceStatistics();
+
+        /**
+         * Add new message statistics.
+         * Requires to be invoked before demand message sending.
+         * This method required for {@code addReceivePartitionStatistics}.
+         * This method add new message statistics if
+         * {@link #printRebalanceStatistics} == true.
+         *
+         * @param topicId Topic id, require not null.
+         * @param supplierNode Supplier node, require not null.
+         * @see RebalanceMessageStatistics
+         * @see #addReceivePartitionStatistics(Integer, ClusterNode, GridDhtPartitionSupplyMessage)
+         */
+        public void addMessageStatistics(final Integer topicId, final ClusterNode supplierNode)
{
+            assert nonNull(topicId);
+            assert nonNull(supplierNode);
+
+            if (!printRebalanceStatistics)
+                return;
+
+            msgStats.computeIfAbsent(topicId, integer -> new ConcurrentHashMap<>())
+                .put(supplierNode, new RebalanceMessageStatistics(currentTimeMillis()));
+        }
+
+        /**
+         * Add new statistics by receive message with partitions from supplier
+         * node. Require invoke {@code addMessageStatistics} before send
+         * demand message. This method add new message statistics if
+         * {@link #printRebalanceStatistics} == true.
+         *
+         * @param topicId Topic id, require not null.
+         * @param supplierNode Supplier node, require not null.
+         * @param supplyMsg Supply message, require not null.
+         * @see ReceivePartitionStatistics
+         * @see #addMessageStatistics(Integer, ClusterNode)
+         */
+        public void addReceivePartitionStatistics(
+            final Integer topicId,
+            final ClusterNode supplierNode,
+            final GridDhtPartitionSupplyMessage supplyMsg
+        ) {
+            assert nonNull(topicId);
+            assert nonNull(supplierNode);
+            assert nonNull(supplyMsg);
+
+            if (!printRebalanceStatistics)
+                return;
+
+            List<PartitionStatistics> partStats = supplyMsg.infos().entrySet().stream()
+                .map(entry -> new PartitionStatistics(entry.getKey(), entry.getValue().infos().size()))
 
 Review comment:
   Entry value can be `null` in case of historical rebalance used. Will we get `NullPointerException`
here?

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