Database connection method and device, equipment and storage medium
Through the client, the backup library attributes are changed to the main library in the database connection task, disconnect and update the backup library list, solving the problem of overloading the new main library after the main library is switched, and the service continuity and high availability are achieved.
Patent Information
- Application Number
- CN202411831455.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-03-25
AI Technical Summary
When the main and backup library is switched, the backup library cannot be upgraded to the main library in time, resulting in the problem of overloading the new main library.
When the client receives the database connection task, it reads the database attributes to be accessed. If it is a backup library, it selects the target backup library in the cached backup library list, sends a connection request, and obtains the current database schema and attributes of the target backup library. When the properties of the target backup library are changed to the main library, disconnect and update the backup library list until the connection is re-established.
By timely perceiving the situation where the backup library switches to the main library, we will avoid the new main library from taking on reading and writing services at the same time, thereby preventing the new main library from being overloaded and ensuring service continuity.
Smart Images

Figure CN119691046A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of financial technology, and in particular to a database connection method, device, equipment and storage medium. Background Art
[0002] Read-write separation means separating the read and write operations of a database to different database nodes. For example, in a master-slave architecture, database write operations are assigned to the master database for processing, and database read operations are assigned to the slave database for processing. This method allows the master database to centrally process write loads, while the slave database can process multiple read requests in parallel, thereby improving the total throughput of the database.
[0003] For read-write separation application direct connection scenarios, when a master-slave database switch occurs, if the slave database cannot sense that it has been promoted to the master database, the new master database will carry both read and write services, causing a sudden increase in business traffic, which can easily cause database overload and ultimately affect the continuity of services provided by the new master database. Summary of the invention
[0004] The present invention provides a database connection method, device, equipment and storage medium to solve the problem of overload of a new main database caused by failure to timely perceive the upgrade of the main database by the backup database in the case of main-backup switching.
[0005] According to one aspect of the present invention, a database connection method is provided, which is applied to a client and includes:
[0006] In response to a user initiating a database connection task, reading a property of a database to be connected in the database connection task;
[0007] In the case where the attribute of the database to be connected is a standby database, a target standby database is selected from a cached standby database list, and a connection request is sent to the target standby database; the standby database list includes at least one standby database and standby database connection information included in the database architecture;
[0008] Obtaining the current database architecture fed back by the target standby database and the current properties of the target standby database;
[0009] When the current attribute of the target standby database is changed to the master database, the connection with the target standby database is disconnected, and after the standby database list is updated according to the current database architecture, the operation of selecting the target standby database in the cached standby database list is returned to be executed until the connection with the standby database is established.
[0010] According to another aspect of the present invention, a database connection method is provided, which is applied to a database node and includes:
[0011] In response to a connection request sent by a client, obtaining a property of a database to be accessed in the connection request;
[0012] In the case where the attribute of the database to be connected is a standby database, establishing a connection with the client, and feeding back the current database architecture and the current attributes of the current database node to the client, so as to instruct the client to update the standby database list according to the current database architecture, so as to establish a connection with the standby database according to the standby database list;
[0013] The standby database list includes at least one standby database and standby database connection information contained in the database architecture.
[0014] According to another aspect of the present invention, there is provided a database connection device, which is configured on a client and includes:
[0015] A connection task reading module, used for reading the attributes of the database to be connected in the database connection task in response to the user initiating the database connection task;
[0016] A connection request sending module, configured to select a target standby database from a cached standby database list and send a connection request to the target standby database when the attribute of the database to be connected is a standby database; the standby database list includes at least one standby database and standby database connection information included in the database architecture;
[0017] An attribute acquisition module, used to acquire the current database architecture fed back by the target standby database and the current attributes of the target standby database;
[0018] The database connection module is used to disconnect the target standby database when the current attribute of the target standby database is changed to the primary database, and after updating the standby database list according to the current database architecture, return to execute the operation of selecting the target standby database in the cached standby database list until the connection with the standby database is established.
[0019] According to another aspect of the present invention, there is provided a database connection device, which is configured in a database node and includes:
[0020] A database attribute acquisition module, used to respond to a connection request sent by a client and acquire the attributes of the database to be connected in the connection request;
[0021] An attribute feedback module, used for establishing a connection with the client when the attribute of the database to be connected is a standby database, and feeding back the current database architecture and the current attributes of the current database node to the client, so as to instruct the client to update the standby database list according to the current database architecture, so as to establish a connection with the standby database according to the standby database list;
[0022] The standby database list includes at least one standby database and standby database connection information contained in the database architecture.
[0023] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0024] at least one processor; and
[0025] a memory communicatively connected to the at least one processor; wherein,
[0026] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the database connection method described in any embodiment of the present invention.
[0027] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the database connection method described in any embodiment of the present invention when executed.
[0028] According to another aspect of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the database connection method of any embodiment of the present disclosure is implemented.
[0029] According to the technical solution of the embodiment of the present invention, in response to a user initiating a database connection task, the client reads the attribute of the database to be connected in the database connection task, selects the target standby database from the cached standby database list when the attribute of the database to be connected is a standby database, and sends a connection request to the target standby database, thereby obtaining the current database architecture and the current attribute of the target standby database fed back by the target standby database, disconnects the target standby database when the current attribute of the target standby database is changed to a master database, and after updating the standby database list according to the current database architecture, returns to perform the operation of selecting the target standby database in the cached standby database list until a connection is established with the standby database, determines whether to establish a connection with the current database node through the current database architecture and current attribute fed back by the database node, and can avoid the problem of overloading the new master database caused by the new master database simultaneously taking on read and write services when the standby database is switched to the master database.
[0030] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0032] Figure 1ais a flowchart of a database connection method provided according to Embodiment 1 of the present invention;
[0033] Figure 1b This is a flowchart of a method for establishing a standby database connection provided according to Embodiment 1 of the present invention;
[0034] Figure 2 is a flowchart of a database connection method provided according to Embodiment 2 of the present invention;
[0035] Figure 3 is a schematic diagram of the structure of a database connection device provided according to Embodiment 3 of the present invention;
[0036] Figure 4 is a schematic diagram of the structure of a database connection device provided according to a fourth embodiment of the present invention;
[0037] Figure 5 It is a structural schematic diagram of an electronic device for implementing the database connection method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0038] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0039] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0040] Embodiment 1
[0041] Figure 1aA flowchart of a database connection method is provided for the first embodiment of the present invention. This embodiment is applicable to the case where a client establishes a connection with a standby database in a master-standby architecture. The method can be executed by a database connection device, which can be implemented in the form of hardware and / or software. The database connection device can be configured in various general computing devices, for example, the device where the database client is located. Figure 1a As shown, the method includes:
[0042] S110 . In response to a user initiating a database connection task, read attributes of a database to be connected in the database connection task.
[0043] The database connection task is initiated by the client user of the database and is used to instruct the database driver of the client to establish a connection with the primary database or the backup database in the database architecture. Exemplarily, the database connection task includes a flag bit of the attribute of the database to be connected, wherein the attribute of the database to be connected includes the primary database and the backup database. For example, if the attribute flag bit of the database to be connected is 1, it means that the database to be connected is the primary database, and if the attribute flag bit of the database to be connected is 0, it means that the database to be connected is the backup database.
[0044] In an embodiment of the present invention, after receiving a database connection task initiated by a user, the client first interprets the database connection task, obtains a property flag of the database to be connected in the database connection task, and determines the property of the database to be connected according to the flag. Exemplarily, after receiving a database connection task initiated by a user, if the property flag of the database to be connected in the database connection task is 0, it can be determined that the database to be connected is a standby database.
[0045] S120: When the attribute of the database to be connected is a standby database, select a target standby database from the cached standby database list, and send a connection request to the target standby database; the standby database list includes at least one standby database included in the database architecture and the standby database connection information.
[0046] The list of standby databases is determined based on the database architecture fed back by the database node when the connection with the database node was established last time, and contains a list of all standby databases in the database architecture. The database architecture is a master-slave architecture, which specifically includes a master database and at least one standby database. When the master database fails, the standby database can be upgraded to the master database to ensure high availability of the database, that is, the master and standby databases may switch.
[0047] In an embodiment of the present invention, when the attribute of the database to be connected is a standby database, a target standby database can be selected from a pre-cached standby database list, and a connection request can be sent to the target standby database. Specifically, when multiple standby databases do not need to be load balancing, a standby database can be randomly selected from the standby database list as the target standby database, or the first standby database in the standby database list can be directly selected as the target standby database. When multiple standby databases need to be load balancing, the standby database that was last connected can be determined based on the database connection history record, and the next standby database of the standby database that was last connected can be selected from the standby database list as the target standby database. Further, a connection request is initiated to the standby database, and the original connection establishment process is executed.
[0048] Optionally, when the attribute of the database to be connected is a standby database, a target standby database is selected from the cached standby database list, and a connection request is sent to the target standby database, including:
[0049] When the database to be connected is a standby database, read the load balancing flag in the database connection task;
[0050] When the load balancing flag indicates that load balancing is required, the target standby database is determined in the cached standby database list according to the database connection history, and a connection request is sent to the target standby database.
[0051] In this optional embodiment, the process of establishing a standby database connection is as follows: Figure 1b As shown, a specific solution is provided for selecting a target standby database from a cached standby database list and sending a connection request to the target standby database when the attribute of the database to be connected is a standby database: when the attribute of the database to be connected is a standby database, read the load balancing flag in the database connection task. The load balancing flag can be 1 or 0. If the load balancing flag is 1, it means that multiple standby databases need to be loaded; if the load balancing flag is 0, it means that multiple standby databases do not need to be loaded.
[0052] When the load balancing flag indicates that load balancing is required, the target standby database is determined in the cached standby database list according to the database connection history record, and a connection request is sent to the target standby database. Specifically, multiple standby databases in the standby database list are stored in the form of a ring link. The standby databases that have been connected to the client before this connection can be determined according to the database connection history record. The first standby database that has not established a connection with the client is selected as the target standby database in the ring link, that is, the next standby database of the last connected standby database is selected in the ring link. By load balancing multiple standby databases, the processing efficiency of read services can be improved, thereby improving the data throughput of the database architecture.
[0053] Optionally, after sending a connection request to the target standby database, the following steps are also included:
[0054] In response to the target standby database feedback that the connection cannot be established, the target standby database is deleted from the standby database list, and the operation of selecting the target standby database from the cached standby database list and sending a connection request to the target standby database is performed again until a connection is established with the standby database.
[0055] In this optional embodiment, when the target standby database needs to be upgraded to the main database, a state in which the connection cannot be established will be set. If a connection request initiated by the client is received at this time, a prompt indicating that the connection cannot be established will be fed back. After the client sends a connection request to the target standby database, if it receives a prompt indicating that the connection cannot be established from the target standby database, it indicates that the target standby database is in the process of upgrading the main database, or the target standby database is faulty. At this time, the database can delete the target standby database from the standby database list, return to execute the operation of selecting the target standby database in the cached standby database list, and sending a connection request to the target standby database until a connection is established with the standby database. By obtaining the connection state of the target standby database based on the connection request feedback, the read-only traffic isolation capability of the new main database during the main-standby switching process is effectively improved, ensuring that all read-only traffic is switched to other standby databases, thereby avoiding the problem of high load pressure on the new main database during the switching process.
[0056] S130: Obtain the current database architecture fed back by the target standby database and the current properties of the target standby database.
[0057] In an embodiment of the present invention, after sending a connection request to a target standby database, the current database architecture fed back by the target standby database and the current attributes of the target standby database are obtained. The current database architecture may include the current master database, master database connection information, at least one standby database, and connection information of each standby database. Since the master database and the standby database in the database architecture can be switched flexibly, when the master database fails, the standby database can be upgraded to the master database at any time. Therefore, each time the database node receives a connection request, it needs to feed back the current attributes to the client so that the client can determine whether the attributes of the currently connected database are the attributes of the database to be connected.
[0058] For example, the target standby database determined according to the standby database list may have been upgraded to the primary database when the connection is established, so the client needs to obtain the current database architecture and current properties of the target standby database fed back by the target standby database to confirm that the target standby database currently requested to connect is still a standby database.
[0059] S140: When the current attribute of the target standby database is changed to the primary database, disconnect the target standby database, update the standby database list according to the current database architecture, and then return to execute the operation of selecting the target standby database in the cached standby database list until the connection with the standby database is established.
[0060] In the embodiment of the present invention, when the current attribute of the target standby database is changed to the master database, it means that the attribute of the target standby database has changed during the connection process, and the standby database has been upgraded to the master database. At this time, it is necessary to disconnect the connection with the target standby database (i.e., the current new master database), and after updating the standby database list according to the current database architecture, return to perform the operation of selecting the target standby database in the cached standby database list until the connection with the standby database is established. This verification process can avoid the new master database from accessing read-only traffic again when the target standby database is upgraded to the master database, and can timely update the standby database list, so as to perceive the changes of the master and standby databases without increasing the performance pressure of the client and database.
[0061] Optionally, the embodiment of the present invention further includes:
[0062] When the attribute of the database to be connected is a standby database and the cached standby database list is empty, a connection request is sent to the primary database through a virtual network device pre-registered with the primary database information;
[0063] Get the current database schema and current properties of the main database feedback;
[0064] If the current properties of the primary database have not changed, disconnect from the primary database, update the standby database list according to the current database schema, and then return to select the target standby database in the cached standby database list until a connection is established with the standby database.
[0065] In this optional embodiment, when the attribute of the database to be connected is a standby database and the cached standby database list is empty, it means that the current client is establishing a connection for the first time, and a connection request can be sent to the main database through a virtual network device with the main database information pre-registered, thereby obtaining the current database architecture and current attributes of the main database fed back by the main database. If the current attributes of the main database have not changed, that is, they are still the main database attributes, disconnect from the main database, and after updating the standby database list according to the current database architecture, return to execute the operation of selecting the target standby database in the cached standby database list until a connection is established with the standby database.
[0066] In addition, when the attribute of the database to be connected is a standby database and the cached standby database list is empty, you can also send a connection request to the first database node in the database architecture through the database architecture contained in the database connection task initiated by the user, and then obtain the current database architecture fed back by the first database node and the current attributes of the first database node. When the current attribute of the first database node is the main database attribute, disconnect from the main database, and update the standby database list according to the current database architecture, and then return to execute the operation of selecting the target standby database in the cached standby database list until the connection with the standby database is established; when the current attribute of the first database node is a standby database, confirm that the connection process is complete. When the client connects to the standby database for the first time, if there is no standby database list, complete the establishment of the standby database, and cache the standby database list locally for subsequent standby database connections.
[0067] According to the technical solution of the embodiment of the present invention, in response to a user initiating a database connection task, the client reads the attribute of the database to be connected in the database connection task, selects the target standby database from the cached standby database list when the attribute of the database to be connected is a standby database, and sends a connection request to the target standby database, thereby obtaining the current database architecture and the current attribute of the target standby database fed back by the target standby database, disconnects the target standby database when the current attribute of the target standby database is changed to a master database, and after updating the standby database list according to the current database architecture, returns to perform the operation of selecting the target standby database in the cached standby database list until a connection is established with the standby database, determines whether to establish a connection with the current database node through the current database architecture and current attribute fed back by the database node, and can avoid the problem of overloading the new master database caused by the new master database simultaneously taking on read and write services when the standby database is switched to the master database.
[0068] Embodiment 2
[0069] Figure 2 A flowchart of a database connection method provided for Embodiment 2 of the present invention. This embodiment is applicable to situations where a client establishes a connection with a standby database in a master-standby architecture. The method can be executed by a database connection device, which can be implemented in the form of hardware and / or software. The database connection device can be configured in various general-purpose computing devices, such as database nodes.
[0070] like Figure 2 As shown, the method includes:
[0071] S210: In response to a connection request sent by a client, obtain attributes of a database to be accessed in the connection request.
[0072] The connection request is sent by the client to the database node to request to establish a connection with the database node. The connection request includes the attribute flag of the database to be connected. For example, if the attribute flag of the database to be connected is 1, it means that the database to be connected is the primary database, and if the attribute flag of the database to be connected is 0, it means that the database to be connected is the backup database.
[0073] In the embodiment of the present invention, after receiving the connection request sent by the client, the database node first needs to obtain the attribute of the database to be accessed in the connection request. Specifically, obtain the attribute flag of the database to be accessed in the connection request, and determine the attribute of the database to be accessed according to the flag.
[0074] S220: When the attribute of the database to be connected is a standby database, establish a connection with the client, and feedback the current database architecture and the current attributes of the current database node to the client, so as to instruct the client to update the standby database list according to the current database architecture, so as to establish a connection with the standby database according to the standby database list;
[0075] The standby database list includes at least one standby database and standby database connection information contained in the database architecture.
[0076] In the embodiment of the present invention, in order to ensure that all read-only traffic is switched to other standby databases in the event of a master-slave switch, the database node feeds back the current database architecture and the current attributes of the current database node to the client when determining that the attribute of the database to be connected is a standby database and establishing a connection with the client. The client updates the standby database list according to the current database architecture, and when the current database node is the master database, disconnects from the master database and establishes a connection with the standby database according to the updated standby database list.
[0077] Optionally, the embodiment of the present invention further includes:
[0078] In response to a user's instruction to change the attribute of the current database node from a standby database to a primary database, the connection state of the current database node is set to a connection-unable state, and the currently active in-transit connection is disconnected;
[0079] Execute the command to change the standby database to the primary path and restore the connection status to the state where the connection can be established.
[0080] In this optional embodiment, when the database node receives the user's instruction to change the attribute of the current database node from the standby database to the main database, it first sets the connection status of the current database node to a state where it cannot be connected, and disconnects the currently active in-transit connection, effectively improving the read-only traffic isolation capability of the new main database during the switching process, and ensuring that 100% of the read-only traffic is switched to other standby databases. Further, the instruction to change the standby database to the main path is executed, and the connection status is restored to a state where it can be connected, so that the new main database can quickly process write traffic. Through the above process, the client does not need to make additional modifications, and can trigger a connection exception error (i.e., feedback that the connection cannot be established) when connecting to the database node next time, and reconnect based on the general client connection pool connection management function.
[0081] According to the technical solution of the embodiment of the present invention, a database node responds to a connection request sent by a client, obtains the attribute of the database to be connected in the connection request, establishes a connection with the client when the attribute of the database to be connected is a standby database, and feeds back the current database architecture and the current attribute of the current database node to the client, so as to instruct the client to update the standby database list according to the current database architecture, so as to establish a connection with the standby database according to the standby database list. By feeding back the current database architecture and the current attribute to the client, the client can determine whether to establish a connection with the current database node, thereby avoiding the problem of overloading the new main database caused by the new main database taking on read and write services at the same time when the standby database switches to the main database.
[0082] Embodiment 3
[0083] Figure 3 This is a schematic diagram of the structure of a database connection device provided in Embodiment 3 of the present invention, which is configured on the device where the client is located. Figure 3 As shown, the device comprises:
[0084] The connection task reading module 310 is used to read the attributes of the database to be connected in the database connection task in response to the user initiating the database connection task;
[0085] A connection request sending module 320 is used to select a target standby database from a cached standby database list and send a connection request to the target standby database when the attribute of the database to be connected is a standby database; the standby database list includes at least one standby database and standby database connection information included in the database architecture;
[0086] The attribute acquisition module 330 is used to acquire the current database architecture fed back by the target standby database and the current attributes of the target standby database;
[0087] The database connection module 340 is used to disconnect the target standby database when the current attribute of the target standby database is changed to the primary database, and after updating the standby database list according to the current database architecture, return to execute the operation of selecting the target standby database in the cached standby database list until the connection with the standby database is established.
[0088] According to the technical solution of the embodiment of the present invention, in response to a user initiating a database connection task, the client reads the attribute of the database to be connected in the database connection task, selects the target standby database from the cached standby database list when the attribute of the database to be connected is a standby database, and sends a connection request to the target standby database, thereby obtaining the current database architecture and the current attribute of the target standby database fed back by the target standby database, disconnects the target standby database when the current attribute of the target standby database is changed to a master database, and after updating the standby database list according to the current database architecture, returns to perform the operation of selecting the target standby database in the cached standby database list until a connection is established with the standby database, determines whether to establish a connection with the current database node through the current database architecture and current attribute fed back by the database node, and can avoid the problem of overloading the new master database caused by the new master database simultaneously taking on read and write services when the standby database is switched to the master database.
[0089] Optionally, the connection request sending module 320 is specifically configured to:
[0090] When the attribute of the database to be connected is a standby database, reading a load balancing flag in the database connection task;
[0091] When the load balancing flag indicates that load balancing is required, a target standby database is determined in a cached standby database list according to the database connection history record, and a connection request is sent to the target standby database.
[0092] Optionally, the database connection device further includes:
[0093] A main database connection request sending module, used to send a connection request to the main database through a virtual network device pre-registered with the main database information when the attribute of the database to be connected is a standby database and the cached standby database list is empty;
[0094] A feedback acquisition module is used to acquire the current database architecture fed back by the master database and the current properties of the master database;
[0095] The standby database connection module is used to disconnect the connection with the main database when the current properties of the main database are not changed, and after updating the standby database list according to the current database architecture, return to execute the operation of selecting the target standby database in the cached standby database list until the connection with the standby database is established.
[0096] Optionally, the database connection device further includes:
[0097] The target standby database deletion module is used to, after sending a connection request to the target standby database, delete the target standby database from the standby database list in response to a prompt from the target standby database that the connection cannot be established, and return to execute the operation of selecting a target standby database from the cached standby database list and sending a connection request to the target standby database until a connection is established with the standby database.
[0098] The database connection device provided in the embodiment of the present invention can execute the database connection method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0099] Embodiment 4
[0100] Figure 4 This is a schematic diagram of the structure of a database connection device provided in Embodiment 4 of the present invention, which is configured in a database node. Figure 4 As shown, the device comprises:
[0101] The database attribute acquisition module 410 is used to respond to the connection request sent by the client and acquire the attributes of the database to be connected in the connection request;
[0102] The attribute feedback module 420 is used to establish a connection with the client when the attribute of the database to be connected is a standby database, and to feedback the current database architecture and the current attributes of the current database node to the client, so as to instruct the client to update the standby database list according to the current database architecture, so as to establish a connection with the standby database according to the standby database list;
[0103] The standby database list includes at least one standby database and standby database connection information contained in the database architecture.
[0104] According to the technical solution of the embodiment of the present invention, a database node responds to a connection request sent by a client, obtains the attribute of the database to be connected in the connection request, establishes a connection with the client when the attribute of the database to be connected is a standby database, and feeds back the current database architecture and the current attribute of the current database node to the client, so as to instruct the client to update the standby database list according to the current database architecture, so as to establish a connection with the standby database according to the standby database list. By feeding back the current database architecture and the current attribute to the client, the client can determine whether to establish a connection with the current database node, thereby avoiding the problem of overloading the new main database caused by the new main database taking on read and write services at the same time when the standby database switches to the main database.
[0105] Optionally, the database connection device further includes:
[0106] An in-transit connection disconnection module is used to respond to a user's instruction to change the attribute of the current database node from a standby database to a primary database, set the connection state of the current database node to a state where the connection cannot be established, and disconnect the currently active in-transit connection;
[0107] The status recovery module is used to execute the command to change the standby database to the primary path and restore the connection status to a state where the connection can be established.
[0108] The database connection device provided in the embodiment of the present invention can execute the database connection method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0109] In the technical solution of the present invention, the collected information is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with the relevant laws, regulations and standards of relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0110] Embodiment 5
[0111] According to an embodiment of the present invention, the present invention also provides an electronic device, a readable storage medium and a computer program product.
[0112] Figure 5 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, applicators, blade applicators, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0113] like Figure 5As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0114] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0115] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a database connection method.
[0116] In some embodiments, the database connection method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the database connection method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the database connection method in any other appropriate manner (e.g., by means of firmware).
[0117] Various implementations 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), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0118] Computer programs for implementing 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, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or application.
[0119] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0120] To provide interaction with a user, the systems and techniques described herein may 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 a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0121] The systems and techniques described herein may be implemented in a computing system that includes a backend component (e.g., as a data applier), or a computing system that includes a middleware component (e.g., an application applier), or a computing system that includes a frontend component (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0122] A computing system may include a client and an application server. The client and the application server are generally remote from each other and usually interact through a communication network. The relationship between the client and the application server is generated by computer programs running on corresponding computers and having a client-application server relationship with each other. The application server may be a cloud application server, also known as a cloud computing application server or a cloud host, which is a host product in a cloud computing application system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS applications.
[0123] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0124] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A database connection method, characterized in that: Applied to the client, including: In response to a user initiating a database connection task, reading a property of a database to be connected in the database connection task; In the case where the attribute of the database to be connected is a standby database, a target standby database is selected from a cached standby database list, and a connection request is sent to the target standby database; the standby database list includes at least one standby database and standby database connection information included in the database architecture; Obtaining the current database architecture fed back by the target standby database and the current properties of the target standby database; When the current attribute of the target standby database is changed to the master database, the connection with the target standby database is disconnected, and after the standby database list is updated according to the current database architecture, the operation of selecting the target standby database in the cached standby database list is returned to be executed until the connection with the standby database is established.
2. The method according to claim 1, characterized in that In a case where the attribute of the database to be connected is a standby database, selecting a target standby database from the cached standby database list and sending a connection request to the target standby database include: When the attribute of the database to be connected is a standby database, reading a load balancing flag in the database connection task; When the load balancing flag indicates that load balancing is required, a target standby database is determined in a cached standby database list according to the database connection history record, and a connection request is sent to the target standby database.
3. The method according to claim 1, characterized in that Also includes: When the attribute of the database to be connected is a standby database and the cached standby database list is empty, a connection request is sent to the main database through a virtual network device pre-registered with the main database information; Obtaining the current database architecture fed back by the master database and the current properties of the master database; If the current properties of the primary database are not changed, disconnect the primary database, update the standby database list according to the current database architecture, and then return to the operation of selecting a target standby database in the cached standby database list until a connection is established with the standby database.
4. The method according to claim 1, characterized in that After sending the connection request to the target standby database, the method further includes: In response to the target standby database indicating that the connection cannot be established, the target standby database is deleted from the standby database list, and the operation of selecting a target standby database from the cached standby database list and sending a connection request to the target standby database is performed again until a connection is established with the standby database.
5. A database connection method, characterized in that: Applicable to database nodes, including: In response to a connection request sent by a client, obtaining a property of a database to be accessed in the connection request; In the case where the attribute of the database to be connected is a standby database, establishing a connection with the client, and feeding back the current database architecture and the current attributes of the current database node to the client, so as to instruct the client to update the standby database list according to the current database architecture, so as to establish a connection with the standby database according to the standby database list; The standby database list includes at least one standby database and standby database connection information contained in the database architecture.
6. The method according to claim 5, characterized in that Also includes: In response to a user's instruction to change the attribute of the current database node from a standby database to a primary database, the connection state of the current database node is set to a state where the connection cannot be established, and the currently active in-transit connection is disconnected; Execute the command to change the standby database to the primary path and restore the connection status to the state where the connection can be established.
7. A database connection device, characterized in that: Configured on the client, including: A connection task reading module, used for reading the attributes of the database to be connected in the database connection task in response to the user initiating the database connection task; A connection request sending module, configured to select a target standby database from a cached standby database list and send a connection request to the target standby database when the attribute of the database to be connected is a standby database; the standby database list includes at least one standby database and standby database connection information included in the database architecture; An attribute acquisition module, used to acquire the current database architecture fed back by the target standby database and the current attributes of the target standby database; The database connection module is used to disconnect the target standby database when the current attribute of the target standby database is changed to the primary database, and after updating the standby database list according to the current database architecture, return to execute the operation of selecting the target standby database in the cached standby database list until the connection with the standby database is established.
8. A database connection device, characterized in that: Configured on the database node, including: A database attribute acquisition module, used to respond to a connection request sent by a client and acquire the attributes of the database to be connected in the connection request; An attribute feedback module, used for establishing a connection with the client when the attribute of the database to be connected is a standby database, and feeding back the current database architecture and the current attributes of the current database node to the client, so as to instruct the client to update the standby database list according to the current database architecture, so as to establish a connection with the standby database according to the standby database list; The standby database list includes at least one standby database and standby database connection information contained in the database architecture.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the database connection method according to any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the database connection method according to any one of claims 1 to 6 when executed.