jeongyooneo commented on a change in pull request #21: [NEMO-46] Make the operations on ExecutorRegistry atomic URL: https://github.com/apache/incubator-nemo/pull/21#discussion_r189777512
########## File path: runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/ExecutorRegistry.java ########## @@ -15,190 +15,98 @@ */ package edu.snu.nemo.runtime.master.scheduler; +import com.google.common.annotations.VisibleForTesting; +import edu.snu.nemo.common.Pair; import edu.snu.nemo.runtime.master.resource.ExecutorRepresenter; import org.apache.reef.annotations.audience.DriverSide; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.NotThreadSafe; +import javax.annotation.concurrent.ThreadSafe; import javax.inject.Inject; import java.util.*; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.stream.Collectors; /** - * (WARNING) This class is not thread-safe. - * (i.e., Only a SchedulingPolicy accesses this class) - * + * (WARNING) This class must be thread-safe. * Maintains map between executor id and {@link ExecutorRepresenter}. */ @DriverSide -@NotThreadSafe +@ThreadSafe public final class ExecutorRegistry { - private final Map<String, ExecutorRepresenter> runningExecutors; - private final Map<String, ExecutorRepresenter> failedExecutors; - private final Map<String, ExecutorRepresenter> completedExecutors; - - @Inject - public ExecutorRegistry() { - this.runningExecutors = new HashMap<>(); - this.failedExecutors = new HashMap<>(); - this.completedExecutors = new HashMap<>(); - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer(); - sb.append("Running: "); - sb.append(runningExecutors.toString()); - sb.append("/ Failed: "); - sb.append(failedExecutors.toString()); - sb.append("/ Completed: "); - sb.append(completedExecutors.toString()); - return sb.toString(); - } - /** - * @param executorId the executor id - * @return the corresponding {@link ExecutorRepresenter} that has not failed - * @throws NoSuchExecutorException when the executor was not found + * States of an executor. */ - @Nonnull - public ExecutorRepresenter getExecutorRepresenter(final String executorId) throws NoSuchExecutorException { - try { - return getRunningExecutorRepresenter(executorId); - } catch (final NoSuchExecutorException e) { - return getFailedExecutorRepresenter(executorId); - } + enum ExecutorState { + RUNNING, + FAILED, + COMPLETED Review comment: How about `TERMINATED` instead of `COMPLETED`? `COMPLETED` seems more suitable for entities like `Job`s or `Task`s, not executors that run them. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services