Database instance connection method and device based on Hash ring, equipment and medium

Through the hash ring-based database instance connection method, the performance degradation and resource waste caused by the interruption of connection between user equipment and database resources in high concurrency scenarios, and the improvement of system performance and stability is achieved.

CN119829616APending Publication Date: 2025-04-15CHINA TELECOM CLOUD TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411756177.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-02
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

In the high concurrency scenario of the database, when the user equipment and the database resource connection are interrupted and the connection is established again, the system performance is degraded and the computing resources are wasted.

Method used

The hash ring-based database instance connection method is adopted. By mapping the identity of the database instance into a hash value and establishing a hash ring structure, finding the corresponding hash value for the reconnection request, thereby establishing a connection between the user equipment and the target database instance.

Benefits of technology

This avoids the user equipment automatically establishing connections with database resources with smaller loads, improves system performance and stability, and reduces the waste of computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829616A_ABST
    Figure CN119829616A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of databases, and discloses a database instance connection method and device based on a hash ring, equipment and a medium, the method comprises the following steps: for each database instance in a plurality of database instances, mapping an identifier of the database instance into a hash value corresponding to the database instance, establishing a hash ring structure comprising hash values corresponding to a plurality of database instances; and when a reconnection request of a user is received from the user equipment, mapping an identifier corresponding to the reconnection request into a first hash value, searching a second hash value corresponding to the first hash value from the hash ring structure, and establishing connection between the user equipment and the target database instance corresponding to the second hash value. According to the embodiment of the invention, the user equipment can be reconnected with the target database instance in the state established last time, the performance and the stability of the system are improved, resources do not need to be consumed again to establish connection, and the waste of computing resources is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a database instance connection method, device, equipment and medium based on a hash ring. Background Art

[0002] With the popularization of the Internet, a large number of convenient applications have been born, which in turn generate a large amount of data, the status and information of which are stored in the database. However, a single database node can no longer meet the exponentially growing data storage needs. At this time, it is necessary to build a database cluster and backup to cope with high concurrency scenarios.

[0003] In the high-concurrency scenario of the database, different users have different performance requirements for the server. In the related technology, users with high concurrency requirements are tagged, and their experience of accessing the database is prioritized through technologies such as load balancing, and disaster recovery and backup strategies are used to ensure the high availability of the system. However, due to external problems such as the network, the connection between the user device and the database resources may be interrupted. When the connection needs to be established again, this method has some limitations: First, the user device will automatically establish a connection with the database resources with a smaller load, which will lead to problems such as increased system load, slower response, and service crashes. Second, the user device needs to consume resources again to establish a connection, resulting in a waste of computing resources. Summary of the invention

[0004] In view of this, the present invention provides a database instance connection method based on a hash ring to solve the problem of system performance degradation and computing resource waste caused by re-establishing a connection between a user device and a database resource after the connection is interrupted in the related art.

[0005] In a first aspect, the present invention provides a database instance connection method based on a hash ring, the method comprising:

[0006] For each database instance in the plurality of database instances, mapping an identifier of the database instance into a hash value corresponding to the database instance, and establishing a hash ring structure including the hash values ​​corresponding to the plurality of database instances;

[0007] When a user's reconnection request is received from a user device, an identifier corresponding to the reconnection request is mapped to a first hash value, a second hash value corresponding to the first hash value is found from the hash ring structure, and a connection between the user device and a target database instance corresponding to the second hash value is established; wherein the reconnection request is sent because the user device requests to connect to the target database instance again due to a connection interruption between the user device and the target database instance.

[0008] In an optional implementation, searching for a second hash value corresponding to the first hash value from the hash ring structure includes:

[0009] Taking the mapping position of the first hash value in the hash ring structure as the starting point, searching for the second hash value along the clockwise or counterclockwise direction of the hash ring structure; the second hash value is the first hash value of the first hash value along the clockwise or counterclockwise direction of the hash ring structure.

[0010] In an optional implementation, after establishing a hash ring structure including hash values ​​corresponding to multiple database instances, the method further includes:

[0011] According to the number of disconnections between the user device and the target database instance and the average time interval for sending reconnection requests, users are divided into hotspot users, secondary hotspot users and ordinary users;

[0012] Corresponding classification labels are assigned to hot users and secondary hot users.

[0013] In an optional implementation, before mapping the identifier of the database instance to a hash value corresponding to the database instance, the method includes:

[0014] Establish multiple database clusters; each database cluster includes multiple databases; each database corresponds to at least one database instance;

[0015] Based on the performance of each database cluster, multiple database clusters are divided into ultra-high performance group, high performance group, and general performance group;

[0016] For the database instance corresponding to each database in the ultra-high performance group, assign a classification label to the hotspot user;

[0017] For the database instance corresponding to each database in the high-performance group, a classification label of the secondary hotspot user is assigned.

[0018] In an optional implementation, searching for a second hash value corresponding to the first hash value from the hash ring structure includes:

[0019] Taking the mapping position of the first hash value in the hash ring structure as the starting point, search for the second hash value along the clockwise or counterclockwise direction of the hash ring structure; the second hash value is the hash value corresponding to the first database instance along the clockwise or counterclockwise direction of the hash ring structure that is equal to the classification label of the user corresponding to the first hash value.

[0020] In an optional embodiment, the number of hash values ​​of the database instances corresponding to the target database in the ultra-high performance group in the hash ring structure is greater than the number of hash values ​​corresponding to other database instances in the hash ring structure; the other database instances are database instances corresponding to databases in the high performance group or the general performance group.

[0021] In an optional implementation, the step of establishing a hash ring structure including hash values ​​corresponding to multiple database instances includes:

[0022] Sort the hash values ​​corresponding to multiple database instances in ascending or descending order, connect them end to end, and form a logical hash ring structure.

[0023] In a second aspect, the present invention provides a database instance connection device based on a hash ring, the device comprising:

[0024] A hash ring construction module, used for mapping, for each database instance in a plurality of database instances, an identifier of the database instance into a hash value corresponding to the database instance, and establishing a hash ring structure including hash values ​​corresponding to the plurality of database instances;

[0025] A database instance connection module is used to map the identifier corresponding to the reconnection request to a first hash value when receiving a user's reconnection request from a user device, find out the second hash value corresponding to the first hash value from the hash ring structure, and establish a connection between the user device and the target database instance corresponding to the second hash value; wherein the reconnection request is sent because the user device requests to connect to the target database instance again due to the interruption of the connection between the user device and the target database instance.

[0026] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0027] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to cause a computer to execute the method of the first aspect or any corresponding embodiment thereof.

[0028] The embodiment of the present invention first establishes a hash ring structure composed of hash values ​​corresponding to database instances, determines the position of each database instance in the hash ring structure; then calculates the first hash value corresponding to the reconnection request sent by the user device, and finds the target database instance with which the status is established through the position of the first hash value in the hash ring structure. According to the unique identifier in the reconnection request sent by the user device, the position before the interruption is located in the hash ring structure, and the target database instance with which the status was established last time is found, which can avoid the user device from automatically establishing a connection with a database resource with a smaller load, improves the performance and stability of the system, and does not need to re-consume resources to establish a connection, reducing the waste of computing resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0030] Figure 1 It is a flowchart of a database instance connection method based on a hash ring according to an embodiment of the present invention;

[0031] Figure 2 is a hash circle addressing rule diagram of a common user according to an embodiment of the present invention;

[0032] Figure 3 is a hash circle addressing rule diagram of a secondary hotspot user according to an embodiment of the present invention;

[0033] Figure 4 is a hash circle structure diagram with virtual nodes according to an embodiment of the present invention;

[0034] Figure 5 is a hash circle structure diagram of a newly added database instance according to an embodiment of the present invention;

[0035] Figure 6 is a structural block diagram of a database instance connection device based on a hash ring according to an embodiment of the present invention;

[0036] Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0038] With the popularization of the Internet, a large number of convenient applications have been born, which in turn generate a large amount of data, the status and information of which are stored in the database. However, a single database node can no longer meet the exponentially growing data storage needs. At this time, it is necessary to build a database cluster and backup to cope with high concurrency scenarios.

