Connection method and device of distributed database, electronic equipment and storage medium
By performing server-side identifier detection and blacklist management in the distributed database driver, the problem of low connection management efficiency when the distributed database service is abnormal is solved, enabling rapid switching to healthy nodes and reducing business latency and throughput.
Patent Information
- Application Number
- CN202211728641.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2026-01-20
- Estimated Expiration
- 2042-12-30
AI Technical Summary
When a distributed database service fails, existing technologies cannot quickly identify and switch to a healthy node, resulting in long business response times or failures, and low efficiency in connection pool management.
In the distributed database driver, server identifiers are obtained and detected, abnormal connections are disconnected, a blacklist is established, healthy nodes not on the blacklist are selected to create connections, and periodic liveness detection is performed through a listening thread.
Quickly identify and switch to healthy nodes to avoid abnormal connections, reduce service latency and throughput, and ensure rapid service response.
Smart Images

Figure CN116248355B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database technology, and more specifically, to a method, apparatus, electronic device, and storage medium for connecting a distributed database. Background Technology
[0002] In the context of massive requests for distributed database services, database servers typically provide services through horizontal scaling of peer nodes and multi-point active-active architecture to meet the needs of load balancing and disaster recovery for user requests. Furthermore, given that databases provide services via connections, an application will have multiple database connections. In the current business model, applications often manage these multiple database connections through database connection pools, which manage the creation, release, and keep-alive of database connections.
[0003] However, when the database server service is abnormal, it takes sub-seconds or more for business requests or connection pool keep-alive to determine that a connection has expired. At this time, when the business sequentially retrieves idle connections from the connection pool, many of the retrieved connections will be abnormal, and it will be necessary to try and fail on each of the abnormal connections. At the same time, the connection pool or business may send new connection requests to the abnormal database server, which may cause the target end of the connection to be selected incorrectly, and a lot of time will be spent trying and failing before the connection can be successfully established. Ultimately, this will result in long response times for the business or business failure recovery taking tens of seconds or even minutes.
[0004] There are currently no effective solutions to the aforementioned problems in the relevant technologies. Summary of the Invention
[0005] This invention provides a method, apparatus, electronic device, and storage medium for connecting distributed databases, in order to solve the technical problem of low efficiency in connection management of distributed databases in related technologies.
[0006] According to one aspect of the embodiments of this application, a method for connecting to a distributed database is provided, comprising: obtaining server identifiers corresponding to multiple servers in a driver program of the distributed database, wherein the distributed database includes multiple servers; performing serviceability detection on each server respectively, disconnecting the connection corresponding to a first server that is detected as abnormal, and adding the server identifier corresponding to the first server to a blacklist; receiving a connection establishment request, and selecting a second server outside the blacklist to establish a connection according to the connection establishment request.
[0007] Furthermore, selecting a second server outside the blacklist to create a connection according to the chain establishment request includes: traversing the server identifiers of the distributed database to determine whether there is a server identifier corresponding to a second server outside the blacklist; if there is a server identifier corresponding to a second server outside the blacklist, then responding to the chain establishment request and creating a connection between the client and the second server.
[0008] Furthermore, after establishing a connection between the client and the second server, the method further includes: determining whether the connection between the client and the second server has been successfully established; if the connection between the client and the second server has been successfully established, detecting whether a packet has been established for the server identifier corresponding to the second server; if a packet has not been established for the server identifier corresponding to the second server, creating a target packet and a listening link corresponding to the target packet based on the server identifier corresponding to the second server; and probing the second server in the target packet through the listening link.
[0009] Furthermore, after receiving the connection establishment request, the method further includes: starting a listening and detection thread within the driver; using the listening and detection thread to detect the activity of a first server in the blacklist, and to detect the activity of a second server outside the blacklist.
[0010] Furthermore, the activity detection of the first server in the blacklist through the monitoring and activity detection thread includes: establishing an activity detection link through the monitoring and activity detection thread; sending a first heartbeat signal to the first server through the activity detection link, and determining whether the first server has been successfully identified as active based on the sending and receiving status of the first heartbeat signal; if the first server has been successfully identified as active, then removing the first server from the blacklist.
[0011] Furthermore, after determining whether the first server has successfully determined its liveness based on the transmission and reception status of the first heartbeat signal, the method further includes: if the first server fails to determine its liveness, then accumulating the number of times the first server has failed to determine its liveness; and reducing the frequency of determining the liveness of the first server through the liveness detection link based on the number of failures.
[0012] Furthermore, the process of probing the second server outside the blacklist includes: obtaining the monitoring link corresponding to the second server outside the blacklist; sending a second heartbeat signal to the second server through the monitoring link, and determining whether the second server has been successfully identified as active based on the sending and receiving status of the second heartbeat signal; if the second server fails to be identified as active, adding the server identifier corresponding to the second server to the blacklist, and disconnecting all connections of the client to the second server.
[0013] According to another aspect of the embodiments of this application, a connection device for a distributed database is also provided, comprising: an acquisition module, configured to acquire server identifiers corresponding to multiple servers in a driver program of the distributed database, wherein the distributed database includes multiple servers; a detection module, configured to perform serviceability detection on each server, disconnect the connection corresponding to a first server that is detected as abnormal, and add the server identifier corresponding to the first server to a blacklist; and a connection module, configured to receive a connection establishment request and select a second server outside the blacklist to establish a connection according to the connection establishment request.
[0014] 0 Further, the connection module includes a first connection unit, used to traverse the server identifiers of the distributed database and determine whether there is a server identifier corresponding to a second server outside the blacklist; if there is a server identifier corresponding to a second server outside the blacklist, then respond to the connection establishment request and create a connection between the client and the second server.
[0015] Furthermore, the first connection unit is also used to determine whether the connection between the client and the second server has been successfully established; if the connection between the client and the second server has been successfully established,
[0016] Then, it checks whether a group has been established for the server identifier corresponding to the second server; if a group has not been established for the server identifier corresponding to the second server, a target group and a listening link corresponding to the target group are created according to the server identifier corresponding to the second server; the second server in the target group is probed for activity through the listening link.
[0017] 0. Furthermore, the connection device of the distributed database also includes a listening module, which is used to start a listening and detection thread in the driver; and to detect the activity of the first server in the blacklist and the second server outside the blacklist through the listening and detection thread.
[0018] Furthermore, the monitoring module includes a first monitoring unit, used to establish a liveness detection link through the monitoring liveness detection thread; send a first heartbeat signal to the first server through the liveness detection link, and determine whether the first server has been successfully live based on the sending and receiving status of the first heartbeat signal; if the first server has been successfully live, then remove the first server from the blacklist.
[0019] Furthermore, the first monitoring unit is also configured to, if the first server fails to determine its liveness, accumulate the number of times the first server fails to determine its liveness; and reduce the frequency of determining the liveness of the first server through the liveness detection link based on the number of failures.
[0020] Furthermore, the monitoring module also includes a second monitoring unit, used to obtain the monitoring link corresponding to the second server outside the blacklist; send a second heartbeat signal to the second server through the monitoring link, and determine whether the second server has successfully been identified as active based on the sending and receiving status of the second heartbeat signal; if the second server fails to be identified as active, add the server identifier corresponding to the second server to the blacklist, and disconnect all connections of the client to the second server.
[0021] According to another aspect of the embodiments of this application, a storage medium is also provided, the storage medium including a stored program that executes the above steps when the program is run.
[0022] According to another aspect of the embodiments of this application, an electronic device is also provided, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; wherein: the memory is used to store computer programs; and the processor is used to execute the steps in the above method by running the programs stored in the memory.
[0023] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the steps in the above-described method.
[0024] This invention obtains server identifiers for multiple servers in the driver program of a distributed database, where the distributed database includes multiple servers. It performs serviceability detection on each server, disconnects connections to the first server that detects an anomaly, and adds the server identifier of the first server to a blacklist. Upon receiving a connection request, it selects a second server (not on the blacklist) to create a connection. By avoiding the blacklist during connection establishment, the invention prevents connection requests from selecting abnormal servers, significantly saving connection establishment time and eliminating increased latency and reduced throughput caused by node or network anomalies. Furthermore, when a server anomaly occurs, it can quickly and proactively disconnect all database links established on that server, preventing services from obtaining or continuously obtaining invalid or dead connections when requesting connections. Simultaneously, it quickly performs disaster recovery traffic distribution on the abnormal server, preventing prolonged unresponsiveness and low throughput during anomalies. Attached Figure Description
[0025] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0026] Figure 1This is a hardware structure block diagram of a computer according to an embodiment of the present invention;
[0027] Figure 2 This is a flowchart of a distributed database connection method according to an embodiment of the present invention;
[0028] Figure 3 This is a schematic diagram illustrating the process of self-management of distributed database connections at the driver layer according to an embodiment of the present invention;
[0029] Figure 4 This is a structural block diagram of a distributed database connection device according to an embodiment of the present invention. Detailed Implementation
[0030] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, and not all of them. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present application. It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of the present application can be combined with each other.
[0031] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0032] Example 1
[0033] The method embodiment provided in Embodiment 1 of this application can be executed on a mobile phone, computer, tablet, or similar computing device. Taking running on a computer as an example, Figure 1 This is a hardware structure block diagram of a computer according to an embodiment of the present invention. For example... Figure 1 As shown, a computer may include one or more ( Figure 1Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. Optionally, the computer may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the computer described above. For example, the computer may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0034] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to a video motion rate recognition method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the aforementioned method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0035] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by a computer's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0036] This embodiment provides a method for connecting to a distributed database. Figure 2 This is a flowchart of a distributed database connection method according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps:
[0037] Step S10: Obtain server identifiers corresponding to multiple servers in the driver of the distributed database, wherein the distributed database includes multiple servers;
[0038] Step S20: Perform serviceability detection on each server, disconnect the connection corresponding to the first server that is detected as abnormal, and add the server identifier corresponding to the first server to the blacklist.
[0039] Step S30: Receive a connection establishment request, and select a second server outside the blacklist to create a connection based on the connection establishment request.
[0040] This embodiment autonomously manages the connection for business access to the database at the driver layer of the distributed database. Specifically, it includes management of connection grouping, blacklisting, blacklist connection activation detection, and server availability judgment. When a distributed database driver receives a connection establishment request from an upstream application or connection pool, it obtains server identifiers for multiple servers and automatically groups and manages the servers according to these identifiers. Servers with different identifiers are divided into different groups, and each server undergoes a serviceability test. This test can be performed by creating a connection between the client and server, sending a heartbeat signal to the server, and monitoring the heartbeat's transmission and reception. Connections within groups that test abnormally are disconnected entirely, meaning all connections to the first abnormal server are disconnected quickly, preventing time wasted by prolonged liveness checks by the application or connection pool. The server identifier of the first abnormal server is added to a blacklist for management. When the application or connection pool sends a new connection establishment request, the driver receives the request and selects a second server (not on the blacklist) to establish a connection. This prevents the application or connection pool from sending new connection establishment requests to already abnormal servers, avoiding blocking or prolonged error checks during connection establishment. The server identifier can be the server's network address (such as an IP address), i.e., the server address, which is a unique identifier for the server providing services externally. In this embodiment, when a server malfunctions, requests and traffic are quickly diverted to other disaster recovery and load balancing nodes, saving significant time spent on trial and error in finding available servers and creating new connections. This embodiment is implemented at the database driver layer, without intruding on the database methods of the business logic. Features such as connection self-management and blacklists are controlled via parameters.
[0041] Through the above steps, the driver program of the distributed database obtains server identifiers corresponding to multiple servers. The distributed database includes multiple servers. Serviceability detection is performed on each server. Connections to the first server that detects an anomaly are disconnected, and its server identifier is added to a blacklist. A connection establishment request is received, and a second server not on the blacklist is selected to establish a connection based on the request. By avoiding the blacklist during connection establishment, abnormal servers are avoided, significantly saving connection establishment time and eliminating increased latency and reduced throughput caused by node or network anomalies. Furthermore, when a server anomaly occurs, all database links established on that server can be proactively and quickly disconnected, preventing services from obtaining or continuously obtaining invalid or dead connections when requesting connections. Simultaneously, traffic on the abnormal server is quickly distributed for disaster recovery, preventing prolonged unresponsiveness and low throughput during anomalies.
[0042] In one embodiment of this example, selecting a second server outside the blacklist to create a connection based on the connection establishment request includes:
[0043] Step 31: Traverse the server identifiers of the distributed database and determine whether there is a server identifier corresponding to a second server outside the blacklist.
[0044] Step 32: If a server identifier for a second server outside the blacklist exists, then respond to the connection establishment request and create a connection between the client and the second server.
[0045] When establishing a connection, the server identifiers of the distributed data are traversed. In this embodiment, the server identifier is the server address. It is determined whether there is an available server address. The server address corresponding to a server not on the blacklist is the available server address. If a second server address not on the blacklist exists, a connection establishment request is responded to, and a connection is established between the client and the second server. During connection establishment, the blacklist is used to determine whether the server is in a serviceable state, allowing for quick selection of a server identifier not on the blacklist for connection establishment. The database driver layer performs reverse engineering and group management of connections established through the driver, achieving connection self-management.
[0046] In this embodiment, after establishing a connection between the client and the second server, the method further includes:
[0047] Step 33: Determine whether the connection between the client and the second server has been successfully established;
[0048] Step 34: If the connection between the client and the second server is successfully established, check whether the server identifier corresponding to the second server has been grouped.
[0049] Step 35: If the server identifier corresponding to the second server has not established a group, then create a target group and a listening link corresponding to the target group according to the server identifier corresponding to the second server.
[0050] Step 36: Probe the activity of the second server in the target group through the monitoring link.
[0051] refer to Figure 3 After establishing a connection between the client and the second server, the system checks whether the connection was successfully established. If the connection is successful, the second server is considered serviceable and can provide services normally. Therefore, it checks whether a group has been established for the server identifier corresponding to the second server. If a group has been established, the created link is added to the group for link management. If a group has not been established for the server identifier corresponding to the second server, a target group and a corresponding listening link are created based on the server identifier. The second server in the target group is then probed for activity through the listening link, and the established link is returned. If the connection fails to establish after determining whether the connection between the client and the second server was successfully established, the server address corresponding to the second server is added to a blacklist, and a link establishment failure is returned. The distributed database's server identifiers are then iterated again until another second server with a successfully established connection is found.
[0052] In another embodiment of this example, after receiving the connection establishment request, the method further includes:
[0053] Step A: Start a listening and probing thread within the driver;
[0054] Step B involves using the monitoring and detection thread to detect the activity of the first server in the blacklist and the second server outside the blacklist.
[0055] After receiving a chain establishment request, a chain is created according to the chain establishment request. It is then determined whether the listening and detection thread in the driver has been started. If the listening and detection thread in the driver has not been started, it is started in the driver. The listening and detection thread is used to detect the first server in the blacklist and to detect the second server outside the blacklist.
[0056] Specifically, the activity detection of the first server in the blacklist through the monitoring and activity detection thread includes:
[0057] Step b1: Establish a liveness detection link through the monitoring and liveness detection thread;
[0058] Step b2: Send a first heartbeat signal to the first server through the liveness detection link, and determine whether the first server has successfully detected liveness based on the sending and receiving status of the first heartbeat signal;
[0059] Step b21: If the first server is successfully identified as active, then the first server is removed from the blacklist.
[0060] By periodically performing liveness detection through a monitoring thread, the client iterates through the server address list and checks if the server address is in the blacklist. If the server address is in the blacklist, it means that the server address corresponds to the first server in the blacklist, and liveness detection is performed on the first server in the blacklist. A liveness detection link is then established between the client and the first server, and a first heartbeat signal is sent to the first server through the liveness detection link. The client determines whether the first server has been successfully live based on the sending and receiving status of the first heartbeat signal. Specifically, if the sending and receiving status of the first heartbeat signal is normal, the first server is considered to have been successfully live; if the sending and receiving status of the first heartbeat signal is abnormal, the first server is considered to have failed to be live. If the first server is successfully live, it means that the first server has recovered its serviceability and can provide services to the outside world, and the first server is removed from the blacklist. This embodiment actively detects liveness in the local blacklist list and promptly releases the identifier of the recovered server, setting it to a serviceable state.
[0061] In this embodiment, after determining whether the first server has successfully become active based on the transmission and reception status of the first heartbeat signal, the method further includes:
[0062] Step b22: If the first server fails to determine liveness, then accumulate the number of times the first server fails to determine liveness.
[0063] Step b23: Reduce the frequency of liveness testing of the first server through the liveness detection link based on the number of liveness testing failures.
[0064] The system sends a first heartbeat signal to the first server via the liveness detection link. Based on the sending and receiving status of the first heartbeat signal, it determines whether the first server has successfully been identified as live. If the first server fails to be identified as live, it means that the first server is still abnormal and cannot provide services to the outside world. The number of liveness detection failures of the first server is then accumulated. The frequency of liveness detection of the first server via the liveness detection link is reduced according to the number of liveness detection failures. For example, by default, the first server is detected as live once every 5 seconds. If the liveness detection is successful, the first server is removed from the blacklist. If the liveness detection fails, the number of failures is accumulated. If the accumulated number of failures exceeds a preset value, such as more than 10 liveness detection failures, the 5-second interval is extended to 30 seconds or 1 minute, etc., to reduce the frequency of liveness detection and further improve connection efficiency.
[0065] In this embodiment, detecting the activity of a second server outside the blacklist includes:
[0066] Step b3: Obtain the monitoring link corresponding to the second server outside the blacklist;
[0067] Step b4: Send a second heartbeat signal to the second server through the monitoring link, and determine whether the second server has successfully been identified as live based on the sending and receiving status of the second heartbeat signal;
[0068] Step b5: If the second server fails to be reactivated, add the server identifier corresponding to the second server to the blacklist and disconnect all connections of the client to the second server.
[0069] The system periodically probes for server availability using a monitoring thread. It iterates through the server address list and checks if the address is in the blacklist. If not, it probes a second server not on the blacklist. This second server typically already has a listening link with the client. The system then obtains the listening link for the second server outside the blacklist and sends a second heartbeat signal to it. The system determines whether the second server has successfully been identified as active based on the heartbeat signal's transmission and reception status. A normal heartbeat signal indicates successful identification, while an abnormal signal indicates failure. If the second server fails to be identified, it indicates an error and cannot provide service. The system then adds the corresponding service identifier to the blacklist and disconnects all connections between the client and the second server. This embodiment uses periodic, proactive server availability probing to determine whether to actively disconnect connections and add servers to the blacklist, ensuring that services can quickly obtain normal, serviceable connections.
[0070] The relevant technologies encompass two scenarios. The first scenario involves direct database connection establishment within the code, rather than using a database connection pool. In case of an exception, the connection is re-established either within the exception handler or via the main thread. Both methods incur costs associated with connection establishment and server address selection, making them inconvenient.
[0071] Quickly create new connections for business use. Second connection scenario: Businesses use database connection pool 5 for link management. The connection pool is responsible for the creation, release, and keep-alive maintenance of database links. When a business needs a database request, it requests a connection from the connection pool. The connection pool retrieves a connection from the idle link pool and provides it to the business. If no idle connection is available, it creates a new connection according to the configuration and returns it to the business. After use, the business returns the connection to the connection pool for maintenance. The connection pool supports approximately three types of keep-alive: fixed...
[0072] While methods like idle-time keep-alive, borrowing-time keep-alive, and return-time keep-alive exist, none can guarantee a rapid return of a healthy connection to the application in the event of a server-side anomaly. This embodiment addresses the fact that most application scenarios require database connection creation via a database driver. Unlike traditional solutions where database connections are managed by a business connection pool or by the business itself, this embodiment implements reverse self-management of the connection creation and already created connections within the database connection driver.
[0073] The mechanism works as follows: During connection establishment, servers are grouped based on their connection identifiers. Server addresses that fail to establish a connection are added to a blacklist to prevent them from being selected again in subsequent connection creations. A listening thread is started within the driver to periodically monitor the connection groups and the blacklist. This listening thread checks the server connection groups for liveness; groups that fail to establish liveness are added to the blacklist. Similarly, the listening thread checks the server connection groups for liveness; groups that fail to establish liveness actively and quickly disconnect existing connections. Finally, the listening thread checks the liveness of servers in the blacklist; successful liveness checks are performed on servers in the blacklist.
[0074] If the test is successful, the server is removed from the blacklist and added to the normal service list; the listening thread keeps a 0 count for the liveness detection of the blacklisted servers, and if the liveness detection fails continuously, the liveness detection weight is reduced.
[0075] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, this…
[0076] The technical solution of the invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0077] Example 2
[0078] This embodiment also provides a connection device for a distributed database, used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0079] Figure 4 This is a structural block diagram of a distributed database connection device according to an embodiment of the present invention, such as... Figure 4 As shown, the device includes: an acquisition module 60, a detection module 61, and a connection module 62, wherein,
[0080] The acquisition module 60 is used to acquire server identifiers corresponding to multiple servers in the driver of the distributed database, wherein the distributed database includes multiple servers;
[0081] The detection module 61 is used to perform serviceability detection on each server, disconnect the connection corresponding to the first server that is detected as abnormal, and add the server identifier corresponding to the first server to the blacklist.
[0082] The connection module 62 is used to receive a connection establishment request and select a second server outside the blacklist to create a connection based on the connection establishment request.
[0083] Optionally, the connection module includes a first connection unit, used to traverse the server identifiers of the distributed database and determine whether there is a server identifier corresponding to a second server outside the blacklist; if there is a server identifier corresponding to a second server outside the blacklist, then respond to the connection establishment request and create a connection between the client and the second server.
[0084] Optionally, the first connection unit is further configured to determine whether the connection between the client and the second server has been successfully established; if the connection between the client and the second server has been successfully established, it detects whether a packet has been established for the server identifier corresponding to the second server; if a packet has not been established for the server identifier corresponding to the second server, it creates a target packet and a listening link corresponding to the target packet based on the server identifier corresponding to the second server; and probes for the second server in the target packet through the listening link.
[0085] Optionally, the connection device of the distributed database further includes a listening module, which is used to start a listening and detection thread in the driver; and to detect the activity of the first server in the blacklist and the second server outside the blacklist through the listening and detection thread.
[0086] Optionally, the monitoring module includes a first monitoring unit, used to establish a liveness detection link through the monitoring liveness detection thread; send a first heartbeat signal to the first server through the liveness detection link, and determine whether the first server has been successfully live based on the sending and receiving status of the first heartbeat signal; if the first server has been successfully live, then remove the first server from the blacklist.
[0087] Optionally, the first monitoring unit is further configured to, if the first server fails to determine its liveness, accumulate the number of times the first server fails to determine its liveness; and reduce the frequency of determining the liveness of the first server through the liveness detection link based on the number of failures.
[0088] Optionally, the monitoring module further includes a second monitoring unit, used to obtain the monitoring link corresponding to the second server outside the blacklist; send a second heartbeat signal to the second server through the monitoring link, and determine whether the second server has successfully been identified as active based on the sending and receiving status of the second heartbeat signal; if the second server fails to be identified as active, add the server identifier corresponding to the second server to the blacklist, and disconnect all connections of the client to the second server.
[0089] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.
[0090] Example 3
[0091] Embodiments of the present invention also provide a storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above method embodiments when running.
[0092] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0093] S1, obtain server identifiers corresponding to multiple servers in the driver of the distributed database, wherein the distributed database includes multiple servers;
[0094] S2, perform serviceability detection on each server, disconnect the connection corresponding to the first server that is detected as abnormal, and add the server identifier corresponding to the first server to the blacklist;
[0095] S3, Receive a connection establishment request, and select a second server outside the blacklist to create a connection based on the connection establishment request.
[0096] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing computer programs, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0097] Embodiments of the present invention also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.
[0098] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0099] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0100] S1, obtain server identifiers corresponding to multiple servers in the driver of the distributed database, wherein the distributed database includes multiple servers;
[0101] S2, perform serviceability detection on each server, disconnect the connection corresponding to the first server that is detected as abnormal, and add the server identifier corresponding to the first server to the blacklist;
[0102] S3, Receive a connection establishment request, and select a second server outside the blacklist to create a connection based on the connection establishment request.
[0103] Optionally, specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated here.
[0104] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0105] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0106] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0107] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0108] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0109] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, 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. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0110] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A connection method of a distributed database, characterized by, The application is applied to a driving layer of a distributed database; the method comprises: In a driving program of a distributed database, a plurality of server identifiers corresponding to a plurality of servers are acquired, wherein the distributed database comprises the plurality of servers; The serviceability of each server is detected respectively, the connection corresponding to a first server which is detected as abnormal is disconnected, and the server identifier corresponding to the first server is added to a blacklist; The connection corresponding to the first server which is detected as abnormal is disconnected, comprising: All connections corresponding to the first server which is detected as abnormal are disconnected; A connection creation request is received, and a second server outside the blacklist is selected according to the connection creation request to create a connection; A monitoring alive thread is started in the driving program, an alive monitoring link is established through the monitoring alive thread, a first heartbeat signal is sent to the first server through the alive monitoring link, and the second server outside the blacklist is monitored alive; whether the first server is successfully judged alive is judged based on the sending and receiving state of the first heartbeat signal; If the first server fails to be judged alive, the number of times that the first server fails to be judged alive is accumulated; the frequency of judging the first server alive through the alive monitoring link is reduced according to the number of times that the first server fails to be judged alive; Whether the connection between the client and the second server is successfully created is judged; If the connection between the client and the second server is successfully created, whether the server identifier corresponding to the second server has been established into a group is detected; If the server identifier corresponding to the second server has not been established into a group, a target group corresponding to the server identifier of the second server and a monitoring link corresponding to the target group are created; The second server in the target group is monitored alive through the monitoring link; and the connection in the target group which is monitored alive abnormally is disconnected as a whole.
2. The method of claim 1, wherein, The connection between the client and the second server is created according to the connection creation request, comprising: The server identifiers of the distributed database are traversed, and whether the server identifier corresponding to the second server outside the blacklist exists is judged; If the server identifier corresponding to the second server outside the blacklist exists, the connection creation request is responded, and the connection between the client and the second server is created.
3. The method of claim 1, wherein, The second server outside the blacklist is monitored alive, comprising: The monitoring link corresponding to the second server outside the blacklist is acquired; A second heartbeat signal is sent to the second server through the monitoring link, and whether the second server is successfully judged alive is judged based on the sending and receiving state of the second heartbeat signal; If the second server fails to be judged alive, the server identifier corresponding to the second server is added to the blacklist, and all connections between the client and the second server are disconnected.
4. A connection apparatus of a distributed database, characterized by comprising: The application is applied to a driving layer of a distributed database; comprising: An acquisition module is configured to acquire, in a driving program of a distributed database, a plurality of server identifiers corresponding to a plurality of servers, wherein the distributed database comprises the plurality of servers; The detection module is configured to perform serviceability detection on each service end respectively, disconnect the connection corresponding to the first service end with an abnormal detection result, and add the service end identifier corresponding to the first service end to a blacklist. The connection corresponding to the first service end with an abnormal detection result is disconnected by disconnecting all connections corresponding to the first service end with an abnormal detection result. The connection module is configured to receive a connection establishment request, and establish a connection with a second service end outside the blacklist according to the connection establishment request. The listening module is configured to start a listening and alive detection thread in the driver program, establish an alive detection link through the listening and alive detection thread, send a first heartbeat signal to the first service end through the alive detection link, and perform alive detection on the second service end outside the blacklist. The alive detection of the first service end is determined based on the transmission and reception state of the first heartbeat signal. If the alive detection of the first service end fails, the number of times of alive detection failure of the first service end is accumulated. The alive detection frequency of the first service end through the alive detection link is reduced according to the number of times of alive detection failure. The connection module includes a first connection unit configured to determine whether the connection between the client and the second service end is successfully established. If the connection between the client and the second service end is successfully established, it is detected whether the service end identifier corresponding to the second service end has established a group. If the service end identifier corresponding to the second service end has not established a group, a target group corresponding to the service end identifier of the second service end and a listening link corresponding to the target group are established according to the service end identifier of the second service end. The alive detection of the second service end in the target group is performed through the listening link. For the connection in the target group with an abnormal alive detection, the connection is disconnected as a whole.
5. An electronic device, comprising: The communication interface is configured to communicate with other devices or servers outside the system. The memory is configured to store a computer program. The processor is configured to execute the method steps of any one of claims 1 to 3 by running the program stored in the memory.
6. A storage medium, characterized by The storage medium includes a stored program, wherein the program performs the method steps of any one of claims 1 to 3 when running. The storage medium includes a stored program, wherein the program performs the method steps of any one of claims 1 to 3 when running.
Citation Information
Patent Citations
Database connection exception handling method and device
CN109002373A
Service request forwarding system and method, computer equipment and storage medium
CN114785861A