Methods, devices, electronic equipment, and storage media for connecting to business databases
By automatically connecting the client to the nearest business database slave node, the problem of extended response time caused by business developers manually configuring domain names is solved, enabling faster data requests and reducing the need for manual configuration.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-25
- Publication Date
- 2026-03-13
AI Technical Summary
In existing technologies, business developers need to manually configure the domain name of the business database slave node, which is prone to errors, resulting in longer response times for business data requests and a degraded user experience.
The client automatically connects to the nearest business database slave node, obtains the business database node configuration information and availability zone information, and establishes a connection with the target slave node using the connection pool, reducing the need for manual configuration.
It effectively shortens the data request response time, reduces the workload of business developers, and alleviates the problem of data request failures caused by human error.
Smart Images

Figure CN117149829B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of database technology, and in particular to a method, apparatus, electronic device and storage medium for connecting to a business database. Background Technology
[0002] The business database can support the normal operation of the corresponding business applications. Currently, due to the scale of the database data and the proportion of business request calls, it is necessary to enable read-write separation, which transfers all or part of the read operations to the business database slave nodes, while the write operations are run on the business database master nodes, thereby ensuring the response time of the business applications.
[0003] Currently, business developers need to determine the business database slave nodes that the business application needs to access so that the domain name of the business database slave node can be hardcoded in the local configuration of the client. This increases the workload of business developers, and because it is a manual operation, it is easy to make mistakes in writing the domain name of the business database slave node, which will cause business data requests to fail to respond and greatly reduce the user experience. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a method, apparatus, electronic device, and storage medium for connecting to a business database. The client automatically connects to the nearest business database slave node for business data requests, effectively shortening the response time of data requests. Furthermore, this method, which eliminates the need for business developers to write the domain name of the business database slave node in the local configuration of the client, can reduce the workload of business developers and effectively alleviate the problem of business data requests not being responded to due to errors in manually writing the domain name of the business database slave node.
[0005] In a first aspect, embodiments of the present invention provide a method for connecting to a business database, wherein the method is applicable to a client and includes:
[0006] In response to the first selection operation for the preset control, the system obtains the business database node configuration information and the client's first availability zone information; wherein, the preset control includes a data read / write separation control and a database proximity connection control, and the first availability zone information is used to characterize the name of the data center corresponding to the client;
[0007] Obtain the second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information; wherein, the second availability zone information is used to represent the name of the data center corresponding to the business database slave node;
[0008] Based on the information from the first availability zone and multiple second availability zones, the target business database slave node closest to the client is determined from multiple business database slave nodes;
[0009] Establish connections with the target business database slave node and / or the business database master node corresponding to the target business database slave node using the connection pool.
[0010] In one possible implementation, the business database node configuration information stores the domain names and second availability zone information of multiple business database slave nodes corresponding to the business database master node in the database cluster.
[0011] Retrieve the second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information, including:
[0012] Using the domain name of each business database slave node as the key, retrieve the second availability zone information corresponding to each domain name from the business database node configuration information.
[0013] In one possible implementation, the target business database slave node closest to the client is determined from multiple business database slave nodes based on first availability zone information and multiple second availability zone information, including:
[0014] Query from multiple second availability zone information to determine if the target second availability zone information matches the first availability zone information;
[0015] If a target second availability zone information that matches the first availability zone information is found from multiple second availability zone information, the business database slave node corresponding to the target second availability zone information is determined as the target business database slave node closest to the client;
[0016] If no target second availability zone information matching the first availability zone information is found from multiple second availability zone information, the first region information corresponding to the first availability zone information and the second region information corresponding to each second availability zone information are retrieved from the availability zone region lookup table; wherein, the availability zone region lookup table stores the correspondence between availability zone information and region information;
[0017] Based on the information from the first region and multiple information from the second region, the target business database slave node closest to the client is determined.
[0018] In one possible implementation, the target business database slave node closest to the client is determined based on first region information and multiple second region information, including:
[0019] Query the target area information from multiple second area information to see if it matches the first area information;
[0020] If a target area information matching the first area information is found from multiple second area information queries, the business database slave node of the second availability zone information corresponding to the target area information is determined as the target business database slave node closest to the client.
[0021] In one possible implementation, the method further includes:
[0022] If no target region information matching the first region information is found from multiple second region information, the target node is selected from multiple business database slave nodes and / or business database master nodes according to the preset fallback and degradation strategy.
[0023] In one possible implementation, the connection pool includes a slave node connection pool and a master node connection pool;
[0024] Establish connections with the target business database slave node and / or the business database master node corresponding to the target business database slave node using the connection pool, including:
[0025] In response to a second selection operation on a data request control, obtain the operation instruction corresponding to the second selection operation;
[0026] When the operation instruction is a write operation instruction, a write connection is retrieved from the master node connection pool, and a connection is established with the business database master node based on the write connection.
[0027] When the operation instruction is a read operation instruction, a read connection is retrieved from the slave node connection pool, and a connection is established with the target business database slave node based on the read connection;
[0028] When the operation instructions are write operation instructions and read operation instructions, a write connection is retrieved from the master node connection pool and a read connection is retrieved from the slave node connection pool. A connection is established with the business database master node based on the write connection and a connection is established with the target business database slave node based on the read connection.
[0029] In one possible implementation, the business database node configuration information and the availability zone query table are pre-configured in the configuration center; the method further includes:
[0030] Upon receiving an update notification from the configuration center, the connection pool is reloaded based on the update time of the business application. The update notification indicates that the administrator has changed the configuration information of the business database node and the availability zone query table in the configuration center.
[0031] Secondly, embodiments of the present invention provide an apparatus for connecting to a business database, wherein the apparatus is applicable to a client and includes:
[0032] The first acquisition module is used to acquire business database node configuration information and the first availability zone information of the client in response to the first selection operation of the preset control; wherein, the preset control includes a data read-write separation control and a database proximity connection control, and the first availability zone information is used to represent the name of the data center corresponding to the client;
[0033] The second acquisition module is used to obtain the second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information; wherein, the second availability zone information is used to represent the name of the data center corresponding to the business database slave node;
[0034] The determination module is used to determine the target business database slave node that is closest to the client from multiple business database slave nodes based on information from the first availability zone and multiple second availability zones;
[0035] The connection module is used to establish connections with the target business database slave node and / or the business database master node corresponding to the target business database slave node using the connection pool.
[0036] Thirdly, embodiments of the present invention provide an electronic device, comprising: a processor and a memory, wherein the processor is configured to execute a program for a business database connection stored in the memory, so as to implement the above-described method for connecting to a business database.
[0037] Fourthly, embodiments of the present invention provide a storage medium, wherein the storage medium stores one or more programs, which can be executed by one or more processors to implement the above-described method for connecting to a business database.
[0038] The present invention provides a method, apparatus, electronic device, and storage medium for connecting to a business database. The method includes, in response to a first selection operation on a preset control, acquiring business database node configuration information and first availability zone information of the client; acquiring second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information; determining the target business database slave node closest to the client from the multiple business database slave nodes based on the first availability zone information and the multiple second availability zone information; and establishing a connection with the target business database slave node and / or with the business database master node corresponding to the target business database slave node using a connection pool. This invention enables the client to automatically connect to the nearest business database slave node based on the name of its corresponding data center for business data requests, effectively shortening the response time of data requests. Furthermore, this method, which eliminates the need for business developers to write business database slave node domain names in the client's local configuration, reduces the workload of business developers and effectively alleviates the problem of unresponsive business data requests caused by manually incorrectly written business database slave node domain names. Attached Figure Description
[0039] Figure 1 A flowchart illustrating an embodiment of a method for connecting to a business database provided by this invention;
[0040] Figure 2 A flowchart illustrating an embodiment of another method for connecting to a business database provided by this invention;
[0041] Figure 3 A block diagram illustrating an embodiment of a business database connection device provided in this invention;
[0042] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0043] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0044] To facilitate understanding of the embodiments of the present invention, further explanations and descriptions will be provided below with reference to the accompanying drawings and specific embodiments. These embodiments do not constitute a limitation on the embodiments of the present invention.
[0045] This invention provides a method for connecting to a business database. This method is applicable to a client, which is an electronic device with a business application installed. The business application is a specific application used by the user, such as iQiyi, Tencent, WeChat, Alipay, etc., and is not limited thereto. See also Figure 1 , Figure 1 A flowchart illustrating an embodiment of a business database connection method provided by this invention. Figure 1 The process shown may include the following steps:
[0046] Step 101: In response to the first selection operation for the preset control, obtain the business database node configuration information and the first availability zone information of the client;
[0047] The preset controls include a data read / write separation control and a database proximity connection control. These preset controls are displayed on the client's settings interface. When the user clicks or double-clicks to select the data read / write separation control and the database proximity connection control, the client can use the method provided in this embodiment to automatically select the nearest business database slave node from multiple business database slave nodes corresponding to the business database master node, establish a connection with the client to meet business data requests, and ensure the normal operation of the business application.
[0048] The first availability zone information is used to identify the name of the data center corresponding to the client. The data center can be understood as the computer room corresponding to the client. The first availability zone information is the name of the computer room corresponding to the client (e.g., Beijing Telecom, Shanghai Unicom, Hangzhou Zhongyunxin, etc.). The name of the computer room is the unique identifier of the computer room.
[0049] Step 102: Obtain the second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information;
[0050] The above-mentioned business database node configuration information stores the domain names and second availability zone information of multiple business database slave nodes corresponding to the business database master node in the database cluster. The second availability zone information is used to represent the name of the data center corresponding to the business database slave node. The second availability zone information is the name of the data center corresponding to the business database slave node.
[0051] Because the domain names and second availability zone information of the business database slave nodes are stored in the configuration information of the business database nodes in the form of key-value pairs and numerical values, that is, the domain names of the business database slave nodes are stored in the configuration information of the business database nodes in the form of key-value pairs and the second availability zone information of the business database slave nodes is stored in the form of numerical values corresponding to the key-value pairs, the client can use the domain names of each business database slave node as key-value pairs to obtain the second availability zone information corresponding to each domain name from the configuration information of the business database nodes.
[0052] Step 103: Based on the information of the first availability zone and multiple information of the second availability zone, determine the target business database slave node that is closest to the client from multiple business database slave nodes;
[0053] In actual use, if there is a second availability zone that is the same as the first availability zone, it means that the client and the target business database slave node belong to the same data center. In this case, the target business database slave node responds to the client's business data requests the fastest and with the shortest response time.
[0054] Step 104: Establish a connection with the target business database slave node and / or the business database master node corresponding to the target business database slave node using the connection pool.
[0055] In this embodiment, specifically, a connection is established with the target business database slave node and / or the business database master node corresponding to the target business database slave node. This is related to the actual operation instructions sent by the client. Specifically, in response to the second selection operation of the data request control, the operation instruction corresponding to the second selection operation is obtained. If the operation instruction is a write operation instruction, a write connection is retrieved from the master node connection pool, and a connection is established with the business database master node based on the write connection. If the operation instruction is a read operation instruction, a read connection is retrieved from the slave node connection pool, and a connection is established with the target business database slave node based on the read connection. If the operation instructions are both a write operation instruction and a read operation instruction, a write connection is retrieved from the master node connection pool and a read connection is retrieved from the slave node connection pool, and a connection is established with the business database master node based on the write connection and with the target business database slave node based on the read connection.
[0056] In specific implementation, the connection pool includes a slave node connection pool and a master node connection pool. The slave node connection pool has pre-created read connections to the target business database slave node. When it is determined that the operation instruction includes a read operation instruction, it means that the client needs to establish a database connection with the target business database slave node in order to read the data required by the business application from the target business database slave node.
[0057] The master node connection pool has pre-created write connections to the business database master node. When it is determined that the operation instruction includes a write operation instruction, it means that the client needs to establish a database connection with the business database master node in order to write the data generated by the business application into the business database master node for storage.
[0058] The method for connecting to a business database provided in this invention includes: responding to a first selection operation on a preset control; obtaining business database node configuration information and first availability zone information of the client; obtaining second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information; determining the target business database slave node closest to the client from the multiple business database slave nodes based on the first availability zone information and the multiple second availability zone information; and establishing a connection with the target business database slave node and / or the business database master node corresponding to the target business database slave node using a connection pool. This invention enables the client to automatically connect to the nearest business database slave node based on the name of its corresponding data center for business data requests, effectively shortening the response time of data requests. Furthermore, this method, which eliminates the need for business developers to write business database slave node domain names in the client's local configuration, reduces the workload of business developers and effectively alleviates the problem of unresponsive business data requests caused by manually incorrectly written business database slave node domain names.
[0059] See Figure 2 , Figure 2 A flowchart illustrating an embodiment of another method for connecting to a business database provided by an embodiment of the present invention. Figure 2 The process shown may include the following steps:
[0060] Step 201: In response to the first selection operation for the preset control, obtain the business database node configuration information and the first availability zone information of the client; wherein, the preset control includes a data read / write separation control and a database proximity connection control, and the first availability zone information is used to characterize the name of the data center corresponding to the client;
[0061] Step 202: Obtain the second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information; wherein, the second availability zone information is used to represent the name of the data center corresponding to the business database slave node;
[0062] Step 203: Query from multiple second availability zone information whether the target second availability zone information matches the first availability zone information;
[0063] If a target second availability zone matching the first availability zone is found among multiple second availability zone information, it means that the client and the business database slave node corresponding to the target second availability zone information belong to the same data center. Execute step 204 to determine the business database slave node corresponding to the target second availability zone information as the target business database slave node closest to the client, so as to read the data required by the business application from the target business database slave node. If no target second availability zone matching the first availability zone is found among multiple second availability zone information, it means that none of the business database slave nodes among the multiple second availability zone information belong to the same data center as the client. It needs to be downgraded to region matching, specifically by executing step 205.
[0064] Step 204: Determine the target business database slave node corresponding to the target second availability zone information as the target business database slave node closest to the client;
[0065] Step 205: Query the first region information corresponding to the first availability zone information and the second region information corresponding to each second availability zone information from the availability zone region query table;
[0066] The availability zone query table stores the correspondence between availability zone information and regional information. For example, Beijing Telecom corresponds to the North China region, while Shanghai Unicom and Hangzhou Zhongyunxin correspond to the South China region.
[0067] Since the availability zone lookup table stores the correspondence between availability zone information and zone information, it is possible to retrieve the first zone information corresponding to the first availability zone information, as well as the second zone information corresponding to each second availability zone information, from the availability zone lookup table.
[0068] Step 206: Determine the target business database slave node closest to the client based on the first region information and multiple second region information;
[0069] For details on the implementation process, please refer to steps A1 to A4:
[0070] Step A1: Query the target area information from multiple second area information to see if it matches the first area information;
[0071] If a target region matching the first region information is found from multiple second region information sources, proceed to step A2; if no target region matching the first region information is found from multiple second region information sources, proceed to step A3.
[0072] Step A2: Determine the business database slave node corresponding to the second availability zone information of the target area information as the target business database slave node closest to the client.
[0073] For example, if the client's first region information is South China, then all second region information that is South China is found from multiple second region information, and then all the second availability zone information that is found to be South China is determined as the target business database slave node.
[0074] Step A3: Select the target node from multiple business database slave nodes and / or business database master nodes according to the preset fallback and degradation strategy.
[0075] If no target region information matching the first region information is found from multiple second region information, it indicates that the region where the client is located is different from the regions where the various business database slave nodes are located. In this case, a target node can be arbitrarily selected from multiple business database slave nodes to establish a database connection with the client according to the preset fallback strategy of arbitrarily selecting slave nodes, or a target node can be arbitrarily selected from multiple business database slave nodes and business database master nodes to establish a database connection with the client according to the preset fallback strategy of arbitrarily selecting master nodes, or a target node can be selected from the business database master nodes as the target node to establish a database connection with the client according to the preset fallback strategy of master node selection.
[0076] Step 207: Establish a connection with the target business database slave node and / or the business database master node corresponding to the target business database slave node using the connection pool;
[0077] Step 208: If an update notification is received from the configuration center, the connection pool is reloaded based on the update time of the business application.
[0078] In actual use, the business database node configuration information and availability zone query table are pre-configured by the database administrator in the configuration center. In response to the first selection operation for the preset control, the client can obtain the business database node configuration information and availability zone query table from the configuration center to automatically select the target business database slave node.
[0079] In practical use, when scenarios such as adding or reclaiming data centers occur, administrators first modify the business database node configuration information and availability zone query table on the management platform by adding, deleting, or updating information. Then, through workflow, manual, or timed refresh methods, the modified business database node configuration information and availability zone query table are used to replace the original business database node configuration information and availability zone query table in the configuration center. After the replacement is completed, the configuration center will send the update notification information, which indicates that the administrator has changed the business database node configuration information and availability zone query table in the configuration center, to the client to notify the client that the business database node configuration information and availability zone query table have been updated. At this time, the client can re-select the target business database slave node using the new business database node configuration information and availability zone query table according to the update time of the business application, in order to reload the connection pool and establish a database connection.
[0080] See Figure 3 This is a block diagram illustrating an embodiment of a business database connection device provided by an embodiment of the present invention. This device is suitable for client applications, such as… Figure 3 As shown, the device includes:
[0081] The first acquisition module 301 is used to acquire business database node configuration information and the first availability zone information of the client in response to a first selection operation on a preset control; wherein, the preset control includes a data read-write separation control and a database proximity connection control, and the first availability zone information is used to represent the name of the data center corresponding to the client;
[0082] The second acquisition module 302 is used to acquire second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information; wherein, the second availability zone information is used to represent the name of the data center corresponding to the business database slave node;
[0083] The determination module 303 is used to determine the target business database slave node closest to the client from multiple business database slave nodes based on the first availability zone information and multiple second availability zone information;
[0084] The connection module 304 is used to establish a connection with the target business database slave node and / or the business database master node corresponding to the target business database slave node using the connection pool.
[0085] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Figure 4The illustrated electronic device 500 includes at least one processor 501, a memory 502, at least one network interface 504, and other user interfaces 503. The various components in the electronic device 500 are coupled together via a bus system 505. It is understood that the bus system 505 is used to implement communication between these components. In addition to a data bus, the bus system 505 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 4 The general designated all buses as Bus System 505.
[0086] The user interface 503 may include a display, keyboard, or clicking device (e.g., mouse, trackball, touchpad, or touchscreen).
[0087] It is understood that the memory 502 in the embodiments of the present invention can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchlink DRAM (SLDRAM), and Direct Rambus RAM (DRRAM). The memory 502 described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0088] In some implementations, memory 502 stores elements, executable units or data structures, or subsets thereof, or extended sets thereof: operating system 5021 and application program 5022.
[0089] The operating system 5021 includes various system programs, such as the framework layer, core library layer, and driver layer, used to implement various basic business functions and handle hardware-based tasks. The application program 5022 includes various applications, such as a media player and a browser, used to implement various application functions. The program implementing the method of this embodiment can be included in the application program 5022.
[0090] In this embodiment of the invention, the processor 501 executes the method steps provided in each method embodiment by calling the program or instructions stored in the memory 502, specifically the program or instructions stored in the application program 5022.
[0091] The methods disclosed in the above embodiments of the present invention can be applied to or implemented by processor 501. Processor 501 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in processor 501 or by instructions in the form of software. The processor 501 may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present invention can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software units in the decoding processor. The software units may be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory 502. Processor 501 reads the information in memory 502 and, in conjunction with its hardware, completes the steps of the above method.
[0092] It is understood that the embodiments described herein can be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit can be implemented in one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described herein, or combinations thereof.
[0093] For software implementation, the techniques described herein can be implemented by units that perform the functions described herein. The software code can be stored in memory and executed by a processor. The memory can be implemented in the processor or external to the processor.
[0094] The electronic device provided in this embodiment may be as follows: Figure 4 The electronic device shown can perform the following: Figure 1-2 All steps of the method for connecting to the business database in the middle, thereby achieving Figure 1-2 For details on the technical effects of the business database connection method shown, please refer to [link / reference]. Figure 1-2 The relevant descriptions are presented concisely and will not be elaborated upon here.
[0095] This invention also provides a storage medium (computer-readable storage medium). This storage medium stores one or more programs. The storage medium may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as read-only memory, flash memory, hard disk, or solid-state drive; the memory may also include combinations of the above types of memory.
[0096] The above-mentioned method of connecting to a business database is implemented when one or more programs in the storage medium can be executed by one or more processors.
[0097] The processor is used to execute a program stored in memory for connecting to a business database, in order to implement the steps of a method for connecting to a business database.
[0098] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0099] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0100] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for connecting to a business database, characterized in that, The method is applicable to the client, and the method includes: In response to a first selection operation on a preset control, the system obtains business database node configuration information and the first availability zone information of the client; wherein, the preset control includes a data read / write separation control and a database proximity connection control, and the first availability zone information is used to characterize the name of the data center corresponding to the client; Obtain second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information; wherein, the second availability zone information is used to characterize the name of the data center corresponding to the business database slave node; Determining the target business database slave node closest to the client from multiple business database slave nodes based on the first availability zone information and multiple second availability zone information includes: querying whether target second availability zone information matches the first availability zone information from the multiple second availability zone information; if target second availability zone information matching the first availability zone information is found from the multiple second availability zone information, determining the business database slave node corresponding to the target second availability zone information as the target business database slave node closest to the client; if no target second availability zone information matching the first availability zone information is found from the multiple second availability zone information, querying the first region information corresponding to the first availability zone information and the second region information corresponding to each of the second availability zone information from an availability zone region lookup table; wherein, the availability zone region lookup table stores the correspondence between availability zone information and region information; and determining the target business database slave node closest to the client based on the first region information and multiple second region information. Establish connections with the target business database slave node and / or the business database master node corresponding to the target business database slave node using the connection pool.
2. The method according to claim 1, characterized in that, The business database node configuration information stores the domain names and second availability zone information of multiple business database slave nodes corresponding to the business database master node in the database cluster. The step of obtaining the second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information includes: Using the domain name of each of the business database slave nodes as the key, the second availability zone information corresponding to each of the domain names is obtained from the configuration information of the business database nodes.
3. The method according to claim 1, characterized in that, The step of determining the target business database slave node closest to the client based on the first region information and multiple second region information includes: Query from multiple sets of second region information whether the target region information matches the first region information; If a target area information matching the first area information is found from multiple second area information, the business database slave node of the second availability zone information corresponding to the target area information is determined as the target business database slave node closest to the client.
4. The method according to claim 3, characterized in that, The method further includes: If no target region information matching the first region information is found from multiple second region information, a target node is selected from multiple business database slave nodes and / or business database master nodes according to a preset fallback and degradation strategy.
5. The method according to claim 1, characterized in that, The connection pool includes a slave node connection pool and a master node connection pool; The step of establishing a connection with the target business database slave node and / or the business database master node corresponding to the target business database slave node using a connection pool includes: In response to a second selection operation on a data request control, obtain the operation instruction corresponding to the second selection operation; When the operation instruction is a write operation instruction, a write connection is retrieved from the master node connection pool, and a connection is established with the business database master node based on the write connection. When the operation instruction is a read operation instruction, a read connection is retrieved from the slave node connection pool, and a connection is established with the target business database slave node based on the read connection; When the operation instructions are write operation instructions and read operation instructions, a write connection is retrieved from the master node connection pool and a read connection is retrieved from the slave node connection pool. A connection is established with the business database master node based on the write connection and a connection is established with the target business database slave node based on the read connection.
6. The method according to claim 1, characterized in that, The business database node configuration information and the availability zone query table are pre-configured in the configuration center; the method further includes: Upon receiving an update notification from the configuration center, the connection pool is reloaded based on the update time of the business application; wherein, the update notification indicates that the administrator has changed the configuration information of the business database node and the availability zone query table in the configuration center.
7. An apparatus for connecting to a business database, characterized in that, The device is applicable to a client, and the device includes: The first acquisition module is used to acquire business database node configuration information and the first availability zone information of the client in response to a first selection operation on a preset control; wherein, the preset control includes a data read-write separation control and a database proximity connection control, and the first availability zone information is used to characterize the name of the data center corresponding to the client; The second acquisition module is used to acquire second availability zone information corresponding to multiple business database slave nodes from the business database node configuration information; wherein, the second availability zone information is used to characterize the name of the data center corresponding to the business database slave node; A determination module is configured to determine the target business database slave node closest to the client from a plurality of business database slave nodes based on the first availability zone information and a plurality of second availability zone information, including: querying the plurality of second availability zone information to see if target second availability zone information matches the first availability zone information; if target second availability zone information matching the first availability zone information is found from the plurality of second availability zone information, determining the business database slave node corresponding to the target second availability zone information as the target business database slave node closest to the client; if no target second availability zone information matching the first availability zone information is found from the plurality of second availability zone information, querying the first region information corresponding to the first availability zone information and the second region information corresponding to each of the second availability zone information from an availability zone region lookup table; wherein, the availability zone region lookup table stores the correspondence between availability zone information and region information; and determining the target business database slave node closest to the client based on the first region information and the plurality of second region information. The connection module is used to establish a connection with the target business database slave node and / or the business database master node corresponding to the target business database slave node using the connection pool.
8. An electronic device, characterized in that, include: A processor and a memory, the processor being configured to execute a program for a business database connection stored in the memory to implement the business database connection method according to any one of claims 1 to 6.
9. A storage medium, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the business database connection method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Business data reading and writing method and device, equipment and storage medium
CN110096552A
Network system having geographic coordinate information
CN1466073A