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/12/28 08:22:41 UTC

[GitHub] [ignite] ygerzhedovich commented on a change in pull request #8607: IGNITE-13904 don't use rows buffers for simple one-way reducer

ygerzhedovich commented on a change in pull request #8607:
URL: https://github.com/apache/ignite/pull/8607#discussion_r549257424



##########
File path: modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/UnsortedBaseReducer.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.h2.twostep;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2Cursor;
+import org.h2.index.Cursor;
+import org.h2.result.Row;
+import org.h2.result.SearchRow;
+import org.h2.value.Value;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Base unsorted merge index.
+ */
+public abstract class UnsortedBaseReducer extends AbstractReducer {
+    /** */
+    protected final AtomicInteger activeSourcesCnt = new AtomicInteger(-1);
+
+    /** */
+    protected final PollableQueue<ReduceResultPage> queue = new PollableQueue<>();
+
+    /** */
+    protected Iterator<Value[]> iter = Collections.emptyIterator();
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Context.
+     */
+    public UnsortedBaseReducer(GridKernalContext ctx) {
+        super(ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void setSources(Collection<ClusterNode> nodes, int segmentsCnt) {
+        super.setSources(nodes, segmentsCnt);
+
+        int x = srcNodes.size() * segmentsCnt;
+
+        assert x > 0 : x;
+
+        activeSourcesCnt.set(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean fetchedAll() {
+        int x = activeSourcesCnt.get();
+
+        assert x >= 0 : x; // This method must not be called if the sources were not set.
+
+        return x == 0 && queue.isEmpty();
+    }
+
+    /**
+     * @param page Page.
+     */
+    @Override protected void addPage0(ReduceResultPage page) {
+        assert page.rowsInPage() > 0 || page.isLast() || page.isFail();
+
+        // Do not add empty page to avoid premature stream termination.
+        if (page.rowsInPage() != 0 || page.isFail())
+            queue.add(page);
+
+        if (page.isLast()) {
+            int x = activeSourcesCnt.decrementAndGet();
+
+            assert x >= 0 : x;
+
+            if (x == 0) // Always terminate with empty iterator.
+                queue.add(createDummyLastPage(page));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Cursor findAllFetched(List<Row> fetched, @Nullable SearchRow first, @Nullable SearchRow last) {
+        // This index is unsorted: have to ignore bounds.
+        return new GridH2Cursor(fetched.iterator());
+    }
+
+    /**
+     *

Review comment:
       short version of JavaDoc




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