Search in sources :

Example 36 with Merge

use of org.h2.command.dml.Merge in project ignite by apache.

the class ValidateIndexesClosure method checkSizes.

/**
 * Checking size of records in cache and indexes with a record into
 * {@code checkSizeRes} if they are not equal.
 *
 * @param cacheSizesFutures Futures calculating size of records in caches.
 * @param idxSizeFutures Futures calculating size of indexes of caches.
 * @param checkSizeRes Result of size check.
 */
private void checkSizes(List<T3<CacheGroupContext, GridDhtLocalPartition, Future<CacheSize>>> cacheSizesFutures, List<T3<GridCacheContext, Index, Future<T2<Throwable, Long>>>> idxSizeFutures, Map<String, ValidateIndexesCheckSizeResult> checkSizeRes) throws ExecutionException, InterruptedException {
    if (!checkSizes)
        return;
    Map<Integer, CacheSize> cacheSizeTotal = new HashMap<>();
    for (T3<CacheGroupContext, GridDhtLocalPartition, Future<CacheSize>> cacheSizeFut : cacheSizesFutures) {
        CacheGroupContext cacheGrpCtx = cacheSizeFut.get1();
        CacheSize cacheSize = cacheSizeFut.get3().get();
        Throwable cacheSizeErr = cacheSize.err;
        int grpId = cacheGrpCtx.groupId();
        if (failCalcCacheSizeGrpIds.contains(grpId) && nonNull(cacheSizeErr)) {
            checkSizeRes.computeIfAbsent(cacheGrpInfo(cacheGrpCtx), s -> new ValidateIndexesCheckSizeResult(0, new ArrayList<>())).issues().add(new ValidateIndexesCheckSizeIssue(null, 0, cacheSizeErr));
        } else {
            cacheSizeTotal.computeIfAbsent(grpId, i -> new CacheSize(null, new HashMap<>())).merge(cacheSize.cacheSizePerTbl);
        }
    }
    for (T3<GridCacheContext, Index, Future<T2<Throwable, Long>>> idxSizeFut : idxSizeFutures) {
        GridCacheContext cacheCtx = idxSizeFut.get1();
        int grpId = cacheCtx.groupId();
        if (failCalcCacheSizeGrpIds.contains(grpId))
            continue;
        Index idx = idxSizeFut.get2();
        String tblName = idx.getTable().getName();
        AtomicLong cacheSizeObj = cacheSizeTotal.get(grpId).cacheSizePerTbl.getOrDefault(cacheCtx.cacheId(), emptyMap()).get(tblName);
        long cacheSizeByTbl = isNull(cacheSizeObj) ? 0L : cacheSizeObj.get();
        T2<Throwable, Long> idxSizeRes = idxSizeFut.get3().get();
        Throwable err = idxSizeRes.get1();
        long idxSize = idxSizeRes.get2();
        if (isNull(err) && idxSize != cacheSizeByTbl)
            err = new IgniteException("Cache and index size not same.");
        if (nonNull(err)) {
            checkSizeRes.computeIfAbsent("[" + cacheGrpInfo(cacheCtx.group()) + ", " + cacheInfo(cacheCtx) + ", tableName=" + tblName + "]", s -> new ValidateIndexesCheckSizeResult(cacheSizeByTbl, new ArrayList<>())).issues().add(new ValidateIndexesCheckSizeIssue(idx.getName(), idxSize, err));
        }
    }
}
Also used : Collections.shuffle(java.util.Collections.shuffle) IgniteEx(org.apache.ignite.internal.IgniteEx) DbException(org.h2.message.DbException) H2Utils(org.apache.ignite.internal.processors.query.h2.H2Utils) Index(org.h2.index.Index) IdleVerifyUtility.checkPartitionsPageCrcSum(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.checkPartitionsPageCrcSum) ConnectionManager(org.apache.ignite.internal.processors.query.h2.ConnectionManager) Future(java.util.concurrent.Future) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) BPlusTree(org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree) JdbcConnection(org.h2.jdbc.JdbcConnection) Objects.isNull(java.util.Objects.isNull) LoggerResource(org.apache.ignite.resources.LoggerResource) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridNotIdleException(org.apache.ignite.internal.processors.cache.verify.GridNotIdleException) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Executors(java.util.concurrent.Executors) GRID_NOT_IDLE_MSG(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.GRID_NOT_IDLE_MSG) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) Cursor(org.h2.index.Cursor) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Entry(java.util.Map.Entry) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Objects.nonNull(java.util.Objects.nonNull) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) CacheObjectUtils(org.apache.ignite.internal.processors.cache.CacheObjectUtils) PartitionKey(org.apache.ignite.internal.processors.cache.verify.PartitionKey) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) IgniteLogger(org.apache.ignite.IgniteLogger) CorruptedTreeException(org.apache.ignite.internal.processors.cache.persistence.tree.CorruptedTreeException) Supplier(java.util.function.Supplier) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteCallable(org.apache.ignite.lang.IgniteCallable) HashSet(java.util.HashSet) IdleVerifyUtility.formatUpdateCountersDiff(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.formatUpdateCountersDiff) Session(org.h2.engine.Session) Collections.newSetFromMap(java.util.Collections.newSetFromMap) IdleVerifyUtility.compareUpdateCounters(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.compareUpdateCounters) MvccUtils(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IdleVerifyUtility.getUpdateCountersSnapshot(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility.getUpdateCountersSnapshot) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) IdleVerifyUtility(org.apache.ignite.internal.processors.cache.verify.IdleVerifyUtility) ExecutorService(java.util.concurrent.ExecutorService) F(org.apache.ignite.internal.util.typedef.F) Collections.emptyMap(java.util.Collections.emptyMap) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) H2TreeIndexBase(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) T3(org.apache.ignite.internal.util.typedef.T3) GridIterator(org.apache.ignite.internal.util.lang.GridIterator) T2(org.apache.ignite.internal.util.typedef.T2) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) H2CacheRow(org.apache.ignite.internal.processors.query.h2.opt.H2CacheRow) Collections(java.util.Collections) MvccQueryTracker(org.apache.ignite.internal.processors.cache.mvcc.MvccQueryTracker) QueryContext(org.apache.ignite.internal.processors.query.h2.opt.QueryContext) IgniteUtils.error(org.apache.ignite.internal.util.IgniteUtils.error) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Index(org.h2.index.Index) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteException(org.apache.ignite.IgniteException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Future(java.util.concurrent.Future) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 37 with Merge

use of org.h2.command.dml.Merge in project ignite by apache.

the class GridSqlQueryParser method parseMerge.

/**
 * @param merge Merge.
 * @see <a href="http://h2database.com/html/grammar.html#merge">H2 merge spec</a>
 */
private GridSqlMerge parseMerge(Merge merge) {
    GridSqlMerge res = (GridSqlMerge) h2ObjToGridObj.get(merge);
    if (res != null)
        return res;
    res = new GridSqlMerge();
    h2ObjToGridObj.put(merge, res);
    Table srcTbl = MERGE_TABLE.get(merge);
    GridSqlElement tbl = parseTable(srcTbl);
    res.into(tbl);
    Column[] srcCols = MERGE_COLUMNS.get(merge);
    GridSqlColumn[] cols = new GridSqlColumn[srcCols.length];
    for (int i = 0; i < srcCols.length; i++) {
        cols[i] = new GridSqlColumn(srcCols[i], tbl, null, null, srcCols[i].getName());
        cols[i].resultType(fromColumn(srcCols[i]));
    }
    res.columns(cols);
    if (!F.isEmpty(MERGE_KEYS.get(merge))) {
        log.warning("The search row by explicit KEY isn't supported. The primary key is always used to search row " + "[sql=" + merge.getSQL() + ']');
    }
    List<Expression[]> srcRows = MERGE_ROWS.get(merge);
    if (!srcRows.isEmpty()) {
        List<GridSqlElement[]> rows = new ArrayList<>(srcRows.size());
        for (Expression[] srcRow : srcRows) {
            GridSqlElement[] row = new GridSqlElement[srcRow.length];
            for (int i = 0; i < srcRow.length; i++) {
                row[i] = parseExpression(srcRow[i], false);
                if (row[i] == null) {
                    throw new IgniteSQLException("Explicit DEFAULT values are unsupported for MERGE.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
                }
            }
            rows.add(row);
        }
        res.rows(rows);
    } else {
        res.rows(Collections.emptyList());
        res.query(parseQuery(MERGE_QUERY.get(merge)));
    }
    return res;
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) RangeTable(org.h2.table.RangeTable) MetaTable(org.h2.table.MetaTable) CreateTable(org.h2.command.ddl.CreateTable) FunctionTable(org.h2.table.FunctionTable) Table(org.h2.table.Table) DropTable(org.h2.command.ddl.DropTable) ArrayList(java.util.ArrayList) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) GridSqlType.fromColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) IndexColumn(org.h2.table.IndexColumn) Expression(org.h2.expression.Expression) GridSqlType.fromExpression(org.apache.ignite.internal.processors.query.h2.sql.GridSqlType.fromExpression) ValueExpression(org.h2.expression.ValueExpression) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Aggregations

Column (org.h2.table.Column)13 PreparedStatement (java.sql.PreparedStatement)9 ArrayList (java.util.ArrayList)9 Expression (org.h2.expression.Expression)8 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)7 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 Statement (java.sql.Statement)6 Connection (java.sql.Connection)5 List (java.util.List)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)5 HashMap (java.util.HashMap)4 IgniteException (org.apache.ignite.IgniteException)4 ValueExpression (org.h2.expression.ValueExpression)4 DbException (org.h2.message.DbException)4 ValueString (org.h2.value.ValueString)4 LinkedHashMap (java.util.LinkedHashMap)3 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)3 GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)3