Github user hyunsik commented on a diff in the pull request:

    https://github.com/apache/tajo/pull/608#discussion_r34887805
  
    --- Diff: tajo-core/src/main/java/org/apache/tajo/master/rm/NodeStatus.java 
---
    @@ -0,0 +1,293 @@
    +/**
    + * 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.tajo.master.rm;
    +
    +import io.netty.util.internal.PlatformDependent;
    +import org.apache.commons.logging.Log;
    +import org.apache.commons.logging.LogFactory;
    +import org.apache.hadoop.yarn.event.EventHandler;
    +import org.apache.hadoop.yarn.state.*;
    +import org.apache.tajo.master.cluster.WorkerConnectionInfo;
    +import org.apache.tajo.resource.NodeResource;
    +import org.apache.tajo.resource.NodeResources;
    +import org.apache.tajo.util.TUtil;
    +
    +import java.util.EnumSet;
    +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
    +import java.util.concurrent.atomic.AtomicLongFieldUpdater;
    +
    +/**
    + * It contains resource and various information for a node.
    + */
    +public class NodeStatus implements EventHandler<NodeEvent>, 
Comparable<NodeStatus> {
    +  /** class logger */
    +  private static final Log LOG = LogFactory.getLog(NodeStatus.class);
    +
    +  /** context of {@link TajoResourceManager} */
    +  private final TajoRMContext rmContext;
    +
    +  /** last heartbeat time */
    +  private volatile long lastHeartbeatTime;
    +
    +  private volatile int numRunningTasks;
    +
    +  private volatile int numRunningQueryMaster;
    +
    +  private static AtomicLongFieldUpdater HEARTBEAT_TIME_UPDATER;
    +  private static AtomicIntegerFieldUpdater RUNNING_TASK_UPDATER;
    +  private static AtomicIntegerFieldUpdater RUNNING_QM_UPDATER;
    +
    +  static {
    +    HEARTBEAT_TIME_UPDATER = 
PlatformDependent.newAtomicLongFieldUpdater(NodeStatus.class, 
"lastHeartbeatTime");
    +    if (HEARTBEAT_TIME_UPDATER == null) {
    +      HEARTBEAT_TIME_UPDATER = 
AtomicLongFieldUpdater.newUpdater(NodeStatus.class, "lastHeartbeatTime");
    +      RUNNING_TASK_UPDATER = 
AtomicIntegerFieldUpdater.newUpdater(NodeStatus.class, "numRunningTasks");
    +      RUNNING_QM_UPDATER = 
AtomicIntegerFieldUpdater.newUpdater(NodeStatus.class, "numRunningQueryMaster");
    +    } else {
    +      RUNNING_TASK_UPDATER = 
PlatformDependent.newAtomicIntegerFieldUpdater(NodeStatus.class, 
"numRunningTasks");
    +      RUNNING_QM_UPDATER = 
PlatformDependent.newAtomicIntegerFieldUpdater(NodeStatus.class, 
"numRunningQueryMaster");
    +    }
    +  }
    +
    +  /** Available resources on the node. */
    +  private final NodeResource availableResource;
    +
    +  /** Total resources on the node. */
    +  private final NodeResource totalResourceCapability;
    +
    +  /** Node connection information */
    +  private WorkerConnectionInfo connectionInfo;
    +
    +  private static final ReconnectNodeTransition RECONNECT_NODE_TRANSITION = 
new ReconnectNodeTransition();
    +  private static final StatusUpdateTransition STATUS_UPDATE_TRANSITION = 
new StatusUpdateTransition();
    +
    +  private static final StateMachineFactory<NodeStatus,
    +      NodeState,
    +      NodeEventType,
    +      NodeEvent> stateMachineFactory
    +      = new StateMachineFactory<NodeStatus,
    +      NodeState,
    +      NodeEventType,
    +      NodeEvent>(NodeState.NEW)
    +
    +      // Transition from NEW
    +      .addTransition(NodeState.NEW, NodeState.RUNNING,
    +          NodeEventType.STARTED,
    +          new AddNodeTransition())
    +
    +      // Transition from RUNNING
    +      .addTransition(NodeState.RUNNING, EnumSet.of(NodeState.RUNNING, 
NodeState.UNHEALTHY),
    +          NodeEventType.STATE_UPDATE,
    +          STATUS_UPDATE_TRANSITION)
    +      .addTransition(NodeState.RUNNING, NodeState.LOST,
    +          NodeEventType.EXPIRE,
    +          new DeactivateNodeTransition(NodeState.LOST))
    +      .addTransition(NodeState.RUNNING, NodeState.RUNNING,
    +          NodeEventType.RECONNECTED,
    +          RECONNECT_NODE_TRANSITION)
    +
    +      // Transitions from UNHEALTHY state
    +      .addTransition(NodeState.UNHEALTHY, EnumSet.of(NodeState.RUNNING, 
NodeState.UNHEALTHY),
    +          NodeEventType.STATE_UPDATE,
    +          STATUS_UPDATE_TRANSITION)
    +      .addTransition(NodeState.UNHEALTHY, NodeState.LOST,
    +          NodeEventType.EXPIRE,
    +          new DeactivateNodeTransition(NodeState.LOST))
    +      .addTransition(NodeState.UNHEALTHY, NodeState.UNHEALTHY,
    +          NodeEventType.RECONNECTED,
    +          RECONNECT_NODE_TRANSITION);
    +
    +  private final StateMachine<NodeState, NodeEventType, NodeEvent> 
stateMachine =
    +      stateMachineFactory.make(this, NodeState.NEW);
    +
    +  public NodeStatus(TajoRMContext rmContext, NodeResource 
totalResourceCapability, WorkerConnectionInfo connectionInfo) {
    +    this.rmContext = rmContext;
    +
    +    this.connectionInfo = connectionInfo;
    +    this.lastHeartbeatTime = System.currentTimeMillis();
    +    this.totalResourceCapability = totalResourceCapability;
    +    this.availableResource = NodeResources.clone(totalResourceCapability);
    +  }
    +
    +  public int getWorkerId() {
    +    return connectionInfo.getId();
    +  }
    +
    +  public WorkerConnectionInfo getConnectionInfo() {
    +    return connectionInfo;
    +  }
    +
    +  public void setLastHeartbeatTime(long lastheartbeatReportTime) {
    +    HEARTBEAT_TIME_UPDATER.lazySet(this, lastheartbeatReportTime);
    +  }
    +
    +  public void setNumRunningQueryMaster(int numRunningQueryMaster) {
    +    RUNNING_QM_UPDATER.lazySet(this, numRunningQueryMaster);
    +  }
    +
    +  public int getNumRunningQueryMaster() {
    +    return numRunningQueryMaster;
    +  }
    +
    +  public void setNumRunningTasks(int numRunningTasks) {
    +    RUNNING_TASK_UPDATER.lazySet(this, numRunningTasks);
    --- End diff --
    
    ``RUNNING_TASK_UPDATE`` contains the number of running tasks. But, the 
getter method ``getNumRunningTasks()`` uses just the member variable 
``numrunningTasks``. It seems to be invalid.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to