Shared resource access method and device, electronic equipment and storage medium

By building multi-level distributed lock middleware and using quality attributes at different levels to determine the hierarchy order, the distributed lock synchronization failure problem caused by single middleware failure is solved, and more efficient mutually exclusive access to shared resources is achieved.

CN120029789APending Publication Date: 2025-05-23INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510124401.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-26
Publication Date
2025-05-23

AI Technical Summary

Technical Problem

In a distributed system, after a single middleware media fails, the distributed lock synchronization fails, resulting in the inability to guarantee mutually exclusive access to shared resources.

Method used

Build a multi-level distributed lock middleware, determine the hierarchy order based on the quality attributes of different levels (such as security and timeliness), and lock shared resources through the target distributed lock middleware at the target level.

Benefits of technology

Even if a distributed lock middleware at a certain level fails, resource locking can still be achieved through other levels of distributed lock middleware, improving the effect of mutually exclusive access to shared resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120029789A_ABST
    Figure CN120029789A_ABST
Patent Text Reader

Abstract

The invention discloses a shared resource access method and device, electronic equipment and a storage medium, and relates to the field of distributed technologies. The method comprises the steps that multi-level distributed lock middleware is constructed, and different levels of distributed lock middleware are different in type; determining a target hierarchy and target distributed lock middleware under the target hierarchy according to the hierarchy use condition of each hierarchy and the current state of the distributed lock middleware of each hierarchy in response to an acquisition request of the distributed node for a resource lock corresponding to a target shared resource; and locking the target shared resource through the target distributed lock middleware under the target hierarchy, and feeding back a locking result to the distributed node, so that the distributed node determines whether to access the target shared resource or not according to the locking result. By the adoption of the method and device, even if a certain middleware medium fails, locking can still be achieved through distributed lock middleware of other hierarchies, so that the effect of mutual exclusion access of shared resources is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of distributed technology, and in particular to a shared resource access method, device, electronic device and storage medium. Background Art

[0002] In a distributed system, if one or a group of resources are shared between different nodes, then when accessing these resources, they often need to be configured as mutually exclusive to prevent interference with each other to ensure consistency. To achieve this function, distributed locks are required.

[0003] At present, the commonly used distributed lock service implementation is mainly based on a single middleware medium. This implementation method has certain shortcomings: when the single middleware medium fails, the distributed lock fails synchronously, resulting in the inability to guarantee mutually exclusive access to shared resources. Summary of the invention

[0004] The present invention provides a shared resource access method, device, electronic device, storage medium and computer program product.

[0005] According to one aspect of the present invention, a shared resource access method is provided, comprising:

[0006] Build multi-level distributed lock middleware, where the types of distributed lock middleware at different levels are different;

[0007] In response to a distributed node's acquisition request for a resource lock corresponding to a target shared resource, determine a target level and a target distributed lock middleware under the target level according to the level usage conditions of each level and the current state of the distributed lock middleware of each level;

[0008] The target shared resource is locked through the target distributed lock middleware under the target level, and the locking result is fed back to the distributed node, so that the distributed node determines whether to access the target shared resource according to the locking result.

[0009] Optionally, build a multi-level distributed lock middleware, including:

[0010] Determine the hierarchical order based on the quality attributes of different types of middleware media; the quality attributes include the security and timeliness of the middleware media;

[0011] Build multi-level distributed lock middleware according to the order of levels.

[0012] Optionally, in response to a distributed node's acquisition request for a resource lock corresponding to a target shared resource, determining a target level and a target distributed lock middleware under the target level according to the level usage conditions of each level and the current state of the distributed lock middleware of each level, including:

[0013] In response to the distributed node's request to obtain the resource lock corresponding to the target shared resource, enter each level in sequence according to the order of the levels;

[0014] Each time a level is entered, it is determined whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level and the current state of the distributed lock middleware of the level;

[0015] If so, the level is used as the target level, and the distributed lock middleware of the level is used as the target distributed lock middleware.

[0016] Optionally, each level includes multiple sub-levels, and the type of distributed lock middleware in each sub-level under the same level is the same, and each sub-level corresponds to a sub-level usage condition;

[0017] Each time a level is entered, it is determined whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level and the current state of the distributed lock middleware of the level, including:

[0018] Each time a level is entered, it is determined whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level;

[0019] If yes, determine the target sub-level for locking the target shared resource and the target distributed lock middleware under the target sub-level according to the sub-level usage conditions of each sub-level under the level;

[0020] According to the current state of the target distributed lock middleware, determine whether to use the target distributed lock middleware to lock the target shared resource.

[0021] Optionally, the multi-level distributed lock middleware constructed in hierarchical order is cache middleware, distributed coordination service middleware, and database middleware.

[0022] Optionally, the method further includes:

[0023] Collect the usage status data of the resource lock corresponding to each shared resource and record it in a preset data format;

[0024] Send recorded usage status data to the console, log file, or persistent database.

[0025] Optionally, the method further includes:

[0026] According to the usage status data of each resource lock, the configuration parameters of each resource lock are dynamically adjusted.

[0027] According to another aspect of the present invention, there is provided a shared resource access device, comprising:

[0028] A construction module is used to build multi-level distributed lock middleware, where the types of distributed lock middleware at different levels are different;

[0029] A determination module, for responding to a distributed node's acquisition request for a resource lock corresponding to a target shared resource, and determining a target level and a target distributed lock middleware under the target level according to the level usage conditions of each level and the current state of the distributed lock middleware of each level;

[0030] The locking module is used to lock the target shared resource through the target distributed lock middleware under the target level, and feed back the locking result to the distributed node, so that the distributed node determines whether to access the target shared resource according to the locking result.

[0031] Optionally, the building blocks are specifically used to:

[0032] Determine the hierarchical order based on the quality attributes of different types of middleware media; the quality attributes include the security and timeliness of the middleware media;

[0033] Build multi-level distributed lock middleware according to the order of levels.

[0034] Optionally, the determination module includes:

[0035] A response unit, used to respond to a request from a distributed node to obtain a resource lock corresponding to a target shared resource, and enter each level in sequence according to the order of the levels;

[0036] A judgment unit, for each time entering a level, determining whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level and the current state of the distributed lock middleware of the level;

[0037] The determining unit is used to, if yes, take the level as the target level, and take the distributed lock middleware of the level as the target distributed lock middleware.

[0038] Optionally, each level includes multiple sub-levels, and the type of distributed lock middleware in each sub-level under the same level is the same, and each sub-level corresponds to a sub-level usage condition;

[0039] The judgment unit is specifically used for:

[0040] Each time a level is entered, it is determined whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level;

[0041] If yes, determine the target sub-level for locking the target shared resource and the target distributed lock middleware under the target sub-level according to the sub-level usage conditions of each sub-level under the level;

[0042] According to the current state of the target distributed lock middleware, determine whether to use the target distributed lock middleware to lock the target shared resource.

[0043] Optionally, the multi-level distributed lock middleware constructed in hierarchical order is cache middleware, distributed coordination service middleware, and database middleware.

[0044] Optionally, the device further comprises:

[0045] The collection module is used to collect the usage status data of the resource lock corresponding to each shared resource and record it according to a preset data format;

[0046] The storage module is used to send the recorded usage status data to the console, log file or persistent database.

[0047] Optionally, the device further comprises:

[0048] The parameter dynamic adjustment module is used to dynamically adjust the configuration parameters of each resource lock according to the usage status data of each resource lock.

[0049] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0050] at least one processor; and

[0051] a memory communicatively connected to at least one processor; wherein,

[0052] The memory stores a computer program that can be executed by at least one processor. The computer program is executed by the at least one processor so that the at least one processor can execute the shared resource access method according to the embodiment of the present invention.

[0053] According to another aspect of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium stores computer instructions. The computer instructions are used to enable a processor to implement the shared resource access method according to an embodiment of the present invention when executed.

[0054] According to another aspect of the present invention, a computer program product is provided, comprising a computer program, and when the computer program is executed by a processor, the steps in the above method are implemented.

[0055] The technical solution of the embodiment of the present invention can still implement resource locking through distributed lock middleware at other levels even if the distributed lock middleware at a certain level fails, thereby improving the effect of mutually exclusive access to shared resources.

[0056] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0058] Figure 1 It is a flow chart of a shared resource access method provided by an embodiment of the present invention;

