Method and system for realizing master selection of distributed system based on cloud native platform

By using ConfigMap and Kubernetes API to manage resource locks on cloud native platforms, the lightweight master selection method of distributed systems is implemented, which solves the complexity and stability of electing master nodes in distributed systems and improves the availability of systems and stability.

CN118963919APending Publication Date: 2024-11-15SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411056198.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-02
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

On cloud-native platforms, the primary node needs to be elected in distributed systems to avoid duplicate task execution and system failure. The existing technology is complex and unstable, and there is a lack of a lightweight master selection method.

Method used

By using ConfigMap resources and Kubernetes API on cloud native platforms, the preemption and management of resource locks is realized. The child process is responsible for creating and updating ConfigMap, the main process is responsible for business logic, and through shared memory communication, it ensures the independence and fairness of the main selection process. .

Benefits of technology

It provides a lightweight and stable method of master selection, simplifies master selection logic, improves system availability and stability, avoids single point of failure, and is suitable for distributed application systems deployed on cloud-native platforms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118963919A_ABST
    Figure CN118963919A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of cloud native, in particular to a distributed system master selection implementation method and system based on a cloud native platform, and the method comprises the following steps: starting an application program, executing the business logic of the application in a host process, and processing a specific business task by the host process; a ConfigMap resource is obtained; lock information comparison: carrying out data comparison on the information obtained after analysis of the existing ConfigMap resources according to a configuration rule, so as to judge whether a leader node is normal or not, and further decide whether to switch a main node or not; the implementation method and system for master selection of the distributed system based on the cloud native platform are suitable for a distributed application system deployed on the cloud native platform, independent of third-party software, based on a resource lock of Kubernetes, multi-copy simultaneous lock grabbing is carried out, the node grabbing the resource lock at first is the leader, and the node grabbing the resource lock at first is the leader, so that the node grabbing the resource lock at first is the leader, and the node grabbing the resource lock at second is the leader. Compared with a traditional master selection mode, master selection logic is simpler, lighter and more stable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cloud native technology, and specifically to a method and system for implementing master election in a distributed system based on a cloud native platform. Background Art

[0002] When users develop and deploy application systems on cloud-native platforms, they often start multiple nodes / replicas to provide services to improve system stability and high availability. Replicas of some stateless applications can work simultaneously and provide loads at the same time without involving master nodes or slave nodes. For example, the springboot project developed using Java technology starts multiple replicas at the same time and binds them to the same Service (a resource of Kubernetes), which forwards requests to each replica.

[0003] When there are multiple copies of another application, one copy needs to be selected as the primary node to provide services, and the other copies serve as standby nodes without providing workloads to prevent all copies from performing the same operation. This will cause system failures due to repeated task execution. When the primary node fails, all slave nodes compete for the leader and only provide loads after seizing the leader. For example, for kubernetes custom resources CustomResourceDefinition (CR), when there are multiple copies of the Operator (controller of custom resources) operating the CR, it will cause repeated operations or other exceptions, so one of the nodes needs to be elected as the leader to perform the operation, and the other nodes exist as standby nodes without providing loads.

[0004] Therefore, for the second scenario above, a lightweight master election method is needed that does not require the installation of other components and is easy to operate and stable and reliable. Summary of the invention

[0005] The purpose of the present invention is to provide a method and system for implementing leader election in a distributed system based on a cloud native platform to solve the problems raised in the above background technology.

[0006] To achieve the above object, the present invention provides the following technical solution: a method for implementing master election in a distributed system based on a cloud native platform, the method comprising the following steps:

[0007] Start the application. The business logic of the application is executed in the main process, which is responsible for handling specific business tasks.

[0008] Get ConfigMap resources;

[0009] Lock information comparison: compare the information parsed from the existing ConfigMap resources according to the configuration rules to determine whether the leader node is normal and decide whether to switch the primary node.

[0010] Preferably, the specific operation of starting the application program includes:

