Search in sources :

Example 1 with QueryResultSizeExceededException

use of com.hazelcast.map.QueryResultSizeExceededException in project hazelcast by hazelcast.

the class QueryResult method add.

public void add(QueryableEntry entry, Projection projection, SerializationService serializationService) {
    if (++resultSize > resultLimit) {
        throw new QueryResultSizeExceededException();
    }
    Data key = null;
    Data value = null;
    switch(iterationType) {
        case KEY:
            key = entry.getKeyData();
            break;
        case VALUE:
            value = getValueData(entry, projection, serializationService);
            break;
        case ENTRY:
            key = entry.getKeyData();
            value = entry.getValueData();
            break;
        default:
            throw new IllegalStateException("Unknown iterationtype:" + iterationType);
    }
    rows.add(new QueryResultRow(key, value));
}
Also used : Data(com.hazelcast.nio.serialization.Data) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException)

Example 2 with QueryResultSizeExceededException

use of com.hazelcast.map.QueryResultSizeExceededException in project hazelcast by hazelcast.

the class AbstractMapQueryMessageTask method collectResults.

@SuppressWarnings("unchecked")
private PartitionIdSet collectResults(Collection<AccumulatedResults> result, List<Future> futures, int partitionCount) {
    PartitionIdSet finishedPartitions = new PartitionIdSet(partitionCount);
    for (Future future : futures) {
        try {
            QueryResult queryResult = (QueryResult) future.get();
            if (queryResult != null) {
                PartitionIdSet partitionIds = queryResult.getPartitionIds();
                if (partitionIds != null && !partitionIds.intersects(finishedPartitions)) {
                    // Collect results only if there is no overlap with already collected partitions.
                    // If there is an overlap it means there was a partition migration while QueryOperation(s) were
                    // running. In this case we discard all results from this member and will target the missing
                    // partition separately later.
                    finishedPartitions.union(partitionIds);
                    extractAndAppendResult(result, queryResult);
                }
            }
        } catch (Throwable t) {
            if (t.getCause() instanceof QueryResultSizeExceededException) {
                throw rethrow(t);
            } else {
                // the missing partition IDs will be queried anyway, so it's not a terminal failure
                if (logger.isFineEnabled()) {
                    logger.fine("Query on member failed with exception", t);
                }
            }
        }
    }
    return finishedPartitions;
}
Also used : PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) Future(java.util.concurrent.Future) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException)

Example 3 with QueryResultSizeExceededException

use of com.hazelcast.map.QueryResultSizeExceededException in project hazelcast by hazelcast.

the class AbstractMapQueryMessageTask method createInvocations.

private List<Future> createInvocations(Collection<Member> members, Predicate predicate) {
    List<Future> futures = new ArrayList<>(members.size());
    final OperationServiceImpl operationService = nodeEngine.getOperationService();
    final Query query = buildQuery(predicate);
    MapService mapService = nodeEngine.getService(getServiceName());
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    for (Member member : members) {
        try {
            Future future = operationService.createInvocationBuilder(SERVICE_NAME, createQueryOperation(query, mapServiceContext), member.getAddress()).invoke();
            futures.add(future);
        } catch (Throwable t) {
            if (!(t instanceof HazelcastException)) {
                // these are programmatic errors that needs to be visible
                throw rethrow(t);
            } else if (t.getCause() instanceof QueryResultSizeExceededException) {
                throw rethrow(t);
            } else {
                // the missing partition IDs will be queried anyway, so it's not a terminal failure
                if (logger.isFineEnabled()) {
                    logger.fine("Query invocation failed on member " + member, t);
                }
            }
        }
    }
    return futures;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Query(com.hazelcast.map.impl.query.Query) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) MapService(com.hazelcast.map.impl.MapService) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException) Member(com.hazelcast.cluster.Member) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 4 with QueryResultSizeExceededException

use of com.hazelcast.map.QueryResultSizeExceededException in project hazelcast by hazelcast.

the class QueryResultSizeExceededExceptionTest method testStringConstructor.

@Test
public void testStringConstructor() throws Exception {
    QueryResultSizeExceededException exception = new QueryResultSizeExceededException();
    String expectedMessage = exception.getMessage();
    // invoke the constructor like in ClientInvocationServiceSupport.handleClientMessage()
    Class<?> causeClazz = Class.forName(QueryResultSizeExceededException.class.getName());
    Constructor<?> causeConstructor = causeClazz.getDeclaredConstructor(String.class);
    causeConstructor.setAccessible(true);
    Throwable actual = (Throwable) causeConstructor.newInstance(expectedMessage);
    assertEquals(expectedMessage, actual.getMessage());
}
Also used : QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with QueryResultSizeExceededException

use of com.hazelcast.map.QueryResultSizeExceededException in project hazelcast by hazelcast.

the class ClientMapUnboundReturnValuesTestSupport method internalRunTxn.

/**
 * Calls {@link TransactionalMap} methods once which are expected to throw {@link QueryResultSizeExceededException}.
 * <p/>
 * This method requires the map to be filled to an amount where the exception is safely triggered.
 * <p/>
 * This methods fails if any of the called methods does not trigger the exception.
 */
private void internalRunTxn(String mapName) {
    TransactionContext transactionContext = instance.newTransactionContext();
    try {
        transactionContext.beginTransaction();
        TransactionalMap<Object, Integer> txnMap = transactionContext.getMap(mapName);
        try {
            txnMap.values(Predicates.alwaysTrue());
            failExpectedException("TransactionalMap.values(predicate)");
        } catch (QueryResultSizeExceededException e) {
            checkException(e);
        }
        try {
            txnMap.keySet(Predicates.alwaysTrue());
            failExpectedException("TransactionalMap.keySet(predicate)");
        } catch (QueryResultSizeExceededException e) {
            checkException(e);
        }
        try {
            txnMap.values();
            failExpectedException("TransactionalMap.values()");
        } catch (QueryResultSizeExceededException e) {
            checkException(e);
        }
        try {
            txnMap.keySet();
            failExpectedException("TransactionalMap.keySet()");
        } catch (QueryResultSizeExceededException e) {
            checkException(e);
        }
    } finally {
        transactionContext.rollbackTransaction();
    }
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) QueryResultSizeExceededException(com.hazelcast.map.QueryResultSizeExceededException)

Aggregations

QueryResultSizeExceededException (com.hazelcast.map.QueryResultSizeExceededException)7 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)3 Future (java.util.concurrent.Future)2 Member (com.hazelcast.cluster.Member)1 HazelcastException (com.hazelcast.core.HazelcastException)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 Query (com.hazelcast.map.impl.query.Query)1 Data (com.hazelcast.nio.serialization.Data)1 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 TransactionContext (com.hazelcast.transaction.TransactionContext)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1