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