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);
}
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);
}
}
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);
}
}
Aggregations