Data unit access and update method, device, electronic device and storage medium

By setting one-to-one corresponding locks and pointers for each data unit in the database, and controlling the object update frequency according to preset conditions, the problem of global lock contention under multi-thread concurrency is solved and database performance is improved.

CN118260272BActive Publication Date: 2024-09-20TIANJIN NANKAI UNIV GENERAL DATA TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410683437.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-30
Publication Date
2024-09-20
Estimated Expiration
2044-05-30

AI Technical Summary

Technical Problem

In the case of multi-thread concurrency, the access speed in the database is slow due to global lock contention, which in turn causes database performance to decrease.

Method used

By setting a one-to-one corresponding lock and pointer for each data unit, the lock is used in the locking process, and the pointer is used to point to the object in the cache pool, reducing dependence on global locks, and controlling the placement of objects in the queue according to preset update conditions. The location update frequency in .

Benefits of technology

It reduces contention for global locks and improves database access speed and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118260272B
    Figure CN118260272B
Patent Text Reader

Abstract

The present application is applicable to the field of electronic digital data processing technology, and provides a data unit access and update method, device, electronic device and storage medium. The method includes: receiving a request sent by a thread to access a target data unit in a database, and obtaining a target lock corresponding to the target data unit according to the request; if the target lock is obtained, and the target pointer corresponding to the target lock is not empty, then based on the target lock, the target object corresponding to the target data unit in the cache pool pointed to by the target pointer is sent to the thread, and the target lock is released; determine whether to update the position of the target object in the cache pool queue according to the preset update condition; if updated, move the position of the target object in the cache pool queue to the preset position towards the head of the queue. The present application sets a target lock and a target pointer, which can reduce the contention of the global lock when multiple threads are concurrent, and sets a preset update condition, which can reduce the update frequency of the target object, further reduce the contention of the global lock, and improve the performance of the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of electronic digital data processing, and in particular to a data unit access and update method, device, electronic device and storage medium. Background Art

[0002] The smallest unit of database access is the data unit. The database includes multiple data units, and each data unit stores multiple data. For example, each data unit in the GBase 8a database stores 65536 data. The database is stored in a storage device. In order to reduce the number of accesses to the storage device, a cache pool is usually used to save the data in the data unit read from the storage device. When a working thread needs to access a data unit, it first queries the object (data) corresponding to the data unit in the cache pool, and updates the queried object in the queue in the cache pool.

[0003] The above query and update steps require understanding or changing the storage structure of the cache pool, so global locks are required to ensure that only one worker thread accesses the current data unit. When multiple worker threads need to materialize data with discrete row numbers, different data units may be frequently accessed. For example, if the database includes 1,000 data units and the current task is to get a piece of data from each data unit, 1,000 data units need to be accessed at the same time. Since query and update steps involve global locks, when multiple worker threads are concurrent, serious global lock contention will occur, and the access speed will be slow, which will cause database performance degradation. Summary of the invention

[0004] In view of this, the embodiments of the present application provide a data unit access and update method, device, electronic device and storage medium to solve the technical problem in the related technology that when multiple working threads are concurrent, it will cause serious global lock contention, slow access speed, and thus cause database performance degradation.

[0005] In a first aspect, an embodiment of the present application provides a data unit access and update method, including:

[0006] A request for accessing a target data unit in a database sent by a receiving thread is used to obtain a target lock corresponding to the target data unit according to the request;

[0007] If the target lock is acquired and the target pointer corresponding to the target lock is not empty, then based on the target lock, the target object corresponding to the target data unit in the cache pool pointed to by the target pointer is sent to the thread, and the target lock is released; wherein, the data unit corresponds to the lock one-to-one, the lock corresponds to the pointer one-to-one, the lock is used to lock the processing process of the object of the corresponding data unit in the cache pool after the lock is acquired, and the pointer is used to point to the object corresponding to the data unit in the cache pool;

[0008] Determine whether to update the position of the target object in the cache pool queue according to a preset update condition; wherein the cache pool includes objects corresponding to a plurality of data units in the database, and each object is arranged in the form of a queue; the preset update condition is determined according to the last update time of the target object or the reference count corresponding to the target object;

