Shared resource processing method and device applying distributed lock and electronic equipment
By allocating shared resources to multiple resource segments and configuring distributed locks, multi-resource segmentation parallel processing in high concurrency scenarios is realized, the system's concurrent processing capability is improved, and the problem of low distributed lock efficiency is solved.
Patent Information
- Application Number
- CN202411723297.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-02-21
AI Technical Summary
In high concurrency and flash sale scenarios, the distributed lock efficiency is low, resulting in reduced system processing capabilities and the inability to effectively ensure the data consistency of shared resources.
Assign shared resources to multiple resource segments, each resource segment is configured with a distributed lock, and the system's concurrent processing capability is improved by processing multiple resource segments in parallel.
By allocating shared resources to multiple resource segments and configuring distributed locks, parallel processing of multiple resource segments is realized, the system's concurrent processing capability is improved, and the problem of low distributed lock efficiency is solved.
Smart Images

Figure CN119493636A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device and electronic device for processing shared resources using a distributed lock. Background Art
[0002] With the development of information technology, the requirements for system processing capabilities are getting higher and higher. In order to improve processing capabilities, many systems currently use distributed deployment. The data consistency problem in distributed scenarios is a more concerned issue in this scenario. Distributed locks are usually used to solve the data consistency problem in distributed scenarios. Distributed locks are a mechanism used to control the access of multiple clients to shared resources in a distributed system, and ensure data consistency through mutually exclusive access.
[0003] In high-concurrency and flash sales scenarios, access to shared resources is critical. For example, the products purchased by customers in flash sales are shared resources for the service provider. Usually, the service provider is deployed in a distributed manner. When calculating whether the product can be sold, each service will first access the inventory (the inventory is a shared resource). The product can only be sold if the inventory is sufficient. If the data access is inconsistent, it may lead to overselling of products, which will lead to business risks. In order to ensure the consistent reading and writing of the shared resource inventory, the service provider adopts a distributed lock. When the customer's flash sale request reaches the service provider, the service provider first obtains the distributed lock, and then accesses the inventory and performs business logic processing. Before releasing the lock, other user requests are always in a waiting state for the lock, which ensures mutual exclusive access to the inventory and ensures the data consistency of the shared resource inventory. However, this will result in only processing a single user request at the same time when accessing the inventory and processing the business logic. For high-concurrency flash sales, the processing of business reduces the system processing capacity and produces related problems such as low efficiency of distributed locks. Summary of the invention
[0004] In order to solve the above problems, this application provides the following technical solutions:
[0005] A method for processing shared resources using distributed locks, comprising:
[0006] In response to receiving a shared resource acquisition request from a requesting end, acquiring a target distributed lock corresponding to the shared resource acquisition request from at least one resource segment;
[0007] When the resources in the target resource segment corresponding to the target distributed lock satisfy the shared resource acquisition request, releasing the target distributed lock of the target resource segment, so that the requesting end accesses the resources stored in the target resource segment based on the target distributed lock;
[0008] The shared resources are allocated to at least one resource segment, and each resource segment is configured with a corresponding distributed lock.
[0009] Optionally, it also includes:
[0010] In a case where resources in the target resource segment corresponding to the target distributed lock do not satisfy the shared resource acquisition request, determining a first resource segment in other resource segments except the target resource segment;
[0011] The first distributed lock corresponding to the first resource segment is released, so that the requesting end obtains the resources stored in the first resource segment based on the first distributed lock.
[0012] Optionally, it also includes:
[0013] When the requesting end accesses the resources stored in the target resource segment based on the target distributed lock and uses the resources stored in the target resource segment to perform business processing, the resources stored in the target resource segment are adjusted.
[0014] Optionally, it also includes:
[0015] The amount of resources to obtain shared resources;
[0016] Based on the resource amount, dividing the shared resource into at least one resource segment, and storing each resource segment in a memory database;
[0017] A corresponding distributed lock is configured for each resource segment, so that resources of the resource segment are accessed based on the distributed lock.
[0018] Optionally, it also includes:
[0019] In the case that resources corresponding to the shared resources are stored in each of the resource segments, newly added shared resources are obtained, and the newly added shared resources are divided into each of the resource segments.
[0020] Optionally, it also includes:
[0021] In response to a request end accessing a resource in the resource segment, controlling the request end to access an original shared resource in the resource segment based on a first access logic, wherein the original shared resource is a resource stored in the resource segment before the newly added shared resource;
[0022] Controlling the requesting end to access the newly added shared resource in the resource segment based on the second access logic;
[0023] The resource access modes in the resource segments corresponding to the first access logic and the second access logic are different.
[0024] A shared resource processing device using a distributed lock, comprising:
[0025] An acquisition unit, configured to, in response to receiving a shared resource acquisition request from a requesting end, acquire a target distributed lock corresponding to the shared resource acquisition request from at least one resource segment;
[0026] A release unit, configured to release the target distributed lock of the target resource segment when the resources in the target resource segment corresponding to the target distributed lock meet the shared resource acquisition request, so that the requesting end can access the resources stored in the target resource segment based on the target distributed lock;
[0027] The shared resources are allocated to at least one resource segment, and each resource segment is configured with a corresponding distributed lock.
[0028] Optionally, it also includes:
[0029] A resource acquisition unit, used for obtaining the resource amount of shared resources;
[0030] A partitioning unit, configured to partition the shared resource into at least one resource segment based on the resource amount, and store each resource segment in a memory database;
[0031] A configuration unit is used to configure a corresponding distributed lock for each resource segment, so that resources of the resource segment can be accessed based on the distributed lock.
[0032] Optionally, it also includes:
[0033] The newly added resource processing unit is used to obtain newly added shared resources and divide the newly added shared resources into each of the resource segments when resources corresponding to the shared resources are stored in each of the resource segments.
[0034] An electronic device, comprising:
[0035] A memory, used to store applications and data generated by the operation of the applications;
[0036] The processor is used to execute the application program to implement the shared resource processing method of the application distributed lock as described in any one of the above.
[0037] Compared with the prior art, the present application provides a shared resource processing method, device and electronic device using distributed locks. In response to receiving a shared resource acquisition request from a requesting end, a target distributed lock corresponding to the shared resource acquisition request is acquired from at least one resource segment; when the resources in the target resource segment corresponding to the target distributed lock satisfy the shared resource acquisition request, the target distributed lock of the target resource segment is released, so that the requesting end can access the resources stored in the target resource segment based on the target distributed lock. In an embodiment of the present application, shared resources are allocated to at least one resource segment, and each resource segment is configured with a corresponding distributed lock. By segmenting shared resources, the efficiency of distributed locks is improved, and parallel processing of multiple resource segments is achieved, thereby improving the concurrent processing capability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0039] Figure 1 A flow chart of a method for processing shared resources using a distributed lock provided in an embodiment of the present application;
[0040] Figure 2 A schematic diagram of a process of accessing resources through a distributed lock in an application scenario provided in an embodiment of the present application;
[0041] Figure 3 A schematic diagram of the structure of a shared resource processing device using a distributed lock provided in an embodiment of the present application. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0043] The terms "first" and "second" in this application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may include steps or units that are not listed.
[0044] In order to facilitate the description of the relevant contents of the embodiments of the present application, the relevant terms used in the embodiments of the present application are now explained.
[0045] In-memory database: Compared with traditional databases that store data on disk for management, in-memory databases store data in memory and operate directly. They have higher performance and are often used as cache to improve system response speed. Common in-memory databases include Redis and others.
[0046] Distributed locks: In distributed systems, it is often necessary to coordinate their actions. If different systems or different hosts in the same system share one or a group of resources, then when accessing these resources, mutual exclusion is required to prevent interference with each other to ensure consistency. At this time, distributed locks are needed. Distributed locks are a way to control the synchronous access to shared resources between distributed systems.
[0047] See also Figure 1 , is a flow chart of a shared resource processing method applied to a distributed lock provided in an embodiment of the present application, the method may include the following steps:
[0048] S101 . In response to receiving a shared resource acquisition request from a requesting end, acquiring a target distributed lock corresponding to the shared resource acquisition request from at least one resource segment.
[0049] S102: When the resources in the target resource segment corresponding to the target distributed lock satisfy the shared resource acquisition request, release the target distributed lock of the target resource segment, so that the requesting end can access the resources stored in the target resource segment based on the target distributed lock.
[0050] The requesting end is a device end that needs to obtain shared resources, such as a user end. Shared resources can be resources that multiple clients can access. For example, in scenarios such as high concurrency and flash sales, access to shared resources is particularly critical. The products purchased by the client through flash sales are shared resources for the service provider. Usually, the service provider is deployed in a distributed manner. When calculating whether the product can be sold, each service will first access the inventory, where the inventory is a shared resource. In an embodiment of the present application, the shared resources are allocated to at least one resource segment, and each resource segment is configured with a corresponding distributed lock. Further, the shared resources can be evenly distributed to the resource segments. The shared resources are segmented and evenly dispersed into each resource segment, and each resource segment is stored as a field in the database. When mutually exclusive access is made to shared resources, a separate distributed lock is used to control each resource segment. Originally, access to resources was serial, but now with the increase in segments and distributed locks, each requesting end can concurrently access each resource segment, thereby improving the system concurrency performance.
[0051] After receiving a shared resource acquisition request, a distributed lock can be randomly acquired from at least one resource segment and used as the target distributed lock. Then, it is detected whether the resources in the corresponding target resource segment meet the shared resource acquisition request. If so, the target distributed lock corresponding to the target resource segment will be released, so that the requesting end can acquire the resources stored in the target resource segment, so that the requesting end can perform related business processing based on the resources.
[0052] In an embodiment of the present application, a method for processing shared resources using distributed locks is provided. In response to receiving a shared resource acquisition request from a requesting end, a target distributed lock corresponding to the shared resource acquisition request is acquired from at least one resource segment; when the resources in the target resource segment corresponding to the target distributed lock satisfy the shared resource acquisition request, the target distributed lock of the target resource segment is released, so that the requesting end can access the resources stored in the target resource segment based on the target distributed lock. In an embodiment of the present application, shared resources are allocated to at least one resource segment, and each resource segment is configured with a corresponding distributed lock. By segmenting shared resources, the efficiency of distributed locks is improved, and parallel processing of multiple resource segments is achieved, thereby improving the concurrent processing capability of the system.
[0053] In one implementation of the embodiment of the present application, the method further includes: when the resources in the target resource segment corresponding to the target distributed lock do not satisfy the shared resource acquisition request, determine a first resource segment in other resource segments except the target resource segment; release the first distributed lock corresponding to the first resource segment, so that the requesting end obtains the resources stored in the first resource segment based on the first distributed lock. In this implementation, when the resources in the target resource segment do not satisfy the request of the requesting end, other resource segments will continue to be accessed, such as accessing the first resource segment. If the resources in the first resource segment satisfy the request, the corresponding first distributed lock will be released to obtain the resources stored in the first resource segment.
[0054] Furthermore, the method also includes: when the requesting end accesses the resources stored in the target resource segment based on the target distributed lock and uses the resources stored in the target resource segment to perform business processing, adjusting the resources stored in the target resource segment.
[0055] In this implementation, after the requesting end obtains the corresponding shared resource from the corresponding resource segment (such as the target resource segment), the resource in the target resource segment will be adjusted based on the current business processing result to meet the subsequent shared resource acquisition request. For example, the shared resource is the inventory of a certain commodity, when the inventory stored in the target resource segment is the first inventory, the current request corresponds to the second inventory, and the second inventory is less than the first inventory, then when the target resource segment responds to the request, the inventory in the target resource segment will be adjusted to the difference between the first inventory and the second inventory.
[0056] The resource segmentation in the embodiment of the present application is described in detail below. In one embodiment, the resource amount of the shared resource is obtained; based on the resource amount, the shared resource is divided into at least one resource segment, and each of the resource segments is stored in the memory database; a corresponding distributed lock is configured for each of the resource segments, so that the resources of the resource segment are accessed based on the distributed lock. Specifically, the shared resources can be evenly divided into each resource segment according to the resource amount of the shared resource, or there can be a certain quantity deviation in the resource amount of each resource segment. Each segment is stored as a field in the database. When mutually exclusive access is made to shared resources, a separate lock is used to control each segment. Originally, access to resources was serial, but now with the increase in segmentation and distributed locks, each process can concurrently access each segment, thereby improving the system concurrency performance.
[0057] Furthermore, it also includes: when resources corresponding to the shared resources are stored in each of the resource segments, newly added shared resources are obtained, and the newly added shared resources are divided into each of the resource segments. In a concurrent scenario, if the amount of resources needs to be increased, such as the business needs to increase inventory, the newly added shared resources can be divided into each resource segment to ensure the consistency of the shared resources.
[0058] After adding a new shared resource to the resource segment, the corresponding access logic can be used to control the application or target thread corresponding to the resource request end to access the corresponding resource. For example, when the shared resource is inventory, such processing can avoid modifying hot data due to the business demand for increasing inventory in concurrent scenarios, causing potential business risks. Specifically, in one implementation of the embodiment of the present application, it also includes: in response to the request end accessing the resources in the resource segment, controlling the request end to access the original shared resource in the resource segment based on the first access logic, and the original shared resource is the resource stored in the resource segment before the newly added shared resource; controlling the request end to access the newly added shared resource in the resource segment based on the second access logic; wherein the resource access methods in the resource segment corresponding to the first access logic and the second access logic are different. The first access logic and the second access logic can be implemented by setting the logical switch of the original shared resources and the newly added shared resources in each resource segment in the memory database. This can ensure effective access to shared resources and ensure data consistency.
[0059] The following is an explanation of the shared resource processing method of the application distributed lock in the embodiment of the present application in conjunction with specific application scenarios. Taking high concurrency, flash sales and other scenarios as examples, the products purchased by customers in flash sales are shared resources for the service provider. Usually, the service provider is deployed in a distributed manner. When calculating whether the product can be sold, each service will first access the inventory (the inventory is a shared resource). The inventory must be sufficient to sell it. If the data access is inconsistent, it may cause the product to be oversold, thereby causing business risks. In the prior art, the shared resource representing the inventory is stored in a field in the database. In the embodiment of the present application, the shared resource representing the inventory is broken up and segmented. For example, N fields can be used to store all these resources. At the same time, the distributed lock is also expanded to N, and each lock is responsible for the resources of one of the segments. The parallel processing capability of the system is increased by adjusting this architecture, and the overall processing performance of the distributed lock is improved.
[0060] First, divide the shared resources into segments, such as the above-mentioned inventory. According to business needs, evenly distribute this resource into multiple resource segments. Assume that the total amount of resources is M, which is divided into N resource segments. See Table 1, which is a design table of resource segments in an embodiment of the present application.
[0061] Table 1
[0062] Resource Name Segment 1 Segment 2 ...... Segment N AResource Inventory M / N M / N M / N M / N
[0063] The first row in Table 1 represents the design of how to store shared resources in a relational database. The resource name is the primary key of the table. Each column in the table has a corresponding column in the database. The purpose of segmentation is to keep the storage of resources as evenly as possible. Assuming the total amount is M and divided into N segments, the amount stored in each segment is M / N. When it cannot be divided evenly, it is OK for one segment to have a little more, as long as it is as evenly distributed as possible.
[0064] When accessing shared resources, each segment is locked independently, and the concurrent processing capability of the system is improved by adding segments. First, randomly access a segment and obtain the distributed lock corresponding to this segment. Access the resource segment corresponding to this lock. If the corresponding segment resource quantity is insufficient, randomly select another segment from the remaining segments and obtain the corresponding lock; and so on. If all segments are accessed and the distributed lock is still not obtained, it means that the shared resources have been insufficiently consumed. The flowchart of resource access and business processing through distributed locks is as follows. Figure 2 As shown. When a user requests to obtain the corresponding shared resources, a distributed lock will be randomly obtained from N ends. Suppose segment X is accessed, and its corresponding distributed lock is LockX. Get the resource amount of segment X in the database, and then determine whether the resource amount of segment X is sufficient. If so, the business logic processes the business successfully, modifies the resource amount of segment X, and releases the distributed lock of segment X. At this time, the state is Unlock X. If the resource amount of segment X is insufficient, release the distributed lock of segment X, and then determine whether there are any available segments. If not, the business logic fails to process the business. If so, randomly obtain a distributed lock from the remaining segments. Suppose segment Y is accessed, and its corresponding distributed lock is Lock Y. Then continue to determine whether the resource amount in segment Y is sufficient. The logic for determining whether the resource amount of segment X is sufficient is consistent with the above, and will not be described in detail here.
[0065] In the flash sale scenario, the row of data "A resource inventory" in the database resource storage table (the corresponding row in Table 1 above) is hot data. When the resource quantity is insufficient, the business may need to increase the resource inventory. For example, if the business sees a flash sale for a certain product and the inventory is insufficient, it decides to increase the inventory. For this scenario, if each segmented data of the "A resource inventory" row is modified directly, it may cause data consistency problems, because in high concurrency scenarios, modifying these hot data has certain business risks.
[0066] In order to shield the above risks, in the embodiment of the present application, a corresponding application logic switch can be configured, and a new row "A resource inventory 2" is added to the resource storage table, which is parallel to the row "A resource inventory" and has the same meaning as the row "A resource inventory". As described in Table 2 below:
[0067] Table 2
[0068] Resource Name Segment 1 Segment 2 ...... Segment N AResource Inventory M / N M / N M / N M / N A Resource Inventory 2 M2 / N M2 / N M2 / N M2 / N
[0069] When the logic switch is set to "0", the "A resource inventory" is accessed, and the total amount M of the A resource inventory is stored in segments, and there is an independent lock for access to each segmented resource.
[0070] When the business needs to increase the inventory of resource A, add it to another row: "A resource inventory 2". The total amount of resources M2 that need to be added is evenly distributed into N segments, and each segment corresponds to the amount of M2 / N. After completing this configuration in the database, set the logical switch to "1". Perform logical control in the application. When the logical switch is "0", access "A resource inventory"; when the logical switch is set to "1", access "A resource inventory 2". This avoids the business risk of adding resource inventory at the business level when the hot data of this row of resource inventory is snapped up, resulting in inconsistent data and difficult traceability.
[0071] In the embodiment of the present application, the shared resources are segmented, and an independent distributed lock is used for access to each resource segment, which horizontally expands the distributed lock as a whole to improve the concurrent processing capability of the system. In a high-concurrency scenario, when modifying the number of resources in the business (such as adding inventory), the row of data storing the resource is not directly modified, but a row with the same meaning is added to the database (representing the inventory of the same resource), and a logical switch is added to control the specific resource row that needs to be accessed, avoiding direct modification of hot data.
[0072] In the embodiment of the present application, a shared resource processing device using a distributed lock is also provided. Figure 3 , the device comprises:
[0073] The acquisition unit 301 is configured to acquire a target distributed lock corresponding to the shared resource acquisition request from at least one resource segment in response to receiving a shared resource acquisition request from a requesting end;
[0074] A releasing unit 302 is used to release the target distributed lock of the target resource segment when the resources in the target resource segment corresponding to the target distributed lock meet the shared resource acquisition request, so that the requesting end accesses the resources stored in the target resource segment based on the target distributed lock;
[0075] The shared resources are allocated to at least one resource segment, and each resource segment is configured with a corresponding distributed lock.
[0076] Optionally, it also includes:
[0077] A resource acquisition unit, used for obtaining the resource amount of shared resources;
[0078] A partitioning unit, configured to partition the shared resource into at least one resource segment based on the resource amount, and store each resource segment in a memory database;
[0079] A configuration unit is used to configure a corresponding distributed lock for each resource segment, so that resources of the resource segment can be accessed based on the distributed lock.
[0080] Optionally, it also includes:
[0081] The newly added resource processing unit is used to obtain newly added shared resources and divide the newly added shared resources into each of the resource segments when resources corresponding to the shared resources are stored in each of the resource segments.
[0082] Optionally, it also includes:
[0083] a determining unit, configured to determine a first resource segment in other resource segments except the target resource segment when resources in the target resource segment corresponding to the target distributed lock do not satisfy the shared resource acquisition request;
[0084] A resource acquisition unit is used to release the first distributed lock corresponding to the first resource segment, so that the request end obtains the resources stored in the first resource segment based on the first distributed lock.
[0085] Optionally, it also includes:
[0086] The adjustment unit is used to adjust the resources stored in the target resource segment when the request end accesses the resources stored in the target resource segment based on the target distributed lock and uses the resources stored in the target resource segment to perform business processing.
[0087] Based on the foregoing embodiment, the embodiment of the present application further provides an electronic device, including:
[0088] A memory, used to store applications and data generated by the operation of the applications;
[0089] A processor, configured to execute the application program to implement:
[0090] In response to receiving a shared resource acquisition request from a requesting end, acquiring a target distributed lock corresponding to the shared resource acquisition request from at least one resource segment;
[0091] When the resources in the target resource segment corresponding to the target distributed lock satisfy the shared resource acquisition request, releasing the target distributed lock of the target resource segment, so that the requesting end accesses the resources stored in the target resource segment based on the target distributed lock;
[0092] The shared resources are allocated to at least one resource segment, and each resource segment is configured with a corresponding distributed lock.
[0093] Optionally, it also includes:
[0094] In a case where resources in the target resource segment corresponding to the target distributed lock do not satisfy the shared resource acquisition request, determining a first resource segment in other resource segments except the target resource segment;
[0095] The first distributed lock corresponding to the first resource segment is released, so that the requesting end obtains the resources stored in the first resource segment based on the first distributed lock.
[0096] Optionally, it also includes:
[0097] When the requesting end accesses the resources stored in the target resource segment based on the target distributed lock and uses the resources stored in the target resource segment to perform business processing, the resources stored in the target resource segment are adjusted.
[0098] Optionally, it also includes:
[0099] The amount of resources to obtain shared resources;
[0100] Based on the resource amount, dividing the shared resource into at least one resource segment, and storing each resource segment in a memory database;
[0101] A corresponding distributed lock is configured for each resource segment, so that resources of the resource segment are accessed based on the distributed lock.
[0102] Optionally, it also includes:
[0103] In the case that resources corresponding to the shared resources are stored in each of the resource segments, newly added shared resources are obtained, and the newly added shared resources are divided into each of the resource segments.
[0104] Optionally, it also includes:
[0105] In response to a request end accessing a resource in the resource segment, controlling the request end to access an original shared resource in the resource segment based on a first access logic, wherein the original shared resource is a resource stored in the resource segment before the newly added shared resource;
[0106] Controlling the requesting end to access the newly added shared resource in the resource segment based on the second access logic;
[0107] The resource access modes in the resource segments corresponding to the first access logic and the second access logic are different.
[0108] The specific execution process of the relevant units and processing components in the shared resource processing device and electronic device applied to a distributed lock provided in the embodiment of the present application can be referred to the shared resource processing method applied to a distributed lock in the embodiment of the present application, which will not be described in detail here.
[0109] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0110] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0111] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for processing shared resources using distributed locks, characterized in that: include: In response to receiving a shared resource acquisition request from a requesting end, acquiring a target distributed lock corresponding to the shared resource acquisition request from at least one resource segment; When the resources in the target resource segment corresponding to the target distributed lock satisfy the shared resource acquisition request, releasing the target distributed lock of the target resource segment, so that the requesting end accesses the resources stored in the target resource segment based on the target distributed lock; The shared resources are allocated to at least one resource segment, and each resource segment is configured with a corresponding distributed lock.
2. The method according to claim 1, characterized in that Also includes: In a case where resources in the target resource segment corresponding to the target distributed lock do not satisfy the shared resource acquisition request, determining a first resource segment in other resource segments except the target resource segment; The first distributed lock corresponding to the first resource segment is released, so that the requesting end obtains the resources stored in the first resource segment based on the first distributed lock.
3. The method according to claim 1, characterized in that Also includes: When the requesting end accesses the resources stored in the target resource segment based on the target distributed lock and uses the resources stored in the target resource segment to perform business processing, the resources stored in the target resource segment are adjusted.
4. The method according to claim 1, characterized in that: Also includes: The amount of resources to obtain shared resources; Based on the resource amount, dividing the shared resource into at least one resource segment, and storing each resource segment in a memory database; A corresponding distributed lock is configured for each resource segment, so that resources of the resource segment are accessed based on the distributed lock.
5. The method according to claim 4, characterized in that Also includes: In the case that resources corresponding to the shared resources are stored in each of the resource segments, newly added shared resources are obtained, and the newly added shared resources are divided into each of the resource segments.
6. The method according to claim 5, characterized in that Also includes: In response to a request end accessing a resource in the resource segment, controlling the request end to access an original shared resource in the resource segment based on a first access logic, wherein the original shared resource is a resource stored in the resource segment before the newly added shared resource; Controlling the requesting end to access the newly added shared resource in the resource segment based on the second access logic; The resource access modes in the resource segments corresponding to the first access logic and the second access logic are different.
7. A shared resource processing device using a distributed lock, characterized in that: include: An acquisition unit, configured to, in response to receiving a shared resource acquisition request from a requesting end, acquire a target distributed lock corresponding to the shared resource acquisition request from at least one resource segment; A release unit, configured to release the target distributed lock of the target resource segment when the resources in the target resource segment corresponding to the target distributed lock meet the shared resource acquisition request, so that the requesting end can access the resources stored in the target resource segment based on the target distributed lock; The shared resources are allocated to at least one resource segment, and each resource segment is configured with a corresponding distributed lock.
8. The device according to claim 7, characterized in that Also includes: A resource acquisition unit, used for obtaining the resource amount of shared resources; A partitioning unit, configured to partition the shared resource into at least one resource segment based on the resource amount, and store each resource segment in a memory database; A configuration unit is used to configure a corresponding distributed lock for each resource segment, so that resources of the resource segment can be accessed based on the distributed lock.
9. The device according to claim 8, characterized in that Also includes: The newly added resource processing unit is used to obtain newly added shared resources and divide the newly added shared resources into each of the resource segments when resources corresponding to the shared resources are stored in each of the resource segments.
10. An electronic device, characterized in that: include: A memory, used to store applications and data generated by the operation of the applications; A processor is used to execute the application program to implement the shared resource processing method of the application distributed lock as described in any one of claims 1 to 6.