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();
}
}
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();
}
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);
}
}
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.
}
}
}
}
Aggregations