Search in sources :

Example 31 with QueryCursor

use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.

the class GridQueryProcessor method queryLocalSql.

/**
     * @param cctx Cache context.
     * @param qry Query.
     * @param keepBinary Keep binary flag.
     * @return Cursor.
     */
private <K, V> QueryCursor<Cache.Entry<K, V>> queryLocalSql(final GridCacheContext<?, ?> cctx, final SqlQuery qry, final boolean keepBinary) {
    if (!busyLock.enterBusy())
        throw new IllegalStateException("Failed to execute query (grid is stopping).");
    final String schemaName = idx.schema(cctx.name());
    final int mainCacheId = CU.cacheId(cctx.name());
    try {
        return executeQuery(GridCacheQueryType.SQL, qry.getSql(), cctx, new IgniteOutClosureX<QueryCursor<Cache.Entry<K, V>>>() {

            @Override
            public QueryCursor<Cache.Entry<K, V>> applyx() throws IgniteCheckedException {
                String type = qry.getType();
                String typeName = typeName(cctx.name(), type);
                qry.setType(typeName);
                sendQueryExecutedEvent(qry.getSql(), qry.getArgs(), cctx.name());
                if (cctx.config().getQueryParallelism() > 1) {
                    qry.setDistributedJoins(true);
                    return idx.queryDistributedSql(schemaName, qry, keepBinary, mainCacheId);
                } else
                    return idx.queryLocalSql(schemaName, qry, idx.backupFilter(requestTopVer.get(), qry.getPartitions()), keepBinary);
            }
        }, true);
    } catch (IgniteCheckedException e) {
        throw new CacheException(e);
    } finally {
        busyLock.leaveBusy();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) QueryCursor(org.apache.ignite.cache.query.QueryCursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) Cache(javax.cache.Cache)

Example 32 with QueryCursor

use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.

the class IgniteCacheContinuousQueryBackupQueueTest method testManyQueryBackupQueue.

/**
     * @throws Exception If failed.
     */
public void testManyQueryBackupQueue() throws Exception {
    List<QueryCursor> qryCursors = new ArrayList<>();
    for (int i = 0; i < QUERY_COUNT; i++) {
        ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
        qry.setLocalListener(new CacheEventListener());
        qry.setRemoteFilterFactory(new AlwaysFalseFilterFactory());
        qryCursors.add(grid(0).cache(CACHE_NAME).query(qry));
    }
    for (int i = 0; i < KEYS_COUNT; i++) {
        log.info("Put key: " + i);
        for (int j = 0; j < 150; j++) grid(ThreadLocalRandom.current().nextInt(GRID_COUNT)).cache(CACHE_NAME).put(i, new byte[1024 * 50]);
    }
    int size = backupQueueSize();
    assertTrue(size > 0);
    assertTrue(size <= BACKUP_ACK_THRESHOLD * QUERY_COUNT * /* partition count */
    1024);
    for (QueryCursor qry : qryCursors) qry.close();
}
Also used : ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) ArrayList(java.util.ArrayList) QueryCursor(org.apache.ignite.cache.query.QueryCursor)

Example 33 with QueryCursor

use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.

the class IgniteCacheContinuousQueryBackupQueueTest method testBackupQueueAutoUnsubscribeFalse.

/**
     * @throws Exception If failed.
     */
public void testBackupQueueAutoUnsubscribeFalse() throws Exception {
    try {
        client = true;
        Ignite client = startGrid(GRID_COUNT);
        awaitPartitionMapExchange();
        List<QueryCursor> qryCursors = new ArrayList<>();
        for (int i = 0; i < QUERY_COUNT; i++) {
            ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
            qry.setLocalListener(new CacheEventListener());
            qry.setRemoteFilterFactory(new AlwaysFalseFilterFactory());
            qry.setAutoUnsubscribe(false);
            qryCursors.add(client.cache(CACHE_NAME).query(qry));
        }
        for (int i = 0; i < KEYS_COUNT; i++) {
            log.info("Put key: " + i);
            grid(i % GRID_COUNT).cache(CACHE_NAME).put(i, new byte[1024 * 50]);
        }
        int size = backupQueueSize();
        assertTrue(size > 0);
        assertTrue(size <= BACKUP_ACK_THRESHOLD * QUERY_COUNT * /* partition count */
        1024);
        stopGrid(GRID_COUNT);
        awaitPartitionMapExchange();
        for (int i = 0; i < KEYS_COUNT; i++) {
            log.info("Put key: " + i);
            grid(i % GRID_COUNT).cache(CACHE_NAME).put(i, new byte[1024 * 50]);
        }
        size = backupQueueSize();
        assertEquals(-1, size);
    } finally {
        stopGrid(GRID_COUNT);
    }
}
Also used : ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite) QueryCursor(org.apache.ignite.cache.query.QueryCursor)

Example 34 with QueryCursor

use of org.apache.ignite.cache.query.QueryCursor in project ignite by apache.

the class IgniteCacheRandomOperationBenchmark method doSqlQuery.

/**
     * @param cache Ignite cache.
     * @throws Exception If failed.
     */
private void doSqlQuery(IgniteCache<Object, Object> cache) throws Exception {
    List<SqlCacheDescriptor> descriptors = cacheSqlDescriptors.get(cache.getName());
    if (descriptors != null) {
        Query sq = null;
        if (queries.isEmpty()) {
            if (!descriptors.isEmpty()) {
                SqlCacheDescriptor randomDesc = descriptors.get(nextRandom(descriptors.size()));
                int id = nextRandom(args.range());
                sq = nextBoolean() ? randomDesc.getSqlQuery(id) : randomDesc.getSqlFieldsQuery(id);
            }
        } else {
            TestQuery qry = queries.get(nextRandom(queries.size()));
            String sql = randomizeSql(qry.sql);
            sq = new SqlFieldsQuery(sql);
            ((SqlFieldsQuery) sq).setDistributedJoins(qry.distributedJoin);
        }
        if (sq != null)
            try (QueryCursor cursor = cache.query(sq)) {
                for (Object obj : cursor) {
                // No-op.
                }
            }
    }
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SqlQuery(org.apache.ignite.cache.query.SqlQuery) ScanQuery(org.apache.ignite.cache.query.ScanQuery) Query(org.apache.ignite.cache.query.Query) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor)

Aggregations

QueryCursor (org.apache.ignite.cache.query.QueryCursor)34 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)20 IgniteCache (org.apache.ignite.IgniteCache)16 Ignite (org.apache.ignite.Ignite)14 Cache (javax.cache.Cache)13 ArrayList (java.util.ArrayList)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgniteException (org.apache.ignite.IgniteException)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 CacheEntryEvent (javax.cache.event.CacheEntryEvent)8 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)7 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 CacheException (javax.cache.CacheException)6 CacheEntryUpdatedListener (javax.cache.event.CacheEntryUpdatedListener)6 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)6 SqlQuery (org.apache.ignite.cache.query.SqlQuery)6 ScanQuery (org.apache.ignite.cache.query.ScanQuery)5 PA (org.apache.ignite.internal.util.typedef.PA)5 EntryProcessorException (javax.cache.processor.EntryProcessorException)4