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/06/01 09:07:27 UTC

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

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



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/UnsortedDistributedCacheQueryReducer.java
##########
@@ -0,0 +1,211 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.P1;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Reducer of distributed query, fetch pages from remote nodes. All pages go in single page stream so no ordering is provided.
+ */
+class UnsortedDistributedCacheQueryReducer<R> extends AbstractCacheQueryReducer<R> implements DistributedCacheQueryReducer<R> {
+    /**
+     * Whether it is allowed to send cache query result requests to nodes.
+     * It is set to {@code false} if a query finished or failed.
+     */
+    protected volatile boolean loadAllowed;
+
+    /** Query request ID. */
+    protected final long reqId;
+
+    /**
+     * Dynamic collection of nodes that run this query. If a node finishes this query then remove it from this colleciton.
+     */
+    protected final Collection<UUID> subgrid = new HashSet<>();
+
+    /**
+     * List of nodes that respons with cache query result pages. This collection should be cleaned before sending new
+     * cache query request.
+     */
+    protected final Collection<UUID> rcvd = new HashSet<>();
+
+    /** Requester of cache query result pages. */
+    protected final CacheQueryPageRequester pageRequester;
+
+    /** Cache context. */
+    protected final GridCacheContext cctx;
+
+    /** Count down this latch when every node responses on initial cache query request. */
+    private final CountDownLatch firstPageLatch = new CountDownLatch(1);
+
+    /** Single page stream. */
+    private final PageStream pageStream;
+
+    /** Query future. */
+    protected final GridCacheQueryFutureAdapter fut;
+
+    /**
+     * @param reqId Cache query request ID.
+     * @param pageRequester Provides a functionality to request pages from remote nodes.
+     * @param nodes Collection of nodes this query applies to.
+     */
+    UnsortedDistributedCacheQueryReducer(GridCacheQueryFutureAdapter fut, long reqId, CacheQueryPageRequester pageRequester,
+        Collection<ClusterNode> nodes) {
+        super(fut);
+
+        this.reqId = reqId;
+        this.pageRequester = pageRequester;
+
+        synchronized (queueLock()) {
+            for (ClusterNode node : nodes)
+                subgrid.add(node.id());
+        }
+
+        cctx = fut.cctx;
+
+        pageStream = new PageStream();
+
+        this.fut = fut;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasNext() throws IgniteCheckedException {
+        return pageStream.hasNext();
+    }
+
+    /** {@inheritDoc} */
+    @Override public R next() throws IgniteCheckedException {
+        return pageStream.next();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void addPage(@Nullable UUID nodeId, Collection<R> data) {
+        pageStream.addPage(data);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onLastPage() {
+        super.onLastPage();
+
+        loadAllowed = false;
+
+        firstPageLatch.countDown();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void cancel() {

Review comment:
       No, as `cancel()` always prefaced with `onLastPage()` call. 
   
   Also, I checked that actually the `awaitFirstItem()` used only for ScanQuery only in case user specified partitions to enable retry this query if first page loading failed. Looks too narrow case, and I think there should be a separate activity to investigate this functionality.




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