The original of this article QQ Space link: http://user.qzone.qq.com/29185807/blog/1462853926
The original article csdn blog link: http://blog.csdn.net/screscent/article/details/51362116
In the previous article, the analysis of Create and join was created and joined to the swarm cluster. So how the Swarm cluster works and manages it.
Let's analyze it below. 1, Swarm manage main body construction process
Let's see how the Manage command was built.
Code in Swarm\main.go
The action here is the Manage function.
Let's take a look at this function
Code in Swarm\manage.go
The above is mainly TLS configuration
It builds a store.
It builds a cluster
It builds a strategy
The above constructs a filter
It builds a discovery
It builds a scheduler
Finally, the API service is turned on
The overall build process is clear and modular is clear.
Here we have a module to analyze
2, Store
Code in Swarm\state\store.go
Let's look at the structure first.
The annotation here is very clear, is to have a simple key "--" requestedstate map storage
Let's see requestedstate.
Code in Swarm\state\state.go
Let's see Containerconfig again.
Code in Github.com\samalba\dockerclient\types.go
It's clear here that the store keeps the container information.
Here's what the store offers.
Newstore
Initializing directory paths and map Initialize
Called the Restore
Restore
Traverse all files in the directory and use JSON to load
Load
Using JSON to parse a file get
Find the corresponding information from the map Add
Called the set set
Write the information to the file and save the information to the map remove
Delete the file and delete the information in the map Replace
Replace
Summary
Stroe is also very simple, mainly maintaining a directory file and a map store.
If there is a place where the explanation is wrong, please forgive me and look at it.
Hao Haohua
QQ Crescent moon Lonely Road length 29185807
May 10, 2016
(Copyright statement: This article for the author original, if you need to reprint, please notify me, and indicate the source and author.) Reproduced without authorization, reserve the right to pursue its infringement. )