Search in sources :

Example 1 with StatisticsObjectConfiguration

use of org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration 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 StatisticsObjectConfiguration

use of org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration in project ignite by apache.

the class IgniteStatisticsConfigurationManager method updateAllLocalStatistics.

/**
 * Scan statistics configuration and update each key it contains.
 */
public void updateAllLocalStatistics() {
    try {
        distrMetaStorage.iterate(STAT_OBJ_PREFIX, (k, v) -> {
            StatisticsObjectConfiguration cfg = (StatisticsObjectConfiguration) v;
            updateLocalStatistics(cfg);
        });
    } catch (IgniteCheckedException e) {
        log.warning("Unexpected statistics configuration processing error", e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Example 3 with StatisticsObjectConfiguration

use of org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration in project ignite by apache.

the class IgniteStatisticsConfigurationManager method dropAll.

/**
 * Drop all local statistics on the cluster.
 */
public void dropAll() {
    try {
        final List<StatisticsTarget> targetsToRemove = new ArrayList<>();
        distrMetaStorage.iterate(STAT_OBJ_PREFIX, (k, v) -> {
            StatisticsKey statKey = ((StatisticsObjectConfiguration) v).key();
            StatisticsObjectConfiguration cfg = (StatisticsObjectConfiguration) v;
            if (!F.isEmpty(cfg.columns()))
                targetsToRemove.add(new StatisticsTarget(statKey, null));
        });
        dropStatistics(targetsToRemove, false);
    } catch (IgniteCheckedException e) {
        throw new IgniteSQLException("Unexpected exception drop all statistics", IgniteQueryErrorCode.UNKNOWN, e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ArrayList(java.util.ArrayList) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Example 4 with StatisticsObjectConfiguration

use of org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration 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 5 with StatisticsObjectConfiguration

use of org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration in project ignite by apache.

the class IgniteStatisticsConfigurationManager method dropStatistics.

/**
 * Drop local statistic for specified database objects on the cluster.
 * Remove local aggregated and partitioned statistics that are stored at the local metastorage.
 *
 * @param targets DB objects to update statistics by.
 * @param validate if {@code true} - validate statistics existence, otherwise - just try to remove.
 */
public void dropStatistics(List<StatisticsTarget> targets, boolean validate) {
    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);
                if (validate)
                    validateDropRefresh(target, oldCfg);
                if (oldCfg == null)
                    return;
                Set<String> dropColNames = (target.columns() == null) ? Collections.emptySet() : Arrays.stream(target.columns()).collect(Collectors.toSet());
                StatisticsObjectConfiguration newCfg = oldCfg.dropColumns(dropColNames);
                if (oldCfg.equals(newCfg))
                    break;
                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) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Aggregations

StatisticsObjectConfiguration (org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 ArrayList (java.util.ArrayList)6 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)6 StatisticsColumnConfiguration (org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnConfiguration)6 Collections (java.util.Collections)4 List (java.util.List)4 Set (java.util.Set)4 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)4 F (org.apache.ignite.internal.util.typedef.F)4 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 IgniteLogger (org.apache.ignite.IgniteLogger)3 QueryUtils (org.apache.ignite.internal.processors.query.QueryUtils)3 Collection (java.util.Collection)2 UUID (java.util.UUID)2