Hadoop 2.0 Yarn code: RM and NM code _ heartbeat-driven service analysis _ 1 Initial Stage (before Job submission)

Source: Internet
Author: User

1. Overview

When RM (ResourcesManager) and NM (NodeManager) Start services of all modules one after another, NodeStatusUpdater is started. NodeStatusUpdater uses Hadoop RPC to remotely call functions in ResourcesTrackerService and initialize resources, prepare the Job to be run. The following mainly analyzes the operations of RM and NM on the heartbeat driver before Job submission.

Mainly involved java files

Packages under hadoop-yarn-server-resourcemanager

  • Org. apache. hadoop. yarn. server. resourcemanager

    • ResourceTrackerService. java
  • Org. apache. hadoop. yarn. server. resourcemanager. schedager. fifo
    • Kerberoscheduler. java
  • Org. apache. hadoop. yarn. server. resourcemanager. rmnode
    • RMNodeImpl. java

 

Packages under hadoop-yarn-server-nodemanager

  • Org. apache. hadoop. yarn. server. nodemanager

    • NodeStatusUpdaterImpl. java

 

2. Code Analysis

Each service code has been started, and NodeStatusUpdate starts to drive the entire Hadoop operation.

1). NodeStatusUpdaterImpl (NodeManager side ):

  • Once NodeStatusUpdaterImpl is started, the start () function is called to initialize the Hadoop RPC server (call the getServer function to create a service ).
  • The start () function calls the registerWithRM () function and the startStatusUpdater () function in sequence.
  • RegisterWithRM () function
    • Set necessary configuration information and security authentication operations
    • Use Hadoop RPC to remotely call the registerNodeManager () method under ResourcesTrackerService on the RM end. For details, see registerNodeManager () code analysis under ResourcesTrackerService.
  • StartStatusUpdater () function
    • Create a thread and start it. All operations are in the while loop.
    • Set, obtain, and output necessary configuration information. It is important to call the getNodeStatus () method to obtain the status of the local iner and local Node for use by the subsequent nodeHeartbeat () method.
    • Use Hadoop RPC to remotely call the nodeHeartbeat () function under ResourcesTrackerService on the RM end and send heartbeat information to RM at a certain interval using the while loop. For the heartbeat operation, see the nodeHeartbeat () function under ResourcesTrackerService
    • NodeHeartbeat () will return the information to the NM. Based on the returned response, mark the unnecessary Container and Application Based on the information returned by the response and send the corresponding FINISH_CONTAINERS and FINISH_APPS to the ContainerManager, clean up ---- see the code analysis below for details

 

2). ResourceTrackerService (ResourcesManager side ):

  • ResourceTrackerService starts with NodeStatusUpdaterImpl. The start () function is called to initialize the Hadoop RPC server. Wait for a remote call to the function in ResourceTrackerService.
  • The Hadoop RPC call to registerNodeManager () and nodeHeartbeat () in NodeStatusUpdaterImpl is shown in the following figure.

The following table is divided into two parts: registerNodeManager () and nodeHeartbeat ---

 

Part 1:

1). Connect to the registerNodeManager () function under ResourceTrackerService.

  • First, obtain the local NodeID and the corresponding host name, port, and request resource information.
  • Perform Security Authentication and other auxiliary operations to check whether the Node marked by the NodeID is "valid". If "invalid", return immediately
  • Node "valid" indicates that this Node is available. Therefore, RMNode (new RMNodeImpl) is created to identify the Node status and monitor the Container and Application running on this Node.
  • Determines whether it is a new RMNode. If yes, it sends RMNodeEventType. STARTED
  • If it is not a new RMNode, send RMNodeEventType. RECONNECTED to RMNode and reconnect to the Node. See additional code analysis.
  • Finally, return the operation result to the caller.

 

2). RMNodeImpl: When RMNodeEventType. STARTED is received (followed by 1), NodeState (NEW → RUNNING) is transferred, and the Transition function is called.

  • Send NODE_ADDED to the scheduler.
  • Determine whether the Node is Inactive. If the Node is Inactive, the Node is removed from Inactive; otherwise, the number of ActiveNodes is increased.

 

3). Accept oschedded: receives the NODE_ADDED event, calls the addNode () function, and reports the status of the newly added Node to RM.

  • The addNode function is called. First, the node ID of the received RMNode and its newly created SchedulerNode (including various operations on the resource) are placed in the node object of the ConcurrentHashMap type.
  • Call the addTo () function under Resources to accumulate the number of Node Resources to calculate the number of Resources in the cluster.

 

Now the Node at the NM end has been added to the RM jurisdiction, and the NM is successfully registered to the RM

 

