cryptoe commented on code in PR #12848:
URL: https://github.com/apache/druid/pull/12848#discussion_r936694467


##########
processing/src/main/java/org/apache/druid/frame/channel/WritableStreamFrameChannel.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.druid.frame.channel;
+
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.druid.frame.file.FrameFileWriter;
+
+import java.io.IOException;
+
+/**
+ * Frame channel backed by a {@link FrameFileWriter}.
+ */
+public class WritableStreamFrameChannel implements WritableFrameChannel

Review Comment:
   Nit: Could you explain the usage of the word Stream here?
   Should this be WritableFrameFileChannel?



##########
processing/src/test/java/org/apache/druid/frame/write/FrameWritersTest.java:
##########
@@ -132,30 +132,27 @@ public void test_columnar_unsupportedColumnType()
   @Test
   public void test_rowBased_unsupportedSortColumnType()
   {
+    // Register, but don't unregister, because many other tests out there 
expect this to exist even though they

Review Comment:
   Wont this cause flakiness based on the order of how and when this test runs ?



##########
processing/src/main/java/org/apache/druid/frame/processor/AwaitAnyWidget.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.druid.frame.processor;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import it.unimi.dsi.fastutil.ints.IntIterator;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import org.apache.druid.frame.channel.ReadableFrameChannel;
+import org.apache.druid.java.util.common.concurrent.Execs;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Helper used by {@link FrameProcessorExecutor#runFully} when workers return 
{@link ReturnOrAwait#awaitAny}.
+ *
+ * The main idea is to reuse listeners from previous calls to {@link 
#awaitAny(IntSet)} in cases where a particular
+ * channel has not receieved any input since the last call. (Otherwise, 
listeners would pile up.)
+ */
+public class AwaitAnyWidget
+{
+  private final List<ReadableFrameChannel> channels;
+
+  @GuardedBy("listeners")
+  private final List<Listener> listeners;
+
+  public AwaitAnyWidget(final List<ReadableFrameChannel> channels)
+  {
+    this.channels = channels;
+    this.listeners = new ArrayList<>(channels.size());
+
+    for (int i = 0; i < channels.size(); i++) {
+      listeners.add(null);
+    }
+  }
+
+  public ListenableFuture<?> awaitAny(final IntSet awaitSet)
+  {
+    synchronized (listeners) {
+      final SettableFuture<?> retVal = SettableFuture.create();
+
+      final IntIterator awaitSetIterator = awaitSet.iterator();
+      while (awaitSetIterator.hasNext()) {
+        final int channelNumber = awaitSetIterator.nextInt();
+        final ReadableFrameChannel channel = channels.get(channelNumber);
+
+        if (channel.canRead() || channel.isFinished()) {
+          retVal.set(null);
+          return retVal;
+        } else {
+          final Listener priorListener = listeners.get(channelNumber);
+          if (priorListener == null || !priorListener.replaceFuture(retVal)) {
+            final Listener newListener = new Listener(retVal);
+            channel.readabilityFuture().addListener(newListener, 
Execs.directExecutor());
+            listeners.set(channelNumber, newListener);
+          }
+        }
+      }
+
+      return retVal;
+    }
+  }
+
+  private static class Listener implements Runnable

Review Comment:
   Nit: Can we rename this private class to WidgetListener?
   Its aids in the readability. 



##########
processing/src/main/java/org/apache/druid/frame/processor/AwaitAnyWidget.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.druid.frame.processor;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import it.unimi.dsi.fastutil.ints.IntIterator;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import org.apache.druid.frame.channel.ReadableFrameChannel;
+import org.apache.druid.java.util.common.concurrent.Execs;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Helper used by {@link FrameProcessorExecutor#runFully} when workers return 
{@link ReturnOrAwait#awaitAny}.
+ *
+ * The main idea is to reuse listeners from previous calls to {@link 
#awaitAny(IntSet)} in cases where a particular
+ * channel has not receieved any input since the last call. (Otherwise, 
listeners would pile up.)
+ */
+public class AwaitAnyWidget
+{
+  private final List<ReadableFrameChannel> channels;
+
+  @GuardedBy("listeners")
+  private final List<Listener> listeners;
+
+  public AwaitAnyWidget(final List<ReadableFrameChannel> channels)
+  {
+    this.channels = channels;
+    this.listeners = new ArrayList<>(channels.size());
+
+    for (int i = 0; i < channels.size(); i++) {
+      listeners.add(null);
+    }
+  }
+
+  public ListenableFuture<?> awaitAny(final IntSet awaitSet)

Review Comment:
   Also, can you add documentation about what does a future with a null value 
mean ?



##########
processing/src/main/java/org/apache/druid/frame/processor/AwaitAnyWidget.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.druid.frame.processor;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import it.unimi.dsi.fastutil.ints.IntIterator;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import org.apache.druid.frame.channel.ReadableFrameChannel;
+import org.apache.druid.java.util.common.concurrent.Execs;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Helper used by {@link FrameProcessorExecutor#runFully} when workers return 
{@link ReturnOrAwait#awaitAny}.
+ *
+ * The main idea is to reuse listeners from previous calls to {@link 
#awaitAny(IntSet)} in cases where a particular
+ * channel has not receieved any input since the last call. (Otherwise, 
listeners would pile up.)
+ */
+public class AwaitAnyWidget
+{
+  private final List<ReadableFrameChannel> channels;
+
+  @GuardedBy("listeners")
+  private final List<Listener> listeners;
+
+  public AwaitAnyWidget(final List<ReadableFrameChannel> channels)
+  {
+    this.channels = channels;
+    this.listeners = new ArrayList<>(channels.size());
+
+    for (int i = 0; i < channels.size(); i++) {
+      listeners.add(null);
+    }
+  }
+
+  public ListenableFuture<?> awaitAny(final IntSet awaitSet)

Review Comment:
   nit: awaitChannelNumberSet ?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to