You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/04/21 11:20:38 UTC

[GitHub] [ignite] bratwurzt opened a new pull request #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

bratwurzt opened a new pull request #7704:
URL: https://github.com/apache/ignite/pull/7704


   Because QueryKeyValueIterable does not implement spliterator, calling `spliterator().hasCharacteristics(Spliterator.SIZED)` will construct a new Spliterator with `java.util.Spliterators#spliteratorUnknownSize(java.util.Iterator<? extends T>, int)` and that will call `org.apache.ignite.internal.processors.cache.QueryCursorImpl#iter` again, thus throwing exception `throw new IgniteException("Iterator is already fetched or query was cancelled.")`


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] nizhikov commented on a change in pull request #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #7704:
URL: https://github.com/apache/ignite/pull/7704#discussion_r427873967



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/QueryCursorImpl.java
##########
@@ -92,6 +93,11 @@ public QueryCursorImpl(Iterable<T> iterExec, GridQueryCancel cancel, boolean isQ
         return new AutoClosableCursorIterator<>(this, iter());
     }
 
+    /** {@inheritDoc} */
+    @Override public Spliterator<T> spliterator() {
+        return iterExec == null ? QueryCursorEx.super.spliterator() : iterExec.spliterator();

Review comment:
       Do we have a scenario when `iterExec` is null?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] bratwurzt edited a comment on issue #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
bratwurzt edited a comment on issue #7704:
URL: https://github.com/apache/ignite/pull/7704#issuecomment-617667418


   > 
   > 
   > > > Looks good to me, but you should re-run ~Run-All TC task~ possible blockers of your PR until no blockers found for that (`Results ready` button will green and contain '0' caption) and then publish the approval to jira ticket by pressing the `Comment JIRA` button.
   > > > Upd: Easy way is to go into [Show pull/7704/head report](https://mtcga.gridgain.com/pr.html?serverId=apache&suiteId=IgniteTests24Java8_RunAll&branchForTc=pull/7704/head&action=Latest) page and press `Re-run possible blockers` button there.
   > > 
   > > 
   > > Thank you, I got lost in TC searching for failed tests. :)
   > 
   > FYI: [TC Builds page](https://ci.ignite.apache.org/buildConfiguration/IgniteTests24Java8_RunAll?branch=pull%2F7704%2Fhead&buildTypeTab=overview&mode=builds) of this PR.
   
   master branch tests are failing. Should I clean (some of) them up? Since some are trivial (add a .travis.yml exclude to apache-rat-plugin)...
   
   ps: you have an interesting git workflow for a complex project


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] bratwurzt commented on a change in pull request #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
bratwurzt commented on a change in pull request #7704:
URL: https://github.com/apache/ignite/pull/7704#discussion_r428534696



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/QueryCursorSpliteratorCallsTest.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.Query;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Query cursor spliterator called multiple times without triggering IgniteException("Iterator is already fetched or
+ * query was cancelled.")
+ */
+public class QueryCursorSpliteratorCallsTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+                .setIndexedTypes(Integer.class, String.class));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(1);
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testScanQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new ScanQuery<>((key, val) -> key != null));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testContinuousQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new ContinuousQuery<>()
+            .setInitialQuery(new ScanQuery<>((key, val) -> key != null))
+            .setAutoUnsubscribe(true)
+            .setLocalListener(iterable -> {}));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testSqlQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new SqlQuery<>("String", "from String"));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testSqlFieldQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new SqlFieldsQuery("select _key from String"));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testTextQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new TextQuery<>("String", "1"));
+    }
+
+    /**
+     * Executes query on cache then calls {@link QueryCursor#iterator()} and {@link QueryCursor#spliterator()}
+     * sequentially.
+     *
+     * @param qry Query.
+     */
+    private void doQueryCursorSpliteratorCalls(Query<?> qry) {
+        Ignite client = grid(0);
+
+        IgniteCache<Object, String> cache = client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        try (QueryCursor<?> cur = cache.query(qry)) {
+            cur.iterator();

Review comment:
       This will not work, since you can't reuse QueryCursorImpl's iterator/spliterator. I think that's why there's `new IgniteException("Iterator is already fetched or query was cancelled.")` on iter() call. Will add AutoClosableCursorSpliterator




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] bratwurzt commented on a change in pull request #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
bratwurzt commented on a change in pull request #7704:
URL: https://github.com/apache/ignite/pull/7704#discussion_r428534696



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/QueryCursorSpliteratorCallsTest.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.Query;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Query cursor spliterator called multiple times without triggering IgniteException("Iterator is already fetched or
+ * query was cancelled.")
+ */
+public class QueryCursorSpliteratorCallsTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+                .setIndexedTypes(Integer.class, String.class));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(1);
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testScanQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new ScanQuery<>((key, val) -> key != null));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testContinuousQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new ContinuousQuery<>()
+            .setInitialQuery(new ScanQuery<>((key, val) -> key != null))
+            .setAutoUnsubscribe(true)
+            .setLocalListener(iterable -> {}));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testSqlQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new SqlQuery<>("String", "from String"));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testSqlFieldQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new SqlFieldsQuery("select _key from String"));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testTextQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new TextQuery<>("String", "1"));
+    }
+
+    /**
+     * Executes query on cache then calls {@link QueryCursor#iterator()} and {@link QueryCursor#spliterator()}
+     * sequentially.
+     *
+     * @param qry Query.
+     */
+    private void doQueryCursorSpliteratorCalls(Query<?> qry) {
+        Ignite client = grid(0);
+
+        IgniteCache<Object, String> cache = client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        try (QueryCursor<?> cur = cache.query(qry)) {
+            cur.iterator();

Review comment:
       This will not work, since you can't reuse QueryCursorImpl's iterator/spliterator. I think that's why there's `new IgniteException("Iterator is already fetched or query was cancelled.")` on iter() call. ~~Will add AutoClosableCursorSpliterator~~ will find a fix




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] bratwurzt commented on issue #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
bratwurzt commented on issue #7704:
URL: https://github.com/apache/ignite/pull/7704#issuecomment-617600393


   > 
   > 
   > Looks good to me, but you should re-run ~Run-All TC task~ possible blockers of your PR until no blockers found for that (`Results ready` button will green and contain '0' caption) and then publish the approval to jira ticket by pressing the `Comment JIRA` button.
   > 
   > Upd: Easy way is to go into [Show pull/7704/head report](https://mtcga.gridgain.com/pr.html?serverId=apache&suiteId=IgniteTests24Java8_RunAll&branchForTc=pull/7704/head&action=Latest) page and press `Re-run possible blockers` button there.
   
   Thank you, I got lost in TC searching for failed tests. :)


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] nizhikov commented on a change in pull request #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #7704:
URL: https://github.com/apache/ignite/pull/7704#discussion_r427885038



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/QueryCursorSpliteratorCallsTest.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.Query;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Query cursor spliterator called multiple times without triggering IgniteException("Iterator is already fetched or
+ * query was cancelled.")
+ */
+public class QueryCursorSpliteratorCallsTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+                .setIndexedTypes(Integer.class, String.class));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(1);