[0011] The leader election logic runs as a subprocess, which is responsible for creating ConfigMap, grabbing resource locks, and updating resource locks. After starting to run, the program enters the waiting state for election. The subprocess and the main process communicate and collaborate through shared memory. When the subprocess successfully grabs the leader role, it notifies the main process through shared memory. After receiving the notification from the subprocess, the main process performs corresponding operations as needed. The communication mechanism based on shared memory ensures timely interaction and data transmission between the subprocess and the main process.

[0012] By creating a ConfigMap to store the configuration information required for master election, the initialization and settings of master election are convenient. At the same time, during the master election process, the independence and fairness of each role in the master election process are ensured by preempting resource locks, and the main process is notified through shared memory. During the election process, the program enters a waiting state, waiting for each sub-process to complete the execution of the master election logic. Once the election is completed, the sub-process notifies the main process, and the entire system will enter a normal operating state to obtain ConfigMap resources.

[0013] Preferably, the specific operations for obtaining ConfigMap resources include:

[0014] ConfigMap is used to save non-confidential data in the form of key-value pairs. ConfigMap can be created by calling the create interface of Kubernetes. When in use, Pod uses ConfigMap as an environment variable, command line parameter, or configuration file in a storage volume to decouple environment configuration information and container images, making it easier to modify application configuration. ConfigMap and the Pod of the distributed application system are in the same namespace and can be obtained by the name of ConfigMap.

[0015] If the ConfigMap resource cannot be obtained, it means that the resource does not exist, which means that the distributed application system is running for the first time. In this case, create a ConfigMap resource and mark the current Pod as the leader role. Write the Pod name, lease duration, timestamp of obtaining the lock, time of updating the lock, and number of leader switching information into the ConfigMap so that other nodes can obtain and parse this information;

[0016] If the ConfigMap resource is successfully obtained, it means that a leader node already exists. In this case, there is no need to create it again. The obtained ConfigMap information is parsed for subsequent comparison and judgment. By comparing the lease duration and lock timestamp information of different nodes, it is determined which node has a higher priority, so as to select the appropriate leader node. By obtaining and creating ConfigMap and parsing the information therein, the role allocation and switching of different nodes in the distributed application system can be effectively managed and controlled.

[0017] Preferably, the specific operations of lock information comparison include:

[0018] Get the leader node name holderIdentity, update resource timestamp renewTime and resource timeout leaseDurationSeconds in ConfigMap;

[0019] If holderIdentity is consistent with the Pod name of the node, it means that the node holds the lock, that is, the node is the leader role; continue to compare whether the lock has timed out. If the time difference between the current time and the renewalTime is greater than leaseDurationSeconds, update the renewalTime operation, that is, update the renewalTime value to the current timestamp; if the time difference between the current time and the renewalTime is less than leaseDurationSeconds, no update operation is performed; the node continues to act as the leader;

[0020] If holderIdentity is inconsistent with the Pod name of the node, it means that the node is a follower node. Continue to compare whether the lock has timed out. If the time difference between the current time and renewTime exceeds leaseDurationSeconds, the leader node has not updated the lock information in time, proving that the leader is faulty, and the master node is switched. Specifically, the node updates the value of holderIdentity to the node Pod name, updates renewTime to the current timestamp, adds 1 to the number of master node switches in leaderTransitions, and notifies the main process, that is, the business logic process, through shared memory to perform corresponding business operations. At this time, the node runs as a leader; if the time difference between the current time and renewTime is less than leaseDurationSeconds, it means that the leader is continuously updating renewTime, the leader node is running normally, and there is no need to switch the master node. The node continues to run as a follower.

[0021] A distributed system master election implementation system based on a cloud native platform, the system consisting of a program startup module, a resource acquisition module, and an information comparison module;

[0022] The program startup module is used to start the application. The business logic of the application is executed in the main process, which is responsible for handling specific business tasks.

[0023] Resource acquisition module, used to obtain ConfigMap resources;

[0024] The information comparison module is used to compare lock information. It compares the information parsed from the existing ConfigMap resources according to the configuration rules to determine whether the leader node is normal and decide whether to switch the master node.