[0009] If it is determined to be updated, the position of the target object in the buffer pool queue is moved toward the head of the queue by a preset position.

[0010] In a possible implementation of the first aspect, the method further includes:

[0011] If the target lock is acquired and the target pointer corresponding to the target lock is empty, constructing a target object corresponding to the target data unit in the cache pool based on the target data unit in the storage device where the database is located;

[0012] Based on the target lock, the target pointer is pointed to the target object in the cache pool, the target object in the cache pool pointed to by the target pointer is sent to the thread, and the target lock is released.

[0013] In a possible implementation of the first aspect, the method further includes:

[0014] If the target lock is not acquired, determining the number of times each thread acquires the target lock within a preset time period, and determining whether the number is greater than a preset number threshold;

[0015] If the number of times is greater than the preset number threshold, the target lock is acquired again after a preset time interval, until the target lock is acquired.

[0016] In a possible implementation manner of the first aspect, determining whether to update the position of the target object in the cache pool queue according to a preset update condition includes:

[0017] Determine whether the time interval between the current time and the last update time of the target object is greater than a preset time threshold;

[0018] If the time interval is greater than the preset time threshold, it is determined to update the position of the target object in the cache pool queue.

[0019] In a possible implementation manner of the first aspect, determining whether to update the position of the target object in the cache pool queue according to a preset update condition includes:

[0020] Based on the target lock, updating the reference count corresponding to the target object, and determining whether the updated reference count of the target object is greater than a preset count threshold;

[0021] If the updated reference count is greater than the preset count threshold, it is determined to update the position of the target object in the cache pool queue.

[0022] In a possible implementation manner of the first aspect, after constructing the target object corresponding to the target data unit in the cache pool, the method further includes:

[0023] Obtain the global lock corresponding to the cache pool;

[0024] If the global lock is acquired, it is determined whether the number of objects in the cache pool is greater than a preset number threshold, and when the number of objects in the cache pool is greater than the preset number threshold, the first object with a reference count of 0 is eliminated based on the global lock along the queue in the cache pool from the tail to the head, and the global lock is released.

[0025] In a possible implementation of the first aspect, moving the position of the target object in the buffer pool queue toward the head of the queue by a preset position includes:

[0026] Obtain the global lock corresponding to the cache pool;

[0027] If the global lock is acquired, the target object is updated to the head of the queue in the cache pool based on the global lock, and the global lock is released.

[0028] In a second aspect, an embodiment of the present application provides a data unit access and update device, including:

[0029] A receiving module, configured to receive a request sent by a thread to access a target data unit in a database, and obtain a target lock corresponding to the target data unit according to the request;

[0030] An access module, for, when the target lock is acquired and the target pointer corresponding to the target lock is not empty, based on the target lock, sending the target object corresponding to the target data unit in the cache pool pointed to by the target pointer to the thread, and releasing the target lock; wherein the data unit corresponds to the lock one-to-one, the lock corresponds to the pointer one-to-one, the lock is used to lock the processing process of the object of the corresponding data unit in the cache pool after the lock is acquired, and the pointer is used to point to the object corresponding to the data unit in the cache pool;

[0031] A judgment module, used to determine whether to update the position of the target object in the cache pool queue according to a preset update condition; wherein the cache pool includes objects corresponding to multiple data units in the database, and each object is arranged in the form of a queue; the preset update condition is determined according to the last update time of the target object or the reference count corresponding to the target object;

[0032] The update module is used to move the position of the target object in the cache pool queue to a preset position towards the head of the queue when determining to update.

[0033] In a third aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the computer program, the data unit access and update method as described in any one of the first aspects is implemented.

[0034] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the data unit access and update method as described in any one of the first aspects.

[0035] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the data unit access and update method described in any one of the first aspects above.

[0036] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.