[0059] Figure 2 It is a flowchart of another shared resource access method provided by an embodiment of the present invention;

[0060] Figure 3 It is a flowchart of another shared resource access method provided by an embodiment of the present invention;

[0061] Figure 4 It is a structural diagram of a shared resource access device provided by an embodiment of the present invention;

[0062] Figure 5 It is a structural schematic diagram of an electronic device for implementing the shared resource access method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0063] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0064] Embodiment 1

[0065] Figure 1 A flowchart of a shared resource access method provided in an embodiment of the present invention. This embodiment is applicable to scenarios of mutually exclusive access to shared resources in a distributed system. The method can be executed by a shared resource access device, which can be implemented in the form of hardware and / or software, and can be configured in an electronic device.

[0066] like Figure 1 As shown, the shared resource access method includes:

[0067] S101. Construct a multi-level distributed lock middleware, wherein the types of distributed lock middleware at different levels are different.

[0068] In the embodiment of the present invention, the distributed lock middleware refers to the middleware medium for implementing the distributed lock.

[0069] In an optional implementation, constructing a multi-level distributed lock middleware includes: determining the hierarchical order according to the quality attributes of different types of middleware media; wherein the quality attributes include the security and timeliness of the middleware media; and then, constructing the multi-level distributed lock middleware according to the hierarchical order. Exemplarily, the multi-level distributed lock middleware constructed in the hierarchical order are cache middleware, distributed coordination service middleware, and database middleware. That is, in the constructed multi-level distributed lock middleware, the cache middleware is at the highest level, the distributed coordination service middleware is at the middle level, and the database middleware is at the lowest level.

[0070] It should be noted that when responding to a request to obtain a resource lock, the cache middleware at the highest level is used first, followed by the distributed coordination service middleware at the middle level, and finally the database middleware at the lowest level. It can be understood that by setting up multiple levels of distributed lock middleware, even if a certain level of distributed lock middleware is abnormal, the shared resources can be locked based on the distributed lock middleware at other levels, which can effectively avoid the problem of resource lock failure due to the failure of a single middleware.

[0071] S102, in response to a distributed node's acquisition request for a resource lock corresponding to a target shared resource, determine a target level and target distributed lock middleware under the target level according to level usage conditions of each level and a current state of distributed lock middleware of each level.

[0072] In an embodiment of the present invention, a distributed node refers to an independent computing unit that constitutes a distributed system, each node can perform tasks independently, and interact and collaborate with other nodes through a communication protocol. Distributed nodes are usually deployed on different physical or virtual servers, and communicate and exchange data with each other through a network connection. Each distributed node has its own processing power, storage resources and communication capabilities, which together constitute a distributed system. The target shared resource refers to a shared data that can be operated by different distributed nodes. The hierarchical usage conditions of different levels are used to limit the usage of distributed lock middleware at different levels. Exemplarily, the hierarchical usage conditions of the cache middleware are: the access delay requirements for shared resources are extremely high or the data update frequency of the target shared resource is high, and the data timeliness requirements are strict. It can be understood that the above-mentioned hierarchical usage conditions are only examples, and the hierarchical usage conditions of different levels can be configured in advance according to actual business needs.

