Search in sources :

Example 6 with StatisticsObjectConfiguration

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

the class IgniteStatisticsManagerImpl method processObsolescence.

/**
 * Save dirty obsolescence info to local metastore. Check if statistics need to be refreshed and schedule it.
 *
 * 1) Get all dirty partition statistics.
 * 2) Make separate tasks for each key to avoid saving obsolescence info for removed partition (race).
 * 3) Check if partition should be recollected and add it to list in its tables task.
 * 4) Submit tasks. Actually obsolescence info will be stored during task processing.
 */
public synchronized void processObsolescence() {
    StatisticsUsageState usageState = usageState();
    if (usageState != ON || ctx.isStopping()) {
        if (log.isDebugEnabled())
            log.debug("Skipping obsolescence processing.");
        return;
    }
    if (log.isTraceEnabled())
        log.trace("Process statistics obsolescence started.");
    List<StatisticsKey> keys = statsRepos.getObsolescenceKeys();
    if (F.isEmpty(keys)) {
        if (log.isTraceEnabled())
            log.trace("No obsolescence info found. Finish obsolescence processing.");
        return;
    } else {
        if (log.isTraceEnabled())
            log.trace(String.format("Scheduling obsolescence savings for %d targets", keys.size()));
    }
    for (StatisticsKey key : keys) {
        StatisticsObjectConfiguration cfg = null;
        try {
            cfg = statCfgMgr.config(key);
        } catch (IgniteCheckedException e) {
        // No-op/
        }
        Set<Integer> tasksParts = calculateObsolescencedPartitions(cfg, statsRepos.getObsolescence(key));
        GridH2Table tbl = schemaMgr.dataTable(key.schema(), key.obj());
        if (tbl == null) {
            // Table can be removed earlier, but not already processed. Or somethink goes wrong. Try to reschedule.
            if (log.isDebugEnabled())
                log.debug(String.format("Got obsolescence statistics for unknown table %s", key));
        }
        LocalStatisticsGatheringContext ctx = new LocalStatisticsGatheringContext(true, tbl, cfg, tasksParts, null);
        statProc.updateLocalStatistics(ctx);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Example 7 with StatisticsObjectConfiguration

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

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

the class CommandProcessor method processAnalyzeCommand.

/**
 * Process analyze command.
 *
 * @param cmd Sql analyze command.
 */
private void processAnalyzeCommand(SqlAnalyzeCommand cmd) throws IgniteCheckedException {
    ctx.security().authorize(SecurityPermission.CHANGE_STATISTICS);
    IgniteH2Indexing indexing = (IgniteH2Indexing) ctx.query().getIndexing();
    StatisticsObjectConfiguration[] objCfgs = cmd.configurations().stream().map(t -> {
        if (t.key().schema() == null) {
            StatisticsKey key = new StatisticsKey(cmd.schemaName(), t.key().obj());
            return new StatisticsObjectConfiguration(key, t.columns().values(), t.maxPartitionObsolescencePercent());
        } else
            return t;
    }).toArray(StatisticsObjectConfiguration[]::new);
    indexing.statsManager().collectStatistics(objCfgs);
}
Also used : GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) QueryUtils(org.apache.ignite.internal.processors.query.QueryUtils) GridQueryKillResponse(org.apache.ignite.internal.processors.query.messages.GridQueryKillResponse) SqlCreateUserCommand(org.apache.ignite.internal.sql.command.SqlCreateUserCommand) MvccUtils.txStart(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.txStart) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) Map(java.util.Map) NoOperation(org.h2.command.dml.NoOperation) SqlSetStreamingCommand(org.apache.ignite.internal.sql.command.SqlSetStreamingCommand) GridIoPolicy(org.apache.ignite.internal.managers.communication.GridIoPolicy) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) SqlCreateIndexCommand(org.apache.ignite.internal.sql.command.SqlCreateIndexCommand) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor) QueryField(org.apache.ignite.internal.processors.query.QueryField) CIX2(org.apache.ignite.internal.util.typedef.CIX2) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) Set(java.util.Set) QueryEntityEx(org.apache.ignite.internal.processors.query.QueryEntityEx) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) SqlAnalyzeCommand(org.apache.ignite.internal.sql.command.SqlAnalyzeCommand) DataType(org.h2.value.DataType) SqlRefreshStatitsicsCommand(org.apache.ignite.internal.sql.command.SqlRefreshStatitsicsCommand) PARAM_WRAP_VALUE(org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser.PARAM_WRAP_VALUE) Message(org.apache.ignite.plugin.extensions.communication.Message) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) BulkLoadStreamerWriter(org.apache.ignite.internal.processors.bulkload.BulkLoadStreamerWriter) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteLogger(org.apache.ignite.IgniteLogger) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) SecurityPermission(org.apache.ignite.plugin.security.SecurityPermission) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) LinkedHashMap(java.util.LinkedHashMap) Column(org.h2.table.Column) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSqlAlterTableAddColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlterTableAddColumn) SqlBeginTransactionCommand(org.apache.ignite.internal.sql.command.SqlBeginTransactionCommand) SqlIndexColumn(org.apache.ignite.internal.sql.command.SqlIndexColumn) MvccUtils(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils) SqlKillQueryCommand(org.apache.ignite.internal.sql.command.SqlKillQueryCommand) NestedTxMode(org.apache.ignite.internal.processors.query.NestedTxMode) SqlDropUserCommand(org.apache.ignite.internal.sql.command.SqlDropUserCommand) Value(org.h2.value.Value) ServiceMXBeanImpl(org.apache.ignite.internal.ServiceMXBeanImpl) GridQueryProperty(org.apache.ignite.internal.processors.query.GridQueryProperty) GridSqlCreateIndex(org.apache.ignite.internal.processors.query.h2.sql.GridSqlCreateIndex) GridSqlAlterTableDropColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlterTableDropColumn) BulkLoadParser(org.apache.ignite.internal.processors.bulkload.BulkLoadParser) SqlBulkLoadCommand(org.apache.ignite.internal.sql.command.SqlBulkLoadCommand) GridRunningQueryInfo(org.apache.ignite.internal.processors.query.GridRunningQueryInfo) DropIndex(org.h2.command.ddl.DropIndex) GridSqlDropTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropTable) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridTopic(org.apache.ignite.internal.GridTopic) SqlClientContext(org.apache.ignite.internal.processors.query.SqlClientContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) TransactionsMXBeanImpl(org.apache.ignite.internal.TransactionsMXBeanImpl) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) CacheMode(org.apache.ignite.cache.CacheMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) SqlRollbackTransactionCommand(org.apache.ignite.internal.sql.command.SqlRollbackTransactionCommand) SqlAlterUserCommand(org.apache.ignite.internal.sql.command.SqlAlterUserCommand) DmlBulkLoadDataConverter(org.apache.ignite.internal.processors.query.h2.dml.DmlBulkLoadDataConverter) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) SqlAlterTableCommand(org.apache.ignite.internal.sql.command.SqlAlterTableCommand) IgniteCluster(org.apache.ignite.IgniteCluster) StatisticsTarget(org.apache.ignite.internal.processors.query.stat.StatisticsTarget) CreateTable(org.h2.command.ddl.CreateTable) QueryEntity(org.apache.ignite.cache.QueryEntity) UpdatePlan(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan) SqlCommand(org.apache.ignite.internal.sql.command.SqlCommand) EventType(org.apache.ignite.events.EventType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridSqlStatement(org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement) UUID(java.util.UUID) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Objects(java.util.Objects) SqlKillContinuousQueryCommand(org.apache.ignite.internal.sql.command.SqlKillContinuousQueryCommand) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SqlKillScanQueryCommand(org.apache.ignite.internal.sql.command.SqlKillScanQueryCommand) BulkLoadAckClientParameters(org.apache.ignite.internal.processors.bulkload.BulkLoadAckClientParameters) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) NotNull(org.jetbrains.annotations.NotNull) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) GridSqlColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn) GridQueryKillRequest(org.apache.ignite.internal.processors.query.messages.GridQueryKillRequest) UpdatePlanBuilder(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) QueryMXBeanImpl(org.apache.ignite.internal.QueryMXBeanImpl) SqlCommitTransactionCommand(org.apache.ignite.internal.sql.command.SqlCommitTransactionCommand) MvccUtils.tx(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.tx) HashMap(java.util.HashMap) GridSqlCreateTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlCreateTable) SqlKillServiceCommand(org.apache.ignite.internal.sql.command.SqlKillServiceCommand) IgniteClosureX(org.apache.ignite.internal.util.lang.IgniteClosureX) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) BulkLoadCacheWriter(org.apache.ignite.internal.processors.bulkload.BulkLoadCacheWriter) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration) BulkLoadContextCursor(org.apache.ignite.cache.query.BulkLoadContextCursor) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) QueryIndexType(org.apache.ignite.cache.QueryIndexType) F(org.apache.ignite.internal.util.typedef.F) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) Iterator(java.util.Iterator) SqlKillComputeTaskCommand(org.apache.ignite.internal.sql.command.SqlKillComputeTaskCommand) GridSqlDropIndex(org.apache.ignite.internal.processors.query.h2.sql.GridSqlDropIndex) SqlDropStatisticsCommand(org.apache.ignite.internal.sql.command.SqlDropStatisticsCommand) SqlKillTransactionCommand(org.apache.ignite.internal.sql.command.SqlKillTransactionCommand) MvccUtils.mvccEnabled(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils.mvccEnabled) IgniteQueryErrorCode(org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode) SqlDropIndexCommand(org.apache.ignite.internal.sql.command.SqlDropIndexCommand) Prepared(org.h2.command.Prepared) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) BulkLoadProcessor(org.apache.ignite.internal.processors.bulkload.BulkLoadProcessor) CreateIndex(org.h2.command.ddl.CreateIndex) ComputeMXBeanImpl(org.apache.ignite.internal.ComputeMXBeanImpl) Collections(java.util.Collections) QueryIndex(org.apache.ignite.cache.QueryIndex) DropTable(org.h2.command.ddl.DropTable) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) StatisticsKey(org.apache.ignite.internal.processors.query.stat.StatisticsKey) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration)