Additional code analysis

Additional 2). RMNodeImpl: When RMNode receives RMNodeEventType. RECONNECTED (connected to 1), the current status remains unchanged (RUNNING or UNHEALTHY), and the Transition function is called.

  • First, send the NODE_REMOVED event to the scheduler to delete the current Node.
  • Then reconnect. If the newly connected Node is the same as the last disconnected Node, the NODE_ADDED event is directly sent to the scheduler. If the two nodes are not the same, then, update the parameter about the Node and add the new Node to the node object of the ConcurrentHashMap type (the same as that in the previous javasoscheduler)
  • Finally, send RMNodeEventType. STARTED to the new RMNode.

3). Invoke oscheded: receives the NODE_REMOVED event and calls the removeNode () function.

  • In the removeNode () function, Kill all the containers on the Node and send RMContainerEventType. KILL. Because no Job is running, no Container can be killed.
  • Remove the Node from nodes, compute the cluster resources, and deduct the number of Node resources from the total cluster resources.

 

 

Part 2

1 ). according to the nodeHeartbeat () function under ResourceTrackerService, each NM has been registered to RM, and each NM starts to call this function to send a "Heartbeat" to RM to keep in touch, in addition, we will discuss the situation where no Job is submitted.

  • Obtain the required parameter variables, such as NodeStatus and NodeId.
  • Verify that the "heartbeat" NM sent has been registered with RM. If it is not registered, it will be returned to NM for reboot) register to RM (in fact, let NodeStatusUpdater skip this loop ).
  • Verify that this NM is "valid" (valid: the host queue contains this NM or the blacklist does not have this NM). If "invalid", RMNodeEventType is sent. DECOMMISSION to the corresponding RMNode of the nm, and close (shutdown) the NM --- the downlink appending 2)
  • Verify whether the "Heartbeat" is repeated with the previous "Heartbeat" or is not a new "Heartbeat". This is achieved through the heartbeat ID. If it is repeated, the heartbeat information is output and returned directly, if it is not a new heartbeat, RMNodeEventType is sent to RMNode. REBOOTING, and then return reboot to "restart" The NM (same as the above NodeStatusUpdater skips when this loop) --- append 2)
  • Set a new heartbeat ID to obtain information about the Container and Application.
  • Send the RMNodeStatusEvent that contains STATUS_UPDATE, iner, Application, and other information to RMNode, and then return the corresponding set response to the caller.

 

2). RMNodeImpl: RMNode receives RMNodeStatusEvent that contains STATUS_UPDATE, iner, Application, and other information. RMNodeImpl migrates NodeState (RUNNING → UNHEALTHY or RUNNING → RUNNING) and the Transition function is called.

  • Obtain the necessary variables from RMNodeStatusEvent, and then judge the "Health" status of the corresponding Node. If a problem occurs, report the Node to the scheduler NODE_REMOVED, then, the scheduler deletes the NM from the cluster management (see Appendix 3 in part 1), sends NODE_UNUSABLE to NodeListManager, and places its RMNode in the set of "unusable, nodeState (RUNNING → UNHEALTHY) of RMNodeImpl)
  • If it is "healthy", it runs smoothly and obtains information about the iner remotely transmitted by NM (transmitted when nodeHeartbeat () is called by Hadoop RPC on the NM end ),

 

Note:

During this discussion, no Job is submitted, and no iner is started on the NM end. The List containing the Container status in the event sent by NM to RM is empty, therefore, only sending "Heartbeat" indicates that the NM activity information is not actually processed, and the RM end does not have Application processing. Accepting "Heartbeat" will only send the RMNodeCleanContainerEvent event to the RMNode, clean up the inerlaunchedonnode function that may interact with each other (for the corresponding code, see containerLaunchedOnNode function under javasoscheduler ). For details, see the following article: RM and NM code_heartbeat driver service analysis _ 2 Container configuration and allocation (Job submission. NodeState (RUNNING → RUNNING) of RMNodeImpl)

 

So far, the RM-NM code has been started, RM and NM between a certain interval with heartbeat interaction information, waiting for the Job to submit

 

Additional code analysis

Additional 2) RMNodeImpl: When RMNode receives RMNodeEventType. DECOMMISSION), status transfer NodeState (RUNNING → DECOMMISSIONED) occurs, and the Transition function is called,

  • Set DECOMMISSIONED to finalState
  • When it is similar to RMNodeEventType. REBOOTING, set REBOOTING to finalState.

 

For analysis, for example, the white line is the first part, the initial NM is registered to the RM stage, the yellow line is the second part, and the NM sends the "Heartbeat" information to the RM stage.

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.