Container upgrading method and device in distributed system, computer equipment and storage medium
By removing the temporary data of the old version in the distributed system, migrating the persistent objects of the new version to the mapping directory, and using point-to-point networks and symbolic links to perform container upgrades, the problem of persistent directory overwriting new images is solved, and flexible upgrades of containers and system consistency is achieved.
Patent Information
- Application Number
- CN202510173619.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-17
- Publication Date
- 2025-07-04
AI Technical Summary
During container upgrade, the persistent directory directly overwrites the directory or file in the new image, resulting in the default data loss, data conflicts, and running logic failure of the new version.
When upgrading containers for each node in a distributed system, temporary data or objects that have not been migrated by the old version, and persistent objects of the new version are migrated to the mapping directory, building a point-to-point network, creating symbolic links, producing and broadcasting new blocks based on the Genesis node, storing them to the local ledger, and upgrading according to the mapping directory and symbolic links.
It solves the problem of the persistent directory directly covering new images, improves the flexibility of the container iteration process, and ensures system consistency and normal operation of the container.
Smart Images

Figure CN120255919A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a method, apparatus, computer device, and storage medium for upgrading containers in a distributed system. Background Art
[0002] A distributed system is a computing system that connects multiple computers or nodes through a network to collaboratively complete computing tasks. These nodes communicate and coordinate with each other, presenting as a unified system. Each node can be regarded as a separate host; the host operating system manages the host file system and the containerization platform; the containerization platform manages the operation of the container and the container file system.
[0003] Currently, when upgrading a container, the persistent directory usually stores the business data generated during the operation of the previous version, while the directories or files in the new image contain the default data of the new version required after the upgrade. If the persistent directory directly overwrites the directories or files in the new image, the following problems may occur: 1. Loss of new version default data: The default configuration, initialization data, or important files in the new image may be overwritten, resulting in abnormal operation of the container after the upgrade; 2. Data conflict and consistency problems: The content or structure of the persistent data and the new image data may be incompatible, and direct overwriting may cause conflicts, affecting system consistency; 3. Failure of the running logic: Some upgrade logics may rely on specific files in the new image, and the persistent directory overwrite may cause these logics to not execute correctly.
[0004] Regarding the problems caused by the persistent directory directly overwriting the directories or files in the new image in the related art, no effective solution has been proposed yet. Summary of the Invention
[0005] In this embodiment, a method, apparatus, computer device, and storage medium for upgrading containers in a distributed system are provided to solve the problems caused by the persistent directory directly overwriting the directories or files in the new image in the related art.
[0006] In a first aspect, in this embodiment, a method for upgrading a container in a distributed system is provided. The distributed system includes several nodes, and each node is provided with a host operating system; the host operating system manages the host file system and the containerization platform, and the containerization platform manages the operation of the corresponding container and the container file system; the method includes:
[0007] When upgrading the containers of each node in the distributed system, remove the temporary data or objects of the containers of the old version that have not been migrated, and migrate the persistent objects of the new version of the containers to the mapping directory; the mapping directory is the directory corresponding to the container in the container file system; a peer-to-peer network is built among the nodes in the distributed system;
[0008] Create a first symbolic link in the container file system; the path of the first symbolic link is the same as the original path of the persistent object, and points to the persistent object in the mapping directory;
[0009] Select a genesis node from all the nodes of the peer-to-peer network, and based on the genesis block of the genesis node, produce and broadcast new blocks of all the nodes to the peer-to-peer network; and in each node, store the new blocks that pass the verification into the local ledger;
[0010] Upgrade each container according to the persistent objects in the mapping directory, the first symbolic link, the new blocks in the local ledger, and the pulled new version image.
[0011] In some embodiments, the method further includes:
[0012] After migrating the persistent objects of the new version of the container to the mapping directory, perform incremental upgrades on the old persistent objects in the mapping directory.
[0013] In some embodiments, the method further includes:
[0014] Obtain the version information of all nodes in the peer-to-peer network by accessing the ledger service of any node.
[0015] In some embodiments, the method further includes:
[0016] When the container in each node in the distributed system is started for the first time, map the mounting node in the host file system to the mapping directory in the container file system; and migrate the persistent objects in the container file system to the mapping directory; create a second symbolic link in the container file system; the path of the second symbolic link is the same as the original path of the persistent object, and points to the persistent object in the mapping directory;
[0017] Build a peer-to-peer network among the nodes in the distributed system, and select a genesis node from all the nodes of the peer-to-peer network;
[0018] Based on the genesis block of the genesis node, produce and broadcast new blocks of all the nodes to the peer-to-peer network; and in each of the nodes, store the verified new blocks into the local ledger.
[0019] Deploy each of the containers according to the persistent objects in the mapping directory, the second symbolic link, the new blocks of the local ledger, and the pulled new version images.
[0020] In some embodiments, selecting the genesis node from all the nodes of the peer-to-peer network includes:
[0021] Randomly select the genesis node from all the nodes of the peer-to-peer network;
[0022] Or, determine the scores of all the nodes of the peer-to-peer network; select the genesis node from all the nodes of the peer-to-peer network based on the scores.
[0023] In some embodiments, determining the scores of all the nodes of the peer-to-peer network includes:
[0024] Determine the scores of all the nodes of the peer-to-peer network based on a preset node score formula.
[0025] In some embodiments, the method further includes:
[0026] Periodically check whether the containers of each of the nodes are deployed.
[0027] In a second aspect, in this embodiment, an upgrade device for containers in a distributed system is provided. The distributed system includes a number of nodes, and each node is provided with a host operating system; the host operating system manages the host file system and the containerization platform, and the containerization platform manages the operation of the corresponding containers and the container file system; the device includes: a removal and migration module, a creation module, a selection module, and an upgrade module;
[0028] The removal and migration module is used to remove the temporary data or objects of the containers with the old version that have not been migrated and migrate the persistent objects of the new version of the containers to the mapping directory when the containers of each node in the distributed system are upgraded; the mapping directory is the directory corresponding to the container in the container file system; a peer-to-peer network is built between each of the nodes in the distributed system.
[0029] The creation module is used to create a first symbolic link in the container file system; the path of the first symbolic link is the same as the original path of the persistent object, and points to the persistent object in the mapping directory.
[0030] The selection module is used to select a genesis node from all the nodes of the peer-to-peer network, produce and broadcast new blocks of all the nodes to the peer-to-peer network based on the genesis block of the genesis node; and in each node, store the verified new blocks into the local ledger.
[0031] The upgrade module is used to upgrade each container according to the persistent objects in the mapping directory, the first symbolic link, the new blocks of the local ledger, and the pulled new version image.
[0032] In a third aspect, a computer device is provided in this embodiment, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the upgrade method of the container in the distributed system described in the first aspect above is implemented.
[0033] In a fourth aspect, a storage medium is provided in this embodiment, on which a computer program is stored. When the program is executed by a processor, the upgrade method of the container in the distributed system described in the first aspect above is implemented.
[0034] Compared with the related art, in the upgrade method, device, computer device, and storage medium of the container in the distributed system provided in this embodiment, when upgrading the containers of each node in the distributed system, the temporary data or objects of the containers of the old version that have not been migrated are removed, and the persistent objects of the new version of the containers are migrated to the mapping directory; the mapping directory is the directory corresponding to the container in the container file system; a peer-to-peer network is built between each node in the distributed system; a first symbolic link is created in the container file system; the path of the first symbolic link is the same as the original path of the persistent object, pointing to the persistent object in the mapping directory; a genesis node is selected from all the nodes of the peer-to-peer network, and new blocks of all the nodes are produced and broadcast to the peer-to-peer network based on the genesis block of the genesis node; and in each node, the verified new blocks are stored into the local ledger; each container is upgraded according to the persistent objects in the mapping directory, the first symbolic link, the new blocks of the local ledger, and the pulled new version image, without the need for cumbersome container driver configuration. A first symbolic link is established during the upgrade of the container, greatly improving the flexibility of the container iteration process; and by using the temporary mapping directory of the container, the problems caused by directly overwriting the directories or files in the new image by the persistent directory in the related art are solved; the upgrade of the container in the distributed system is realized.
[0035] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more concise and understandable. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings described herein are used to provide a further understanding of the present application and form a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:
[0037] Figure 1 is a flowchart of a method for upgrading a container in a distributed system provided by an embodiment of the present application;
[0038] Figure 2 is a flowchart of a deployment process of a container in a distributed system provided by an embodiment of the present application;
[0039] Figure 3 is a schematic diagram of a cycle synchronization process provided by an embodiment of the present application;
[0040] Figure 4 is a schematic diagram of a cycle check node container deployment provided by an embodiment of the present application;
[0041] Figure 5 is a structural block diagram of an apparatus for upgrading a container in a distributed system provided by an embodiment of the present application.
[0042] In the figure: 110, removal and migration module; 120, creation module; 130, selection module; 140, upgrade module. Detailed implementation manners
[0043] To more clearly understand the purpose, technical solution, and advantages of the present application, the present application will be described and explained below with reference to the accompanying drawings and embodiments.
[0044] Unless otherwise defined, technical or scientific terms used in this application shall have the ordinary meanings understood by those of ordinary skill in the technical field to which this application pertains. In this application, words such as "a", "an", "one", "the", "these", etc. do not denote a limitation in quantity and can be singular or plural. The terms "including", "comprising", "having" and any variations thereof used in this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The terms "connected", "coupled" and similar words used in this application do not limit to physical or mechanical connections, but may include electrical connections, whether directly or indirectly. The term "plurality" used in this application means two or more. "And / or" describes the association relationship of associated objects and indicates that three relationships can exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, and B exists alone. Usually, the character " / " indicates that the objects associated before and after are in an "or" relationship. The terms "first", "second", "third", etc. used in this application only distinguish similar objects and do not represent a specific order for the objects.
[0045] The method embodiments provided in this embodiment can be executed in a distributed system or a similar system. For example, running on a distributed system, a distributed system is a computing system that connects multiple computers or nodes together through a network to cooperate in completing computing tasks. These nodes communicate and coordinate with each other and behave as a unified system. A distributed system can include several nodes, and each node can be regarded as a separate host; a host operating system is provided in the host; the host operating system manages the host file system and the containerization platform, and the containerization platform manages the operation of the corresponding containers and the container file system.
[0046] Among them, the containerization platform is a platform for realizing the containerization process. In software engineering, container technology is a lightweight operating system-level virtualization technology that provides a resource-independent running environment for software applications and their dependent components. During the containerization process, the application program and all its necessary dependencies are packaged into a reusable image. The image running environment does not share memory, CPU and hard disk space with the main operating system to ensure the independence of the processes inside the container from the external processes. Among them, an image is a read-only template used to indicate the creation of containers. A container is a runnable instance of an image.
[0047] In this embodiment, a method for upgrading containers in a distributed system is provided. Figure 1 It is a flowchart of the method for upgrading containers in the distributed system of this embodiment, as Figure 1 shown. The process includes the following steps:
[0048] Step S110, when upgrading the containers of each node in the distributed system, remove the temporary data or objects of the containers of the old version that have not been migrated, and migrate the persistent objects of the new version of the containers to the mapping directory; the mapping directory is the directory corresponding to the container in the container file system; a peer-to-peer network is built between each node in the distributed system.
[0049] Step S120, create a first symbolic link in the container file system; the path of the first symbolic link is the same as the original path of the persistent object, and points to the persistent object in the mapping directory.
[0050] Step S130, select a genesis node from all the nodes of the peer-to-peer network, and based on the genesis block of the genesis node, produce and broadcast the new blocks of all the nodes to the peer-to-peer network; and in each node, store the new blocks that pass the verification into the local ledger.
[0051] Step S140, upgrade each container according to the persistent object in the mapping directory, the first symbolic link, the new block of the local ledger, and the pulled new version image.
[0052] Specifically, the mapping directory is preset, and it is the directory for mapping corresponding to the container in the container file system. The mounting node in the host operating system can be mapped to this mapping directory. The containers of each node in the distributed system need to be upgraded due to reasons such as operation and maintenance management requirements, environment configuration requirements, software update requirements, etc.; when upgrading the containers of each node, remove the temporary data or objects of the containers of the old version that have not been migrated, and migrate the persistent objects of the new version of the containers to the mapping directory. The old version can be the previous version; then what can be removed are the temporary data or objects (directories or files) of the containers of the previous version that have not been migrated to the mapping directory. The persistent objects include but are not limited to all directories or files that need to be persisted. In this embodiment, the mapping directory is used to replace the persistent directory in the related technology to realize the centralized management of the persistent data of the containers, thereby avoiding the problems caused by the persistent directory directly overwriting the directories or files in the new image.
[0053] Among them, the first symbolic link is pre-created. Also known as a soft link, it is a special type of file that contains a reference pointing to another file or directory in the form of an absolute path or a relative path. The operation of the first symbolic link is transparent: a program that reads and writes to the first symbolic link file will behave as if it is operating directly on the target file. Some programs that need to handle the first symbolic link specially (such as backup programs) may recognize and operate on it directly. A first symbolic link file only contains a text string, which is interpreted by the operating system as a path pointing to another file or directory. It is an independent file, and its existence does not depend on the target file. If a first symbolic link is deleted, the target file it points to is not affected. If the target file is moved, renamed, or deleted, any first symbolic link pointing to it still exists, but they will point to a non-existent file. This situation is sometimes referred to as "orphaned". The path of the first symbolic link is the same as the original path of the persistent object, pointing to the persistent object in the mapped directory, and using the first symbolic link as the basis for implementing communication in a distributed system.
[0054] Among them, a point-to-point network is constructed between nodes in the distributed system. The point-to-point network and the consensus mechanism of the distributed system ensure data replication across nodes. Through random selection, based on a scoring mechanism, etc., a genesis node is selected from all nodes in the point-to-point network; centered on this genesis node, through the genesis block of this genesis node, new blocks of all nodes are produced and broadcast to the point-to-point network; and in each node, the verified new blocks are stored in the local ledger, so that all nodes can record information about the new version of the container. Among them, the genesis block contains "the hash value of the shared key and the timestamp", "the timestamp", etc. After all nodes receive the genesis block, they use the shared key to decrypt and verify it. If the block verification passes, the node will save the genesis block locally and start continuously synchronizing the ledgers of other nodes in a cycle to ensure the consistency of the upgraded version.
[0055] Finally, based on the persistent object in the mapped directory, the first symbolic link, the new blocks in the local ledger, and the pulled new version image, the upgrade of each container is completed; it is ensured that centralized management of data in a containerized environment is achieved, the flexibility of the container iteration process is improved, and the problems caused by directly overwriting the directories or files in the new image by the persistent directory in related technologies can be solved.
[0056] In the related art, when a container is upgraded, the persistent directory usually stores the business data generated during the operation of the previous version, while the directories or files in the new image contain the default data of the new version required after the upgrade. If the persistent directory directly overwrites the directories or files in the new image, the following problems may occur: 1. Loss of default data in the new version: The default configuration, initialization data, or important files in the new image may be overwritten, resulting in abnormal operation of the container after the upgrade; 2. Data conflict and consistency issues: The content or structure of the persistent data and the new image data may be incompatible, and direct overwriting may cause conflicts, affecting system consistency; 3. Failure of the running logic: Some upgrade logics may rely on specific files in the new image, and the persistent directory overwrite may cause these logics to fail to execute correctly. Therefore, there are problems caused by the persistent directory directly overwriting the directories or files in the new image. Through the above steps, when the containers of each node in the distributed system are upgraded, the temporary data or objects of the containers of the old version that have not been migrated are removed, and the persistent objects of the new version of the containers are migrated to the mapping directory; the mapping directory is the directory corresponding to the container in the container file system; a point-to-point network is built between each node in the distributed system; a first symbolic link is created in the container file system; the path of the first symbolic link is the same as the original path of the persistent object, and it points to the persistent object in the mapping directory; the genesis node is selected from all the nodes of the point-to-point network, and based on the genesis block of the genesis node, new blocks of all the nodes are generated and broadcast to the point-to-point network; and in each node, the new blocks that pass the verification are stored in the local ledger; according to the persistent objects in the mapping directory, the first symbolic link, the new blocks of the local ledger, and the pulled new version image, each container is upgraded, and there is no need for cumbersome container driver configuration. A first symbolic link is established during the upgrade of the container, greatly improving the flexibility of the container iteration process; and by using the temporary mapping directory of the container, the problems caused by the persistent directory directly overwriting the directories or files in the new image in the related art are solved; the upgrade of the containers in the distributed system is realized.
[0057] The above process will be described in detail below:
[0058] In some of these embodiments, the method for upgrading a container in a distributed system further includes the following steps:
[0059] After migrating the persistent objects of the new version of the container to the mapping directory, perform an incremental upgrade on the old persistent objects in the mapping directory.
[0060] Specifically, incremental upgrade refers to processing such as storing key data of old persistent objects in the mapping directory and adding new attributes according to user requirements. Taking Python language and SQLite database as an example of persistent storage, assume that the old persistent object is a record in the database and there is a new object model that needs to update these records: First, it is necessary to connect to the database storing the old objects. Second, assume that the old object model corresponds to the table structure in the database, and the new object model is the structure to which it needs to be upgraded. For example, the old table may only have name and age fields, and the new model needs to add an email field. Third, read the old persistent objects. Finally, upgrade each old persistent object and add new attributes (at the database level, new columns can be added through the ALTER TABLE statement and then the data can be updated).
[0061] Through this embodiment, incremental upgrade can be performed on the old persistent objects in the mapping directory, improving the utilization of the old persistent objects.
[0062] In some of these embodiments, the method for upgrading containers in a distributed system further includes the following steps:
[0063] By accessing the ledger service of any node, obtain the version information of all nodes in the peer-to-peer network.
[0064] Specifically, since a peer-to-peer network is built among the nodes in the distributed system, the peer-to-peer network and the consensus mechanism of the distributed system ensure data replication across nodes, and each node periodically synchronizes the ledgers of other nodes. Therefore, users can directly obtain the version information of all nodes in the peer-to-peer network by accessing the ledger service of any node, thus greatly simplifying the cost for users to know the versions of each node and facilitating management.
[0065] The above process is the process of upgrading containers in a distributed system, realizing that the upgrade process of all nodes in the distributed system is traceable and tamper-proof, providing a powerful final state control mechanism for the distributed system, and ensuring the consistency of all node versions after the upgrade of the entire system.
[0066] The following introduces the deployment process of containers in a distributed system:
[0067] In some of these embodiments, as Figure 2 shown, the method for upgrading containers in a distributed system further includes the following steps:
[0068] Step S210, when the container in each node of the distributed system is started for the first time, map the mounted nodes in the host file system to the mapped directory in the container file system; migrate the persistent objects in the container file system to the mapped directory; create a second symbolic link in the container file system; the path of the second symbolic link is the same as the original path of the persistent object, pointing to the persistent object in the mapped directory.
[0069] Step S220, construct a peer-to-peer network among the nodes in the distributed system, and select a genesis node from all the nodes in the peer-to-peer network.
[0070] Step S230, based on the genesis block of the genesis node, produce and broadcast new blocks of all nodes to the peer-to-peer network; and in each node, store the verified new blocks into the local ledger.
[0071] Step S240, deploy each container according to the persistent objects in the mapped directory, the second symbolic link, the new blocks in the local ledger, and the pulled new version images.
[0072] Specifically, all nodes in the distributed system can form a cluster; this cluster can be created by the user. Node information is injected into the container process of each node through environment variables; the node information includes but is not limited to node ID, shared key (the same key for all nodes), version information, set of IP addresses of other nodes, etc. When the container in each node of the distributed system is started for the first time, map the mounted nodes in the host file system to the mapped directory in the container file system; migrate the persistent objects (all directories or files that need to be persisted) in the container file system to the mapped directory; create a second symbolic link in the container file system; the path of the second symbolic link is the same as the original path of the persistent object, pointing to the persistent object in the mapped directory.
[0073] Verify identities using the efficacy keys between all nodes. If the nodes pass the identity verification, the peer-to-peer network between the corresponding nodes is completed. Based on this, complete the construction of the peer-to-peer network among the nodes in the distributed system; and select a genesis node from all the nodes in the peer-to-peer network by means of random selection, based on a scoring mechanism, etc.; with this genesis node as the center, through the genesis block of this genesis node, produce and broadcast new blocks of all nodes to the peer-to-peer network; and in each node, store the verified new blocks into the local ledger, so that all nodes can record information about the new version of the container. Among them, the genesis block contains "hash value of the shared key and timestamp", "timestamp", etc. After all nodes receive the genesis block, they use the shared key to decrypt and verify it. If the block verification passes, the node will save the genesis block locally and start continuously synchronizing the ledgers of other nodes in a cycle to ensure version consistency.
[0074] Finally, upgrade each container according to the persistent objects in the mapping directory, the second symbolic link, the new blocks of the local ledger, and the pulled new version images, ensuring centralized data management in the containerized environment and enhancing the flexibility of the container iteration process.
[0075] After the above process is completed on all nodes, it can be considered that the deployment of all nodes in the distributed system is completed. Among them, the first symbolic link and the second symbolic link are both symbolic links, but they are used in different scenarios. The mapping directory, the genesis block, etc. are similar, and will not be repeated here.
[0076] Through this embodiment, the deployment of containers in the distributed system can be quickly completed, the upgrade process of all nodes in the distributed system can be traced and cannot be tampered with, providing a powerful final state control mechanism for the distributed system, and ensuring the consistency of all node versions after the upgrade of the entire system.
[0077] In some of these embodiments, the periodic synchronization process is as Figure 3 shown. All nodes respectively generate new blocks, write their own node information and version information into the new blocks, and then broadcast the new blocks to the entire peer-to-peer network. After receiving the new blocks, other nodes decrypt the new blocks using the shared key, verify whether the timestamp of the new block is within the specified time window (to prevent rollback attacks), and ensure that the previous hash of the new block is consistent with the previous block, that is, the integrity of the blockchain. If the verification passes, the node stores the new block in the local ledger. And each new block will be propagated to all participating nodes through the peer-to-peer network. Over time, all nodes will synchronize to the latest ledger state, and the ledger records the version information of all nodes.
[0078] Among them, the Hash calculation method is: Hash = HMAC(shared_key, timestamp); in the formula, HMAC (Hash-based Message Authentication Code) is a message authentication mechanism based on a hash function and a key, used to verify the integrity and authenticity of a message. shared_key is the shared key (the keys of all nodes are the same); timestamp is the content broadcast by the block, which contains the timestamp and the Hash value. The timestamp is a time stamp in milliseconds (ms).
[0079] Among them, the time window verification is: |current_time–timestamp| / 1000 <= windowTime; where current_time is its own timestamp in ms, and windowTime is the time window range which can be set by oneself in seconds s.
[0080] The verification method is as follows: The node calculates its own Hash1 through HMAC(shared_key,timestamp), and broadcasts Hash1 and timestamp to other nodes; other nodes receive Hash1 and timestamp, calculate Hash2 through HMAC(shared_key,timestamp), and verify whether the value of Hash2 is the same as that of Hash1, and whether timestamp is within the time window (to prevent rollback attacks). It can be seen that the key point of verification lies in shared_key. If the shared_keys between nodes are different, they cannot pass the HMAC verification. If the verification passes, the node stores the new block in the local ledger. Through the above verification, the integrity of the blockchain can be ensured.
[0081] It should be noted that the implementation process of step S130 is the same, so it will not be repeated here.
[0082] In some of these embodiments, selecting the genesis node from all nodes of the peer-to-peer network in step S220 includes the following steps:
[0083] Step S221, randomly select the genesis node from all nodes of the peer-to-peer network;
[0084] Step S222, or, determine the scores of all nodes of the peer-to-peer network; select the genesis node from all nodes of the peer-to-peer network based on the scores.
[0085] Specifically, there are various ways to select the genesis node.
[0086] Method 1: Randomly select the genesis node from all nodes of the peer-to-peer network. This method can reduce the demand for computing resources and improve the efficiency of container deployment and upgrade.
[0087] Method 2: Determine the scores of all nodes of the peer-to-peer network; select the genesis node from all nodes of the peer-to-peer network based on the scores. Specifically, it can be to determine the scores of all nodes of the peer-to-peer network based on a preset node score formula.
[0088] Exemplarily: Assume there are N nodes in the distributed system, and each node is set as i.
[0089] Calculate the score Si of each node in the peer-to-peer network. The calculation formula for the score Si is as follows:
[0090]
[0091] where Wi is the performance weight of the node, representing the comprehensive ability indicators such as the computing power, bandwidth, and storage of the node. Ri is the random number of the node, and the value range of the random number can be set. R max represents the largest random number among all nodes, and R max = max(R1, R2,..., R N ). W max represents the largest weight among all nodes; W max = max(W1, W2,..., W N ). α ∈ [0, 1] is the balance factor, and the default value is 0.5, which can be set; when α = 0, the election result is completely determined by the performance (W max ); when α = 1, it is completely random, and the election result has nothing to do with the performance.
[0092] Specifically, the performance weight Wi of the node can be expressed as:
[0093] W i = a·CPU i + b·Bandwidth i + c·Storage i + d·Uptime i
[0094] where a, b, c, and d are weight coefficients and can be set. CPU is the CPU computing power. Bandwidth is the network bandwidth. Storage is the storage capacity (disk or memory size). Uptime is the online time of the node.
[0095] After all nodes calculate their own scores Si, select the node with the highest score Si as the genesis node.
[0096] Through this embodiment, the selection method of the genesis node can be determined according to the requirements of the application scenario, improving the applicability.
[0097] In some of these embodiments, the method for upgrading containers in a distributed system further includes the following steps:
[0098] Periodically check whether the containers of each node are deployed.
[0099] Specifically, the process of periodically checking the deployment of node containers is as Figure 4As shown, after the container deployment of node A is completed, check the deployment status of the containers of node B, check the deployment status of the containers of node C, and check the deployment status of the containers of node N until the container deployment of all nodes is completed. Among them, the inspection period can be set according to the application scenario, and there is no limit to this.
[0100] Through this embodiment, it is possible to ensure that the container deployment of all nodes is completed, providing guarantee for the subsequent upgrade of the containers.
[0101] It should be noted that the steps shown in the above process or the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order from here.
[0102] In this embodiment, an upgrade device for containers in a distributed system is also provided. This device is used to implement the above embodiments and preferred implementation manners, and those that have been described will not be repeated here. The following terms such as "module", "unit", "sub-unit", etc. can be a combination of software and / or hardware that can achieve a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware is also possible and contemplated.
[0103] Figure 5 is the structural block diagram of the upgrade device for containers in the distributed system of this embodiment, as Figure 5 shown, this device includes: a removal and migration module 110, a creation module 120, a selection module 130, and an upgrade module 140;
[0104] The removal and migration module 110 is used to remove the temporary data or objects of the containers of the old version that have not been migrated when the containers of each node in the distributed system are upgraded, and migrate the persistent objects of the new version of the containers to the mapping directory; the mapping directory is the directory corresponding to the container in the container file system; a point-to-point network is built between each node in the distributed system;
[0105] The creation module 120 is used to create a first symbolic link in the container file system; the path of the first symbolic link is the same as the original path of the persistent object, and points to the persistent object in the mapping directory;
[0106] The selection module 130 is used to select the genesis node from all nodes of the point-to-point network, produce and broadcast the new blocks of all nodes to the point-to-point network based on the genesis block of the genesis node; and in each node, store the verified new blocks in the local ledger;
[0107] An upgrade module 140 for upgrading each container according to the persistent objects, the first symbolic links, the new blocks of the local ledger, and the pulled new version images in the mapping directory.
[0108] In some of these embodiments, the container upgrade device in the distributed system further includes: an incremental upgrade module;
[0109] The incremental upgrade module is used to perform incremental upgrades on the old persistent objects in the mapping directory after migrating the persistent objects of the new version of the container to the mapping directory.
[0110] With the above device, upgrading each container no longer requires cumbersome container driver configuration. Establishing the first symbolic link during container upgrade greatly improves the flexibility of the container iteration process; and using the temporary mapping directory of the container solves the problems caused by directly overwriting the directories or files in the new image with the persistent directory in the related art; realizing the upgrade of containers in the distributed system.
[0111] In some of these embodiments, the container upgrade device in the distributed system further includes: an acquisition module;
[0112] The acquisition module is used to obtain the version information of all nodes in the peer-to-peer network by accessing the ledger service of any node.
[0113] In some of these embodiments, the container upgrade device in the distributed system further includes: a deployment module;
[0114] The deployment module is used to, when the container in each node of the distributed system is started for the first time, map the mounted nodes in the host file system to the mapping directory in the container file system; and migrate the persistent objects in the container file system to the mapping directory; create a second symbolic link in the container file system; the path of the second symbolic link is the same as the original path of the persistent object, pointing to the persistent object in the mapping directory;
[0115] Construct a peer-to-peer network among the nodes in the distributed system and select a genesis node from all the nodes in the peer-to-peer network;
[0116] Based on the genesis block of the genesis node, produce and broadcast the new blocks of all nodes to the peer-to-peer network; and in each node, store the verified new blocks in the local ledger;
[0117] Deploy each container according to the persistent objects, the second symbolic links, the new blocks of the local ledger, and the pulled new version images in the mapping directory.
[0118] In some of these embodiments, the deployment module is further used to randomly select a genesis node from all the nodes in the peer-to-peer network;
[0119] Alternatively, determine the scores of all nodes in the peer-to-peer network; select the genesis node from all nodes in the peer-to-peer network based on the scores.
[0120] In some of these embodiments, the deployment module is further configured to determine the scores of all nodes in the peer-to-peer network based on a preset node score formula.
[0121] In some of these embodiments, the upgrade device for containers in the distributed system further includes: an inspection module;
[0122] The inspection module is configured to periodically check whether the containers of each node are deployed.
[0123] It should be noted that the above-mentioned respective modules can be functional modules or program modules, and can be implemented either by software or by hardware. For the modules implemented by hardware, the above-mentioned respective modules can be located in the same processor; or the above-mentioned respective modules can also be located in different processors in any combined form.
[0124] In this embodiment, a computer device is further provided, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any of the above method embodiments.
[0125] Optionally, the above computer device may further include a transmission device and input / output devices. Among them, the transmission device is connected to the above processor, and the input / output devices are connected to the above processor.
[0126] Optionally, in this embodiment, the above processor may be configured to execute the following steps through a computer program:
[0127] S1. When upgrading the containers of each node in the distributed system, remove the temporary data or objects of the un-migrated containers of the old version, and migrate the persistent objects of the new version of the containers to the mapping directory; the mapping directory is the directory corresponding to the container in the container file system; a peer-to-peer network is constructed among the nodes in the distributed system;
[0128] S2. Create a first symbolic link in the container file system; the path of the first symbolic link is the same as the original path of the persistent object, and points to the persistent object in the mapping directory;
[0129] S3. Select the genesis node from all nodes in the peer-to-peer network, produce and broadcast the new blocks of all nodes to the peer-to-peer network based on the genesis block of the genesis node; and in each node, store the verified new blocks in the local ledger;
[0130] S4. Upgrade each container according to the persistent objects, first symbolic links, new blocks of the local ledger, and pulled new version images in the mapping directory.
[0131] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation manners, and will not be elaborated herein.
[0132] In addition, in combination with the method for upgrading containers in the distributed system provided in the above embodiments, a storage medium can also be provided in this embodiment to implement it. A computer program is stored on the storage medium; when the computer program is executed by a processor, it implements any one of the methods for upgrading containers in the distributed system in the above embodiments.
[0133] It should be noted that the information and data involved in this application are all information and data authorized by users or fully authorized by all parties, and will be used legally.
[0134] It should be understood that the specific embodiments described here are only used to explain this application, rather than to limit it. According to the embodiments provided in this application, all other embodiments obtained by those of ordinary skill in the art without creative work belong to the protection scope of this application.
[0135] Obviously, the drawings are only some examples or embodiments of this application. For those of ordinary skill in the art, this application can also be applied to other similar situations based on these drawings without creative work. In addition, it can be understood that although the work done during the development process here may be complex and time-consuming, for those of ordinary skill in the art, some design, manufacturing, or production changes based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient disclosure of this application.
[0136] The term "embodiment" in this application means that the specific features, structures, or characteristics described in combination with the embodiment may be included in at least one embodiment of this application. The phrase appears in various positions in the specification does not necessarily mean the same embodiment, nor does it mean being independent or alternative to other embodiments and mutually exclusive. Those of ordinary skill in the art can clearly or implicitly understand that the embodiments described in this application can be combined with other embodiments without conflict.
[0137] The above-described embodiments merely represent several implementation manners of the present application. The description thereof is relatively specific and detailed, but it should not be construed as a limitation on the scope of patent protection. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all fall within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.
Claims
1. A method for upgrading containers in a distributed system, characterized in that, The distributed system includes several nodes, and each node is provided with a host operating system; the host operating system manages the host file system and the containerization platform, and the containerization platform manages the operation of the corresponding containers and the container file systems; the method includes: When upgrading the containers of each node in the distributed system, remove the temporary data or objects of the containers with the old version not migrated, and migrate the persistent objects of the new version of the containers to the mapping directory; the mapping directory is the directory corresponding to the container in the container file system; a peer-to-peer network is built among all the nodes in the distributed system; Create a first symbolic link in the container file system; the path of the first symbolic link is the same as the original path of the persistent object, and points to the persistent object in the mapping directory; Select a genesis node from all the nodes of the peer-to-peer network, and based on the genesis block of the genesis node, produce and broadcast new blocks of all the nodes to the peer-to-peer network; and in each node, store the verified new blocks into the local ledger; Upgrade each container according to the persistent object in the mapping directory, the first symbolic link, the new block of the local ledger, and the pulled new version image.
2. The method for upgrading a container in the distributed system according to claim 1, wherein The method further includes: After migrating the persistent object of the new version of the container to the mapping directory, perform an incremental upgrade on the old persistent object in the mapping directory.
3. The method for upgrading a container in a distributed system according to claim 1, wherein The method further includes: Obtain the version information of all the nodes in the peer-to-peer network by accessing the ledger service of any node.
4. The method for upgrading a container in a distributed system according to any one of claims 1 to 3, characterized in that, The method further includes: When the containers in each node in the distributed system are started for the first time, mount the node mapping in the host file system to the mapping directory of the container file system; and migrate the persistent objects in the container file system to the mapping directory; create a second symbolic link in the container file system; the path of the second symbolic link is the same as the original path of the persistent object, and points to the persistent object in the mapping directory; Build a peer-to-peer network among all the nodes in the distributed system, and select a genesis node from all the nodes of the peer-to-peer network; Based on the genesis block of the genesis node, produce and broadcast new blocks of all the nodes to the peer-to-peer network; and in each node, store the verified new blocks into the local ledger; Deploy each container according to the persistent object in the mapping directory, the second symbolic link, the new block of the local ledger, and the pulled new version image.
5. The method for upgrading a container in a distributed system according to claim 4, wherein Selecting a genesis node from all the nodes of the peer-to-peer network includes: Randomly select a genesis node from all the nodes of the peer-to-peer network; Or, determine the scores of all the nodes of the peer-to-peer network; select a genesis node from all the nodes of the peer-to-peer network based on the scores.
6. The method for upgrading a container in a distributed system according to claim 1, wherein Determining the scores of all the nodes of the peer-to-peer network includes: Determine the scores of all the nodes in the peer-to-peer network based on a preset node score formula.
7. The method for upgrading a container in a distributed system according to claim 2, wherein The method further includes: Periodically check whether the containers of each node are deployed.
8. An upgrade device for containers in a distributed system, characterized in that, The distributed system includes a number of nodes, and each node is provided with a host operating system; the host operating system manages the host file system and the containerization platform, and the containerization platform manages the operation of the corresponding container and the container file system; the device includes: a removal and migration module, a creation module, a selection module, and an upgrade module; The removal and migration module is used to remove the temporary data or objects of the containers of the old version that have not been migrated and migrate the persistent objects of the new version of the containers to the mapping directory when the containers of each node in the distributed system are upgraded; the mapping directory is the directory corresponding to the container in the container file system; a peer-to-peer network is constructed between each of the nodes in the distributed system. The creation module is used to create a first symbolic link in the container file system; the path of the first symbolic link is the same as the original path of the persistent object and points to the persistent object in the mapping directory. The selection module is used to select a genesis node from all the nodes in the peer-to-peer network, produce and broadcast new blocks of all the nodes to the peer-to-peer network based on the genesis block of the genesis node; and in each node, store the new blocks that pass the verification into the local ledger. The upgrade module is used to upgrade each container according to the persistent object in the mapping directory, the first symbolic link, the new blocks in the local ledger, and the pulled new version image.
9. A computer device, comprising a memory and a processor, characterized in that, A computer program is stored in the memory, and the processor is set to run the computer program to execute the steps of the method for upgrading containers in the distributed system according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the steps of the method for upgrading containers in the distributed system according to any one of claims 1 to 7 are implemented.