[
https://issues.apache.org/jira/browse/IGNITE-16158?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Maksim Timonin updated IGNITE-16158:
------------------------------------
Description:
```
IgniteCache<Long, Person> cache = crd.createCache("CACHE");
try (IgniteDataStreamer<Long, Person> streamer =
ignite.dataStreamer(cache.getName()))
{ for (int i = 0; i < CNT; i++) streamer.addData((long)i, new
Person(i)); }
IndexQuery<Long, Person> qry = new IndexQuery<Long, Person>(Person.class, IDX)
.setCriteria(lt("id", CNT / 2));
QueryCursor cursor = cache.query(qry);
cursor.close();
}
```
QueryCursor holds a future that will be completed with iterator over result
data.
Starting a query spawns a new thread locally that query cache in background,
prepares data, and it completes the future with iterator. All affected nodes
run such threads.
But cancelling of query with `QueryCursor.close` doesn't cancel query, and it
will prepare data that will never request. Also cancelling of query doesn't
clean up iterator.
For local query this issue doesn't lead to any memory leaks, and the future and
the iterator will be cleaned up by GC later. But actually we can help to GC by
avoiding preparing the data and by explicit cleaning of those structures.
But for remote queries those structures spends memory. And closing of cursor
has to cancel them.
was:
```
IgniteCache<Long, Person> cache = crd.createCache("CACHE");
try (IgniteDataStreamer<Long, Person> streamer =
ignite.dataStreamer(cache.getName()))
{ for (int i = 0; i < CNT; i++) streamer.addData((long)i, new
Person(i)); }
IndexQuery<Long, Person> qry = new IndexQuery<Long, Person>(Person.class, IDX)
.setCriteria(lt("id", CNT / 2));
QueryCursor cursor = cache.query(qry.setLocal(true));
cursor.close();
}
```
QueryCursor holds a future that will be completed with iterator over result
data.
Starting a query spawns a new thread that query cache in background, prepares
data, and it completes the future with iterator.
But cancelling of query with `QueryCursor.close` doesn't stops the background
thread, and it will prepare data that will never request. Also cancelling of
query doesn't clean up iterator. Cancellation is also invoked after cursor
reaches specified query limit.
This issue doesn't lead to any memory leaks, and the future and the iterator
will be cleaned up by GC later. But actually we can help to GC by avoiding
preparing the data and by explicit cleaning of those structures.
> QueryCursor.close CacheQuery doesn't cancel query
> -------------------------------------------------
>
> Key: IGNITE-16158
> URL: https://issues.apache.org/jira/browse/IGNITE-16158
> Project: Ignite
> Issue Type: New Feature
> Reporter: Maksim Timonin
> Priority: Minor
>
> ```
> IgniteCache<Long, Person> cache = crd.createCache("CACHE");
> try (IgniteDataStreamer<Long, Person> streamer =
> ignite.dataStreamer(cache.getName()))
> { for (int i = 0; i < CNT; i++) streamer.addData((long)i, new
> Person(i)); }
> IndexQuery<Long, Person> qry = new IndexQuery<Long, Person>(Person.class, IDX)
> .setCriteria(lt("id", CNT / 2));
> QueryCursor cursor = cache.query(qry);
> cursor.close();
> }
> ```
> QueryCursor holds a future that will be completed with iterator over result
> data.
> Starting a query spawns a new thread locally that query cache in background,
> prepares data, and it completes the future with iterator. All affected nodes
> run such threads.
> But cancelling of query with `QueryCursor.close` doesn't cancel query, and it
> will prepare data that will never request. Also cancelling of query doesn't
> clean up iterator.
>
> For local query this issue doesn't lead to any memory leaks, and the future
> and the iterator will be cleaned up by GC later. But actually we can help to
> GC by avoiding preparing the data and by explicit cleaning of those
> structures.
>
> But for remote queries those structures spends memory. And closing of cursor
> has to cancel them.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)