[0073] In an embodiment of the present invention, if any distributed node wants to operate the target shared resource, it is first necessary to obtain the resource lock corresponding to the target shared resource to avoid multiple different distributed nodes operating the target shared resource at the same time. In response to any distributed node's acquisition request for the resource lock corresponding to the target shared resource, the target level and the target distributed lock middleware under the target level can be determined according to the level usage conditions of each level and the current state of the distributed lock middleware of each level. In the specific implementation, in response to the distributed node's acquisition request for the resource lock corresponding to the target shared resource, each level is entered in sequence according to the order of the levels; each time a level is entered, according to the level usage conditions of the level and the current state of the distributed lock middleware of the level, it is determined whether to use the distributed lock middleware of the level to lock the target shared resource; if so, the level is used as the target level, and the distributed lock middleware of the level is used as the target distributed lock middleware. Exemplarily, in response to a distributed node's request to obtain a resource lock corresponding to a target shared resource, the highest level is first entered, and based on the level usage conditions of the highest level, it is determined whether to use the cache middleware of the highest level to complete the locking of the target shared resource; if not, the middle level is entered; if so, a determination is made as to whether the current state of the cache middleware is in a normal working state; if it is in a normal working state, the highest level is used as the target level, and the cache middleware at the highest level is used as the target distributed lock middleware, that is, the locking of the target shared resource is subsequently completed through the cache middleware of the highest level; if it is in an abnormal working state (for example, caused by software failure, network problems, hardware damage, etc.), the middle level is entered. After entering the middle level, determine whether to use the distributed coordination service middleware of the middle level to complete the locking of the target shared resources based on the level usage conditions of the middle level; if not, enter the lowest level; if so, determine whether the current state of the distributed coordination middleware is in a normal working state. If it is in a normal working state, the middle level is used as the target level, and the distributed coordination service middleware under the middle level is used as the target distributed lock middleware, that is, the distributed coordination service middleware of the middle level is used to complete the locking of the target shared resources in the future; if it is in an abnormal working state (for example, caused by software failure, network problems, hardware damage, etc.), enter the lowest level.Similarly, after entering the lowest level, determine whether to use the lowest level database middleware to complete the locking of the target shared resources based on the level usage conditions of the lowest level; if not, it is determined that the locking has failed and the distributed nodes cannot access the target shared resources; if so, determine whether the current state of the database middleware is in a normal working state; if it is in a normal working state, take the lowest level as the target level, and take the database middleware at the lowest level as the target distributed lock middleware, that is, the target shared resources are subsequently locked through the database middleware at the lowest level; if it is in an abnormal working state (for example, caused by software failure, network problems, hardware damage, etc.), it is determined that the resource locking cannot be completed through the three levels of distributed lock middleware.

[0074] S103: Lock the target shared resource through the target distributed lock middleware under the target level, and feed back the locking result to the distributed node, so that the distributed node determines whether to access the target shared resource according to the locking result.

[0075] In an embodiment of the present invention, after determining the target level and the target distributed lock middleware under the target level through step S102, the target distributed lock middleware can be used to complete the locking of the target shared resource, and the locking result can be fed back to the distributed node, so that the distributed node determines whether to access the target shared resource based on the locking result. For example, if the locking is successful, the target shared resource is operated.

[0076] In an embodiment of the present invention, a pre-designed global recording module can be used to record the acquisition status of the resource lock of each shared resource at each level. For example, after the resource lock of the target shared resource is successfully acquired at the highest level (that is, after the lock is successfully added), the status of the resource lock of the target shared resource is exemplarily recorded as "acquired-highest level". Later, during the period when the resource lock is not released, even if the cache middleware at the highest level is abnormal, according to the record, other distributed nodes will not be able to acquire the resource lock of the target shared resource from other levels.

[0077] In an embodiment of the present invention, by designing a multi-level distributed lock middleware, even if the distributed lock middleware at a certain level fails, resource locking can still be achieved through the distributed lock middleware at other levels, thereby avoiding the problem of resource lock failure caused by an exception of a single distributed lock middleware and improving the effect of mutually exclusive access to shared resources.

[0078] Embodiment 2

[0079] Figure 2A flowchart of a shared resource access method provided by an embodiment of the present invention. In this embodiment, for multi-level distributed lock middleware, each level includes multiple sub-levels, and the types of distributed lock middleware in each sub-level under the same level are the same, and each sub-level corresponds to a sub-level usage condition. Figure 2 , the method comprises the following steps:

[0080] S201. Construct a multi-level distributed lock middleware, wherein the types of distributed lock middleware at different levels are different.

[0081] In an embodiment of the present invention, in response to a distributed node's request to obtain a resource lock corresponding to a target shared resource, the process of determining the target level and the target distributed lock middleware under the target level according to the level usage conditions of each level and the current state of the distributed lock middleware of each level can be seen in steps S202-S204.

[0082] S202 : In response to a request from a distributed node to obtain a resource lock corresponding to a target shared resource, enter each level in sequence according to the order of the levels.

[0083] Among them, the multi-level distributed lock middleware constructed in the order of hierarchy is cache middleware, distributed coordination service middleware, and database middleware. That is, in the constructed multi-level distributed lock middleware, the cache middleware is at the highest level, the distributed coordination service middleware is at the middle level, and the database middleware is at the lowest level. On the basis of the above, according to the order of hierarchy, entering each level in turn means entering the highest level first, then the middle level, and finally the lowest level.