[0039] In a high-concurrency database scenario, different users have different performance requirements for the server. For example, in an online shopping scenario, the DML (Data Manipulation Language) operations of the data of users and merchants participating in the flash sale may be relatively frequent, and the performance requirements for the database are relatively high; while the DQL (Data Query Language) operations of the data of users and merchants not participating in the flash sale are relatively frequent, and the performance requirements for the database are relatively low.

[0040] DML refers to statements for operating databases, with INSERT, UPDATE, and DELETE as the core, representing insert, update, and delete respectively. DQL is responsible for querying data without modifying the data itself, and the reserved word SELECT is often used.

[0041] In related technologies, users with high concurrency requirements are tagged, and their experience of accessing the database is prioritized through technologies such as load balancing, and disaster recovery and backup strategies are used to ensure high availability of the system. However, due to external problems such as the network, the connection between the user device and the database resources may be interrupted. When the connection needs to be established again, this method has some limitations: First, the user device will automatically establish a connection with the database resources with a smaller load, which will lead to problems such as increased system load, slower response, and service crashes. Second, the user device needs to consume resources to establish a connection again, resulting in a waste of computing resources.

[0042] In view of this, the present invention provides a database instance connection method based on a hash ring, establishing a hash ring structure composed of hash values ​​corresponding to the database instances, referred to as a hash circle, and calculating the hash value corresponding to the user device to ensure that the user device can re-establish a connection with the same database instance as the last connection, that is, state preservation or state reuse, thereby improving the overall performance and stability of the system, and eliminating the need to re-consume resources to establish a connection, thereby reducing the waste of computing resources.

[0043] According to an embodiment of the present invention, a database instance connection method embodiment based on a hash ring is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0044] Figure 1 is a flowchart of a database instance connection method based on a hash ring according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0045] Step S101 : for each database instance among a plurality of database instances, mapping the identifier of the database instance into a hash value corresponding to the database instance, and establishing a hash ring structure including the hash values ​​corresponding to the plurality of database instances.

[0046] The database instance and the database can be in a one-to-one correspondence, that is, one database corresponds to one instance, or one database can correspond to multiple database instances to achieve parallel processing and load balancing. The database instance is a channel for accessing the database. When the user device establishes a connection with the database instance, that is, after the state is established, the user device can insert, update, delete, and query the data in the database through the database instance.

[0047] In step S101, the identifier of the database instance may be the IP or domain name corresponding to the database instance. According to the identifier of the database instance, it may be mapped into a corresponding hash value, i.e., a hash value. The hash value is a value between 0 and 2. 32 A numeric value of -1.

[0048] Then, a virtual hash ring structure, namely a hash circle, is established according to multiple hash values ​​mapped from the identifiers of multiple database instances.

[0049] Step S102, when a user's reconnection request is received from a user device, an identifier corresponding to the reconnection request is mapped to a first hash value, a second hash value corresponding to the first hash value is found from a hash ring structure, and a connection between the user device and a target database instance corresponding to the second hash value is established; wherein the reconnection request is sent because the connection between the user device and the target database instance is interrupted and the user device requests to connect to the target database instance again.

[0050] In step S102, according to the ID in the reconnection request sent by the user equipment, it can also be mapped into a corresponding 0 to 2 32 -1, that is, the first hash value. At this time, according to the position of the first hash value mapped in the hash ring structure, the second hash value corresponding to the target database instance with which the user device establishes a connection is found.

[0051] Among them, the process of finding the second hash value corresponding to the target database instance to which the user device establishes a connection according to the position of the first hash value mapping in the hash ring structure can also be called hash addressing.

[0052] It should be noted that no matter how many times the user device initiates a request, as long as the user device remains unchanged, its corresponding ID is determined, and the calculation method of the hash value is also determined. Therefore, the hash value corresponding to the user device is unique. At this time, when the user device sends a request to reconnect, it will eventually fall into the same position in the hash ring structure, that is, it will reconnect with the database instance that established the state last time. Therefore, the target database instance corresponding to the second hash value is the same as the database instance before the interruption, which can be called state reuse or state retention. The hash value calculation method is used to map a piece of text or string into a 0 to 2 32 The process of getting a hash value of -1 is also called hash consistency.

