Database connection method and device, computer equipment, medium and program product

By establishing a mapping relationship between Elastic Public Network Addresses (IPAs) and Virtual Private Cloud Addresses (VPNs) on the cloud platform and replacing VPNs with IPAs, the problem of MongoDB database replica set nodes not being directly accessible from the public network is solved, achieving secure and reliable database connections and improving connection flexibility and ease of use of application systems.

CN121509020APending Publication Date: 2026-02-10CHINA TELECOM CLOUD TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202511775595.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-28
Publication Date
2026-02-10

AI Technical Summary

Technical Problem

The virtual private cloud architecture of the cloud platform prevents MongoDB database replica set nodes from being directly accessed via the public network, resulting in insufficient database connection flexibility for application systems.

Method used

By obtaining the client's connection request information and global singleton object data, a mapping relationship between the Elastic Public Network Address and the Virtual Private Cloud Address is established. The Virtual Private Cloud Address in the original response result is replaced with the Elastic Public Network Address, thereby enabling a secure and reliable connection between the client and the MongoDB replica set node.

Benefits of technology

While ensuring the security and isolation of cloud databases, it improves the flexibility and reliability of database connections and simplifies client development and maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121509020A_ABST
    Figure CN121509020A_ABST
Patent Text Reader

Abstract

The invention relates to a database connection method and device, computer equipment, a medium and a program product. The method comprises the following steps: acquiring connection request information and global singleton object data from a client, and obtaining a mapping relationship between an elastic public network address and a virtual private cloud address; obtaining an original response result which corresponds to an original main node confirmation command of the client and comprises address information of the replica set node; under the condition that it is determined that the connection request needs to be subjected to elastic public network address replacement according to the connection request information and the global singleton object data, a virtual private cloud address in the original response result is replaced with a corresponding elastic public network address according to the global singleton object data, and a target response result is obtained; and sending the target response result to the client, and establishing connection between the client and each node of the replica set according to address information in the target response result. By adopting the method, the database connection flexibility can be improved on the basis of ensuring the security isolation of the cloud database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database technology, and in particular to a database connection method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Technology

[0002] In today's era of rapid development in internet technology, an increasing number of application systems are choosing to deploy their databases on cloud platforms in order to achieve higher availability and more flexible scalability. MongoDB, as a popular NoSQL database, provides high availability and data redundancy through its replica set architecture. After purchasing a document database instance, cloud customers often choose to bind the database instance node to an Elastic IP address (EIP) when they need direct access to the database from the external network.

[0003] However, the cloud platform adopts a Virtual Private Cloud (VPC) network architecture. In order to ensure the security and isolation of the MongoDB cloud database, the initialization of its underlying instance nodes and internal communication require the use of VPC IP. The nodes of the database replica set are often deployed inside the VPC and cannot be accessed directly through the public network, which makes the database connection flexibility of the application system deployed in the public network environment insufficient. Summary of the Invention

[0004] Therefore, it is necessary to provide a database connection method, device, computer equipment, computer-readable storage medium, and computer program product that can improve the flexibility of database connection while ensuring the security and isolation of cloud databases, in order to address the above-mentioned technical problems.

[0005] Firstly, this application provides a database connection method, including:

[0006] Obtain connection request information and global singleton object data from the client; wherein, the global singleton object data includes the mapping relationship between elastic public network addresses and virtual private cloud addresses;

[0007] Obtain the original response result corresponding to the original master node confirmation command of the client; wherein, the original response result includes the address information of the replica set node;

[0008] If it is determined from the connection request information and the global singleton object data that the connection request requires replacement of the elastic public network address, the virtual private cloud address in the original response result is replaced with the corresponding elastic public network address according to the global singleton object data to obtain the target response result;

[0009] The target response result is sent to the client, and a connection is established between the client and each node of the replica set based on the address information in the target response result.

[0010] In one embodiment, the method further includes:

[0011] Get the elastic public IP address binding operation request initiated by the client;

[0012] Based on the binding operation request, a mapping relationship between the elastic public network address and the virtual private cloud address is generated;

[0013] Record the mapping relationship in the kernel configuration table.

[0014] In one embodiment, the method for obtaining the global singleton object data includes:

[0015] Periodically retrieve changes to the data in the kernel configuration table;

[0016] If the mapping relationship in the kernel configuration table changes, the latest mapping relationship will be loaded into the global singleton object data.

[0017] In one embodiment, the connection request information includes the client network address and the target server network address; the global singleton object data also includes intranet whitelist information; the method further includes:

[0018] If the target server network address is a virtual private cloud address, query whether the client network address is within the intranet whitelist;