[0037] The data unit access and update method, device, electronic device and storage medium provided in the embodiments of the present application set locks and pointers corresponding to the data units one by one, wherein the lock is used to lock the processing process of the object of the corresponding data unit in the cache pool after the lock is obtained, and the pointer is used to point to the object corresponding to the data unit in the cache pool. In this way, when it is necessary to access the target data unit in the database, the target lock corresponding to the target data unit can be obtained, and when the target lock is obtained and the target pointer corresponding to the target lock is not empty, the target object corresponding to the target data unit is directly sent to the thread based on the target lock and the target pointer. Therefore, there is no need to use a global lock to query whether there is a target object corresponding to the target data unit in the cache pool, and the contention for the global lock can be reduced when multiple threads are concurrent. In addition, a preset update condition is set and the position of the target object in the cache pool queue is updated only when the preset update condition is met, thereby reducing the update frequency of the target object, reducing the contention for the global lock, and improving the access speed, thereby improving the database performance.

[0038] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present specification. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0040] Figure 1 It is a flowchart of a data unit access and update method provided by an embodiment of the present application;

[0041] Figure 2 It is a structural diagram of a data unit access and update device provided by an embodiment of the present application;

[0042] Figure 3 It is a schematic diagram of the structure of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0043] The present application is described more clearly below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the effects of the present application, but are not intended to limit the present application in any form. It should be noted that, for those of ordinary skill in the art, several variations and improvements may be made without departing from the concept of the present application. These all fall within the scope of protection of the present application.

[0044] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0045] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0046] In the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0047] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0048] In addition, the “plurality” mentioned in the embodiments of the present application should be interpreted as two or more.

[0049] When a worker thread needs to access a data unit, it first queries the cache pool for the object corresponding to the data unit, and then updates the queried object in the queue in the cache pool. The above query and update steps all require the use of the global lock corresponding to the cache pool. When multiple worker threads are concurrent, they may frequently access different data units, which will lead to serious global lock contention, slow access speed, and thus degrade database performance.

[0050] Optionally, taking a communication system as an example, the communication system may include a network device and a terminal device with communication functions, there may be multiple terminal devices, and the network device may be a device that communicates with each terminal device. The network device includes a storage device, and the storage device includes a database. The database includes multiple data units, and each data unit can store relevant data of a terminal device. In order to reduce the number of times the storage device is accessed, a cache pool is used to save the data in the data unit read from the storage device, that is, the relevant data of the terminal device stored in the cache data unit in the cache pool. If a terminal device accesses a data unit in the network device, a global lock is required to ensure that only one working thread accesses the current data unit. When multiple working threads are concurrent, different data units may be frequently accessed, which will cause serious global lock contention.

[0051] Based on the above problems, the inventors have found through research that locks and pointers corresponding to data units can be set one by one, wherein the lock is used to lock the processing process of the object of the corresponding data unit in the cache pool after the lock is obtained, and the pointer is used to point to the object corresponding to the data unit in the cache pool. In this way, when it is necessary to access the target data unit in the database, the target lock corresponding to the target data unit can be obtained, and when the target lock is obtained and the target pointer corresponding to the target lock is not empty (indicating that the cache pool includes the target object corresponding to the target data unit), the target object corresponding to the target data unit is directly sent to the thread based on the target lock and the target pointer. Therefore, there is no need to use a global lock to query whether the target object corresponding to the target data unit exists in the cache pool, and the contention for the global lock can be reduced when multiple threads are concurrent. In addition, a preset update condition is set and the position of the target object in the cache pool queue is updated only when the condition is met, thereby reducing the update frequency of the target object, reducing the contention for the global lock, and thereby improving the database performance.

[0052] Figure 1 FIG. 1 is a flow chart of a method for accessing and updating a data unit provided in an embodiment of the present application. Figure 1 As shown, the method in the embodiment of the present application may include:

[0053] Step 101: A request for accessing a target data unit in a database sent by a receiving thread is used to obtain a target lock corresponding to the target data unit according to the request.