[0053] The embodiment of the present invention first establishes a hash ring structure composed of hash values ​​corresponding to database instances, determines the position of each database instance in the hash ring structure; then calculates the first hash value corresponding to the reconnection request sent by the user device, and finds the target database instance with which the status is established through the position of the first hash value in the hash ring structure. According to the unique identifier in the reconnection request sent by the user device, the position before the interruption is located in the hash ring structure, and the target database instance with which the status was established last time is found, which can avoid the user device from automatically establishing a connection with a database resource with a smaller load, improves the performance and stability of the system, and does not need to re-consume resources to establish a connection, reducing the waste of computing resources.

[0054] In some optional implementations, searching for a second hash value corresponding to the first hash value from the hash ring structure includes:

[0055] Taking the mapping position of the first hash value in the hash ring structure as the starting point, searching for the second hash value along the clockwise or counterclockwise direction of the hash ring structure; the second hash value is the first hash value along the clockwise or counterclockwise direction of the hash ring structure.

[0056] In some optional implementations, after establishing a hash ring structure including hash values ​​corresponding to multiple database instances, the database instance connection method based on the hash ring further includes:

[0057] According to the number of disconnections between the user device and the target database instance and the average time interval for sending reconnection requests, users are divided into hotspot users, secondary hotspot users and ordinary users;

[0058] Corresponding classification labels are assigned to hot users and secondary hot users.

[0059] Among them, the screening of hotspot users and secondary hotspot users can be manual screening or system screening. Taking system screening as an example, users are classified according to the number of interruptions in the connection status between the user device and the corresponding database instance monitored by the system and the average time interval for sending reconnection requests, and hotspot users and secondary hotspot users are marked with classification labels. The classification label level of secondary hotspot users is lower than the classification label level of hotspot users.

[0060] In some optional implementations, before mapping the identifier of the database instance to a hash value corresponding to the database instance, the database instance connection method based on the hash ring further includes:

[0061] Establish multiple database clusters; each database cluster includes multiple databases; each database corresponds to at least one database instance;

[0062] Based on the performance of each database cluster, multiple database clusters are divided into ultra-high performance group, high performance group, and general performance group;

[0063] For the database instance corresponding to each database in the ultra-high performance group, assign a classification label to the hotspot user;

[0064] For the database instance corresponding to each database in the high-performance group, a classification label of the secondary hotspot user is assigned.

[0065] Specifically, the classification label level corresponds to the grouping of database resources. The user with more interruptions and shorter average time interval for sending reconnection requests has a higher hotspot label level, indicating that more resources are needed to establish a status with the database. By assigning the same classification label to the ultra-high performance group and hotspot users, hotspot users can preferentially establish a connection with the database instance in the ultra-high performance group when searching for the corresponding database instance in the hash ring structure; similarly, by assigning the same classification label to the high performance group and the secondary hotspot users, secondary hotspot users can preferentially establish a connection with the database instance in the high performance group, ensuring the reasonable allocation of database resources, especially in the high concurrency scenario of the database, meeting the different performance requirements of different users for the server.

[0066] The database resources may correspond to multiple database clusters, each of which includes multiple databases, and each database corresponds to at least one database instance.

[0067] It should be noted that these database clusters can be divided into three types of database resources according to performance, namely, ultra-high performance group, high performance group and general performance group. Each group of resources is one or more database clusters. Cluster resources within a group focus on the CP characteristics in the CAP theory to ensure the consistency of data within the group. Cluster resources between groups focus on the AP characteristics in the CAP theory, allowing data inconsistency for a very short time, but ensuring availability.