[0019] If the client's network address is not in the intranet whitelist, and the global singleton object data contains the elastic public IP address information corresponding to the target server's network address, then it is determined that the connection request needs to be replaced with an elastic public IP address.

[0020] In one embodiment, the step of replacing the virtual private cloud address in the original response result with the corresponding elastic public network address based on the global singleton object data to obtain the target response result includes:

[0021] Extract the field to be replaced containing the virtual private cloud address from the original response result; the field to be replaced includes one or more of the following: node address list field, master node address field, current response node address field, arbitrator node address field, passive node address field, and hidden node address field;

[0022] Based on the global singleton object data, the virtual private cloud address in each of the fields to be replaced is replaced with the corresponding elastic public network address to obtain the target field;

[0023] The response data is reconstructed based on the target field to obtain the target response result.

[0024] In one embodiment, the step of replacing the virtual private cloud address in each of the fields to be replaced with the corresponding elastic public network address based on the global singleton object data to obtain the target field includes:

[0025] Perform the following steps for each of the fields to be replaced:

[0026] Parse the field value of the field to be replaced, and separate the address part and port part of the field value according to a preset format;

[0027] Search for the elastic public IP address corresponding to the address portion in the global singleton object data;

[0028] According to the preset format, a new field value is constructed based on the elastic public IP address to obtain the target field.

[0029] Secondly, this application also provides a database connection device, comprising:

[0030] The data acquisition module is used to acquire connection request information and global singleton object data from the client; wherein, the global singleton object data includes the mapping relationship between elastic public network addresses and virtual private cloud addresses;

[0031] The response acquisition module is used to acquire the original response result corresponding to the original master node confirmation command of the client; wherein, the original response result includes the address information of the replica set node;

[0032] The address processing module is used to replace the virtual private cloud address in the original response result with the corresponding elastic public network address based on the global singleton object data when it is determined that the connection request needs to be replaced with an elastic public network address based on the connection request information and the global singleton object data, so as to obtain the target response result.

[0033] The node connection module is used to send the target response result to the client and establish a connection between the client and each node of the replica set based on the address information in the target response result.

[0034] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:

[0035] Obtain connection request information and global singleton object data from the client; wherein, the global singleton object data includes the mapping relationship between elastic public network addresses and virtual private cloud addresses;

[0036] Obtain the original response result corresponding to the original master node confirmation command of the client; wherein, the original response result includes the address information of the replica set node;

[0037] If it is determined from the connection request information and the global singleton object data that the connection request requires replacement of the elastic public network address, the virtual private cloud address in the original response result is replaced with the corresponding elastic public network address according to the global singleton object data to obtain the target response result;

[0038] The target response result is sent to the client, and a connection is established between the client and each node of the replica set based on the address information in the target response result.

[0039] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:

[0040] Obtain connection request information and global singleton object data from the client; wherein, the global singleton object data includes the mapping relationship between elastic public network addresses and virtual private cloud addresses;

[0041] Obtain the original response result corresponding to the original master node confirmation command of the client; wherein, the original response result includes the address information of the replica set node;

[0042] If it is determined from the connection request information and the global singleton object data that the connection request requires replacement of the elastic public network address, the virtual private cloud address in the original response result is replaced with the corresponding elastic public network address according to the global singleton object data to obtain the target response result;

[0043] The target response result is sent to the client, and a connection is established between the client and each node of the replica set based on the address information in the target response result.

[0044] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:

[0045] Obtain connection request information and global singleton object data from the client; wherein, the global singleton object data includes the mapping relationship between elastic public network addresses and virtual private cloud addresses;

[0046] Obtain the original response result corresponding to the original master node confirmation command of the client; wherein, the original response result includes the address information of the replica set node;

[0047] If it is determined from the connection request information and the global singleton object data that the connection request requires replacement of the elastic public network address, the virtual private cloud address in the original response result is replaced with the corresponding elastic public network address according to the global singleton object data to obtain the target response result;

[0048] The target response result is sent to the client, and a connection is established between the client and each node of the replica set based on the address information in the target response result.

[0049] The aforementioned database connection method, apparatus, computer equipment, computer-readable storage medium, and computer program product obtain the mapping relationship between Elastic Public Network Addresses (UPN) and Virtual Private Cloud (VPN) addresses by acquiring connection request information and global singleton object data from the client. By obtaining the original response result corresponding to the client's original master node confirmation command, they can obtain the address information of the replica set nodes. Furthermore, by analyzing the original response result in conjunction with the global singleton object data, they can determine which node addresses need to be replaced. If, based on the connection request information and global singleton object data, it is determined that the connection request requires Elastic Public Network Address replacement, the original response is then processed according to the global singleton object data. The Virtual Private Cloud address in the response is replaced with the corresponding Elastic Public Network address to obtain the target response result. This realizes the mapping from VPC address to Elastic Public Network address, enabling the client to access the database node inside the VPC through the Elastic Public Network address. The target response result is sent to the client, and the client establishes a connection with each node of the replica set based on the address information in the target response result. This enables the client to achieve a secure and reliable connection with the MongoDB replica set deployed inside the VPC, making the application system accessible and maintainable, and ensuring the security of data transmission. It also improves the flexibility of database connection while ensuring the security and isolation of the cloud database. Attached Figure Description

