Lock releasing method and device and electronic equipment
By identifying and releasing locks that need to be released in the database, the problem of business system interruption caused by lock timeout is solved, and business continuity and efficient processing are achieved.
Patent Information
- Application Number
- CN202311391079.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-24
- Publication Date
- 2024-10-18
AI Technical Summary
In the existing technology, the collective timeout caused by lock timeout during the peak period of the business causes the business system to be interrupted, and the business continuity cannot be guaranteed.
By obtaining multiple data tables and table data in the database, determine the total number of records, lock holding ratio and alarm indicators of each data table, identify the target data table that needs to release the lock, and release the lock when there is a locked record, so as to Early warning and handling of congestion.
It avoids business system interruption, ensures business continuity, and reduces economic losses and user experience problems caused by lock timeouts.
Smart Images

Figure CN118796847A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database operation and maintenance, and in particular to a lock releasing method, device and electronic equipment. Background Art
[0002] At present, whether it is a single-process program, a multi-process program, or a distributed system, it needs to face a common problem in concurrent program processing, that is, how to ensure the timing, atomicity, and consistency of read and write operations on shared resources in concurrent scenarios. Especially in the database, it is absolutely not allowed for two different threads to modify the same record in the database at the same time, otherwise it will cause data overwrite problems due to concurrent data writing. In order to avoid data overwrite problems caused by such concurrent data writing, it is generally considered to lock the data that needs to be updated at present, and use locks to protect concurrent read and write data.
[0003] The existing technology monitors the holding time of each lock, and if it is found that the lock is held for too long, the lock is released according to the timeout time under the lock holding time. However, during business peak periods, a large number of locks often time out collectively. Since the data corresponding to the lock cannot be accessed when the lock times out, if the lock is released according to the lock timeout time, it will inevitably cause business system interruption, and it will take some time to get back online, and business continuity cannot be guaranteed. Summary of the invention
[0004] In view of this, the present application provides a lock releasing method, device and electronic device, the main purpose of which is to solve the technical problem that currently releasing the lock according to the lock timeout period will inevitably cause business system interruption, require waiting for a period of time to get back online, and cannot guarantee business continuity.
[0005] According to a first aspect of the present disclosure, a lock releasing method is provided, the method comprising:
[0006] Get multiple data tables in the database and table data corresponding to the multiple data tables;
[0007] Determine a first total number of records in each data table according to the table data, and determine a table type and a first lock ratio of a locked data table in each data table;
[0008] Based on the table type of the locked data table in each data table, determine a first alarm indicator corresponding to the locked data table, wherein different table types correspond to different first alarm indicators;
[0009] Determine a target data table for which an alarm needs to be issued among the multiple data tables based on a first total number of records, a first lock holding ratio, and a first alarm indicator of each data table;
[0010] It is determined whether there is a lock record in the target data table. If so, the lock corresponding to the target data table is released. The lock record is a record of a lock operation performed on the target data table.
[0011] According to a second aspect of the present disclosure, there is provided a lock releasing device, the device comprising:
[0012] An acquisition module, used to acquire multiple data tables in a database and table data corresponding to the multiple data tables;
[0013] A first determination module is used to determine a first total number of records in each data table according to the table data, and to determine a table type and a first lock ratio of a locked data table in each data table;
[0014] A second determination module is used to determine a first alarm indicator corresponding to the locked data table based on the table type of the locked data table in each data table, wherein different table types correspond to different first alarm indicators;
[0015] A third determination module is used to determine a target data table that needs to be alarmed in the multiple data tables based on the first total number of records, the first lock holding ratio and the first alarm indicator of each data table;
[0016] The first judgment module is used to judge whether there is a locking record in the target data table, and if so, release the lock corresponding to the target data table, wherein the locking record is a record of performing a locking operation on the target data table.
[0017] According to the third aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method of the aforementioned first aspect.
[0018] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the method of the aforementioned first aspect.
[0019] The lock releasing method, device and electronic device provided by the present invention, compared with the prior art, obtain multiple data tables and table data corresponding to the multiple data tables in a database; determine a first total number of records in each data table according to the table data, and determine the table type and the first lock ratio of the locked data table in each data table; determine the first alarm indicator corresponding to the locked data table based on the table type of the locked data table in each data table, wherein different table types correspond to different first alarm indicators; determine the target data table that needs to be alarmed in the multiple data tables based on the first total number of records, the first lock ratio and the first alarm indicator of each data table; determine whether there is a lock record in the target data table, and if so, release the lock corresponding to the target data table, wherein the lock record is a record when the target data table is locked. By applying the scheme disclosed in the present invention, the target data table for which an alarm needs to be issued is determined according to the first total number of records, the first lock holding ratio and the first alarm index of each data table. If there are locked records in the target data table, the lock of the target data table is released, thereby enabling early warning of congestion in the business system, allowing time to handle the impending congestion accordingly, avoiding interruption of the business system and ensuring business continuity.
[0020] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0023] Figure 1 A schematic flow chart of a lock releasing method provided by an embodiment of the present disclosure;
[0024] Figure 2 A summary statistical chart of the data table provided in the embodiment of the present disclosure;
[0025] Figure 3 A top view of a data table provided in an embodiment of the present disclosure;
[0026] Figure 4A schematic diagram of the structure of a lock release device provided in an embodiment of the present disclosure;
[0027] Figure 5 A schematic diagram of the structure of another lock release device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0028] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description. It should be noted that, in the absence of conflict, the embodiments of the present disclosure and the features in the embodiments may be combined with each other.
[0029] The lock releasing method, device and electronic device according to the embodiments of the present disclosure are described below with reference to the accompanying drawings.
[0030] The present invention provides a method, device and electronic device for releasing information locks. By releasing the locks of a target data table, early warning of congestion in a business system can be given, so that there is time to deal with the impending congestion accordingly, avoiding interruption of the business system and ensuring business continuity.
[0031] like Figure 1 As shown, an embodiment of the present disclosure provides a lock releasing method, comprising:
[0032] Step 101: Acquire multiple data tables and table data corresponding to the multiple data tables in a database.
[0033] Among them, the database is "a warehouse that organizes, stores and manages data according to the data structure". It is a collection of data that is stored in a computer for a long time, organized, shared and uniformly managed. The database is a collection of data that is stored together in a certain way, can be shared with multiple users, has as little redundancy as possible, and is independent of the application program. It can be regarded as an electronic filing cabinet - a place to store electronic files, but the speed of reading and writing data in the file is relatively slow. Users can add, query, update, delete and other operations on the data in the file.
[0034] A database is composed of a set of data tables and other related objects. For the embodiments of the present disclosure, the database is a distributed memory database as an example to illustrate the technical solution in the present disclosure, but it does not constitute a specific limitation on the technical solution in the present disclosure. Among them, a distributed database is a database that stores data in different physical locations in a dispersed manner.
[0035] A data table is an object used to store data in a database. It is a collection of structured data and the foundation of the entire database system. A data table is a database object that contains all the data in the database. It consists of a set of rows and columns. Each data table has a unique name and contains a structure that defines the names, data types, and constraints of each column. Among them, a column is a data field in a data table that is used to store a specific type of data. Each column has a name and a data type, such as an integer, character, date, etc. A row is a record in a data table that contains the specific values of each column in the table. Each row has a unique identifier, called a primary key, which is used to uniquely identify the row.
[0036] For the embodiments of the present disclosure, the execution subject may be a lock release device or equipment. The present disclosure may utilize the lock release device or equipment to use SQL query statements to obtain multiple data tables in the database, and may call table statistical functions to read table data corresponding to each data table in the database, wherein the table data includes data table name, column name, data type, etc.; wherein, SQL (Structured Query Language) query statements are a structured query language for retrieving and manipulating data from a database, and may be used to perform various operations such as selection, filtering, sorting, grouping, and calculation. The table statistical function may utilize the getTableCount() function, which is a function provided by a database management system (DBMS) for obtaining the number of tables in a database. Exemplarily, the getTableCount() function may be used to obtain the number of tables in a database, using a loop to traverse all table names, and executing a SELECT*FROM TABLE_NAME statement for each table to obtain table data.
[0037] Step 102: Determine a first total number of records in each data table according to the table data, and determine a table type and a first lock ratio of a locked data table in each data table.
[0038] The first total number of records is the total number of records in the data tables of different table types in the database; the locked data table is a data table in which records are locked by other transactions or operations at the current moment. Locking is a mechanism to ensure data consistency and avoid concurrent access conflicts. When a transaction is accessing or modifying a record in a data table, the record may be locked. This means that other transactions cannot access or modify these locked records until the lock is released.
[0039] In a database, data tables can be classified according to their purpose and nature. Common table types include system tables and business tables. System tables are pre-defined tables in the database, used to store database table data; business tables are tables created based on actual business needs, used to store business data. Compared with system tables, business tables have complex and changeable data structures, and are more likely to cause system congestion due to locking.
[0040] The first lock ratio can be the proportion of locked data in data tables under different table types. For example, if the total number of records in the statistical data table is 1,000, of which 100 are locked, then the lock ratio of the data table is 10%. The lock ratio can be used to evaluate the locking status of the data table and whether performance optimization is needed.
[0041] For the embodiment of the present disclosure, to determine the first total number of records in each data table, a SQL query statement may be used to obtain the data table name of each data table, and a table data statistics function (such as getTableCount()) may be called to count the data table name of each data table, and the first total number of records in each data table may be calculated. The first total number of records may include the total number of records in the system table and the total number of records in the business table, the total number of records in the system table may be the total number of records in the system table, and the total number of records in the business table may be the total number of records in the business table.
[0042] For the disclosed embodiment, the table type of the locked data table in each data table is determined. An SQL statement can be used to query whether there is a data table with locked records in multiple data tables, and the data table with locked records is determined as the locked data table, wherein the locked record can be a record in a data table that is locked by other transactions, resulting in other transactions being unable to update or delete the record. The locked table statistics function provided by the database is used to obtain the locked table data of the locked data table, wherein the locked table data includes locked data table attribute information, such as table name, table type attribute value, lock status, etc.
[0043] It should be noted that the distributed memory database contains several data tables, and the data tables contain records corresponding to the data. In order to protect the data, if there are operations on the data, such as insert, delete, update, select...from..., where...for update, etc., the corresponding records are locked. If the data table contains locked records, it means that the data table is locked.
[0044] By analyzing and processing the locked data table attribute information, the table type of the locked data table is obtained. As a possible implementation method, the table type can be determined according to the attribute value of the table type in the locked data table attribute information, wherein the attribute value of the table type can be a string or an integer, which is used to indicate the table type of the data table. For example, if the attribute value of the table type is "SystemTable", it indicates that the table is a system table; if the attribute value of the table type is "BusinessTable", it indicates that the table is a business table.
[0045] For the embodiments of the present disclosure, a first locking ratio of the locked data table in each data table is determined, wherein the first locking ratio may include a system table locking ratio and a business table locking ratio, wherein the system table locking ratio may be the ratio of locked data in the system table; the business table locking ratio may be the ratio of locked data in the business table.
[0046] As a possible implementation method, first, the system table name whose table type is system table can be queried in the data table through SQL statements, and the table data statistical function (such as getTableCount()) can be called to count the system table name of each system table, and the total number of system table records of each system table can be calculated; and the business table name whose table type is business table can be queried in the data table through SQL statements, and the table data statistical function (such as getTableCount()) can be called to count the business table name of each business table, and the total number of business table records of each business table can be calculated.
[0047] During database operations, some records may be locked to ensure data consistency and integrity. The number of locked records function can be used to obtain the number of locked records in system tables whose table type is system tables in multiple data tables, and the number of locked records function can be used to obtain the number of locked records in business tables whose table type is business tables in multiple data tables. The number of locked records function can be the getLockCount() function, which is used in MySQL to return the number of locks on a specified data table; the number of locked records in system tables can be the number of locked records in system tables; and the number of locked records in business tables can be the number of locked records in business tables.
[0048] After obtaining the number of system table locked records and the total number of system table records of each system table, the ratio of the number of system table locked records to the total number of system table records of each system table is determined as the system table locked ratio; and after obtaining the number of business table locked records and the total number of business table records of each business table, the ratio of the number of business table locked records to the total number of business table records of each business table is determined as the business table locked ratio.
[0049] For the embodiment of the present disclosure, after obtaining the first total number of records (total number of records), the number of locked records and the first locked ratio (locked ratio) of each data table, the data is summarized to obtain the following: Figure 2 Statistical table shown.
[0050] Step 103: Based on the table type of the locked data table in each data table, determine a first alarm indicator corresponding to the locked data table.
[0051] Among them, different table types correspond to different first alarm indicators; the first alarm indicators include the number of system table alarm records, the number of business table alarm records, the system table alarm lock ratio and the business table alarm lock ratio, among which the number of system table alarm records can be the number of times the records in the pre-set system table trigger the alarm; the number of business table alarm records can be the number of times the records in the pre-set business table trigger the alarm; the system table alarm lock ratio can be the proportion of locked data in the system table; the business table alarm lock ratio can be the proportion of locked data in the business table.
[0052] For the embodiments of the present disclosure, different first alarm indicators may be set for different types of tables. Since business tables are more likely to cause system congestion due to locking than system tables, the threshold of the business table alarm indicator corresponding to the business table is lower than the threshold of the system table alarm indicator of the system table, that is, the number of business table alarm records and the business table alarm lock ratio in the business table alarm indicator corresponding to the business table are lower than the number of system table alarm records and the system table alarm lock ratio in the system table alarm indicator corresponding to the system table. For example, the number of business table alarm records in the business table alarm indicator is set to 300, and the business table alarm lock ratio is set to 10%. The number of system table alarm records in the system table alarm indicator is set to 1000, and the system table alarm lock ratio is set to 50%.
[0053] Step 104: Determine a target data table for which an alarm is required among the multiple data tables based on the first total number of records, the first lock holding ratio, and the first alarm indicator of each data table.
[0054] For the embodiments of the present disclosure, the first total number of records and the first lock ratio of each data table can be compared with the number of system table alarm records, the number of business table alarm records, the system table alarm lock ratio and the business table alarm lock ratio in the first alarm indicator determined according to the table type, and the data table that meets the first alarm indicator is determined as the target data table. The target data table is a table that has a congestion risk and needs to be alarmed.
[0055] Exemplarily, when the total number of system table records in the system table exceeds a preset system table alarm record number threshold, and the system table lock ratio exceeds the system table alarm lock ratio, the system table is determined as a target data table that needs to be alarmed; or, when the total number of business table records in the business table exceeds a preset business table alarm record number threshold, and the business table lock ratio exceeds the business table alarm lock ratio, the business table is determined as a target data table that needs to be alarmed. Furthermore, after obtaining the target data table, the target data table is placed at the top, such as Figure 3 shown.
[0056] Step 105: Determine whether there is a locked record in the target data table. If so, release the lock corresponding to the target data table.
[0057] Among them, the lock record can be a locking operation performed on data in a database or other shared data system to ensure data consistency and prevent concurrent access conflicts. "Lock" refers to a synchronization mechanism used to control access to shared resources (such as data tables). When a thread or process needs to read or write to a shared resource, it needs to acquire a lock first. Other threads or processes cannot operate on the shared resource during this period until the lock is released.
[0058] For the disclosed embodiment, the SQL statements being executed and / or recently executed in the database session are analyzed to determine whether the SQL statements have locked the target data table. If it is determined that the SQL statement has locked N records in the target data table, the locks added to the corresponding records are released while the database session corresponding to the SQL statement is terminated, so that the congestion of the business system can be warned in advance, so that there is time to deal with the impending congestion accordingly, avoiding interruption of the business system, ensuring the continuity of the business, and avoiding economic losses caused by business paralysis due to a large number of lock timeouts or bringing a poor system experience to users. Among them, the database session is an independent unit for executing a series of SQL statements, and a session can contain one or more SQL statements; the locking operation may include SELECT FOR UPDATE, SELECT LOCK IN SHARE MODE, etc.
[0059] For the embodiments of the present disclosure, as another possible implementation method, the locking mode corresponding to the locked data table can be first determined, as well as the second total number of records and the second locking ratio of each data table under different locking modes; based on the locking mode of each locked data table, the second alarm indicator under the different locking modes is determined; according to the second total number of records, the second locking ratio and the second alarm indicator of each data table under different locking modes, the target data table that needs to be alarmed is determined; it is determined whether there is a locked record in the target data table, and if so, the database session is ended and the lock corresponding to the target data table is released.
[0060] For the disclosed embodiments, the locks in the lock data table can be first obtained, and the lock attribute information can be queried using SQL statements. The lock attribute information may include lock attributes such as lock type, lock range, lock level, and lock status. By analyzing and processing the lock attribute information, the lock mode of each record in the lock data table can be determined. Among them, the lock mode may include a shared lock mode and an exclusive lock mode. A shared lock is also called a read lock. When a record holds a read lock, other transactions can only read the data but cannot write to it. An exclusive lock is also called a write lock. When a record holds a write lock, other transactions can no longer write to the locked data. Compared with a shared lock, an exclusive lock is more likely to conflict with other locks. Too many exclusive locks are more likely to cause system congestion.
[0061] The second total number of records may be the total number of records in the data table under different locking modes in the database; the second locking ratio may be the ratio of locked data in the data table under different locking modes, and the second locking ratio may include a shared lock ratio and an exclusive lock ratio. The shared lock ratio may be the ratio of the number of records with shared locks in the data table to the second total number of records; the exclusive lock ratio may be the ratio of the number of records with exclusive locks in the data table to the second total number of records.
[0062] For the disclosed embodiment, the number of shared lock records in the shared lock mode and the number of exclusive lock records in the exclusive lock mode of each locked data table can be first obtained by using the number of locked records function, wherein the number of locked records function can be the getLockCount() function, the number of shared lock records can be the number of records locked by shared locks in the data table; the number of exclusive lock records can be the number of records locked by exclusive locks in the data table. Secondly, the data table name in each data table can be queried through SQL statements, and the table data statistics function (such as getTableCount()) can be called to count the data table name of each data table, and the second total number of records in each data table can be calculated.
[0063] After obtaining the number of shared lock records, the number of exclusive lock records and the second total number of records of each data table, the ratio of the number of shared lock records of each data table to the second total number of records is determined as the shared lock holding ratio; and after obtaining the number of exclusive lock records and the second total number of records of each data table, the ratio of the number of exclusive lock records of each data table to the second total number of records is determined as the exclusive lock holding ratio.
[0064] For example, when the second total number of records in the data table is 300, the number of records holding shared locks in the data table is 100, and the number of records holding exclusive locks is 30, the proportion of shared locks in the data table is 1 / 3, and the proportion of exclusive locks is 1 / 10.
[0065] For the disclosed embodiment, based on the lock mode of each lock data table, the second alarm index under different lock modes is determined, wherein different lock modes correspond to different second alarm indicators, and the second alarm indicators include the number of second alarm records, the shared lock alarm ratio under the shared lock mode, and the exclusive lock alarm ratio under the exclusive lock mode, wherein the number of second alarm records can be the number of times the alarm is triggered by the record in the pre-set data table; the shared lock alarm ratio can be the ratio of data locked by the shared lock in the data table. Compared with shared locks, too many exclusive locks are more likely to cause system congestion, so the exclusive lock alarm ratio corresponding to the exclusive lock is lower than the shared lock alarm ratio corresponding to the shared lock.
[0066] For example, the exclusive lock alarm lock holding ratio set for the exclusive lock is 5%, the shared lock alarm lock holding ratio set for the shared lock is 10%, and the number of second alarm records is set to 300.
[0067] For the embodiments of the present disclosure, the target data table for which an alarm needs to be issued is determined based on the second total number of records, the second locking ratio and the second alarm index of each data table under different locking modes. Specifically, the second total number of records in the data table and the locking ratio under each locking mode can be compared with the second alarm record number and different alarm locking ratios corresponding to different locking modes, and the table that meets the second alarm index can be determined as the target data table.
[0068] For example, if the exclusive lock alarm holding ratio set for the exclusive lock is 5%, the shared lock alarm holding ratio set for the shared lock is 10%, and the second alarm record number is set to 300, among multiple data tables, when the second total record number is greater than or equal to 300, the data tables with an exclusive lock holding ratio greater than or equal to 5% or a shared lock holding ratio greater than or equal to 10% are determined as target data tables that require alarms.
[0069] Finally, the SQL statements being executed and / or recently executed in the database session are analyzed to determine whether the SQL statements have locked the target data table. If it is determined that the SQL statement has locked N records in the target data table, the locks added to these N records are released while the database session corresponding to the SQL statement is ended. This can provide early warning of congestion in the business system, allowing time to handle the impending congestion accordingly, avoiding interruptions to the business system and ensuring business continuity, thereby avoiding economic losses caused by business paralysis due to a large number of lock timeouts or providing users with a poor system experience.
[0070] In summary, compared with the prior art, the lock releasing method provided by the present invention obtains multiple data tables in a database and table data corresponding to the multiple data tables; determines a first total number of records in each data table according to the table data, and determines a table type and a first lock ratio of the locked data table in each data table; determines a first alarm indicator corresponding to the locked data table based on the table type of the locked data table in each data table, wherein different table types correspond to different first alarm indicators; determines a target data table in the multiple data tables that needs to be alarmed based on the first total number of records, the first lock ratio and the first alarm indicator of each data table; determines whether there is a locked record in the target data table, and if so, releases the lock corresponding to the target data table, wherein the locked record is a record when a locking operation is performed on the target data table. By applying the scheme disclosed in the present invention, the target data table for which an alarm needs to be issued is determined according to the first total number of records, the first lock holding ratio and the first alarm index of each data table. If there are locked records in the target data table, the lock of the target data table is released, thereby enabling early warning of congestion in the business system, allowing time to handle the impending congestion accordingly, avoiding interruption of the business system and ensuring business continuity.
[0071] Based on the above Figure 1 The present disclosure provides a lock release device, such as Figure 4 As shown, the device includes: an acquisition module 31, a first determination module 32, a second determination module 33, a third determination module 34, and a first judgment module 35;
[0072] An acquisition module 31 is used to acquire multiple data tables and table data corresponding to the multiple data tables in a database;
[0073] A first determination module 32, configured to determine a first total number of records in each data table according to the table data, and determine a table type and a first lock ratio of a locked data table in each data table;
[0074] A second determination module 33 is used to determine a first alarm indicator corresponding to the locked data table based on the table type of the locked data table in each data table, wherein different table types correspond to different first alarm indicators;
[0075] A third determination module 34 is used to determine a target data table that needs to be alarmed in the multiple data tables based on the first total number of records, the first lock holding ratio and the first alarm indicator of each data table;
[0076] The first judgment module 35 is used to judge whether there is a locking record in the target data table, and if so, release the lock corresponding to the target data table, wherein the locking record is a record of performing a locking operation on the target data table.
[0077] In a specific application scenario, the table data includes data table attribute information, and the data table attribute information includes a data table name. The first determination module 32 can be used to use a table data statistical function to count the data table name of each data table to obtain a first total number of records for each data table.
[0078] In a specific application scenario, the first determination module 32 can be used to determine a data table with locked records among multiple data tables as a locked data table; obtain the locked table data of the locked data table using a locked table statistical function, wherein the locked table data includes locked data table attribute information; analyze and process the locked data table attribute information to obtain the table type of the locked data table, wherein the table type includes a system table and a business table.
[0079] In a specific application scenario, the first total number of records includes the total number of system table records and the total number of business table records, the first lock ratio includes the system table lock ratio and the business table lock ratio, and the first determination module 32 can be used to obtain the total number of system table records whose table type is system table in each data table, and the total number of business table records whose table type is business table in each data table; use the lock record number function to obtain the number of system table lock records whose table type is system table in multiple data tables, and use the lock record number function to obtain the number of business table lock records whose table type is business table in multiple data tables; determine the ratio of the number of system table lock records to the total number of system table records of each system table as the system table lock ratio, and determine the ratio of the number of business table lock records to the total number of business table records of each business table as the business table lock ratio.
[0080] In a specific application scenario, the first alarm indicator includes the number of system table alarm records, the number of business table alarm records, the system table alarm lock ratio and the business table alarm lock ratio. The third determination module 34 can be used to determine the system table whose total number of system table records is greater than or equal to the number of system table alarm records and whose system table lock ratio is greater than or equal to the system table alarm lock ratio as the target data table that needs to be alarmed; or, determine the business table whose total number of business table records is greater than or equal to the number of business table alarm records and whose business table lock ratio is greater than or equal to the business table alarm lock ratio as the target data table that needs to be alarmed.
[0081] In specific application scenarios, such as Figure 5 As shown, the device further includes: a fourth determination module 36, a fifth determination module 37, a sixth determination module 38 and a second judgment module 39;
[0082] A fourth determination module 36 is used to determine the locking mode corresponding to the locking data table, and determine the second total number of records and the second locking ratio of each data table under different locking modes;
[0083] A fifth determining module 37, configured to determine a second alarm indicator under different locking modes based on the locking mode of each locking data table;
[0084] A sixth determination module 38, configured to determine a target data table for which an alarm is required according to the second total number of records, the second locking ratio and the second alarm index of each data table under different locking modes;
[0085] The second judgment module 39 is used to judge whether there is a locked record in the target data table. If yes, the database session is terminated and the lock corresponding to the target data table is released.
[0086] In a specific application scenario, the fourth determining module 36 may be used to obtain lock attribute information in the lock holding data table; and determine the lock holding mode corresponding to the lock holding data table based on the lock attribute information.
[0087] In a specific application scenario, the lock mode includes a shared lock mode and an exclusive lock mode, the second lock ratio includes a shared lock ratio and an exclusive lock ratio, and the fourth determination module 36 can be used to use the lock record number function to obtain the number of shared lock records in each locked data table in the shared lock mode and the number of exclusive lock records in the exclusive lock mode; the ratio of the number of shared lock records in each data table to the second total number of records is determined as the shared lock ratio; the ratio of the number of exclusive lock records in each data table to the second total number of records is determined as the exclusive lock ratio.
[0088] In a specific application scenario, the second alarm indicator includes the number of second alarm records, the shared lock alarm ratio under the shared lock mode, and the exclusive lock alarm ratio under the exclusive lock mode. The sixth determination module 38 can be used to determine the data table in which the second total number of records in each data table is greater than or equal to the second alarm record number, and the data table in which the proportion of shared locks in the shared lock mode in each data table is greater than or equal to the shared lock alarm ratio as the target data table that needs to be alarmed; or, determine the data table in which the second total number of records in multiple data tables is greater than or equal to the second alarm record number, and the data table in which the proportion of exclusive locks in the exclusive lock mode in each data table is greater than or equal to the exclusive lock alarm ratio as the target data table that needs to be alarmed.
[0089] It should be noted that for other corresponding descriptions of the functional units involved in the lock release device provided by the present disclosure, please refer to Figure 1 The corresponding description in will not be repeated here.
[0090] Based on the above Figure 1 The method shown in the present disclosure, accordingly, also provides a computer-readable storage medium having a computer program stored thereon, which implements the above-mentioned Figure 1 The method shown.
[0091] Based on this understanding, the technical solution of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of various implementation scenarios of the present disclosure.
[0092] Based on the above Figure 1 The method shown, and Figure 5 In order to achieve the above-mentioned purpose, the embodiment of the present disclosure also provides an electronic device that can be configured on the vehicle (such as an electric vehicle) side, and the device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figure 1 The method shown.
[0093] Optionally, the above-mentioned physical device may also include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.
[0094] Those skilled in the art will appreciate that the above-mentioned physical device structure provided by the present disclosure does not constitute a limitation on the physical device, and may include more or fewer components, or a combination of certain components, or different arrangements of components.
[0095] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the above-mentioned physical device, and supports the operation of the information processing program and other software and / or programs. The network communication module is used to realize the communication between the components inside the storage medium, and the communication with other hardware and software in the information processing physical device.
[0096] Through the description of the above implementation methods, the technical personnel in this field can clearly understand that the present disclosure can be implemented by means of software plus the necessary general hardware platform, or by hardware. According to the lock release method, device and electronic device provided by the present disclosure, compared with the prior art, the present disclosure obtains multiple data tables in the database and table data corresponding to the multiple data tables; determines the first total number of records of each data table according to the table data, and determines the table type and the first lock ratio of the locked data table in each data table; determines the first alarm indicator corresponding to the locked data table based on the table type of the locked data table in each data table, wherein different table types correspond to different first alarm indicators; determines the target data table that needs to be alarmed in multiple data tables based on the first total number of records, the first lock ratio and the first alarm indicator of each data table; determines whether there is a lock record in the target data table, and if so, releases the lock corresponding to the target data table, and the lock record is the record when the target data table is locked. By applying the scheme disclosed in the present invention, the target data table for which an alarm needs to be issued is determined according to the first total number of records, the first lock holding ratio and the first alarm index of each data table. If there are locked records in the target data table, the lock of the target data table is released, thereby enabling early warning of congestion in the business system, allowing time to handle the impending congestion accordingly, avoiding interruption of the business system and ensuring business continuity.
[0097] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0098] The above are only specific embodiments of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to these embodiments herein, but will conform to the widest scope consistent with the principles and novel features applied herein.
Claims
1. A lock releasing method, characterized in that: include: Get multiple data tables in the database and table data corresponding to the multiple data tables; Determine a first total number of records in each data table according to the table data, and determine a table type and a first lock ratio of a locked data table in each data table; Based on the table type of the locked data table in each data table, determine a first alarm indicator corresponding to the locked data table, wherein different table types correspond to different first alarm indicators; Determine a target data table for which an alarm needs to be issued among the multiple data tables based on a first total number of records, a first lock holding ratio, and a first alarm indicator of each data table; Determine whether there is a locked record in the target data table, and if so, release the lock corresponding to the target data table.
2. The method according to claim 1, characterized in that The table data includes data table attribute information, and the data table attribute information includes a data table name; The determining a first total number of records in each data table according to the table data comprises: Use the table data statistics function to count the data table name of each data table to obtain the first total record number of each data table.
3. The method according to claim 1, characterized in that Determining the table type of the locked data table in each data table includes: A data table having locked records in multiple data tables is determined as a locked data table; Using a lock table statistics function to obtain lock table data of the lock data table, the lock table data including lock data table attribute information; The attribute information of the lock holding data table is analyzed and processed to obtain the table type of the lock holding data table, where the table type includes a system table and a business table.
4. The method according to claim 3, characterized in that The first total number of records includes the total number of records in the system table and the total number of records in the business table, and the first lock ratio includes the lock ratio of the system table and the lock ratio of the business table; The determining of a first lock ratio of a locked data table in each data table includes: Get the total number of system table records whose table type is system table in each data table, and the total number of business table records whose table type is business table in each data table; The number of locked records in a system table whose table type is a system table is obtained by using the number of locked records function in multiple data tables, and the number of locked records in a business table whose table type is a business table is obtained by using the number of locked records function in multiple data tables; The ratio of the number of system table locked records to the total number of system table records for each system table is determined as the system table lock ratio, and the ratio of the number of business table locked records to the total number of business table records for each business table is determined as the business table lock ratio.
5. The method according to claim 4, characterized in that The first alarm indicator includes the number of system table alarm records, the number of business table alarm records, the system table alarm lock ratio, and the business table alarm lock ratio; The step of determining a target data table in the multiple data tables that needs to be warned based on the first total number of records, the first lock holding ratio, and the first warning indicator of the multiple data tables includes: For each system table, the system table whose total number of system table records is greater than or equal to the number of system table alarm records and whose system table lock ratio is greater than or equal to the system table alarm lock ratio is determined as the target data table that needs to be alarmed; or, The business tables whose total number of business table records is greater than or equal to the number of business table alarm records and whose business table lock ratio is greater than or equal to the business table alarm lock ratio are determined as target data tables that need to be alarmed.
6. The method according to claim 1, characterized in that The method further comprises: Determine the locking mode corresponding to the locked data table, and determine the second total number of records and the second locking ratio of each data table under different locking modes; Based on the locking mode of each locking data table, determine the second alarm indicator under different locking modes; Determine the target data table for which an alarm needs to be issued according to the second total number of records, the second locking ratio, and the second alarm index of each data table under different locking modes; Determine whether there is a locked record in the target data table. If so, end the database session and release the lock corresponding to the target data table.
7. The method according to claim 6, characterized in that The determining of the lock mode corresponding to the lock data table includes: Get the lock attribute information in the lock data table; Based on the lock attribute information, a lock mode corresponding to the lock data table is determined.
8. The method according to claim 6, characterized in that The lock holding mode includes a shared lock mode and an exclusive lock mode, and the second lock holding ratio includes a shared lock ratio and an exclusive lock ratio; Determining the second locking ratio in different locking modes includes: The lock record count function is used to obtain the number of shared lock records in the shared lock mode and the number of exclusive lock records in the exclusive lock mode for each locked data table; The ratio of the number of shared lock records in each data table to the second total number of records is determined as the shared lock ratio; The ratio of the number of exclusive lock records in each data table to the second total number of records is determined as the exclusive lock ratio.
9. The method according to claim 7, characterized in that: The second alarm indicator includes the number of second alarm records, the shared lock alarm ratio in the shared lock mode, and the exclusive lock alarm ratio in the exclusive lock mode; The step of determining the target data table for which an alarm is required according to the second total number of records, the second locking ratio and the second alarm index of each data table in different locking modes comprises: Determine the data tables whose second total number of records in each data table is greater than or equal to the second alarm number of records, and whose shared lock ratio in the shared lock mode is greater than or equal to the shared lock alarm ratio as target data tables that need to be alarmed; or, The data tables in which the second total number of records is greater than or equal to the second alarm record number and the data tables in which the exclusive lock ratio in the exclusive lock mode is greater than or equal to the exclusive lock alarm ratio are determined as target data tables that need to be alarmed.
10. A lock release device, characterized in that: include: An acquisition module, used to acquire multiple data tables in a database and table data corresponding to the multiple data tables; A first determination module is used to determine a first total number of records in each data table according to the table data, and to determine a table type and a first lock ratio of a locked data table in each data table; A second determination module is used to determine a first alarm indicator corresponding to the locked data table based on the table type of the locked data table in each data table, wherein different table types correspond to different first alarm indicators; A third determination module is used to determine a target data table that needs to be alarmed in the multiple data tables based on the first total number of records, the first lock holding ratio and the first alarm indicator of each data table; The first judgment module is used to judge whether there is a locking record in the target data table, and if so, release the lock corresponding to the target data table, wherein the locking record is a record of performing a locking operation on the target data table.
11. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 9.
12. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-9.
Citation Information
Patent Citations
Database migration method and device
CN105183852A
Database system lock operation analysis method and device
CN110399378A
Method, device and equipment for avoiding group frightening during file lock unlocking and storage medium
CN110908968A
Database lock waiting processing method and device
CN112100192A
Lock holding release control method and device, computer equipment and storage medium
CN115114035A
