Killing method, device, computer equipment and storage medium
By obtaining the running information of the target SQL statement and querying the timeout threshold parameter table, generating and executing the kill statement, the problem of inflexible killing strategy in the existing technology is solved, and the flexibility and customization of the search and killing of SQL statements for different users is realized.
Patent Information
- Application Number
- CN202210147156.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-17
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2042-02-17
AI Technical Summary
When checking and killing abnormal SQL statements, the existing technology cannot flexibly adapt to the timeout definition of different users, resulting in poor flexibility in the checking and killing strategy.
By obtaining the operation information of the target SQL statement, including the database account identification, execution time-consuming and distributed database cluster identification, the corresponding time-out threshold value is queried in the time-out threshold parameter table. If the time-consuming exceeds the threshold value, a kill statement will be generated and the kill statement will be checked.
It realizes the flexibility of the SQL statements to detect and kill according to the timeout threshold requirements of different database accounts, and improves the customization and timeliness of the killing strategy.
Smart Images

Figure CN114490720B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a method, device, computer equipment and storage medium for detecting and killing viruses. Background Art
[0002] The data warehouse is a unified basic data platform for enterprises. The data warehouse receives various transaction details from transactional business systems by executing batch jobs, converts, integrates and processes the transaction details in batches, and organizes and stores data according to the data themes of the enterprise to provide data support for analytical applications. Generally, large enterprises use distributed databases as the infrastructure for implementing enterprise data warehouses. In order to ensure the throughput capacity of the batch and flexible query of the data mart of the entire data warehouse, it is necessary to detect and execute abnormal SQL statements in a timely manner, otherwise such SQL statements will occupy system resources and concurrent resources of the submitting user, affecting the completion time of batch jobs.
[0003] In the related art, a SQL killing tool script is developed by R&D personnel, and the SQL killing tool script is used to kill abnormal SQL statements, that is, to kill SQL that takes too long to execute. However, in the process of creating an enterprise's data warehouse, different users will be created in the distributed database used by the data warehouse according to different permissions corresponding to different business systems, and these different users have different standards for defining SQL that takes too long to execute. However, through the SQL killing tool script in the related art, only a unified SQL timeout killing strategy can be used, so that different users are killed according to the same standard, which has poor flexibility. Summary of the invention
[0004] Based on this, it is necessary to provide a method, device, computer equipment, computer-readable storage medium and computer program product that can flexibly detect and kill SQL statements initiated by different users in order to solve the above technical problems.
[0005] In a first aspect, the present application provides a method for detecting and killing viruses. The method comprises:
[0006] Acquire running information of a target SQL statement in execution state, the running information including a first identifier of a database account corresponding to executing the target SQL statement, execution time of the target SQL statement, and a second identifier of a distributed database cluster corresponding to the first identifier of the database account;
[0007] In the timeout threshold parameter table, query the target timeout threshold corresponding to the first identifier and the second identifier;
[0008] If the execution time of the target SQL statement is greater than or equal to the target timeout threshold, a target killing statement is generated;
[0009] According to the target killing statement, the target SQL statement is checked and killed.
[0010] In one of the embodiments, the operation information further includes a third identifier of the operation database corresponding to the database account;
[0011] The querying, in the timeout threshold parameter table, a target timeout threshold corresponding to the first identifier and the second identifier includes:
[0012] In the timeout threshold parameter table, extract the timeout threshold parameter sub-table corresponding to the second identifier of the distributed database cluster;
[0013] In the timeout threshold parameter sub-table, extract multiple timeout threshold parameter sub-table items corresponding to the third identifier;
[0014] In the multiple timeout threshold parameter sub-table items, a target timeout threshold corresponding to the first identifier of the database account corresponding to the execution of the target SQL statement is queried.
[0015] In one embodiment, the method further comprises:
[0016] The running information of the target SQL statement is added to a preset killing log table, wherein the running information also includes the client identifier that submits the target SQL statement and the text information of the target SQL statement.
[0017] In one embodiment, the method further comprises:
[0018] According to the second identifier of the distributed database cluster, the preset killing log table is divided to obtain a killing log sub-table corresponding to the distributed database cluster;
[0019] For each of the killing log sub-tables, sorting the database accounts according to the number of occurrences of the first identifier of each database account in the killing log sub-table to obtain a result of sorting the number of killings;
[0020] Output the sorting result of the number of times the killing is performed.
[0021] In one embodiment, the method further comprises:
[0022] Displaying a timeout threshold parameter table configuration interface; wherein the timeout threshold parameter table configuration interface includes a parameter filling area and a prompt area, the parameter filling area is used to display the timeout threshold parameter table to be filled in, and the prompt area is used to assist in filling in the timeout threshold parameter table;
[0023] In response to the parameter input operation, obtaining target parameter information included in the parameter input operation, the target parameter information including a timeout threshold parameter corresponding to each of the database accounts, a first identifier of the database account, and a second identifier of the distributed database cluster;
[0024] A timeout threshold parameter table is generated according to the target parameter information and the timeout threshold parameter table to be filled in, and the timeout threshold parameter table is stored in a target database.
[0025] In one embodiment, the method further comprises:
[0026] According to a preset time interval, periodically obtain a timeout threshold parameter table from a target database;
[0027] When the timeout threshold parameter table is updated, the timeout threshold parameter table is formatted and the timeout threshold parameter table after the format conversion is stored in a preset cache server.
[0028] In one of the embodiments, the operation information further includes target session identification information corresponding to the target SQL statement;
[0029] The step of checking and killing the target SQL statement according to the target checking and killing statement includes:
[0030] Based on the target killing statement, the target session corresponding to the target session identification information is killed on the running database corresponding to the database account, and the target session is a session that runs the target SQL statement.
[0031] In a second aspect, the present application also provides a detection and killing device. The device comprises:
[0032] An acquisition module, configured to acquire operation information of a target SQL statement in execution state, wherein the operation information includes a first identifier of a database account corresponding to executing the target SQL statement, execution time of the target SQL statement, and a second identifier of a distributed database cluster corresponding to the first identifier of the database account;
[0033] A query module, used to query a timeout threshold parameter table for a target timeout threshold corresponding to the first identifier and the second identifier;
[0034] A generating module, configured to generate a target killing statement if the execution time of the target SQL statement is greater than or equal to the target timeout threshold;
[0035] The killing module is used to kill the target SQL statement according to the target killing statement.
[0036] In one of the embodiments, the operation information further includes a third identifier of the operation database corresponding to the database account;
[0037] The query module is specifically used for:
[0038] In the timeout threshold parameter table, extract the timeout threshold parameter sub-table corresponding to the second identifier of the distributed database cluster;
[0039] In the timeout threshold parameter sub-table, extract multiple timeout threshold parameter sub-table items corresponding to the third identifier;
[0040] In the multiple timeout threshold parameter sub-table items, a target timeout threshold corresponding to the first identifier of the database account corresponding to the execution of the target SQL statement is queried.
[0041] In one embodiment, the device further comprises:
[0042] The adding module is used to add the running information of the target SQL statement to the preset killing log table, wherein the running information also includes the client identifier that submits the target SQL statement and the text information of the target SQL statement.
[0043] In one embodiment, the device further comprises:
[0044] A partitioning module, configured to partition the preset killing log table according to the second identifier of the distributed database cluster to obtain a killing log sub-table corresponding to the distributed database cluster;
[0045] A sorting module is used to sort each of the database accounts according to the number of occurrences of the first identifier of each database account in the kill log sub-table, and obtain a result of the number of kills;
[0046] The killing result output module is used to output the ranking result of the number of times the killing is performed.
[0047] In one embodiment, the device further comprises:
[0048] A display module, used to display a timeout threshold parameter table configuration interface; wherein the timeout threshold parameter table configuration interface includes a parameter filling area and a prompt area, the parameter filling area is used to display the timeout threshold parameter table to be filled in, and the prompt area is used to assist in filling in the timeout threshold parameter table;
[0049] a target parameter information acquisition module, configured to, in response to a parameter input operation, acquire target parameter information included in the parameter input operation, wherein the target parameter information includes a timeout threshold parameter corresponding to each of the database accounts, a first identifier of the database account, and a second identifier of the distributed database cluster;
[0050] The storage module is used to generate a timeout threshold parameter table according to the target parameter information and the timeout threshold parameter table to be filled in, and store the timeout threshold parameter table in a target database.
[0051] In one embodiment, the device further comprises:
[0052] A periodic module, used to periodically obtain a timeout threshold parameter table from a target database at a preset time interval;
[0053] The updating module is used to convert the format of the timeout threshold parameter table when there is an update to the timeout threshold parameter table, and store the timeout threshold parameter table after the conversion to a preset cache server.
[0054] In one of the embodiments, the operation information further includes target session identification information corresponding to the target SQL statement;
[0055] The killing module is specifically used for:
[0056] Based on the target killing statement, the target session corresponding to the target session identification information is killed on the running database corresponding to the database account, and the target session is a session that runs the target SQL statement.
[0057] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0058] Acquire running information of a target SQL statement in execution state, the running information including a first identifier of a database account corresponding to executing the target SQL statement, execution time of the target SQL statement, and a second identifier of a distributed database cluster corresponding to the first identifier of the database account;
[0059] In the timeout threshold parameter table, query the target timeout threshold corresponding to the first identifier and the second identifier;
[0060] If the execution time of the target SQL statement is greater than or equal to the target timeout threshold, a target killing statement is generated;
[0061] According to the target killing statement, the target SQL statement is checked and killed.
[0062] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0063] Acquire running information of a target SQL statement in execution state, the running information including a first identifier of a database account corresponding to executing the target SQL statement, execution time of the target SQL statement, and a second identifier of a distributed database cluster corresponding to the first identifier of the database account;
[0064] In the timeout threshold parameter table, query the target timeout threshold corresponding to the first identifier and the second identifier;
[0065] If the execution time of the target SQL statement is greater than or equal to the target timeout threshold, a target killing statement is generated;
[0066] According to the target killing statement, the target SQL statement is checked and killed.
[0067] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0068] Acquire running information of a target SQL statement in execution state, the running information including a first identifier of a database account corresponding to executing the target SQL statement, execution time of the target SQL statement, and a second identifier of a distributed database cluster corresponding to the first identifier of the database account;
[0069] In the timeout threshold parameter table, query the target timeout threshold corresponding to the first identifier and the second identifier;
[0070] If the execution time of the target SQL statement is greater than or equal to the target timeout threshold, a target killing statement is generated;
[0071] According to the target killing statement, the target SQL statement is checked and killed.
[0072] The above-mentioned killing method, device, computer equipment, storage medium and computer program product obtain the first identifier of the database account of the target SQL statement in the execution state, the execution time, and the second identifier of the distributed database cluster corresponding to the first identifier of the database account; in this way, the target timeout threshold corresponding to the first identifier and the second identifier can be queried in the timeout threshold parameter table; if the execution time of the target SQL statement is greater than or equal to the target timeout threshold, a target killing statement is generated; according to the target killing statement, the target SQL statement is killed. The killing method provided by the embodiment of the present invention can realize flexible killing and customized killing of SQL statements according to different timeout threshold requirements of different database accounts. When an SQL statement with execution timeout is found, the killing strategy will be automatically triggered, so as to achieve active intervention in the SQL statement during the execution of the SQL statement, and ensure the timeliness of killing the SQL statement. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] Figure 1 A schematic diagram of a process flow of a method for detecting and killing viruses in an embodiment;
[0074] Figure 2 A schematic diagram of a flow chart of a step of searching for a target timeout threshold in an embodiment;
[0075] Figure 3 A schematic diagram of a flow chart of a step of outputting a result of ranking the number of times of being checked and killed in one embodiment;
[0076] Figure 4 A schematic diagram of a flow chart of steps for generating a timeout threshold parameter table in one embodiment;
[0077] Figure 5 A schematic diagram of a flow chart of the steps of updating a cache server in one embodiment;
[0078] Figure 6 A schematic diagram of a killing system in one embodiment;
[0079] Figure 7 is a structural block diagram of a killing device in an embodiment;
[0080] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0081] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0082] In one embodiment, Figure 1As shown, a detection and killing method is provided, which can be applied to a terminal, a server, or a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. The above-mentioned terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server can be implemented with an independent server or a server cluster composed of multiple servers. In this embodiment, the detection and killing method is applied to a server as an example, where the server can be called an application server. The detection and killing method includes the following steps:
[0083] Step 102: Obtain the running information of the target SQL statement in the execution state.
[0084] The running information includes the first identifier of the database account corresponding to the target SQL statement, the execution time of the target SQL statement, and the second identifier of the distributed database cluster corresponding to the first identifier of the database account. The distributed database cluster contains multiple databases. The execution time of the target SQL statement is the length of time the target SQL statement has been running on the database in the distributed database cluster.
[0085] Specifically, the target SQL statement in execution state refers to the SQL statement being executed in the database of the distributed database cluster. The specific process of the SQL statement being executed on the database may be: the SQL statement is run on the session, the session generates multiple threads in the database, and the multiple threads are executed in the database of the distributed database cluster. The application server obtains the first identifier of the database account of the target SQL statement in execution state, the execution time, and the second identifier of the distributed database cluster to which the database logged in by the database account belongs.
[0086] Optionally, the application server may obtain the running information of the target SQL statement from the system view of the database logged in by the database account.
[0087] Step 104: In the timeout threshold parameter table, query the target timeout threshold corresponding to the first identifier and the second identifier.
[0088] The timeout threshold parameter table is a table storing each database account of each database included in each distributed database cluster and the pre-set timeout threshold of the database account. The timeout threshold can be determined based on the data in the historical time period. Through the timeout threshold corresponding to the SQL statement executed by each database account on the database in the distributed database cluster, the specific value of the timeout threshold can be set according to the user who logs in to the database account, so as to realize the personalized customization of the timeout threshold.
[0089] Specifically, the application server can obtain a timeout threshold parameter table from a preset cache server, and query the timeout threshold parameter table for a target timeout threshold corresponding to a first identifier of a database account that executes the target SQL statement and a second identifier of a distributed database cluster to which the database account belongs.
[0090] Step 106: If the execution time of the target SQL statement is greater than or equal to the target timeout threshold, a target killing statement is generated.
[0091] Specifically, if the application server determines that the target SQL statement has been executed for a time period greater than or equal to the timeout threshold corresponding to the database account, the application server generates a target killing statement for killing the target SQL statement.
[0092] Step 108, according to the target killing statement, the target SQL statement is checked and killed.
[0093] Specifically, based on the generated target killing statement, the application server can run the target killing statement on the database to achieve the killing of the target SQL statement.
[0094] In the above-mentioned killing method, the first identifier of the database account of the target SQL statement in the execution state, the execution time, and the second identifier of the distributed database cluster corresponding to the first identifier of the database account are obtained; in this way, the target timeout threshold corresponding to the first identifier and the second identifier can be queried in the timeout threshold parameter table; if the execution time of the target SQL statement is greater than or equal to the target timeout threshold, a target killing statement is generated; according to the target killing statement, the target SQL statement is killed. The killing method provided by the embodiment of the present invention can realize flexible killing and customized killing of SQL statements according to different timeout threshold requirements of different database accounts. When an SQL statement with execution timeout is found, the killing strategy will be automatically triggered, so as to achieve active intervention in the SQL statement during the execution of the SQL statement, and ensure the timeliness of killing the SQL statement.
[0095] In one embodiment, the operation information is the operation related information of the target SQL statement that is in the running state on the database, and the database logged in by the database account is the database that is running the target SQL statement, that is, the running database. In this way, the operation information also includes the third identifier of the running database corresponding to the database account. That is, the identifier of the database logged in by the database account, that is, the third identifier.
[0096] Accordingly, if Figure 2 As shown, the specific processing process of step 104 "querying the target timeout threshold corresponding to the first identifier and the second identifier in the timeout threshold parameter table" includes:
[0097] Step 202: extract the timeout threshold parameter sub-table corresponding to the second identifier of the distributed database cluster from the timeout threshold parameter table.
[0098] Specifically, the timeout threshold parameter table may include multiple timeout threshold parameter sub-tables. Each timeout threshold parameter sub-table is divided according to the identifier of the distributed database cluster. In this way, the application server can extract the timeout threshold parameter sub-table corresponding to the second identifier of the distributed database cluster from the timeout threshold parameter table.
[0099] Step 204: extract multiple timeout threshold parameter sub-table entries corresponding to the third identifier from the timeout threshold parameter sub-table.
[0100] Specifically, the distributed database cluster includes multiple databases, and the third identifier is the identifier of the database that is running the target SQL statement. In this way, the application server can extract multiple timeout threshold parameter sub-table items corresponding to the third identifier from the timeout threshold parameter sub-table corresponding to the second identifier.
[0101] Step 206 , query the target timeout threshold corresponding to the first identifier of the database account corresponding to the target SQL statement in the multiple timeout threshold parameter sub-table items.
[0102] Specifically, the application server may query the target timeout threshold corresponding to the first identifier of the database account corresponding to the execution of the target SQL statement in the multiple timeout threshold parameter sub-table items corresponding to the extracted third identifier.
[0103] In one example, the first identifier (database account identifier) of the database account corresponding to executing the target SQL statement can be isfc_query; the second identifier (cluster identifier) of the distributed database cluster can be BDSPCluster; the third identifier (i.e., database identifier) of the running database that is running the target SQL statement can be bdsp.
[0104] Specifically, the timeout threshold parameter sub-table corresponding to the second identifier (BDSPCluster) of the distributed database cluster extracted by the application server in the timeout threshold parameter table may be as shown in the following Table 1:
[0105] Table 1
[0106] Cluster ID Database ID Database Account Timeout threshold (minutes) BDSPCluster bdsp isfc_user 120 BDSPCluster ccrm ccrm_adm 180 BDSPCluster ccrm ccrm_batch_user 180 BDSPCluster ccrm ccrm_icps_user 180 BDSPCluster ccrm ccrm_icps_web_user 180 BDSPCluster ccrm ccrm_web_user 180 BDSPCluster bdsp bdp_user 180 BDSPCluster bdsp cap_user 90 BDSPCluster bdsp alm_user 120 BDSPCluster bdsp crem_user 60 BDSPCluster bdsp mpvs_user 240 BDSPCluster bdsp fgl_user 180 BDSPCluster bdsp isfc_query 60 BDSPCluster bdsp etlmc_user 720 BDSPCluster ccrm etlmc_user 720 BDSPCluster bdsp cra_user 120
[0107] In this way, the terminal extracts multiple timeout threshold parameter sub-table items corresponding to the third identifier (bdsp) in the timeout threshold parameter sub-table corresponding to the second identifier (BDSPCluster) as shown in the following Table 2:
[0108] Table 2
[0109] Cluster ID Database ID Database Account Timeout threshold (minutes) BDSPCluster bdsp isfc_user 120 BDSPCluster bdsp bdp_user 180 BDSPCluster bdsp cap_user 90 BDSPCluster bdsp alm_user 120 BDSPCluster bdsp crem_user 60 BDSPCluster bdsp mpvs_user 240 BDSPCluster bdsp fgl_user 180 BDSPCluster bdsp isfc_query 60 BDSPCluster bdsp etlmc_user 720 BDSPCluster bdsp cra_user 120
[0110] In this way, the terminal queries in multiple timeout threshold parameter sub-table items the target timeout threshold corresponding to the first identifier (isfc_query) of the database account corresponding to the target SQL statement to be executed, which may be 60 minutes.
[0111] In this embodiment, by querying the timeout threshold corresponding to the database account corresponding to the execution of the target SQL statement, it is possible to detect and kill SQL statements corresponding to different detection and killing strategies corresponding to different database accounts on different databases, which has the flexibility of detection and killing and can be customized according to different database accounts.
[0112] In another possible implementation, if the first identifier of the database account corresponding to the execution of the target SQL statement is not unique in the timeout threshold parameter table, the process of steps 202 to 206 can be performed; if the first identifier of the database account corresponding to the execution of the target SQL statement is unique in the timeout threshold parameter table, then the application server can directly extract the unique timeout threshold parameter table item corresponding to the first identifier in the timeout threshold parameter table to determine the target timeout threshold corresponding to the first identifier.
[0113] In this embodiment, by determining whether the first identifier is unique in the timeout threshold parameter table, a simpler and more accurate method can be used to query the target timeout threshold corresponding to the first identifier.
[0114] In one embodiment, the killing method further includes:
[0115] Add the target SQL statement's running information to the preset killing log table.
[0116] The running information also includes the client identifier that submits the target SQL statement and the text information of the target SQL statement.
[0117] Specifically, if the execution time of the target SQL statement is greater than or equal to the target timeout threshold, the terminal generates a target killing statement, and the terminal also adds the running information of the target SQL statement to be killed to the preset killing log table. In this way, the terminal can store the identification information of the database account that executes the target SQL statement, the execution time of the target SQL statement, the client identification that submits the target SQL statement, the text information of the target SQL statement, the session identification information corresponding to the target SQL statement, and the identification information of the distributed database cluster to which the database that executes the target SQL statement belongs to the preset killing log table.
[0118] In this embodiment, the terminal can query the preset killing table to count the distribution of the target SQL statements to be killed in terms of database account dimension, distributed database cluster dimension, dimension of the client identifier that submits the target SQL statement, etc.
[0119] In one embodiment, Figure 3 As shown, the killing method also includes:
[0120] Step 302: divide the preset killing log table according to the second identifier of the distributed database cluster to obtain a killing log sub-table corresponding to the distributed database cluster.
[0121] Specifically, the terminal can divide the preset killing log table in terms of the distributed database cluster dimension based on the second identifier of each distributed database cluster to obtain multiple killing log sub-tables, wherein the killing log sub-tables correspond to the distributed database clusters one by one.
[0122] Optionally, the terminal may count the number of SQL statements that are killed contained in each killing log sub-table to obtain a distributed database cluster ranking of the number of times the SQL statements are killed.
[0123] Step 304: for each kill log sub-table, sort each database account according to the number of occurrences of the first identifier of each database account in the kill log sub-table to obtain a sorting result of the number of kills.
[0124] Specifically, in each kill log subtable, the terminal can count the number of occurrences of the first identifier of each database account in the kill log subtable. The terminal can sort the database accounts in order of the number of occurrences of the database accounts, and obtain the sorting result of the number of kills of each database account.
[0125] Step 306, output the result of the sorting of the number of times the devices have been checked and killed.
[0126] In this embodiment, by counting the number of times SQL statements on database accounts in each distributed database cluster are checked and killed, statistics can be collected on the SQL statements of different database accounts in weekly and monthly time periods, and database accounts with too high rankings can be managed, and the R&D personnel using the database accounts can be urged to rectify and manage various program problems with timed SQL statements. If the account with too many SQL statements checked and killed is an account that submits SQL statements with flexible query functions, it means that the business personnel corresponding to the account lack the ability to master the flexible query functions of SQL statements. The business personnel corresponding to such accounts can be gathered together for SQL training and SQL optimization method training to reduce the generation of timed SQL statements.
[0127] In one embodiment, Figure 4 As shown, the killing method also includes:
[0128] Step 402: Display the timeout threshold parameter table configuration interface.
[0129] Among them, the timeout threshold parameter table configuration interface includes a parameter filling area and a prompt area. The parameter filling area is used to display the timeout threshold parameter table to be filled in, and the prompt area is used to assist in filling in the timeout threshold parameter table.
[0130] Specifically, the terminal includes a display control for a timeout threshold parameter table configuration interface, and the user triggers the display control. The terminal responds to the user's trigger operation and displays the timeout threshold parameter table configuration interface. The specific process of interface display may be: the terminal responds to the user's trigger operation and displays the timeout threshold parameter table to be filled in and the prompt information corresponding to the above form on the terminal. The timeout threshold parameter table to be filled in is displayed in the form filling area, and the prompt information is displayed in the prompt area.
[0131] Optionally, the terminal may also display the timeout threshold parameter table configuration interface without a trigger operation by the user.
[0132] Step 404: In response to the parameter input operation, obtain target parameter information included in the parameter input operation.
[0133] The target parameter information includes a timeout threshold parameter corresponding to each database account, a first identifier of the database account, and a second identifier of the distributed database cluster.
[0134] Step 406: Generate a timeout threshold parameter table according to the target parameter information and the timeout threshold parameter table to be filled in, and store the timeout threshold parameter table in the target database.
[0135] Specifically, in response to the parameter input operation of the user device, the terminal can obtain the target parameter information corresponding to the parameter input operation, that is, the timeout threshold parameter corresponding to each database account, the first identifier of the database account, and the second identifier of the distributed database cluster. In this way, the terminal can generate a timeout threshold parameter table according to the target parameter information and the timeout threshold parameter table to be filled in, and store the timeout threshold parameter table in the target database. The target database can be a relational database.
[0136] In this embodiment, different SQL execution timeout thresholds can be set for different database accounts, which provides better flexibility.
[0137] In one embodiment, Figure 5 As shown, the killing method also includes:
[0138] Step 502: periodically obtain a timeout threshold parameter table from a target database at a preset time interval.
[0139] Specifically, the preset time interval may be a value determined according to an actual application scenario, or may be a time interval value input by a user obtained by the terminal. The application server periodically obtains the timeout threshold parameter table from the target database according to the preset time interval. The target database may be a relational database connected to the application server.
[0140] Step 504: when there is an update to the timeout threshold parameter table, convert the format of the timeout threshold parameter table, and store the converted timeout threshold parameter table in a preset cache server.
[0141] Specifically, the application server periodically obtains the timeout threshold parameter table from the target database at a preset time interval. At the current moment, the application server determines that the obtained timeout threshold parameter table is different from the timeout threshold parameter table at the previous moment, that is, the timeout threshold parameter table at the current moment is updated, then the application server needs to update the timeout threshold parameter table in the preset cache server. In other words, the application server obtains the timeout threshold parameter table stored in the relational database, and when it is determined that the timeout threshold parameter table is updated, the timeout threshold parameter table will be formatted, for example, the timeout threshold parameter table may be converted into a KV format (key-Value format, key-value pair format), and the converted timeout threshold parameter table is stored in the preset cache server.
[0142] Optionally, the application server can start a cache maintenance project, which is used to maintain data in a preset cache server. For example, the application server can start the cache maintenance project and start a background thread at the same time, and use the background thread to read the common parameter table data of the cache maintenance project stored in the target database (relational database) at a preset time interval, and store it in the preset cache server (Redis cache). The common parameter table data may include a timeout threshold parameter table and connection string information, connection user name, connection encryption password, and driver name of each set of distributed database clusters.
[0143] In one embodiment, since the SQL statement is executed on the session, that is, caused by the session, the execution information also includes target session identification information corresponding to the target SQL statement.
[0144] Accordingly, the specific execution process of step 108 "checking and killing the target SQL statement according to the target checking and killing statement" includes:
[0145] Based on the target killing statement, the target session corresponding to the target session identification information is killed on the running database corresponding to the database account.
[0146] The target session is a session that runs the target SQL statement. The specific process of the target session running the target SQL statement may be that the target session generates multiple threads corresponding to the target SQL statement on the running database, and runs the target SQL statement by executing the multiple threads.
[0147] Specifically, the process of the application server checking and killing the target session corresponding to the target session identification information may be to call a preset checking and killing interface of the distributed database cluster corresponding to the running database corresponding to the database account to check and kill the target session, that is, to check and kill multiple threads corresponding to the distributed database cluster corresponding to the target session, to achieve the killing of the target session, that is, to achieve the killing of the target SQL statement in the user dimension.
[0148] The present invention also provides a detection and killing system. The following is a detailed description of the detection and killing system provided by an embodiment of the present invention in conjunction with a schematic diagram. Figure 6 As shown, it may include multiple distributed database clusters, application servers, Redis cache (Redis cache server), relational databases, configuration maintenance modules, and statistical analysis modules. The multiple distributed database clusters include distributed database cluster A, distributed database cluster B, and distributed database cluster C. The killing method provided by the present invention can be applied to application servers. The specific execution process of the killing method may include:
[0149] Step 1: The application server builds cache information. The cache maintenance project is used to maintain data in the preset cache server. For example, the application server can start the cache maintenance project and start a background thread at the same time. The background thread reads the common parameter table data of the cache maintenance project stored in the target database (relational database) at a preset time interval and stores it in the preset cache server (Redis cache). The common parameter table data may include the timeout threshold parameter table and the connection string information, connection user name, connection encryption password, and driver name of each set of distributed database clusters.
[0150] Step 2: Obtain the running information of the target SQL statement in the execution state. Specifically, the application server can obtain the running information of the target SQL statement in the execution state by reading the data audit log table of the distributed database. The running information includes the first identifier of the database account corresponding to the execution target SQL statement, the execution time of the target SQL statement, the second identifier of the distributed database cluster corresponding to the first identifier of the database account, the third identifier of the running database corresponding to the database account, the client identifier that submits the target SQL statement, the text information of the target SQL statement, etc. That is, the relevant information of the SQL statement that is in the execution state on the distributed database cluster, specifically including the database account identifier information of the SQL execution, the execution time of the SQL statement, the IP address information of the client that submits the SQL, the name of the connected database, and the text information of the SQL statement, the session identifier information, etc., plus the connected distributed database cluster identifier.
[0151] Step 3: The application server compares the execution time of the acquired target SQL statement with the timeout threshold corresponding to the database account that submitted the target SQL statement. If the comparison result is that the execution time is less than the timeout threshold corresponding to the corresponding database account, no processing will be performed; if the comparison result is that the execution time is greater than or equal to the timeout threshold corresponding to the database account, the target SQL statement will be checked and killed according to the session information corresponding to the target SQL statement.
[0152] Step 4: The application server records the running information of the SQL statement being checked and killed into the preset killing log table. In other words, the application server adds the database account that executes the SQL statement, the execution time of the SQL statement, the client IP address that submits the SQL statement, the SQL statement text information, the session ID that caused the SQL statement, and the distributed database cluster ID information to the killing log table, which can be used for subsequent query statistics.
[0153] Step 5: Query and analyze statistics. The statistical analysis module can query and analyze the top-ranked accounts based on the distributed database cluster identifier and database account summary by checking the log table.
[0154] Step 6: Configuration management. The configuration maintenance module can provide maintenance of the data in the parameter table on the front-end web page (timeout threshold parameter table configuration interface and distributed database cluster connection parameter table configuration interface). The application server can generate a distributed database cluster connection parameter table and a database account timeout threshold setting table based on the parameter table configuration interface and the user's parameter configuration operations.
[0155] Optionally, the connection process between the preset cache server (Redis cache server) and the application server may include:
[0156] Step A0: The application server obtains the connection address of the relational database, that is, the application server connects to the relational database.
[0157] Step A1: The application server obtains the connection address of the preset cache server, that is, the application server connects to the preset cache server.
[0158] Step A2: The application server obtains relevant data of the distributed database cluster connection parameter table from the relational database.
[0159] Step A3: The application server writes the acquired data to the preset cache server (Redis cache server). The specific writing process may include: the application server writes the acquired data to the preset cache server in KV format using the table name and database cluster code as key, and the database account (check and kill permission), account password, and connection driver name as value.
[0160] Step A4: The application server obtains relevant data of the database account timeout threshold setting table from the relational database.
[0161] Step A5: Use the table name, database cluster code identifier, and database account as the key, and the timeout threshold field as the value to write the KV to the preset cache server.
[0162] Step A6: The application server releases connection resources, closes the relational database connection, and closes the redis connection. That is, the application server disconnects from the relational database and disconnects from the preset cache server.
[0163] Step A7: Wait for the next cache update to keep the Redis cache data synchronized with the data in the parameter table in the relational database.
[0164] The present invention provides a method for checking and killing that can set SQL execution timeout thresholds based on different database accounts, thereby realizing the checking and killing of SQL execution timeouts for these database accounts. The method for checking and killing provided by the present invention can realize centralized monitoring and checking and killing. Centralized management and control of multiple database account checking and killing strategies are realized. Customized SQL timeout judgment can also be realized, and different SQL execution timeout thresholds are set for different database accounts, which has better flexibility. The method for checking and killing provided by the present invention will automatically trigger the checking and killing strategy when SQL execution timeouts are found, thereby achieving active intervention during the event, avoiding intervention by operation and maintenance personnel afterwards, ensuring the smooth operation of the distributed database cluster, effectively guaranteeing the timeliness of batch operations of each database account, and guaranteeing the timely response of various flexible query SQL statements.
[0165] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0166] Based on the same inventive concept, the embodiment of the present application also provides a killing device for implementing the above-mentioned killing method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in one or more killing device embodiments provided below can refer to the limitations of the killing method above, and will not be repeated here.
[0167] In one embodiment, Figure 7 As shown, a detection and killing device 600 is provided, comprising: an acquisition module 601, a query module 602, a generation module 603 and a detection and killing module 604, wherein:
[0168] The acquisition module 601 is used to obtain the running information of the target SQL statement in the execution state, and the running information includes the first identifier of the database account corresponding to the execution of the target SQL statement, the execution time of the target SQL statement, and the second identifier of the distributed database cluster corresponding to the first identifier of the database account.
[0169] The query module 602 is used to query the target timeout threshold corresponding to the first identifier and the second identifier in the timeout threshold parameter table.
[0170] The generating module 603 is used to generate a target killing statement if the execution time of the target SQL statement is greater than or equal to the target timeout threshold.
[0171] The checking and killing module 604 is used to check and kill the target SQL statement according to the target checking and killing statement.
[0172] In one of the embodiments, the operation information further includes a third identifier of the operation database corresponding to the database account;
[0173] The query module is specifically used for:
[0174] In the timeout threshold parameter table, extract the timeout threshold parameter sub-table corresponding to the second identifier of the distributed database cluster;
[0175] In the timeout threshold parameter sub-table, extract multiple timeout threshold parameter sub-table items corresponding to the third identifier;
[0176] In the multiple timeout threshold parameter sub-table items, a target timeout threshold corresponding to the first identifier of the database account corresponding to the execution of the target SQL statement is queried.
[0177] In one embodiment, the device further comprises:
[0178] The adding module is used to add the running information of the target SQL statement to the preset killing log table, wherein the running information also includes the client identifier that submits the target SQL statement and the text information of the target SQL statement.
[0179] In one embodiment, the device further comprises:
[0180] A partitioning module, configured to partition the preset killing log table according to the second identifier of the distributed database cluster to obtain a killing log sub-table corresponding to the distributed database cluster;
[0181] A sorting module is used to sort each of the database accounts according to the number of occurrences of the first identifier of each database account in the kill log sub-table, and obtain a result of the number of kills;
[0182] The killing result output module is used to output the ranking result of the number of times the killing is performed.
[0183] In one embodiment, the device further comprises:
[0184] A display module, used to display a timeout threshold parameter table configuration interface; wherein the timeout threshold parameter table configuration interface includes a parameter filling area and a prompt area, the parameter filling area is used to display the timeout threshold parameter table to be filled in, and the prompt area is used to assist in filling in the timeout threshold parameter table;
[0185] a target parameter information acquisition module, configured to, in response to a parameter input operation, acquire target parameter information included in the parameter input operation, wherein the target parameter information includes a timeout threshold parameter corresponding to each of the database accounts, a first identifier of the database account, and a second identifier of the distributed database cluster;
[0186] The storage module is used to generate a timeout threshold parameter table according to the target parameter information and the timeout threshold parameter table to be filled in, and store the timeout threshold parameter table in a target database.
[0187] In one embodiment, the device further comprises:
[0188] A periodic module, used to periodically obtain a timeout threshold parameter table from a target database at a preset time interval;
[0189] The updating module is used to convert the format of the timeout threshold parameter table when there is an update to the timeout threshold parameter table, and store the timeout threshold parameter table after the conversion to a preset cache server.
[0190] In one of the embodiments, the operation information further includes target session identification information corresponding to the target SQL statement;
[0191] The killing module is specifically used for:
[0192] Based on the target killing statement, the target session corresponding to the target session identification information is killed on the running database corresponding to the database account, and the target session is a session that runs the target SQL statement.
[0193] Each module in the above-mentioned anti-virus device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0194] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 8As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store relevant data of SQL statements. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a killing method is implemented.
[0195] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0196] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0197] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0198] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0199] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0200] It should be noted that the methods and devices of the embodiments of the present disclosure can be used in the field of artificial intelligence technology, the field of financial technology or other related fields, and the methods and devices of the embodiments of the present disclosure are not limited to the application fields.
[0201] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0202] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0203] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method of killing. It is characterized in that The method comprises: Acquire running information of a target SQL statement in execution state, the running information including a first identifier of a database account corresponding to executing the target SQL statement, execution time of the target SQL statement, and a second identifier of a distributed database cluster corresponding to the first identifier of the database account; In the timeout threshold parameter table, query the target timeout threshold corresponding to the first identifier and the second identifier; If the execution time of the target SQL statement is greater than or equal to the target timeout threshold, a target killing statement is generated; According to the target killing statement, the target SQL statement is killed; The method further comprises: Adding the running information of the target SQL statement to a preset killing log table, the running information also includes the client identifier that submits the target SQL statement and the text information of the target SQL statement; According to the second identifier of the distributed database cluster, the preset killing log table is divided to obtain a killing log sub-table corresponding to the distributed database cluster; For each of the killing log sub-tables, the database accounts are sorted according to the number of occurrences of the first identifier of each database account in the killing log sub-table to obtain a killing number sorting result; and the killing number sorting result is output.
2. The method according to claim 1, It is characterized in that The operation information also includes a third identifier of the operation database corresponding to the database account; The querying, in the timeout threshold parameter table, a target timeout threshold corresponding to the first identifier and the second identifier includes: In the timeout threshold parameter table, extract the timeout threshold parameter sub-table corresponding to the second identifier of the distributed database cluster; In the timeout threshold parameter sub-table, extract multiple timeout threshold parameter sub-table items corresponding to the third identifier; In the multiple timeout threshold parameter sub-table items, a target timeout threshold corresponding to the first identifier of the database account corresponding to the execution of the target SQL statement is queried.
3. The method according to claim 1, It is characterized in that The method further comprises: Displaying a timeout threshold parameter table configuration interface; wherein the timeout threshold parameter table configuration interface includes a parameter filling area and a prompt area, the parameter filling area is used to display the timeout threshold parameter table to be filled in, and the prompt area is used to assist in filling in the timeout threshold parameter table; In response to the parameter input operation, obtaining target parameter information included in the parameter input operation, the target parameter information including a timeout threshold parameter corresponding to each of the database accounts, a first identifier of the database account, and a second identifier of the distributed database cluster; A timeout threshold parameter table is generated according to the target parameter information and the timeout threshold parameter table to be filled in, and the timeout threshold parameter table is stored in a target database.
4. The method according to claim 3, It is characterized in that The method further comprises: According to a preset time interval, periodically obtain a timeout threshold parameter table from a target database; When the timeout threshold parameter table is updated, the timeout threshold parameter table is formatted and the timeout threshold parameter table after the format conversion is stored in a preset cache server.
5. The method according to claim 1, It is characterized in that The operation information also includes target session identification information corresponding to the target SQL statement; The step of checking and killing the target SQL statement according to the target checking and killing statement includes: Based on the target killing statement, the target session corresponding to the target session identification information is killed on the running database corresponding to the database account, and the target session is a session that runs the target SQL statement.
6. A detection and killing device, It is characterized in that The device comprises: An acquisition module, configured to acquire operation information of a target SQL statement in execution state, wherein the operation information includes a first identifier of a database account corresponding to the execution of the target SQL statement, execution time of the target SQL statement, and a second identifier of a distributed database cluster corresponding to the first identifier of the database account; A query module, used to query a timeout threshold parameter table for a target timeout threshold corresponding to the first identifier and the second identifier; A generating module, configured to generate a target killing statement if the execution time of the target SQL statement is greater than or equal to the target timeout threshold; A detection and killing module, used for detecting and killing the target SQL statement according to the target detection and killing statement; The device also includes: An adding module, used for adding the running information of the target SQL statement to a preset killing log table, wherein the running information also includes the client identifier submitting the target SQL statement and the text information of the target SQL statement; A partitioning module, configured to partition the preset killing log table according to the second identifier of the distributed database cluster to obtain a killing log sub-table corresponding to the distributed database cluster; A sorting module is used to sort each of the database accounts according to the number of occurrences of the first identifier of each database account in the kill log sub-table, and obtain a result of the number of kills; The killing result output module is used to output the ranking result of the number of times the killing is performed.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
9. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Mobile terminal control method, mobile terminal control device, mobile terminal and storage medium
CN107659718A
Database operation statement processing method and device, electronic equipment and medium
CN112181948A