Search in sources :

Example 1 with StatisticsColumnConfiguration

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);
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Example 2 with StatisticsColumnConfiguration

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);
        }
    }
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) Arrays(java.util.Arrays) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) QueryUtils(org.apache.ignite.internal.processors.query.QueryUtils) DistributedMetastorageLifecycleListener(org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) ClusterState(org.apache.ignite.cluster.ClusterState) IgniteLogger(org.apache.ignite.IgniteLogger) StatisticsColumnConfigurationViewWalker(org.apache.ignite.internal.managers.systemview.walker.StatisticsColumnConfigurationViewWalker) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) GridSystemViewManager(org.apache.ignite.internal.managers.systemview.GridSystemViewManager) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration) X(org.apache.ignite.internal.util.typedef.X) BiConsumer(java.util.function.BiConsumer) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) SchemaManager(org.apache.ignite.internal.processors.query.h2.SchemaManager) F(org.apache.ignite.internal.util.typedef.F) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ColumnConfigurationViewSupplier(org.apache.ignite.internal.processors.query.stat.view.ColumnConfigurationViewSupplier) Set(java.util.Set) IgniteQueryErrorCode(org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode) Collectors(java.util.stream.Collectors) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) List(java.util.List) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) GridClusterStateProcessor(org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) ArrayList(java.util.ArrayList) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Example 3 with StatisticsColumnConfiguration

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);
}
Also used : ObjectPartitionStatisticsImpl(org.apache.ignite.internal.processors.query.stat.ObjectPartitionStatisticsImpl) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration)

Example 4 with StatisticsColumnConfiguration

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;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) ArrayList(java.util.ArrayList) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Example 5 with StatisticsColumnConfiguration

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);
}
Also used : StatisticsColumnOverrides(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnOverrides) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) StatisticsColumnConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Aggregations

StatisticsColumnConfiguration (org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration)10 StatisticsObjectConfiguration (org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)6 ArrayList (java.util.ArrayList)5 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 F (org.apache.ignite.internal.util.typedef.F)4 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Function (java.util.function.Function)3 IgniteLogger (org.apache.ignite.IgniteLogger)3 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)3 Column (org.h2.table.Column)3 Collection (java.util.Collection)2 IgniteException (org.apache.ignite.IgniteException)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2