[0050] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0051] Figure 1 This is an application environment diagram of a database connection method in one embodiment;

[0052] Figure 2 This is a flowchart illustrating a database connection method in one embodiment;

[0053] Figure 3This is a flowchart illustrating step S206 of the database connection method in one embodiment;

[0054] Figure 4 This is a structural block diagram of a database connection device in one embodiment;

[0055] Figure 5 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0056] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0057] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.

[0058] The database connection method provided in this application embodiment can be applied to, for example... Figure 1In the application environment shown, terminal 102 communicates with server 104 via a network and can act as a client to send connection request information to server 104. A data storage system can store the data that server 104 needs to process. The data storage system can be integrated on server 104 or located on the cloud or other network servers. The data storage system can be used to store data such as global singleton object data. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, drones, low-altitude aircraft, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart vehicle devices, projection devices, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc. Head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. Server 104 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. In this embodiment, server 104 may be a database connection management server deployed on a cloud platform, responsible for handling client connection requests and coordinating communication between the client and each node of the database replica set.

[0059] In one exemplary embodiment, such as Figure 2 As shown, a database connection method is provided, which can be applied to... Figure 1 Taking server 104 as an example, the explanation includes the following steps S202 to S208. Wherein:

[0060] Step S202: Obtain connection request information and global singleton object data from the client.

[0061] Among them, such as Figure 3 As shown, the client refers to the application system that accesses the database service and can be deployed in a public network environment. A Virtual Private Cloud (VPC) is a network isolation solution provided by a cloud platform, allowing cloud resources to be deployed in a logically isolated network environment. An Elastic Public IP is a public IP address resource provided by the cloud platform that can be dynamically bound to cloud servers within a VPC, enabling public network access to the cloud servers.

[0062] The connection request information may include the client's network address and the target server's network address. The client's network address may include, for example, an IP address and a port number, while the target server's network address may include, for example, the domain name or IP address of the database service.

[0063] A global singleton object is a data object where only one instance exists throughout the entire system, and data can be shared across multiple modules. The global singleton object data can include the mapping relationship between Elastic Public IP addresses and Virtual Private Cloud addresses.

[0064] For example, server 104 can obtain the elastic public network address binding operation request initiated by the client; generate the mapping relationship between the elastic public network address and the virtual private cloud address according to the binding operation request; and record the mapping relationship in the kernel configuration table.

[0065] For example, to maintain the mapping relationship between Elastic Public IP addresses and VPC addresses, server 104 can interact with the cloud platform's management system. When a client initiates an Elastic Public IP binding operation request, server 104 can obtain the request and generate a mapping record based on the request parameters. This record may contain information such as the Elastic Public IP address and its associated VPC internal IP address. Server 104 can write this record to the kernel configuration table, which is a data structure used to store system configuration information and can be persistently stored in a file system or database.

[0066] Furthermore, server 104 can periodically obtain changes to the data in the kernel configuration table. When the mapping relationships in the kernel configuration table change, the latest mapping relationships are loaded into the global singleton object data. To ensure that the mapping relationships in the global singleton object are consistent with the kernel configuration table, server 104 can also periodically query the kernel configuration table to obtain change records. Once an update to the mapping relationship is detected, server 104 can synchronize the latest mapping relationship to the global singleton object, ensuring that subsequent address translation processes use the latest mapping data. Through these steps, server 104 can dynamically adapt to these changes by updating the kernel configuration table and the global singleton object, ensuring correct routing of connection requests. Furthermore, since the mapping relationship between Elastic Public Addresses (IPAs) and VPC addresses is uniformly managed by server 104, clients cannot directly obtain network topology information within the VPC, reducing the risk of malicious attackers probing and intruding into the VPC's internal network.

[0067] Step S204: Obtain the original response result corresponding to the original master node confirmation command from the client.

[0068] The original master node confirmation command refers to the command sent by the client to the server (e.g., the `isMaster` command) when connecting to a MongoDB replica set. Its purpose is to confirm the master node information of the current replica set so that the client can establish a connection with the master node and perform subsequent data operations. The original response includes the address information of the replica set nodes, such as the node's IP address and port number.

