pavlukhin commented on a change in pull request #6917: IGNITE-12189 
Implementation correct limit for TextQuery
URL: https://github.com/apache/ignite/pull/6917#discussion_r338485139
 
 

 ##########
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryFutureAdapter.java
 ##########
 @@ -330,15 +333,18 @@ protected void onNodeLeft(UUID evtNodeId) {
      */
     protected void enqueue(Collection<?> col) {
         assert Thread.holdsLock(this);
-
-        if(limitCnt <= 0 || limitCnt >= col.size()) {
-            queue.add((Collection<R>)col);
-            cnt.addAndGet(col.size());
-            limitCnt -= col.size();
-        } else {
-            int toAdd = limitCnt;
-            queue.add(new ArrayList(col).subList(0, toAdd));
-            cnt.addAndGet(toAdd);
+        if(!limitReached){
+            if(capacity <= 0 || capacity >= col.size()) {
 
 Review comment:
   I suppose a bug is hidden here. If we got `capacity == col.size()`, then 
`capacity` becomes 0 but `limitReached` flag is still false. Subsequent 
`enqueue` calls will add items to the queue unconditionally. It seems can be 
fixed here by changing `>=` to `>` (`capacity > col.size()`). But let me 
suggest my version for your justification:
   ```
   if (limitDisabled) {
       queue.add((Collection<R>)col);
   
       cnt.addAndGet(col.size());
   }
   else {
       if (capacity >= col.size()) {
           queue.add((Collection<R>)col);
           capacity -= col.size();
   
           cnt.addAndGet(col.size());
       }
       else if (capacity > 0) {
           queue.add(new ArrayList<>((Collection<R>)col).subList(0, capacity));
           capacity = 0;
   
           cnt.addAndGet(capacity);
       }
   }
   ```
   
   By the way, can we have `col.size() == 0` here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to