Decentralized record lock management method and related equipment for data management system
By adopting a decentralized record lock management method in shared memory and utilizing the relationship between lock information pages and data pages, decentralized management of lock information is achieved, which solves the problem of high competition and high maintenance costs of hash tables in high concurrency scenarios. problems and improve the concurrency and efficiency of the system.
Patent Information
- Application Number
- CN202311308007.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-10
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2043-10-10
AI Technical Summary
In high-concurrency scenarios, the shared memory lock management system has low system efficiency due to high hash table competition and high dynamic maintenance costs. How to reduce the cost of lock management and improve the concurrency of the system has become an urgent technical issue to be solved.
A decentralized record lock management method is adopted to establish a relationship between the lock information page and the data page. The lock information page includes the original lock information structure. When a lock application request is received, the target lock information structure is filtered out from the original lock information structure. Create a lock object based on the lock application request and the lock list, and update the lock information structure to complete the lock application and implement a decentralized lock management structure.
It improves the concurrency of the shared memory lock management system and reduces the cost of lock management. Compared with the hash table method, the maintenance cost is smaller. Each lock information page only needs to maintain the lock information on the data page, reducing the maintenance of lock management. cost.
Smart Images

Figure CN117539650B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a decentralized record lock management method for a data management system. Background Art
[0002] Shared memory is a part of physical memory space that can be accessed by multiple processes (or threads) at the same time, and the advantage of shared memory is that it can achieve efficient data sharing and communication. Because data does not need to be copied and transmitted between different processes, but is directly accessed in memory, the overhead of copying and transmitting data can be reduced, thereby improving the efficiency of data access and communication.
[0003] In a high-concurrency scenario, a process (or thread) needs to acquire a lock before performing an operation on a resource in a shared memory. In the related art, the control of concurrent access between different processes (or threads) is implemented by a lock management system, and the lock management system manages locks in two ways: first, using a hash table to uniformly manage the lock objects of all processes and threads. Second, adopting a global and local hash table collaborative management technology, that is, each process maintains a local hash table and a global hash table. When a process has a lock request, if the local hash table cannot make a judgment, the global hash table will make the judgment. However, for the first management method, all processes (or threads) need to check the hash table when applying for a lock. If in a high-concurrency scenario, the hash table generates a lot of competition, thereby affecting the efficiency of the database system, and the dynamic maintenance cost of the hash table is high. For the second management method, although the global and local hash table collaborative management improves the concurrency of the system, there are still problems such as large competition for the global hash table and high dynamic maintenance cost. Therefore, how to reduce the overhead of lock management and improve the concurrency of the system has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The main purpose of the embodiments of the present application is to propose a decentralized record lock management method and related equipment for a data management system, aiming to reduce the overhead of lock management and improve the concurrency of the system.
[0005] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a decentralized record lock management method for a data management system, which is applied to a shared memory, wherein the shared memory includes: a data page and a lock information page, wherein the data page is provided with a page pointer pointing to the lock information page, and the lock information page includes an original lock information structure; the method includes:
[0006] Obtaining a data processing request of a target process; wherein the data processing request includes: target data information, a lock application request and a lock holding list;
[0007] According to the target data information, a preset original lock information structure is filtered and processed to obtain a target lock information structure; wherein the target lock information structure includes: a spin lock;
[0008] Perform a lock search on the target process according to the target lock information structure to obtain a lock search result;
[0009] If the lock search result indicates that the target process does not own the lock, a lock object is created according to the lock application request, the lock holding list and the target lock information structure to obtain a target lock object, and the target lock object is inserted into a preset lock queue;
[0010] Modify the target lock information structure according to the lock type of the target lock object to obtain an updated lock information structure;
[0011] The spin lock is released according to the update lock information structure to perform a preset target operation on the data on the data page in the shared memory.
[0012] In some embodiments, the lock application request includes any one of the following: a read lock application request and a write lock application request; if the lock search result indicates that the target process does not own the lock, a lock object is created according to the lock application request, the lock holding list and the target lock information structure to obtain a target lock object, and the target lock object is inserted into a preset lock queue, including:
[0013] If the lock search result indicates that the target process does not own the lock, obtaining the lock application request;
[0014] If the lock application request is a read lock application request, a lock object is created according to the read lock application request, the lock holding list and the target lock information structure to obtain a first lock object, and the first lock object is inserted into the preset lock queue;
[0015] If the lock application request is a write lock application request, a lock object is created according to the write lock application request, the lock holding list and the target lock information structure to obtain a second lock object, and the second lock object is inserted into the preset lock queue.
[0016] In some embodiments, the target lock information structure includes: the number of applied read locks, the number of applied write locks, the applied lock queue, the waiting lock queue and the spin lock information; the preset lock queue includes: the applied lock queue and the waiting lock queue, if the lock application request is a read lock application request, a lock object is created according to the read lock application request, the lock holding list and the target lock information structure, a first lock object is obtained, and the first lock object is inserted into the preset lock queue, including:
[0017] If the lock application request is the read lock application request,
[0018] Compare the number of applied write locks with a zero value to obtain a first comparison result;
[0019] If the first comparison result is that the number of applied write locks is equal to zero, create the first lock object, and insert the first lock object into the applied lock queue;
[0020] If the first comparison result is that the number of applied write locks is not equal to zero, the lock type at the top of the applied lock queue is obtained to obtain a first lock type,
[0021] The first lock object is created according to the first lock category, and the first lock object is inserted into the waiting lock queue.
[0022] In some embodiments, if the lock application request is a write lock application request, creating a lock object according to the write lock application request, the lock holding list and the target lock information structure to obtain a second lock object, and inserting the second lock object into the preset lock queue includes:
[0023] If the lock application request is the write lock application request,
[0024] Compare the number of applied write locks, the number of applied read locks, and a zero value to obtain a second comparison result;
[0025] If the second comparison result is that the number of applied write locks and the number of applied read locks are equal to zero, create the second lock object, and insert the second lock object into the waiting lock queue;
[0026] If the second comparison result is that the number of applied write locks or the number of applied read locks is not equal to zero, create the second lock object and insert the second lock object into the applied lock queue.
[0027] In some embodiments, the method further comprises:
[0028] If the lock search result is that the target process already has the lock, obtain the current lock object in the target process and the current lock type of the current lock object;
[0029] If the current lock type is a read lock type, release the spin lock;
[0030] If the current lock category is a write lock category and the current lock object is stronger than the applied lock object, determine whether the element of the applied lock queue is 1; if the element of the applied lock queue is 1, upgrade the lock of the applied lock queue to a write lock; if the element of the applied lock queue is not 1, create a target lock object and insert the target lock object into the waiting lock queue.
[0031] In some embodiments, modifying the target lock information structure according to the lock type of the target lock object to obtain an updated lock information structure includes:
[0032] If the lock type of the first lock object is a read lock or a read-write lock, updating the number of applied read locks;
[0033] If the lock type of the first lock object is a write lock, the number of applied write locks is updated.
[0034] In some embodiments, the data processing request includes: a lock release request; after creating a lock object according to the lock application request, the lock holding list and the target lock information structure to obtain a target lock object, the method further includes:
[0035] The target lock object in the applied lock queue is deleted according to the lock release request, and the category of the deleted target lock object is obtained to obtain the deleted lock category, the category of the first lock in the waiting lock queue is obtained to obtain the first lock category, and the status of the applied lock queue is obtained to obtain the queue status;
[0036] If the delete lock type is a read lock, the number of applied read locks is reduced by one;
[0037] If the delete lock type is a write lock, the number of applied write locks is reduced by one;
[0038] If the delete lock type is a read lock and the queue state is not empty, release the spin lock;
[0039] If the delete lock type is a read lock, the queue state is empty and the first lock type is a write lock, the first write lock in the waiting lock queue is added to the preset lock set, and the locks in the lock set are awakened to release the spin lock.
[0040] In some embodiments, the data processing request includes: a lock wake-up request; after releasing the spin lock according to the update lock information structure to perform a preset target operation on the data on the data page in the shared memory, the method further includes:
[0041] Waking up the target lock object in the waiting lock queue according to the lock wake-up request, and waking up the target process corresponding to the target lock object;
[0042] The target lock object is added to the applied lock queue, and the target lock object in the waiting lock queue is deleted.
[0043] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a device applied to a shared memory, wherein the shared memory includes: a data page and a lock information page, wherein a page pointer pointing to the lock information page is provided in the data page, and the lock information page includes an original lock information structure; the device includes:
[0044] A request acquisition module is used to acquire a data processing request of a target process; wherein the data processing request includes: target data information, a lock application request and a lock holding list;
[0045] A screening module is used to screen and process the preset original lock information structure according to the target data information to obtain a target lock information structure; wherein the target lock information structure includes: a spin lock;
[0046] A lock search module, used to perform a lock search on the target process according to the target lock information structure to obtain a lock search result;
[0047] A lock object creation module, configured to create a lock object according to the lock application request, the lock holding list and the target lock information structure, obtain a target lock object, and insert the target lock object into a preset lock queue if the lock search result indicates that the target process does not own the lock;
[0048] A modification module, used for modifying the target lock information structure according to the lock type of the target lock object to obtain an updated lock information structure;
[0049] A lock release module is used to release the spin lock according to the update lock information structure to perform a preset target operation on the data on the data page in the shared memory.
[0050] To achieve the above objectives, a third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.
[0051] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.
[0052] The decentralized record lock management method and related equipment of the data management system proposed in the present application, when receiving the lock application request sent by the target process, screens out the target lock information structure from the original lock information structure. If the target lock structure indicates that the target process does not have a lock, a lock object is created based on the lock application request, the lock holding list and the target lock information structure to obtain a target lock object, and then the target lock information structure is updated through the target lock object to obtain an updated lock information structure, and the spin lock is released to complete the lock application. Therefore, by maintaining the lock information through the lock information structure, a decentralized lock management structure is realized, the concurrency of the shared memory lock management system is improved, and the maintenance cost is lower than that of the hash table method. Each lock information page only needs to maintain the lock information corresponding to the data on the data page, so that the lock management overhead is reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 It is a system architecture diagram of the lock information page and the data page in the decentralized record lock management method of the data management system provided by the embodiment of the present application;
[0054] Figure 2 It is a flow chart of a decentralized record lock management method of a data management system provided in an embodiment of the present application;
[0055] Figure 3 yes Figure 2 Flow chart of step S203 in FIG.
[0056] Figure 4 It is a schematic diagram of a lock information structure in a decentralized record lock management method of a data management system provided in an embodiment of the present application;
[0057] Figure 5 yes Figure 3 Flow chart of step S301 in FIG.
[0058] Figure 6 It is a detailed flow chart of a read lock application in a decentralized record lock management method of a data management system provided in an embodiment of the present application;
[0059] Figure 7 yes Figure 3 Flow chart of step S302 in FIG.
[0060] Figure 8 is a flow chart of a decentralized record lock management method of a data management system provided by another embodiment of the present application;
[0061] Fig. 9 yes Figure 2 Flow chart of step S204 in FIG.
[0062] Fig.10It is a detailed flow chart of a write lock application in a decentralized record lock management method of a data management system provided in an embodiment of the present application;
[0063] Fig.11 is a flow chart of a decentralized record lock management method of a data management system provided by another embodiment of the present application;
[0064] Fig.12 yes Fig.10 Detailed flow chart of middle lock release;
[0065] Fig.13 is a flow chart of a decentralized record lock management method of a data management system provided by another embodiment of the present application;
[0066] Fig.14 yes Fig.13 Detailed flowchart of middle lock wake-up;
[0067] Fig.15 It is a structural diagram of a decentralized lock management device based on a database provided in an embodiment of the present application;
[0068] Fig.16 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0069] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0070] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0071] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0072] First, some nouns involved in this application are analyzed:
[0073] Shared memory: A large memory that can be accessed by different central processing units (CPUs) in a multi-processor computer system. Since multiple CPUs need to access memory quickly, the memory must be cached. When any cached data is updated, other processors may also need to access it, so the shared memory needs to be updated immediately, otherwise different processors may use different data.
[0074] Data page: A page used to store and organize data, usually used to record and display data in a specific field.
[0075] Information structure: is a data structure used to store and organize different types of information. Information structure usually consists of multiple fields, each field can store different types of data.
[0076] Lock queue: is a multi-thread synchronization mechanism used to ensure mutually exclusive access to shared resources in a multi-threaded environment. The lock queue ensures that only one thread can access shared resources at the same time, and other threads need to wait. In the lock queue, when a thread acquires the lock, other threads must wait until the thread releases the lock. This can avoid data inconsistency or race conditions caused by multiple threads accessing shared resources at the same time.
[0077] Spin lock: a lock introduced specifically to prevent multi-processor concurrency. Spin locks are widely used in the kernel in interrupt processing and other parts (for a single processor, preventing concurrency in interrupt processing can be simply done by turning off interrupts, that is, turning off / on the interrupt flag in the flag register, without the need for a spin lock).
[0078] In the computer field, shared memory is a portion of physical memory space that can be accessed by multiple processes (or threads) at the same time. The advantage of shared memory is that it enables efficient data sharing and communication, because data does not need to be copied and transferred between different processes, but can be accessed directly in memory. This avoids copying and transferring data and overhead, thereby improving the efficiency of data access and communication. However, in high-concurrency scenarios, read and write operations on shared memory also have data contention and synchronization issues.
[0079] In order to solve the above-mentioned problems in high-concurrency scenarios, a process (or thread) needs to acquire a lock before performing operations on resources in shared memory. Because the control of concurrent access between different processes (or threads) is implemented by the lock management system, the lock management system not only records the access to resources and locks held by each process (or thread), but also maintains the corresponding lock waiting queue. When the lock management system receives a new lock request, it will decide whether to satisfy the lock request based on the lock category, lock compatibility, and lock holding status. In the related art, the lock management system mainly manages locks in two ways: first, the lock objects of all processes (or threads) are uniformly managed through a hash table, such as a MySQL database. Second, the global and local hash table collaborative management technology is used, such as a PostgreSQL database. Each process (or thread) maintains a local hash table and a global hash table. When a process (or thread) has a lock request, the local hash table of the process is first used to determine whether the lock request is satisfied. If no judgment can be made, the global hash table is used for judgment. For the first lock management method, all processes (or threads) need to check the hash table when applying for locks, and change the hash table when acquiring and releasing locks. In high-concurrency scenarios, the hash table will also generate a lot of competition, which will affect the efficiency of the database system. At the same time, the dynamic maintenance cost of the hash table is high. Since the number of locks in the hash table is constantly changing, the hash table needs to dynamically allocate memory to handle the corresponding size changes, which will result in additional memory allocation and copying overhead. Moreover, as the number of locks increases, the possibility of lock collisions in the hash table also increases, and additional overhead is required to resolve lock conflicts between processes. For the second lock management method, although the global hash table and local hash table collaborative management technology have improved the concurrency of the system to a certain extent, there is still a lot of competition for the global hash table and high dynamic maintenance cost.
[0080] Based on this, the embodiment of the present application provides a decentralized record lock management method and related equipment for a data management system, by establishing a relationship between a lock information page and a data page, and the lock information page includes an original lock information structure for maintaining lock information. Therefore, when a lock application request sent by a target process is received, if the target process does not own a lock, a target lock information structure is filtered out from the original lock information structure, and then a lock object is created based on the lock application request, a lock holding list, and a target lock information structure to obtain a target lock object, and then the target lock information structure is updated to obtain an updated lock information structure, and the spin lock is released to complete the lock application. Therefore, by maintaining lock information through a lock information structure, a decentralized lock management structure is implemented, the concurrency of a shared memory lock management system is improved, and the maintenance cost is lower than that of a hash table method. Each lock information page only needs to maintain the lock information of the data on the corresponding data page, so that the lock management overhead is reduced.
[0081] The decentralized record lock management method and related equipment of the data management system provided in the embodiment of the present application are specifically explained through the following embodiments. First, the decentralized record lock management method of the data management system in the embodiment of the present application is described.
[0082] The embodiments of the present application can acquire and process relevant data based on computer technology. Among them, computer (Artificial Intelligence, AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0083] Basic computer technologies generally include sensors, special computer chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. Computer software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0084] The decentralized record lock management method of the data management system provided in the embodiment of the present application relates to the field of computer technology. The decentralized record lock management method of the data management system provided in the embodiment of the present application can be applied to the terminal, can also be applied to the server side, and can also be software running in the terminal or the server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or it can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and computer platforms and other basic cloud computing services; the software can be an application that implements the decentralized record lock management method of the data management system, etc., but is not limited to the above forms.
[0085] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0086] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to user identity or characteristics such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of these data will comply with relevant laws, regulations, and standards. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.
[0087] Figure 1 This is a system framework diagram of the shared memory used by the decentralized record lock management method of the data management system provided in the embodiment of the present application. The decentralized record lock management method of the data management system is applied to the shared memory, and the shared memory includes a data page and a lock information page, and the data page includes data and page header data, and the lock information corresponding to the data is stored in the lock information page. A page pointer is stored in the data page, and the page pointer points to the lock information page. Through Figure 1 It can be seen that the system architecture of the decentralized record lock management method of the data management system adopts the decentralized idea. It does not require a unified hash table to manage the lock information of each data, but allocates a lock information page to each data page to manage the lock information of the data on the data page through the lock information page. Among them, the lock information page includes an original lock information structure, and the original lock information structure is an information structure for storing lock information, and each lock information structure records a key-value pair, so as to record the relationship between the data and the lock information in the data page through the key-value pair.
[0088] Figure 2is an optional flowchart of a decentralized record lock management method for a data management system provided in an embodiment of the present application. Figure 2 The method may include but is not limited to steps S201 to S206.
[0089] Step S201, obtaining a data processing request of a target process; wherein the data processing request includes: target data information, a lock application request and a lock holding list;
[0090] Step S202, filtering and processing the preset original lock information structure according to the target data information to obtain a target lock information structure; wherein the target lock information structure includes: a spin lock;
[0091] Step S203, performing a lock search on the target process according to the target lock information structure to obtain a lock search result;
[0092] Step S204: if the lock search result indicates that the target process does not own the lock, a lock object is created according to the lock application request, the lock list and the target lock information structure to obtain the target lock object, and the target lock object is inserted into a preset lock queue;
[0093] Step S205, modifying the target lock information structure according to the lock type of the target lock object to obtain an updated lock information structure;
[0094] Step S206: releasing the spin lock according to the update lock information structure to execute a preset target operation on the data on the data page in the shared memory.
[0095] In the steps S201 to S206 shown in the embodiment of the present application, the target data information, lock application request and lock holding list of the target process are obtained, and the target lock information structure is filtered out from the original information structure according to the target data information. If a lock search result is obtained by performing a lock search on the target process according to the target lock information structure, and the lock search result indicates that the target process does not have a lock, a lock object is created based on the lock application request, the lock holding list and the target lock information structure to obtain a target lock object, and the target lock information structure is modified according to the lock type of the target lock object to obtain an updated lock information structure, and the spin lock is released according to the updated lock information structure to perform a target operation on the data on the data page of the shared memory. Therefore, by using a lock information structure to store the lock information of the data, when a lock application is made and the target process does not own the lock, a lock object can be created directly according to the lock information structure, making the lock object creation operation easier. Moreover, the original lock information structure is the lock information page corresponding to each data page. There is no need to call the hash table each time a lock application is made, thereby realizing a decentralized lock management structure and improving the concurrency of the system. Moreover, by using lock information pages instead of hash tables, the maintenance cost of lock management can be reduced.
[0096] In step S201 of some embodiments, the data processing request provides an application for the target data for the target process, and the data processing request can be an instruction for the target process to process the target data. The data processing request includes: target data information, lock application request and lock holding list, the target data information is the information of the target data that the target process needs to process, the lock application request is the lock application that the target process needs to make for the target data, the lock holding list is the lock list held by the target process, and each process has its own lock holding list. By searching in the lock holding list, it can be determined whether the target process has a lock on the target data. Therefore, it can be determined whether the target process has a lock to process the target data through the target data information, the lock application request and the lock holding list, and the target lock object can be applied according to the judgment result, so as to read and write the target data in the shared memory through the target lock object, which is conducive to the efficient reading and writing of the data in the shared memory.
[0097] In step S202 of some embodiments, the target data information is information about the target data, and the target data information can be used to determine which data the target process needs to apply for a lock. It should be noted that a data page is pre-set, and the data page points to the lock information page through a page pointer. The corresponding selected data page is found in the data page through the target data information, and then the lock information page corresponding to the selected data page is extracted, and the original lock information structure in the lock information page is used as the target lock information structure. Therefore, by setting the lock information page in the data page, the lock information page can be quickly determined according to the target data information, and then the corresponding lock information structure is determined, so that the lock information of the target data is easy to find, and there is no need to set a hash table, which reduces the maintenance cost of lock management, and does not cause the problem of large hash table competition during high concurrency.
[0098] It should be noted that the target lock information structure includes a spin lock. After obtaining the target lock information structure, the spin lock is extracted from the target lock information structure, and the spin lock ensures that only one process (or thread) can read and modify the lock information structure at the same time, so as to ensure that the target process modifies the target lock information structure through the spin lock.
[0099] In step S103 of some embodiments, when a lock application request is received, a lock search is first performed on the target process according to the target lock information structure. It should be noted that the target process is process P, and the lock search result is obtained by querying whether process P has a lock on the target data information.
[0100] In some embodiments, the lock application request includes at least one of the following: a read lock application request and a write lock application request; the read lock application request is used to apply for a read lock of the target data, and the read lock is also called a shared lock, so as to read the target data from the shared memory through the read lock. The write lock application request is used to apply for a write lock of the target data, and the write lock is also called an exclusive lock, so as to write the target data in the shared memory through the write lock.
[0101] It should be noted that in this embodiment, the lock application request includes a read lock application request and a write lock application request. In other embodiments, it may also include application requests for other mode locks, and there is no restriction on other lock types.
[0102] See also Figure 3 In some embodiments, step S203 may include but is not limited to steps S301 to S303:
[0103] Step S301, if the lock search result indicates that the target process does not own the lock, obtain a lock application request;
[0104] Step S302: if the lock application request is a read lock application request, a lock object is created according to the read lock application request, the lock holding list and the target lock information structure to obtain a first lock object, and the first lock object is inserted into a preset lock queue;
[0105] Step S303: If the lock application request is a write lock application request, a lock object is created according to the write lock application request, the lock list and the target lock information structure to obtain a second lock object, and the second lock object is inserted into a preset lock queue.
[0106] In step S301 of some embodiments, if the lock search result indicates that the target process does not own the lock, that is, the target process does not own the lock on the target data information, a lock application request is obtained to create a new lock according to the lock application request or to upgrade the existing lock to the lock corresponding to the lock application request.
[0107] In step S302 of some embodiments, if the lock application request is a read lock application request, a read lock is created according to the read lock application request, the lock list and the target lock information structure to obtain a first lock object, and the first lock object is a read lock for reading target data in the shared memory. After the first lock object is created, the first lock object is inserted into a preset lock queue.
[0108] In step S303 of some embodiments, if the lock application request is a write lock application request, a write lock is created according to the write lock application request, the lock list and the target lock information structure to obtain a second lock object, and the second lock object is a write lock for writing target data into the shared memory. After the second lock object is created, the second lock object is also inserted into the preset lock queue so that subsequent operations can be directly extracted from the preset lock queue.
[0109] In steps S301 to S303 shown in this embodiment, corresponding locks are created according to different lock application requests, and when applying for a lock, lock creation only needs to be performed according to the lock holding list and the target lock information structure, without the need to be completed through a hash table, thereby solving the problem of high contention in the hash table under high concurrency and improving the efficiency of lock application.
[0110] In some embodiments, Figure 4 As shown, through Figure 4 It can be seen that the lock information page stores a series of lock information structures, and the data is stored in the form of key-value pairs on the data page, and the key-value pairs on the data page and the lock information page are associated through pointers. By obtaining the offset on the data page, the lock information page corresponding to the data is determined according to the offset to determine the target lock information structure of the data. The target lock information structure includes: the number of applied read locks, the number of applied write locks, the applied lock queue, the waiting lock queue and the spin lock information. The number of applied read locks is recorded as C S The number of applied read locks is the number of shared locks (read locks) applied for related objects, including lock objects whose application results are waiting. The number of applied write locks is C X , the number of applied write locks is the number of exclusive locks (write locks) applied on the relevant objects, including lock objects whose application results are waiting. The applied lock queue is recorded as GQueue, and the applied lock queue is set with an applied pointer *GQueue, and the applied pointer *GQueue points to the applied lock queue GQueue with a successful application result. The waiting lock queue is recorded as WQueue, and the waiting lock queue is set with a waiting pointer ·WQueue, and the waiting pointer *WQueue points to the waiting lock queue WQueue with an application result of waiting. The spin lock is recorded as And the spin lock ensures that only one target process can read and modify the target lock information structure at the same time.
[0111] See also Figure 5 In some embodiments, step S301 may include but is not limited to steps S501 to S504:
[0112] Step S501, if the lock application request is a read lock application request, compare the number of applied write locks with a zero value to obtain a first comparison result;
[0113] Step S502: if the first comparison result is that the number of applied write locks is equal to zero, create a first lock object and insert the first lock object into the applied lock queue;
[0114] Step S503: if the first comparison result is that the number of applied write locks is not equal to zero, obtain the first lock type in the applied lock queue to obtain the first lock type;
[0115] Step S504: create a first lock object according to the first lock type, and insert the first lock object into a waiting lock queue.
[0116] In step S501 of some embodiments, if the target process needs to apply for a read lock on the target data, after receiving the read lock application request, the number of applied write locks is compared with a zero value to determine whether other processes have applied for write locks on the target data and there is no conflict to obtain a first comparison result. Figure 6 , to determine whether the number of write locks applied is equal to zero, that is, C X =0? If C X =0, the first comparison result is that the number of write locks applied is equal to zero, indicating that there is no lock application conflict; if C X Not equal to 0, the first comparison result is that the number of applied write locks is not equal to zero, indicating that other processes have applied for write locks on the target data, and there may be a lock conflict.
[0117] It should be noted that if the first lock search result is an owned lock, the lock object in the lock holding list is directly returned to the target process as the target lock object, so that the target process can read the target data from the shared memory through the target lock object.
[0118] In step S502 of some embodiments, if the first comparison result is C X =0, indicating that other processes have not applied for write locks on the target data, there is no lock conflict, and the first lock object is directly created. Therefore, when it is determined that there is no process conflict, the lock object creation is completed, and the first lock object is inserted into the applied lock queue to improve the efficiency of lock object creation.
[0119] For example, refer to Figure 6 , judge C X =0, if it is a read lock, the first lock object is created and inserted into the applied lock queue, that is, the first lock object is inserted into the GQueue.
[0120] In steps S503 and S504 of some embodiments, referring to Figure 6 , if the first comparison result is C X≠0, indicating that other processes have applied for write locks on the target data, and there may be lock conflicts. Therefore, it is necessary to further determine the status of write locks applied by other processes to determine whether the write locks applied by other processes are in the waiting or applied stage. The first lock category is obtained by obtaining the first lock category in the applied lock queue, and the first lock category can be a read lock or a read-write lock. If the first lock category is a read lock, it is assumed that all locks in the applied lock queue are read locks, that is, all applied write locks are waiting. At this time, creating a lock object will not cause a conflict, and the first lock object is created directly. If the first lock category is a read-write lock, indicating that the lock application needs to wait, then the first lock object is created, and the first lock object is waited to insert the first lock object into the waiting lock queue.
[0121] For example, refer to Figure 6 , judge C X ≠0 and the first position of GQueue is not a read lock, create the first lock object and insert it into the waiting lock queue. X ≠0 and the first position of GQueue is a read lock, create the first lock object and insert it into the applied lock queue.
[0122] In steps S501 to S504 shown in this embodiment, when applying for a read lock, it is first determined whether there is a lock on the target data in the lock list held by the target process. If there is no lock on the target data in the lock list, it is determined whether there are other processes that have applied for a write lock on the target data based on the number of applied write locks and the applied lock queue, so as to determine whether a conflict will occur when applying for the first lock object at this time, and the creation of the first lock object is completed only when there is no conflict, which not only reduces the incidence of low database operation efficiency caused by lock conflicts, but also improves the efficiency of lock management and realizes decentralized lock management.
[0123] See also Figure 7 In some embodiments, step S302 may include but is not limited to steps S801 to S703:
[0124] Step S701, if the lock application request is a write lock application request, compare the number of applied write locks, the number of applied read locks and zero to obtain a second comparison result;
[0125] Step S702: If the second comparison result is that the number of applied write locks and the number of applied read locks are equal to zero, create a second lock object and insert the second lock object into the applied lock queue;
[0126] Step S703: If the second comparison result is that the number of applied write locks or the number of applied read locks is not equal to zero, create a second lock object and insert the second lock object into the waiting lock queue.
[0127] In step S701 of some embodiments, if the target process does not own a lock, it is necessary to further determine the number of applied read locks and the number of applied write locks corresponding to the target data, and determine whether the number of applied read locks and the number of applied write locks are both 0 to obtain a second comparison result.
[0128] In some embodiments, in step S702 and step S703, if the second comparison result is that the number of applied read locks and the number of applied write locks are both 0, it means that no other process has applied for a lock on the target data, there is no lock conflict, and the second lock object is directly created. If the second comparison result is that the number of applied read locks is not equal to 0 or the number of applied write locks is not equal to 0, it means that other processes have applied for a lock on the target data, that is, other processes have read or written the target data, resulting in a lock conflict, and it is necessary to create a second lock object and wait. For example, please refer to Fig. 9 , judge C S =0? &C X = 0? If yes, create a second lock object. S ≠0 or C X ≠0, create the second lock object.
[0129] It should be noted that after the second lock object is created, if the second comparison result indicates that the number of applied write locks and the number of applied read locks are equal to zero, the second lock object is inserted into the applied lock queue. If the second comparison result indicates that the number of applied write locks is not equal to zero or the number of applied read locks is not equal to zero, the second lock object is inserted into the waiting lock queue.
[0130] In steps S701 to S703 shown in this embodiment, because each data page points to a lock information page, when applying for a write lock, the number of applied read locks, the number of applied write locks, and the applied lock queue on the lock information page are used to determine whether other processes have applied for locks on the target data, so as to determine whether there are processes that perform read and write operations on the target data. Then, when no other process applies for a lock on the target data, a second lock object is created to reduce conflicts between processes, so that data in the shared memory can be processed stably and efficiently.
[0131] Please refer to Figure 8 In some embodiments, after step S103, the database-based decentralized lock management method further includes steps S801 to S803:
[0132] Step S801, if the lock search result shows that the target process already has the lock, obtain the current lock object in the target process and the current lock type of the current lock object;
[0133] Step S802, if the current lock type is a read lock type, release the spin lock;
[0134] Step S803, if the current lock category is a write lock category and the current lock object is stronger than the applied lock object, determine whether the element of the applied lock queue is 1; if the element of the applied lock queue is 1, the lock of the applied lock queue is upgraded to a write lock, if the element of the applied lock queue is not 1, create a target lock object and insert the target lock object into the waiting lock queue.
[0135] In step S801 of some embodiments, when the target process proposes to apply for a write lock on the target data, the target process is first searched to see whether it has a lock on the target data to obtain a lock search result, so as to determine whether the target process has a lock on the target data according to the lock search result. If the lock search result indicates that the lock is already owned, the current lock object of the target process and the current lock category of the current lock object are obtained. It should be noted that the current lock category can be a read lock category or a write lock category.
[0136] In step S801 of some embodiments, if the current lock type is a read lock type, that is, the target process already holds a read lock of the target data, the spin lock is released and the process ends, and the read lock can be directly called from the target process to perform the target operation.
[0137] In step S802 of some embodiments, if the current lock category is a write lock, it is necessary to further determine the lock level of the lock of the target data in the lock list to determine whether the lock level of the current lock object held by the target process is lower than the preset level. It should be noted that the preset level is the level of the lock application, and the lock level of the read lock is defined to be lower than the lock level of the write lock, that is, to determine whether the current lock object held by the target process for the target data is a read lock or a write lock, and then determine whether it is necessary to create another lock object based on the lock level of the lock already held. If the lock level is lower than the preset level, that is, it is determined that the current lock object is stronger than the applied lock, and it is deduced that the lock held by the target process is a read lock, and a write lock needs to be applied for, then it is further determined whether the number of locks in the applied lock queue is 1. If the number of locks in the applied lock queue is 1, the read lock in the applied lock queue is upgraded to a write lock to obtain a second lock object. If the number of locks in the applied lock queue is not 1, create a second lock object. For example, please refer to Fig. 9 If the target process has a lock on the target data, it is necessary to determine whether the lock level of the currently applied lock is higher than the preset level. If so, it is further determined whether the number of locks in the applied lock queue is 1. Otherwise, a second lock object is created. If so, the read lock in the applied lock queue is upgraded to a write lock to obtain the second lock object.
[0138] It should be noted that if the lock level is not lower than the preset level, that is, the lock held by the target process is not weaker than the currently applied lock, and it has a write lock, then the write lock is directly used as the second lock object, and the spin lock is released, and the second lock object is returned to the target process, so that the target process can write the target data to the shared memory according to the second lock object.
[0139] Please refer to Fig. 9 In some embodiments, step S204 may include but is not limited to steps S901 to S902:
[0140] Step S901, updating the number of applied read locks in the target lock information structure according to the first lock object to obtain an updated lock information structure;
[0141] Step S902: If the second lock object updates the number of applied write locks in the target lock information structure, an updated lock information structure is obtained.
[0142] In step S901 of some embodiments, the first lock object is a read lock, indicating that all the locks in the applied lock pair list are read locks, and the applied write lock is pending, so creating a new first lock object will not cause a conflict. After the first lock object is created, the first lock object is inserted into the applied lock queue, and the number of applied read locks is updated, that is, the number of applied read locks increases by one. If the first lock object is a read-write lock, it means that creating the lock will cause a conflict, and the first lock object needs to be inserted into the waiting lock queue to wait for a period of time before returning the first lock object to the target process, to ensure that the read lock application will not conflict with the write lock application of other processes, thereby improving the efficiency of creating the first lock object. For example, refer to Figure 6 , determine whether the first position of GQueue is a read lock. If it is a read lock, create the first lock object, insert the first lock object into the applied lock queue, and update the number of applied read locks C S , and then release the spin lock to complete the read lock application. If the first lock in GQueue is a read-write lock, a lock conflict occurs, and the current lock application needs to wait. The first lock object is inserted into the waiting lock queue WQueue, and the number of applied read locks C is updated. S , and then release the spin lock to complete the read lock application.
[0143] In step S902 of some embodiments, the second lock object is a write lock, and the number of applied write locks in the target lock information structure needs to be updated according to the creation of the write lock. It should be noted that if the second lock object is created, the number of applied write locks C X Add one so that you can determine how many write locks have been applied for based on the number of write locks applied for.
[0144] For example, Fig.10 As shown in Figure 1, if the lock application request is a write lock application request, and the target process does not have the lock corresponding to the target data information, C S , C X When both are 0, the second lock object is inserted into the applied lock queue to return the second lock object to the target process and release the spin lock so that the target process can input the target data into the shared memory according to the second lock object to reduce lock conflicts. After the second lock object is inserted into the applied lock queue, the number of applied write locks is updated, that is, the number of applied write locks CX Plus one. If the second lock object is a write lock, and C S ≠0 or C X ≠0, insert the second lock object into the waiting lock queue, let the second lock object wait for a period of time before returning it to the target process, to reduce the conflict between the target process and other processes operating the target data. After the second lock object is inserted into the waiting lock queue, update the number of applied write locks, that is, C X . It should be noted that if the target process already has the lock corresponding to the target data information, determine whether the lock level of the current lock object is less than the preset lock level. If the current lock object is weaker than the applied lock, and the element in the applied lock queue is 1, upgrade the read lock in the applied lock queue to a write lock to obtain a second lock object. Then the number of applied read locks and the number of applied write locks are updated synchronously, that is, the number of applied read locks is reduced by 1, and the number of applied write locks is increased by 1. If the element in the applied lock queue is not 1, create a second lock object, insert the second lock object into the waiting lock queue, and increase the number of applied write locks by 1.
[0145] In steps S901 to S901 shown in this embodiment, after the creation of the first lock object or the second lock object is completed, it is necessary to update the number of applied read locks in the target lock information structure according to the first lock object, and update the number of applied write locks in the target lock information structure according to the second lock object, so that subsequent application operations can determine whether there is a lock corresponding to the target data based on the number of applied read locks or the number of applied write locks.
[0146] See also Fig.11 In some embodiments, the data processing request includes: a lock release request; after step S105, the decentralized record lock management method of the data management system may also include but is not limited to steps S1101 to S1105:
[0147] Step S1101, according to the lock release request, the target lock object in the applied lock queue is deleted, and the category of the deleted target lock object is obtained to obtain the deleted lock category, the category of the first lock in the waiting lock queue is obtained to obtain the first lock category, and the status of the applied lock queue is obtained to obtain the queue status;
[0148] Step S1102, if the lock type to be deleted is a read lock, the number of applied read locks is reduced by one;
[0149] Step S1103, if the lock type to be deleted is a write lock, the number of write locks applied for is reduced by one;
[0150] Step S1104, if the deletion lock type is a read lock and the queue state is not empty, release the spin lock;
[0151] Step S1105, if the deleted lock type is a read lock, the queue state is empty and the first lock type is a write lock, the first write lock in the waiting lock queue is added to the preset lock set, and the locks in the lock set are awakened to release the spin lock.
[0152] In step S1101 of some embodiments, when the target process completes the read lock or write lock application, after the target data is read according to the read lock or the target data is written to the shared memory according to the write lock, the read lock and the write lock need to be released. At the same time, the update lock information structure of the target data also needs to be modified synchronously, so that the substitute process can directly determine whether there is another process currently reading and writing the target data according to the lock information structure, thereby reducing the situation where multiple processes generate lock conflicts. Therefore, a lock release request sent by the target process is received, and the lock release request is used to indicate the target lock object of the target data to be released from the applied lock queue. Therefore, the corresponding target lock object is deleted in the applied lock queue according to the lock release request. It should be noted that after the deletion of the target lock object is completed, the lock category of the target lock object deleted in the applied lock queue is obtained to obtain the deletion lock category, and the status of the applied lock queue is obtained to obtain the queue status, so as to modify the update lock information structure according to the deletion lock category and the queue status.
[0153] In some embodiments, in step S1102 to step S1103, if the delete lock type is a read lock, the number of applied read locks is reduced by one; if the delete lock type is a write lock, the number of applied write locks is reduced by one to modify the update lock information structure of the target data. Therefore, by deleting the update lock information structure corresponding to the delete lock type, it is convenient to directly determine whether there are other process operations on the target data according to the update lock information structure when applying next time, so as to reduce conflicts between processes.
[0154] In some embodiments, in step S1104 to step S1105, after the modification of the number of applied read locks and the number of applied write locks is completed, it is determined whether the queue status of the applied lock queue is empty. If it is not empty, it indicates that the released lock is a read lock, and other read locks have not been released. There is no need to wake up the lock, and release the spin lock to complete the lock release operation. If the queue status is empty, it is necessary to wake up other locks in the waiting lock queue, and determine whether the first lock in the waiting lock queue is a write lock. If it is necessary, write the first write lock in the waiting lock queue to the preset lock set. If the first lock is not a write lock, all read locks in the waiting lock queue are directly added to the lock set to wake up the locks in the lock set, and release the spin lock to end the lock release operation.
[0155] For example, see Fig.12, after deleting the lock from the applied lock list, change the number of applied read locks and the number of applied write locks corresponding to the target data. Then determine whether the target lock object that needs to be deleted by the target process in the waiting lock queue is a write lock. If so, add the waiting write lock to the preset lock set L. Then wake up the lock in the lock set L and release the spin lock. If the target lock object is not a write lock, determine whether the applied lock pair list is empty. If so, continue to determine whether the first one in the waiting lock queue is a write lock. If it is a write lock, add the first write lock to the lock set L, and wake up the lock in the lock set L. If the first one in the waiting lock queue is not a write lock, add the lock in the waiting lock queue to the lock set L, and then wake up the lock set L to release the spin lock to complete the release of the target lock object.
[0156] In steps S1101 to S1105 shown in this embodiment, after the target data operation is completed by the target process, the corresponding lock is deleted from the applied lock queue, and then the number of applied read locks and the number of applied write locks are synchronously modified, and after determining that the locks in the applied lock queue and the waiting lock queue meet the preset conditions, the lock is put into the lock set and awakened to achieve a complete lock release operation. Therefore, when other processes or the target process need to continue to read and write the target data next time, it can also directly determine whether there is a conflict with other processes through the lock information structure of the target data, so as to reduce process competition and improve the concurrency of the system.
[0157] See also Fig.13 In some embodiments, the data processing request includes: a lock wake-up request; after step S106, the decentralized record lock management method of the data management system may also include but is not limited to steps S1301 to S1302:
[0158] Step S1301, waking up the target lock object in the waiting lock queue according to the lock wake-up request, and waking up the target process corresponding to the target lock object;
[0159] Step S1302, adding the target lock object to the applied lock queue, and deleting the target lock object in the waiting lock queue.
[0160] In some embodiments, in step S1301 to step S1302, please refer to Fig.14, after putting the lock into the lock set, it is necessary to wake up the lock in the lock set, or to wake up the target lock object or target process. If a lock wake-up request is received, the target lock object of the target data is woken up according to the lock wake-up request, and the target process corresponding to the target lock object is woken up. After waking up the target process and target object, the target lock object is added to the applied lock queue, and the target lock object in the waiting lock queue is deleted to complete the wake-up of the target lock object. It should be noted that the lock objects in the lock set are the same as the wake-up operation of the target lock object. They all need to be added from the waiting lock queue to the applied lock queue for wake-up, and the lock objects in the waiting lock queue are deleted.
[0161] In steps S1301 to S1302 shown in this embodiment, the corresponding lock object and process are awakened according to the lock awakening request, and then the lock object is placed in the applied lock queue, and the corresponding lock object in the waiting lock queue is deleted, so that the lock object awakening operation is simple.
[0162] In summary, the row lock application and release process proposed by the present invention uses the counters of the number of applied read locks Cx and the number of applied write locks Cs to quickly judge the lock operation process (such as the lock application mentioned above). MySQL database and PostgreSQL database also have similar technologies, which make quick judgments by counting. For example, PostgreSQL database will record the number of strong table locks on a certain table object to perform quick lock conflict detection on the application of table lock. However, the processing flow of row locks in MySQL database and PostgreSQL database is not optimized by counting. This is because MySQL database and PostgreSQL database essentially use hash tables (the key is row ID, and the value is the lock object corresponding to the row) to manage row locks. If counting is used for judgment, an additional hash table is required to store the count, resulting in too much storage overhead and low optimization efficiency. In comparison, the lock information page management mode proposed by the present invention is lighter and easier to be optimized. It should be further explained that MySQL database and PostgreSQL database are currently the two most mainstream open source relational databases, and both manage lock objects based on hash tables, so they face problems such as large hash table competition and high dynamic hash maintenance costs. The present invention provides a decentralized record lock management method for a data management system, which uses a lock information page to maintain the lock information of each data. Compared with the above two databases, it has the following advantages: (1) The decentralized lock management structure improves the concurrency of the system; (2) The lock information on the lock page can be stored in an array, which has a lower maintenance cost than dynamic hashing; (3) Each lock information page only needs to maintain the lock information of the data on its corresponding data page, and the synchronization overhead is relatively low.
[0163] See also Fig.15The embodiment of the present application also provides a decentralized lock management device based on a database, which can implement the decentralized record lock management method of the above-mentioned data management system, and is applied to a shared memory, wherein the shared memory includes: a data page and a lock information page, wherein a page pointer pointing to the lock information page is provided in the data page, and the lock information page includes an original lock information structure; the device includes:
[0164] The request acquisition module 1501 is used to acquire the data processing request of the target process; wherein the data processing request includes: target data information, lock application request and lock holding list;
[0165] The screening module 1502 is used to screen and process the preset original lock information structure according to the target data information to obtain the target lock information structure; wherein the target lock information structure includes: a spin lock;
[0166] The lock search module 1503 is used to perform a lock search on the target process according to the target lock information structure to obtain a lock search result;
[0167] The lock object creation module 1504 is used to create a lock object according to the lock application request, the lock list and the target lock information structure, obtain the target lock object, and insert the target lock object into the preset lock queue if the lock search result indicates that the target process does not have the lock;
[0168] A modification module 1505 is used to modify the target lock information structure according to the lock type of the target lock object to obtain an updated lock information structure;
[0169] The lock release module 1506 is used to release the spin lock according to the update lock information structure to perform a preset target operation on the data on the data page in the shared memory.
[0170] The specific implementation of the database-based decentralized lock management device is basically the same as the specific implementation of the decentralized record lock management method of the above-mentioned data management system, and will not be repeated here.
[0171] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the decentralized record lock management method of the above data management system when executing the computer program. The electronic device can be any smart terminal including a tablet computer, a car computer, etc.
[0172] See also Fig.16 , Fig.16 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0173] The processor 1601 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0174] The memory 1602 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1602 can store an operating system and other applications. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1602, and the processor 1601 calls and executes the decentralized record lock management method of the data management system of the embodiment of this application;
[0175] Input / output interface 1603, used to implement information input and output;
[0176] The communication interface 1604 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);
[0177] A bus 1605 that transmits information between various components of the device (e.g., the processor 1601, the memory 1602, the input / output interface 1603, and the communication interface 1604);
[0178] The processor 1601 , the memory 1602 , the input / output interface 1603 and the communication interface 1604 are connected to each other in communication within the device via the bus 1605 .
[0179] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0180] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0181] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0182] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0183] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application 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 interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0184] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0185] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as 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 devices or units, which can be electrical, mechanical or other forms.
[0186] The units described above 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.
[0187] In addition, each functional unit in each embodiment of the present application 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.
[0188] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, 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, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0189] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A decentralized record lock management method for a data management system, characterized in that: Applied to a shared memory, the shared memory includes: a data page and a lock information page, the data page is provided with a page pointer pointing to the lock information page, and the lock information page includes an original lock information structure; the method includes: Obtaining a data processing request of a target process; wherein the data processing request includes: target data information, a lock application request and a lock holding list; wherein the lock application request includes any one of the following: a read lock application request and a write lock application request; Filtering and processing the preset original lock information structure according to the target data information to obtain a target lock information structure; wherein the target lock information structure includes: spin lock, the number of applied read locks, the number of applied write locks, the applied lock queue, the waiting lock queue and spin lock information; performing a lock search on the target process according to the target lock information structure to obtain a lock search result; If the lock search result indicates that the target process does not own the lock, a lock object is created according to the lock application request, the lock holding list and the target lock information structure to obtain a target lock object, and the target lock object is inserted into a preset lock queue, including: If the lock search result indicates that the target process does not own the lock, obtaining the lock application request; If the lock application request is a read lock application request, a lock object is created according to the read lock application request, the lock holding list and the target lock information structure to obtain a first lock object, and the first lock object is inserted into the preset lock queue; wherein the preset lock queue includes: an applied lock queue and a waiting lock queue; If the lock application request is a read lock application request, creating a lock object according to the read lock application request, the lock holding list and the target lock information structure to obtain a first lock object, and inserting the first lock object into the preset lock queue specifically includes: If the lock application request is the read lock application request, comparing the applied write lock quantity with a zero value to obtain a first comparison result; If the first comparison result is that the number of applied write locks is equal to zero, create the first lock object, and insert the first lock object into the applied lock queue; Creating the first lock object according to the first lock category, and inserting the first lock object into the waiting lock queue; Modify the target lock information structure according to the lock type of the target lock object to obtain an updated lock information structure; The spin lock is released according to the update lock information structure to perform a preset target operation on the data on the data page in the shared memory.
2. The method according to claim 1, characterized in that If the lock search result indicates that the target process does not own the lock, a lock object is created according to the lock application request, the lock holding list and the target lock information structure to obtain a target lock object, and the target lock object is inserted into a preset lock queue, further comprising: If the lock application request is a write lock application request, a lock object is created according to the write lock application request, the lock holding list and the target lock information structure to obtain a second lock object, and the second lock object is inserted into the preset lock queue.
3. The method according to claim 1, characterized in that If the lock application request is a read lock application request, creating a lock object according to the read lock application request, the lock holding list and the target lock information structure to obtain a first lock object, and inserting the first lock object into the preset lock queue, further comprising: If the first comparison result is that the number of applied write locks is not equal to zero, obtaining the lock type at the first position in the applied lock queue to obtain a first lock type; The first lock object is created according to the first lock category, and the first lock object is inserted into the waiting lock queue.
4. The method according to claim 3, characterized in that: If the lock application request is a write lock application request, creating a lock object according to the write lock application request, the lock holding list and the target lock information structure to obtain a second lock object, and inserting the second lock object into the preset lock queue, including: If the lock application request is the write lock application request, the number of applied write locks, the number of applied read locks and a zero value are compared to obtain a second comparison result; If the second comparison result is that the number of applied write locks and the number of applied read locks are equal to zero, create the second lock object and insert the second lock object into the applied lock queue; If the second comparison result is that the number of applied write locks or the number of applied read locks is not equal to zero, the second lock object is created and inserted into the waiting lock queue.
5. The method according to claim 3, characterized in that: The method further comprises: If the lock search result is that the target process already has the lock, obtain the current lock object in the target process and the current lock type of the current lock object; If the current lock type is a read lock type, release the spin lock; If the current lock category is a write lock category and the current lock object is stronger than the applied lock object, determine whether the element of the applied lock queue is 1; if the element of the applied lock queue is 1, upgrade the lock of the applied lock queue to a write lock; if the element of the applied lock queue is not 1, create a target lock object and insert the target lock object into the waiting lock queue.
6. The method according to claim 4, characterized in that The modifying the target lock information structure according to the lock type of the target lock object to obtain an updated lock information structure includes: The number of applied read locks in the target lock information structure is updated according to the first lock object to obtain the updated lock information structure; The number of applied write locks in the target lock information structure is updated according to the second lock object to obtain the updated lock information structure.
7. The method according to any one of claims 3 to 6, characterized in that: The data processing request includes: a lock release request; after creating a lock object according to the lock application request, the lock holding list and the target lock information structure to obtain a target lock object, the method further includes: The target lock object in the applied lock queue is deleted according to the lock release request, and the category of the deleted target lock object is obtained to obtain the deleted lock category, the category of the first lock in the waiting lock queue is obtained to obtain the first lock category, and the status of the applied lock queue is obtained to obtain the queue status; If the delete lock type is a read lock, the number of applied read locks is reduced by one; If the delete lock type is a write lock, the number of applied write locks is reduced by one; If the delete lock type is a read lock and the queue state is not empty, release the spin lock; If the delete lock type is a read lock, the queue state is empty and the first lock type is a write lock, the first write lock in the waiting lock queue is added to the preset lock set, and the locks in the lock set are awakened to release the spin lock.
8. The method according to any one of claims 3 to 6, characterized in that: The data processing request includes: a lock wake-up request; after the spin lock is released according to the update lock information structure to perform a preset target operation on the data on the data page in the shared memory, the method further includes: Waking up the target lock object in the waiting lock queue according to the lock wake-up request, and waking up the target process corresponding to the target lock object; The target lock object is added to the applied lock queue, and the target lock object in the waiting lock queue is deleted.
9. A decentralized lock management device based on a database, characterized in that: Applied to a shared memory, the shared memory is used to execute a decentralized record lock management method of a data management system according to any one of claims 1 to 8, the shared memory comprises: a data page and a lock information page, the data page is provided with a page pointer pointing to the lock information page, the lock information page comprises an original lock information structure; the device comprises: A request acquisition module is used to acquire a data processing request of a target process; wherein the data processing request includes: target data information, a lock application request and a lock holding list; A screening module is used to screen and process the preset original lock information structure according to the target data information to obtain a target lock information structure; wherein the target lock information structure includes: a spin lock; A lock search module, used to perform a lock search on the target process according to the target lock information structure to obtain a lock search result; A lock object creation module, configured to create a lock object according to the lock application request, the lock holding list and the target lock information structure, obtain a target lock object, and insert the target lock object into a preset lock queue if the lock search result indicates that the target process does not own the lock; A modification module, used for modifying the target lock information structure according to the lock type of the target lock object to obtain an updated lock information structure; A lock release module is used to release the spin lock according to the update lock information structure to perform a preset target operation on the data on the data page in the shared memory.
10. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the decentralized record lock management method of the data management system according to any one of claims 1 to 8 when executing the computer program.
Citation Information
Patent Citations
Large critical region protection method
CN102141932A
Method and system for optimizing reader-writer lock based on Linux
CN105224251A
Lock management method in cluster, lock server and client
CN109359081A
Process management method and device, computer equipment and storage medium
CN112346879A
Process lock holding detection method and electronic equipment and readable medium thereof
CN114625545A