[0069] For example, when a client sends a connection request to server 104, server 104 can forward the request to the master node of the MongoDB replica set. Upon receiving the request, the master node can generate a response containing the address information of each node in the replica set and return it to server 104. Server 104 can then store this response in memory.

[0070] Because MongoDB replica sets can employ automatic failover, the master node of a replica set may change. When a client connects to a replica set, it periodically sends a master node confirmation command to server 104 to obtain the latest replica set topology. Upon receiving these commands, server 104 can repeat the request forwarding and response result storage process described above to ensure that the latest original response result is always stored.

[0071] In a MongoDB replica set, each node has a unique identifier called a "member ID." The member ID can be a 12-byte hexadecimal string used to identify and manage individual nodes within the replica set. In the original response, the address information of each node can be associated with its member ID so that clients can accurately identify and connect to the target node.

[0072] Step S206: If it is determined from the connection request information and global singleton object data that the connection request requires replacement of the elastic public network address, the virtual private cloud address in the original response result is replaced with the corresponding elastic public network address according to the global singleton object data to obtain the target response result.

[0073] For example, server 104 can check whether the target server network address in the connection request information is a VPC address. If it is, it can be directly determined that the connection request requires Elastic IP address replacement.

[0074] The global singleton object data can also include internal network whitelist information. The internal network whitelist can be a pre-configured set of client network addresses that are allowed direct access to resources within the VPC. These addresses can correspond to trusted, highly secure clients, such as those on an enterprise's internal office network. These clients can directly communicate with the database replica set using the VPC address without needing to go through the Elastic IP address translation process.

[0075] After determining that the target server's network address is a VPC address, server 104 can further determine whether the client has permission to directly access VPC resources. For example, if the target server's network address is a Virtual Private Cloud address, server 104 can compare the client's network address in the connection request information with the internal network whitelist in the global singleton object data. If the client's network address is in the internal network whitelist, it means the client is trusted and can directly use the VPC address to communicate with the database replica set. In this case, server 104 does not need to modify the original response result and can directly return it to the client. If the client's network address is not in the internal network whitelist, and the global singleton object data contains the corresponding Elastic Public Address (EPS) information for the target server's network address, server 104 can determine that the connection request needs to be replaced with an EPS.

[0076] For example, a client initiates a connection request, where the target server's network address is "192.168.0.1", while the client's own network address is "203.0.113.1". Upon receiving the request, server 104 first determines that the target server's network address "192.168.0.1" is a VPC address. Next, server 104 checks the internal network whitelist and finds that the client's address "203.0.113.1" is not on the whitelist. Finally, server 104 checks the global singleton object data and finds that the elastic public IP address corresponding to the address "192.168.0.1" is "203.0.113.100". At this point, server 104 can determine that the connection request needs elastic public IP address replacement. After determining that elastic public IP address replacement is necessary, server 104 can modify the address information in the original response result. Server 104 can iterate through each node address in the original response result, replacing the VPC address with the corresponding elastic public IP address.

[0077] Step S208: Send the target response result to the client and establish a connection between the client and each node of the replica set based on the address information in the target response result.

[0078] For example, server 104 can encapsulate the target response into a standard MongoDB protocol message. This message may include multiple parts such as a message header, response flags, and a response document, conforming to the format and specifications of the MongoDB protocol. Server 104 can populate various fields of the message, such as the opcode, request ID, and response content, based on the content of the target response. Subsequently, server 104 can send the encapsulated message to the client over the network. During transmission, server 104 can set various transmission parameters, such as timeout, retries, and buffer size, to improve the reliability and efficiency of message transmission.

[0079] After receiving the target response, the client can first parse and verify it to ensure the message's legitimacy and integrity. Then, the client can extract the address information of each node contained in the response, which may appear in the form of a node address list, master node address, current node address, etc. The client can identify and extract the IP address and port number of each node based on the field names and formats. Next, the client can establish connections with each node in the replica set sequentially based on the extracted address information.

[0080] For example, for each node, the client can perform the following steps: First, create a TCP socket and connect it to the target node's IP address and port number; after the connection is established, the client can send an initialization request to the node to obtain basic information such as the node's role and status; if the node responds to the initialization request and the response content is as expected, the client can mark the node as available and add it to the connection pool; if the node does not respond to the initialization request, or the response content is not as expected, the client can mark the node as unavailable and continue to try to connect to other nodes. The client can repeat the above steps until it successfully connects to the master node of the replica set. Once a connection is established with the master node, the client can begin performing various database operations, such as insert, query, and update.