[0054] As can be seen from the above, the database is stored in a storage device and includes multiple data units, which are units that actually store data. In order to reduce the number of times the storage device is accessed, a cache pool is usually used to save the data in the data unit read from the storage device, that is, the cache pool includes objects corresponding to multiple data units in the database.

[0055] Exemplarily, in this embodiment, the data unit corresponds to the lock one by one, and the lock is used to lock the processing process of the object of the corresponding data unit in the cache pool after the lock is acquired to ensure that multiple threads cannot access the same object at the same time. This embodiment acquires the target lock corresponding to the target data unit according to the target data unit indicated by the request.

[0056] Step 102: If the target lock is acquired and the target pointer corresponding to the target lock is not empty, based on the target lock, the target object corresponding to the target data unit in the cache pool pointed to by the target pointer is sent to the thread, and the target lock is released.

[0057] Among them, the lock corresponds to the pointer one by one, and the pointer is used to point to the object corresponding to the data unit in the cache pool. In this embodiment, the object pointed to by the pointer can be directly accessed by reading the pointer. Here, the pointer pointing to the object can be understood as the pointer indicating how to find the corresponding object.

[0058] Optionally, after acquiring the target lock, if the target pointer corresponding to the target lock is not empty, it means that the cache pool includes the target object corresponding to the target data unit, that is, the target pointer points to the target object corresponding to the target data unit in the cache pool, so that the target object can be sent to the corresponding thread through the target pointer. In this process, in order to ensure that multiple threads cannot access the target object at the same time, the process of sending the target object to the corresponding thread through the target pointer can be locked based on the target lock.

[0059] In this way, compared with the related art that needs to use the global lock of the cache pool to query whether the cache pool includes the target object corresponding to the target data unit, this embodiment can use the target lock and the target pointer to determine whether the cache pool includes the target object corresponding to the target data unit, and the target lock and the target pointer only correspond to the target object, thereby reducing the contention for the global lock when multiple threads are concurrent.

[0060] In a possible implementation, this embodiment can also construct a target object corresponding to the target data unit in the cache pool based on the target data unit in the storage device where the database is located when the target lock is acquired and the target pointer corresponding to the target lock is empty. Then, based on the target lock, the target pointer is pointed to the target object in the cache pool, and the target object in the cache pool pointed to by the target pointer is sent to the thread, and the target lock is released.

[0061] Exemplarily, after acquiring the target lock, if the target pointer corresponding to the target lock is empty, it means that the target object corresponding to the target data unit is not included in the cache pool. At this time, the target data unit in the database of the storage device needs to be loaded into the cache pool, that is, the target object corresponding to the target data unit is constructed in the cache pool. After that, the target pointer is pointed to the target object in the cache pool, and the target object is sent to the corresponding thread through the target pointer. In this process, in order to ensure that multiple threads cannot access the target object at the same time, the process of pointing the target pointer to the target object in the cache pool and sending the target object to the corresponding thread through the target pointer can be locked based on the target lock.

[0062] In a possible implementation, this embodiment can also determine the number of times each thread acquires the target lock within a preset time period when the target lock is not acquired, and determine whether the number is greater than a preset number threshold. If the number is greater than the preset number threshold, the target lock is acquired again after a preset time interval until the target lock is acquired.

[0063] Optionally, in this embodiment, if the target lock cannot be acquired, it means that other threads are accessing the target object corresponding to the target data unit in the cache pool. At this time, in order to avoid repeatedly executing the action of acquiring the target lock, the number of times each thread acquires the target lock within a preset time period is greater than a preset number threshold, that is, when the target lock is frequently used, the action of acquiring the target lock is no longer executed, but the target lock is acquired again after a preset time interval until the target lock is acquired. In this way, it can be avoided that the action of acquiring the target lock is repeatedly executed without acquiring the target lock. And when the number of times each thread acquires the target lock within a preset time period is less than or equal to the preset number threshold, that is, when the target lock is not used frequently, the target lock can be acquired until the target lock is acquired.

[0064] Step 103: Determine whether to update the position of the target object in the cache pool queue according to a preset update condition.

