Database node switching method and device, electronic equipment and storage medium
By using a database driver to determine the type of node disconnection exception and execute rollback or generate a proxy object, the problem of business errors caused by database node switching was solved, achieving efficient node switching and improved user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JINZHUAN INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2026-03-16
- Publication Date
- 2026-06-19
Smart Images

Figure CN122240722A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database systems and application software technology, and in particular to a method, apparatus, electronic device, and storage medium for switching database nodes. Background Technology
[0002] In modern enterprise applications and internet services, the efficiency and reliability of database access are crucial for stable system operation. Java Database Connectivity (JDBC), as a general-purpose database access interface, is widely used in various database systems.
[0003] Current database systems comprise both the database layer and the database driver layer. At the database layer, multiple nodes are deployed, and when one node fails, the system automatically switches to another. At the database driver layer, multiple node addresses can be configured, and if a connection to one node fails, the system retries establishing a connection with the next node. However, this current node switching method has significant drawbacks. When a database node fails, the connection from the failed node can lead to numerous errors in the business logic, requiring the business logic design to be idempotent, which increases the complexity of the business logic design. Summary of the Invention
[0004] This invention provides a database node switching method, apparatus, electronic device, and storage medium to solve the problem of numerous service errors caused by node failures and greatly reduce service interruptions caused by database switching.
[0005] According to one aspect of the present invention, a method for switching nodes in a database is provided, wherein the business terminal calls the corresponding target database through a database driver, and the target database is deployed in multiple nodes, the method comprising: When a disconnection occurs at the first node, the type of the disconnection is determined. The type of the disconnection is determined based on the parameter status of the first node. The parameter status describes whether the first node has any incomplete operations. If the exception type is the first exception type, a rollback operation is performed; the rollback operation returns to the state before the target transaction was executed and controls the database driver to switch the first node to the second node; the first exception type is used to describe that the first node has incomplete operations; If the exception type is the second exception type, the database driver is controlled to generate a native object associated with the second node, a target proxy object is generated based on the native object associated with the second node, and the target proxy object is returned to the business end so that the business end can connect to the second node based on the target proxy object; the target proxy object is an object after the native object is encapsulated.
[0006] According to another aspect of the present invention, a database node switching device is provided, wherein the business terminal calls the corresponding target database through a database driver, and the target database is deployed in multiple nodes, the device comprising: An anomaly detection module is used to determine the anomaly type of the chain breakage anomaly when the first node experiences a chain breakage anomaly; the anomaly type is determined based on the parameter status of the first node; the parameter status is used to describe whether the first node has any incomplete operations; The first switching module is used to perform a rollback operation if the exception type is a first exception type; the rollback operation is to return to the state before the target transaction was executed and control the database driver to switch the first node to the second node; the first exception type is used to describe that the first node has incomplete operations; The second switching module is used to control the database driver to generate a native object associated with the second node if the exception type is the second exception type, generate a target proxy object based on the native object associated with the second node, and return the target proxy object to the business end so that the business end can connect to the second node based on the target proxy object; the target proxy object is an object after the native object is encapsulated.
[0007] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the database node switching method according to any embodiment of the present invention.
[0008] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the node switching method of the database according to any embodiment of the present invention.
[0009] In the technical solution of this invention, the business end calls the corresponding target database through a database driver. The target database is deployed on multiple nodes. When a connection failure occurs on the first node, the type of the failure is determined. The failure type is determined based on the parameter status of the first node. The parameter status describes whether the first node has any incomplete operations, ensuring accurate determination of the failure type and facilitating better node switching. If the failure type is the first failure type, a rollback operation is performed. The rollback operation returns to the state before the target transaction was executed and controls the database driver to switch the first node to the second node. The first failure type describes that the first node has incomplete operations; that is, the first failure type indicates an abnormal state within the transaction. In this case, it is necessary to switch nodes promptly and then re-execute the target transaction on the second node to ensure that the business end's data requirements are not affected, reducing business interruptions caused by database switching and improving user experience. Furthermore, if the exception type is the second exception type, the database driver generates a native object associated with the second node, generates a target proxy object based on the native object associated with the second node, and returns the target proxy object to the business end, enabling the business end to connect to the second node based on the target proxy object. If the second exception type is an exception outside of a transaction, in order to minimize errors and avoid affecting the business process, the database driver is modified to replay the business information sent by the business end. This re-establishes the link between the business end and the second node based on the database driver, ensuring timely node switching and reducing subsequent errors when the business executes operations on the first node. This significantly reduces the problem of numerous business errors caused by faulty node connections. In short, this invention only requires modification of the database driver, without requiring additional database cooperation, thus improving its versatility.
[0010] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0011] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a flowchart of a database node switching method provided by an embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of a database node switching device according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of an electronic device that implements the database node switching method of the present invention, according to an embodiment of the present invention. Detailed Implementation
[0013] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0014] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention 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 the invention 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 a non-exclusive inclusion; for example, a process, method, system, 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.
[0015] Example 1 Figure 1 This is a flowchart of a database node switching method provided in an embodiment of the present invention. This embodiment is applicable to situations where database nodes are switched outside of a transaction. The method can be executed by a database node switching device, which can be implemented in hardware and / or software. The database node switching device can be configured in any electronic device with network communication capabilities.
[0016] In this invention, the business side calls the corresponding target database through a database driver, and the target database is deployed on multiple nodes. For example, the database driver can be a JDBC driver; JDBC (Java Database Connectivity) is the standard interface for Java to operate databases, while a JDBC driver is a specific class library implemented by a database vendor that conforms to the JDBC specification. Its function is to enable Java programs to establish connections with specific databases (such as MySQL, Oracle, and PostgreSQL) and execute SQL.
[0017] like Figure 1As shown, the node switching method of the database of the present invention may include the following process: S110. When a chain break occurs at the first node, determine the type of the chain break. The type of the chain break is determined based on the parameter status of the first node. The parameter status describes whether the first node has any unfinished operations.
[0018] The first node disconnection exception can be understood as the business side being unable to establish a connection with the first node through the database driver, meaning it cannot normally access the first node. The disconnection exception can be understood as the connection between the business side and the database node being unavailable.
[0019] Specifically, when the business side issues an instruction for a target requirement, the corresponding data content is in the target database, and a first node is assigned to this target requirement. A connection is established between the first node and the business side based on the database driver, enabling the business side to call the first node to perform relevant business operations. Furthermore, if a connection failure is received from the first node, this failure can occur during the process of the business side calling the first node to perform relevant business operations, during the initial call to the first node before relevant business operations are performed, or after the business side has called the first node to perform and completed relevant business operations. The parameter status of the first node differs at different stages of the connection failure. Therefore, by analyzing the parameter status of the first node, the type of connection failure can be determined, allowing for precise judgment on how to switch nodes.
[0020] Optionally, the parameter state can be any one of the following: the first node has no target transaction, the target transaction corresponding to the first node is in an incomplete state, the target transaction corresponding to the first node is in a completed state, and the target transaction corresponding to the first node is in an unexecuted state.
[0021] Specifically, "no target transaction on the first node" can be understood as no transaction being executed within the reference time period when the business connects to the first node; the reference time period refers to a preset time period before the connection failure occurs. "The target transaction corresponding to the first node is in an unexecuted state" can be understood as the connection failure occurring before the target transaction was executed after the business connected to the first node. In other words, the case where the target transaction corresponding to the first node is in an incomplete state can be categorized as a connection failure occurring within a transaction, while the cases where the first node has no target transaction, the target transaction corresponding to the first node is in a completed state, and the target transaction corresponding to the first node is in an unexecuted state can be categorized as connection failure occurring outside of a transaction.
[0022] Accordingly, the exception class for determining the chain break exception can include: if the parameter status is that the target transaction corresponding to the first node is in an incomplete state, then the exception type is the first exception type. If the parameter status is any one of the following states: the first node has no target transaction, the target transaction corresponding to the first node is in a completed state, or the target transaction corresponding to the first node is in an unexecuted state, then the exception type is the second exception type. That is, the first exception type of this invention corresponds to the chain break exception occurring within a transaction, and the second exception type corresponds to the chain break exception occurring outside a transaction, thereby facilitating the subsequent accurate allocation of the corresponding node switching method.
[0023] S120. If the exception type is the first exception type, then a rollback operation is performed. The rollback operation returns to the state before the target transaction was executed and controls the database driver to switch the first node to the second node. The first exception type is used to describe that the first node has incomplete operations.
[0024] The second node can be understood as one of the nodes that can establish a normal link with the business side.
[0025] Specifically, if the exception type is the first exception type, the exception is thrown and the business side issues a rollback operation, that is, the state before the execution of the target transaction is returned, the database driver is controlled to switch the first node to the second node, and then the relevant operations of the target transaction are executed on the second node to prevent consistency issues.
[0026] Optionally, in an embodiment of the present invention, after performing a rollback operation, the method further includes: sending and displaying target notification information to the business terminal; and, in response to a confirmation operation on the target notification information, executing the target transaction based on the second node. The target notification information describes that the execution node of the target transaction has switched from the first node to the second node. Specifically, the confirmation operation on the target notification information can be understood as confirming that the execution node of the target transaction has switched from the first node to the second node. The present invention sends and displays target notification information to the business terminal, thereby informing the user of the node switching information. Furthermore, after the user confirms the target notification information, the target transaction is executed based on the second node, enhancing the user's right to know about the execution of the target transaction and improving the user experience.
[0027] S130. If the exception type is the second exception type, the database driver is controlled to generate a native object associated with the second node, generate a target proxy object based on the native object associated with the second node, and return the target proxy object to the business end so that the business end can connect to the second node based on the target proxy object; the target proxy object is an object after the native object is encapsulated.
[0028] Native objects can be used to directly establish links between the business side and nodes, execute operations of the target transaction after the link is established, or return the result data after executing the target transaction. Proxy objects can be understood as objects that wrap native objects; that is, the core of proxy objects is enhanced logic and forwarding calls, meaning they execute their own enhanced logic first, and then call the methods of the native object.
[0029] For example, the native object is Connection, which includes the logic of establishing a link between the business end and the node. The proxy object for Connection can be used to manage operations such as "link establishment / closure, transactions, and statement creation". Among them, Statement is the operation to execute the target transaction, such as SQL execution.
[0030] If the native object is Statement, then the proxy object for Statement can be used to manage "SQL execution, parameter setting, batch operations, creation of ResultSet", etc.; ResultSet can be understood as the data result after the operation of the target transaction is executed.
[0031] The native object is ResultSet, and the proxy object for ResultSet can be used to manage and control commands related to reading results and executing transaction results.
[0032] Specifically, the business side is directly aware of the native object, while it remains unaware of the proxy object. This essentially follows the Liskov Substitution Principle in object-oriented programming, meaning that a subclass / implementation class can replace a parent class / interface without affecting the correctness of the program. Specifically regarding JDBC proxies: the proxy object acts as an "enhanced implementation class" of the JDBC interface, fully compatible with all behaviors of the native object. When the business side calls `conn.createStatement()`, regardless of whether `conn` is a native object or a proxy object, it will obtain a `Statement` object; when the business side calls `stmt.executeQuery(sql)`, regardless of whether `stmt` is native or a proxy, it will obtain a `ResultSet` object, and the result is consistent with the native execution (it may only be enhanced by the proxy, such as data masking, but the business side is unaware of the "enhancement" itself, only seeing the consistent result format). This allows the business side to connect to the second node based on the target proxy object, so that the business side is unaware of the node switch, but the node switch process has actually occurred.
[0033] Optionally, if the parameter status indicates that the target transaction corresponding to the first node is in a completed state, while returning the target proxy object to the business end, the method further includes: obtaining the result data of the first node completing the target transaction and returning the result data to the business end. Specifically, since the execution process of the target transaction has already been completed at the first node, to avoid executing the target transaction again and causing data confusion, the result data of the first node completing the target transaction is returned to the business end so that the business end can directly use the result data without repeating the target transaction later. Moreover, if the target transaction has an associated reference transaction, the execution of subsequent reference transactions can be guided based on the result data, avoiding the situation where the reference transaction fails to receive the execution result of the target transaction and thus executes incorrectly.
[0034] Optionally, before controlling the database driver to generate the native object associated with the second node, the method further includes: determining the target location of the connection failure; if the target location is within a whitelist, then determining to switch the first node; the whitelist describes the locations where node switching is possible. Specifically, the whitelist describes the locations where node switching is possible. That is, when a connection failure occurs, if the location of the connection failure is within the whitelist, a node switching operation can be performed; if it is not within the whitelist, a node switching operation cannot be performed, and an exception needs to be thrown directly. This ensures that node switching is possible only after a connection failure occurs, preventing system chaos caused by arbitrary node switching.
[0035] Optionally, after returning the target proxy object to the business end, the method further includes: cleaning up the relevant resources of the link corresponding to the first node to avoid the existence of the relevant resources of the link with the broken link from affecting the execution of other links, or to avoid resource leakage.
[0036] In the technical solution of this invention, the business end calls the corresponding target database through a database driver. The target database is deployed on multiple nodes. When a connection failure occurs on the first node, the type of the failure is determined. The failure type is determined based on the parameter status of the first node. The parameter status describes whether the first node has any incomplete operations, ensuring accurate determination of the failure type and facilitating better node switching. If the failure type is the first failure type, a rollback operation is performed. The rollback operation returns to the state before the target transaction was executed and controls the database driver to switch the first node to the second node. The first failure type describes that the first node has incomplete operations; that is, the first failure type indicates an abnormal state within the transaction. In this case, it is necessary to switch nodes promptly and then re-execute the target transaction on the second node to ensure that the business end's data requirements are not affected, reducing business interruptions caused by database switching and improving user experience. Furthermore, if the exception type is the second exception type, the database driver generates a native object associated with the second node, generates a target proxy object based on the native object associated with the second node, and returns the target proxy object to the business end, enabling the business end to connect to the second node based on the target proxy object. If the second exception type is an exception outside of a transaction, in order to minimize errors and avoid affecting the business process, the database driver is modified to replay the business information sent by the business end. This re-establishes the link between the business end and the second node based on the database driver, ensuring timely node switching and reducing subsequent errors when the business executes operations on the first node. This significantly reduces the problem of numerous business errors caused by faulty node connections. In short, this invention only requires modification of the database driver, without requiring additional database cooperation, thus improving its versatility.
[0037] Example 2 Figure 2 This is a schematic diagram of a database node switching device provided in an embodiment of the present invention. This embodiment is applicable to situations where database nodes are switched outside of a transaction. The database node switching device can be implemented in hardware and / or software, and can be configured in any electronic device with network communication capabilities. The business terminal of the present invention calls the corresponding target database through a database driver. The target database is deployed on multiple nodes, such as... Figure 2 As shown, the node switching device for the database of the present invention may include: The anomaly detection module 210 is used to determine the anomaly type of the chain breakage anomaly when the first node experiences a chain breakage anomaly; the anomaly type is determined based on the parameter status of the first node; the parameter status is used to describe whether the first node has any incomplete operations; The first switching module 220 is used to perform a rollback operation if the exception type is a first exception type; the rollback operation is to return to the state before the execution of the target transaction and control the database driver to switch the first node to the second node; the first exception type is used to describe that the first node has incomplete operations; The second switching module 230 is used to control the database driver to generate a native object associated with the second node if the exception type is the second exception type, generate a target proxy object based on the native object associated with the second node, and return the target proxy object to the business end so that the business end can connect to the second node based on the target proxy object; the target proxy object is an object after the native object is encapsulated.
[0038] Based on the above embodiments, optionally, the parameter state can be any one of the following states: the first node has no target transaction, the target transaction corresponding to the first node is in an incomplete state, the target transaction corresponding to the first node is in a completed state, and the target transaction corresponding to the first node is in an unexecuted state.
[0039] Based on the above embodiments, optionally, the exception judgment module is used to: if the parameter status is that the target transaction corresponding to the first node is in an incomplete state, then the exception type is a first exception type; if the parameter status is any one of the following states: the first node has no target transaction, the target transaction corresponding to the first node is in a completed state, and the target transaction corresponding to the first node is in an unexecuted state, then the exception type is a second exception type.
[0040] Based on the above embodiments, optionally, if the parameter status indicates that the target transaction corresponding to the first node is in a completed state, the device further includes a data processing module. The data processing module is used to return the target proxy object to the business terminal while obtaining the result data of the first node completing the target transaction, and returning the result data to the business terminal.
[0041] Optionally, based on the above embodiments, the device further includes a switching judgment module: the switching judgment module is used to: determine the target location of the broken link exception before the control database driver generates the native object associated with the second node; if the target location is in the whitelist, then determine to switch the first node; the whitelist is used to describe the locations where node switching can be performed.
[0042] Optionally, based on the above embodiments, the device further includes a data cleaning module, which is used to clean up the relevant resources of the link corresponding to the first node after returning the target proxy object to the business terminal.
[0043] Optionally, based on the above embodiments, the first switching module further includes a transaction execution unit, which is used to: send and display target prompt information to the business end after performing a rollback operation; and execute the target transaction based on the second node in response to the confirmation operation of the target prompt information; the target prompt information is used to describe that the execution node of the target transaction has been switched from the first node to the second node.
[0044] The database node switching device provided in this embodiment of the invention can execute the database node switching method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method execution.
[0045] Example 3 According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0046] Figure 3 A schematic diagram of an electronic device is shown that can be used to implement the node switching method for a database according to embodiments of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0047] like Figure 3 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0048] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0049] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as the node switching method for a database.
[0050] In some embodiments, the database node switching method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via read-only memory (ROM) 12 and / or communication unit 19. When the computer program is loaded into random access memory (RAM) 13 and executed by processor 11, one or more steps of the database node switching method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the database node switching method by any other suitable means (e.g., by means of firmware).
[0051] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0052] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0053] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0054] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0055] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0056] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0057] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0058] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for switching nodes in a database, characterized in that, The business logic calls the corresponding target database through a database driver. The target database is deployed on multiple nodes. The method includes: When a disconnection occurs at the first node, the type of the disconnection is determined. The type of the disconnection is determined based on the parameter status of the first node. The parameter status describes whether the first node has any incomplete operations. If the exception type is the first exception type, a rollback operation is performed; the rollback operation returns to the state before the target transaction was executed and controls the database driver to switch the first node to the second node; the first exception type is used to describe that the first node has incomplete operations; If the exception type is the second exception type, the database driver is controlled to generate a native object associated with the second node, a target proxy object is generated based on the native object associated with the second node, and the target proxy object is returned to the business end so that the business end can connect to the second node based on the target proxy object; the target proxy object is an object after the native object is encapsulated.
2. The method according to claim 1, characterized in that, The parameter state can be any one of the following: the first node has no target transaction, the target transaction corresponding to the first node is in an incomplete state, the target transaction corresponding to the first node is in a completed state, and the target transaction corresponding to the first node is in an unexecuted state.
3. The method according to claim 2, characterized in that, Determine the anomaly type of the chain break anomaly, including: If the parameter status indicates that the target transaction corresponding to the first node is in an incomplete state, then the exception type is the first exception type. If the parameter status is any one of the following: the first node has no target transaction, the target transaction corresponding to the first node is in a completed state, or the target transaction corresponding to the first node is in an unexecuted state, then the exception type is the second exception type.
4. The method according to claim 3, characterized in that, If the parameter status indicates that the target transaction corresponding to the first node is in a completed state, the method further includes returning the target proxy object to the business end while simultaneously: Obtain the result data of the first node completing the target transaction, and return the result data to the business terminal.
5. The method according to claim 1, characterized in that, Before controlling the database driver to generate the native object associated with the second node, the method further includes: Determine the target location of the broken link anomaly. If the target location is within the whitelist, then determine to switch the first node. The whitelist is used to describe the locations where node switching is possible.
6. The method according to claim 1, characterized in that, After returning the target proxy object to the business terminal, the method further includes: Clean up the relevant resources of the link corresponding to the first node.
7. The method according to claim 1, characterized in that, After performing the rollback operation, the method further includes: Send and display target prompt information to the business end; in response to the confirmation operation of the target prompt information, execute the target transaction based on the second node; the target prompt information is used to describe the execution node of the target transaction being switched from the first node to the second node.
8. A node switching device for a database, characterized in that, The business logic calls the corresponding target database through a database driver. The target database is deployed on multiple nodes. The device includes: An anomaly detection module is used to determine the anomaly type of the chain breakage anomaly when the first node experiences a chain breakage anomaly; the anomaly type is determined based on the parameter status of the first node; the parameter status is used to describe whether the first node has any incomplete operations; The first switching module is used to perform a rollback operation if the exception type is a first exception type; the rollback operation is to return to the state before the target transaction was executed and control the database driver to switch the first node to the second node; the first exception type is used to describe that the first node has incomplete operations; The second switching module is used to control the database driver to generate a native object associated with the second node if the exception type is the second exception type, generate a target proxy object based on the native object associated with the second node, and return the target proxy object to the business end so that the business end can connect to the second node based on the target proxy object; the target proxy object is an object after the native object is encapsulated.
9. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the node switching method of the database according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the node switching method of the database according to any one of claims 1-7.