[0081] During communication with the master node, the client can periodically send heartbeat requests to check the connection's validity. If the master node does not respond to the heartbeat request within a certain time, the client can disconnect and attempt to connect to another node. The client can also monitor topology change events in the replica set, such as node joining, leaving, and master node election. Once a topology change is detected, the client can adjust its maintained connection pool accordingly to ensure a constant connection with the master node. By introducing Server 104 as an intermediate layer, the complex network topology within the VPC is hidden from the client's view, allowing the client to connect to the replica set directly using an Elastic Public IP address, just like connecting to a regular MongoDB server. This greatly simplifies client development and maintenance, improving the usability and maintainability of the application system.

[0082] In the aforementioned database connection method, the mapping relationship between the Elastic Public Network Address (VPC) and the Virtual Private Cloud (VPC) address is obtained by acquiring connection request information from the client and global singleton object data. By obtaining the original response result corresponding to the client's original master node confirmation command, the address information of the replica set nodes can be obtained. By analyzing the original response result in conjunction with the global singleton object data, it is determined which node addresses need to be replaced. If it is determined that the connection request requires replacement of the VPC address based on the connection request information and global singleton object data, the VPC address in the original response result is replaced with the corresponding VPC address based on the global singleton object data, resulting in the target response result. This achieves the mapping from VPC address to VPC address, enabling the client to access the database nodes within the VPC via the VPC address. The target response result is sent to the client, and connections are established between the client and each node in the replica set based on the address information in the target response result. This enables a secure and reliable connection between the client and the MongoDB replica set deployed within the VPC, making the application system accessible and maintainable, ensuring data transmission security, and improving database connection flexibility while maintaining the security and isolation of the cloud database.

[0083] In one exemplary embodiment, such as Figure 3 As shown, step S206 includes steps S302 to S306. Wherein:

[0084] Step S302: Extract the field containing the virtual private cloud address to be replaced from the original response result.

[0085] The fields to be replaced may include one or more of the following: node address list field, master node address field, current responding node address field, arbitrator node address field, passive node address field, and hidden node address field.

[0086] For example, the node address list field can represent the address information of all data-carrying nodes in the replica set, including master nodes, slave nodes, etc. Server 104 can iterate through the values ​​of this field and mark each item as a field to be replaced. For example, if the node address list field value of a certain replica set is "192.168.0.1:27017, 192.168.0.2:27017, 192.168.0.3:27017", server 104 can extract all three addresses and mark them as fields to be replaced respectively. The master node address field is used to indicate the master node address of the current replica set; the current response node address field indicates the source node of the current response message, and the value of this field can be the same as one of the items in the master node address field or the node address list field. The arbitrator node address field is used to indicate the arbitrator node address in the replica set. Arbitrator nodes do not store data, but only participate in voting elections. The passive node address field can be used to indicate the passive node address in the replica set. Passive nodes do not participate in master node elections, but only synchronize data. The hidden node address field indicates the hidden node address in the replica set. Hidden nodes are not visible to clients and are used only for special purposes, such as backup or testing. By performing fine-grained parsing and extraction of the original response results, Server 104 can accurately identify all VPC addresses that need to be replaced.

[0087] Step S304: Based on the global singleton object data, replace the virtual private cloud address in each field to be replaced with the corresponding elastic public network address to obtain the target field.

[0088] For example, server 104 can perform the following steps for each field to be replaced: parse the field value of the field to be replaced, and separate the address part and port part of the field value according to a preset format; find the corresponding public IP address in the global singleton object data; construct a new field value based on the public IP address according to the preset format to obtain the target field. The address information of the MongoDB replica set node can appear in the form of "IP address:port number", such as "192.168.0.1:27017". Server 104 can use string splitting and other techniques to extract the IP address ("192.168.0.1") and port number ("27017"). The global singleton object stores the mapping relationship between VPC addresses and public IP addresses. Server 104 can traverse these mapping relationships, find the item that matches the current IP address, and extract the corresponding public IP address. Server 104 can construct a new field value according to the extracted public IP address and port number, in the same format as the original field value. For example, if the original field value is "192.168.0.1:27017" and the corresponding Elastic Public IP address is "203.0.113.101", then server 104 can construct a new field value "203.0.113.101:27017". Finally, server 104 can assign the constructed new field value to the corresponding field, thus obtaining a target field. For example, if the master node address field value in the original response result is "192.168.0.1:27017", server 104 replaces it with "203.0.113.101:27017", thus obtaining a target master node address field that meets the client's connection requirements. Server 104 can perform the above operation on all fields extracted in the above steps until each field has a corresponding target field. All VPC addresses in the original response result can then be replaced with their corresponding Elastic Public IP addresses, which clients can use to establish connections with nodes in the replica set.

