Database node connection switching method, device, computer equipment and storage medium
By calculating the correlation and pressure scores of database nodes, dynamically switching database node connections is solved, and the problem of low data access efficiency caused by fixed database node connections is achieved, and more efficient data access is achieved.
Patent Information
- Application Number
- CN202410165945.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-04
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2044-02-04
AI Technical Summary
In the prior art, the database node connection is fixed, resulting in the database data access efficiency in some cases.
By obtaining data access requests and results, the node correlation scores and node pressure scores of multiple database nodes are calculated, and the connection node switching instructions are determined based on these scores to realize dynamic switching of database node connections.
Improve the accuracy and efficiency of database node connection switching, ensuring that database clients are always connected to the optimal node, thereby improving data access efficiency.
Smart Images

Figure CN118606035B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of distributed databases, and in particular to a database node connection switching method, device, computer equipment and storage medium. Background Art
[0002] A distributed database is a database system that stores data in multiple physical or logical nodes. Its main features are high scalability, high availability, high fault tolerance, high data consistency, and multi-regional deployment. A distributed database can expand the capacity and performance of the database by adding more nodes, so that even if a node fails, the database can continue to run; in a distributed database, data is replicated to multiple nodes, so even if a node fails, the data can still be recovered from other nodes.
[0003] In the related art, database node connections are fixed, resulting in low database data access efficiency in some cases. Summary of the invention
[0004] The embodiments of the present disclosure provide a database node connection switching method and device, a database node connection switching method and device. The database node connection switching method can improve the accuracy of database node connection switching, and the database node connection switching method based on the database node connection switching method can improve the accuracy of database node connection switching.
[0005] A first aspect of the present disclosure provides a database node connection switching method, the method comprising:
[0006] Obtaining a data access request received by a first target node via a target connection within a first target period, and obtaining a data access result corresponding to the data access request, wherein the first target node is a database node in a distributed database, and the data access request accesses data in multiple database nodes of the distributed database;
[0007] Calculate node relevance scores corresponding to the multiple database nodes according to the data access request and the data access result;
[0008] Obtaining node status parameters corresponding to each database node, and calculating a node stress score of each database node according to the node status parameters;
[0009] Determining a connection node switching instruction based on the node relevance score and the node pressure score;
[0010] The node switching instruction is sent to a target terminal, so that the target terminal switches the database node for establishing a connection based on the node switching instruction. The target terminal is a terminal connected to the target database node via the target connection.
[0011] A second aspect of the present disclosure provides a database node connection switching device, the device comprising:
[0012] A first acquisition unit is used to acquire a data access request received by a first target node via a target connection within a first target period, and to acquire a data access result corresponding to the data access request, wherein the first target node is a database node in a distributed database, and the data access request accesses data in multiple database nodes of the distributed database;
[0013] A calculation unit, configured to calculate node relevance scores corresponding to the plurality of database nodes according to the data access request and the data access result;
[0014] A second acquisition unit is used to acquire a node state parameter corresponding to each database node, and calculate a node stress score of each database node according to the node state parameter;
[0015] a determining unit, configured to determine a connection node switching instruction based on the node correlation score and the node pressure score;
[0016] The sending unit is used to send the node switching instruction to the target terminal, so that the target terminal switches the database node for establishing the connection based on the node switching instruction. The target terminal is a terminal connected to the target database node via the target connection.
[0017] Optionally, in some embodiments, the computing unit comprises:
[0018] A parsing subunit, used to parse the data access request and generate a data access plan based on the parsing result;
[0019] A first determining subunit, configured to determine, based on the data access plan, a first correlation score between a data access service initiating the data access request and a plurality of database nodes;
[0020] A second determining subunit, configured to determine a second correlation score between the data access service and the plurality of database nodes according to the data access result;
[0021] The first calculation subunit is configured to calculate node correlation scores corresponding to the plurality of database nodes based on the first correlation score and the second correlation score.
[0022] Optionally, in some embodiments, the first determining subunit includes:
[0023] A first determination module, configured to determine the number of hit accesses of each database node among the plurality of database nodes according to the data access plan;
[0024] The second determination module is configured to determine a first correlation score between the data access service of the data access request and a plurality of database nodes according to the number of accesses.
[0025] Optionally, in some embodiments, the second determining subunit includes:
[0026] A third determination module, configured to determine the number of access results returned by each database node for the data access request based on the data access result;
[0027] The fourth determination module is used to determine a second correlation score between the data access service of the data access request and the multiple database nodes according to the number of the access results.
[0028] Optionally, in some embodiments, the first computing subunit includes:
[0029] An acquisition module, configured to acquire a first weight coefficient corresponding to the first correlation score, and acquire a second weight coefficient corresponding to the second correlation score;
[0030] A calculation module is used to perform weighted calculation on the first correlation score and the second correlation score based on the first weight coefficient and the second weight coefficient to obtain node correlation scores corresponding to the multiple database nodes.
[0031] Optionally, in some embodiments, the database node connection switching device provided by the present disclosure further includes:
[0032] A first acquisition subunit, used to acquire a node switching cost parameter;
[0033] The determining unit is further configured to:
[0034] A connection node switching instruction is determined based on the node relevance score, the node pressure score, and the node switching cost parameter.
[0035] Optionally, in some embodiments, the determining unit includes:
[0036] A second acquisition subunit is used to acquire a third weight coefficient corresponding to the node relevance score, a fourth weight coefficient corresponding to the node pressure score, and a fifth weight coefficient corresponding to the node switching cost parameter;
[0037] a second calculation subunit, configured to perform weighted calculation on the node relevance score, the node pressure score, and the node switching cost parameter based on the third weight coefficient, the fourth weight coefficient, and the fifth weight coefficient to obtain a node switching score corresponding to each of the database nodes;
[0038] The third determining subunit is used to determine a connection node switching instruction according to the node switching score.
[0039] Optionally, in some embodiments, the third determining subunit includes:
[0040] A fifth determination module, configured to determine a second target node having a highest node switching score among the plurality of database nodes;
[0041] A generation module is used to generate a node switching instruction according to the first target node and the second target node when the first target node is different from the second target node, and the node switching instruction indicates that the node connected to the distributed database is switched from the first target node to the second target node.
[0042] Optionally, in some embodiments, the database node connection switching device provided by the present disclosure further includes a construction subunit, wherein the construction subunit includes:
[0043] A disconnection module, used to disconnect the target connection with the first target node;
[0044] An establishing module is used to establish a data connection with the second target node.
[0045] Optionally, in some embodiments, the second acquiring unit includes:
[0046] A third acquisition subunit is used to acquire the CPU usage rate, memory occupancy rate, data transmission rate and input and output data volume of each database node within the first target time period;
[0047] The third calculation subunit is used to calculate the node stress score of each database node according to the CPU usage rate, memory occupancy rate, data transmission rate and input and output data volume.
[0048] Optionally, in some embodiments, the database node switching device provided by the present disclosure further includes:
[0049] an analysis subunit, configured to perform a rationality analysis on the node switching instruction within a second target time period after the target terminal executes the node switching instruction, and obtain an analysis result, wherein the second target time period has the same target duration as the first target time period;
[0050] The execution subunit is used to re-execute the following steps within the second target time period when it is determined that the node switching instruction is reasonable based on the analysis result: calculating the node relevance scores of multiple database nodes based on the data access requests sent by the target terminal to the distributed database within the current time period and the corresponding data access results; calculating the node pressure score of each database node according to the node state parameter of each database node; determining the node switching instruction based on the node relevance score and the node pressure score; and sending the node switching instruction to the target terminal;
[0051] The reducing subunit is used to reduce the target duration when it is determined based on the analysis result that the node switching instruction is unreasonable.
[0052] A third aspect of the present disclosure provides a storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the database node connection switching method as described in the first aspect is implemented.
[0053] A fourth aspect of the present disclosure provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the database node connection switching method as described in the first aspect is implemented.
[0054] A fifth aspect of the present disclosure provides a computer program product, which includes a computer program. The computer program is read and executed by a processor of a computer device, so that the computer device executes the database node connection switching method as described in the first aspect.
[0055] The database node connection switching method provided by the embodiment of the present disclosure obtains data access requests received by the first target node via a target connection within a first target time period, and obtains data access results corresponding to the data access requests, wherein the first target node is a database node in a distributed database, and the data access requests access data in multiple database nodes of the distributed database; node correlation scores corresponding to multiple database nodes are calculated according to the data access requests and the data access results; node status parameters corresponding to each database node are obtained, and a node stress score of each database node is calculated according to the node status parameters; a connection node switching instruction is determined based on the node correlation score and the node stress score; and a node switching instruction is sent to a target terminal, so that the target terminal switches the database node for construction of the connection based on the node switching instruction, and the target terminal is a terminal connected to the target database node via the target connection.
[0056] The disclosed embodiment scores the relevance of the database nodes in the distributed database nodes to the current access business and scores the node pressure of each database node according to a certain time period. Then, a connection node switching instruction is generated according to the node relevance score and the node pressure score to guide the database client to switch the node connection, thereby ensuring that the database client is always connected to the optimal node, thereby improving the data access efficiency of the database.
[0057] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or understood by practicing the present disclosure. The purpose and other advantages of the present disclosure can be realized and obtained by the structures particularly pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] The accompanying drawings are used to provide further understanding of the technical solution of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the technical solution of the present disclosure and do not constitute a limitation on the technical solution of the present disclosure.
[0059] Figure 1 A system architecture diagram for a database node connection switching method according to an embodiment of the present disclosure;
[0060] Figure 2 A system architecture diagram for a database node connection switching method according to an embodiment of the present disclosure;
[0061] Figure 3 A schematic diagram of a flow chart of a database node connection switching method provided by the present disclosure;
[0062] Figure 4 It is a schematic diagram of using a sharding algorithm to access a distributed database in the related art;
[0063] Figure 5 A schematic diagram of a distributed database access using a proxy method in a related art;
[0064] Figure 6 A schematic diagram of database access based on the distributed capability of a distributed database;
[0065] Figure 7 Another schematic diagram of a process flow of a database node connection switching method provided by the present disclosure;
[0066] Figure 8 A schematic diagram of data access using the database node connection switching method provided in this application;
[0067] Fig. 9 A schematic diagram of periodic node switching of the database node switching method provided by the present disclosure;
[0068] Fig.10 A schematic diagram of the structure of a database node connection switching device provided in an embodiment of the present disclosure;
[0069] Fig.11 is a terminal structure diagram for implementing various methods according to an embodiment of the present disclosure;
[0070] Fig.12 It is a server structure diagram for implementing various methods according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0071] In order to make the purpose, technical solution and advantages of the present disclosure more clear, the present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present disclosure and are not used to limit the present disclosure.
[0072] Before further describing the embodiments of the present disclosure in detail, the nouns and terms involved in the embodiments of the present disclosure are described. The nouns and terms involved in the embodiments of the present disclosure are subject to the following interpretations:
[0073] Distributed database: A distributed database is a database system that stores data in multiple physical or logical nodes. Its main features include scalability, high availability, fault tolerance, data consistency, and multi-regional deployment. A distributed database can expand the capacity and performance of the database by adding more nodes. Even if a node fails, the database can continue to run. The data is replicated to multiple nodes, so even if a node fails, the data can still be recovered from other nodes. Distributed databases usually use consistency protocols to ensure data consistency between different nodes and can be deployed in different geographical locations to provide better performance and user experience.
[0074] Online Transaction Processing (OLTP): A computer system used to process a large number of short-term transactions, usually used in enterprise-level applications such as securities, telecommunications, and retail. Objects used in these systems are generally very sensitive to latency. The main characteristics of OLTP systems are high concurrency, high availability, high performance, and high reliability. They need to support transaction management, concurrency control, database indexing, data backup and recovery, security management, and other functions to ensure data consistency and integrity.
[0075] Distributed databases improve the horizontal expansion capability of database systems by distributing and storing data on multiple physical or logical nodes, but this also requires a certain price, such as increasing the access delay of the database. Because the distributed storage of data may cause the node where the data is actually placed and the data access entrance to be not on the same node. In the related art, in order to improve the access efficiency of data in a distributed database, when a general database client receives a data access instruction, it will first determine the target database node where the data accessed by the data access instruction is stored, and then directly establish a connection with the target database node to access the data. However, in some business scenarios with high concurrency, such as OLTP business scenarios, database clients may generate a large number of data access requests at the same time. In extreme cases, each database client is required to establish a data connection with each distributed database node, which causes excessive pressure on data connection management.
[0076] In other related technologies, a proxy module is set between the database client and the database node to coordinate the database access. In this case, each database client only needs to establish a data connection with the proxy module, and then the proxy module establishes a data connection with each database node. This method can greatly reduce the number of data connections, thereby reducing the management pressure of data connections. However, this method causes the data access process to first go to the proxy module and then to the database node. The access process has one more hop, which increases the access delay and reduces the data access efficiency.
[0077] In order to solve the problem of low data access efficiency in the above scenario, the present disclosure provides a database node connection switching method, which can improve the efficiency of data access in a distributed database.
[0078] System architecture and scenario description of the application of the embodiments of the present disclosure
[0079] Figure 1 It is a system architecture diagram applied by the database node connection switching method according to an embodiment of the present disclosure, and includes a terminal 140, the Internet 130, a gateway 120, a server 110, and the like.
[0080] The terminal 140 includes various forms such as desktop computers, laptop computers, PDAs (personal digital assistants), mobile phones, vehicle-mounted terminals, home theater terminals, dedicated terminals, intelligent voice interaction devices, smart home appliances, aircraft, or control terminals of colposcopy image acquisition systems. In addition, it can be a single device or a collection of multiple devices. The terminal 140 can communicate with the Internet 130 in a wired or wireless manner to exchange data. In the disclosed embodiment, the terminal 140 can be loaded with a client of a distributed database, or loaded with other applications that can access distributed data.
[0081] The server 110 refers to a computer system that can provide certain services to the terminal 140. Compared with the ordinary terminal 140, the server 110 has higher requirements in terms of stability, security, performance, etc. The server 110 can be a high-performance computer in a network platform, a cluster of multiple high-performance computers, a part of a high-performance computer (such as a virtual machine), a combination of parts of multiple high-performance computers (such as virtual machines), etc. In the embodiment of the present disclosure, the server 110 specifically provides a storage function, that is, the server 110 here can be a database node of a distributed database, and the present disclosure has a cluster of multiple servers 110 forming a distributed database.
[0082] The gateway 120 is also called an internetwork connector or a protocol converter. The gateway realizes network interconnection at the transport layer and is a computer system or device that acts as a converter. The gateway is a translator between two systems that use different communication protocols, data formats or languages, or even have completely different architectures. At the same time, the gateway can also provide filtering and security functions. The message sent by the terminal 140 to the server 110 must be sent to the corresponding server 110 through the gateway 120. The message sent by the server 110 to the terminal 140 must also be sent to the corresponding terminal 140 through the gateway 120. In the embodiment of the present disclosure, the terminal 140 sends a data access request to the server 110 through the gateway 120, and the server 110 returns the data access result to the terminal 140 via the gateway 120.
[0083] The database node connection switching method provided by the embodiment of the present disclosure may be implemented in the server 110 or in other terminals connected to the server.
[0084] When the database node connection switching method provided by the embodiment of the present disclosure is implemented in the server 110 (distributed database node), the server 110 obtains the data access request received by the first target node via the target connection within the first target period, and obtains the data access result corresponding to the data access request, the first target node is a database node in the distributed database (which can be the server 110 itself), and the data access request accesses the data in multiple database nodes of the distributed database; the server 110 calculates the node correlation scores corresponding to the multiple database nodes according to the data access request and the data access result; obtains the node status parameters corresponding to each database node, and calculates the node stress score of each database node according to the node status parameters; determines the connection node switching instruction based on the node correlation score and the node stress score; sends the node switching instruction to the terminal 140, so that the target terminal switches the database node for construction connection based on the node switching instruction, and the terminal 140 is connected to the target database node via the target connection.
[0085] Among them, in some embodiments, there may also be a connection switching control terminal connected to the terminal 140 and the server 110 respectively between the terminal 140 and the server 110. The terminal 140 does not need to go through the connection switching control terminal when accessing the data in the server 110, but the database node connection switching method provided in the present disclosure can be implemented in the connection switching control terminal. Specifically, the connection switching control terminal obtains the data access request received by the server 110 via the target connection within the first target time period, and obtains the data access result corresponding to the data access request; calculates the node correlation scores corresponding to multiple database nodes according to the data access request and the data access result; obtains the node status parameters corresponding to each database node, and calculates the node pressure score of each database node according to the node status parameters; determines the connection node switching instruction based on the node correlation score and the node pressure score; sends the node switching instruction to the terminal 140, so that the terminal 140 switches the database node to build the connection based on the node switching instruction. As Figure 2 , which is another system architecture diagram applied to the database node connection switching method of an embodiment of the present disclosure.
[0086] The database node connection switching method provided by the embodiment of the present disclosure can be applied to various distributed database usage scenarios, and can be specifically applied to the aforementioned OLTP-type data access business scenario with high concurrency to the distributed database.
[0087] For example, in a securities trading business scenario, the securities trading business corresponding to the securities trading application is stored in multiple database nodes of a distributed database. When conducting securities trading, it is necessary to continuously access the data stored in different database nodes of the distributed database. Since the data accessed by different access requests may be stored in different database nodes, if the securities trading application is fixedly connected to a database node, the access efficiency of the data stored in other nodes will decrease, thereby causing the overall data access efficiency to decrease. Therefore, in the disclosed embodiment, the distributed database node will score the correlation between the current access business and each database node at regular intervals, and perform a node pressure score on each database node, and then perform node connection switching on the database node to which the client of the securities trading application is connected based on the correlation score and the node pressure score, so as to ensure that the client of the securities trading application is always connected to the optimal node, thereby greatly improving the data access efficiency of the database.
[0088] The above examples do not limit the scope of protection of this case.
[0089] General description of the disclosed embodiments
[0090] According to an embodiment of the present disclosure, a database node connection switching method is provided. Figure 3 As shown, it is a flow chart of the database node connection switching method provided by the present disclosure. The method can be applied to a database node connection switching device, and the database node connection switching device can be integrated in a computer device, and the computer device can be a terminal or a server. The database node connection switching method may include:
[0091] Step 310: Obtain a data access request received by the first target node via the target connection within a first target period, and obtain a data access result corresponding to the data access request.
[0092] First of all, before introducing the database node connection switching method provided by the present disclosure, we can first introduce the method of data access to a distributed database in the related art, so as to more clearly demonstrate the improvements made by the method provided by the present disclosure and the effects brought about.
[0093] like Figure 4 As shown, it is a schematic diagram of using a sharding algorithm to access a distributed database in the related art. As shown in the figure, in the scheme of using a sharding algorithm (sharding jdbc) to access data to the database nodes of a distributed database, the client 410 is connected separately with each database node 420 in the distributed database by driving. In this way, when the client generates a data access request to the distributed database, it can first determine which database node the data to be accessed is in according to the data access request, and then further establish a connection with these database nodes, and then access the data in the database node according to the connection corresponding to these database nodes. If the access request of the client includes multiple access requests, then it may be necessary for the driver of the client to establish a data connection with each distributed database node. If there are M clients and N database nodes in the distributed database, then it may be necessary to establish M*N data connections, which will cause the management pressure of data connections to increase.
[0094] like Figure 5 As shown, it is a schematic diagram of using a proxy method to access a distributed database in the related art. As shown in the figure, the client 410 is connected to the proxy module 510 through a driver, and then the proxy module 510 accesses the database node 420 according to the data access request. In this way, each client only needs to connect to the proxy module 510. If there are M clients and N database nodes in the distributed database, then at most M+N data connections need to be established, thereby greatly reducing the management pressure of data connections. However, due to the addition of a proxy module, this solution causes an extra hop to the data access to the distributed database, which in turn causes a decrease in the data access efficiency to the distributed database.
[0095] like Figure 6 As shown, it is a schematic diagram of database access based on the distributed capability of a distributed database. As shown in the figure, in this method, the client driver 410 can be directly connected to the database node 420, without the need for an extra proxy module, thereby avoiding the delay caused by an extra step in the data access request processing flow. Moreover, in this method, the client only needs to establish a connection with a node in the distributed database through the driver, and the data stored in other nodes can be accessed through the distributed capability of the distributed database, that is, the access to the data in other database nodes can be achieved through the communication between the database nodes. However, in this solution, after the client establishes a connection with the database node through the driver, the connection remains fixed. When most of the data corresponding to the data access request is stored in the database node corresponding to the connection, the data access rate is high. However, if only a small part of the data corresponding to the data access request is stored in the database node corresponding to the connection, most of the data is stored in other database nodes. Since the data access request is transmitted between database nodes, it also takes a certain delay, which will lead to a decrease in data access efficiency.
[0096] To solve Figure 6 In the database data access method shown in the figure, the connection between the client and the database node is fixed, resulting in low data access efficiency when the connected database node does not match the database access request. The present disclosure provides a database node connection switching method, which can perform real-time switching and adjustment of node connections according to the correlation between the data access business and each database node and the node pressure of the node itself, so that the node connected to the client is always the optimal node, thereby improving the efficiency of data access. The scheme is described in detail below.
[0097] First, the frequency of switching the database node connection can be set, for example, the first target period can be set as the periodic duration to periodically switch the database node connected to the client. The first target period can be set and adjusted according to actual conditions, for example, it can be set to 10 seconds, 30 seconds, etc.
[0098] The database node connection switching method may be a method for switching the database node to which the target terminal is connected. For different terminals (i.e., different clients), the same method may be used to switch the database node connection. Therefore, only the target terminal is used as an example for introduction. During the first target period, the target terminal is connected to the first target node in the distributed database through the driver, and the connection between the target terminal and the first target node may be referred to as a target connection.
[0099] During the first target period, the first target node receives a data access request sent by the target terminal through the target connection, and parses the data access request. The database access request received by the first target node through the target connection can access the data stored in the first target node, and can also access the data stored in other database nodes in the distributed database; when the data to be accessed by the data access request is stored in the first target node, local access can be performed directly. If the data to be accessed by the data access request is stored in other database nodes, the first target node can send access instructions to other database nodes to achieve data access. The database node connection switching device can obtain the data access requests received by the first target node during the first target period, and the data access results corresponding to these data access requests, so as to use these data to perform node switching evaluation. Among them, the database node connection switching device can be the first target node itself, or it can be other devices connected to the first target node.
[0100] Step 320: Calculate node relevance scores corresponding to multiple database nodes according to the data access request and the data access result.
[0101] After obtaining the data access requests received by the first target node via the target connection during the first target period, and the data access results corresponding to these data access requests, each database node in the distributed database can be scored for node relevance based on these data access requests and the corresponding data access results, and the node relevance score corresponding to each database node can be obtained. Among them, the node relevance score here can specifically be to evaluate the relevance between the data access service of the target terminal (specifically represented by multiple data access requests and corresponding data access results) and each database node during the first target period. For example, the more times a database node is hit in a data access request, the higher the relevance of the database node, and the more data access results returned by a database node in the data access result, the higher the relevance of the database node.
[0102] In some embodiments, calculating node relevance scores corresponding to multiple database nodes according to the data access request and the data access result includes:
[0103] Parse the data access request and generate a data access plan based on the parsing result;
[0104] Determine, based on the data access plan, a first correlation score between the data access service that initiates the data access request and the plurality of database nodes;
[0105] Determine a second correlation score between the data access service and the plurality of database nodes according to the data access result;
[0106] Node relevance scores corresponding to the plurality of database nodes are calculated based on the first relevance score and the second relevance score.
[0107] In the disclosed embodiment, when the first target node receives a structured query language (SQL) statement corresponding to a data access request sent by a target terminal, the optimizer may be used to parse the SQL statement and generate a data access plan based on the parsing result. In the data access plan generation stage, the regularity and frequency of the keys and values of the distribution of the current business (i.e., the data access business) may be learned, and these keys and values may indicate which database nodes the data to be accessed is stored in. Then, the first correlation score between the data access business that initiates the data access request and the multiple database nodes may be determined according to the data access plan. The first correlation score indicates the correlation between the data access request and each database node in the plan generation stage, and the correlation score may be understood as an active correlation score, which is only related to the data access request initiated by the target terminal and has nothing to do with the amount of data stored in the database node. Further, the second correlation score between the data access business and the multiple database nodes may be determined according to the data access result, and the data access result includes the amount of accessed data returned for each data access request. The second correlation score may be understood as a passive correlation score, which is related to the amount of data stored in the database node.
[0108] After the first relevance score and the second relevance score of each database node are determined, the node relevance score of each database node may be further calculated according to the first relevance score and the second relevance score of each database node.
[0109] In some embodiments, determining a first correlation score between a data access service initiating a data access request and a plurality of database nodes based on a data access plan includes:
[0110] Determine the number of times each database node in the plurality of database nodes is accessed according to the data access plan;
[0111] A first correlation score between a data access service of the data access request and a plurality of database nodes is determined according to the number of accesses.
[0112] Among them, in the embodiment of the present disclosure, the first relevance score of each database node can be determined according to the number of accesses hit by each database node in the data access plan. During the first target period, the first target node may receive multiple data access requests from the target terminal. In this case, it is necessary to parse the multiple data access requests and generate access plans, and then summarize the total number of times each database node is hit by multiple data access plans, and determine the first relevance score of each database node according to the total number of times it is hit by multiple data access plans.
[0113] In some embodiments, determining a second correlation score between the data access service and the plurality of database nodes according to the data access result includes:
[0114] Determine the number of access results returned by each database node for the data access request based on the data access result;
[0115] A second correlation score between the data access service of the data access request and the plurality of database nodes is determined according to the number of access results.
[0116] In the embodiment of the present disclosure, the specific process of determining the second correlation score between the data access service and each database node according to the data access result can be to first determine the number of access results returned by each database node for the data access request based on the data access result, specifically, the number of access results returned. Then, the second correlation score corresponding to the data access service corresponding to the data access request and each database node can be further determined according to the number of access results.
[0117] Among them, when the first target node receives multiple data access requests within the first target time period, the number of access results returned by each database node in the multiple access results corresponding to the multiple access requests can be summarized, and then the second correlation score between the data access service and each database node can be determined based on the summarized number of access results.
[0118] The first correlation score and the second correlation score are introduced below with a specific example. For example, the first target node receives the following SQL statement "select * from t where id =: X" (query id is X data), where X is a variable parameter of 478194789. The distributed database includes three database nodes, namely the first database node DB1, the second database node DB2 and the third database node DB3. The data numbered 1, 2 and 3 are stored in the first database node DB1, the data numbered 4, 5 and 6 are stored in the second database node DB2, and the data numbered 7, 8 and 9 are stored in the third database node DB3. In this way, in the plan generation stage, it can be seen that DB1 is hit once, DB2 is hit twice, and DB3 is hit 6 times. In this way, it can be determined that the first correlation score of DB1 is 1, the first correlation score of DB2 is 2, and the first correlation score of DB3 is 6. In the access result return stage, 3 results are returned in DB1, 2 results are returned in DB2, and 6 results are returned in DB3. In this way, it can be determined that the second relevance score of DB1 is 3, the second relevance score of DB2 is 2, and the second relevance score of DB3 is 6.
[0119] In some embodiments, calculating node relevance scores corresponding to a plurality of database nodes based on the first relevance score and the second relevance score includes:
[0120] Obtaining a first weight coefficient corresponding to the first correlation score, and obtaining a second weight coefficient corresponding to the second correlation score;
[0121] The first correlation score and the second correlation score are weightedly calculated based on the first weight coefficient and the second weight coefficient to obtain node correlation scores corresponding to the multiple database nodes.
[0122] Among them, after determining the first correlation score and the second correlation score corresponding to each database node, the first weight coefficient corresponding to the first correlation score can be further obtained, and the second weight coefficient corresponding to the second correlation score can be obtained. The first weight coefficient can be called a hit coefficient (Hit), and the second weight coefficient can be called a result coefficient (Tuple). By setting the first weight coefficient of the first correlation score and the second weight coefficient of the second correlation score, the importance of the active correlation score and the passive correlation score can be controlled in different business scenarios, thereby improving the accuracy of database node connection switching in different business scenarios.
[0123] Specifically, referring to the above example, it can be calculated that the node correlation score corresponding to DB1 is N1=Hit+3*Tuple; the node correlation score corresponding to DB2 is N2=2*Hit+2*Tuple; and the node correlation score corresponding to DB3 is N3=6*Hit+6*Tuple.
[0124] Step 330 : Obtain the node status parameters corresponding to each database node, and calculate the node stress score of each database node according to the node status parameters.
[0125] Among them, since the node correlation score indicates the correlation between each database node and the current data access business, in general, the higher the correlation of the database node, the higher the probability that the data stored therein is accessed by the data access request, and the amount of data corresponding to the data access request stored in the database node is also greater, then it stands to reason that the target terminal should establish a data connection with the database node with the highest correlation to improve the efficiency of data access. However, in some cases, the database node with the highest correlation may not be in a good state itself, for example, the memory usage of the database node is too high, the utilization rate of the central processing unit (CPU) is too high, etc. At this time, if the database node connected to the target terminal is forcibly switched to the node with the highest correlation, it may not only fail to improve the access efficiency of the database data, but may instead cause a decrease in the data access efficiency.
[0126] Therefore, in the disclosed embodiment, after calculating the node relevance score corresponding to each database node, the node state parameter corresponding to each database node can be further obtained, and then the node stress score of each database node can be calculated according to the node state parameter. The node stress score can characterize the current node state of the database node. Generally, the higher the node stress score, the worse the node state.
[0127] In some embodiments, obtaining a node status parameter corresponding to each database node, and calculating a node stress score of each database node according to the node status parameter, includes:
[0128] Obtaining the CPU usage rate, memory occupancy rate, data transmission rate, and input and output data volume of each database node in the first target period;
[0129] The node stress score of each database node is calculated based on the CPU usage, memory usage, data transfer rate, and input and output data volume.
[0130] In an embodiment of the present disclosure, a method for specifically calculating the node pressure of each data node is provided. Among them, in this embodiment, the node status parameters of the database node may specifically include the CPU usage rate, memory occupancy rate, data transmission rate, and input and output data volume. Among them, the CPU usage rate and memory occupancy rate characterize the occupancy of the data processing resources of the database node, that is, the remaining data processing capacity of the database. The data transmission rate characterizes the network status in the database node. If the network is more congested, the data transmission rate will be low; the input and output data volume can specifically refer to the disk IO (in&out). A large amount of input and output data also indicates that the data processing capacity of the database node is occupied.
[0131] After obtaining the CPU usage rate, memory occupancy rate, data transmission rate, and input and output data volume of each database node, the node stress score corresponding to each database node can be calculated based on the CPU usage rate, memory occupancy rate, data transmission rate, and input and output data volume. Among them, the node stress score can be directly proportional to the CPU usage rate, memory occupancy rate, and input and output data volume, and inversely proportional to the data transmission rate. The weight coefficient corresponding to each parameter can be set according to the positive and inverse proportional relationship. The above four parameters can be normalized first, and then the normalized values of the four parameters can be weighted according to the weight coefficients set above to obtain the node stress score corresponding to each database node.
[0132] Step 340: Determine a connection node switching instruction based on the node relevance score and the node pressure score.
[0133] After the node relevance score and the node pressure score of each database node are calculated, the connection node switching instruction can be determined according to the node relevance score and the node pressure score of each database node.
[0134] Specifically, the node switching score corresponding to each database node can be calculated based on the node relevance score and node pressure score of each database node, and the node switching score is the final score of each database node that can be used for node switching evaluation. Generally speaking, the higher the node switching score, the more reasonable it should be to establish a connection with the target terminal.
[0135] In some embodiments, the database node connection switching method provided by the present disclosure may also include:
[0136] Get the node switching cost parameter;
[0137] Determine the connection node switching instruction based on the node correlation score and the node pressure score, including:
[0138] The connection node switching instruction is determined based on the node relevance score, the node pressure score and the node switching cost parameter.
[0139] In the disclosed embodiment, after calculating the node relevance score and node pressure score of each database node, that is, calculating the scoring data of the node switching corresponding to each database node, the node switching cost parameter can be further obtained. It can be understood that the target terminal must pay a certain resource cost when switching the database node to which it is connected, and the cost can be a time cost and a data processing resource cost.
[0140] After further obtaining the node switching cost parameter, the node switching score of each database node can be comprehensively determined according to the node correlation score, the node pressure score and the node switching cost parameter. Finally, the connection node switching instruction is determined based on the comprehensively determined node switching score of each database node.
[0141] In some embodiments, determining a connection node switching instruction based on a node relevance score, a node pressure score, and a node switching cost parameter includes:
[0142] Obtaining a third weight coefficient corresponding to the node relevance score, a fourth weight coefficient corresponding to the node pressure score, and a fifth weight coefficient corresponding to the node switching cost parameter;
[0143] Performing weighted calculation on the node relevance score, the node pressure score, and the node switching cost parameter based on the third weight coefficient, the fourth weight coefficient, and the fifth weight coefficient to obtain a node switching score corresponding to each database node;
[0144] The connection node switching instruction is determined according to the node switching score.
[0145] In the disclosed embodiment, after calculating the node relevance score, node pressure score and node switching cost parameter of each database node, the third weight coefficient corresponding to the node relevance score, the fourth weight coefficient corresponding to the node pressure score and the fifth weight coefficient corresponding to the node switching cost parameter can be further obtained. Further, the node relevance score, node pressure score and node switching cost parameter can be weighted based on the third weight coefficient, the fourth weight coefficient and the fifth weight coefficient to obtain the node switching score corresponding to each database node. The formula is as follows:
[0146] D=a*N+b*P+c*C
[0147] Wherein, D is the node switching score of the database node, N is the node relevance score of the database node, P is the node pressure score of the database node, and C is the node switching cost parameter. a is the aforementioned third weight coefficient, b is the aforementioned fourth weight coefficient, and c is the aforementioned fifth weight coefficient. Wherein a is a positive number, and b and c are negative numbers.
[0148] Among them, weight coefficients are set for the node relevance score, node pressure score and node switching cost respectively, and the influence of the node relevance score, node pressure score and node switching cost on the final node switching score can be regulated in different database environment scenarios. For example, when there are a large number of database nodes in a distributed database and the performance of the distributed database nodes is good, the weight of the node relevance score can be set higher and the weight coefficient of the node pressure score can be set smaller, so that the accuracy of database node connection switching can be improved, and then the access efficiency of database data access can be improved.
[0149] In some embodiments, determining a connection node switching instruction according to a node switching score includes:
[0150] Determine a second target node with the highest node switching score among the multiple database nodes;
[0151] When the first target node and the second target node are different, a node switching instruction is generated according to the first target node and the second target node, and the node switching instruction indicates that the node connected to the distributed database is switched from the first target node to the second target node.
[0152] In the disclosed embodiment, after calculating the node switching score of each database node according to the node relevance score, node pressure score and node switching cost of each database node, the database node with the highest node switching score can be determined among multiple database nodes, which can be referred to as the second target node herein. Among them, the second target node and the first target node may be the same node. When the second target node and the first target node are the same node, there is no need to switch the database node connection; when the second target node and the first target node are different nodes, it is necessary to switch the first target node currently connected to the target terminal to connect to the second target node. That is, a node switching instruction can be generated to switch the connected node from the first target node to the second target node.
[0153] Step 350: Send a node switching instruction to the target terminal.
[0154] After the node switching instruction is generated, the node switching instruction may be sent to the target terminal. The node switching instruction may instruct the target terminal to switch the database node to which it is connected according to the node switching instruction.
[0155] When the node switching instruction is a node switching instruction for switching the connected node from the first target node to the second target node, the step of switching the database node for establishing the connection based on the node switching instruction includes:
[0156] disconnecting the target connection with the first target node;
[0157] A data connection is established with the second target node.
[0158] When the target terminal receives a node switching instruction to switch the connected node from the first target node to the second target node, it can disconnect the target connection with the first target node at an appropriate time and then establish a data connection with the second target node.
[0159] The appropriate time may be, for explicit transactions with begin and commit instructions, when a new transaction needs to be started after a transaction is completed; for some implicit transactions, the connection may be switched when a new SQL statement is executed.
[0160] In some embodiments, the database node connection switching method provided by the present disclosure further includes:
[0161] In a second target period after the target terminal executes the node switching instruction, a rationality analysis is performed on the node switching instruction to obtain an analysis result that the second target period has the same target duration as the first target period;
[0162] When the node switching instruction is determined to be reasonable based on the analysis result, the following steps are re-executed in the second target period: node relevance scores of multiple database nodes are calculated based on the data access requests sent by the target terminal to the distributed database in the current period and the corresponding data access results; node pressure scores of each database node are calculated according to the node status parameters of each database node; node switching instructions are determined based on the node relevance scores and the node pressure scores; and the node switching instructions are sent to the target terminal;
[0163] When it is determined based on the analysis result that the node switching instruction is unreasonable, the target duration is reduced.
[0164] Among them, since the node relevance score and node pressure score evaluated in the present disclosure are all post-scoring. That is, when calculating the node relevance score, it is evaluated based on the transactions that have occurred (such as the data requests that have been received and the data access results that have been generated). However, since the data access service of the target terminal may change, there may be a large difference between the data access service of the current cycle and the data access service of the next cycle. As a result, the node relevance score determined based on the current cycle may not necessarily indicate the correlation between the database node and the data access service of the next cycle. Similarly, the node status of the database node may also change, and the node pressure score calculated from the database node status data of the current cycle may not necessarily characterize the node pressure of the database node in the next cycle.
[0165] Taking into account the hysteresis of the node switching score, after the node switching is performed based on the node switching instruction determined by the node switching score, the node switching instruction determined according to the data of the previous cycle can be analyzed for rationality in the next cycle (the second target period). Specifically, the rationality analysis can be that in the second target period, whenever a data access request is received and a data access result corresponding to the data access request is generated, the node relevance score is calculated based on the data access requests and data access results received in the period; and the node pressure score is calculated, and then the node switching score is calculated based on the node relevance score and the node pressure score, to determine whether the currently connected node is the node with the highest node switching score. If so, the node switching instruction is determined to be reasonable.
[0166] If it is determined that the node switching instruction is reasonable, then it is determined that the data access request of the target terminal is relatively stable, that is, the data access service of the previous cycle is similar to the data access service of the current cycle. In this case, the node connection switching control can be periodically performed with the first target time period as the cycle length. Specifically, the above steps 310 to 350 can be repeated. If the node switching instruction is determined to be unreasonable, it may be that the cycle length of the node switching evaluation cycle (that is, the target length of the target time period) is set too large, and the data access service of the target terminal is difficult to maintain stability over a longer time span. In this way, the cycle length of the node switching evaluation cycle can be reduced, that is, the target length can be reduced, and the evaluation frequency of the node switching evaluation can be increased, so that the data access service of the target terminal can be kept stable within a smaller time span.
[0167] Among them, in some embodiments, when the database nodes of the distributed database change, such as the number of nodes increases or decreases, or the data stored in the database nodes migrates, detailed information of the database node changes needs to be sent to the driver of the target terminal so that the target terminal can accurately switch the database node connection.
[0168] The database node connection switching method provided by the embodiment of the present disclosure obtains data access requests received by the first target node via a target connection within a first target time period, and obtains data access results corresponding to the data access requests, wherein the first target node is a database node in a distributed database, and the data access requests access data in multiple database nodes of the distributed database; node correlation scores corresponding to multiple database nodes are calculated according to the data access requests and the data access results; node status parameters corresponding to each database node are obtained, and a node stress score of each database node is calculated according to the node status parameters; a connection node switching instruction is determined based on the node correlation score and the node stress score; and a node switching instruction is sent to a target terminal, so that the target terminal switches the database node for construction of the connection based on the node switching instruction, and the target terminal is a terminal connected to the target database node via the target connection.
[0169] The disclosed embodiment scores the relevance of the database nodes in the distributed database nodes to the current access business and scores the node pressure of each database node according to a certain time period. Then, a connection node switching instruction is generated according to the node relevance score and the node pressure score to guide the database client to switch the node connection, thereby ensuring that the database client is always connected to the optimal node, thereby improving the data access efficiency of the database.
[0170] The embodiments of the present disclosure are described in detail in combination with specific application scenarios.
[0171] like Figure 7 As shown, it is another flow chart of the database node connection switching method provided by the present disclosure. This embodiment will introduce the database node connection switching method in detail in combination with the execution subject of each step. The method specifically includes the following steps:
[0172] Step 701: During the operation of a target application, a terminal generates a data access request to a target distributed database.
[0173] Among them, in the embodiment of the present disclosure, the terminal is a terminal that can access the data in different database nodes in the target distributed database, and the terminal initiates access to the data in the target distributed data based on the target application installed thereon. The application data of the target application is stored in different database nodes of the target distributed database. The target distributed database can be composed of multiple independently deployed database nodes interconnected by a high-speed network, each database node stores a part of the data of the database cluster, and has a set of independent distributed optimizers and executors to be responsible for parsing the received SQL statements, generating and executing execution plans. In addition, the database node also has the ability to coordinate distributed transactions, that is, if the data access request received by one of the database nodes requires access to data that is not stored in the database node, the database node can access other database nodes to obtain the access result corresponding to the data access request.
[0174] During the operation of the target application, it may be necessary to access data in the target distributed database. In this case, the target application may generate a data access request to the target distributed database.
[0175] Step 702: The terminal driver analyzes the data access request and determines the first target database node that is most relevant to the data access request.
[0176] The terminal driver senses the distribution of data corresponding to the data access request in different database nodes, and then determines the first target database node that is most relevant to the data access request according to the distribution of data corresponding to the data access request in different database nodes.
[0177] When the data corresponding to the data access request is distributed relatively evenly in different database nodes, any one of the multiple database nodes of the target distributed database may be determined as the first target database node.
[0178] Step 703: The terminal driver establishes a first connection with the first target database node, and sends a data access request to the first target database node based on the first connection.
[0179] After determining the first target database node, the terminal driver can establish a first connection with the first target database node, and then send a data access request to the first target database node based on the first connection. In this way, compared with the use of a proxy module to coordinate data access requests in the related art, the one-hop transmission process of data access requests can be reduced, and the access efficiency to data in the target distributed database can be improved. Moreover, this solution only needs to establish a connection with one database node to access the data stored in all database nodes in the target distributed database. For example, if there are M terminals and the target distributed database has N nodes, only M connections need to be established. The number of data connections that need to be maintained can be greatly reduced.
[0180] Step 704: The first target database node accesses local data and data in other database nodes according to the received data access request to obtain a data access result.
[0181] When a first connection is established between the terminal driver and the first target database node, and a data access request is sent to the first target database node based on the first connection, the first target database node can access local data according to the received data access request, and the first target database node can access the data in other database nodes based on the distributed capability of the distributed database as required by the data access request. That is, the first target database node can access the data in other database nodes through the high-speed network between the first target database node and other database nodes.
[0182] Step 705 : The learning module of the first target database node calculates the node affinity of each database node according to the data access requests received in the first time period and the corresponding data access results.
[0183] In the disclosed embodiment, each database node in the target distributed database includes a learning module and a decision module, and the learning module and the decision module are used to learn and make decisions on node switching. The learning module and the decision module can work periodically according to a certain period of time.
[0184] Specifically, the learning module of the first target database node may calculate the node affinity of each database node according to the data access requests received in the first time period and the corresponding data access results.
[0185] Step 706 : The decision module of the first target database node obtains the node pressure of each database node in the first period, and calculates the node switching score of each database node based on the node affinity, the node pressure and the node switching cost.
[0186] After learning the node affinity of each database node in the first period, the learning module can send the node affinity to the decision module. The decision module calculates the node switching score of each database node according to the node affinity, node pressure and node switching cost.
[0187] Step 707: The decision module of the first target database node generates a node switching instruction according to the node switching score.
[0188] Then, the decision module of the first target database node determines the second target database node with the highest node switching score according to the node switching score. When the second target database node and the first target database node are the same database node, there is no need to switch the first target database node connected to the terminal; when the second target database node and the first target database node are different nodes, it is necessary to switch the database node connected to the terminal from the first target database node to the second target database node.
[0189] Step 708: The first target database node sends a node switching instruction to the terminal driver.
[0190] After the node switching instruction is determined, the first target database node can send the node switching instruction to the terminal driver to perform node connection switching.
[0191] Step 709: During the second period, the terminal driver switches the connected node from the first target database node to the second target database node according to the node switching instruction.
[0192] In a second period after the first period, after the terminal driver receives the node switching instruction sent by the first target database node, it can switch the connected node from the first target database node to the second target database node according to the node switching instruction.
[0193] like Figure 8As shown, it is a schematic diagram of data access by the database node connection switching method provided by the present application. As shown in the figure, after the terminal driver sends the data access request "select*fromt where id=:X", X=478194789 to the first target database node according to the first connection with the first target database node, the first target database node determines that the data of X=4 is stored locally, the data of X=1 is stored in database node 1, and the data of X=7, 8 or 9 is stored in database node 3. At this time, the first target database node splits the data access request into three sub-access requests: the first sub-access request "select*from t where id=:X", X=4; the second sub-access request "select*from twhere id=:X", X=7, 8 or 9; the third sub-access request "select*from t where id=:X", X=1. Then the first target database node accesses the local data based on the first sub-access request, the first target database node sends the second sub-access request to database node 3 to access the data therein, and the first target database node sends the third sub-access request to database node 2 to access the data therein.
[0194] The first target database node includes a learning module 810 and a decision module 820. The learning module 810 calculates the node affinity of each database node based on the data access request and the returned data access result. The specific calculation process has been introduced in the above embodiment and will not be repeated here. The decision module 820 calculates the node switching score of each database node based on the learned node affinity, the obtained node pressure score and the node switching cost. Then, a node switching decision is made based on the node switching score to obtain a node switching instruction.
[0195] like Fig. 9 , which is a schematic diagram of periodic node switching of the database node switching method provided by the present disclosure.
[0196] As shown in the figure, the current terminal is connected to DB2, data numbered 1, 2, and 3 are stored in DB1, data numbered 4, 5, and 6 are stored in DB2, and data numbered 7, 8, and 9 are stored in DB3. During the T1 period, read and write data are mainly concentrated on DB3, and the cluster pressure of different database nodes is the same, and the switching cost is stable. At this time, it can be determined that the switching plan is to switch the connection to DB3. During the T2 period, the business is relatively concentrated in DB1 but not significant enough, and considering that switching has a cost, while remaining unchanged does not require a cost, the comprehensive evaluation decision is to remain unchanged. During the T3 period, the business is relatively concentrated in DB1, but the cluster pressure score of DB1 is very high, so the comprehensive evaluation decision is to remain unchanged.
[0197] Description of the apparatus and device of the present disclosure
[0198] It is to be understood that, although the steps in the above-mentioned flowcharts are sequentially displayed according to the characterization of arrows, these steps are not necessarily executed in sequence according to the order of arrow characterization. Unless there is a clear description in the present embodiment, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the above-mentioned flowcharts can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the steps or stages in other steps.
[0199] It should be noted that in each specific embodiment of the present disclosure, when it comes to the need to perform relevant processing based on data related to the characteristics of the target object such as the target object attribute information or attribute information set, the permission or consent of the target object will be obtained first, and the collection, use and processing of these data will comply with the relevant laws, regulations and standards of the relevant region. In addition, when the embodiment of the present application needs to obtain the attribute information of the target object, the separate permission or separate consent of the target object will be obtained through a pop-up window or jump to a confirmation page. After clearly obtaining the separate permission or separate consent of the target object, the necessary target object-related data used to enable the normal operation of the embodiment of the present application will be obtained.
[0200] Fig.10 This is a schematic diagram of the structure of a database node connection switching device 1000 provided in an embodiment of the present disclosure. The device includes:
[0201] A first acquisition unit 1010 is used to acquire a data access request received by a first target node via a target connection within a first target period, and to acquire a data access result corresponding to the data access request, wherein the first target node is a database node in a distributed database, and the data access request accesses data in multiple database nodes of the distributed database;
[0202] A calculation unit 1020, configured to calculate node correlation scores corresponding to multiple database nodes according to the data access request and the data access result;
[0203] The second acquisition unit 1030 is used to acquire the node state parameters corresponding to each database node, and calculate the node stress score of each database node according to the node state parameters;
[0204] A determination unit 1040, configured to determine a connection node switching instruction based on the node correlation score and the node pressure score;
[0205] The sending unit 1050 is used to send a node switching instruction to a target terminal, so that the target terminal switches the database node for establishing a connection based on the node switching instruction. The target terminal is a terminal connected to the target database node via a target connection.
[0206] Optionally, in some embodiments, the computing unit includes:
[0207] A parsing subunit, used to parse the data access request and generate a data access plan based on the parsing result;
[0208] A first determination subunit, configured to determine, based on the data access plan, a first correlation score between a data access service that initiates a data access request and a plurality of database nodes;
[0209] A second determination subunit, configured to determine a second correlation score between the data access service and the plurality of database nodes according to the data access result;
[0210] The first calculation subunit is used to calculate node correlation scores corresponding to multiple database nodes based on the first correlation score and the second correlation score.
[0211] Optionally, in some embodiments, the first determining subunit includes:
[0212] A first determination module is used to determine the number of hit accesses of each database node among the multiple database nodes according to the data access plan;
[0213] The second determination module is used to determine a first correlation score between a data access service of a data access request and a plurality of database nodes according to the number of accesses.
[0214] Optionally, in some embodiments, the second determining subunit includes:
[0215] A third determination module, configured to determine the number of access results returned by each database node for the data access request based on the data access result;
[0216] The fourth determination module is used to determine a second correlation score between the data access service of the data access request and the multiple database nodes according to the number of access results.
[0217] Optionally, in some embodiments, the first computing subunit includes:
[0218] An acquisition module, used to acquire a first weight coefficient corresponding to the first correlation score, and acquire a second weight coefficient corresponding to the second correlation score;
[0219] The calculation module is used to perform weighted calculation on the first correlation score and the second correlation score based on the first weight coefficient and the second weight coefficient to obtain node correlation scores corresponding to multiple database nodes.
[0220] Optionally, in some embodiments, the database node connection switching device provided by the present disclosure further includes:
[0221] A first acquisition subunit, used to acquire a node switching cost parameter;
[0222] Determines the unit, also used for:
[0223] The connection node switching instruction is determined based on the node relevance score, the node pressure score and the node switching cost parameter.
[0224] Optionally, in some embodiments, the determining unit includes:
[0225] A second acquisition subunit is used to acquire a third weight coefficient corresponding to the node relevance score, a fourth weight coefficient corresponding to the node pressure score, and a fifth weight coefficient corresponding to the node switching cost parameter;
[0226] A second calculation subunit is used to perform weighted calculation on the node correlation score, the node pressure score and the node switching cost parameter based on the third weight coefficient, the fourth weight coefficient and the fifth weight coefficient to obtain a node switching score corresponding to each database node;
[0227] The third determining subunit is used to determine the connection node switching instruction according to the node switching score.
[0228] Optionally, in some embodiments, the third determining subunit includes:
[0229] A fifth determination module, configured to determine a second target node with the highest node switching score among multiple database nodes;
[0230] A generation module is used to generate a node switching instruction according to the first target node and the second target node when the first target node is different from the second target node, and the node switching instruction indicates that the node connected to the distributed database is switched from the first target node to the second target node.
[0231] Optionally, in some embodiments, the database node connection switching device provided by the present disclosure further includes a construction subunit, and the construction subunit includes:
[0232] A disconnection module, used for disconnecting a target connection with a first target node;
[0233] The establishing module is used to establish a data connection with the second target node.
[0234] Optionally, in some embodiments, the second acquisition unit includes:
[0235] A third acquisition subunit is used to acquire the CPU usage rate, memory occupancy rate, data transmission rate and input and output data volume of each database node in the first target period;
[0236] The third calculation subunit is used to calculate the node stress score of each database node according to the CPU usage rate, memory occupancy rate, data transmission rate and input and output data volume.
[0237] Optionally, in some embodiments, the database node switching device provided by the present disclosure further includes:
[0238] An analysis subunit, configured to perform a rationality analysis on the node switching instruction within a second target period after the target terminal executes the node switching instruction, and obtain an analysis result that the second target period has the same target duration as the first target period;
[0239] The execution subunit is used to re-execute the following steps within the second target period when it is determined based on the analysis result that the node switching instruction is reasonable: calculating the node relevance scores of multiple database nodes based on the data access requests sent by the target terminal to the distributed database within the current period and the corresponding data access results; calculating the node pressure score of each database node according to the node state parameter of each database node; determining the node switching instruction based on the node relevance score and the node pressure score; and sending the node switching instruction to the target terminal;
[0240] The reduction subunit is used to reduce the target duration when it is determined based on the analysis result that the node switching instruction is unreasonable.
[0241] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0242] Reference Fig.11 , Fig.11The structural block diagram of the terminal 140 for implementing the database node connection switching or database node connection switching method of the embodiment of the present disclosure is as follows: the terminal 140 includes: a radio frequency (RF) circuit 1410, a memory 1115, an input unit 1130, a display unit 1140, a sensor 1150, an audio circuit 1160, a wireless fidelity (WiFi) module 1170, a processor 1180, and a power supply 1190. Those skilled in the art can understand that Fig.11 The structure of the terminal 140 shown does not constitute a limitation on a mobile phone or a computer, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0243] The RF circuit 1110 may be used for receiving and sending signals during information transmission or communication. In particular, after receiving downlink information from the base station, the information is sent to the processor 1180 for processing. In addition, the uplink data is sent to the base station.
[0244] The memory 1115 may be used to store software programs and modules. The processor 1180 executes various functional applications and document editing of the terminal by running the software programs and modules stored in the memory 1115 .
[0245] The input unit 1130 may be used to receive input digital or character information and generate key signal input related to the terminal's settings and function control. Specifically, the input unit 1130 may include a touch panel 1131 and other input devices 1132 .
[0246] The display unit 1140 may be used to display input information or provided information and various menus of the terminal. The display unit 1140 may include a display panel 1141 .
[0247] The audio circuit 1160 , the speaker 1161 , and the microphone 1162 may provide an audio interface.
[0248] In this embodiment, the processor 1180 included in the terminal 140 can execute the database node connection switching or database node connection switching method of the previous embodiment.
[0249] The terminal 140 of the embodiment of the present disclosure includes but is not limited to a mobile phone, a computer, an intelligent voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, etc.
[0250] Fig.12A block diagram of a portion of a server 110 for implementing a database node connection switch or a database node connection switch method according to an embodiment of the present disclosure. The server 110 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPUs) 1222 (e.g., one or more processors) and a storage device 1232, and one or more storage media 1230 (e.g., one or more mass storage devices) storing application programs 1242 or data 1244. Among them, the storage device 1232 and the storage medium 1230 may be temporary storage or permanent storage. The program stored in the storage medium 1230 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server 110. Furthermore, the central processing unit 1222 may be configured to communicate with the storage medium 1230 to execute a series of instruction operations in the storage medium 1230 on the server 110.
[0251] The server 110 may also include one or more power supplies 1226, one or more wired or wireless network interfaces 1250, one or more input and output interfaces 1258, and / or one or more operating systems 1241, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0252] The central processor 1222 in the server 110 may be used to execute the database node connection switching or the database node connection switching method according to the embodiment of the present disclosure.
[0253] The embodiments of the present disclosure further provide a storage medium, the storage medium is used to store program code, and the program code is used to execute the database node connection switching or database node connection switching method of each of the aforementioned embodiments.
[0254] The embodiment of the present disclosure also provides a computer program product, which includes a computer program. A processor of a computer device reads and executes the computer program, so that the computer device implements the above-mentioned database node connection switching or database node connection switching method.
[0255] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present disclosure described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "comprises" and "comprising" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0256] It should be understood that in the present disclosure, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0257] It should be understood that in the description of the embodiments of the present disclosure, the meaning of multiple (or multiple items) is more than two, greater than, less than, exceed, etc. are understood to not include the number, and above, below, within, etc. are understood to include the number.
[0258] In the several embodiments provided in the present disclosure, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0259] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0260] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0261] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present disclosure is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store program codes.
[0262] It should also be understood that the various implementations provided in the embodiments of the present disclosure can be combined arbitrarily to achieve different technical effects.
[0263] The above is a specific description of the implementation methods of the present disclosure, but the present disclosure is not limited to the above implementation methods. Technical personnel familiar with the art can also make various equivalent modifications or substitutions without violating the spirit of the present disclosure. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present disclosure.
Claims
1. A database node connection switching method, characterized in that: The method comprises: Obtaining a data access request received by a first target node via a target connection within a first target period, and obtaining a data access result corresponding to the data access request, wherein the first target node is a database node in a distributed database, and the data access request accesses data in multiple database nodes of the distributed database; Calculate node relevance scores corresponding to the multiple database nodes according to the data access request and the data access result; Obtaining node status parameters corresponding to each database node, and calculating a node stress score of each database node according to the node status parameters; Determining a connection node switching instruction based on the node relevance score and the node pressure score; The node switching instruction is sent to a target terminal, so that the target terminal switches the database node for establishing a connection based on the node switching instruction. The target terminal is a terminal connected to the target database node via the target connection.
2. The method according to claim 1, characterized in that The calculating the node relevance scores corresponding to the plurality of database nodes according to the data access request and the data access result includes: Parsing the data access request and generating a data access plan based on the parsing result; Determine, based on the data access plan, a first correlation score between the data access service initiating the data access request and a plurality of database nodes; Determine a second correlation score between the data access service and the plurality of database nodes according to the data access result; Node relevance scores corresponding to the plurality of database nodes are calculated based on the first relevance score and the second relevance score.
3. The method according to claim 2, characterized in that The determining, based on the data access plan, a first correlation score between the data access service initiating the data access request and the plurality of database nodes comprises: Determine the number of times each database node in the plurality of database nodes is hit according to the data access plan; A first correlation score between the data access service of the data access request and a plurality of database nodes is determined according to the access count.
4. The method according to claim 2, characterized in that: The determining, according to the data access result, a second correlation score between the data access service and the plurality of database nodes comprises: Determine the number of access results returned by each database node for the data access request based on the data access result; A second correlation score between the data access service of the data access request and the plurality of database nodes is determined according to the number of the access results.
5. The method according to claim 2, characterized in that: The calculating the node relevance scores corresponding to the plurality of database nodes based on the first relevance score and the second relevance score comprises: Obtaining a first weight coefficient corresponding to the first correlation score, and obtaining a second weight coefficient corresponding to the second correlation score; The first correlation score and the second correlation score are weightedly calculated based on the first weight coefficient and the second weight coefficient to obtain node correlation scores corresponding to the multiple database nodes.
6. The method according to claim 1, characterized in that The method further comprises: Get the node switching cost parameter; The determining of the connection node switching instruction based on the node correlation score and the node pressure score includes: A connection node switching instruction is determined based on the node relevance score, the node pressure score, and the node switching cost parameter.
7. The method according to claim 6, characterized in that The determining of the connection node switching instruction based on the node correlation score, the node pressure score and the node switching cost parameter includes: Obtaining a third weight coefficient corresponding to the node relevance score, a fourth weight coefficient corresponding to the node pressure score, and a fifth weight coefficient corresponding to the node switching cost parameter; Performing weighted calculation on the node relevance score, the node pressure score, and the node switching cost parameter based on the third weight coefficient, the fourth weight coefficient, and the fifth weight coefficient to obtain a node switching score corresponding to each of the database nodes; A connection node switching instruction is determined according to the node switching score.
8. The method according to claim 7, characterized in that The determining of the connection node switching instruction according to the node switching score comprises: Determine a second target node with the highest node switching score among the multiple database nodes; When the first target node is different from the second target node, a node switching instruction is generated according to the first target node and the second target node, and the node switching instruction indicates to switch the node connected to the distributed database from the first target node to the second target node.
9. The method according to claim 8, characterized in that The step of switching the database node for establishing the connection based on the node switching instruction comprises: disconnecting the target connection with the first target node; A data connection is established with the second target node.
10. The method according to claim 1, characterized in that The obtaining of the node status parameters corresponding to each database node and calculating the node stress score of each database node according to the node status parameters includes: Obtaining the CPU usage rate, memory occupancy rate, data transmission rate, and input and output data volume of each database node during the first target period; The node stress score of each database node is calculated according to the CPU usage, memory occupancy, data transmission rate, and input and output data volume.
11. The method according to claim 1, characterized in that: The method further comprises: within a second target time period after the target terminal executes the node switching instruction, performing a rationality analysis on the node switching instruction to obtain an analysis result, wherein the second target time period has the same target duration as the first target time period; When it is determined based on the analysis result that the node switching instruction is reasonable, the following steps are re-executed within the second target time period: node relevance scores of multiple database nodes are calculated based on the data access requests sent by the target terminal to the distributed database within the current time period and the corresponding data access results; a node pressure score of each database node is calculated based on the node status parameters of each database node; a node switching instruction is determined based on the node relevance score and the node pressure score; and the node switching instruction is sent to the target terminal; When it is determined based on the analysis result that the node switching instruction is unreasonable, the target duration is reduced.
12. A database node connection switching device, characterized in that: The device comprises: A first acquisition unit is used to acquire a data access request received by a first target node via a target connection within a first target period, and to acquire a data access result corresponding to the data access request, wherein the first target node is a database node in a distributed database, and the data access request accesses data in multiple database nodes of the distributed database; A calculation unit, configured to calculate node relevance scores corresponding to the plurality of database nodes according to the data access request and the data access result; A second acquisition unit is used to acquire a node state parameter corresponding to each database node, and calculate a node stress score of each database node according to the node state parameter; a determining unit, configured to determine a connection node switching instruction based on the node correlation score and the node pressure score; The sending unit is used to send the node switching instruction to the target terminal, so that the target terminal switches the database node for establishing the connection based on the node switching instruction. The target terminal is a terminal connected to the target database node via the target connection.
13. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the database node connection switching method according to any one of claims 1 to 11 is implemented.
14. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the database node connection switching method according to any one of claims 1 to 11 is implemented.
15. A computer program product, comprising a computer program, wherein the computer program is read and executed by a processor of a computer device, so that the computer device executes the database node connection switching method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Method and device for generating upstream and downstream receipts based on message, and storage medium
CN115358643A
Data sub-library method and device, equipment, storage medium and program product
CN115599860A