You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nemo.apache.org by GitBox <gi...@apache.org> on 2018/12/14 05:20:02 UTC

[GitHub] johnyangk commented on a change in pull request #178: [NEMO-317] Optimize triggering logic in GroupByKeyAndWindowDoFnTransform

johnyangk commented on a change in pull request #178: [NEMO-317] Optimize triggering logic in GroupByKeyAndWindowDoFnTransform
URL: https://github.com/apache/incubator-nemo/pull/178#discussion_r241644212
 
 

 ##########
 File path: compiler/frontend/beam/src/main/java/org/apache/nemo/compiler/frontend/beam/transform/ContextForTimer.java
 ##########
 @@ -0,0 +1,175 @@
+/*
+ * 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.nemo.compiler.frontend.beam.transform;
+
+import org.apache.beam.runners.core.TimerInternals;
+import org.apache.beam.sdk.state.TimeDomain;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.nemo.common.Pair;
+import org.joda.time.Instant;
+
+import javax.annotation.Nullable;
+import java.util.Comparator;
+import java.util.Map;
+import java.util.NavigableSet;
+import java.util.TreeSet;
+
+/**
+ * This class contains necessary data for timers.
+ * @param <K> key type
+ */
+final class ContextForTimer<K> {
+  // Pending input watermark timers of all keys, in timestamp order.
+  private final NavigableSet<Pair<K, TimerInternals.TimerData>> watermarkTimers;
+
+  // Pending processing time timers of all keys, in timestamp order.
+  private final NavigableSet<Pair<K, TimerInternals.TimerData>> processingTimers;
+
+  // Pending synchronized processing time timers of all keys, in timestamp order.
+  private final NavigableSet<Pair<K, TimerInternals.TimerData>> synchronizedProcessingTimers;
+
+  // Current input watermark.
+  private Instant inputWatermarkTime = BoundedWindow.TIMESTAMP_MIN_VALUE;
+
+  // Current processing time.
+  private Instant processingTime = BoundedWindow.TIMESTAMP_MIN_VALUE;
+
+  // Current synchronized processing time.
+  private Instant synchronizedProcessingTime = BoundedWindow.TIMESTAMP_MIN_VALUE;
+
+  // map that holds timer internals of each key
+  private final Map<K, NemoTimerInternals> timerInternalsMap;
+
+  /**
+   * This comparator first compares the timer data, in timestamp order.
+   * If two timer data have the same timestamp, we order them by key.
+   * As the key is not comparable, we convert it to string and compare the string value.
+   * In fact, the key ordering is not important, because the first ordering is determined by the timestamp.
+   * We only have to check whether the two keys are the same or not.
+   */
+  private final Comparator<Pair<K, TimerInternals.TimerData>> comparator = (o1, o2) -> {
+    final int comp = o1.right().compareTo(o2.right());
+    if (comp == 0) {
+      // if two timer are the same, compare key
+      if (o1.left() == null && o2.left() == null) {
+        return 0;
+      } else if (o1.left() == null || o2.left() == null) {
+        return -1;
+      } else if (o1.left().equals(o2.left())) {
+        return 0;
+      } else {
+        return o1.left().toString().compareTo(o2.left().toString());
+      }
+    } else {
+      return comp;
+    }
+  };
+
+  ContextForTimer(final Map<K, NemoTimerInternals> timerInternalsMap) {
+    this.watermarkTimers = new TreeSet<>(comparator);
+    this.processingTimers = new TreeSet<>(comparator);
+    this.synchronizedProcessingTimers = new TreeSet<>(comparator);
+    this.timerInternalsMap = timerInternalsMap;
+  }
+
+
+  public void setCurrentProcessingTime(final Instant time) {
 
 Review comment:
   Please make this and below methods package-private. (i.e., remove `public`)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services