[0089] Step S306: Reconstruct the response data based on the target field to obtain the target response result.

[0090] For example, server 104 can insert all target fields one by one into the corresponding positions in the original response result according to their original positions and hierarchical relationships. For instance, if the master node address field in the original response result is replaced with a target field, server 104 can assign the value of the target field to the master node address field in the original response result.

[0091] Through the reconstruction and optimization steps described above, a complete and high-quality target response result was finally generated. This result not only includes all node information of the replica set, but also ensures that the addresses of all nodes have been converted from VPC internal addresses to Elastic Public IP addresses that can be directly accessed by clients.

[0092] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.

[0093] Based on the same inventive concept, this application also provides a database connection apparatus for implementing the database connection method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more database connection apparatus embodiments provided below can be found in the limitations of the database connection method described above, and will not be repeated here.

[0094] In one exemplary embodiment, such as Figure 4 As shown, a database connection device is provided, including: a data acquisition module 402, a response acquisition module 404, an address processing module 406, and a node connection module 408, wherein:

[0095] The data acquisition module 402 is used to acquire connection request information and global singleton object data from the client; wherein, the global singleton object data includes the mapping relationship between the elastic public network address and the virtual private cloud address;

[0096] The response acquisition module 404 is used to acquire the original response result corresponding to the original master node confirmation command from the client; wherein, the original response result includes the address information of the replica set node;

[0097] Address processing module 406 is used to replace the virtual private cloud address in the original response result with the corresponding elastic public network address based on the global singleton object data when it is determined that the connection request needs to be replaced with an elastic public network address based on the connection request information and global singleton object data, so as to obtain the target response result.

[0098] The node connection module 408 is used to send the target response result to the client and establish the connection between the client and each node of the replica set based on the address information in the target response result.

[0099] In one embodiment, the apparatus further includes: a binding processing module, configured to obtain an elastic public address binding operation request initiated by the client; generate a mapping relationship between the elastic public address and the virtual private cloud internal address based on the binding operation request; and record the mapping relationship in the kernel configuration table.

[0100] In one embodiment, the apparatus further includes: a global singleton object acquisition module, used to periodically acquire changes in data in the kernel configuration table; and to load the latest mapping relationship into the global singleton object data when the mapping relationship in the kernel configuration table changes.

[0101] In one embodiment, the connection request information includes the client network address and the target server network address; the global singleton object data also includes intranet whitelist information; the device further includes: an access control module, used to query whether the client network address is in the intranet whitelist when the target server network address is an internal address of the virtual private cloud; and to determine that the connection request needs to be replaced with an elastic public IP address when the client network address is not in the intranet whitelist and the global singleton object data contains elastic public IP address information corresponding to the target server network address.

[0102] In one embodiment, the address processing module 406 is specifically used to extract a field containing the internal address of the virtual private cloud from the original response result; the field to be replaced includes one or more of the following: node address list field, master node address field, current response node address field, arbitrator node address field, passive node address field, and hidden node address field; based on the global singleton object data, the internal address of the virtual private cloud in each field to be replaced is replaced with the corresponding elastic public network address to obtain the target field; the response data is reconstructed based on the target field to obtain the target response result.

[0103] In one embodiment, the address processing module 406 is further configured to perform the following steps for each field to be replaced: parse the field value of the field to be replaced, and separate the address part and port part of the field value according to a preset format; search for the elastic public network address corresponding to the address part in the global singleton object data; and construct a new field value according to the elastic public network address according to the preset format to obtain the target field.

[0104] Each module in the aforementioned database connection device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.

[0105] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 5 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores data such as global singleton object data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a database connection method.

[0106] Those skilled in the art will understand that Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0107] In an exemplary embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to perform the following steps: obtaining connection request information and global singleton object data from a client; wherein the global singleton object data includes a mapping relationship between elastic public network addresses and virtual private cloud internal addresses; obtaining the original response result corresponding to the client's original master node confirmation command; wherein the original response result includes address information of replica set nodes; if it is determined from the connection request information and global singleton object data that the connection request requires elastic public network address replacement, the virtual private cloud internal address in the original response result is replaced with the corresponding elastic public network address according to the global singleton object data to obtain a target response result; sending the target response result to the client, and establishing connections between the client and each node of the replica set according to the address information in the target response result.

[0108] In one embodiment, when the processor executes the computer program, it further performs the following steps: obtaining an elastic public network address binding operation request initiated by the client; generating a mapping relationship between the elastic public network address and the internal address of the virtual private cloud based on the binding operation request; and recording the mapping relationship in the kernel configuration table.