[0065] The cache pool includes objects corresponding to multiple data units in the database, and each object is arranged in the form of a queue; the preset update condition is determined according to the last update time of the target object or the reference count corresponding to the target object.

[0066] From the above, it can be seen that in the related technology, after determining the target object in the cache pool, the target object is updated to the head of the cache pool queue, for example, the LirsUpdate function is called to update the target object to the head of the queue. In this process, the storage structure of the cache pool will be changed, so a global lock is required, which will cause serious global lock contention when multiple threads are concurrent.

[0067] Exemplarily, after determining the target object in the cache pool, this embodiment can determine whether to update the position of the target object in the cache pool queue according to the preset update condition, and only update the position of the target object in the cache pool queue when the preset update condition is met, otherwise it will not be updated. In this way, the update frequency of the target object can be reduced, thereby reducing the contention of the global lock when multiple threads are concurrent. Among them, the preset update condition can be determined according to the last update time of the target object or the reference count corresponding to the target object. For example, the preset update condition can be whether the time interval between the current time and the last update time of the target object is greater than a preset time threshold, etc.

[0068] Step 104: If it is determined to be updated, the position of the target object in the buffer pool queue is moved toward the head of the queue by a preset position.

[0069] In a possible implementation, the preset position may be determined based on actual conditions. For example, the preset position is determined based on the position of the head of a queue in a cache pool. In this embodiment, when the position of the target object in the cache pool queue is moved toward the head of the queue by a preset position, the global lock corresponding to the cache pool may be acquired. When the global lock is acquired, the target object may be updated to the head of the queue in the cache pool based on the global lock, and the global lock may be released.

[0070] Exemplarily, in this embodiment, after determining the position of the target object to be updated in the cache pool queue according to the preset update condition, the global lock is first acquired. When the global lock is acquired, the target object is updated to the head of the queue in the cache pool, or the target object is updated to the front preset position of the queue in the cache pool. In this process, to ensure that multiple threads cannot access the target object at the same time, the process of updating the target object in the cache pool queue can be locked based on the global lock.

[0071] Optionally, if the global lock is not acquired, it means that the global lock is occupied at this time, and the global lock can be acquired again until the global lock is acquired; alternatively, the number of times each thread acquires the global lock within a preset time period is determined, and when the number of times the global lock is acquired is greater than a preset threshold, the global lock is acquired again after a preset time interval until the global lock is acquired.

[0072] The data unit access and update method provided in the embodiment of the present application sets locks and pointers corresponding to the data units one by one, wherein the lock is used to lock the processing process of the object of the corresponding data unit in the cache pool after the lock is obtained, and the pointer is used to point to the object corresponding to the data unit in the cache pool. In this way, when it is necessary to access the target data unit in the database, the target lock corresponding to the target data unit can be obtained, and when the target lock is obtained and the target pointer corresponding to the target lock is not empty, the target object corresponding to the target data unit is directly sent to the thread based on the target lock and the target pointer. Therefore, there is no need to use a global lock to query whether there is a target object corresponding to the target data unit in the cache pool, and the contention for the global lock can be reduced when multiple threads are concurrent. In addition, a preset update condition is set and the position of the target object in the cache pool queue is updated only when the preset update condition is met, thereby reducing the update frequency of the target object, reducing the contention for the global lock, and improving the access speed, thereby improving the database performance.

[0073] In some embodiments, the preset update condition may be whether the time interval between the current time and the last update time of the target object is greater than a preset time threshold. Thus, when determining whether to update the position of the target object in the cache pool queue according to the preset update condition, this embodiment may determine whether the time interval between the current time and the last update time of the target object is greater than the preset time threshold, and determine to update the position of the target object in the cache pool queue when the time interval is greater than the preset time threshold.

[0074] Exemplarily, if the time interval between the current time and the last update time of the target object is greater than the preset time threshold, it indicates that the update of the target object is not frequent, and the position of the target object in the cache pool queue can be updated at this time; otherwise, it indicates that the update of the target object is frequent, and the position of the target object in the cache pool queue will no longer be updated this time, so as to reduce the update frequency of the target object and thereby reduce the contention for the global lock.

