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 2021/10/04 11:54:34 UTC

[GitHub] [ignite] Mmuzaf commented on a change in pull request #9081: IGNITE-14703. Add MergeSort distributed cache query reducer.

Mmuzaf commented on a change in pull request #9081:
URL: https://github.com/apache/ignite/pull/9081#discussion_r721285189



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/NodePageStream.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.cache.query.reducer;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * This class provides an interface {@link #nextPage()} that returns a {@link NodePage} of cache query result from
+ * single node. A new page requests when previous page was fetched by class consumer.
+ */
+public class NodePageStream<R> {
+    /** Node ID to stream pages */
+    private final UUID nodeId;
+
+    /** Flags shows whether there are no available pages on a query node. */
+    private boolean noRemotePages;
+
+    /** Last delivered page from the stream. */
+    private NodePage<R> head;
+
+    /** Promise to notify the stream consumer about delivering new page. */
+    private CompletableFuture<UUID> pageReady = new CompletableFuture<>();
+
+    /** This lock syncs {@link #head} and {@link #noRemotePages}. */
+    private final Object pagesLock = new Object();

Review comment:
       Let's do synchronization on `this`.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/DistributedCacheQueryReducer.java
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.cache.query.reducer;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCheckedException;
+
+/**
+ * Base class for distributed cache query reducers.
+ */
+public abstract class DistributedCacheQueryReducer<T> extends CacheQueryReducer<T> {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Page streams collection. */
+    protected final Map<UUID, NodePageStream<T>> pageStreams;
+
+    /** Timestamp of query timeout. */
+    protected final long endTime;

Review comment:
       Let's move the endTime-related logic out from the distributed reducer to the `NodeStreams` class. When the `endTime` is reached the `NodeStreams#nextPage` should throw an `IgniteTimeoutException`.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/NodePageStream.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.cache.query.reducer;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * This class provides an interface {@link #nextPage()} that returns a {@link NodePage} of cache query result from
+ * single node. A new page requests when previous page was fetched by class consumer.
+ */
+public class NodePageStream<R> {
+    /** Node ID to stream pages */
+    private final UUID nodeId;
+
+    /** Flags shows whether there are no available pages on a query node. */
+    private boolean noRemotePages;
+
+    /** Last delivered page from the stream. */
+    private NodePage<R> head;

Review comment:
       Do we need it in case of using the ` CompletableFuture<Collection<R>>`?

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/NodePageStream.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.cache.query.reducer;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * This class provides an interface {@link #nextPage()} that returns a {@link NodePage} of cache query result from
+ * single node. A new page requests when previous page was fetched by class consumer.
+ */
+public class NodePageStream<R> {
+    /** Node ID to stream pages */
+    private final UUID nodeId;
+
+    /** Flags shows whether there are no available pages on a query node. */
+    private boolean noRemotePages;
+
+    /** Last delivered page from the stream. */
+    private NodePage<R> head;
+
+    /** Promise to notify the stream consumer about delivering new page. */
+    private CompletableFuture<UUID> pageReady = new CompletableFuture<>();
+
+    /** This lock syncs {@link #head} and {@link #noRemotePages}. */
+    private final Object pagesLock = new Object();
+
+    /** Request pages action. */
+    private final Runnable reqPages;
+
+    /** */
+    public NodePageStream(UUID nodeId, Runnable reqPages) {
+        this.nodeId = nodeId;
+        this.reqPages = reqPages;
+    }
+
+    /** */
+    public UUID nodeId() {
+        return nodeId;
+    }
+
+    /**
+     * @return Future that will be completed when a new page delivered.
+     */
+    public CompletableFuture<UUID> pageReady() {
+        return pageReady;
+    }
+
+    /**
+     * Returns a last delivered page from this stream. Note, that this method has to be invoked after getting
+     * the future provided with {@link #pageReady()}.
+     *
+     * @return Query result page.
+     */
+    public NodePage<R> nextPage() {

Review comment:
       I suggest keeping CompletableFuture<NodePage<R>> the method return type here.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/NodePageStream.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.cache.query.reducer;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * This class provides an interface {@link #nextPage()} that returns a {@link NodePage} of cache query result from
+ * single node. A new page requests when previous page was fetched by class consumer.
+ */
+public class NodePageStream<R> {
+    /** Node ID to stream pages */
+    private final UUID nodeId;
+
+    /** Flags shows whether there are no available pages on a query node. */
+    private boolean noRemotePages;
+
+    /** Last delivered page from the stream. */
+    private NodePage<R> head;
+
+    /** Promise to notify the stream consumer about delivering new page. */
+    private CompletableFuture<UUID> pageReady = new CompletableFuture<>();

Review comment:
       We should keep not the nodeId promise, but `CompletableFuture<Collection<R>>`.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/NodePageStream.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.cache.query.reducer;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * This class provides an interface {@link #nextPage()} that returns a {@link NodePage} of cache query result from
+ * single node. A new page requests when previous page was fetched by class consumer.
+ */
+public class NodePageStream<R> {
+    /** Node ID to stream pages */
+    private final UUID nodeId;
+
+    /** Flags shows whether there are no available pages on a query node. */
+    private boolean noRemotePages;
+
+    /** Last delivered page from the stream. */
+    private NodePage<R> head;
+
+    /** Promise to notify the stream consumer about delivering new page. */
+    private CompletableFuture<UUID> pageReady = new CompletableFuture<>();
+
+    /** This lock syncs {@link #head} and {@link #noRemotePages}. */
+    private final Object pagesLock = new Object();
+
+    /** Request pages action. */
+    private final Runnable reqPages;
+
+    /** */
+    public NodePageStream(UUID nodeId, Runnable reqPages) {
+        this.nodeId = nodeId;
+        this.reqPages = reqPages;
+    }
+
+    /** */
+    public UUID nodeId() {
+        return nodeId;
+    }
+
+    /**
+     * @return Future that will be completed when a new page delivered.
+     */
+    public CompletableFuture<UUID> pageReady() {
+        return pageReady;
+    }
+
+    /**
+     * Returns a last delivered page from this stream. Note, that this method has to be invoked after getting
+     * the future provided with {@link #pageReady()}.
+     *
+     * @return Query result page.
+     */
+    public NodePage<R> nextPage() {
+        boolean loadPage = false;
+
+        NodePage<R> page;
+
+        synchronized (pagesLock) {
+            assert head != null;
+
+            page = head;
+
+            head = null;
+
+            if (!noRemotePages)
+                loadPage = true;
+        }
+
+        if (loadPage) {
+            pageReady = new CompletableFuture<>();
+
+            reqPages.run();
+        }
+
+        return page;
+    }
+
+    /**
+     * Add new query result page of data.
+     *
+     * @param data Collection of query result items.
+     * @param last Whether it is the last page from this node.
+     */
+    public void addPage(Collection<R> data, boolean last) {
+        synchronized (pagesLock) {
+            head = new NodePage<>(nodeId, data);
+
+            if (last)
+                noRemotePages = true;
+        }
+
+        pageReady.complete(nodeId);
+    }
+
+    /**
+     * Cancel query on all nodes.
+     */
+    public void cancel() {
+        synchronized (pagesLock) {
+            head = new NodePage<>(nodeId, Collections.emptyList());

Review comment:
       I suggest completing the future with the `IgniteCancelledException` in case of any errors and change the `cancel` to the `complete(IgniteException e)` or `error(IgniteException e)`.




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org