[0084] S203 . Each time a level is entered, it is determined whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level and the current state of the distributed lock middleware of the level.

[0085] In an embodiment of the present invention, each level includes multiple sub-levels, and the types of distributed lock middleware in each sub-level under the same level are the same, and each sub-level corresponds to a sub-level usage condition. Exemplarily, taking the database middleware of the lowest level as an example, the lowest level includes a first sub-level and a second sub-level, the first sub-level includes a relational database middleware, and the second sub-level includes a non-relational database middleware. Similarly, for the multiple sub-levels of the highest level package, the cache middleware included in each sub-level is implemented based on different cache software.

[0086] In the case where each level includes multiple sub-levels, each time entering a level, determine whether to use the distributed lock middleware of this level to lock the target shared resources according to the level usage conditions of this level; if not, enter the next level; if so, determine the target sub-level for locking the target shared resources and the target distributed lock middleware under the target sub-level according to the sub-level usage conditions of each sub-level under this level in turn; determine whether to use the target distributed lock middleware under the target sub-level to lock the target shared resources according to the current state of the target distributed lock middleware.

[0087] S204: If yes, the level is used as the target level, and the distributed lock middleware of the level is used as the target distributed lock middleware.

[0088] In an embodiment of the present invention, for the case where each level includes multiple sub-levels, after entering a level, if it is determined that there is a target sub-level that meets the conditions for locking the target shared resource based on the sub-level usage conditions of each sub-level under the level, and the distributed lock middleware under the target sub-level is in a normal state, then the distributed lock middleware under the target sub-level is used as the target distributed lock middleware.

[0089] S205. Lock the target shared resource through the target distributed lock middleware under the target level, and feed back the locking result to the distributed node, so that the distributed node determines whether to access the target shared resource according to the locking result.

[0090] In the embodiment of the present invention, in the multi-level distributed lock middleware, each level can be subdivided into multiple sub-levels, so as to ensure the stability and reliability of the multi-level distributed lock middleware.

[0091] Embodiment 3

[0092] Figure 3 The present invention provides a flow chart of a method for accessing a shared resource. Figure 3 , the method comprises the following steps:

[0093] S301. Construct a multi-level distributed lock middleware, wherein the types of distributed lock middleware at different levels are different.

[0094] Optionally, constructing a multi-level distributed lock middleware includes: determining the hierarchical order according to the quality attributes of different types of middleware media; wherein the quality attributes include the security and timeliness of the middleware media; and constructing a multi-level distributed lock middleware according to the hierarchical order. The multi-level distributed lock middleware constructed in accordance with the hierarchical order is, in turn, cache middleware, distributed coordination service middleware, and database middleware.

[0095] S302: In response to a distributed node's acquisition request for a resource lock corresponding to a target shared resource, determine a target level and target distributed lock middleware under the target level according to level usage conditions of each level and a current state of distributed lock middleware of each level.

[0096] Optionally, in response to a distributed node's request to acquire a resource lock corresponding to a target shared resource, enter each level in sequence in the order of the levels; each time a level is entered, determine whether to use the distributed lock middleware of that level to lock the target shared resource based on the level usage conditions of that level and the current state of the distributed lock middleware of that level; if so, use that level as the target level, and use the distributed lock middleware of that level as the target distributed lock middleware.

[0097] S303: Lock the target shared resource through the target distributed lock middleware under the target level, and feed back the locking result to the distributed node, so that the distributed node determines whether to access the target shared resource according to the locking result.

[0098] After completing the access to the shared resource through steps S301-S303, in the embodiment of the present invention, the usage of the resource lock of each shared resource can be counted, and the configuration parameters of the resource lock can be dynamically optimized. For details, please refer to steps S304-S305.

[0099] S304: Collect usage status data of the resource lock corresponding to each shared resource, and record it according to a preset data format; send the recorded usage status data to a console, a log file or a persistent database.