[0075] In some embodiments, the preset update condition may be whether the updated reference count of the target object is greater than a preset count threshold. Thus, when determining whether to update the position of the target object in the cache pool queue according to the preset update condition, this embodiment may update the reference count corresponding to the target object based on the target lock, and determine whether the updated reference count of the target object is greater than the preset count threshold. When the updated reference count is greater than the preset count threshold, it is determined to update the position of the target object in the cache pool queue.

[0076] Exemplarily, after determining the target object in the cache pool, this embodiment updates the reference count corresponding to the target object, for example, calling the Lock function to add 1 to the reference count corresponding to the target object. In this process, to ensure that multiple threads cannot access the target object at the same time, the process of updating the reference count corresponding to the target object can be locked based on the target lock.

[0077] Optionally, if the updated reference count of the target object is greater than a preset count threshold, it indicates that the target object is frequently accessed, and the position of the target object in the cache pool queue can be updated at this time; otherwise, it indicates that the target object is not frequently accessed, and the position of the target object in the cache pool queue will not be updated this time to reduce the update frequency of the target object, thereby reducing contention for the global lock.

[0078] In some embodiments, after constructing the target object corresponding to the target data unit in the cache pool, the present embodiment can also obtain the global lock corresponding to the cache pool. When the global lock is obtained, it is determined whether the number of objects in the cache pool is greater than a preset number threshold, and when the number of objects in the cache pool is greater than the preset number threshold, along the queue in the cache pool from the tail to the head of the queue, the first object with a reference count of 0 is eliminated based on the global lock, and the global lock is released.

[0079] Exemplarily, the number of objects corresponding to the data units included in the cache pool is limited, that is, the number of objects of the data units included in the cache pool does not exceed the maximum number threshold under normal circumstances. Therefore, after constructing the target object corresponding to the target data unit in the cache pool, when the number of objects in the cache pool is greater than the preset number threshold, the object with the first reference count of 0 is eliminated from the queue from the end to the head, that is, the object with the first reference count of 0 is removed from the cache pool, thereby ensuring that the number of objects in the cache pool does not exceed the preset number threshold, and ensuring the performance of the database. Among them, the preset number threshold can be determined according to the maximum number threshold, for example, the preset number threshold is equal to the maximum number threshold.

[0080] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0081] Figure 2 1 is a schematic diagram of the structure of a data unit access and update device provided by an embodiment of the present application. Figure 2 As shown, the data unit access and update device provided in this embodiment may include: a receiving module 201 , an access module 202 , a determination module 203 and an update module 204 .

[0082] The receiving module 201 is used to receive a request sent by a thread to access a target data unit in a database, and obtain a target lock corresponding to the target data unit according to the request.

[0083] The access module 202 is used to send the target object corresponding to the target data unit in the cache pool pointed to by the target pointer to the thread and release the target lock based on the target lock when the target lock is acquired and the target pointer corresponding to the target lock is not empty; wherein, the data unit corresponds to the lock one-to-one, and the lock corresponds to the pointer one-to-one. The lock is used to lock the processing process of the object of the corresponding data unit in the cache pool after the lock is acquired, and the pointer is used to point to the object corresponding to the data unit in the cache pool.

[0084] The judgment module 203 is used to determine whether to update the position of the target object in the cache pool queue according to a preset update condition; wherein the cache pool includes objects corresponding to multiple data units in the database, and each object is arranged in the form of a queue; the preset update condition is determined according to the last update time of the target object or the reference count corresponding to the target object.

[0085] The updating module 204 is used to move the position of the target object in the buffer pool queue to the head of the queue by a preset position when determining to update.

[0086] Optionally, the access module 202 is further configured to:

[0087] If the target lock is acquired and the target pointer corresponding to the target lock is empty, constructing a target object corresponding to the target data unit in the cache pool based on the target data unit in the storage device where the database is located;

[0088] Based on the target lock, the target pointer is pointed to the target object in the cache pool, the target object in the cache pool pointed to by the target pointer is sent to the thread, and the target lock is released.

