Docker Swarm程式碼分析筆記(10)——Cluster.validatePendingEngine

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

Cluster.validatePendingEngine是實際上用來串連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, don't get a hold    // of 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[engine.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 rebooted and get new IP from DHCP, previous address will 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.validatePendingEngine永遠操作Cluster.pendingEngines裡的Engine,如果串連Docker engine成功,就會把這個Engine移到Cluster.engines這個map裡。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.