[0025] Preferably, in the program startup module, the leader selection logic runs in the form of a subprocess, and the subprocess is responsible for executing the operations of creating ConfigMap, seizing resource locks, and updating resource locks; after starting to run, the program enters a waiting state for election, and the subprocess and the main process communicate and collaborate through shared memory. When the subprocess successfully seizes the leader role, it notifies the main process through shared memory. After receiving the notification from the subprocess, the main process performs corresponding operations as needed; based on the communication mechanism of shared memory, timely interaction and data transmission between the subprocess and the main process are guaranteed;

[0026] By creating a ConfigMap to store the configuration information required for master election, the initialization and settings of master election are convenient. At the same time, during the master election process, the independence and fairness of each role in the master election process are ensured by preempting resource locks, and the main process is notified through shared memory. During the election process, the program enters a waiting state, waiting for each sub-process to complete the execution of the master election logic. Once the election is completed, the sub-process notifies the main process, and the entire system will enter a normal operating state to obtain ConfigMap resources.

[0027] Preferably, in the resource acquisition module, ConfigMap is used to save non-confidential data in the form of key-value pairs, and ConfigMap can be created by calling the create interface of Kubernetes; when in use, Pod uses ConfigMap as an environment variable, command line parameter or configuration file in a storage volume to achieve decoupling of environment configuration information and container image, making it convenient to modify application configuration. ConfigMap and the Pod of the distributed application system are in the same namespace and are obtained by the name of ConfigMap;

[0028] If the ConfigMap resource cannot be obtained, it means that the resource does not exist, which means that the distributed application system is running for the first time. In this case, create a ConfigMap resource and mark the current Pod as the leader role. Write the Pod name, lease duration, timestamp of obtaining the lock, time of updating the lock, and number of leader switching information into the ConfigMap so that other nodes can obtain and parse this information;

[0029] If the ConfigMap resource is successfully obtained, it means that a leader node already exists. In this case, there is no need to create it again. The obtained ConfigMap information is parsed for subsequent comparison and judgment. By comparing the lease duration and lock timestamp information of different nodes, it is determined which node has a higher priority, so as to select the appropriate leader node. By obtaining and creating ConfigMap and parsing the information therein, the role allocation and switching of different nodes in the distributed application system can be effectively managed and controlled.

[0030] Preferably, the information comparison module obtains the leader node name holderIdentity, the update resource timestamp renewTime and the resource timeout time leaseDurationSeconds in ConfigMap;

[0031] If holderIdentity is consistent with the Pod name of the node, it means that the node holds the lock, that is, the node is the leader role; continue to compare whether the lock has timed out. If the time difference between the current time and the renewalTime is greater than leaseDurationSeconds, update the renewalTime operation, that is, update the renewalTime value to the current timestamp; if the time difference between the current time and the renewalTime is less than leaseDurationSeconds, no update operation is performed; the node continues to act as the leader;

[0032] If holderIdentity is inconsistent with the Pod name of the node, it means that the node is a follower node. Continue to compare whether the lock has timed out. If the time difference between the current time and renewTime exceeds leaseDurationSeconds, the leader node has not updated the lock information in time, proving that the leader is faulty, and the master node is switched. Specifically, the node updates the value of holderIdentity to the node Pod name, updates renewTime to the current timestamp, adds 1 to the number of master node switches in leaderTransitions, and notifies the main process, that is, the business logic process, through shared memory to perform corresponding business operations. At this time, the node runs as a leader; if the time difference between the current time and renewTime is less than leaseDurationSeconds, it means that the leader is continuously updating renewTime, the leader node is running normally, and there is no need to switch the master node. The node continues to run as a follower.

[0033] Compared with the prior art, the present invention has the following beneficial effects:

[0034] The method and system for implementing leader election in a distributed system based on a cloud-native platform proposed in the present invention are suitable for distributed application systems deployed on a cloud-native platform. They do not rely on third-party software and are based on Kubernetes' resource locks. Multiple copies simultaneously grab locks, and the node that first grabs the resource lock becomes the leader. Compared with the traditional leader election method, the leader election logic is simpler, lighter, and more stable. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 The figure is a flow chart of the method of the present invention. DETAILED DESCRIPTION

[0036] In order to make the purpose and technical solution of the present invention clearly and completely described, and the advantages more clearly understood, the embodiments of the present invention are further described in detail with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are part of the embodiments of the present invention, rather than all of the embodiments, and are only used to explain the embodiments of the present invention, and are not used to limit the embodiments of the present invention. All other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0037] Embodiment 1

[0038] See also Figure 1 The present invention provides a technical solution: a method for implementing master election in a distributed system based on a cloud native platform, comprising the following steps:

[0039] The purpose is to provide a lightweight leader election method for distributed system applications deployed on cloud-native platforms. By leveraging the atomicity of Kubernetes API operations, this method uses ConfigMap resources to implement resource lock competition between nodes. All nodes simultaneously preempt the ConfigMap resource lock. The node that successfully preempts the lock becomes the leader and continuously updates the lock time. Other nodes play the follower role and perform lock grabbing operations at regular intervals. When the leader node releases the lock resource or fails due to a fault, one of the follower nodes will immediately compete for the resource lock to replace the leader role.

[0040] The core advantage of this leader election method is that it adopts a distributed architecture and fully utilizes the characteristics of the cloud native platform and the powerful functions of the Kubernetes API. First, through the creation and management of ConfigMap resources, fine-grained control of resource locks is achieved, ensuring that each node competes for resource locks fairly and efficiently. Second, all nodes have the opportunity to become the leader, thereby sharing the system load and the risk of single point failure, and improving the availability and stability of the entire system.

[0041] The leader election method has several key steps. First, when the system starts, all nodes simultaneously preempt the ConfigMap resource lock. This step is based on the atomicity of the Kubernetes API, ensuring that the competition of all nodes is synchronous and conflict-free. After the preemption is successful, the node will become the leader role and start to continuously update the lock time, indicating that it is in an active state. At the same time, other nodes act as followers and perform lock grabbing operations regularly. These nodes periodically check the status of the leader node. When the leader node releases the lock resource or fails, one of the follower nodes will immediately initiate resource lock competition to replace the leader role. This dynamic leader election mechanism can respond to system changes in a timely manner and ensure the high availability of the system. The implementation of the invention also takes into account the fault tolerance and scalability of the system. During the leader election process, the node can automatically adapt to the addition of new nodes and the exit of old nodes to maintain the consistency and stability of the system. At the same time, the method can also be seamlessly integrated with other distributed system applications to provide a unified leader election solution for the entire cloud native platform. See Chapter 7 for the specific leader election process.

[0042] The following further explains:

[0043] 1. Start waiting:

[0044] The first step in the leader election of a distributed application system is to start the application. In general, the leader election logic runs as a child process, which is responsible for creating ConfigMap, seizing resource locks, and updating resource locks. The business logic of the application is executed in the main process, which is responsible for handling specific business tasks. After starting to run, the program will enter the waiting state for election. The child process and the main process communicate and collaborate through shared memory. When the child process successfully seizes the leader role, it notifies the main process through shared memory. After receiving the notification from the child process, the main process performs corresponding operations as needed. This communication mechanism based on shared memory ensures timely interaction and data transmission between the child process and the main process. The leader election process is not just a simple competition for roles, but also involves resource management and synchronization. By creating a ConfigMap to store the configuration information required for the leader election, the leader election can be initialized and set up conveniently. At the same time, in the process of leader election, the seizure of resource locks is also a key link. By seizing resource locks, the independence and fairness of each role in the leader election process are ensured. Only the child process that successfully obtains the resource lock can become the leader role and notify the main process through shared memory. During the election process, the program enters a waiting state, waiting for each subprocess to complete the execution of the master election logic. The duration of this stage depends on the specific master election algorithm and system load. Once the election is completed, the subprocess notifies the master process, and the entire system will enter a normal operation state to obtain ConfigMap resources.