[0089] Optionally, the access module 202 is further configured to:

[0090] If the target lock is not acquired, determining the number of times each thread acquires the target lock within a preset time period, and determining whether the number is greater than a preset number threshold;

[0091] If the number of times is greater than the preset number threshold, the target lock is acquired again after a preset time interval, until the target lock is acquired.

[0092] Optionally, the determination module 203 is specifically used for:

[0093] Determine whether the time interval between the current time and the last update time of the target object is greater than a preset time threshold;

[0094] If the time interval is greater than the preset time threshold, it is determined to update the position of the target object in the cache pool queue.

[0095] Optionally, the determination module 203 is specifically used for:

[0096] Based on the target lock, updating the reference count corresponding to the target object, and determining whether the updated reference count of the target object is greater than a preset count threshold;

[0097] If the updated reference count is greater than the preset count threshold, it is determined to update the position of the target object in the cache pool queue.

[0098] Optionally, the access module 202 is further configured to:

[0099] Obtain the global lock corresponding to the cache pool;

[0100] If the global lock is acquired, it is determined whether the number of objects in the cache pool is greater than a preset number threshold, and when the number of objects in the cache pool is greater than the preset number threshold, the first object with a reference count of 0 is eliminated based on the global lock along the queue in the cache pool from the tail to the head, and the global lock is released.

[0101] Optionally, the updating module 204 is specifically used for:

[0102] Obtain the global lock corresponding to the cache pool;

[0103] If the global lock is acquired, the target object is updated to the head of the queue in the cache pool based on the global lock, and the global lock is released.

[0104] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0105] Figure 3 Schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Figure 3 As shown, the electronic device 300 of this embodiment includes: a processor 310 and a memory 320, wherein the memory 320 stores a computer program 321 that can be run on the processor 310. When the processor 310 executes the computer program 321, the steps in any of the above method embodiments are implemented, for example Figure 1 Alternatively, when the processor 310 executes the computer program 321, the functions of each module / unit in the above-mentioned device embodiments are implemented, for example Figure 2 The functions of modules 201 to 204 are shown.

[0106] Exemplarily, the computer program 321 may be divided into one or more modules / units, one or more modules / units are stored in the memory 320, and are executed by the processor 310 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 321 in the electronic device 300.

[0107] Those skilled in the art will understand that Figure 3 These are merely examples of electronic devices and do not constitute a limitation of the electronic device. The electronic device may include more or fewer components than those shown in the figure, or a combination of certain components, or different components, such as input and output devices, network access devices, buses, etc.

[0108] The processor 310 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0109] The memory 320 may be an internal storage unit of the electronic device, such as a hard disk or memory of the electronic device, or an external storage device of the electronic device, such as a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. The above-mentioned memory 320 may also include both an internal storage unit of the electronic device and an external storage device. The above-mentioned memory 320 is used to store computer programs and other programs and data required by the electronic device. The memory 320 may also be used to temporarily store data that has been output or is to be output.

[0110] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0111] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0112] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0113] In the embodiments provided by the present invention, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. For example, the device / electronic device embodiments described above are only schematic. For example, the division of the modules or 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.

[0114] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0115] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0116] If the integrated module / 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 present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal and software distribution medium, etc.

[0117] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.

Claims