Review comment:
       The test incomplete, because of two reasons:
   
   1. It always checks empty cache iterators.
   2. It doesn't check that we can actually iterate on the `iterator()` and `spliterator()` results.
   
   See suggested changes below, does it makes sense for you? (changes will made test fail).
   
   ```
           IgniteEx ign = startGrids(1);
           IgniteCache<Integer, String> cache = ign.cache(DEFAULT_CACHE_NAME);
   
           cache.put(1, "1");
           cache.put(2, "2");
           cache.put(3, "3");
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] bratwurzt commented on a change in pull request #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
bratwurzt commented on a change in pull request #7704:
URL: https://github.com/apache/ignite/pull/7704#discussion_r428505038



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/QueryCursorSpliteratorCallsTest.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.Query;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Query cursor spliterator called multiple times without triggering IgniteException("Iterator is already fetched or
+ * query was cancelled.")
+ */
+public class QueryCursorSpliteratorCallsTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+                .setIndexedTypes(Integer.class, String.class));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(1);

Review comment:
       Yes, you're right, I was so stuck on spliterator().size() I didn't realize I'm testing empty caches. Thank you.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] x-kreator commented on issue #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
x-kreator commented on issue #7704:
URL: https://github.com/apache/ignite/pull/7704#issuecomment-617779697


   > > > > Looks good to me, but you should re-run ~Run-All TC task~ possible blockers of your PR until no blockers found for that (`Results ready` button will green and contain '0' caption) and then publish the approval to jira ticket by pressing the `Comment JIRA` button.
   > > > > Upd: Easy way is to go into [Show pull/7704/head report](https://mtcga.gridgain.com/pr.html?serverId=apache&suiteId=IgniteTests24Java8_RunAll&branchForTc=pull/7704/head&action=Latest) page and press `Re-run possible blockers` button there.
   > > > 
   > > > 
   > > > Thank you, I got lost in TC searching for failed tests. :)
   > > 
   > > 
   > > FYI: [TC Builds page](https://ci.ignite.apache.org/buildConfiguration/IgniteTests24Java8_RunAll?branch=pull%2F7704%2Fhead&buildTypeTab=overview&mode=builds) of this PR.
   > 
   > master branch tests are failing. Should I clean (some of) them up? Since some are trivial (add a .travis.yml exclude to apache-rat-plugin)...
   > 
   > ps: you have an interesting git workflow for a complex project
   
   Some tests at master branch can fail occasionally, you should exclude the influence of your change by several re-runs of failed tests, the most of them should pass without failures. In case when you get some repeatedly failed tests, i.e. blockers count won't zeroed after several runs (3-5), you'll have to research those test for affecting by your changes.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] bratwurzt commented on a change in pull request #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
bratwurzt commented on a change in pull request #7704:
URL: https://github.com/apache/ignite/pull/7704#discussion_r428534696



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/QueryCursorSpliteratorCallsTest.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.Query;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Query cursor spliterator called multiple times without triggering IgniteException("Iterator is already fetched or
+ * query was cancelled.")
+ */
+public class QueryCursorSpliteratorCallsTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+                .setIndexedTypes(Integer.class, String.class));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(1);
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testScanQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new ScanQuery<>((key, val) -> key != null));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testContinuousQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new ContinuousQuery<>()
+            .setInitialQuery(new ScanQuery<>((key, val) -> key != null))
+            .setAutoUnsubscribe(true)
+            .setLocalListener(iterable -> {}));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testSqlQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new SqlQuery<>("String", "from String"));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testSqlFieldQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new SqlFieldsQuery("select _key from String"));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testTextQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new TextQuery<>("String", "1"));
+    }
+
+    /**
+     * Executes query on cache then calls {@link QueryCursor#iterator()} and {@link QueryCursor#spliterator()}
+     * sequentially.
+     *
+     * @param qry Query.
+     */
+    private void doQueryCursorSpliteratorCalls(Query<?> qry) {
+        Ignite client = grid(0);
+
+        IgniteCache<Object, String> cache = client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        try (QueryCursor<?> cur = cache.query(qry)) {
+            cur.iterator();

Review comment:
       This will not work, since you can't reuse QueryCursorImpl's iterator in case of ScanQueries. I think that's why there's `new IgniteException("Iterator is already fetched or query was cancelled.")` on iter() call. ~~Will add AutoClosableCursorSpliterator~~ will find a fix




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] nizhikov commented on a change in pull request #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #7704:
URL: https://github.com/apache/ignite/pull/7704#discussion_r427885258



##########
File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/QueryCursorSpliteratorCallsTest.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.Query;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Query cursor spliterator called multiple times without triggering IgniteException("Iterator is already fetched or
+ * query was cancelled.")
+ */
+public class QueryCursorSpliteratorCallsTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+                .setIndexedTypes(Integer.class, String.class));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(1);
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testScanQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new ScanQuery<>((key, val) -> key != null));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testContinuousQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new ContinuousQuery<>()
+            .setInitialQuery(new ScanQuery<>((key, val) -> key != null))
+            .setAutoUnsubscribe(true)
+            .setLocalListener(iterable -> {}));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testSqlQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new SqlQuery<>("String", "from String"));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testSqlFieldQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new SqlFieldsQuery("select _key from String"));
+    }
+
+    /**
+     * @throws IgniteException If failed.
+     */
+    @Test
+    public void testTextQueryCursorSpliteratorCalls() throws IgniteException {
+        doQueryCursorSpliteratorCalls(new TextQuery<>("String", "1"));
+    }
+
+    /**
+     * Executes query on cache then calls {@link QueryCursor#iterator()} and {@link QueryCursor#spliterator()}
+     * sequentially.
+     *
+     * @param qry Query.
+     */
+    private void doQueryCursorSpliteratorCalls(Query<?> qry) {
+        Ignite client = grid(0);
+
+        IgniteCache<Object, String> cache = client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
+
+        try (QueryCursor<?> cur = cache.query(qry)) {
+            cur.iterator();

Review comment:
       ```
               Iterator<Object> iter = (Iterator<Object>)cur.iterator();
               Spliterator<Object> spliter = (Spliterator<Object>)cur.spliterator();
   
               Set<Object> iterData = new HashSet<>();
               Set<Object> spliterData = new HashSet<>();
   
               while (iter.hasNext())
                   iterData.add(iter.next());
   
               spliter.forEachRemaining(spliterData::add);
   
               assertEqualsCollections(iterData, spliterData);
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] x-kreator edited a comment on issue #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
x-kreator edited a comment on issue #7704:
URL: https://github.com/apache/ignite/pull/7704#issuecomment-617779697


   > > > > Looks good to me, but you should re-run ~Run-All TC task~ possible blockers of your PR until no blockers found for that (`Results ready` button will green and contain '0' caption) and then publish the approval to jira ticket by pressing the `Comment JIRA` button.
   > > > > Upd: Easy way is to go into [Show pull/7704/head report](https://mtcga.gridgain.com/pr.html?serverId=apache&suiteId=IgniteTests24Java8_RunAll&branchForTc=pull/7704/head&action=Latest) page and press `Re-run possible blockers` button there.
   > > > 
   > > > 
   > > > Thank you, I got lost in TC searching for failed tests. :)
   > > 
   > > 
   > > FYI: [TC Builds page](https://ci.ignite.apache.org/buildConfiguration/IgniteTests24Java8_RunAll?branch=pull%2F7704%2Fhead&buildTypeTab=overview&mode=builds) of this PR.
   > 
   > master branch tests are failing. Should I clean (some of) them up? Since some are trivial (add a .travis.yml exclude to apache-rat-plugin)...
   > 
   > ps: you have an interesting git workflow for a complex project
   
   Some tests at master branch can fail occasionally, you should exclude the influence of your changes by several re-runs of failed tests, the most of them should pass without failures. In case when you get some repeatedly failed tests, i.e. blockers count won't zeroed after several runs (3-5), you'll have to research those tests for affecting by your changes.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] x-kreator commented on issue #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