[0045] 2. The second step is to obtain ConfigMap resources, which is an important part of the master election mechanism in distributed application systems. In order to implement the lock grabbing mechanism for Kubernetes resource ConfigMap, you first need to obtain ConfigMap resources. ConfigMap is an API object that is used to save non-confidential data in the form of key-value pairs. ConfigMap can be created by calling the create interface of Kubernetes. When in use, Pod can use ConfigMap as an environment variable, command line parameter, or configuration file in a storage volume to decouple environment configuration information and container images, making it easier to modify application configuration. Usually, ConfigMap and the Pod of the distributed application system are in the same namespace and can be obtained by the name of ConfigMap. If the ConfigMap resource cannot be obtained, it means that the resource does not exist, which means that the distributed application system is running for the first time. In this case, you need to create a ConfigMap resource and mark the current Pod as the leader role. Write information such as the Pod name, lease duration, timestamp of obtaining the lock, time to update the lock, and number of leader switches into ConfigMap so that other nodes can obtain and parse this information. If the ConfigMap resource can be successfully obtained, it means that a leader node already exists and there is no need to create it again. The acquired ConfigMap information can be parsed for subsequent comparison and judgment. By comparing the lease duration, lock timestamp and other information of different nodes, it can be determined which node has a higher priority, so as to select the appropriate leader node. In the entire process of selecting the leader, obtaining ConfigMap resources is a very critical step. By acquiring and creating ConfigMap and parsing the information therein, the role allocation and switching of different nodes in the distributed application system can be effectively managed and controlled. This ConfigMap-based lock grabbing mechanism provides basic support for the high availability and stability of distributed application systems.

[0046] The following is an example of a ConfigMap:

[0047]

[0048] namespace:default

[0049] resourceVersion:"73851631"

[0050] uid:c3066893-9afd-4de6-b337-270de9a30120.

[0051] 3. Lock information comparison:

[0052] The parsed information of the existing ConfigMap resources is compared with the configuration rules to determine whether the leader node is normal, and then decide whether to switch the master node. Specifically: get the leader node name (holderIdentity), update resource timestamp (renewTime) and resource timeout (leaseDurationSeconds) in ConfigMap.

[0053] If holderIdentity is consistent with the Pod name of the node, it means that the node holds the lock, that is, the node is the leader role; continue to compare whether the lock has timed out. If the time difference between the current time and renewalTime is greater than leaseDurationSeconds, update renewalTime, that is, update the value of renewalTime to the current timestamp; if the time difference between the current time and renewalTime is less than leaseDurationSeconds, no update operation is performed; the node continues to act as the leader.

[0054] If the holderIdentity is inconsistent with the Pod name of the node, it means that the node is a follower node, and the lock is compared to see if it has timed out. If the time difference between the current time and the renewalTime exceeds the leaseDurationSeconds, the leader node has not updated the lock information in time, proving that the leader is faulty, and the master node is switched. Specifically, the node updates the value of the holderIdentity to the node Pod name, updates the renewalTime to the current timestamp, and adds 1 to the leaderTransitions (master node switching times), and notifies the main process (business logic process) through shared memory to perform the corresponding business operations. At this time, the node runs as a leader; if the time difference between the current time and the renewalTime is less than the leaseDurationSeconds, it means that the leader is continuously updating the renewalTime, the leader node is running normally, and there is no need to switch the master node. The node continues to run as a follower.

[0055] Embodiment 2

[0056] Based on the first embodiment, a distributed system master election implementation system based on a cloud native platform is proposed. The system consists of a program startup module, a resource acquisition module, and an information comparison module.

[0057] The program startup module is used to start the application. The business logic of the application is executed in the main process, which is responsible for handling specific business tasks. The master election logic runs as a subprocess, which is responsible for creating ConfigMap, preempting resource locks, and updating resource locks. After starting to run, the program enters the waiting state for election. The subprocess and the main process communicate and collaborate through shared memory. When the subprocess successfully preempts the leader role, it notifies the main process through shared memory. After receiving the notification from the subprocess, the main process performs corresponding operations as needed. The communication mechanism based on shared memory ensures timely interaction and data transmission between the subprocess and the main process.