[0109] In one embodiment, when the processor executes a computer program, it also performs the following steps: periodically retrieves changes to data in the kernel configuration table; and, if the mapping in the kernel configuration table changes, loads the latest mapping into the global singleton object data.

[0110] In one embodiment, when the processor executes the computer program, it further performs the following steps: if the target server network address is an internal address of the virtual private cloud, it queries whether the client network address is in the internal network whitelist; if the client network address is not in the internal network whitelist, and the global singleton object data contains the elastic public IP address information corresponding to the target server network address, it determines that the connection request needs to be replaced with an elastic public IP address.

[0111] In one embodiment, when the processor executes the computer program, it further performs the following steps: extracting a field containing the internal address of the virtual private cloud from the original response result; the field to be replaced includes one or more of the following: node address list field, master node address field, current response node address field, arbitrator node address field, passive node address field, and hidden node address field; replacing the internal address of the virtual private cloud in each field to be replaced with the corresponding elastic public network address according to the global singleton object data, to obtain the target field; reconstructing the response data according to the target field to obtain the target response result.

[0112] In one embodiment, when the processor executes the computer program, it further performs the following steps: for each field to be replaced, it performs the following steps: parses the field value of the field to be replaced, and separates the address part and port part of the field value according to a preset format; searches for the elastic public network address corresponding to the address part in the global singleton object data; and constructs a new field value based on the elastic public network address according to a preset format to obtain the target field.

[0113] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When executed by a processor, the computer program performs the following steps: obtaining connection request information and global singleton object data from a client; wherein the global singleton object data includes a mapping relationship between elastic public network addresses and virtual private cloud internal addresses; obtaining the original response result corresponding to the client's original master node confirmation command; wherein the original response result includes address information of replica set nodes; if it is determined from the connection request information and global singleton object data that the connection request requires elastic public network address replacement, replacing the virtual private cloud internal address in the original response result with the corresponding elastic public network address according to the global singleton object data, to obtain a target response result; sending the target response result to the client, and establishing connections between the client and each node of the replica set according to the address information in the target response result.

[0114] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: obtaining the elastic public network address binding operation request initiated by the client; generating a mapping relationship between the elastic public network address and the virtual private cloud internal address based on the binding operation request; and recording the mapping relationship in the kernel configuration table.

[0115] In one embodiment, when the computer program is executed by the processor, it also performs the following steps: periodically retrieves changes to the data in the kernel configuration table; and, if the mapping in the kernel configuration table changes, loads the latest mapping into the global singleton object data.

[0116] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: if the target server network address is an internal address of the virtual private cloud, it queries whether the client network address is in the internal network whitelist; if the client network address is not in the internal network whitelist, and the global singleton object data contains the elastic public IP address information corresponding to the target server network address, it determines that the connection request needs to be replaced with an elastic public IP address.

[0117] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: extracting a field containing the internal address of the virtual private cloud from the original response result; the field to be replaced includes one or more of the following: node address list field, master node address field, current response node address field, arbitrator node address field, passive node address field, and hidden node address field; replacing the internal address of the virtual private cloud in each field to be replaced with the corresponding elastic public network address according to the global singleton object data, to obtain the target field; reconstructing the response data according to the target field to obtain the target response result.

[0118] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: for each field to be replaced, it performs the following steps: parses the field value of the field to be replaced, and separates the address part and port part of the field value according to a preset format; searches for the elastic public network address corresponding to the address part in the global singleton object data; and constructs a new field value based on the elastic public network address according to a preset format to obtain the target field.

[0119] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps: obtaining connection request information and global singleton object data from a client; wherein the global singleton object data includes a mapping relationship between elastic public network addresses and virtual private cloud internal addresses; obtaining the original response result corresponding to the client's original master node confirmation command; wherein the original response result includes address information of replica set nodes; if it is determined from the connection request information and global singleton object data that the connection request requires elastic public network address replacement, replacing the virtual private cloud internal address in the original response result with the corresponding elastic public network address according to the global singleton object data, to obtain a target response result; sending the target response result to the client, and establishing connections between the client and each node of the replica set according to the address information in the target response result.

[0120] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: obtaining the elastic public network address binding operation request initiated by the client; generating a mapping relationship between the elastic public network address and the virtual private cloud internal address based on the binding operation request; and recording the mapping relationship in the kernel configuration table.

[0121] In one embodiment, when the computer program is executed by the processor, it also performs the following steps: periodically retrieves changes to the data in the kernel configuration table; and, if the mapping in the kernel configuration table changes, loads the latest mapping into the global singleton object data.

[0122] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: if the target server network address is an internal address of the virtual private cloud, it queries whether the client network address is in the internal network whitelist; if the client network address is not in the internal network whitelist, and the global singleton object data contains the elastic public IP address information corresponding to the target server network address, it determines that the connection request needs to be replaced with an elastic public IP address.

