use of org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration in project ignite by apache.
the class IgniteStatisticsConfigurationManager method refreshStatistics.
/**
* Refresh local statistic for specified database objects on the cluster.
*
* @param targets DB objects to statistics update.
*/
public void refreshStatistics(List<StatisticsTarget> targets) {
if (log.isDebugEnabled())
log.debug("Drop statistics [targets=" + targets + ']');
for (StatisticsTarget target : targets) {
String key = key2String(target.key());
try {
while (true) {
StatisticsObjectConfiguration oldCfg = distrMetaStorage.read(key);
validateDropRefresh(target, oldCfg);
Set<String> cols;
if (F.isEmpty(target.columns())) {
cols = oldCfg.columns().values().stream().map(StatisticsColumnConfiguration::name).collect(Collectors.toSet());
} else
cols = Arrays.stream(target.columns()).collect(Collectors.toSet());
StatisticsObjectConfiguration newCfg = oldCfg.refresh(cols);
if (distrMetaStorage.compareAndSet(key, oldCfg, newCfg))
break;
}
} catch (IgniteCheckedException ex) {
throw new IgniteSQLException("Error on get or update statistic schema", IgniteQueryErrorCode.UNKNOWN, ex);
}
}
}
use of org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration in project ignite by apache.
the class IgniteStatisticsConfigurationManager method updateStatistics.
/**
* Update local statistic for specified database objects on the cluster.
* Each node will scan local primary partitions to collect and update local statistic.
*
* @param targets DB objects to statistics update.
*/
public void updateStatistics(StatisticsObjectConfiguration... targets) {
if (log.isDebugEnabled())
log.debug("Update statistics [targets=" + targets + ']');
for (StatisticsObjectConfiguration target : targets) {
GridH2Table tbl = schemaMgr.dataTable(target.key().schema(), target.key().obj());
validate(target, tbl);
List<StatisticsColumnConfiguration> colCfgs;
if (F.isEmpty(target.columns()))
colCfgs = Arrays.stream(tbl.getColumns()).filter(c -> c.getColumnId() >= QueryUtils.DEFAULT_COLUMNS_COUNT).map(c -> new StatisticsColumnConfiguration(c.getName(), null)).collect(Collectors.toList());
else
colCfgs = new ArrayList<>(target.columns().values());
StatisticsObjectConfiguration newCfg = new StatisticsObjectConfiguration(target.key(), colCfgs, target.maxPartitionObsolescencePercent());
try {
while (true) {
String key = key2String(newCfg.key());
StatisticsObjectConfiguration oldCfg = distrMetaStorage.read(key);
StatisticsObjectConfiguration resultCfg = (oldCfg == null) ? newCfg : StatisticsObjectConfiguration.merge(oldCfg, newCfg);
if (distrMetaStorage.compareAndSet(key, oldCfg, resultCfg))
break;
}
} catch (IgniteCheckedException ex) {
throw new IgniteSQLException("Error on get or update statistic schema", IgniteQueryErrorCode.UNKNOWN, ex);
}
}
}
use of org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration 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.config.StatisticsColumnConfiguration in project ignite by apache.
the class ColumnConfigurationViewSupplier method columnConfigurationViewSupplier.
/**
* Statistics column configuration view filterable supplier.
*
* @param filter Filter.
* @return Iterable with selected statistics column configuration views.
*/
public Iterable<StatisticsColumnConfigurationView> columnConfigurationViewSupplier(Map<String, Object> filter) {
String schema = (String) filter.get(StatisticsColumnConfigurationViewWalker.SCHEMA_FILTER);
String name = (String) filter.get(StatisticsColumnConfigurationViewWalker.NAME_FILTER);
Collection<StatisticsObjectConfiguration> configs;
try {
if (!F.isEmpty(schema) && !F.isEmpty(name)) {
StatisticsKey key = new StatisticsKey(schema, name);
StatisticsObjectConfiguration keyCfg = cfgMgr.config(key);
if (keyCfg == null)
return Collections.emptyList();
configs = Collections.singletonList(keyCfg);
} else
configs = cfgMgr.getAllConfig();
} catch (IgniteCheckedException e) {
log.warning("Error while getting statistics configuration: " + e.getMessage(), e);
configs = Collections.emptyList();
}
List<StatisticsColumnConfigurationView> res = new ArrayList<>();
for (StatisticsObjectConfiguration cfg : configs) {
for (StatisticsColumnConfiguration colCfg : cfg.columnsAll().values()) {
if (!colCfg.tombstone())
res.add(new StatisticsColumnConfigurationView(cfg, colCfg));
}
}
return res;
}
use of org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration in project ignite by apache.
the class SqlAnalyzeCommand method buildConfig.
/**
* Build statistics object configuration from command arguments.
*
* @param target Statistics target.
* @param params Map of parameter to value strings.
* @return Statistics object configuration.
* @throws IgniteSQLException In case of unexpected parameter.
*/
public StatisticsObjectConfiguration buildConfig(StatisticsTarget target, Map<String, String> params) throws IgniteSQLException {
byte maxChangedRows = getByteOrDefault(params, MAX_CHANGED_PARTITION_ROWS_PERCENT, StatisticsObjectConfiguration.DEFAULT_OBSOLESCENCE_MAX_PERCENT);
StatisticsColumnOverrides overrides = overrides(params);
if (!F.isEmpty(params))
throw new IgniteSQLException("");
List<StatisticsColumnConfiguration> colCfgs = (target.columns() == null) ? Collections.emptyList() : Arrays.stream(target.columns()).map(col -> new StatisticsColumnConfiguration(col, overrides)).collect(Collectors.toList());
return new StatisticsObjectConfiguration(target.key(), colCfgs, maxChangedRows);
}
Aggregations