Database request processing method, device, computer equipment and storage medium
By extracting the selection parameters and forwarding them to the matching server when receiving a database service request, the problem in the prior art that it is difficult to isolate faults by one server connecting to multiple databases is solved, and the fault tolerance and stability of the database system are improved.
Patent Information
- Application Number
- CN202010779054.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-05
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2040-08-05
AI Technical Summary
In the existing technology, when one server connects to multiple databases, it is difficult to achieve fault isolation, resulting in poor fault tolerance of the database business system and inability to meet business needs under high concurrency and large data volume.
When receiving a database business request, extract the database selection parameters, select a matching target server from at least two servers, and forward the request to the server to ensure that different databases are configured with different servers to achieve fault isolation.
It improves the accuracy of processing database business requests, effectively implements database fault isolation, and improves the fault tolerance rate and stability of the database business system.
Smart Images

Figure CN111949402B
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of data processing, and in particular to a database request processing method, device, computer equipment and storage medium. Background Art
[0002] Currently, the business system will configure two databases, and the main database will be used as the production database to provide external services. The standby database will be used as a backup database to synchronize data with the main database in real time, ensuring that when the main database fails, it can be switched to the standby database seamlessly and with zero data loss, so as to meet business continuity requirements.
[0003] However, the service provided by the above method always has only one database at a time point. There is a small probability that 1+N databases will crash at the same time, causing the entire business system to be unavailable. In addition, with the development of time and business, the amount of data in the business system is increasing, and the concurrent access volume of the business system is also increasing. A single database can no longer meet business needs. In this case, the database is usually divided into different databases to meet business needs. Specifically, the database can be divided into different databases by horizontal splitting. Horizontal splitting means that when the amount of data in the database table is too large, the data in the table is divided according to certain rules or dimensions, and then stored in different databases. Different databases contain the same table structure but store different data.
[0004] The existing horizontal sharding method is to configure a business system to correspond to multiple databases, configure data judgment rules in the business system, and let the business system process the database according to the request. Since the requests sent to different databases still come from the same business system, when one of the databases fails, the request processing thread of the entire business system will be suspended, which will cause the entire business system to be unavailable, and ultimately the entire business system will be unable to provide services to the outside world and fail to meet the fault isolation requirements. Summary of the invention
[0005] The embodiments of the present invention provide a database request processing method, device, computer equipment and storage medium, which can isolate database faults and improve the stability and fault tolerance of the database system.
[0006] In a first aspect, an embodiment of the present invention provides a method for processing a database request, comprising:
[0007] When receiving a database service request, extracting a database selection parameter from the database service request;
[0008] Selecting a target server matching the database selection parameter from at least two servers, and forwarding the database service request to the target server to instruct the target server to process the target database corresponding to the target server according to the database service request, where different databases correspond to different servers;
[0009] Receive response data sent by the target server, and return the response data to the sender of the database service request.
[0010] In a second aspect, an embodiment of the present invention further provides a database request processing device, including:
[0011] A database selection parameter acquisition module, used to extract database selection parameters from the database service request when receiving the database service request;
[0012] A target server forwarding module, used to select a target server matching the database selection parameter from at least two servers, and forward the database service request to the target server, so as to instruct the target server to process the target database corresponding to the target server according to the database service request, and different databases correspond to different servers;
[0013] The response data receiving module is used to receive the response data sent by the target server and return the response data to the sender of the database service request.
[0014] In a third aspect, an embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, a database request processing method as described in any one of the embodiments of the present invention is implemented.
[0015] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a database request processing method as described in any one of the embodiments of the present invention.
[0016] The embodiment of the present invention extracts the database selection parameter in the database business request when receiving the database business request, determines the server that matches the database selection parameter, forwards the database business request to the matching server, and the server processes the matching database according to the database business request, thereby configuring different servers for different databases, and having different servers process database business requests for different databases. This solves the problem in the prior art that one server is connected to multiple databases, making it difficult to isolate faults, resulting in poor fault tolerance of the database business system. The processing accuracy of database business requests can be improved, database fault isolation can be effectively implemented, and the fault tolerance and stability of the database business system can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1a is a flowchart of a database request processing method in Embodiment 1 of the present invention;
[0018] Figure 1b It is a schematic diagram of an application scenario to which the embodiment of the present invention is applicable;
[0019] Figure 2 is a flowchart of a database request processing method in Embodiment 2 of the present invention;
[0020] Figure 3 is a flowchart of a database request processing method in Embodiment 3 of the present invention;
[0021] Figure 4 is a flowchart of a database request processing method in Embodiment 4 of the present invention;
[0022] Figure 5 It is a structural diagram of a database request processing device in Embodiment 5 of the present invention;
[0023] Figure 6 It is a structural diagram of a computer device in Embodiment 6 of the present invention. DETAILED DESCRIPTION
[0024] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0025] Embodiment 1
[0026] Figure 1aThis is a schematic diagram of a flowchart of a database request processing method in Embodiment 1 of the present invention. This method can be executed by a database request processing device provided in an embodiment of the present invention. The device can be implemented in software and / or hardware and can generally be integrated into a computer device, such as a server. Figure 1a As shown, the method of this embodiment specifically includes:
[0027] S110, when a database service request is received, extracting a database selection parameter from the database service request.
[0028] The database service request is used to perform database operations on at least one database, wherein the database operation may include at least one of the following: querying, adding, modifying and deleting data in the database. The database selection parameter is used to point to at least one database. The database selection parameter may refer to the attribute value corresponding to the preset field included in the database service request. The database service request includes the database selection parameter, and the parsing module may be pre-configured according to the data structure of the database service request, and the database service request may be parsed, and the database selection parameter may be queried from the database service request and obtained. Specifically, the database selection parameter may be a field describing the database dimension, and the attribute value corresponding to the field.
[0029] Exemplarily, a database service request is used to query data in region A, the field is information indicating the region, and the attribute value corresponding to the field is A. Specifically, the dimension of the database sub-library may include at least one of the following: time, region, service type, user level, or other dimensional conditions, etc., and accordingly, the database dimension field may include at least one of the following: time field, region field, service type field, user level field, or other dimensional condition field, etc. In addition, the database dimension field may also be other information, such as a database identifier, etc., which is not specifically limited in the embodiment of the present invention.
[0030] S120, selecting at least one target server that matches the database selection parameter from at least two servers, and forwarding the database service request to each of the target servers to instruct each of the target servers to process the target database corresponding to each of the target servers according to the database service request, and different databases correspond to different servers.
[0031] The server is used to process the matched database. Optionally, the number of databases matched by a server is one. Different servers correspond to different databases. The existence of at least two servers at the same time indicates that operations on different databases are performed by different servers, realizing isolated operations of the databases, thereby realizing fault isolation of the databases, that is, when a database fails, it will only affect the database operations of one server, and will not affect the database operations of other servers, thereby not affecting the responses of database service requests of other databases.
[0032] The database selection parameter is used to determine the database, and the database is operated by the matching server, that is, the database selection parameter is used to determine the server that performs the operation on the database. The target server is the server that matches the database selection parameter. The target server is used to respond to the database service request, specifically, to perform the operation on the target database according to the database service request.
[0033] It should be noted that the number of target servers matching the database selection parameters is at least one. The data to be processed that matches the database selection parameters can be stored repeatedly in multiple target databases, or stored in multiple target databases in a dispersed manner. Therefore, according to the database business request, at least one database operation request can be generated according to the database sub-database dimension, each database operation request corresponds to a target database, and different database operation requests correspond to different target databases. Correspondingly, each database operation request is sent to a different target server respectively to instruct each target server to process the corresponding target database according to the corresponding database operation request. Alternatively, the database business request can be directly forwarded to different target servers respectively to instruct each target server to process the corresponding target database according to the corresponding database business request.
[0034] When the to-be-processed data matching the database selection parameter is repeatedly stored in multiple target databases, it can be further screened according to the preset restriction condition, and one of the multiple servers can be selected as the target server. The preset restriction condition is used to screen the server, and illustratively, the restriction condition can be at least one of the performance of the server, the amount of data in the matching database, and the like.
[0035] S130, receiving response data sent by each of the target servers, and returning the response data to the sender of the database service request.
[0036] After the target server processes the target database according to the database service request, it will feedback the response data. After receiving the response data, if there is only one response data fed back by the target server, the response data can be directly fed back to the sender; if there are at least two response data fed back by the target servers, the response data can be combined to form the target response data, and then fed back to the sender.
[0037] The sender may be a terminal device used by the user, specifically a client or web page configured on the terminal device. The computer device for implementing the database request processing method provided in the embodiment of the present invention is a computer device configured between the terminal device used by the user and the server. Figure 1b As shown, a computer device 152 for implementing a database request processing method provided by an embodiment of the present invention is configured between the terminal device 151 and the first server 153 and between the terminal device 151 and the second server 155. The computer device 152 performs database sub-selection, the first server 153 is used to maintain the first database 154, and the second server 155 is used to provide a second database 156 for large households. The first server 153 and the second server 155 do not need to maintain multiple databases, and do not need to pay attention to the problem of database selection, thereby effectively shielding the transformation of the first server 153 and the second server 155 by database sub-selection.
[0038] Optionally, the database request processing method further includes: if it is determined that the number of requests received within a set time period is greater than a set threshold, stopping receiving database service requests.
[0039] The computer device provided by the embodiment of the present invention usually refuses to accept more database service requests for processing in order to ensure the accuracy of processing database service requests when the traffic is large. Specifically, within a set time, the number of database service requests received is less than a set threshold.
[0040] For example, the set duration may be 1 minute, and the set threshold may be 50. In addition, the setting may be made according to actual conditions, and the embodiment of the present invention does not impose any specific limitation on this.
[0041] If the number of requests received within the set time is greater than the set threshold, it indicates that the amount of data processed by the computer device provided by the embodiment of the present invention is large. Choosing to stop receiving database business requests to avoid processing too much data can reduce processing exceptions while taking into account processing efficiency.
[0042] Optionally, the receiving of response data sent by each of the target servers and returning it to the sender of the database service request includes: combining the response data sent by each of the target servers to form target response data, and returning it to the sender of the database service request, and the number of the target servers is at least two.
[0043] The target response data includes the response data sent by all target servers. By integrating the response data sent by each target server, the number of transmission times of the response data is reduced, the amount of redundant data transmitted to the sender is reduced, and the transmission efficiency is improved.
[0044] The embodiment of the present invention extracts the database selection parameter in the database business request when receiving the database business request, determines the server that matches the database selection parameter, forwards the database business request to the matching server, and the server processes the matching database according to the database business request, thereby configuring different servers for different databases, and having different servers process database business requests for different databases. This solves the problem in the prior art that one server is connected to multiple databases, making it difficult to isolate faults, resulting in poor fault tolerance of the database business system. The processing accuracy of database business requests can be improved, database fault isolation can be effectively implemented, and the fault tolerance and stability of the database business system can be improved.
[0045] Embodiment 2
[0046] Figure 2 This is a flowchart of a database request processing method in Embodiment 2 of the present invention. This embodiment is specific based on the above embodiment. The method of this embodiment specifically includes:
[0047] S210: When a database service request is received, extract a database selection parameter from the database service request.
[0048] For a non-exhaustive description of the embodiments of the present invention, reference may be made to the aforementioned embodiments.
[0049] S220, extracting sub-database dimension information from the database selection parameters.
[0050] The database sharding dimension information is used to describe the rule information when the database is sharded, and specifically refers to the field representing the database type and the attribute value corresponding to the field. The database sharding dimension information can be used to identify the database.
[0051] S230, according to the pre-configured correspondence between the sub-library dimension information and the server, select at least one target server matching the database selection parameter from at least two servers to instruct each of the target servers to process the target database corresponding to each of the target servers according to the database business request. Different databases correspond to different servers, and the servers correspond to databases one-to-one.
[0052] The correspondence between the sub-library dimension information and the server is actually used to represent the correspondence between the database and the server. The correspondence between the sub-library dimension information and the server can be pre-configured, and the matching target server can be queried from the correspondence according to the sub-library dimension information extracted from the database business request.
[0053] Among them, the server and the database correspond one to one, which means that the database corresponding to each server is different, that is, each database has fault isolation, which can effectively reduce the impact of database failure on other databases.
[0054] Optionally, before selecting a target server matching the database selection parameters from at least two servers according to the pre-configured correspondence between sub-library dimension information and the server, the method further includes: obtaining at least two databases and sub-library dimension information corresponding to each of the databases, the databases being formed by sub-librarying an initial database according to the corresponding dimension information; obtaining servers corresponding to each of the databases, and establishing a correspondence between the sub-library dimension information and the server.
[0055] Before obtaining the correspondence between the pre-configured sub-library dimension information and the server, the database is pre-divided, and the sub-library dimension information of the database is determined according to the sub-library rule information. By dividing the initial database, at least one database in the embodiment of the present invention can be obtained. The data in the database after the division is independent of each other, and each server responsible for processing each database is independent of each other, and the database processing operations will not interfere with each other.
[0056] According to the server responsible for processing the database and the sub-library dimension information corresponding to the database, a corresponding relationship between the sub-library dimension information and the server can be established and stored.
[0057] In the prior art, a structured query language (SQL) parsing and database partitioning judgment module is added to the original server. Before the server sends the SQL statement to the database for execution, the specific SQL is intercepted and parsed at the SQL level, and the database that should execute this SQL statement is identified based on the parameters in the SQL statement and the current database partitioning dimension. For example, some existing open source distributed database middleware also adopts this kind of principle or method, but the biggest problem with this kind of method is that it is more suitable for newly built systems. For systems that have been built for many years, all SQL statements of the existing system need to be analyzed one by one, and database partitioning rules need to be added to a certain extent for various SQL statements of the original database.
[0058] Or, at the application level of the server, the method or function is intercepted before it is executed, and then the database connection required to execute the current method or function is determined based on the current request parameters of the method or function. Since the method or function is intercepted, the coupling between the underlying SQL parsing method and the application logic is stronger than that of the aforementioned method, and the implementation is more difficult.
[0059] The embodiment of the present invention configures a computer device for performing sub-library judgment before the server, establishes and stores the corresponding relationship between the sub-library dimension information and the server, thereby avoiding the server from intercepting and analyzing SQL and reducing the data processing cost of transforming the historical database. At the same time, it can avoid intercepting the server's execution method or function before it is executed, reduce the coupling between the server's SQL execution function and method and request parsing, realize business decoupling of database business request processing, and improve the scalability and flexibility of the database business request processing system.
[0060] S240, receiving response data sent by each of the target servers, and returning the response data to the sender of the database service request.
[0061] The embodiment of the present invention extracts sub-library dimension information from database selection parameters, and according to the correspondence between the pre-configured sub-library dimension information and the server, can quickly and accurately determine the target server, improve the response accuracy of database business requests, and realize accurate processing of database business requests, and can avoid and save the interception and analysis of SQL query statements or the interception and analysis of functions for response requests on the server, reduce the data processing cost of transforming historical databases, and reduce the coupling between the SQL execution function and request parsing of the server, realize business decoupling of database business request processing, improve the scalability and flexibility of the database business request processing system, reduce the database transformation cost of database business request processing, reduce the difficulty of implementing database sub-library, and allow databases that have been built for many years to be sub-library.
[0062] Embodiment 3
[0063] Figure 3 This is a flowchart of a database request processing method in Embodiment 3 of the present invention. This embodiment is specific based on the above embodiment. The method of this embodiment specifically includes:
[0064] S310: When a database service request is received, extract a database selection parameter from the database service request.
[0065] For a non-exhaustive description of the embodiments of the present invention, reference may be made to the aforementioned embodiments.
[0066] S320: Select at least one target server matching the database selection parameter from at least two servers.
[0067] S330, selecting a target thread pool matching the target server from at least two thread pools according to a pre-configured correspondence between servers and thread pools, where different thread pools correspond to different servers.
[0068] Using thread pool to process database business processing requests is actually using multi-threaded processing to process database business processing requests. During the processing, tasks are added to the queue, and then the tasks in the queue are automatically started after the thread is created. The thread pool can refer to a collection of multiple threads.
[0069] In an embodiment of the present invention, a thread pool corresponds to a server, indicating that each task in a request queue corresponding to a thread pool is used to forward a database service request to a server corresponding to the thread pool. Optionally, the server corresponds to the thread pool one-to-one. The corresponding relationship between the server and the thread pool is used to determine the target request queue to which the forwarding task of the database service request is added.
[0070] Optionally, before selecting a target thread pool matching the target server from at least two thread pools according to a pre-configured correspondence between servers and thread pools, the method further includes: creating at least two thread pools, and establishing a correspondence between thread pools and servers, with servers and thread pools corresponding one to one; and configuring parameters of the thread pool corresponding to the server according to information about the server and information about a database corresponding to the server.
[0071] A thread pool can be established, and a corresponding relationship between the thread pool and the server can be established. At the same time, the server and the thread pool correspond one to one, that is, the thread pool corresponding to each server is different.
[0072] The thread pool parameters are used to configure the function and state of the thread pool. According to the information of the server and the information of the database corresponding to the server, the parameters of the thread pool are configured, specifically, they are used to adjust the state and properties of the thread pool according to the state and properties of the server and the state and properties of the matching database, that is, the parameters of the thread pool can be adjusted in real time according to the state of the server and the matching database, so that the parameters of the thread pool are used to represent the state and properties of the server and the state and properties of the matching database. Exemplarily, if the server or the matching database fails, the thread pool can be adjusted to a closed state in real time, and no database business requests will be added.
[0073] By establishing a corresponding relationship between the thread pool and the thread pool and the server, and adjusting the thread pool according to the information of the corresponding server and the matching database, the state of the thread pool can be adjusted in real time according to the state and properties of the server and the matching database, so as to accurately respond to abnormalities of faulty databases or faulty servers, avoid more erroneous processing of database business requests, and improve the real-time performance of abnormal response in database business request processing.
[0074] Optionally, the parameters of the thread pool include at least one of the following: a minimum number of threads included in the thread pool, a maximum number of threads, a range of request numbers in a corresponding request queue, a dynamic adjustment method for the number of requests in a corresponding request queue, and an idle thread recycle time.
[0075] The thread pool includes multiple threads. A thread may refer to the smallest unit for executing a task. When receiving a task, the thread pool specifies an idle thread among the included threads to execute the task. The maximum and minimum values of the number of threads are used to determine the number of threads included in the thread pool. The maximum value of the number of threads is used to determine the maximum number of tasks that the thread pool can execute simultaneously, and the minimum value of the number of threads is used to determine the minimum number of tasks that the thread pool can execute simultaneously. Among them, the number of threads included in the thread pool can be adjusted dynamically. For example, in a certain time period, the number of tasks is large, and threads can be added to process more tasks, but the total number of threads in the thread pool after the increase is less than or equal to the maximum value. For another example, in a certain time period, the number of tasks is small, and threads can be reduced, but the total number of threads in the thread pool after the reduction is greater than or equal to the minimum value. The idle thread recycle time is used to determine the survival time of the idle thread. If the waiting time or idle time of the idle thread is greater than or equal to the idle thread recycle time, the idle thread is deleted, that is, the idle thread is no longer alive. It should be noted that if the total number of threads in the thread pool is equal to the minimum value, the idle thread will not be deleted even if there is an idle thread whose waiting time or idle time is greater than or equal to the idle thread recycle time.
[0076] Usually, tasks are added to the request queue, which is used to sort the added tasks according to the processing priority. The thread pool obtains tasks from the request queue and calls an idle thread to execute the task. If there is no idle thread, the task in the request queue needs to wait to be executed. Usually, the number of requests included in the request queue is pre-configured, usually a constant. The number of requests included in the request queue can be adjusted dynamically. The request number range is used to determine the minimum and maximum number of tasks waiting to be executed in the request queue. The dynamic adjustment method of the request number is used to adjust the number of requests in the request queue. For example, in a certain time period, the number of tasks is large, and the number of requests in the request queue can be increased, but the total number of requests in the request queue after the increase belongs to the request number range. For another example, in a certain time period, the number of tasks is small, and the number of requests can be reduced, but the total number of requests in the request queue after the reduction belongs to the request number range.
[0077] In addition, the parameters of the thread pool may also include an identifier of the thread pool and / or a switch state of the thread pool, etc., which may be specifically set according to actual conditions, and the embodiments of the present invention do not impose specific limitations on this.
[0078] By pre-configuring multiple parameters of the thread pool parameters, the state and function of the thread pool can be flexibly adjusted to adapt the thread pool to the processing requirements of database business requests and the performance of the server and database, thereby improving the flexibility of database business request processing.
[0079] Specifically, Figure 1b As shown, the computer device 152 may include a parameter configuration module to implement the aforementioned parameter configuration function of the thread pool.
[0080] S340, adding the database service request to the request queue corresponding to the target thread pool.
[0081] Adding the database business request to the request queue corresponding to the target thread pool actually means adding the forwarding task of the database business request to the request queue corresponding to the target thread pool, so that the threads in the target thread pool can forward the database business request to the target server corresponding to the target thread pool.
[0082] S350, calling the thread in the target thread pool to forward the database service request to the target server to instruct the target server to process the target database corresponding to the target server according to the database service request, and different databases correspond to different servers.
[0083] The threads in the target thread pool are used to execute tasks in the request queue, specifically to forward database business requests to the corresponding target server.
[0084] S360, receiving response data sent by each of the target servers, and returning the response data to the sender of the database service request.
[0085] In addition, the computer device provided in the embodiment of the present invention can also monitor various thread pools and various database service requests, support automatic dynamic or manual adjustment of the maximum number of requests in the thread pool queue and take effect in real time, and support monitoring of the execution success rate, number of transactions per second (TPS), average execution time of requests and other indicators of various database service requests. Specifically, Figure 1b As shown, the computer device 152 may include a monitoring module to implement the aforementioned monitoring function.
[0086] The embodiment of the present invention configures the correspondence between the server and the thread pool, selects the target thread pool corresponding to the target server, and forwards the database business request to the target server by calling the thread of the target thread pool, accurately forwards the database business request to the target server, and instructs the target server to process the target database, accurately implements the database sub-library judgment of the database business request, can quickly and accurately determine the target server, improve the response accuracy of the database business request, realize the accurate processing of the database business request, and at the same time reduce the modification of the server and reduce the difficulty of implementing the database sub-library.
[0087] Embodiment 4
[0088] Figure 4 This is a flowchart of a database request processing method in Embodiment 4 of the present invention. This embodiment is specific based on the above embodiment. The method of this embodiment specifically includes:
[0089] S410: When a database service request is received, extract a database selection parameter from the database service request.
[0090] For a non-exhaustive description of the embodiments of the present invention, reference may be made to the aforementioned embodiments.
[0091] S420: Select at least one target server matching the database selection parameter from at least two servers.
[0092] S430, selecting a target thread pool matching the target server from at least two thread pools according to a pre-configured correspondence between servers and thread pools, where different thread pools correspond to different servers.
[0093] S440: Add the database service request to the request queue corresponding to the target thread pool.
[0094] S450, calling the thread in the target thread pool, forwarding the database service request to the target server, instructing the target server to process the target database corresponding to the target server according to the database service request, and different databases correspond to different servers.
[0095] S460, receiving response data sent by each of the target servers, and returning the response data to the sender of the database service request.
[0096] S470: If it is determined that an exception occurs in the target server, stop calling the threads in the target thread pool, and stop forwarding the database service requests in the request queue corresponding to the target thread pool to the target server.
[0097] The target server has an exception, indicating that the target server cannot provide correct services. The target server exception may include the server itself and the target database.
[0098] At this time, the switch state of the target thread pool can be automatically configured to be closed. In the closed state, the target thread pool can stop calling threads in the target thread pool and stop forwarding database business requests in the request queue corresponding to the target thread pool to the target server. As a result, the target thread pool no longer forwards database business requests in the corresponding request queue to the target server.
[0099] Optionally, determining that an abnormality has occurred in the target server includes: if it is determined that the waiting time for response data matching the target database business request is greater than a preset time threshold, then determining that an abnormality has occurred in the target server, and the target database business request is a database business request forwarded to the target server; and / or if it is determined that the number of waiting timeouts for the response data is greater than a preset number threshold, then determining that an abnormality has occurred in the target server.
[0100] If the waiting time for the response data matching the target database business request is greater than the preset time threshold or the number of waiting timeouts, it indicates that an abnormality occurs in the target server processing the database business request, specifically, an abnormality occurs in the target server itself or in the database corresponding to the target server itself.
[0101] The target database service request refers to a database service request whose waiting time for the matching response data is greater than a preset time threshold and / or whose waiting timeout times for the matching response data are greater than a preset number threshold. It can be any database service request forwarded to the target server. The database service request includes a request identifier, so that when the response data sent by the target server is received, the database service request matching the response data can be determined according to the request identifier included in the response data.
[0102] The waiting time for the response data matched by the database service request is used to indicate the time from when the database service request is sent to the target server to when the response data matched by the database service request is received by the target server. The preset time threshold is used to determine whether the waiting time for the response data matched by the database service request has timed out. Exemplarily, the preset time threshold is 1 minute. It can be set according to actual conditions, and the embodiment of the present invention does not impose specific restrictions on this.
[0103] The number of waiting timeouts is used to indicate the number of times the waiting timeout occurs, and specifically refers to the number of waiting timeout events that occur on the target server within the set time period. Exemplarily, the number may be: within the set time period, the same database service request is repeatedly sent to the target server, and the statistical number of times the waiting time of the response data matched by the database service request is greater than the preset time threshold; or, within the set time period, different database service requests are sent to the target server, and the statistical number of database service requests whose waiting time of the matching response data is greater than the preset time threshold. The preset number threshold determines whether the waiting timeout event that occurs on the target server occurs multiple times. Exemplarily, the preset time threshold is 3 times. It can be set specifically according to actual conditions, and the embodiments of the present invention do not impose specific restrictions on this.
[0104] By counting the waiting time for the response data matched by the database business request and the number of waiting timeouts, it is determined whether an abnormality has occurred in the target server. In this way, it is possible to determine in real time whether an abnormality exists in the server or the database corresponding to the server, so that abnormal events can be responded to in a timely manner, reducing resource consumption for exception handling and reducing power consumption.
[0105] Optionally, before determining that an abnormality occurs in the target server, the method further includes: monitoring the target database service request, obtaining monitoring data matching the target database service request, wherein the monitoring data includes the waiting time for response data and / or the number of waiting timeouts for response data.
[0106] By continuously monitoring the database service request and obtaining the monitoring data of the database service request, such as the waiting time for the response data matched by the database service request and / or the number of waiting timeouts for the response data, it is possible to accurately determine whether an abnormality occurs in the target server based on the monitoring data.
[0107] By monitoring each database service request and judging whether the response to the database service request is normal based on the monitoring data, it is possible to accurately detect whether the corresponding server has an abnormality, thereby improving the accuracy and real-time performance of server anomaly detection.
[0108] In addition, the thread pool can be monitored and the maximum number of requests in the thread pool queue can be automatically adjusted.
[0109] Optionally, while stopping forwarding the database business requests in the request queue corresponding to the target thread pool to the target server, it also includes: selecting a switching server that matches the database selection parameters from at least two servers, and the switching server is different from the target server; adding the database business request to the request queue corresponding to the switching thread pool corresponding to the switching server; calling the thread in the switching thread pool to forward the database business request to the switching server to instruct the switching server to process the switching database corresponding to the switching server according to the database business request.
[0110] The switch server is used to provide the same service as the target server for database business requests when an exception occurs on the target server. The service provided by the switch server is the same as that provided by the target server. The switch server is different from the target server and the corresponding data is different.
[0111] The database service request is added to the request queue corresponding to the switching thread pool corresponding to the switching server, and the thread of the switching thread pool is called to forward the database service request to the switching server to instruct the switching database corresponding to the switching server to be processed according to the database service request. The database service request can be switched to the operation processing of other databases.
[0112] It should be noted that the target server may not have a matching switching server. In this case, the database service request cannot be forwarded to the switching server and can be discarded. In addition, when the database service request is used for at least one operation of adding, deleting and modifying the original data of the target database, after switching to other switching servers for processing, the target database can be updated according to the same operation after the target server is used normally, or it can be directly discarded without switching and forwarding to the switching server. This can be set according to actual conditions, and the embodiments of the present invention are not specifically limited.
[0113] By adding the database business requests in the request queue to the request queue corresponding to the switching thread pool and forwarding them to the switching server for processing, when the target server fails, the database business requests can be forwarded to the switching server for processing, so that the database business requests can be processed normally and in a timely manner, and abnormal compensation can be performed in real time, thereby improving the processing accuracy of database business requests.
[0114] S480, stop adding the database service request to the request queue corresponding to the target thread pool.
[0115] The request queue corresponding to the target thread pool will no longer add new database service requests, avoiding the situation where the database service request is added to the request queue but cannot be processed correctly. Accordingly, the database service request can be directly discarded or forwarded to other thread pools for processing, etc. This can be set according to actual conditions, and the embodiment of the present invention does not make specific restrictions on this.
[0116] At this point, each thread pool is independent of each other, and other thread pools except the target thread pool continue to process normally. The shutdown state of the target thread pool will not affect the normal operation of other thread pools, thereby achieving fault isolation function.
[0117] The embodiment of the present invention stops calling threads in the target thread pool and stops executing tasks in the request queue when determining that the target server is abnormal, that is, stops forwarding any database business request to the target server, and stops sending any database business request to the corresponding request queue, so that the target thread pool can accurately respond to server abnormal events and improve the abnormal response efficiency of the overall system.
[0118] Embodiment 5
[0119] Figure 5 Schematic diagram of a database request processing device in Embodiment 5 of the present invention. Embodiment 5 is a corresponding device for implementing the database request processing method provided in the above embodiments of the present invention, which can be implemented in software and / or hardware and can generally be integrated into a computer device.
[0120] Accordingly, the device of this embodiment may include:
[0121] A database selection parameter acquisition module 510 is used to extract database selection parameters from a database service request when receiving the database service request;
[0122] The target server forwarding module 520 is used to select at least one target server matching the database selection parameter from at least two servers, and forward the database service request to each of the target servers to instruct each of the target servers to process the target database corresponding to each of the target servers according to the database service request, and different databases correspond to different servers;
[0123] The response data receiving module 530 is used to receive the response data sent by each target server and return it to the sender of the database service request.
[0124] The embodiment of the present invention extracts the database selection parameter in the database business request when receiving the database business request, determines the server that matches the database selection parameter, forwards the database business request to the matching server, and the server processes the matching database according to the database business request, thereby configuring different servers for different databases, and having different servers process database business requests for different databases. This solves the problem in the prior art that one server is connected to multiple databases, making it difficult to isolate faults, resulting in poor fault tolerance of the database business system. The processing accuracy of database business requests can be improved, database fault isolation can be effectively implemented, and the fault tolerance and stability of the database business system can be improved.
[0125] Furthermore, the target server forwarding module 520 includes: a target server determination unit, used to extract sub-library dimension information from the database selection parameters; based on the pre-configured correspondence between the sub-library dimension information and the server, selecting at least one target server matching the database selection parameters from at least two servers, and the servers correspond to the databases one-to-one.
[0126] Furthermore, the database request processing device also includes: a library dimension correspondence establishment module, which is used to obtain at least two databases and library dimension information corresponding to each of the databases before selecting at least one target server matching the database selection parameters from at least two servers according to the pre-configured correspondence between the library dimension information and the server, the database being formed by partitioning the initial database according to the corresponding dimension information; obtaining the server corresponding to each of the databases, and establishing a correspondence between the library dimension information and the server.
[0127] Furthermore, the target server forwarding module 520 includes: a thread pool forwarding unit, which is used to select a target thread pool matching the target server from at least two thread pools according to the pre-configured correspondence between the server and the thread pool, and different thread pools correspond to different servers; add the database business request to the request queue corresponding to the target thread pool; call the thread in the target thread pool to forward the database business request to the target server.
[0128] Furthermore, the database request processing device also includes: a thread pool correspondence establishment module, which is used to create at least two thread pools and establish a correspondence between the thread pool and the server before selecting a target thread pool matching the target server from at least two thread pools according to the pre-configured correspondence between the server and the thread pool, and the server and the thread pool correspond one to one; configure the parameters of the thread pool corresponding to the server according to the information of the server and the information of the database corresponding to the server.
[0129] Furthermore, the parameters of the thread pool include at least one of the following: a minimum number of threads included in the thread pool, a maximum number of threads, a range of request numbers in a corresponding request queue, a dynamic adjustment method for the number of requests in a corresponding request queue, and an idle thread recycle time.
[0130] Furthermore, the database request processing device also includes: an exception response module, which is used to stop calling the threads in the target thread pool if it is determined that an exception occurs in the target server, and stop forwarding the database business requests in the request queue corresponding to the target thread pool to the target server; and stop adding the database business requests to the request queue corresponding to the target thread pool.
[0131] Furthermore, the database request processing device also includes: a request switching forwarding module, which is used to select a switching server that matches the database selection parameters from at least two servers while stopping forwarding the database business request in the request queue corresponding to the target thread pool to the target server, and the switching server is different from the target server; add the database business request to the request queue corresponding to the switching thread pool corresponding to the switching server; call the thread in the switching thread pool to forward the database business request to the switching server to instruct the switching server to process the switching database corresponding to the switching server according to the database business request.
[0132] Furthermore, the abnormal response module includes: a waiting timeout judgment unit, which is used to determine that an abnormality has occurred in the target server if the waiting time of the response data matching the target database business request is greater than a preset time threshold, and the target database business request is a database business request forwarded to the target server; and / or if the number of waiting timeouts for the response data is greater than a preset number threshold, it is determined that an abnormality has occurred in the target server.
[0133] Furthermore, the database request processing device also includes: before determining that an abnormality has occurred in the target server, a database service request monitoring module is used to monitor the target database service request and obtain monitoring data matching the target database service request, wherein the monitoring data includes the waiting time for response data and / or the number of waiting timeouts for response data.
[0134] Furthermore, the database request processing device also includes: a request current limiting module, which is used to stop receiving database service requests if it is determined that the number of requests received within a set time period is greater than a set threshold.
[0135] Furthermore, the response data receiving module 530, a response data combining unit, is used to combine the response data sent by each of the target servers to form target response data, and return it to the sender of the database service request, and the number of the target servers is at least two.
[0136] The above-mentioned device can execute the database request processing method provided by the embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0137] Embodiment 6
[0138] Figure 6 A schematic diagram of the structure of a computer device provided in Embodiment 6 of the present invention. Figure 6 A block diagram of an exemplary computer device 12 suitable for use in implementing embodiments of the present invention is shown. Figure 6 The computer device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0139] like Figure 6 As shown, the computer device 12 is in the form of a general-purpose computing device. The components of the computer device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16). The computer device 12 may be a device attached to the bus.
[0140] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus structures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MCA) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.
[0141] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0142] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 6 not shown, usually called a "hard drive"). Although Figure 6 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a compact disk read-only memory (CD-ROM), a digital video disk (DVD-ROM) or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.
[0143] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0144] The computer device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), one or more devices that enable a user to interact with the computer device 12, and / or any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 22. In addition, the computer device 12 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN)) through a network adapter 20. As shown in the figure, the network adapter 20 communicates with other modules of the computer device 12 through the bus 18. It should be understood that although Figure 6Not shown, other hardware and / or software modules may be used in conjunction with the computer device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays (Redundant Arrays of Inexpensive Disks, RAID) systems, tape drives, and data backup storage systems.
[0145] The processing unit 16 executes various functional applications and data processing by running the programs stored in the system memory 28, such as implementing the database request processing method provided by any embodiment of the present invention.
[0146] Embodiment 7
[0147] Embodiment 7 of the present invention provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method provided in all the embodiments of the present invention is implemented:
[0148] That is, when the program is executed by the processor, it is implemented as follows: when a database service request is received, a database selection parameter is extracted from the database service request; at least one target server matching the database selection parameter is selected from at least two servers, and the database service request is forwarded to each of the target servers to instruct each of the target servers to process the target database corresponding to each of the target servers according to the database service request, and different databases correspond to different servers; response data sent by each of the target servers is received, and returned to the sender of the database service request.
[0149] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, - but not limited to - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a RAM, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable CD-ROM, an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, a device or a device or used in combination with it.
[0150] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0151] The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wire, optical cable, radio frequency (RF), etc., or any suitable combination of the foregoing.
[0152] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a LAN or WAN, or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0153] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A database request processing method, characterized in that: Applied to a computer device, the computer device is configured before a server, and the method comprises: When receiving a database service request, extracting a database selection parameter from the database service request; Selecting at least one target server matching the database selection parameter from at least two of the servers, and forwarding the database service request to each of the target servers to instruct each of the target servers to process the target database corresponding to each of the target servers according to the database service request, wherein different databases correspond to different servers; operations on different databases are performed by different servers to implement database isolation operations; The selecting at least one target server matching the database selection parameter from at least two of the servers comprises: when the to-be-processed data matching the database selection parameter are repeatedly stored in multiple target databases, selecting one of the multiple servers as the target server; Receiving response data sent by each of the target servers, and returning the response data to the sender of the database service request; The selecting at least one target server matching the database selection parameter from at least two servers comprises: Extract sub-database dimension information from the database selection parameter; the database is a database formed by sub-database the initial database; According to the pre-configured correspondence between the sub-database dimension information and the server, at least one target server matching the database selection parameter is selected from at least two servers, and the server corresponds to the database one by one; The forwarding the database service request to the target server includes: According to the pre-configured correspondence between the server and the thread pool, a target thread pool matching the target server is selected from at least two thread pools, where different thread pools correspond to different servers; Adding the database service request to the request queue corresponding to the target thread pool; Calling a thread in the target thread pool to forward the database service request to the target server; If it is determined that an exception occurs in the target server, then stop calling the threads in the target thread pool, and stop forwarding the database service requests in the request queue corresponding to the target thread pool to the target server; Stop adding database service requests to the request queue corresponding to the target thread pool; While stopping forwarding the database service requests in the request queue corresponding to the target thread pool to the target server, the method further includes: Selecting a switching server matching the database selection parameter from at least two servers, the switching server being different from the target server; Adding the database service request to a request queue corresponding to a switching thread pool corresponding to the switching server; The thread in the switching thread pool is called to forward the database service request to the switching server, so as to instruct the switching server to process the switching database corresponding to the switching server according to the database service request.
2. The method according to claim 1, characterized in that Before selecting at least one target server matching the database selection parameter from at least two servers according to the pre-configured correspondence between the sub-library dimension information and the server, the method further includes: Acquire at least two databases and sub-database dimension information corresponding to each of the databases, wherein the databases are formed by sub-database-ing an initial database according to the corresponding dimension information; The server corresponding to each of the databases is obtained, and a corresponding relationship between the sub-database dimension information and the server is established.
3. The method according to claim 1, characterized in that Before selecting a target thread pool matching the target server from at least two thread pools according to the pre-configured correspondence between the server and the thread pool, the method further includes: Create at least two thread pools and establish a correspondence between the thread pools and the servers, with the servers corresponding to the thread pools one to one; According to the information of the server and the information of the database corresponding to the server, the parameters of the thread pool corresponding to the server are configured.
4. The method according to claim 3, characterized in that The parameters of the thread pool include at least one of the following: the minimum number of threads included in the thread pool, the maximum number of threads, the range of the number of requests in the corresponding request queue, the dynamic adjustment method of the number of requests in the corresponding request queue, and the idle thread recovery time.
5. The method according to claim 1, characterized in that The determining that an abnormality occurs on the target server includes: If it is determined that the waiting time for the response data matching the target database service request is greater than a preset time threshold, it is determined that an abnormality occurs in the target server, and the target database service request is a database service request forwarded to the target server; and / or If it is determined that the number of waiting timeouts for the response data is greater than a preset number threshold, it is determined that an abnormality occurs in the target server.
6. The method according to claim 5, characterized in that Before determining that the target server is abnormal, the method further includes: The target database service request is monitored to obtain monitoring data matching the target database service request, wherein the monitoring data includes a waiting time for response data and / or a number of waiting timeouts for response data.
7. The method according to claim 1, characterized in that Also includes: If it is determined that the number of requests received within the set time period is greater than the set threshold, then the receiving of database service requests is stopped.
8. The method according to claim 1, characterized in that The receiving the response data sent by each of the target servers and returning the response data to the sender of the database service request includes: The response data sent by each of the target servers are combined to form target response data, and the target response data is returned to the sender of the database service request, and the number of the target servers is at least two.
9. A database request processing device, characterized in that: The device is configured on a computer device, and the computer device is configured before the server, and the device includes: A database selection parameter acquisition module, used to extract database selection parameters from the database service request when receiving the database service request; A target server forwarding module, used to select at least one target server matching the database selection parameter from at least two of the servers, and forward the database service request to each of the target servers, so as to instruct each of the target servers to process the target database corresponding to each of the target servers according to the database service request, and different databases correspond to different servers; operations on different databases are performed by different servers, so as to implement database isolation operations; A response data receiving module, used for receiving the response data sent by each of the target servers, and returning it to the sender of the database service request; The target server forwarding module is further used to: when the to-be-processed data matching the database selection parameter is repeatedly stored in multiple target databases, select one of the multiple servers as the target server; The target server forwarding module includes: a target server determination unit, configured to extract sub-library dimension information from the database selection parameter; the database is a database formed by sub-librarying the initial database; and select at least one target server matching the database selection parameter from at least two servers according to a pre-configured correspondence between the sub-library dimension information and the server, wherein the server corresponds to the database one by one; The target server forwarding module includes: A thread pool forwarding unit is used to select a target thread pool matching the target server from at least two thread pools according to a pre-configured correspondence between servers and thread pools, where different thread pools correspond to different servers; add the database service request to a request queue corresponding to the target thread pool; call a thread in the target thread pool to forward the database service request to the target server; The database request processing device further includes: an abnormal response module, which is used to stop calling threads in the target thread pool and stop forwarding database service requests in the request queue corresponding to the target thread pool to the target server if it is determined that an abnormality occurs in the target server; and stop adding database service requests to the request queue corresponding to the target thread pool; The database request processing device also includes: a request switching forwarding module, which is used to select a switching server that matches the database selection parameter from at least two servers while stopping forwarding the database business request in the request queue corresponding to the target thread pool to the target server, and the switching server is different from the target server; add the database business request to the request queue corresponding to the switching thread pool corresponding to the switching server; call the thread in the switching thread pool to forward the database business request to the switching server to instruct the switching server to process the switching database corresponding to the switching server according to the database business request.
10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the database request processing method as described in any one of claims 1-8 is implemented.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the database request processing method as described in any one of claims 1 to 8 is implemented.