[0123] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: extracting a field containing the internal address of the virtual private cloud from the original response result; the field to be replaced includes one or more of the following: node address list field, master node address field, current response node address field, arbitrator node address field, passive node address field, and hidden node address field; replacing the internal address of the virtual private cloud in each field to be replaced with the corresponding elastic public network address according to the global singleton object data, to obtain the target field; reconstructing the response data according to the target field to obtain the target response result.

[0124] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: for each field to be replaced, it performs the following steps: parses the field value of the field to be replaced, and separates the address part and port part of the field value according to a preset format; searches for the elastic public network address corresponding to the address part in the global singleton object data; and constructs a new field value based on the elastic public network address according to a preset format to obtain the target field.

[0125] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.

[0126] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.

[0127] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0128] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A database connection method, characterized in that, The method includes: Obtain connection request information and global singleton object data from the client; wherein, the global singleton object data includes the mapping relationship between elastic public network addresses and virtual private cloud addresses; Obtain the original response result corresponding to the original master node confirmation command of the client; wherein, the original response result includes the address information of the replica set node; If it is determined from the connection request information and the global singleton object data that the connection request requires replacement of the elastic public network address, the virtual private cloud address in the original response result is replaced with the corresponding elastic public network address according to the global singleton object data to obtain the target response result; The target response result is sent to the client, and a connection is established between the client and each node of the replica set based on the address information in the target response result.

2. The method according to claim 1, characterized in that, The method further includes: Get the elastic public IP address binding operation request initiated by the client; Based on the binding operation request, a mapping relationship between the elastic public network address and the virtual private cloud address is generated; Record the mapping relationship in the kernel configuration table.

3. The method according to claim 2, characterized in that, The methods for obtaining the global singleton object data include: Periodically retrieve changes to the data in the kernel configuration table; If the mapping relationship in the kernel configuration table changes, the latest mapping relationship will be loaded into the global singleton object data.

4. The method according to claim 1, characterized in that, The connection request information includes the client network address and the target server network address; The global singleton object data also includes intranet whitelist information; the method further includes: If the target server network address is a virtual private cloud address, query whether the client network address is within the intranet whitelist; If the client's network address is not in the intranet whitelist, and the global singleton object data contains the elastic public IP address information corresponding to the target server's network address, then it is determined that the connection request needs to be replaced with an elastic public IP address.

5. The method according to any one of claims 1 to 4, characterized in that, The step of replacing the Virtual Private Cloud address in the original response result with the corresponding Elastic Public Network address based on the global singleton object data to obtain the target response result includes: Extract the field to be replaced containing the virtual private cloud address from the original response result; the field to be replaced includes one or more of the following: node address list field, master node address field, current response node address field, arbitrator node address field, passive node address field, and hidden node address field; Based on the global singleton object data, the virtual private cloud address in each of the fields to be replaced is replaced with the corresponding elastic public network address to obtain the target field; The response data is reconstructed based on the target field to obtain the target response result.

6. The method according to claim 5, characterized in that, The step involves replacing the Virtual Private Cloud address in each of the fields to be replaced with the corresponding Elastic Public Network Address based on the global singleton object data, to obtain the target fields, including: Perform the following steps for each of the fields to be replaced: Parse the field value of the field to be replaced, and separate the address part and port part of the field value according to a preset format; Search for the elastic public IP address corresponding to the address portion in the global singleton object data; According to the preset format, a new field value is constructed based on the elastic public IP address to obtain the target field.

7. A database connection device, characterized in that, The device includes: The data acquisition module is used to acquire connection request information and global singleton object data from the client; wherein, the global singleton object data includes the mapping relationship between elastic public network addresses and virtual private cloud addresses; The response acquisition module is used to acquire the original response result corresponding to the original master node confirmation command of the client; wherein, the original response result includes the address information of the replica set node; The address processing module is used to replace the virtual private cloud address in the original response result with the corresponding elastic public network address based on the global singleton object data when it is determined that the connection request needs to be replaced with an elastic public network address based on the connection request information and the global singleton object data, so as to obtain the target response result. The node connection module is used to send the target response result to the client and establish a connection between the client and each node of the replica set based on the address information in the target response result.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Optical touch screen and touch pen

    CN101344827A

  • System for monitoring network communication data packets

    CN101594263A

  • Configuration information updating method and device, electronic equipment and storage medium

    CN111277432A

  • Single example object loading method and device, storage medium and electronic equipment

    CN119201276A

  • Cloud scene message processing method, cloud scene database auditing method and gateway

    CN119383158A