I'm trying to iterate over all cache entities using ScanQuery and iterator (not to pull them from distributed cache to local client at once):
IgniteCache cache = ignite.getOrCreateCache("test2");
ScanQuery<Integer, Person> scan = new ScanQuery<>();
scan.setPageSize(256);
Iterator<Cache.Entry<Integer, Person>> it = cache.query(scan).iterator();
int id;
while(it.hasNext()) {
id = it.next().getValue().getId();
<...>
}
but the code above fails, consuming all memory available. In the same time it works well when I'm trying to get iterator from cache:
IgniteCache cache = ignite.getOrCreateCache("test2");
Iterator<Cache.Entry<Integer, Person>> it = cache.iterator();
int id;
while(it.hasNext()) {
id = it.next().getValue().getId();
<...>
}
Docs state that:
QueryCursor represents query result set and allows for transparent page-by-page iteration. Whenever user starts iterating over the last page, it will automatically request the next page in the background.
So why ignite local node fails when iterating over cache with ScanQuery?
UPD:
- Person is an example name instead of actual class's name. Actual class contain one Integer and 10 String fields.
- Actually I've already set page size to a smaller number - 256 instead of default 1024. Same behavior with default and smaller value
- When I try to use
cache.query(scan).getAll()
things go same way, but I can't use iterator value in while loop, application just became stuck until OOM. Exception msg:
Aug 31, 2018 6:16:15 PM org.apache.ignite.logger.java.JavaLogger error SEVERE: Runtime error caught during grid runnable execution: Socket reader [id=105, name=tcp-disco-sock-reader-#13, nodeId=83e986dc-9fc1-433c- 8953-2a11460376a0] java.lang.OutOfMemoryError: Java heap space
full stacktrace: https://pastebin.com/raw/ZpHnRjx8
Person
look like, how big is that class? What happens if you don't setpageSize
(or set a different value)? (Do you know whatpageSize
does?) What happens if you docache.query(scan).getAll()
? And last but not least, please add the full exception message and stacktrace. – Max Vollmer