[0100] In an embodiment of the present invention, the usage status data of the resource lock may include data such as the actual holding time, expiration time, and number of conflicts of the resource lock. For the collected usage status data of the resource lock, the data format can be customized according to actual business needs, and then the usage status data of each resource lock can be recorded according to the customized data format. Furthermore, the recorded usage status data can be sent to a console, a log file, or a persistent database, so that the data can be subsequently extracted from the console, the log file, or the persistent database for analysis. Exemplarily, the usage status data of each resource lock recorded in the log file is analyzed, and it is found that each time the resource lock is acquired, it is at the middle level, rather than at the highest level. Then, it is determined that the distributed lock middleware at the highest level is abnormal, and the management personnel can be prompted to perform abnormal detection by means of abnormal notification.

[0101] S305: Dynamically adjust the configuration parameters of each resource lock according to the usage status data of each resource lock.

[0102] In the embodiment of the present invention, the configuration parameters of the macro resource lock can be optionally pre-configured parameters for controlling the resource lock. Exemplarily, the configuration parameters may include key parameters such as holding time and release time. According to the usage status data of each resource lock, the configuration parameters of each resource lock are dynamically adjusted, including: determining the mean value of the holding time of each resource lock within a period of time according to the usage status data of the resource lock; adjusting the holding time in the configuration parameters by comparing the mean value with the holding time in the resource lock configuration parameters. For example, the holding time in the configuration parameters is 1000 seconds, and the mean value of the actual holding time of the resource lock determined according to the usage status data of the resource lock is 800 seconds. At this time, the holding time in the configuration parameters of the resource lock can be reduced, for example, adjusted to the mean value. In addition, the configuration parameters of the resource lock can be dynamically adjusted according to the changes in the business volume so that the configuration parameters of the resource lock can meet the business needs.

[0103] The embodiment of the present invention can realize the collection of the actual usage of the resource lock and the dynamic optimization of the configuration parameters of the resource lock.

[0104] Embodiment 4

[0105] Figure 4 The structure diagram of a shared resource access device provided by an embodiment of the present invention is shown in FIG. This embodiment is applicable to scenarios where shared resources in a distributed system are accessed mutually exclusively. The device can execute any of the shared resource access methods of the present invention. Figure 4 As shown, the shared resource access device includes:

[0106] A construction module 401 is used to construct a multi-level distributed lock middleware, wherein the types of distributed lock middleware at different levels are different;

[0107] A determination module 402 is used to determine the target level and the target distributed lock middleware under the target level according to the level usage conditions of each level and the current state of the distributed lock middleware of each level in response to the acquisition request of the distributed node for the resource lock corresponding to the target shared resource;

[0108] The locking module 403 is used to lock the target shared resource through the target distributed lock middleware under the target level, and feed back the locking result to the distributed node, so that the distributed node determines whether to access the target shared resource according to the locking result.

[0109] Optionally, the construction module 401 is specifically used for:

[0110] Determine the hierarchical order based on the quality attributes of different types of middleware media; the quality attributes include the security and timeliness of the middleware media;

[0111] Build multi-level distributed lock middleware according to the order of levels.

[0112] Optionally, the determining module 402 includes:

[0113] A response unit, used to respond to a request from a distributed node to obtain a resource lock corresponding to a target shared resource, and enter each level in sequence according to the order of the levels;

[0114] A judgment unit, for each time entering a level, determining whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level and the current state of the distributed lock middleware of the level;

[0115] The determining unit is used to, if yes, take the level as the target level, and take the distributed lock middleware of the level as the target distributed lock middleware.

[0116] Optionally, each level includes multiple sub-levels, and the type of distributed lock middleware in each sub-level under the same level is the same, and each sub-level corresponds to a sub-level usage condition;

[0117] The judgment unit is specifically used for:

[0118] Each time a level is entered, it is determined whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level;

[0119] If yes, then determine the target sub-level for locking the target shared resource and the target distributed lock middleware under the target sub-level according to the sub-level usage conditions of each sub-level under the level;

[0120] According to the current state of the target distributed lock middleware, determine whether to use the target distributed lock middleware to lock the target shared resource.

[0121] Optionally, the multi-level distributed lock middleware constructed in hierarchical order is cache middleware, distributed coordination service middleware, and database middleware.

[0122] Optionally, the device further comprises:

[0123] The collection module is used to collect the usage status data of the resource lock corresponding to each shared resource and record it according to a preset data format;