[0068] Among them, the CAP theory indicates that it is impossible to meet three basic requirements at the same time in a distributed system. The three basic requirements include: consistency (Consistency), availability (Availability), and partition tolerance (PartitionTolerance). At most two can be met at the same time. AP (Availability + Partition Tolerance): refers to giving up strong consistency and achieving final consistency. CP (Consistency + Partition Tolerance: refers to giving up high availability and achieving strong consistency.

[0069] In some optional implementations, searching for a second hash value corresponding to the first hash value from the hash ring structure includes:

[0070] Take the mapping position of the first hash value in the hash ring structure as the starting point, and search for the second hash value along the clockwise or counterclockwise direction of the hash ring structure; the second hash value is the hash value corresponding to the first database instance along the clockwise or counterclockwise direction of the hash ring structure that is equal to the classification label of the user corresponding to the first hash value.

[0071] Specifically, as mentioned above, the hotspot tag level corresponds to the database resource grouping. When a user and a corresponding database resource are tagged with the same classification tag, when the first hash value searches for the second hash value in the hash ring structure, the hash value corresponding to the database resource with the same tag will be established first.

[0072] As an example, Figure 2 As shown in the figure, user 1, user 2 and user 3 are all ordinary users, and the hash circle addressing direction is counterclockwise. For the hash circle addressing of ordinary users, first calculate the first hash value corresponding to the ID in the connection request sent by user 1, user 2 and user 3, which are hash 1 、hash 2 and hash 3 , and then according to the starting position of the first hash value in the hash ring structure, that is Figure 2 For the current positions of the three users shown, the first hash value encountered counterclockwise along the hash ring structure is the second hash value corresponding to the target database instance connected to the ordinary user. That is, user 1 and user 2 both establish a status with the target database instance in high-performance group 2, and user 3 establishes a status with the target database instance in high-performance group 1.

[0073] As an example, Figure 3 As shown in the figure, user 2 and user 3 are ordinary users, user 1 is a secondary hotspot user, and the hash circle addressing direction is counterclockwise. For the hash circle addressing of secondary hotspot user 1, first calculate the first hash value hash corresponding to the ID in the connection request sent by secondary hotspot user 1 1 , and then according to the starting position of the first hash value in the hash ring structure, that is Figure 2 At the current position of the secondary hotspot user 1 shown in the figure, the first hash value encountered counterclockwise along the hash ring structure and having the same classification label as the secondary hotspot user 1 is the second hash value corresponding to the target database instance to establish a connection with the secondary hotspot user 1. In other words, the secondary hotspot user 1 will skip the general performance group 1 and establish a connection with the first database instance with the same classification label encountered, that is, the database instance in the ultra-high performance group 1.

[0074] As an example, for a hotspot user, according to the ID in the connection request sent by the hotspot user, the first hash value corresponds to the first hash value, and according to the starting position of the first hash value in the hash ring structure, the first hash value encountered clockwise or counterclockwise along the hash ring structure and the same as the classification label of the hotspot user is the second hash value corresponding to the target database instance connected to the hotspot user. The target database instance connected to the hotspot user is the target database instance corresponding to the target database in the ultra-high performance group.

[0075] In some optional embodiments, the number of hash values ​​corresponding to the database instances of the target database in the ultra-high performance group in the hash ring structure is greater than the number of hash values ​​corresponding to other database instances in the hash ring structure; the other database instances are database instances corresponding to databases in the high performance group or the general performance group.

[0076] Among them, a target database in the ultra-high performance group may correspond to multiple database instances, and the identifiers of multiple database instances corresponding to the same target database may be mapped into multiple hash values, thus forming a hash circle including multiple virtual ultra-high performance group nodes, such as Figure 4 As shown, it is suitable for scenarios where the resource utilization of ultra-high performance groups needs to be improved. The embodiment of the present invention uses virtual nodes to increase the proportion of ultra-high performance group resources in the hash circle, increase the connection request rate of the ultra-high performance group, and thus improve the resource utilization of the ultra-high performance group.

[0077] In some optional implementations, establishing a hash ring structure including hash values ​​corresponding to multiple database instances includes:

[0078] Sort the hash values ​​corresponding to multiple database instances in ascending or descending order, connect them end to end, and form a logical hash ring structure.

[0079] The hash ring structure of the embodiment of the present invention is sorted in ascending or descending order of hash values. When a new database instance needs to be added, the database instance is mapped to a hash value and added to the hash circle. Since the sorting and location selection rules are determined, for most user connections, the last database instance is still the one that is reconnected. The number of requests falling on the new machine is relatively small, which can ensure that the status of most users is maintained, thereby ensuring the stability of the entire system. The same is true for deleting database instances, which will not be repeated here.

[0080] As an example, Figure 5 As shown, general performance group 3 is a newly added database instance. For user 2 and user 1, the database instance used to re-establish the connection is still the previous one, that is, high performance group 2. Only the database instance corresponding to user 3 is changed from general performance 1 to general performance 3. In this way, the status of most users can be maintained at the expense of maintaining the status of individual users, thereby ensuring the stability of the entire system.

[0081] It should be noted that, in the implementation of the hash ring, an AVL tree can be used. For an AVL tree with n nodes, the height can be maintained at log2n, and the search time complexity can be maintained at O(log2n).

[0082] Among them, the AVL tree is a self-balancing binary search tree, the absolute value of the height difference between the left and right subtrees does not exceed 1, and the left and right subtrees are both balanced binary trees.

[0083] In this embodiment, a database instance connection device based on a hash ring is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0084] This embodiment provides a database instance connection device based on a hash ring, such as Figure 6 As shown, including:

