Database lock configuration method and device, medium and product
By detecting the lock type in the database and adding preset exclusive tags, the problem of excessive read operations causing blockage of write operations is solved, and the exclusive lock acquisition efficiency and database processing efficiency are improved.
Patent Information
- Application Number
- CN202411604923.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-11
- Publication Date
- 2025-02-14
AI Technical Summary
In the database, too many database read operations cause the database write operations to be in a waiting state because they cannot obtain the exclusive lock, causing the write operations to be blocked.
By detecting the type of lock currently held by the database resource, if it is a shared lock, a preset exclusive mark is added to the lock status of the database resource, and subsequent shared lock requests and exclusive lock requests are prohibited to acquire the lock, increasing the priority of exclusive lock acquisition.
To a certain extent, the efficiency of database exclusive lock acquisition is improved, the situation of long-term blockage of exclusive lock requests caused by holding shared locks is reduced, and the database processing efficiency is improved.
Smart Images

Figure CN119441242A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and in particular to a database lock configuration method, device, medium and product. Background Art
[0002] In the process of using the database, the lock mechanism is a common concurrency control mechanism, which is used to manage the possible competition state when multiple users or multiple transactions access the same database resource at the same time. Generally speaking, the database lock will be configured with shared locks and exclusive locks. Among them, the shared lock allows multiple database read operations to read the same database resource at the same time, that is, multiple database read operations can hold shared locks on the same database resource at the same time, but no database write operation is allowed to hold an exclusive lock on the database resource.
[0003] Therefore, when a database resource has been shared locked by a database read operation, subsequent database write operations on the database resource cannot hold an exclusive lock. However, subsequent database read operations on the database resource can hold a shared lock on the database resource. In this way, when there are too many database read operations, it is easy for the database write operation to be in a waiting state due to the inability to obtain an exclusive lock, resulting in blocking of the database write operation. Summary of the invention
[0004] An object of the present invention is to provide a database lock configuration method, device, medium and product that can improve the exclusive lock acquisition efficiency of the database shared memory to a certain extent.
[0005] A further object of the present invention is to reduce the impact on database processing efficiency.
[0006] In particular, the present invention provides a database lock configuration method, comprising:
[0007] Obtain an exclusive lock request for database resources;
[0008] Acquire an exclusive lock of the database resource according to the exclusive lock request;
[0009] If it is detected that the exclusive lock is not successfully acquired, the type of lock currently held by the database resource is acquired;
[0010] If the type of lock currently held by the database resource is a shared lock, a preset exclusive mark is added to the lock state of the database resource and set to a first mark state, and the first mark state of the preset exclusive mark is used to prohibit shared lock requests and exclusive lock requests other than the exclusive lock request from obtaining the lock of the database resource.
[0011] Optionally, the preset exclusive mark has a second mark state, and the second mark state allows a shared lock request and an exclusive lock request other than the exclusive lock request to acquire a lock on the database resource;
[0012] After the step of adding a preset exclusive mark to the lock state of the database resource, the following steps are included: attempting to obtain an exclusive lock of the database resource at a preset frequency;
[0013] When it is detected that the exclusive lock is not acquired successfully after the preset timeout period is reached, the preset exclusive mark is modified to the second mark state until the exclusive lock request is awakened again, and then the preset exclusive mark is modified to the first mark state.
[0014] Optionally, the database is configured with a preset request queue, and the preset request queue is used to place lock requests for the database resource in order, and the step of obtaining the type of lock currently held by the database resource includes:
[0015] Check whether the preset request queue is empty. If so, put the exclusive lock request into the preset request queue and execute the step of obtaining the type of lock currently held by the database resource; if not, put the exclusive lock request into the preset request queue and end the request work.
[0016] Optionally, the step of checking whether the preset request queue is empty includes: checking whether the lock state of the database resource is set with a preset waiting mark, and if so, determining that there is a lock request in the preset request queue, executing the step of placing the exclusive lock request into the preset request queue and ending the request work;
[0017] If not, determining that the preset request queue is empty, placing the exclusive lock request into the preset request queue and executing the step of obtaining the type of lock currently held by the database resource, and setting a preset waiting mark in the lock state of the database resource;
[0018] The preset waiting mark is used to indicate that there is a waiting lock request in the preset request queue.
[0019] Optionally, the obtaining of an exclusive lock request for a database resource comprises: obtaining an exclusive lock request in the preset request queue;
[0020] In the case of acquiring an exclusive lock request in the preset request queue, after the step of detecting that the exclusive lock has not been successfully acquired when the preset timeout period is reached, the method includes: adjusting the order of the exclusive lock request in the preset request queue backward.
[0021] Optionally, obtaining a shared lock request for the database resource;
[0022] Check whether the lock state of the database resource has the preset exclusive mark, and if so, put the shared lock request into the preset request queue and end the request work;
[0023] If not, check whether the preset request queue is empty. If so, obtain the shared lock of the database resource according to the shared lock request. If it is detected that the shared lock is not successfully obtained, put the shared lock request into the preset request queue and end the request work. If not, put the shared lock request into the preset request queue and end the request work.
[0024] Optionally, when it is detected that the preset request queue is empty, the preset waiting mark in the lock state of the database resource is cleared.
[0025] According to another aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a computer executable program stored in the memory and running on the processor, and the processor implements the database lock configuration method according to any one of the above items when executing the computer executable program.
[0026] According to another aspect of the present invention, a computer-readable storage medium is provided, on which a computer-executable program is stored. When the computer-executable program is executed by a processor, the database lock configuration method according to any one of the above items is implemented.
[0027] According to another aspect of the present invention, a computer program product is provided, including a computer executable program, and when the computer executable program is executed by a processor, the database lock configuration method according to any one of the above items is implemented.
[0028] The database lock configuration method, device, medium and product of the present invention obtain the type of lock currently held by the database resource after the exclusive lock request fails to successfully obtain the exclusive lock of the database resource. When the lock currently held by the database resource is a shared lock, a preset exclusive mark is added to the lock state of the database resource. When a subsequent shared lock request attempts to obtain the shared lock of the database resource, the database detects that the lock state of the database resource has a preset exclusive mark and is in the first mark state. Even if the current database resource is held with a shared lock, the subsequent shared lock request is prohibited from obtaining the shared lock. That is to say, even if the current database resource is held with a shared lock, the exclusive lock request can have more opportunities to obtain the lock of the database resource with higher priority than the shared lock request, thereby improving the efficiency of obtaining the database exclusive lock to a certain extent, and effectively reducing the situation where the database resource is always held with a shared lock, resulting in the exclusive lock request being blocked for a long time.
[0029] Furthermore, the lock configuration method, device, medium and product of the present invention attempt to obtain an exclusive lock of a database resource within a preset timeout period after adding a preset exclusive mark to the lock state of the database resource. If it is detected that the exclusive lock has not been successfully acquired when the preset timeout period is reached, the preset exclusive mark is modified to a second mark state. That is to say, when it is detected that the exclusive lock has not been successfully acquired when the preset timeout period is reached, a shared lock request can be allowed to start jointly holding a shared lock of the database resource. Because the mechanism of multiple database processes jointly holding a shared lock on database resources can greatly improve the processing efficiency of the database, if the process currently holding the shared lock on the database resource needs to lock it for a long time, the exclusive lock request cannot obtain the exclusive lock for a long time, and because the preset exclusive mark is in the first mark state, subsequent shared lock requests cannot hold the shared lock on the database resource, which will lead to a waste of database resources. Therefore, when the exclusive lock reaches the preset timeout time and is still not successfully obtained, the preset exclusive mark is changed to the second mark state to avoid the shared lock of the current database resource lasting too long so that the preset exclusive mark is in the first mark state for a long time and causes a backlog of processes, thereby improving the efficiency of obtaining the database exclusive lock to a certain extent, while reducing the impact on the database processing efficiency, so that the exclusive lock acquisition efficiency and the database processing efficiency are both within an acceptable range.
[0030] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0032] Figure 1 is a schematic flow chart of a database lock configuration method according to an embodiment of the present invention;
[0033] Figure 2 is a schematic flow chart of a database lock configuration method according to another embodiment of the present invention;
[0034] Figure 3 is a schematic flow chart of a database lock configuration method according to yet another embodiment of the present invention;
[0035] Figure 4 is a schematic flow chart of a database lock configuration method according to yet another embodiment of the present invention;
[0036] Figure 5is a schematic flow chart of a database lock configuration method according to yet another embodiment of the present invention;
[0037] Figure 6 is a schematic diagram of a computer device according to an embodiment of the present invention;
[0038] Figure 7 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention;
[0039] Figure 8 is a schematic diagram of a computer program product according to an embodiment of the present invention. DETAILED DESCRIPTION
[0040] It should be understood by those skilled in the art that the embodiments described below are only some embodiments of the present invention, rather than all embodiments of the present invention, and these embodiments are intended to explain the technical principles of the present invention, rather than to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should still fall within the protection scope of the present invention.
[0041] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.
[0042] The flow chart provided by the present invention is not intended to indicate that the operation of the method will be performed in any particular order, or all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical thinking provided by the present embodiment method, additional changes can be made to the above method.
[0043] During the use of the database, the lock mechanism includes locking the database object and locking the shared memory. For the shared memory lock mechanism, there is currently no good solution to the situation where the database write operation is always in a waiting state due to failure to obtain an exclusive lock, which causes the database write operation to be blocked. The following embodiment describes a lock configuration method mainly for the database shared memory.
[0044] like Figure 1 As shown, in one embodiment, the lock configuration method of the database generally includes:
[0045] Step S101, an exclusive lock request for a database resource is obtained. In layman's terms, a request from a process to add an exclusive lock to a database resource is obtained.
[0046] Step S102: acquiring an exclusive lock of the database resource according to the exclusive lock request. After acquiring the exclusive lock request, an attempt is made to make the process making the exclusive lock request acquire or hold the exclusive lock of the database resource.
[0047] Step S103, if it is detected that the exclusive lock is not successfully obtained, the type of lock currently held by the database resource is obtained. If the exclusive lock of the database resource is not successfully obtained, it means that the database resource is currently held by other processes, which may be a shared lock or an exclusive lock, because when the database resource is held by a shared lock or an exclusive lock, no other process can hold the exclusive lock of the database resource. Then, if the exclusive lock of the database resource is not successfully obtained, it is obtained whether the lock currently held by the database resource is an exclusive lock or a shared lock.
[0048] Step S104, if the type of lock currently held by the database resource is a shared lock, a preset exclusive mark is added to the lock state of the database resource and set to a first mark state, and the first mark state of the preset exclusive mark is used to prohibit shared lock requests and exclusive lock requests other than exclusive lock requests from obtaining the lock of the database resource.
[0049] Specifically, when the type of lock currently held by the database resource is a shared lock, although the current exclusive lock request cannot obtain the exclusive lock, by adding a preset exclusive mark to the lock state of the database resource and setting it to the first mark state, when subsequent shared lock requests try to obtain the shared lock of the database resource, the database detects that the lock state of the database resource has the preset exclusive mark and is in the first mark state, even if the current database resource is held by a shared lock, subsequent shared lock requests will be prohibited from obtaining the shared lock.
[0050] In the solution of this embodiment, after the exclusive lock request fails to successfully obtain the exclusive lock of the database resource, the type of lock currently held by the database resource is obtained. When the lock currently held by the database resource is a shared lock, a preset exclusive mark is added to the lock state of the database resource. When a subsequent shared lock request attempts to obtain the shared lock of the database resource, the database detects that the lock state of the database resource has the preset exclusive mark and is in the first mark state. Even if the current database resource is held with a shared lock, the subsequent shared lock request will be prohibited from obtaining the shared lock. In other words, even if the current database resource is held with a shared lock, the exclusive lock request can have more opportunities to obtain the lock of the database resource with higher priority than the shared lock request, thereby improving the efficiency of obtaining the database exclusive lock to a certain extent, and effectively reducing the situation where the database resource is always held with a shared lock, resulting in the exclusive lock request being blocked for a long time.
[0051] like Figure 2 As shown, in one embodiment, the preset exclusive mark has a second mark state, and the second mark state allows shared lock requests and exclusive lock requests other than exclusive lock requests to obtain the lock of the database resource. The step of adding the preset exclusive mark to the lock state of the database resource includes: trying to obtain the exclusive lock of the database resource within a preset timeout period; detecting that the exclusive lock is still not successfully obtained when the preset timeout period is reached, and modifying the preset exclusive mark to the second mark state.
[0052] In this embodiment, the database lock configuration method generally includes:
[0053] Step S201: obtaining an exclusive lock request for database resources.
[0054] Step S202: Acquire an exclusive lock of a database resource according to an exclusive lock request.
[0055] Step S203: If it is detected that the exclusive lock is not successfully acquired, the type of lock currently held by the database resource is acquired.
[0056] Step S204: If the type of the lock currently held by the database resource is a shared lock, a preset exclusive mark is added to the lock state of the database resource and is set to a first mark state.
[0057] The same steps are as described above.
[0058] Step S205, try to obtain the exclusive lock of the database resource within a preset timeout period. Specifically, that is, continue to try to obtain the exclusive lock of the database resource within a certain period of time, for example, it can be 10 seconds, 20 seconds or 30 seconds, etc. Those skilled in the art can set the specific timeout period as needed.
[0059] Step S206, if it is detected that the exclusive lock is still not acquired successfully after the preset timeout period is reached, the preset exclusive mark is changed to the second mark state. Specifically, if the exclusive lock is still not acquired after the preset timeout period is reached, the preset exclusive mark is changed to the second mark state, that is, shared lock requests and exclusive lock requests other than exclusive lock requests are allowed to acquire locks of database resources.
[0060] In addition, if the exclusive lock of the database resource is successfully acquired within the preset timeout period, the preset exclusive mark of the exclusive lock application in the database resource lock state is removed.
[0061] In the solution of this embodiment, by adding a preset exclusive mark to the lock state of the database resource, attempting to obtain the exclusive lock of the database resource within the preset timeout period, if it is detected that the exclusive lock has not been successfully acquired when the preset timeout period is reached, the preset exclusive mark is modified to a second mark state, that is, when it is detected that the exclusive lock has not been successfully acquired when the preset timeout period is reached, the shared lock request can be allowed to start jointly holding the shared lock of the database resource. Because the mechanism of multiple database processes jointly holding a shared lock on database resources can greatly improve the processing efficiency of the database, if the process currently holding the shared lock on the database resource needs to lock it for a long time, the exclusive lock request cannot obtain the exclusive lock for a long time, and because the preset exclusive mark is in the first mark state, subsequent shared lock requests cannot hold the shared lock on the database resource, which will lead to a waste of database resources. Therefore, when the exclusive lock reaches the preset timeout time and is still not successfully obtained, the preset exclusive mark is changed to the second mark state to avoid the shared lock of the current database resource lasting too long so that the preset exclusive mark is in the first mark state for a long time and causes a backlog of processes, thereby improving the efficiency of obtaining the database exclusive lock to a certain extent, while reducing the impact on the database processing efficiency, so that the exclusive lock acquisition efficiency and the database processing efficiency are both within an acceptable range.
[0062] In one embodiment, the database is configured with a preset request queue, which is used to place lock requests for database resources in order, so that the lock requests in the preset request queue can be executed in the queue order to ensure fairness. The step of obtaining the type of lock currently held by the database resource includes: checking whether the preset request queue is empty, if so, putting the exclusive lock request into the preset request queue and executing the step of obtaining the type of lock currently held by the database resource. If the preset request queue is empty, it means that there is no waiting lock request in front, and the current exclusive lock request has not successfully obtained the lock, so the exclusive lock request is first put into the preset request queue, and then see whether to set the preset exclusive mark; if not, the exclusive lock request is put into the preset request queue and the request work is terminated. If the preset request queue is not empty, it means that there is still a waiting lock request in front, so the exclusive lock request is first put into the preset request queue and waits to be awakened before processing.
[0063] like Figure 3 As shown, in one embodiment, the step of checking whether the preset request queue is empty includes: checking whether the lock state of the database resource is set with a preset waiting mark, the preset waiting mark is used to indicate that there is a waiting lock request in the preset request queue, if so, it is determined that there is a lock request in the preset request queue, that is, the preset request queue is not empty, if not, it is determined that the preset request queue is empty.
[0064] Specifically, in this embodiment, the database lock configuration method generally includes:
[0065] Step S301: obtaining an exclusive lock request for database resources.
[0066] Step S302: Acquire an exclusive lock of a database resource according to an exclusive lock request.
[0067] Step S303, if it is detected that the exclusive lock is not successfully acquired, check whether the lock state of the database resource is set with a preset waiting mark, if so, execute step S304, if not, execute step S305. That is, by checking whether the lock state of the database resource has a preset waiting mark, it is determined whether the preset request queue is empty.
[0068] Step S304, put the exclusive lock request into the preset request queue and end the request work. If the lock state of the database resource has a preset waiting mark, it means that the preset request queue is not empty, that is, there is a waiting lock request before the current exclusive lock request. In order to ensure fairness, the current exclusive lock request is no longer processed, that is, the work of adding the preset exclusive mark to the database resource is no longer performed, but the current exclusive lock request is put into the queue and the request work is ended, waiting to be awakened in order and then continue to be processed.
[0069] Step S305, put the exclusive lock request into the preset request queue and set the preset waiting mark in the lock state of the database resource. If the lock state of the database resource does not have a preset waiting mark, it means that the preset request queue is empty and there is no waiting lock request. Then, put the exclusive lock request into the queue and add the preset waiting mark, and then see whether the preset exclusive mark needs to be added.
[0070] Step S306, obtaining the type of lock currently held by the database resource.
[0071] Step S307: If the type of lock currently held by the database resource is a shared lock, a preset exclusive mark is added to the lock state of the database resource and set to the first mark state. After the preset exclusive mark is added and set to the first mark state, subsequent shared lock requests and exclusive lock requests cannot obtain the lock of the database resource, but are placed in the preset request queue according to the request order.
[0072] It should be noted that if the type of lock currently held by the database resource is an exclusive lock, the exclusive lock request is placed in a preset request queue and the request work is terminated.
[0073] In the solution of this embodiment, by setting a preset request queue, lock requests that cannot obtain the database resource lock at that time can be placed in the preset request queue according to the request order, and then awakened and processed from the queue in order, thereby ensuring the fairness of lock request processing. By setting a preset waiting mark, it can be indicated whether there are waiting lock requests in the preset request queue. Compared with checking the queue, checking the preset waiting mark can determine the status of the preset request queue more quickly, thereby improving execution efficiency.
[0074] It should be noted that in some other embodiments, for each exclusive lock request, the steps of adding a preset exclusive mark and attempting to obtain an exclusive lock of the database resource within a preset timeout period may be first performed. If it is detected that the exclusive lock has not been successfully obtained when the preset timeout period is reached, the preset exclusive mark is modified to a second mark state, and the exclusive lock request is placed in a queue.
[0075] like Figure 4 As shown, in one embodiment, obtaining an exclusive lock request for a database resource includes: obtaining an exclusive lock request in a preset request queue, and after detecting that the exclusive lock has not been successfully obtained when a preset timeout period has been reached, the step includes: adjusting the order of the exclusive lock request in the preset request queue backward.
[0076] Specifically, the database lock configuration method of this embodiment generally includes:
[0077] Step S401: an exclusive lock request for a database resource is obtained, that is, the exclusive lock request in the queue is awakened and processed.
[0078] Step S402: Acquire an exclusive lock of a database resource according to an exclusive lock request.
[0079] Step S403: If it is detected that the exclusive lock is not successfully acquired, the type of lock currently held by the database resource is acquired.
[0080] Step S404: If the type of the lock currently held by the database resource is a shared lock, a preset exclusive mark is added to the lock state of the database resource and is set to a first mark state.
[0081] Step S405: attempt to obtain an exclusive lock on the database resource within a preset timeout period.
[0082] Step S406: if it is detected that the exclusive lock has not been successfully acquired after the preset timeout period has expired, the preset exclusive mark is changed to a second mark state.
[0083] Step S407, the order of the exclusive lock request in the preset request queue is adjusted backward. Specifically, it can be adjusted backward by a preset number of positions, or it can be adjusted backward to the end of the queue. Because the exclusive lock is not successfully acquired when the preset timeout period is reached, in order to ensure fairness, the exclusive lock request at the head of the queue is first placed backward to give the subsequent shared lock request a chance, thereby reducing the impact on the database processing efficiency.
[0084] In addition, when the type of lock currently held by the database resource is an exclusive lock, the waiting process continues and there is no need to adjust the order of the exclusive lock request in the preset request queue.
[0085] It should be noted that in some other embodiments, without setting a queue, after the exclusive lock request fails to successfully acquire the exclusive lock and the preset exclusive mark is changed to the second mark state, the exclusive lock request can also be suspended and the exclusive locks can be awakened by timed awakening.
[0086] like Figure 5 As shown, in one embodiment, the lock configuration method of the database generally includes:
[0087] Step S501: obtaining a shared lock request for database resources.
[0088] Step S502, check whether the lock state of the database resource has a preset exclusive mark, if so, execute step S505, if not, execute step S503.
[0089] Step S503, check whether the preset request queue is empty, if yes, execute step S504, if no, execute step S505. If the lock state of the database resource does not have a preset exclusive mark, check whether the preset request queue is empty, that is, determine whether there are any waiting lock requests.
[0090] Step S504, acquire the shared lock of the database resource according to the shared lock request. If the preset request queue is empty, it means that there is no waiting lock request, then try to acquire the shared lock of the database resource. If it is detected that the shared lock is not successfully acquired, put the shared lock request into the preset request queue and end the request work. If the shared lock is not successfully acquired, it means that the database resource is currently held by an exclusive lock, then put the shared lock request into the preset request queue and end the request work, waiting to be awakened and executed again.
[0091] Step S505: put the shared lock request into a preset request queue and end the request work.
[0092] If there is a preset exclusive mark, although the current lock held by the database resource is also a shared lock, the shared lock request can no longer obtain the shared lock of the database resource. Then the shared lock request is placed in the preset request queue and the request work is terminated, waiting to be awakened and executed again.
[0093] If the preset request queue is not empty, it means there is a waiting lock request in front, then the shared lock request is put into the preset request queue and the request work is ended, waiting to be awakened and executed again.
[0094] It should be noted that, in some other implementations, this embodiment may also check whether the preset request queue is empty by checking whether the lock state of the database resource is set with a preset wait mark. In this implementation, a preset wait mark is set in the lock state of the database resource when the shared lock request is placed in the preset request queue.
[0095] In addition, when the shared lock request in the queue is awakened, if the shared lock cannot be obtained, it means that the database resource is held by an exclusive lock, then wait for the exclusive lock to be released.
[0096] In one embodiment, when a preset request queue and a preset wait mark are set, the lock configuration method includes: detecting that the preset request queue is empty, clearing the preset wait mark in the lock state of the database resource, thereby preventing the preset wait mark from occupying resources.
[0097] It should be noted that the preset wait mark can be a mark with a count, that is, each time a lock request is placed in the preset request queue, the count of the preset wait mark is increased by 1, and each time a lock request in the preset request queue is awakened and successfully locked, the count of the preset wait mark is reduced by 1. In this way, when the preset wait mark count is 0, the preset wait mark in the lock state of the database resource can be cleared.
[0098] This embodiment also provides a computer device and a computer-readable storage medium. Figure 6 is a schematic diagram of a computer device 10 according to one embodiment of the present invention. Figure 7 is a schematic diagram of a computer-readable storage medium 20 according to one embodiment of the present invention.
[0099] The computer device 10 may include a memory 110, a processor 120, and a computer executable program 11 stored in the memory 110 and running on the processor 120, and the processor 120 implements the database lock configuration method of any of the above embodiments when executing the computer executable program 11.
[0100] The computer-readable storage medium 20 stores a computer-executable program 11 thereon. When the computer-executable program 11 is executed by a processor, the database lock configuration method of any of the above embodiments can be implemented.
[0101] This embodiment also provides a computer program product. Figure 81 is a schematic diagram of a computer program product 30 according to an embodiment of the present invention. The computer program product 30 includes a computer executable program 11, and when the computer executable program 11 is executed by a processor 120, any of the database lock configuration methods described above can be implemented.
[0102] Specifically, the computer executable program 11 for performing the operations of the present invention may be assembly instructions, instruction set architecture (ISA) instructions, computer instructions, computer-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages.
[0103] For the purpose of the description of the present embodiment, the computer-readable storage medium 20 can be any device that can contain, store, communicate, propagate or transmit a program for use with an instruction execution system, device or equipment or in conjunction with these instruction execution systems, devices or equipment. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection portion (electronic device) with one or more wirings, a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and editable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable storage medium 20 can even be paper or other suitable media on which the program can be printed, because the program can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpreting or processing in other suitable ways as necessary, and then stored in a computer memory.
[0104] It should be understood that each part of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0105] The computer device 10 may be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, the computer device 10 may be a cloud acquisition node. The computer device 10 may be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module may include routines, programs, object programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. The computer device 10 may be implemented in a distributed cloud acquisition environment where remote processing devices linked via a communication network perform tasks. In a distributed cloud acquisition environment, program modules may be located on a local or remote acquisition system storage medium including a storage device.
[0106] The computer device 10 may include a processor 120 adapted to execute stored instructions, and a memory 110 that provides temporary storage space for the operation of the instructions during operation. The processor 120 may be a single-core processor, a multi-core processor, an acquisition cluster, or any number of other configurations. The memory 110 may include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.
[0107] The processor 120 may be connected to an I / O interface (input / output interface) suitable for connecting the computer device 10 to one or more I / O devices (input / output devices) via a system interconnect (e.g., PCI, PCI-Express, etc.). The I / O devices may include, for example, a keyboard and a pointing device, wherein the pointing device may include a touch pad or a touch screen, etc. The I / O devices may be built-in components of the computer device 10, or may be devices externally connected to an acquisition device.
[0108] Processor 120 can also be linked to a display interface suitable for connecting computer device 10 to a display device through a system interconnection. Display device can include a display screen as a built-in component of computer device 10. Display device can also include a computer monitor, a television or a projector, etc., which are externally connected to computer device 10. In addition, a network interface controller (NIC) can be suitable for connecting computer device 10 to a network through a system interconnection. In some embodiments, NIC can use any suitable interface or protocol (such as an Internet small computer system interface, etc.) to transmit data. The network can be a cellular network, a radio network, a wide area network (WAN), a local area network (LAN) or the Internet, etc. A remote device can be connected to a computer device through a network.
[0109] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A database lock configuration method, comprising: Obtain an exclusive lock request for database resources; Acquire an exclusive lock of the database resource according to the exclusive lock request; If it is detected that the exclusive lock is not successfully acquired, the type of lock currently held by the database resource is acquired; If the type of lock currently held by the database resource is a shared lock, a preset exclusive mark is added to the lock state of the database resource and set to a first mark state, and the first mark state of the preset exclusive mark is used to prohibit shared lock requests and exclusive lock requests other than the exclusive lock request from obtaining the lock of the database resource.
2. The database lock configuration method according to claim 1, wherein: The preset exclusive mark has a second mark state, and the second mark state allows a shared lock request and an exclusive lock request other than the exclusive lock request to acquire a lock of the database resource; The step of adding a preset exclusive mark to the lock state of the database resource includes: Attempt to obtain an exclusive lock on the database resource within a preset timeout period; If it is detected that the exclusive lock has not been successfully acquired when the preset timeout period is reached, the preset exclusive mark is modified to a second mark state.
3. The database lock configuration method according to claim 2, wherein: The database is configured with a preset request queue, and the preset request queue is used to place lock requests for the database resource in order, and the step of obtaining the type of lock currently held by the database resource includes: Check whether the preset request queue is empty. If so, put the exclusive lock request into the preset request queue and execute the step of obtaining the type of lock currently held by the database resource; if not, put the exclusive lock request into the preset request queue and end the request work.
4. The database lock configuration method according to claim 3, wherein: The step of checking whether the preset request queue is empty includes: checking whether the lock state of the database resource is set with a preset waiting mark, and if so, determining that there is a lock request in the preset request queue, executing the step of placing the exclusive lock request in the preset request queue and ending the request work; If not, determining that the preset request queue is empty, placing the exclusive lock request into the preset request queue and executing the step of obtaining the type of lock currently held by the database resource, and setting a preset waiting mark in the lock state of the database resource; The preset waiting mark is used to indicate that there is a waiting lock request in the preset request queue.
5. The database lock configuration method according to claim 3, wherein: The obtaining of the exclusive lock request for the database resource comprises: obtaining the exclusive lock request in the preset request queue; In the case of acquiring an exclusive lock request in the preset request queue, after the step of detecting that the exclusive lock has not been successfully acquired when the preset timeout period is reached, the method includes: adjusting the order of the exclusive lock request in the preset request queue backward.
6. The database lock configuration method according to claim 3, wherein: Obtaining a shared lock request for the database resource; Check whether the lock state of the database resource has the preset exclusive mark, and if so, put the shared lock request into the preset request queue and end the request work; If not, check whether the preset request queue is empty. If so, obtain the shared lock of the database resource according to the shared lock request. If it is detected that the shared lock is not successfully obtained, put the shared lock request into the preset request queue and end the request work. If not, put the shared lock request into the preset request queue and end the request work.
7. The database lock configuration method according to claim 4, wherein: It is detected that the preset request queue is empty, and the preset waiting mark in the lock state of the database resource is cleared.
8. A computer device comprising a memory, a processor, and a computer executable program stored in the memory and running on the processor, wherein the processor implements the database lock configuration method according to any one of claims 1 to 7 when executing the computer executable program.
9. A computer-readable storage medium having a computer executable program stored thereon, wherein the computer executable program, when executed by a processor, implements the database lock configuration method according to any one of claims 1 to 7.
10. A computer program product, comprising a computer executable program, wherein when the computer executable program is executed by a processor, the database lock configuration method according to any one of claims 1 to 7 is implemented.