[0124] The storage module is used to send the recorded usage status data to the console, log file or persistent database.

[0125] Optionally, the device further comprises:

[0126] The parameter dynamic adjustment module is used to dynamically adjust the configuration parameters of each resource lock according to the usage status data of each resource lock.

[0127] The shared resource access device provided in the embodiment of the present invention can execute the shared resource access method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0128] According to an embodiment of the present invention, the present invention also provides an electronic device, a readable storage medium and a computer program product.

[0129] Embodiment 5

[0130] Figure 5 The components, their connections and relationships, and their functions shown herein are merely examples and are not intended to limit implementation of the invention described and / or claimed herein.

[0131] like Figure 5 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0132] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0133] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as executing a shared resource access method.

[0134] In some embodiments, the shared resource access method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the shared resource access method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the shared resource access method in any other appropriate manner (e.g., by means of firmware).

[0135] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0136] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable shared resource access device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0137] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0138] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0139] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0140] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0141] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0142] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for accessing a shared resource, characterized in that: include: Build multi-level distributed lock middleware, where the types of distributed lock middleware at different levels are different; In response to a distributed node's acquisition request for a resource lock corresponding to a target shared resource, determine a target level and a target distributed lock middleware under the target level according to the level usage conditions of each level and the current state of the distributed lock middleware of each level; The target shared resource is locked by the target distributed lock middleware under the target level, and the locking result is fed back to the distributed node, so that the distributed node determines whether to access the target shared resource according to the locking result.

2. The method according to claim 1, characterized in that The multi-level distributed lock middleware is constructed, including: Determine the hierarchical order according to the quality attributes of different types of middleware media; wherein the quality attributes include the security and timeliness of the middleware media; According to the order of the levels, a multi-level distributed lock middleware is constructed.

3. The method according to claim 2, characterized in that The method responds to the distributed node's acquisition request for the resource lock corresponding to the target shared resource, and determines the target level and the target distributed lock middleware under the target level according to the level usage conditions of each level and the current state of the distributed lock middleware of each level, including: In response to the distributed node's request to obtain the resource lock corresponding to the target shared resource, enter each level in sequence according to the order of the levels; Each time a level is entered, it is determined whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level and the current state of the distributed lock middleware of the level; If so, the level is used as the target level, and the distributed lock middleware of the level is used as the target distributed lock middleware.

4. The method according to claim 3, characterized in that Each level includes multiple sub-levels, and the types of distributed lock middleware in each sub-level under the same level are the same, and each sub-level corresponds to a sub-level usage condition; Each time a level is entered, determining whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level and the current state of the distributed lock middleware of the level, includes: Each time a level is entered, it is determined whether to use the distributed lock middleware of the level to lock the target shared resource according to the level usage conditions of the level; If yes, then determine the target sub-level for locking the target shared resource and the target distributed lock middleware under the target sub-level according to the sub-level usage conditions of each sub-level under the level; According to the current state of the target distributed lock middleware, it is determined whether to use the target distributed lock middleware to lock the target shared resource.

5. The method according to claim 1, characterized in that The multi-level distributed lock middleware constructed in hierarchical order is cache middleware, distributed coordination service middleware, and database middleware.

6. The method according to claim 1, characterized in that The method further comprises: Collect the usage status data of the resource lock corresponding to each shared resource and record it in a preset data format; The recorded usage status data is sent to a console, a log file or a persistent database.

7. The method according to claim 6, characterized in that The method further comprises: According to the usage status data of each resource lock, the configuration parameters of each resource lock are dynamically adjusted.

8. A shared resource access device, characterized in that: include: A construction module is used to build multi-level distributed lock middleware, where the types of distributed lock middleware at different levels are different; A determination module, configured to respond to a distributed node's acquisition request for a resource lock corresponding to a target shared resource, determine a target level and a target distributed lock middleware under the target level according to the level usage conditions of each level and the current state of the distributed lock middleware of each level; The locking module is used to lock the target shared resource through the target distributed lock middleware under the target level, and feed back the locking result to the distributed node, so that the distributed node determines whether to access the target shared resource according to the locking result.

9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method according to any one of claims 1 to 7 when executed.

11. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 7.