abstractdog commented on a change in pull request #105:
URL: https://github.com/apache/tez/pull/105#discussion_r573447936
##########
File path:
tez-runtime-internals/src/main/java/org/apache/tez/runtime/InputReadyTracker.java
##########
@@ -18,165 +18,215 @@
package org.apache.tez.runtime;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
-import org.apache.tez.runtime.api.Input;
-import org.apache.tez.runtime.api.MergedLogicalInput;
+import javax.annotation.concurrent.GuardedBy;
import org.apache.tez.common.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
+import org.apache.tez.runtime.api.Input;
+import org.apache.tez.runtime.api.MergedLogicalInput;
+/**
+ * A class for tracking a global list of ready {@code Inputs} and waiting for a
+ * certain subset of {@code Inputs} to appear in the global list.
+ */
public class InputReadyTracker {
- private final ConcurrentMap<Input, Boolean> readyInputs;
-
- private ConcurrentMap<Input, List<MergedLogicalInput>> inputToGroupMap;
+ @GuardedBy("lock")
+ private final Set<Input> readyInputs;
+
+ @GuardedBy("lock")
+ private Map<Input, List<MergedLogicalInput>> inputToGroupMap;
private final ReentrantLock lock = new ReentrantLock();
private final Condition condition = lock.newCondition();
+ /**
+ * Constructor.
+ */
public InputReadyTracker() {
- readyInputs = Maps.newConcurrentMap();
+ readyInputs = new HashSet<>();
+ inputToGroupMap = Collections.emptyMap();
}
- // Called by the InputContext once it's ready.
+ /**
+ * Mark an input as being ready. If the same Input is marked as ready
multiple
+ * times, all subsequent attempts will be ignored.
+ *
+ * @param input The input to consider as ready
+ */
public void setInputIsReady(Input input) {
lock.lock();
try {
- Boolean old = readyInputs.putIfAbsent(input, true);
- if (old == null) {
+ boolean added = readyInputs.add(input);
+ if (added) {
informGroupedInputs(input);
condition.signalAll();
- } else {
- // Ignore duplicate inputReady from the same Input
Review comment:
this message is useful for code learners, can we keep it somehow? but I
agree that using an else block for comment is not really clean
----------------------------------------------------------------
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:
[email protected]