[0058] By creating a ConfigMap to store the configuration information required for master election, the initialization and settings of master election are convenient. At the same time, during the master election process, the independence and fairness of each role in the master election process are ensured by preempting resource locks, and the main process is notified through shared memory. During the election process, the program enters a waiting state, waiting for each sub-process to complete the execution of the master election logic. Once the election is completed, the sub-process notifies the main process, and the entire system will enter a normal operating state to obtain ConfigMap resources.

[0059] Resource acquisition module, used to obtain ConfigMap resources; ConfigMap is used to save non-confidential data in the form of key-value pairs. ConfigMap can be created by calling the create interface of Kubernetes; when in use, Pod uses ConfigMap as an environment variable, command line parameter or configuration file in the storage volume to achieve the decoupling of environment configuration information and container image, which is convenient for modifying application configuration. ConfigMap and Pod of distributed application system are in the same namespace and can be obtained by the name of ConfigMap;

[0060] If the ConfigMap resource cannot be obtained, it means that the resource does not exist, which means that the distributed application system is running for the first time. In this case, create a ConfigMap resource and mark the current Pod as the leader role. Write the Pod name, lease duration, timestamp of obtaining the lock, time of updating the lock, and number of leader switching information into the ConfigMap so that other nodes can obtain and parse this information;

[0061] If the ConfigMap resource is successfully obtained, it means that a leader node already exists. In this case, there is no need to create it again. The obtained ConfigMap information is parsed for subsequent comparison and judgment. By comparing the lease duration and lock timestamp information of different nodes, it is determined which node has a higher priority, so as to select the appropriate leader node. By obtaining and creating ConfigMap and parsing the information therein, the role allocation and switching of different nodes in the distributed application system can be effectively managed and controlled.

[0062] The information comparison module is used to compare lock information. It compares the information after parsing the existing ConfigMap resources according to the configuration rules to determine whether the leader node is normal and decide whether to switch the master node. It obtains the leader node name holderIdentity, the update resource timestamp renewTime, and the resource timeout leaseDurationSeconds in the ConfigMap.

[0063] If holderIdentity is consistent with the Pod name of the node, it means that the node holds the lock, that is, the node is the leader role; continue to compare whether the lock has timed out. If the time difference between the current time and the renewalTime is greater than leaseDurationSeconds, update the renewalTime operation, that is, update the renewalTime value to the current timestamp; if the time difference between the current time and the renewalTime is less than leaseDurationSeconds, no update operation is performed; the node continues to act as the leader;

[0064] If holderIdentity is inconsistent with the Pod name of the node, it means that the node is a follower node. Continue to compare whether the lock has timed out. If the time difference between the current time and renewTime exceeds leaseDurationSeconds, the leader node has not updated the lock information in time, proving that the leader is faulty, and the master node is switched. Specifically, the node updates the value of holderIdentity to the node Pod name, updates renewTime to the current timestamp, adds 1 to the number of master node switches in leaderTransitions, and notifies the main process, that is, the business logic process, through shared memory to perform corresponding business operations. At this time, the node runs as a leader; if the time difference between the current time and renewTime is less than leaseDurationSeconds, it means that the leader is continuously updating renewTime, the leader node is running normally, and there is no need to switch the master node. The node continues to run as a follower.

[0065] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A method for implementing leader election in a distributed system based on a cloud native platform. Features: The method comprises the following steps: Start the application. The business logic of the application is executed in the main process, which is responsible for handling specific business tasks. Get ConfigMap resources; Lock information comparison: compare the information parsed from the existing ConfigMap resources according to the configuration rules to determine whether the leader node is normal and decide whether to switch the master node.

