use of org.apache.ignite.internal.processors.query.stat.ObjectPartitionStatisticsImpl in project ignite by apache.
the class GatherPartitionStatistics method processPartition.
/**
* Decide what column should be gathered and what partition statistics already has and either fix it or
* collect new data.
*
* @param cctx Cache context to get partition from.
* @return New partition statistics.
*/
private ObjectPartitionStatisticsImpl processPartition(GridCacheContext<?, ?> cctx) {
ObjectPartitionStatisticsImpl partStat = statRepo.getLocalPartitionStatistics(gathCtx.configuration().key(), partId);
Map<String, StatisticsColumnConfiguration> colsToCollect = getColumnsToCollect(partStat);
Set<String> colsToRemove = getColumnsToRemove(partStat);
// Try to use existing statitsics.
if (F.isEmpty(colsToCollect))
return fixExisting(partStat, colsToRemove);
else
return recollectPartition(cctx, partStat, colsToCollect, colsToRemove);
}
use of org.apache.ignite.internal.processors.query.stat.ObjectPartitionStatisticsImpl in project ignite by apache.
the class ColumnPartitionDataViewSupplier method columnPartitionStatisticsViewSupplier.
/**
* Statistics column partition data view filterable supplier.
*
* @param filter Filter.
* @return Iterable with statistics column partition data views.
*/
public Iterable<StatisticsColumnPartitionDataView> columnPartitionStatisticsViewSupplier(Map<String, Object> filter) {
String type = (String) filter.get(StatisticsColumnPartitionDataViewWalker.TYPE_FILTER);
if (type != null && !StatisticsColumnConfigurationView.TABLE_TYPE.equalsIgnoreCase(type))
return Collections.emptyList();
String schema = (String) filter.get(StatisticsColumnPartitionDataViewWalker.SCHEMA_FILTER);
String name = (String) filter.get(StatisticsColumnPartitionDataViewWalker.NAME_FILTER);
Integer partId = (Integer) filter.get(StatisticsColumnPartitionDataViewWalker.PARTITION_FILTER);
String column = (String) filter.get(StatisticsColumnPartitionDataViewWalker.COLUMN_FILTER);
Map<StatisticsKey, Collection<ObjectPartitionStatisticsImpl>> partsStatsMap;
if (!F.isEmpty(schema) && !F.isEmpty(name)) {
StatisticsKey key = new StatisticsKey(schema, name);
Collection<ObjectPartitionStatisticsImpl> keyStat;
if (partId == null)
keyStat = store.getLocalPartitionsStatistics(key);
else {
ObjectPartitionStatisticsImpl partStat = store.getLocalPartitionStatistics(key, partId);
keyStat = (partStat == null) ? Collections.emptyList() : Collections.singletonList(partStat);
}
partsStatsMap = Collections.singletonMap(key, keyStat);
} else
partsStatsMap = store.getAllLocalPartitionsStatistics(schema);
List<StatisticsColumnPartitionDataView> res = new ArrayList<>();
for (Map.Entry<StatisticsKey, Collection<ObjectPartitionStatisticsImpl>> partsStatsEntry : partsStatsMap.entrySet()) {
StatisticsKey key = partsStatsEntry.getKey();
for (ObjectPartitionStatisticsImpl partStat : partsStatsEntry.getValue()) {
if (column == null) {
for (Map.Entry<String, ColumnStatistics> colStatEntry : partStat.columnsStatistics().entrySet()) res.add(new StatisticsColumnPartitionDataView(key, colStatEntry.getKey(), partStat));
} else {
ColumnStatistics colStat = partStat.columnStatistics(column);
if (colStat != null)
res.add(new StatisticsColumnPartitionDataView(key, column, partStat));
}
}
}
return res;
}
use of org.apache.ignite.internal.processors.query.stat.ObjectPartitionStatisticsImpl in project ignite by apache.
the class GatherPartitionStatistics method fixExisting.
/**
* Fix existing partition statistics, update repo and return resulting partition statistics.
*
* @param partStat Partition statistics to fix.
* @param colsToRemove Columns to remove.
* @return New "fixed" partition statistics or existing, if colsToRemove is empty.
*/
private ObjectPartitionStatisticsImpl fixExisting(ObjectPartitionStatisticsImpl partStat, Set<String> colsToRemove) {
if (log.isDebugEnabled())
log.debug("Existing parititon statistics fit to configuration requirements. " + "Skipping recollection for " + gathCtx.configuration().key() + "[" + partId + "].");
ObjectPartitionStatisticsImpl res;
if (F.isEmpty(colsToRemove))
// No changes - no need to write existing parition back.
res = partStat;
else {
Map<String, ColumnStatistics> allCols = new HashMap<>(partStat.columnsStatistics());
for (String col : colsToRemove) allCols.remove(col);
res = new ObjectPartitionStatisticsImpl(partStat.partId(), getRowCount(allCols), partStat.updCnt(), allCols);
assert !allCols.isEmpty() : "No columns left after fixing existing partition statistics.";
statRepo.replaceLocalPartitionStatistics(gathCtx.configuration().key(), res);
}
return res;
}
use of org.apache.ignite.internal.processors.query.stat.ObjectPartitionStatisticsImpl in project ignite by apache.
the class GatherPartitionStatistics method recollectPartition.
/**
* Collect some statistics, fix existing in repo and return resulting partition statistics.
*
* @param cctx Cache context to get partition from.
* @param partStat Existing partition statistics to fix or use as a base.
* @param colsToCollect Columns to collect.
* @param colsToRemove Columns to remove.
* @return New partition statistics.
*/
private ObjectPartitionStatisticsImpl recollectPartition(GridCacheContext<?, ?> cctx, ObjectPartitionStatisticsImpl partStat, Map<String, StatisticsColumnConfiguration> colsToCollect, Set<String> colsToRemove) {
CacheGroupContext grp = cctx.group();
GridDhtPartitionTopology top = grp.topology();
AffinityTopologyVersion topVer = top.readyTopologyVersion();
GridDhtLocalPartition locPart = top.localPartition(partId, topVer, false);
if (locPart == null)
throw new GatherStatisticCancelException();
boolean reserved = locPart.reserve();
GridH2Table tbl = gathCtx.table();
ObjectPartitionStatisticsImpl res = null;
try {
if (!reserved || (locPart.state() != OWNING)) {
if (log.isDebugEnabled()) {
log.debug("Partition not owning. Need to retry [part=" + partId + ", tbl=" + tbl.identifier() + ']');
}
throw new GatherStatisticCancelException();
}
Column[] cols = IgniteStatisticsHelper.filterColumns(tbl.getColumns(), colsToCollect.keySet());
ColumnStatisticsCollector[] collectors = new ColumnStatisticsCollector[cols.length];
for (int i = 0; i < cols.length; ++i) {
long colCfgVer = colsToCollect.get(cols[i].getName()).version();
collectors[i] = new ColumnStatisticsCollector(cols[i], tbl::compareTypeSafe, colCfgVer);
}
GridH2RowDescriptor rowDesc = tbl.rowDescriptor();
GridQueryTypeDescriptor typeDesc = rowDesc.type();
try {
int checkInt = CANCELLED_CHECK_INTERVAL;
if (log.isDebugEnabled()) {
log.debug("Start partition scan [part=" + partId + ", tbl=" + gathCtx.table().identifier() + ']');
}
for (CacheDataRow row : grp.offheap().cachePartitionIterator(gathCtx.table().cacheId(), partId, null, false)) {
if (--checkInt == 0) {
if (gathCtx.future().isCancelled())
throw new GatherStatisticCancelException();
checkInt = CANCELLED_CHECK_INTERVAL;
}
if (!typeDesc.matchType(row.value()) || wasExpired(row))
continue;
H2Row h2row = rowDesc.createRow(row);
for (ColumnStatisticsCollector colStat : collectors) colStat.add(h2row.getValue(colStat.col().getColumnId()));
}
} catch (IgniteCheckedException e) {
log.warning(String.format("Unable to collect partition level statistics by %s.%s:%d due to %s", tbl.identifier().schema(), tbl.identifier().table(), partId, e.getMessage()));
throw new IgniteException("Unable to collect partition level statistics", e);
}
Map<String, ColumnStatistics> colStats = Arrays.stream(collectors).collect(Collectors.toMap(csc -> csc.col().getName(), ColumnStatisticsCollector::finish));
// Add existing to full replace existing statistics with new one.
if (partStat != null) {
for (Map.Entry<String, ColumnStatistics> oldColStat : partStat.columnsStatistics().entrySet()) {
if (!colsToRemove.contains(oldColStat.getKey()))
colStats.putIfAbsent(oldColStat.getKey(), oldColStat.getValue());
}
}
res = new ObjectPartitionStatisticsImpl(partId, getRowCount(colStats), locPart.updateCounter(), colStats);
} finally {
if (reserved)
locPart.release();
}
statRepo.replaceLocalPartitionStatistics(gathCtx.configuration().key(), res);
if (gathCtx.configuration().columns().size() == colsToCollect.size())
statRepo.refreshObsolescence(gathCtx.configuration().key(), partId);
return res;
}
Aggregations