Berkof commented on a change in pull request #9392: URL: https://github.com/apache/ignite/pull/9392#discussion_r745549211
########## File path: modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/stat/IgniteGlobalStatisticsManager.java ########## @@ -0,0 +1,1026 @@ +/* + * 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.query.stat; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.events.DiscoveryEvent; +import org.apache.ignite.internal.GridTopic; +import org.apache.ignite.internal.events.DiscoveryCustomEvent; +import org.apache.ignite.internal.managers.communication.GridIoManager; +import org.apache.ignite.internal.managers.communication.GridIoPolicy; +import org.apache.ignite.internal.managers.communication.GridMessageListener; +import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; +import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager; +import org.apache.ignite.internal.managers.systemview.GridSystemViewManager; +import org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnGlobalDataViewWalker; +import org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnLocalDataViewWalker; +import org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnPartitionDataViewWalker; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch; +import org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware; +import org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor; +import org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration; +import org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration; +import org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage; +import org.apache.ignite.internal.processors.query.stat.messages.StatisticsObjectData; +import org.apache.ignite.internal.processors.query.stat.messages.StatisticsRequest; +import org.apache.ignite.internal.processors.query.stat.messages.StatisticsResponse; +import org.apache.ignite.internal.processors.query.stat.view.StatisticsColumnConfigurationView; +import org.apache.ignite.internal.processors.query.stat.view.StatisticsColumnGlobalDataView; +import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.thread.IgniteThreadPoolExecutor; + +/** + * Global statistics manager. Cache global statistics and collect it. + */ +public class IgniteGlobalStatisticsManager implements GridMessageListener { + /** */ + private static final String STAT_GLOBAL_VIEW_NAME = "statisticsGlobalData"; + + /** */ + private static final String STAT_GLOBAL_VIEW_DESCRIPTION = "Global statistics."; + + /** Statistics manager. */ + private final IgniteStatisticsManagerImpl statMgr; + + /** Statistics gatherer. */ + //private final StatisticsProcessor statProc; + + /** Pool to process statistics requests. */ + private final IgniteThreadPoolExecutor mgmtPool; + + /** Discovery manager to get server node list to statistics master calculation. */ + private final GridDiscoveryManager discoMgr; + + /** Cluster state processor. */ + private final GridClusterStateProcessor cluster; + + /** Cache partition exchange manager. */ + private final GridCachePartitionExchangeManager<?, ?> exchange; + + /** Helper to transform or generate statistics related messages. */ + private final IgniteStatisticsHelper helper; + + /** Grid io manager to exchange global and local statistics. */ + private final GridIoManager ioMgr; + + /** Cache for global statistics. */ + private final ConcurrentMap<StatisticsKey, CacheEntry<ObjectStatisticsImpl>> globalStatistics = + new ConcurrentHashMap<>(); + + /** Incoming requests which should be served after local statistics collection finish. */ + private final ConcurrentMap<StatisticsKey, Collection<StatisticsAddressedRequest>> inLocalRequests = + new ConcurrentHashMap<>(); + + /** Incoming requests which should be served after global statistics collection finish. */ + private final ConcurrentMap<StatisticsKey, Collection<StatisticsAddressedRequest>> inGloblaRequests = + new ConcurrentHashMap<>(); + + /** Outcoming global collection requests. */ + private final ConcurrentMap<StatisticsKey, StatisticsGatheringContext> curCollections = new ConcurrentHashMap<>(); + + /** Outcoming global statistics requests to request id. */ + private final ConcurrentMap<StatisticsKey, UUID> outGlobalStatisticsRequests = new ConcurrentHashMap<>(); + + /** Logger. */ + private final IgniteLogger log; + + /** Started flag. */ + private boolean started; + + /** Exchange listener: clean inbound requests and restart outbount. */ + private final PartitionsExchangeAware exchAwareLsnr = new PartitionsExchangeAware() { + @Override public void onDoneAfterTopologyUnlock(GridDhtPartitionsExchangeFuture fut) { + + // Skip join/left client nodes. + if (fut.exchangeType() != GridDhtPartitionsExchangeFuture.ExchangeType.ALL || + cluster.clusterState().lastState() != ClusterState.ACTIVE) + return; + + DiscoveryEvent evt = fut.firstEvent(); + + // Skip create/destroy caches. + if (evt.type() == DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) { + DiscoveryCustomMessage msg = ((DiscoveryCustomEvent)evt).customMessage(); + + if (msg instanceof DynamicCacheChangeBatch) + return; + + // Just clear all activities and update topology version. + if (log.isDebugEnabled()) + log.debug("Resetting all global statistics activities due to new topology " + + fut.topologyVersion()); + + inLocalRequests.clear(); + inGloblaRequests.clear(); + + Set<StatisticsKey> curColls = curCollections.keySet(); + + for (StatisticsKey key : curColls) { + curCollections.remove(key); + + mgmtPool.submit(() -> collectGlobalStatistics(key)); + } + + Set<StatisticsKey> outReqs = outGlobalStatisticsRequests.keySet(); + + for (StatisticsKey key : outReqs) { + outGlobalStatisticsRequests.remove(key); + + mgmtPool.submit(() -> collectGlobalStatistics(key)); + } + } + } + }; + + /** + * Constructor. + * + * @param statMgr Statistics manager. + * @param sysViewMgr System view manager. + //* @param statProc Statistics processor. Review comment: Removed. ########## File path: modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/stat/IgniteGlobalStatisticsManager.java ########## @@ -0,0 +1,1026 @@ +/* + * 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.query.stat; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.events.DiscoveryEvent; +import org.apache.ignite.internal.GridTopic; +import org.apache.ignite.internal.events.DiscoveryCustomEvent; +import org.apache.ignite.internal.managers.communication.GridIoManager; +import org.apache.ignite.internal.managers.communication.GridIoPolicy; +import org.apache.ignite.internal.managers.communication.GridMessageListener; +import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage; +import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager; +import org.apache.ignite.internal.managers.systemview.GridSystemViewManager; +import org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnGlobalDataViewWalker; +import org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnLocalDataViewWalker; +import org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnPartitionDataViewWalker; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch; +import org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture; +import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware; +import org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor; +import org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration; +import org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration; +import org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage; +import org.apache.ignite.internal.processors.query.stat.messages.StatisticsObjectData; +import org.apache.ignite.internal.processors.query.stat.messages.StatisticsRequest; +import org.apache.ignite.internal.processors.query.stat.messages.StatisticsResponse; +import org.apache.ignite.internal.processors.query.stat.view.StatisticsColumnConfigurationView; +import org.apache.ignite.internal.processors.query.stat.view.StatisticsColumnGlobalDataView; +import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.thread.IgniteThreadPoolExecutor; + +/** + * Global statistics manager. Cache global statistics and collect it. + */ +public class IgniteGlobalStatisticsManager implements GridMessageListener { + /** */ + private static final String STAT_GLOBAL_VIEW_NAME = "statisticsGlobalData"; + + /** */ + private static final String STAT_GLOBAL_VIEW_DESCRIPTION = "Global statistics."; + + /** Statistics manager. */ + private final IgniteStatisticsManagerImpl statMgr; + + /** Statistics gatherer. */ + //private final StatisticsProcessor statProc; + + /** Pool to process statistics requests. */ + private final IgniteThreadPoolExecutor mgmtPool; + + /** Discovery manager to get server node list to statistics master calculation. */ + private final GridDiscoveryManager discoMgr; + + /** Cluster state processor. */ + private final GridClusterStateProcessor cluster; + + /** Cache partition exchange manager. */ + private final GridCachePartitionExchangeManager<?, ?> exchange; + + /** Helper to transform or generate statistics related messages. */ + private final IgniteStatisticsHelper helper; + + /** Grid io manager to exchange global and local statistics. */ + private final GridIoManager ioMgr; + + /** Cache for global statistics. */ + private final ConcurrentMap<StatisticsKey, CacheEntry<ObjectStatisticsImpl>> globalStatistics = + new ConcurrentHashMap<>(); + + /** Incoming requests which should be served after local statistics collection finish. */ + private final ConcurrentMap<StatisticsKey, Collection<StatisticsAddressedRequest>> inLocalRequests = + new ConcurrentHashMap<>(); + + /** Incoming requests which should be served after global statistics collection finish. */ + private final ConcurrentMap<StatisticsKey, Collection<StatisticsAddressedRequest>> inGloblaRequests = + new ConcurrentHashMap<>(); + + /** Outcoming global collection requests. */ + private final ConcurrentMap<StatisticsKey, StatisticsGatheringContext> curCollections = new ConcurrentHashMap<>(); + + /** Outcoming global statistics requests to request id. */ + private final ConcurrentMap<StatisticsKey, UUID> outGlobalStatisticsRequests = new ConcurrentHashMap<>(); + + /** Logger. */ + private final IgniteLogger log; + + /** Started flag. */ + private boolean started; + + /** Exchange listener: clean inbound requests and restart outbount. */ + private final PartitionsExchangeAware exchAwareLsnr = new PartitionsExchangeAware() { + @Override public void onDoneAfterTopologyUnlock(GridDhtPartitionsExchangeFuture fut) { + + // Skip join/left client nodes. + if (fut.exchangeType() != GridDhtPartitionsExchangeFuture.ExchangeType.ALL || + cluster.clusterState().lastState() != ClusterState.ACTIVE) + return; + + DiscoveryEvent evt = fut.firstEvent(); + + // Skip create/destroy caches. + if (evt.type() == DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) { + DiscoveryCustomMessage msg = ((DiscoveryCustomEvent)evt).customMessage(); + + if (msg instanceof DynamicCacheChangeBatch) + return; + + // Just clear all activities and update topology version. + if (log.isDebugEnabled()) + log.debug("Resetting all global statistics activities due to new topology " + + fut.topologyVersion()); + + inLocalRequests.clear(); + inGloblaRequests.clear(); + + Set<StatisticsKey> curColls = curCollections.keySet(); + + for (StatisticsKey key : curColls) { + curCollections.remove(key); + + mgmtPool.submit(() -> collectGlobalStatistics(key)); + } + + Set<StatisticsKey> outReqs = outGlobalStatisticsRequests.keySet(); + + for (StatisticsKey key : outReqs) { + outGlobalStatisticsRequests.remove(key); + + mgmtPool.submit(() -> collectGlobalStatistics(key)); + } + } + } + }; + + /** + * Constructor. + * + * @param statMgr Statistics manager. + * @param sysViewMgr System view manager. + //* @param statProc Statistics processor. + * @param mgmtPool Statistics management pool. + * @param discoMgr Grid discovery manager. + * @param cluster Cluster state processor. + * @param exchange Partition exchange manager. + * @param helper Statistics helper. + * @param ioMgr Communication manager. + * @param logSupplier Log supplier. + */ + public IgniteGlobalStatisticsManager( + IgniteStatisticsManagerImpl statMgr, + GridSystemViewManager sysViewMgr, + //StatisticsProcessor statProc, Review comment: removed -- 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]
