Docker Swarm Code Analysis Note (--cluster.validatependingengine)

Source: Internet
Author: User
Tags docker swarm
This is a creation in Article, where the information may have evolved or changed.

Cluster.validatePendingEngineIs the code that is actually used to connect Docker engine :

Validatependingengine connects to the Engine,func (c *cluster) Validatependingengine (engine *cluster. Engine) bool {//Attempt a connection to the engine.    Since This is slow, and don ' t get a hold//of the The lock yet. If err: = engine. Connect (C.tlsconfig); Err! = Nil {log. Withfields (log. fields{"ADDR": Engine. ADDR}). DEBUGF ("Failed to validate pending node:%s", err) return false}//The following is critical and fast.    Grab a lock. C.lock () defer c.unlock ()//only validate engines from Pendingengines list if _, exists: = C.pendingengines[engi Ne.    ADDR];!exists {return false}//Make sure the engine ID is unique. If old, exists: = C.engines[engine.id]; exists {if old. Addr! = engine. Addr {log. Errorf ("ID duplicated. %s shared by%s and%s ', Engine.id, old. ADDR, engine.            ADDR)//Keep this engine in Pendingengines table and show its error. If it ' s ID duplication from VM clone, user see this MEssage and can fix it.  If the engine is a rebooted and get new IP from DHCP, previous address'll be removed//from discovery after            a while.            In both cases, retry may fix the problem. Engine. Handleidconflict (old. ADDR)} else {log. DEBUGF ("Node%q (name:%q) with address%q is already registered", Engine.id, engine. Name, engine. ADDR) engine. Disconnect ()//Remove it from pendingengines table Delete (C.pendingengines, engine. ADDR)} return False}//Engine validated, move from Pendingengines table to engines table Delete ( C.pendingengines, engine. ADDR)//Set engine state to healthy, and start refresh loop engine. Validationcomplete () c.engines[engine.id] = engine Log.infof ("registered engine%s at%s", engine. Name, engine. ADDR) return True}

Cluster.validatePendingEngineAlways in Operation Cluster.pendingEngines Engine , if the connection is Docker engine successful, it will be Engine moved to Cluster.engines this map .

Related Article

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.