2. According to claim 1, a method for implementing master election based on a cloud native platform distributed system, Features: The specific operations to start the application include: The leader election logic runs as a subprocess, which is responsible for creating ConfigMap, grabbing resource locks, and updating resource locks. After starting to run, the program enters the waiting state for election. The subprocess and the main process communicate and collaborate through shared memory. When the subprocess successfully grabs the leader role, it notifies the main process through shared memory. After receiving the notification from the subprocess, the main process performs corresponding operations as needed. The communication mechanism based on shared memory ensures timely interaction and data transmission between the subprocess and the main process. By creating a ConfigMap to store the configuration information required for master election, the initialization and settings of master election are convenient. At the same time, during the master election process, the independence and fairness of each role in the master election process are ensured by preempting resource locks, and the main process is notified through shared memory. During the election process, the program enters a waiting state, waiting for each sub-process to complete the execution of the master election logic. Once the election is completed, the sub-process notifies the main process, and the entire system will enter a normal operating state to obtain ConfigMap resources.

3. According to the method for implementing master election based on a cloud native platform distributed system according to claim 1, Features: The specific operations for obtaining ConfigMap resources include: ConfigMap is used to save non-confidential data in the form of key-value pairs. ConfigMap can be created by calling the create interface of Kubernetes. When in use, Pod uses ConfigMap as an environment variable, command line parameter, or configuration file in a storage volume to decouple environment configuration information and container images, making it easier to modify application configuration. ConfigMap and the Pod of the distributed application system are in the same namespace and can be obtained by the name of ConfigMap. If the ConfigMap resource cannot be obtained, it means that the resource does not exist, which means that the distributed application system is running for the first time. In this case, create a ConfigMap resource and mark the current Pod as the leader role. Write the Pod name, lease duration, timestamp of obtaining the lock, time of updating the lock, and number of leader switching information into the ConfigMap so that other nodes can obtain and parse this information; If the ConfigMap resource is successfully obtained, it means that a leader node already exists. In this case, there is no need to create it again. The obtained ConfigMap information is parsed for subsequent comparison and judgment. By comparing the lease duration and lock timestamp information of different nodes, it is determined which node has a higher priority, so as to select the appropriate leader node. By obtaining and creating ConfigMap and parsing the information therein, the role allocation and switching of different nodes in the distributed application system can be effectively managed and controlled.

4. According to claim 1, a method for implementing master election based on a cloud native platform distributed system, Features: The specific operations of lock information comparison include: Get the leader node name holderIdentity, update resource timestamp renewTime and resource timeout leaseDurationSeconds in ConfigMap; If holderIdentity is consistent with the Pod name of the node, it means that the node holds the lock, that is, the node is the leader role; continue to compare whether the lock has timed out. If the time difference between the current time and the renewalTime is greater than leaseDurationSeconds, update the renewalTime operation, that is, update the renewalTime value to the current timestamp; if the time difference between the current time and the renewalTime is less than leaseDurationSeconds, no update operation is performed; the node continues to act as the leader; If holderIdentity is inconsistent with the Pod name of the node, it means that the node is a follower node. Continue to compare whether the lock has timed out. If the time difference between the current time and renewTime exceeds leaseDurationSeconds, the leader node has not updated the lock information in time, proving that the leader is faulty, and the master node is switched. Specifically, the node updates the value of holderIdentity to the node Pod name, updates renewTime to the current timestamp, adds 1 to the number of master node switches in leaderTransitions, and notifies the main process, that is, the business logic process, through shared memory to perform corresponding business operations. At this time, the node runs as a leader; if the time difference between the current time and renewTime is less than leaseDurationSeconds, it means that the leader is continuously updating renewTime, the leader node is running normally, and there is no need to switch the master node. The node continues to run as a follower.

5. A system for implementing leader election based on a cloud native platform distributed system according to the method for implementing leader election based on a cloud native platform distributed system according to any one of claims 1 to 4, Features: The system consists of a program startup module, a resource acquisition module and an information comparison module; The program startup module is used to start the application. The business logic of the application is executed in the main process, which is responsible for handling specific business tasks. Resource acquisition module, used to obtain ConfigMap resources; The information comparison module is used to compare lock information. It compares the information parsed from the existing ConfigMap resources according to the configuration rules to determine whether the leader node is normal and decide whether to switch the master node.