[0085] A hash ring construction module 601 is used to map, for each database instance in a plurality of database instances, an identifier of the database instance into a hash value corresponding to the database instance, and to establish a hash ring structure including hash values ​​corresponding to the plurality of database instances;

[0086] The database instance connection module 602 is used to map the identifier corresponding to the reconnection request to a first hash value when receiving a user's reconnection request from the user device, find out the second hash value corresponding to the first hash value from the hash ring structure, and establish a connection between the user device and the target database instance corresponding to the second hash value; wherein the reconnection request is sent because the user device requests to connect to the target database instance again because the connection between the user device and the target database instance is interrupted.

[0087] In some optional embodiments, the database instance connection module 602 is also used to use the mapping position of the first hash value in the hash ring structure as a starting point to search for the second hash value in a clockwise or counterclockwise direction along the hash ring structure; the second hash value is the first hash value of the first hash value in a clockwise or counterclockwise direction along the hash ring structure.

[0088] In some optional implementations, a database instance connection device based on a hash ring further includes:

[0089] The user classification module 603 is used to classify users into hotspot users, secondary hotspot users and ordinary users according to the number of connection interruptions between the user device and the target database instance and the average time interval for sending reconnection requests;

[0090] The classification label assigning module 604 is used to assign corresponding classification labels to hot users and secondary hot users.

[0091] In some optional implementations, a database instance connection device based on a hash ring further includes:

[0092] The database cluster establishment module 605 is used to establish multiple database clusters; each database cluster includes multiple databases; and each database corresponds to at least one database instance.

[0093] The database cluster grouping module 606 is used to group the multiple database clusters into an ultra-high performance group, a high performance group, and a general performance group according to the performance of each database cluster.

[0094] The classification label corresponding module 607 is used to assign classification labels of hot users to the database instance corresponding to each database in the ultra-high performance group; and to assign classification labels of secondary hot users to the database instance corresponding to each database in the high performance group.

[0095] In some optional embodiments, the database instance connection module 602 is also used to use the mapping position of the first hash value in the hash ring structure as a starting point, and search for the second hash value along the clockwise or counterclockwise direction of the hash ring structure; the second hash value is the hash value corresponding to the first database instance along the clockwise or counterclockwise direction of the hash ring structure of the first hash value, which is equal to the classification label of the user corresponding to the first hash value.

[0096] In some optional embodiments, the number of hash values ​​corresponding to the database instances of the target database in the ultra-high performance group in the hash ring structure is greater than the number of hash values ​​corresponding to other database instances in the hash ring structure; the other database instances are database instances corresponding to databases in the high performance group or the general performance group.

[0097] In some optional implementations, the hash ring construction module 601 is further used to sort the hash values ​​corresponding to the multiple database instances in ascending or descending order, connect them end to end, and form a logical hash ring structure.

[0098] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0099] In this embodiment, a database instance connection device based on a hash ring is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0100] The embodiment of the present invention also provides a computer device having the above Figure 6A database instance connection device based on a hash ring is shown.

