Search in sources :

Example 1 with StatisticsObjectData

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

the class StatisticsUtils method toObjectData.

/**
 * Build statistics object data from values.
 *
 * @param keyMsg Statistics key.
 * @param type Statistics type.
 * @param stat Object statistics to convert.
 * @return Converted StatsObjectData message.
 * @throws IgniteCheckedException In case of errors.
 */
public static StatisticsObjectData toObjectData(StatisticsKeyMessage keyMsg, StatisticsType type, ObjectStatisticsImpl stat) throws IgniteCheckedException {
    Map<String, StatisticsColumnData> colData = new HashMap<>(stat.columnsStatistics().size());
    for (Map.Entry<String, ColumnStatistics> ts : stat.columnsStatistics().entrySet()) colData.put(ts.getKey(), toMessage(ts.getValue()));
    StatisticsObjectData data;
    if (stat instanceof ObjectPartitionStatisticsImpl) {
        ObjectPartitionStatisticsImpl partStats = (ObjectPartitionStatisticsImpl) stat;
        data = new StatisticsObjectData(keyMsg, stat.rowCount(), type, partStats.partId(), partStats.updCnt(), colData);
    } else
        data = new StatisticsObjectData(keyMsg, stat.rowCount(), type, 0, 0, colData);
    return data;
}
Also used : StatisticsObjectData(org.apache.ignite.internal.processors.query.stat.messages.StatisticsObjectData) HashMap(java.util.HashMap) StatisticsColumnData(org.apache.ignite.internal.processors.query.stat.messages.StatisticsColumnData) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with StatisticsObjectData

use of org.apache.ignite.internal.processors.query.stat.messages.StatisticsObjectData 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)

Example 3 with StatisticsObjectData

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

the class IgniteStatisticsPersistenceStoreImpl method getAllLocalPartitionsStatistics.

/**
 * {@inheritDoc}
 */
@Override
public Map<StatisticsKey, Collection<ObjectPartitionStatisticsImpl>> getAllLocalPartitionsStatistics(String schema) {
    String prefix = (schema == null) ? STAT_DATA_PREFIX : STAT_DATA_PREFIX + META_SEPARATOR + schema;
    Map<StatisticsKey, Collection<ObjectPartitionStatisticsImpl>> res = new HashMap<>();
    try {
        iterateMeta(prefix, (k, v) -> {
            StatisticsKey key = getStatsKey(k);
            StatisticsObjectData statData = (StatisticsObjectData) v;
            try {
                ObjectPartitionStatisticsImpl stat = StatisticsUtils.toObjectPartitionStatistics(null, statData);
                res.computeIfAbsent(key, k1 -> new ArrayList<>()).add(stat);
            } catch (IgniteCheckedException e) {
                log.warning(String.format("Error during reading statistics %s.%s by key %s", key.schema(), key.obj(), k));
            }
        }, true);
    } catch (IgniteCheckedException e) {
        log.warning("Unable to read local partition statistcs", e);
    }
    return res;
}
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) StatisticsObjectData(org.apache.ignite.internal.processors.query.stat.messages.StatisticsObjectData) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HashMap(java.util.HashMap) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Aggregations

StatisticsObjectData (org.apache.ignite.internal.processors.query.stat.messages.StatisticsObjectData)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 StatisticsKeyMessage (org.apache.ignite.internal.processors.query.stat.messages.StatisticsKeyMessage)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)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