Search in sources :

Example 1 with StatisticsKeyMessage

use of org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage in project ignite by apache.

the class IgniteStatisticsHelper method aggregateLocalStatistics.

/**
 * Aggregate specified partition level statistics to local level statistics.
 *
 * @param cfg Statistics object configuration.
 * @param stats Collection of all local partition level or local level statistics by specified key to aggregate.
 * @return Local level aggregated statistics.
 */
public ObjectStatisticsImpl aggregateLocalStatistics(StatisticsObjectConfiguration cfg, Collection<? extends ObjectStatisticsImpl> stats) {
    StatisticsKeyMessage keyMsg = new StatisticsKeyMessage(cfg.key().schema(), cfg.key().obj(), new ArrayList<>(cfg.columns().keySet()));
    // For now there can be only tables
    GridH2Table tbl = schemaMgr.dataTable(keyMsg.schema(), keyMsg.obj());
    if (tbl == null) {
        // remove all loaded statistics.
        if (log.isDebugEnabled())
            log.debug(String.format("Removing statistics for object %s.%s cause table doesn't exists.", keyMsg.schema(), keyMsg.obj()));
        return null;
    }
    return aggregateLocalStatistics(tbl, cfg, stats, log);
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) StatisticsKeyMessage(org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage)

Example 2 with StatisticsKeyMessage

use of org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage in project ignite by apache.

the class IgniteStatisticsPersistenceStoreImpl method replaceLocalPartitionsStatistics.

/**
 * {@inheritDoc}
 */
@Override
public void replaceLocalPartitionsStatistics(StatisticsKey key, Collection<ObjectPartitionStatisticsImpl> statistics) {
    if (!checkMetastore("Unable to save local partitions statistics: %s.%s for %d partitions", key.schema(), key.obj(), statistics.size()))
        return;
    StatisticsKeyMessage keyMsg = new StatisticsKeyMessage(key.schema(), key.obj(), null);
    Map<Integer, ObjectPartitionStatisticsImpl> partStatistics = statistics.stream().collect(Collectors.toMap(ObjectPartitionStatisticsImpl::partId, s -> s));
    String objPrefix = getPartKeyPrefix(key);
    try {
        iterateMeta(objPrefix, (k, v) -> {
            ObjectPartitionStatisticsImpl newStats = partStatistics.remove(getPartitionId(k));
            try {
                if (newStats == null) {
                    if (log.isTraceEnabled())
                        log.trace("Removing statistics by key" + k);
                    metastore.remove(k);
                } else {
                    if (log.isTraceEnabled())
                        log.trace("Rewriting statistics by key " + k);
                    metastore.write(k, StatisticsUtils.toObjectData(keyMsg, StatisticsType.PARTITION, newStats));
                }
            } catch (IgniteCheckedException e) {
                log.warning(String.format("Error during saving statistics %s.%s to %s", key.schema(), key.obj(), k), e);
            }
        }, false);
        if (!partStatistics.isEmpty()) {
            for (Map.Entry<Integer, ObjectPartitionStatisticsImpl> entry : partStatistics.entrySet()) writeMeta(objPrefix + entry.getKey(), StatisticsUtils.toObjectData(keyMsg, StatisticsType.PARTITION, entry.getValue()));
        }
    } catch (IgniteCheckedException e) {
        log.warning(String.format("Error during saving statistics %s.%s", key.schema(), key.obj()), e);
    }
}
Also used : IntMap(org.apache.ignite.internal.util.collection.IntMap) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MetastorageLifecycleListener(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetastorageLifecycleListener) Set(java.util.Set) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ReadOnlyMetastorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadOnlyMetastorage) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) List(java.util.List) StatisticsKeyMessage(org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage) Map(java.util.Map) ReadWriteMetastorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadWriteMetastorage) BiConsumer(java.util.function.BiConsumer) StatisticsObjectData(org.apache.ignite.internal.processors.query.stat.messages.StatisticsObjectData) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap) Collections(java.util.Collections) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) StatisticsKeyMessage(org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage) IntMap(org.apache.ignite.internal.util.collection.IntMap) HashMap(java.util.HashMap) Map(java.util.Map) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap)

Example 3 with StatisticsKeyMessage

use of org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage in project ignite by apache.

the class IgniteStatisticsPersistenceStoreImpl method saveLocalPartitionStatistics.

/**
 * {@inheritDoc}
 */
@Override
public void saveLocalPartitionStatistics(StatisticsKey key, ObjectPartitionStatisticsImpl stat) {
    if (!checkMetastore("Unable to store local partition statistics %s.%s:%d", key.schema(), key.obj(), stat.partId()))
        return;
    String partKey = getPartKeyPrefix(key) + stat.partId();
    StatisticsKeyMessage keyMsg = new StatisticsKeyMessage(key.schema(), key.obj(), null);
    try {
        StatisticsObjectData statsMsg = StatisticsUtils.toObjectData(keyMsg, StatisticsType.PARTITION, stat);
        if (log.isTraceEnabled())
            log.trace("Writing statistics by key " + partKey);
        writeMeta(partKey, statsMsg);
    } catch (IgniteCheckedException e) {
        log.warning(String.format("Error while storing local partition statistics %s.%s:%d", key.schema(), key.obj(), stat.partId()), e);
    }
}
Also used : StatisticsObjectData(org.apache.ignite.internal.processors.query.stat.messages.StatisticsObjectData) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) StatisticsKeyMessage(org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage)

Aggregations

StatisticsKeyMessage (org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 StatisticsObjectData (org.apache.ignite.internal.processors.query.stat.messages.StatisticsObjectData)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 BiConsumer (java.util.function.BiConsumer)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 MetastorageLifecycleListener (org.apache.ignite.internal.processors.cache.persistence.metastorage.MetastorageLifecycleListener)1 ReadOnlyMetastorage (org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadOnlyMetastorage)1 ReadWriteMetastorage (org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadWriteMetastorage)1