ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [47/50] ignite git commit: Fixed iterator.
Date Mon, 14 Aug 2017 10:30:57 GMT
Fixed iterator.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2ff58058
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2ff58058
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2ff58058

Branch: refs/heads/ignite-5991-6019
Commit: 2ff5805884c5b75a4ac094c4d47502adcedb2dc5
Parents: 4b6383a
Author: devozerov <vozerov@gridgain.com>
Authored: Mon Aug 14 13:27:21 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Mon Aug 14 13:27:21 2017 +0300

----------------------------------------------------------------------
 .../h2/twostep/GridMergeIndexeIterator.java     | 57 +++++++++++---------
 1 file changed, 33 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2ff58058/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexeIterator.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexeIterator.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexeIterator.java
index f3cfc37..1850adc 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexeIterator.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridMergeIndexeIterator.java
@@ -48,10 +48,10 @@ class GridMergeIndexeIterator implements Iterator<List<?>>
{
     private final boolean distributedJoins;
 
     /** Iterator over indexes. */
-    private final Iterator<GridMergeIndex> idxs;
+    private final Iterator<GridMergeIndex> idxIter;
 
     /** Current cursor. */
-    private Cursor cur;
+    private Cursor cursor;
 
     /** Next row to return. */
     private List<Object> next;
@@ -78,7 +78,7 @@ class GridMergeIndexeIterator implements Iterator<List<?>> {
         this.qryReqId = qryReqId;
         this.distributedJoins = distributedJoins;
 
-        this.idxs = run.indexes().iterator();
+        this.idxIter = run.indexes().iterator();
 
         advance();
     }
@@ -109,36 +109,42 @@ class GridMergeIndexeIterator implements Iterator<List<?>>
{
      * Advance iterator.
      */
     private void advance() {
-        next = null;
-
         try {
-            boolean hasNext = false;
-
-            while (cur == null || !(hasNext = cur.next())) {
-                if (idxs.hasNext())
-                    cur = idxs.next().findInStream(null, null);
+            while (true) {
+                // Get next index cursor to iterate over.
+                if (cursor == null && idxIter.hasNext())
+                    cursor = idxIter.next().findInStream(null, null);
                 else {
-                    close0();
+                    next = null;
 
                     break;
                 }
-            }
 
-            if (hasNext) {
-                Row row = cur.get();
+                assert cursor != null;
 
-                int cols = row.getColumnCount();
+                if (cursor.next()) {
+                    Row row = cursor.get();
 
-                List<Object> res = new ArrayList<>(cols);
+                    int cols = row.getColumnCount();
 
-                for (int c = 0; c < cols; c++)
-                    res.add(row.getValue(c).getObject());
+                    List<Object> res = new ArrayList<>(cols);
 
-                next = res;
+                    for (int c = 0; c < cols; c++)
+                        res.add(row.getValue(c).getObject());
+
+                    next = res;
+
+                    break;
+                }
+                else
+                    cursor = null;
             }
+
+            if (next == null)
+                releaseIfNeeded();
         }
         catch (Exception e) {
-            close0();
+            releaseIfNeeded();
 
             throw e;
         }
@@ -147,11 +153,14 @@ class GridMergeIndexeIterator implements Iterator<List<?>>
{
     /**
      * Close routine.
      */
-    private void close0() {
+    private void releaseIfNeeded() {
         if (!released) {
-            rdcExec.releaseRemoteResources(nodes, run, qryReqId, distributedJoins);
-
-            released = true;
+            try {
+                rdcExec.releaseRemoteResources(nodes, run, qryReqId, distributedJoins);
+            }
+            finally {
+                released = true;
+            }
         }
     }
 }


Mime
View raw message