Distributed application method, device, computer equipment, and storage medium
By using the server's heartbeat mechanism and database in distributed applications, autonomously determining the dominant and follow servers, solving the operation and maintenance problems brought by third-party components, achieving higher simplicity and maintenance efficiency.
Patent Information
- Application Number
- CN202110600028.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-31
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2041-05-31
AI Technical Summary
Existing distributed applications use third-party components to increase operational and maintenance difficulties.
Through the server's heartbeat mechanism and database, determine the dominant server and follower server in the distributed framework, and avoid the use of third-party components.
It improves the simplicity of distributed applications, reduces the difficulty of maintenance of network systems, and reduces operational complexity.
Smart Images

Figure CN113220464B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed deployment, and in particular to a distributed application method, apparatus, computer equipment and storage medium. Background Art
[0002] In the late 1990s, distributed object technology emerged in the information industry. Applications can be distributed on different system platforms, and objects between heterogeneous platforms can communicate with each other through distributed technology. Integrating existing enterprise systems into distributed systems can greatly improve the scalability of enterprise application systems. The emergence of multi-layer distributed applications in the late 1990s pointed the way for enterprises to further simplify the development of application systems. Distributed task scheduling refers to assigning multiple tasks divided from an application or business to multiple servers for processing. Distributed task scheduling can solve problems such as insufficient resources on a single server and achieve the purpose of large-scale data computing.
[0003] There are many existing distributed frameworks, such as Zookeeper technology. Distributed application coordination services shard data and assign them to multiple application servers for processing, achieving parallel execution and thus improving processing speed. Existing distributed frameworks use third-party components, such as Zookeeper, Redis and other third-party plug-ins to elect leader servers and follower servers, and use the leader server as the center of the distributed system to manage the follower servers. However, since third-party components often need to manage many application servers, the operation is difficult. And the use of third-party components also requires additional maintenance costs. Summary of the invention
[0004] The embodiments of the present application provide a distributed application method, apparatus, computer device, and storage medium, which are intended to solve the problem of increased difficulty in operation and maintenance caused by the use of third-party components in distributed applications in the prior art.
[0005] In a first aspect, an embodiment of the present application provides a distributed application method, comprising: after determining that a target server is started, writing the heartbeat information of the target server into a heartbeat table in a database, the heartbeat table being used to record the heartbeat information of servers in a network system; obtaining the heartbeat information of at least three servers in the heartbeat table, the at least three servers including the target server; sorting the at least three servers in chronological order according to the heartbeat information of the at least three servers to obtain a server sequence; if the target server is the first in the server sequence, determining that the target server is a dominant server; if the target server is not the first in the server sequence, determining that the target server is a follower server or a working server, the working server being a backup server of the follower server.
[0006] In an optional implementation, the at least three servers are sorted in chronological order based on the heartbeat information of the at least three servers to obtain a server sequence, including: determining the first heartbeat time point of the at least three servers in the heartbeat information of the at least three servers, the first heartbeat time period being the heartbeat time point that is first written into the heartbeat table after the server is started; and sorting the at least three servers in order from far to near on the timeline based on the first heartbeat time point of the at least three servers to obtain the server sequence.
[0007] In an optional implementation, if the target server is not the first in the server sequence, the target server is determined to be a follower server or a working server, including: if the target server ranks second or third in the server sequence, the target server is determined to be the follower server; if the target server ranks after the third in the server sequence, the target server is determined to be the working server.
[0008] In an optional implementation, it further includes: after determining the server type of the target server, adding the type identifier of the target server in the heartbeat table, the server types including the leading server, the follower server and the working server.
[0009] In an optional implementation, it also includes: checking whether the server with the type identification as the follower server in the heartbeat table is disconnected every time period; after determining that the N follower servers included in the heartbeat table are disconnected, selecting N from the working servers to change to the follower servers, where N is a positive integer.
[0010] In an optional implementation, after determining that N follower servers included in the heartbeat table are disconnected, selecting N servers from the working servers to change to the follower servers, where N is a positive integer, includes: after determining that N follower servers included in the heartbeat table are disconnected, selecting servers ranked first to Nth in the server sequence from the working servers that remain connected as the follower services, where N is a positive integer.
[0011] In an optional implementation, the method further includes: checking whether the leading server is disconnected at every time period; if it is determined that the leading server is disconnected, changing one of the follower servers to the leading server, and broadcasting the changed leading server in the network system.
[0012] In a second aspect, an embodiment of the present application provides a distributed application device, comprising: a writing unit, used to write the heartbeat information of the target server into a heartbeat table in a database after determining that the target server is started, the heartbeat table being used to record the heartbeat information of servers in a network system; an acquiring unit, used to acquire the heartbeat information of at least three servers in the heartbeat table, the at least three servers including the target server; a sorting unit, used to sort the at least three servers in chronological order according to the heartbeat information of the at least three servers to obtain a server sequence; a determining unit, used to determine that the target server is a dominant server if the target server is the first in the server sequence; the determining unit is also used to determine that the target server is a follower server or a working server if the target server is not the first in the server sequence, the working server being a backup server of the follower server.
[0013] In an optional implementation, the sorting unit is specifically used to: determine the first heartbeat time point of the at least three servers in the heartbeat information of the at least three servers, the first heartbeat time period being the heartbeat time point that is first written into the heartbeat table after the server is started; and sort the at least three servers in order from far to near on the timeline according to the first heartbeat time point of the at least three servers to obtain the server sequence.
[0014] In an optional implementation, the sorting unit determination unit is specifically used to: if the target server ranks second or third in the server sequence, determine the target server as the follower server; if the target server ranks after the third in the server sequence, determine the target server as the working server.
[0015] In an optional implementation, the device further includes: an adding unit, configured to add a type identifier of the target server in the heartbeat table after determining the server type of the target server, wherein the server types include the leading server, the follower server and the working server.
[0016] In an optional implementation, the device also includes: a checking unit, used to check whether the server with the type identification as the follower server in the heartbeat table is disconnected every time period; a changing unit, used to select N from the working servers to be changed to the follower servers after determining that the N follower servers included in the heartbeat table are disconnected, where N is a positive integer.
[0017] In an optional implementation, the changing unit is specifically used to, after determining that the N follow-up servers included in the heartbeat table are disconnected, select servers ranked first to Nth in the server sequence from the working servers that remain connected as the follow-up service, where N is a positive integer.
[0018] In an optional implementation, the checking unit is also used to check whether the server with the type identification as the dominant server in the heartbeat table is disconnected at intervals; the changing unit is also used to change one of the follower servers to the dominant server if it is determined that the dominant server is disconnected, and broadcast the changed dominant server in the network system.
[0019] In a third aspect, an embodiment of the present application further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the distributed application method described in the first aspect when executing the computer program.
[0020] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the distributed application method described in the first aspect above.
[0021] The embodiments of the present application provide a distributed application method, apparatus, computer equipment and storage medium, which determine the leading server and follower server in the distributed framework through the heartbeat mechanism and database of the server to run the distributed application without the need for third-party components. This solves the problem of increased difficulty in operation and maintenance caused by the use of third-party components in distributed application programs in the prior art, improves the simplicity of distributed applications, and reduces the difficulty of maintaining the network system. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0023] Figure 1 A schematic diagram of an application scenario of the distributed application method provided in an embodiment of the present application;
[0024] Figure 2 A schematic diagram of a distributed application method provided in an embodiment of the present application;
[0025] Figure 3A flowchart of another distributed application method provided in an embodiment of the present application;
[0026] Figure 4 A schematic block diagram of a distributed application device provided in an embodiment of the present application;
[0027] Figure 5 A schematic block diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0029] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0030] It should also be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0031] It should be further understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0032] The embodiment of the present invention provides a distributed application method. To more clearly describe the solution of the present invention, some knowledge related to distribution is first introduced below.
[0033] Throughout the history of computer development, the information industry undergoes periodic changes every ten to fifteen years. From 1950 to 1970, enterprises mainly adopted the mainframe-terminal architecture, and enterprise application systems adopted a single, centralized approach to provide users with resource sharing services. In the early 1980s, open systems and relational database management systems were widely adopted by enterprises. Unlike centralized systems, application logic was dispersed between the master and slave ends. With the popularization of Windows, the 1990s was the era of graphical applications, and client and server architectures were also widely adopted. In the late 1990s, distributed object technology emerged in the information industry. Applications can be distributed on different system platforms, and objects between heterogeneous platforms can communicate with each other through distributed technology. Integrating existing enterprise systems into distributed systems can greatly improve the scalability of enterprise application systems. The emergence of multi-layer distributed applications in the late 1990s pointed the way for enterprises to further simplify the development of application systems.
[0034] Distributed task scheduling refers to assigning multiple tasks divided from an application or business to multiple servers for processing. Distributed task scheduling can solve problems such as insufficient resources on a single server and achieve the purpose of large-scale data computing. There are many traditional distributed frameworks, such as Quartz and Zookeeper, which can implement distributed task scheduling. Among them, Quartz's clustering method uses the lock of the database, allowing only one server to obtain the lock and execute tasks at the same time. It does not take advantage of the cluster for parallel execution, and the processing speed is relatively slow. Zookeeper is a distributed application coordination service that shards data and assigns it to multiple application servers for processing, achieving parallel execution and thus improving processing speed. However, since Zookeeper often needs to manage many application servers, the records of the start and end of each task also need to be written to Zookeeper, causing a heavy burden on Zookeeper. In addition, if a new application server is to be added, it is also necessary to operate on Zookeeper, further increasing its burden.
[0035] In a distributed system, nodes distributed on different hosts need to detect the status of other nodes, such as server nodes need to detect whether slave nodes are invalid. In order to detect the validity of the other node, a message is sent to the other party at a fixed time, and the other party replies with a message. If no reply is received from the other party for a long time, the connection with the other party is disconnected. The sender can be either the server or the client, depending on the specific implementation. Because it is sent once at a fixed time, similar to a heartbeat, the fixed information sent is called a heartbeat packet. Heartbeat packets are mainly used to maintain long connections and short-line links.
[0036] See also Figure 1 and Figure 2 , Figure 1 A schematic diagram of an application scenario of the distributed application method provided in an embodiment of the present application; Figure 2 A flow chart of a distributed application method provided in an embodiment of the present application. The distributed application method is applied in a server and is executed by application software installed in the server.
[0037] like Figure 2 As shown, the method includes steps S101 to S105.
[0038] S101. After determining that a target server is started, the heartbeat information of the target server is written into a heartbeat table in a database. The heartbeat table is used to record the heartbeat information of servers in a network system.
[0039] After determining that the target server is started, the distributed application device writes the heartbeat information of the target server into the heartbeat table in the database, and the heartbeat table is used to record the heartbeat information of the server in the network system. The heartbeat information of the server includes multiple heartbeat time points.
[0040] It is understandable that the distributed application device will periodically write the heartbeat information of the target server to the heartbeat table. The heartbeat mechanism of the server is a mechanism that periodically sends a custom structure, also known as a heartbeat packet, to ensure the validity of the connection. The distributed application device uses the time point of each detection of the server heartbeat packet as the heartbeat time point of the server. When the distributed application device detects a server heartbeat packet for the first time within a period of time, it can be determined that the server is started for the first time within this period of time.
[0041] S102: Obtain heartbeat information of at least three servers in a heartbeat table, where the at least three servers include a target server.
[0042] The distributed application device obtains the heartbeat information of at least three servers in the heartbeat table, and the at least three servers include the target server. It is understandable that the at least three servers are in the above network system. After any server in the network system is started, the distributed application device detects the heartbeat packet of the server and writes the heartbeat information of the server into the heartbeat table.
[0043] In some embodiments, the at least three servers are the three servers determined to be started in the network system. In this embodiment, the three servers determined to be started can ensure the normal operation of the distributed application. In other embodiments, the at least three servers are all servers in the network system. This embodiment can ensure that all servers in the network system can share data and resources of the network system.
[0044] S103. Sort the at least three servers in chronological order according to the heartbeat information of the at least three servers to obtain a server sequence.
[0045] The distributed application device sorts at least three servers in chronological order according to the heartbeat information of at least three servers to obtain a server sequence. The server sequence sorted by the distributed application device is used to elect a leader server, a follower server and a worker server.
[0046] Specifically, the distributed application device determines the first heartbeat time point of the at least three servers in the heartbeat information of the at least three servers. The first heartbeat time point of the server is the heartbeat time point when the server is first written into the heartbeat table by the distributed application device. The distributed application device then sorts the at least upper jaw server according to the first heartbeat time points of the at least three servers in the order from far to near on the time axis to obtain a server sequence. For example, the heartbeat information of server A contains the heartbeat time points: "12:10:12", "12:10:18" and "12:10:24", then the heartbeat time point "12:10:12" is the first heartbeat time point of server A. If the first heartbeat time points of server A, server B and server C are "12:10:12", "12:11:00" and "12:10:9" respectively, then according to the order from far to near of the first heartbeat time points on the time axis, the server sequence obtained by the distributed application device is server C, server A and server B.
[0047] S104: If the target server is the first in the server sequence, determine that the target server is the dominant server.
[0048] If the target server is the first in the server sequence, the distributed application device determines that the target server is the leading server. The leader server is the distribution center in the distributed framework. Its main function is to maintain the distributed cache, distributed locks and global uniqueness of certain business requirements of the network system. If a server is not a leading server, when the server needs to obtain distributed locks and distributed caches, the server sends a request to the leading server, and only after receiving the return information that the leading server agrees to obtain, the server can use the requested distributed locks and distributed caches. This method is used to ensure the performance and stability of distributed applications.
[0049] It can be understood that using the first server in the server sequence as the dominant server can ensure that when the network system starts up a server, there is a server that serves as the dominant server as a distribution center to allocate resources, thereby improving the stability of the network system.
[0050] S105: If the target server is not the first one in the server sequence, determine that the target server is a follower server or a working server, and the working server is a backup server of the follower server.
[0051] If the target server is not the first one in the server sequence, the distributed application device determines that the target server is a follower server or a working server, and the working server is a backup server of the follower server.
[0052] It should be noted that the follower server is a backup server of the leading server. After the distributed application device determines that the leading server is disconnected, the distributed application device changes a follower server to the leading server to work in place of the original leading server. The worker server is a backup server of the follower server in the network system. After the follower server is disconnected, it works in place of the original follower server.
[0053] Specifically, if the target server ranks second or third in the server sequence, the distributed application device determines the target server as a follower server; if the target server ranks after the third in the server sequence, the distributed application device determines the target server as a working server. The preferred number of follower servers is 2. In this implementation, the two follower servers set by the distributed application device are convenient for replacing the original leading server with the follower server to work after the leading server is disconnected. The two follower servers can also ensure that when any follower server fails, the other follower server can work normally, maintaining the stability of the system. At the same time, there is no need to set too many follower servers, which reduces complexity and maintenance difficulty.
[0054] In some other embodiments, the distributed application device sets the number of follow-up servers to an integer greater than 2. This implementation method can further maintain the stability of the network system.
[0055] The method uses the server's heartbeat mechanism and database to determine the leading server and follower server in a distributed framework to run distributed applications without the need for third-party components. This solves the problem of increased difficulty in operation and maintenance caused by the use of third-party components in distributed applications in the prior art, improves the simplicity of distributed applications, and reduces the difficulty of maintaining network systems.
[0056] Figure 3 A flow chart of a distributed application method provided in an embodiment of the present application. The distributed application method is applied in a server and is executed by application software installed in the server.
[0057] like Figure 3As shown, the method includes steps S201 to S210.
[0058] S201. After determining that the target server is started, write the heartbeat information of the target server into a heartbeat table in a database, where the heartbeat table is used to record the heartbeat information of the server in the network system.
[0059] S202: Obtain heartbeat information of at least three servers in the heartbeat table, where the at least three servers include a target server.
[0060] S203. Sort the at least three servers in chronological order according to the heartbeat information of the at least three servers to obtain a server sequence.
[0061] S204: If the target server is the first in the server sequence, determine that the target server is the dominant server.
[0062] S205: If the target server is not the first one in the server sequence, determine that the target server is a follower server or a working server, and the working server is a backup server of the follower server.
[0063] The above steps S201 to S205 are Figure 2 Steps S101 to S105 shown in the embodiment are similar and will not be described again here.
[0064] S206: After determining the server type of the target server, add the type identifier of the target server to the heartbeat table. The server types include a leading server, a follower server, and a working server.
[0065] After determining the server type of the target server, the distributed application device adds the type identifier of the target server to the heartbeat table to ensure that each server in the network system can query the role type of all servers in the heartbeat table, so that each server can work according to the divided server type and maintain the stability of the system.
[0066] S207. Check at every time period whether the server whose type is identified as a follower server in the heartbeat table is disconnected.
[0067] The distributed application device checks whether the follow-up server is disconnected at every time period, which may be the case where the distributed application device checks whether the follow-up server is disconnected at every fixed time period, for example, the fixed time period is two heartbeat cycles of the follow-up server. The distributed application device may also check whether the follow-up server is disconnected at every non-fixed period, which is not limited here and can be adjusted according to specific circumstances.
[0068] It should be noted that the distributed application device can determine whether the server is down or disconnected based on the detected heartbeat packet. The server's heartbeat cycle is fixed. If the distributed application device does not detect the server's heartbeat packet within two heartbeat cycles of the server, it can be determined that the server is down or disconnected.
[0069] S208. After determining that N follower servers included in the heartbeat table are disconnected, select N from the working servers to be changed to follower servers, where N is a positive integer.
[0070] After determining that the N follower servers included in the heartbeat table are disconnected, the distributed application device selects N servers from the working servers to be changed to follower servers, where N is a positive integer. Optionally, after determining that the N follower servers included in the heartbeat table are disconnected, the distributed application device selects servers ranked first to Nth in the server sequence from the working servers that remain connected as follower services, where N is a positive integer.
[0071] It should be noted that the order in which servers are started in a network system indicates the demand structure of servers in the network system. Giving priority to servers that start faster in the network system as dominant servers can improve the stability of distributed applications.
[0072] S209: Check at every time period whether the server whose type is identified as the leading server in the heartbeat table is disconnected.
[0073] The distributed application device checks whether the server with the type identification of the dominant server in the heartbeat table is disconnected at every time period. The distributed application device checks whether the dominant server is disconnected at every time period, which can be that the distributed application device checks whether the dominant server is disconnected at every fixed time end, for example, the fixed time period is 2 heartbeat cycles of the dominant server. The distributed application device can also check whether the dominant server is disconnected at every non-fixed period, which is not limited here and can be adjusted according to specific circumstances.
[0074] S210: If it is determined that the leading server is disconnected, a follower server is changed to the leading server, and the changed leading server is broadcasted in the network system.
[0075] If the distributed application device determines that the leading server is disconnected, a follower server is changed to the leading server and the changed leading server is broadcasted in the network system. After determining that the leading server is disconnected, the distributed application device changes the target server to the leading server to replace the original leading server to maintain the normal operation of the network system and improve the stability of the distributed application.
[0076] In other embodiments, if there are two or more follower servers in the network system, the distributed application system selects one from the multiple follower servers to be changed into the leading server. Optionally, the distributed application device selects one from the multiple follower servers to be changed into the leading server according to the server sequence. This method can further improve the stability of the distributed application.
[0077] The method uses the server's heartbeat mechanism and database to determine the leading server and follower server in a distributed framework to run distributed applications without the need for third-party components. This solves the problem of increased difficulty in operation and maintenance caused by the use of third-party components in distributed applications in the prior art, improves the simplicity of distributed applications, and reduces the difficulty of maintaining network systems.
[0078] The present application also provides a distributed application device, which is used to execute any embodiment of the above-mentioned distributed application method. Figure 4 , Figure 4 1 is a schematic block diagram of a distributed application device provided in an embodiment of the present application. The distributed application device 100 may be configured in a server.
[0079] like Figure 4 As shown, the distributed application device 100 includes: a writing unit 110 , an acquiring unit 120 , a sorting unit 130 , and a determining unit 140 .
[0080] A writing unit 110 is used to write the heartbeat information of the target server into the heartbeat table in the database after determining that the target server is started, and the heartbeat table is used to record the heartbeat information of the server in the network system;
[0081] An acquisition unit 120 is used to acquire heartbeat information of at least three servers in the heartbeat table, where the at least three servers include a target server;
[0082] A sorting unit 130, configured to sort the at least three servers in chronological order according to the heartbeat information of the at least three servers to obtain a server sequence;
[0083] A determination unit 140, configured to determine the target server as a leading server if the target server is the first in the server sequence;
[0084] The determination unit 140 is further configured to determine that the target server is a follower server or a working server if the target server is not the first server in the server sequence, and the working server is a backup server of the follower server.
[0085] In one embodiment, the sorting unit 130 is specifically configured to:
[0086] In the heartbeat information of at least three servers, the first heartbeat time points of at least three servers are determined, and the first heartbeat time period is the heartbeat time point that is first written into the heartbeat table after the server is started; according to the first heartbeat time points of at least three servers, the at least three servers are sorted in order from far to near on the timeline to obtain a server sequence.
[0087] In one embodiment, the sorting unit determination unit 140 is specifically configured to:
[0088] If the target server ranks second or third in the server sequence, the target server is determined to be a follower server; if the target server ranks after the third in the server sequence, the target server is determined to be a working server.
[0089] In one embodiment, the device further includes: an adding unit 150, which is used to add a type identifier of the target server in the heartbeat table after determining the server type of the target server, and the server types include a leading server, a follower server and a working server.
[0090] In one embodiment, the device also includes: a checking unit 160, which is used to check whether the server whose type is identified as a follower server in the heartbeat table is disconnected every time period; a changing unit 170, which is used to select N follower servers from the working servers to be changed to follower servers after determining that N follower servers included in the heartbeat table are disconnected, where N is a positive integer.
[0091] In one embodiment, the changing unit 170 is specifically used to select servers ranked first to Nth in the server sequence from the working servers that remain connected as follower services after determining that N follower servers included in the heartbeat table are disconnected, where N is a positive integer.
[0092] In one embodiment, the checking unit 160 is also used to check whether the server with the type identification of the dominant server in the heartbeat table is disconnected at intervals; the changing unit 170 is also used to change a follower server to the dominant server if it is determined that the dominant server is disconnected, and broadcast the changed dominant server in the network system.
[0093] The device uses the heartbeat mechanism and database of the server to determine the leading server and the following server in the distributed framework to run distributed applications without the need for third-party components. This solves the problem of increased difficulty in operation and maintenance caused by the use of third-party components in distributed applications in the prior art, improves the simplicity of distributed applications, and reduces the difficulty of maintaining the network system.
[0094] The above-mentioned distributed application device can be implemented in the form of a computer program, which can be Figure 5Runs on the computer device shown.
[0095] See also Figure 5 , Figure 5 Schematic block diagram of a computer device provided in an embodiment of the present application. The computer device 500 is a server, which may be an independent server or a server cluster composed of multiple servers.
[0096] See also Figure 5 The computer device 500 includes a processor 502 , a memory and a network interface 505 connected via a system bus 501 , wherein the memory may include a storage medium 503 and an internal memory 504 .
[0097] The storage medium 503 may store an operating system 5031 and a computer program 5032. When the computer program 5032 is executed, the processor 502 may execute a distributed application method.
[0098] The processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500 .
[0099] The internal memory 504 provides an environment for the operation of the computer program 5032 in the storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute the distributed application method.
[0100] The network interface 505 is used for network communication, such as providing data information transmission, etc. Those skilled in the art will understand that Figure 5 The structure shown in the figure is merely a block diagram of a portion of the structure related to the solution of the present application, and does not constitute a limitation on the computer device 500 to which the solution of the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0101] The processor 502 is used to run the computer program 5032 stored in the memory to implement the distributed application method disclosed in the embodiment of the present application.
[0102] Those skilled in the art will understand that Figure 5 The embodiments of the computer device shown in the figure do not constitute a limitation on the specific composition of the computer device. In other embodiments, the computer device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, in some embodiments, the computer device may only include a memory and a processor. In such embodiments, the structure and function of the memory and the processor are the same as those of the embodiment of the present invention. Figure 4 The embodiments shown are consistent and will not be described again here.
[0103] It should be understood that in the embodiment of the present application, the processor 502 may be a central processing unit (CPU), and the processor 502 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0104] In another embodiment of the present application, a computer-readable storage medium is provided. The computer-readable storage medium may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the distributed application method disclosed in the embodiment of the present application is implemented.
[0105] It will be clear to those skilled in the art that, for the convenience and simplicity of description, the specific working process of the above-described equipment, devices and units can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. It will be appreciated by those of ordinary skill in the art that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to the function. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0106] In the several embodiments provided in the present application, it should be understood that the disclosed equipment, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. Units with the same function may also be combined into one unit. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices or units, or may be electrical, mechanical or other forms of connection.
[0107] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present application.
[0108] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0109] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), disk or CD-ROM and other media that can store program codes.
[0110] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A distributed application method, characterized in that: include: After determining that the target server is started, writing the heartbeat information of the target server into a heartbeat table in a database, wherein the heartbeat table is used to record the heartbeat information of the server in the network system; Acquire heartbeat information of at least three servers in the heartbeat table, where the at least three servers include the target server; According to the heartbeat information of the at least three servers, the at least three servers are sorted in chronological order to obtain a server sequence; If the target server is the first one in the server sequence, determining the target server as the dominant server; If the target server is not the first one in the server sequence, determining that the target server is a follower server or a working server, and the working server is a backup server of the follower server; After determining the server type of the target server, adding a type identifier of the target server to the heartbeat table, wherein the server types include the leading server, the following server and the working server; At every time period, checking whether the server whose type identifier is the follower server in the heartbeat table is disconnected; After determining that N follower servers included in the heartbeat table are disconnected, selecting N from the working servers to be changed to the follower servers, where N is a positive integer; After determining that the N follower servers included in the heartbeat table are disconnected, selecting N from the working servers to be changed to the follower servers, where N is a positive integer, comprises: After determining that the N follower servers included in the heartbeat table are disconnected, the servers ranked first to Nth in the server sequence are selected from the working servers that remain connected as the follower services, where N is a positive integer.
2. The method according to claim 1, characterized in that The step of sorting the at least three servers in chronological order according to the heartbeat information of the at least three servers to obtain a server sequence includes: In the heartbeat information of the at least three servers, determining the first heartbeat time period of the at least three servers, the first heartbeat time period being the heartbeat time point first written into the heartbeat table after the server is started; According to the first heartbeat time points of the at least three servers, the at least three servers are sorted in order from far to near on the time axis to obtain the server sequence.
3. The method according to claim 1, characterized in that If the target server is not the first one in the server sequence, determining that the target server is a follower server or a working server includes: If the target server ranks second or third in the server sequence, determining the target server as the follower server; If the target server ranks after the third in the server sequence, the target server is determined to be the working server.
4. The method according to claim 1, characterized in that: Also includes: At every time period, checking whether the server identified as the leading server in the heartbeat table is disconnected; If it is determined that the leading server is disconnected, one of the follower servers is changed to the leading server, and the changed leading server is broadcasted in the network system.
5. A distributed application device, characterized in that: include: A writing unit, used for writing the heartbeat information of the target server into a heartbeat table in a database after determining that the target server is started, wherein the heartbeat table is used to record the heartbeat information of the server in the network system; An acquiring unit, configured to acquire heartbeat information of at least three servers in the heartbeat table, wherein the at least three servers include the target server; A sorting unit, configured to sort the at least three servers in chronological order according to the heartbeat information of the at least three servers to obtain a server sequence; a determination unit, configured to determine the target server as a leading server if the target server is the first one in the server sequence; The determining unit is further configured to determine, if the target server is not the first server in the server sequence, that the target server is a follower server or a working server, and the working server is a backup server of the follower server; An adding unit, used for adding a type identifier of the target server in the heartbeat table after determining the server type of the target server, where the server types include a leading server, a following server and a working server; A checking unit, used for checking whether the server with the type identification of the follower server in the heartbeat table is disconnected at every time period; A change unit, used for selecting N servers to be changed to follower servers from the working servers after it is determined that N follower servers included in the heartbeat table are disconnected, where N is a positive integer; After determining that N follower servers included in the heartbeat table are disconnected, select servers ranked first to Nth in the server sequence from the working servers that remain connected as follower services, where N is a positive integer.
6. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the distributed application method according to any one of claims 1 to 4 is implemented.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, enables the processor to perform the distributed application method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Implementation method of flattened high-availability namenode model
CN107832138A
Heartbeat Heuristics
US20070180077A1