Example 9 with StatisticsObjectConfiguration

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

the class StatisticsConfigurationTest method checkClientNode.

/**
 * Start client node and check no store related errors in log.
 *
 * @throws Exception In case of errors.
 */
@Test
public void checkClientNode() throws Exception {
    startGridAndChangeBaseline(0);
    createSmallTable(null);
    IgniteEx client = startClientGrid("cli");
    collectStatistics(SMALL_TARGET);
    sql("delete from small");
    for (int i = 0; i < 1000; i++) sql(String.format("INSERT INTO small(a, b, c) VALUES(%d, %d, %d)", i, i, i % 10));
    StatisticsObjectConfiguration smallCfg = statisticsMgr(0).statisticConfiguration().config(SMALL_KEY);
    statisticsMgr(client).refreshStatistics(SMALL_TARGET);
    Thread.sleep(100);
    StatisticsObjectConfiguration smallCfg2 = statisticsMgr(0).statisticConfiguration().config(SMALL_KEY);
    assertNotSame(smallCfg.columns().get("A").version(), smallCfg2.columns().get("A").version());
    client.cluster().state(ClusterState.INACTIVE);
    client.cluster().state(ClusterState.ACTIVE);
    assertFalse(obsolescenceLsnr.check(TIMEOUT));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) StatisticsObjectConfiguration(org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration) Test(org.junit.Test)

Example 10 with StatisticsObjectConfiguration

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

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