1. A data unit access and update method, characterized in that: include: A request for accessing a target data unit in a database sent by a receiving thread is received, and a target lock corresponding to the target data unit is acquired according to the request; If the target lock is acquired and the target pointer corresponding to the target lock is not empty, then based on the target lock, the target object corresponding to the target data unit in the cache pool pointed to by the target pointer is sent to the thread, and the target lock is released; wherein, the data unit corresponds to the lock one-to-one, the lock corresponds to the pointer one-to-one, the lock is used to lock the processing process of the object of the corresponding data unit in the cache pool after the lock is acquired, and the pointer is used to point to the object corresponding to the data unit in the cache pool; Determine whether to update the position of the target object in the cache pool queue according to a preset update condition; wherein the cache pool includes objects corresponding to a plurality of data units in the database, and each object is arranged in the form of a queue; the preset update condition is determined according to the last update time of the target object or the reference count corresponding to the target object; If the update is determined, the position of the target object in the buffer pool queue is moved toward the head of the queue by a preset position; Wherein, determining whether to update the position of the target object in the cache pool queue according to a preset update condition includes: Determine whether the time interval between the current time and the last update time of the target object is greater than a preset time threshold; if the time interval is greater than the preset time threshold, determine to update the position of the target object in the cache pool queue; Alternatively, based on the target lock, the reference count corresponding to the target object is updated, and it is determined whether the updated reference count of the target object is greater than a preset count threshold; if the updated reference count is greater than the preset count threshold, it is determined to update the position of the target object in the cache pool queue.

2. The data unit access and update method according to claim 1, characterized in that: The method further comprises: If the target lock is acquired and the target pointer corresponding to the target lock is empty, constructing a target object corresponding to the target data unit in the cache pool based on the target data unit in the storage device where the database is located; Based on the target lock, the target pointer is pointed to the target object in the cache pool, the target object in the cache pool pointed to by the target pointer is sent to the thread, and the target lock is released.

3. The data unit access and update method according to claim 1, characterized in that: The method further comprises: If the target lock is not acquired, determining the number of times each thread acquires the target lock within a preset time period, and judging whether the number is greater than a preset number threshold; If the number of times is greater than the preset number threshold, the target lock is acquired again after a preset time interval, until the target lock is acquired.

4. The data unit access and update method according to claim 2, characterized in that: After constructing the target object corresponding to the target data unit in the cache pool, the method further includes: Obtain the global lock corresponding to the cache pool; If the global lock is acquired, it is determined whether the number of objects in the cache pool is greater than a preset number threshold, and when the number of objects in the cache pool is greater than the preset number threshold, the first object with a reference count of 0 is eliminated based on the global lock along the queue in the cache pool from the tail to the head, and the global lock is released.

5. The data unit access and update method according to any one of claims 1 to 3, characterized in that: The step of moving the position of the target object in the buffer pool queue toward the head of the queue by a preset position includes: Obtain the global lock corresponding to the cache pool; If the global lock is acquired, the target object is updated to the head of the queue in the cache pool based on the global lock, and the global lock is released.

6. A data unit access and update device, characterized in that: include: A receiving module, configured to receive a request sent by a thread to access a target data unit in a database, and obtain a target lock corresponding to the target data unit according to the request; An access module, for, when the target lock is acquired and the target pointer corresponding to the target lock is not empty, based on the target lock, sending the target object corresponding to the target data unit in the cache pool pointed to by the target pointer to the thread, and releasing the target lock; wherein the data unit corresponds to the lock one-to-one, the lock corresponds to the pointer one-to-one, the lock is used to lock the processing process of the object of the corresponding data unit in the cache pool after the lock is acquired, and the pointer is used to point to the object corresponding to the data unit in the cache pool; A judgment module, used to determine whether to update the position of the target object in the cache pool queue according to a preset update condition; wherein the cache pool includes objects corresponding to multiple data units in the database, and each object is arranged in the form of a queue; the preset update condition is determined according to the last update time of the target object or the reference count corresponding to the target object; An updating module, used for moving the position of the target object in the cache pool queue toward the head of the queue by a preset position when determining to update; The judgment module is specifically used to judge whether the time interval between the current time and the last update time of the target object is greater than a preset time threshold; if the time interval is greater than the preset time threshold, determine to update the position of the target object in the cache pool queue; Alternatively, based on the target lock, the reference count corresponding to the target object is updated, and it is determined whether the updated reference count of the target object is greater than a preset count threshold; if the updated reference count is greater than the preset count threshold, it is determined to update the position of the target object in the cache pool queue.

7. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, the data unit access and update method according to any one of claims 1 to 5 is implemented.

8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the data unit access and update method according to any one of claims 1 to 5 is implemented.