Database table locking method, device, storage medium and electronic device
By obtaining the lock flag when the database table is locked and returning an error command, the problem of client waiting after the database table is locked is solved and access efficiency is improved.
Patent Information
- Application Number
- CN202110975608.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-24
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2041-08-24
AI Technical Summary
In the prior art, after the database table is locked, the client's access request will be in a waiting state, resulting in low access efficiency.
When the client requests to lock a database table, obtain the lock flag of the table. If the lock flag is the target lock flag, an error instruction is returned directly to indicate that the client access failed and avoid waiting.
By directly returning error instructions, the client avoids the problem of long waiting and improves the efficiency of accessing database tables.
Smart Images

Figure CN113760932B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a database table locking method, device, storage medium and electronic equipment. Background Art
[0002] In the prior art, when accessing a table in a database, the table needs to be locked to avoid conflicts caused by other users accessing the table during the access process.
[0003] However, in the prior art, if the accessed table has been locked, the access request will be stuck and will be in a waiting state, resulting in low efficiency in accessing the database table. Summary of the invention
[0004] The embodiments of the present invention provide a database table locking method, device, storage medium and electronic device to at least solve the technical problem of low access efficiency caused by locking in the process of accessing a table in a database.
[0005] According to a first aspect of an embodiment of the present invention, a method for locking a database table is provided, comprising: upon obtaining a first locking request from a client requesting to lock a target table in a database, obtaining a lock flag of the target table, wherein the lock flag is used to indicate a locking type of the target table; and when the lock flag is a target locking flag, returning an error instruction to the client, wherein the error instruction is used to indicate that the client has failed to access the target table.
[0006] According to another aspect of an embodiment of the present invention, a locking device for a database table is provided, comprising: a first acquisition unit, for acquiring a lock flag of the target table in a database upon acquiring a first lock request from a client requesting to lock the target table in the database, wherein the lock flag is used to indicate a locking type of the target table; and a first return unit, for returning an error instruction to the client upon a first lock request from a client requesting to lock the target table, wherein the error instruction is used to indicate that the client has failed to access the target table.
[0007] According to another aspect of the embodiments of the present invention, a storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned database table locking method when running.
[0008] According to another aspect of an embodiment of the present invention, there is provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the database table locking method through the computer program.
[0009] In an embodiment of the present invention, a method is adopted in which, when a first lock request is obtained from a client requesting to lock a target table in a database, a lock flag of the target table is obtained, wherein the lock flag is used to indicate the lock type of the target table; when the lock flag is a target lock flag, an error instruction is returned to the client, wherein the error instruction is used to indicate that the client has failed to access the target table. In the above method, during the process of accessing the target table in the database, if the target table has been locked and the lock flag is the target lock flag, an error instruction is directly returned to indicate that the client has failed to access the target table, thereby avoiding the problem of the client being stuck waiting and improving the access efficiency to the tables in the database. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0011] Figure 1 is a flow chart of an optional database table locking method according to an embodiment of the present invention;
[0012] Figure 2 is a schematic diagram of processing different types of locks of an optional database table locking method according to an embodiment of the present invention;
[0013] Figure 3 It is a waiting queue schematic diagram of an optional database table locking method according to an embodiment of the present invention;
[0014] Figure 4 is a lock compatibility diagram of an optional database table locking method according to an embodiment of the present invention;
[0015] Figure 5 is a flowchart of another optional database table locking method according to an embodiment of the present invention;
[0016] Figure 6 It is a schematic diagram of the structure of an optional database table locking device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0018] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0019] Metadata Locking (MDL) is mainly used to protect the security of tables during concurrent access. It can lock table structure information as well as table data. When a table is opened, an MDL read lock is added. If the table structure is changed, an MDL write lock is added. There are many types of metadata locks in MySQL, and each type corresponds to different usage scenarios.
[0020] According to a first aspect of an embodiment of the present invention, a method for locking a database table is provided. Optionally, as follows: Figure 1 As shown, the above method includes:
[0021] S102, when a first lock request from a client to lock a target table in a database is obtained, a lock flag of the target table is obtained, wherein the lock flag is used to indicate a lock type of the target table;
[0022] S104: When the lock flag is a target lock flag, an error instruction is returned to the client, wherein the error instruction is used to indicate that the client fails to access the target table.
[0023] Optionally, the lock flag in this embodiment can be used to mark the type of lock. Different lock flags can mark different lock types. The target table in the database can be locked by different types of locks. There is a mutually exclusive or compatible relationship between different types of locks. Mutually compatible locks can lock a target table at the same time. Mutually exclusive locks cannot lock a target table at the same time.
[0024] Optionally, in this embodiment, the first lock request may be initiated when the client requests to access the target table in the database. Alternatively, in this embodiment, the first lock request may be initiated to lock the target table during the migration of the table.
[0025] For example, take table migration as an example. When migrating the target table, a first locking instruction is generated to request locking of the target table. At this time, the lock flag of the target table is obtained. If the lock flag is the target locking flag, it can be considered that the target table has been locked and the lock is a specific lock. Therefore, at this time, the table cannot be locked and migrated in response to the first locking request. An error instruction should be returned to the client, indicating that the current access to the target table has failed and cannot be locked.
[0026] Through this embodiment, during the process of accessing the target table in the database, if the target table has been locked and the lock flag is the target lock flag, an error instruction is directly returned to indicate that the client has failed to access the target table, thereby avoiding the problem of the client being stuck waiting and improving the access efficiency to the table in the database.
[0027] As an optional implementation, the above method further includes:
[0028] When the lock flag is the first lock flag, obtain the lock status of the target table;
[0029] When the lock state is unlocked, adjust the lock state of the target table from unlocked to locked;
[0030] Return a prompt message to the client so that the client can access the target table.
[0031] Optionally, in this embodiment, different locks can be distinguished by lock flags. In this embodiment, if the lock flag is a target lock flag, it means that the current lock of the target table is a target type lock. After this type of lock locks the target table, other incompatible locks cannot lock the target table, and an error instruction will be immediately fed back to avoid waiting. If the lock flag is a first lock flag, it means that the lock of the target table at this time is the first lock. Get the status of the first lock to check whether the lock status is locked or unlocked. If it is unlocked, the target table can be locked. After the lock is successfully locked, the client can access the target table.
[0032] For example, combined with Figure 2 If the lock flag of the target table is the target lock flag, an error instruction is fed back. If it is the first lock flag, the lock state is obtained, and different processing procedures are performed according to different lock states.
[0033] As an optional implementation, the above method further includes:
[0034] When the lock state is locked, the first lock request is saved in the waiting queue.
[0035] Optionally, in this embodiment, if the lock flag of the lock of the target table is the first lock flag, it means that the lock of the target table is the first lock at this time. The state of the first lock is obtained to check whether the lock state is locked or unlocked. If the lock state is locked, it means that the current target table has been locked. Therefore, the first lock request can be saved in the waiting queue. After the first lock request is saved in the waiting queue, the target table is unlocked before being locked.
[0036] Combination Figure 3 When the lock flag is the first lock flag and the lock state is locked, the first lock request is saved in the waiting queue. There is already a third lock request in the waiting queue, so the first lock request is sorted after the third lock request.
[0037] As an optional implementation, the above method further includes:
[0038] Parse the first lock request;
[0039] When the first lock request is a target lock request, when the lock state is unlocked, after adjusting the lock state of the target table from unlocked to locked, the lock flag of the target table is adjusted from the first lock flag to the target lock flag.
[0040] Optionally, in this embodiment, after locking the target table, it is also necessary to modify the lock flag and lock status of the target table.
[0041] In this embodiment, since different locks have different lock flags, the type of the locked lock flag can be carried in the first lock request. If the first lock request is a target lock request, it means that the type of the locked lock flag is a target lock flag. At this time, a target lock can be added to the target table to lock the target table. After locking the target table, the lock flag of the lock of the target table is changed to the target lock flag, and the lock state is changed to the locked state. When other clients request to lock the target table, an error instruction will be fed back, indicating that the lock failed.
[0042] As an optional implementation, in the case where the first lock request for locking the target table in the database is obtained, obtaining the lock flag of the target table includes:
[0043] Before obtaining the first lock request, if a second lock request requesting to lock the target table is obtained, the second lock request is saved in the grant queue;
[0044] When the first lock request is compatible with the second lock request, the first lock request is saved in the grant queue and the lock flag is obtained.
[0045] As an optional implementation, the above method further includes:
[0046] When the first lock request is incompatible with the second lock request, the first lock request is saved in a waiting queue;
[0047] When the grant queue is empty, the first lock request is transferred from the wait queue to the grant queue, and the lock flag is obtained.
[0048] Optionally, in this embodiment, for different lock requests, it is first possible to check whether the locks between the lock requests are compatible. If they are compatible, they can be locked at the same time. If the different locks are not compatible, it is necessary to process the second lock request first and then the first lock request in order. Figure 4 Provide explanation. Figure 4 In the grant queue of the target table, the target lock and the first lock are compatible and can be locked at the same time. The second lock and the third lock are compatible with each other, but not with the target lock or the first lock, so they are in the waiting queue. When the target lock and the first lock are processed, the second lock and the third lock are transferred to the grant queue and the target table is locked.
[0049] Figure 5 This is a flow chart of the present embodiment. The metadata lock in the present embodiment may have a special tag, such as a migrate tag. Keywords can be obtained through word analysis, and syntax analysis can be performed by generating a syntax analyzer (Yet Another CompilerCompiler, referred to as yacc), and the MDL lock type is determined by parsing the keywords. Compare the compatibility of the MDL lock and the MDL lock waiting queue with the lock grant queue. If compatible, check whether the MDL lock has a migrate tag. When it is found that the metadata lock has a migrate tag, an error will be returned directly without blocking and waiting. If there is no migrate tag, it is determined whether the lock state is locked or unlocked. If it is unlocked, it can be locked. If it is locked, enter the waiting queue and wait.
[0050] In this embodiment, a migrate option can be added to the syntax of lock table in the sql_yacc.yy file. After adding the option, the lock table test migrate statement is used to lock. The sql_yacc.yy file is a file in the yacc syntax analyzer that is used to parse the syntax. The file includes the syntax of lock table. The lock table syntax is the syntax for locking the table. In this embodiment, a migrate option is added to the syntax of lock table, and the syntax after addition is the lock table test migrate statement. Through this statement, the table can be locked. The locked table has a migrate flag.
[0051] If the migrate option is used, a write lock is added, and then the migrate mark is put on the metadata lock. When other sessions request the metadata lock, they will find that it is marked with the migrate mark, and an error will be returned immediately instead of being locked and waiting.
[0052] Through this embodiment, a new flag is added in the MDL locking process to indicate whether the table is marked as a table being migrated. If the marking is successful, other sessions will directly report an error when reading and writing the table, and the error message is: ERROR1105 (HY000): Unknown error. This error message indicates that an unknown error has occurred, and the error code is 1105 (HY000). The error type can be known or found according to the error code.
[0053] In this embodiment, different tables do not interfere with each other in terms of locking. Each locking process is performed on a table-by-table basis. When executing the lock table test migrate statement, if the table is successfully locked, the migration of the table is marked as true, indicating that the table has been locked. When executing the unlock command unlock tables, the migration of the table is marked as false, indicating that the table has been unlocked.
[0054] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0055] According to another aspect of the embodiment of the present invention, a device for implementing the above-mentioned database table locking method is also provided. Figure 6 As shown, the device comprises:
[0056] A first acquisition unit 602 is used to acquire a lock flag of the target table when a first lock request from a client to lock a target table in a database is acquired, wherein the lock flag is used to indicate a lock type of the target table;
[0057] The first returning unit 604 is used to return an error instruction to the client when the lock flag is a target locking flag, wherein the error instruction is used to indicate that the client fails to access the target table.
[0058] Optionally, the lock flag in this embodiment can be used to mark the type of lock. Different lock flags can mark different lock types. The target table in the database can be locked by different types of locks. There is a mutually exclusive or compatible relationship between different types of locks. Mutually compatible locks can lock a target table at the same time. Mutually exclusive locks cannot lock a target table at the same time.
[0059] Optionally, in this embodiment, the first lock request may be initiated when the client requests to access the target table in the database. Alternatively, in this embodiment, the first lock request may be initiated to lock the target table during the migration of the table.
[0060] For example, take table migration as an example. When migrating the target table, a first locking instruction is generated to request locking of the target table. At this time, the lock flag of the target table is obtained. If the lock flag is the target locking flag, it can be considered that the target table has been locked and the lock is a specific lock. Therefore, at this time, the table cannot be locked and migrated in response to the first locking request. An error instruction should be returned to the client, indicating that the current access to the target table has failed and cannot be locked.
[0061] Through this embodiment, during the process of accessing the target table in the database, if the target table has been locked and the lock flag is the target lock flag, an error instruction is directly returned to indicate that the client has failed to access the target table, thereby avoiding the problem of the client being stuck waiting and improving the access efficiency to the table in the database.
[0062] As an optional implementation, the above device further includes:
[0063] A second acquisition unit, configured to acquire a lock state of a target table when the lock flag is a first locking flag;
[0064] A first adjustment unit, configured to adjust the lock state of the target table from an unlocked state to a locked state when the lock state is unlocked;
[0065] The second returning unit is used to return a prompt message to the client so that the client can access the target table.
[0066] Optionally, in this embodiment, different locks can be distinguished by lock flags. In this embodiment, if the lock flag is a target lock flag, it means that the current lock of the target table is a target type lock. After this type of lock locks the target table, other incompatible locks cannot lock the target table, and an error instruction will be immediately fed back to avoid waiting. If the lock flag is a first lock flag, it means that the lock of the target table at this time is the first lock. Get the status of the first lock to check whether the lock status is locked or unlocked. If it is unlocked, the target table can be locked. After the lock is successfully locked, the client can access the target table.
[0067] As an optional implementation, the above device further includes:
[0068] The first saving unit is used to save the first lock request into the waiting queue when the lock state is locked.
[0069] Optionally, in this embodiment, if the lock flag of the lock of the target table is the first lock flag, it means that the lock of the target table is the first lock at this time. The state of the first lock is obtained to check whether the lock state is locked or unlocked. If the lock state is locked, it means that the current target table has been locked. Therefore, the first lock request can be saved in the waiting queue. After the first lock request is saved in the waiting queue, the target table is unlocked before being locked.
[0070] As an optional implementation, the above device further includes:
[0071] A parsing unit, configured to parse the first lock request;
[0072] The second adjustment unit is used to adjust the lock state of the target table from an unlocked state to a locked state when the first lock request is a target lock request and the lock state is unlocked, and then adjust the lock flag of the target table from a first lock flag to a target lock flag.
[0073] Optionally, in this embodiment, after locking the target table, it is also necessary to modify the lock flag and lock status of the target table.
[0074] In this embodiment, since different locks have different lock flags, the type of the locked lock flag can be carried in the first lock request. If the first lock request is a target lock request, it means that the type of the locked lock flag is a target lock flag. At this time, a target lock can be added to the target table to lock the target table. After locking the target table, the lock flag of the lock of the target table is changed to the target lock flag, and the lock state is changed to the locked state. When other clients request to lock the target table, an error instruction will be fed back, indicating that the lock failed.
[0075] As an optional implementation manner, the first acquiring unit includes:
[0076] A second saving unit is used to save the second lock request into the grant queue when a second lock request for locking the target table is obtained before the first lock request is obtained;
[0077] The third saving unit is used to save the first lock request to the grant queue and obtain the lock flag when the first lock request is compatible with the second lock request.
[0078] As an optional implementation, the above device further includes:
[0079] A fourth saving unit, configured to save the first lock request into a waiting queue when the first lock request is incompatible with the second lock request;
[0080] The transfer unit is used to transfer the first lock request from the waiting queue to the grant queue when the grant queue is empty, and obtain the lock flag.
[0081] For other examples of this embodiment, please refer to the above examples and will not be described in detail here.
[0082] Optionally, in this embodiment, for different lock requests, it is first possible to check whether the locks between the lock requests are compatible. If they are compatible, they can be locked at the same time. If the different locks are not compatible, it is necessary to process the second lock request first and then the first lock request in order. Figure 4 Provide explanation. Figure 4 In the grant queue of the target table, the target lock and the first lock are compatible and can be locked at the same time. The second lock and the third lock are compatible with each other, but not with the target lock or the first lock, so they are in the waiting queue. When the target lock and the first lock are processed, the second lock and the third lock are transferred to the grant queue and the target table is locked.
[0083] Figure 5This is a flow chart of the present embodiment. The metadata lock in the present embodiment may have a special tag, such as a migrate tag. Keywords can be obtained through word analysis, and syntax analysis can be performed by generating a syntax analyzer (Yet Another CompilerCompiler, referred to as yacc), and the MDL lock type is determined by parsing the keywords. Compare the compatibility of the MDL lock and the MDL lock waiting queue with the lock grant queue. If compatible, check whether the MDL lock has a migrate tag. When it is found that the metadata lock has a migrate tag, an error will be returned directly without blocking and waiting. If there is no migrate tag, it is determined whether the lock state is locked or unlocked. If it is unlocked, it can be locked. If it is locked, enter the waiting queue and wait.
[0084] In this embodiment, a migrate option can be added to the syntax of lock table in the sql_yacc.yy file. After adding the option, the lock table test migrate statement is used to lock. The sql_yacc.yy file is a file in the yacc syntax analyzer that is used to parse the syntax. The file includes the syntax of lock table. The lock table syntax is the syntax for locking the table. In this embodiment, a migrate option is added to the syntax of lock table, and the syntax after addition is the lock table test migrate statement. Through this statement, the table can be locked. The locked table has a migrate flag.
[0085] If the migrate option is used, a write lock is added, and then the migrate mark is put on the metadata lock. When other sessions request the metadata lock, they will find that it is marked with the migrate mark, and an error will be returned immediately instead of being locked and waiting.
[0086] Through this embodiment, a new flag is added in the MDL locking process to indicate whether the table is marked as a table being migrated. If the marking is successful, other sessions will directly report an error when reading and writing the table, and the error message is: ERROR1105 (HY000): Unknown error. This error message indicates that an unknown error has occurred, and the error code is 1105 (HY000). The error type can be known or found according to the error code.
[0087] In this embodiment, different tables do not interfere with each other in terms of locking. Each locking process is performed on a table-by-table basis. When executing the lock table test migrate statement, if the table is successfully locked, the migration of the table is marked as true, indicating that the table has been locked. When executing the unlock command unlock tables, the migration of the table is marked as false, indicating that the table has been unlocked.
[0088] According to another aspect of an embodiment of the present invention, an electronic device for implementing the above-mentioned database table locking method is also provided. The electronic device may include a memory and a processor. The memory stores a computer program. The processor is configured to execute the steps in the above-mentioned database table locking method embodiment through the computer program.
[0089] According to another aspect of the embodiments of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of the above-mentioned database table locking method embodiment when running.
[0090] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.
[0091] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0092] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on such understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which can be personal computers, servers or network devices, etc.) to perform all or part of the steps of the methods of various embodiments of the present invention.
[0093] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0094] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0095] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0096] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0097] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A database table locking method, characterized in that: include: When a first lock request from a client to lock a target table in a database is obtained, a lock flag of the target table is obtained, wherein the lock flag is used to indicate a lock type of the target table; Before acquiring the first lock request, if a second lock request requesting to lock the target table is acquired, saving the second lock request in a grant queue; When the first lock request is compatible with the second lock request, the first lock request is saved in the grant queue; when the first lock request is incompatible with the second lock request, the first lock request is saved in the waiting queue, wherein compatible lock requests lock the target table at the same time, and incompatible lock requests lock the target table one after another; In the case where the lock flag is a target lock flag, an error instruction is returned to the client, wherein the error instruction is used to indicate that the client fails to access the target table; When the lock flag is a first lock flag, the lock state of the target table is acquired, and when the lock state is locked, the first lock request is saved in the waiting queue.
2. The method according to claim 1, characterized in that The method further comprises: When the lock state is unlocked, adjusting the lock state of the target table from the unlocked state to the locked state; A prompt message is returned to the client, so that the client accesses the target table.
3. The method according to claim 1, characterized in that The method further comprises: Parsing the first lock request; In the case where the first lock request is a target lock request, when the lock state is unlocked, after the lock state of the target table is adjusted from the unlocked state to the locked state, the lock flag of the target table is adjusted from the first lock flag to the target lock flag.
4. The method according to claim 1, characterized in that: The method further comprises: When the grant queue is empty, the first lock request is transferred from the waiting queue to the grant queue, and the lock flag is obtained.
5. A locking device for a database table, characterized in that: include: A first acquiring unit is configured to acquire a lock flag of a target table in a database upon acquiring a first lock request from a client requesting to lock the target table, wherein the lock flag is used to indicate a lock type of the target table; A first returning unit, configured to return an error instruction to the client when the lock flag is a target locking flag, wherein the error instruction is used to indicate that the client fails to access the target table; a second saving unit, configured to save the second lock request to a grant queue if a second lock request requesting to lock the target table is obtained before the first lock request is obtained; a third saving unit, configured to save the first lock request to the grant queue if the first lock request is compatible with the second lock request; a fourth saving unit, configured to save the first lock request to a waiting queue when the first lock request is incompatible with the second lock request, wherein compatible lock requests lock the target table at the same time, and incompatible lock requests lock the target table one after another; A second acquisition unit, configured to acquire a lock state of the target table when the lock flag is a first locking flag; The first saving unit is used to save the first lock request into the waiting queue when the lock state is locked.
6. The device according to claim 5, characterized in that The device also includes: A first adjustment unit, configured to adjust the lock state of the target table from the unlocked state to the locked state when the lock state is unlocked; The second returning unit is used to return a prompt message to the client, so that the client can access the target table.
7. The device according to claim 6, characterized in that The device also includes: A parsing unit, configured to parse the first lock request; A second adjustment unit is used to adjust the lock state of the target table from the unlocked state to the locked state when the first lock request is a target lock request and the lock state is unlocked, and then adjust the lock flag of the target table from the first lock flag to the target lock flag.
8. The device according to claim 5, characterized in that The device also includes: A transfer unit is used to transfer the first lock request from the waiting queue to the grant queue when the grant queue is empty, and obtain the lock flag.
9. A computer-readable storage medium storing a computer program, characterized in that: The computer program executes the method described in any one of claims 1 to 4 when executed.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 4 through the computer program.
Citation Information
Patent Citations
Distributed database transaction processing system
CN109800062A
Data processing method and device applied to server, computing equipment and medium
CN110399383A