6. According to claim 5, a system for implementing master election based on a cloud native platform distributed system, Features: The program starts the module, and the leader selection logic runs in the form of a subprocess. The subprocess is responsible for executing the operations of creating ConfigMap, seizing resource locks, and updating resource locks. After starting to run, the program enters the waiting state for election. The subprocess and the main process communicate and collaborate through shared memory. When the subprocess successfully seizes the leader role, it notifies the main process through shared memory. After receiving the notification from the subprocess, the main process performs corresponding operations as needed. The communication mechanism based on shared memory ensures timely interaction and data transmission between the subprocess and the main process. By creating a ConfigMap to store the configuration information required for master election, the initialization and settings of master election are convenient. At the same time, during the master election process, the independence and fairness of each role in the master election process are ensured by preempting resource locks, and the main process is notified through shared memory. During the election process, the program enters a waiting state, waiting for each sub-process to complete the execution of the master election logic. Once the election is completed, the sub-process notifies the main process, and the entire system will enter a normal operating state to obtain ConfigMap resources.

7. According to claim 5, a system for implementing master election based on a cloud native platform distributed system, Features: In the resource acquisition module, ConfigMap is used to save non-confidential data in the form of key-value pairs. ConfigMap can be created by calling the create interface of Kubernetes. When in use, Pod uses ConfigMap as an environment variable, command line parameter or configuration file in a storage volume to achieve the decoupling of environment configuration information and container image, making it easier to modify application configuration. ConfigMap and the Pod of the distributed application system are in the same namespace and are obtained by the name of ConfigMap. If the ConfigMap resource cannot be obtained, it means that the resource does not exist, which means that the distributed application system is running for the first time. In this case, create a ConfigMap resource and mark the current Pod as the leader role. Write the Pod name, lease duration, timestamp of obtaining the lock, time of updating the lock, and number of leader switching information into the ConfigMap so that other nodes can obtain and parse this information; If the ConfigMap resource is successfully obtained, it means that a leader node already exists. In this case, there is no need to create it again. The obtained ConfigMap information is parsed for subsequent comparison and judgment. By comparing the lease duration and lock timestamp information of different nodes, it is determined which node has a higher priority, so as to select the appropriate leader node. By obtaining and creating ConfigMap and parsing the information therein, the role allocation and switching of different nodes in the distributed application system can be effectively managed and controlled.

8. According to claim 5, a system for implementing master election based on a cloud native platform distributed system, Features: The information comparison module obtains the leader node name holderIdentity, the update resource timestamp renewTime and the resource timeout time leaseDurationSeconds in ConfigMap; If holderIdentity is consistent with the Pod name of the node, it means that the node holds the lock, that is, the node is the leader role; continue to compare whether the lock has timed out. If the time difference between the current time and the renewalTime is greater than leaseDurationSeconds, update the renewalTime operation, that is, update the renewalTime value to the current timestamp; if the time difference between the current time and the renewalTime is less than leaseDurationSeconds, no update operation is performed; the node continues to act as the leader; If holderIdentity is inconsistent with the Pod name of the node, it means that the node is a follower node. Continue to compare whether the lock has timed out. If the time difference between the current time and renewTime exceeds leaseDurationSeconds, the leader node has not updated the lock information in time, proving that the leader is faulty, and the master node is switched. Specifically, the node updates the value of holderIdentity to the node Pod name, updates renewTime to the current timestamp, adds 1 to the number of master node switches in leaderTransitions, and notifies the main process, that is, the business logic process, through shared memory to perform corresponding business operations. At this time, the node runs as a leader; if the time difference between the current time and renewTime is less than leaseDurationSeconds, it means that the leader is continuously updating renewTime, the leader node is running normally, and there is no need to switch the master node. The node continues to run as a follower.