[0101] like Figure 7 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.

[0102] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0103] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.

[0104] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0105] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0106] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0107] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0108] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A database instance connection method based on a hash ring, characterized in that: The method comprises: For each database instance in the plurality of database instances, mapping an identifier of the database instance into a hash value corresponding to the database instance, and establishing a hash ring structure including the hash values ​​corresponding to the plurality of database instances; When a user's reconnection request is received from a user device, an identifier corresponding to the reconnection request is mapped to a first hash value, a second hash value corresponding to the first hash value is found from the hash ring structure, and a connection between the user device and a target database instance corresponding to the second hash value is established; wherein the reconnection request is sent because the user device requests to connect to the target database instance again due to a connection interruption between the user device and the target database instance.

2. The method according to claim 1, characterized in that The step of searching the hash ring structure for a second hash value corresponding to the first hash value includes: Taking the mapping position of the first hash value in the hash ring structure as the starting point, searching for the second hash value along the clockwise or counterclockwise direction of the hash ring structure; the second hash value is the first hash value of the first hash value along the clockwise or counterclockwise direction of the hash ring structure.

3. The method according to claim 1, characterized in that After establishing a hash ring structure including hash values ​​corresponding to multiple database instances, the method further includes: According to the number of disconnections between the user device and the target database instance and the average time interval for sending reconnection requests, users are divided into hotspot users, secondary hotspot users and ordinary users; Corresponding classification labels are assigned to hot users and secondary hot users.

4. The method according to claim 3, characterized in that Before mapping the identifier of the database instance into a hash value corresponding to the database instance, the method includes: Establish multiple database clusters; each database cluster includes multiple databases; each database corresponds to at least one database instance; Based on the performance of each database cluster, multiple database clusters are divided into ultra-high performance group, high performance group, and general performance group; For the database instance corresponding to each database in the ultra-high performance group, assign a classification label to the hotspot user; For the database instance corresponding to each database in the high-performance group, a classification label of the secondary hotspot user is assigned.

5. The method according to claim 4, characterized in that The step of searching the hash ring structure for a second hash value corresponding to the first hash value includes: Taking the mapping position of the first hash value in the hash ring structure as the starting point, search for the second hash value along the clockwise or counterclockwise direction of the hash ring structure; the second hash value is the hash value corresponding to the first database instance along the clockwise or counterclockwise direction of the hash ring structure that is equal to the classification label of the user corresponding to the first hash value.

6. The method according to claim 5, characterized in that The number of hash values ​​of the database instances corresponding to the target database in the ultra-high performance group in the hash ring structure is greater than the number of hash values ​​corresponding to other database instances in the hash ring structure; the other database instances are database instances corresponding to databases in the high performance group or the general performance group.

7. The method according to claim 1 or 6, characterized in that: The step of establishing a hash ring structure including hash values ​​corresponding to multiple database instances includes: Sort the hash values ​​corresponding to multiple database instances in ascending or descending order, connect them end to end, and form a logical hash ring structure.

8. A database instance connection device based on a hash ring, characterized in that: The device comprises: A hash ring construction module, used for mapping, for each database instance in a plurality of database instances, an identifier of the database instance into a hash value corresponding to the database instance, and establishing a hash ring structure including hash values ​​corresponding to the plurality of database instances; A database instance connection module is used to map the identifier corresponding to the reconnection request to a first hash value when receiving a user's reconnection request from a user device, find out the second hash value corresponding to the first hash value from the hash ring structure, and establish a connection between the user device and the target database instance corresponding to the second hash value; wherein the reconnection request is sent because the user device requests to connect to the target database instance again due to the interruption of the connection between the user device and the target database instance.

9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method according to any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Distributed request processing method and device, equipment and storage medium

    CN113315825A

  • Method and device for improving local cache hit rate of OLAP analysis database and medium

    CN115658743A

  • Instance processing method and device, electronic equipment and computer readable storage medium

    CN117081761A

  • Message pushing method and device, computer equipment and storage medium

    CN117176796A

  • Request processing method and device based on hash ring, electronic equipment and storage medium

    CN117459597A