x-kreator commented on issue #7704:
URL: https://github.com/apache/ignite/pull/7704#issuecomment-617637952


   > > Looks good to me, but you should re-run ~Run-All TC task~ possible blockers of your PR until no blockers found for that (`Results ready` button will green and contain '0' caption) and then publish the approval to jira ticket by pressing the `Comment JIRA` button.
   > > Upd: Easy way is to go into [Show pull/7704/head report](https://mtcga.gridgain.com/pr.html?serverId=apache&suiteId=IgniteTests24Java8_RunAll&branchForTc=pull/7704/head&action=Latest) page and press `Re-run possible blockers` button there.
   > 
   > Thank you, I got lost in TC searching for failed tests. :)
   
   FYI: [TC Builds page](https://ci.ignite.apache.org/buildConfiguration/IgniteTests24Java8_RunAll?branch=pull%2F7704%2Fhead&buildTypeTab=overview&mode=builds) of this PR.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] bratwurzt commented on a change in pull request #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
bratwurzt commented on a change in pull request #7704:
URL: https://github.com/apache/ignite/pull/7704#discussion_r428506350



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/QueryCursorImpl.java
##########
@@ -92,6 +93,11 @@ public QueryCursorImpl(Iterable<T> iterExec, GridQueryCancel cancel, boolean isQ
         return new AutoClosableCursorIterator<>(this, iter());
     }
 
+    /** {@inheritDoc} */
+    @Override public Spliterator<T> spliterator() {
+        return iterExec == null ? QueryCursorEx.super.spliterator() : iterExec.spliterator();

Review comment:
       You don't use @Nonnull annotations or some `com.google.common.base.Preconditions` equivalent in this project, right? Force of habit, I guess. :) will fix.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite] bratwurzt commented on issue #7704: IGNITE-12905 - QueryKeyValueIterable missing custom spliterator() implementation

Posted by GitBox <gi...@apache.org>.
bratwurzt commented on issue #7704:
URL: https://github.com/apache/ignite/pull/7704#issuecomment-617667418


   > 
   > 
   > > > Looks good to me, but you should re-run ~Run-All TC task~ possible blockers of your PR until no blockers found for that (`Results ready` button will green and contain '0' caption) and then publish the approval to jira ticket by pressing the `Comment JIRA` button.
   > > > Upd: Easy way is to go into [Show pull/7704/head report](https://mtcga.gridgain.com/pr.html?serverId=apache&suiteId=IgniteTests24Java8_RunAll&branchForTc=pull/7704/head&action=Latest) page and press `Re-run possible blockers` button there.
   > > 
   > > 
   > > Thank you, I got lost in TC searching for failed tests. :)
   > 
   > FYI: [TC Builds page](https://ci.ignite.apache.org/buildConfiguration/IgniteTests24Java8_RunAll?branch=pull%2F7704%2Fhead&buildTypeTab=overview&mode=builds) of this PR.
   
   master branch tests are failing. Should I clean (some of) them up? Since some are trivial (add a .travis.yml exclude to apache-rat-plugin)...


----------------------------------------------------------------
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:
users@infra.apache.org