CN111163140A - Method, apparatus and computer readable storage medium for resource acquisition and allocation - Google Patents
Method, apparatus and computer readable storage medium for resource acquisition and allocation Download PDFInfo
- Publication number
- CN111163140A CN111163140A CN201911324766.4A CN201911324766A CN111163140A CN 111163140 A CN111163140 A CN 111163140A CN 201911324766 A CN201911324766 A CN 201911324766A CN 111163140 A CN111163140 A CN 111163140A
- Authority
- CN
- China
- Prior art keywords
- resource
- distributed lock
- application
- service
- distributed
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 53
- 238000012544 monitoring process Methods 0.000 claims abstract description 21
- 238000013468 resource allocation Methods 0.000 claims abstract description 18
- 238000004590 computer program Methods 0.000 claims description 16
- 238000004891 communication Methods 0.000 claims description 14
- 238000010586 diagram Methods 0.000 description 10
- 238000003491 array Methods 0.000 description 2
- 239000000872 buffer Substances 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000007717 exclusion Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
- G06F16/2308—Concurrency control
- G06F16/2336—Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
- G06F16/2343—Locking methods, e.g. distributed locking or locking implementation details
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/38—Concurrent instruction execution, e.g. pipeline or look ahead
- G06F9/3867—Concurrent instruction execution, e.g. pipeline or look ahead using instruction pipelines
- G06F9/3869—Implementation aspects, e.g. pipeline latches; pipeline synchronisation and clocking
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5022—Mechanisms to release resources
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L63/00—Network architectures or network communication protocols for network security
- H04L63/10—Network architectures or network communication protocols for network security for controlling access to devices or network resources
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/60—Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Physics & Mathematics (AREA)
- Physics & Mathematics (AREA)
- Signal Processing (AREA)
- Computer Networks & Wireless Communication (AREA)
- Computing Systems (AREA)
- Computer Security & Cryptography (AREA)
- Computer Hardware Design (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The embodiment of the invention discloses a resource acquisition method, which is applied to a distributed system and comprises the following steps: generating a resource application according to a service to be executed, and sending the resource application to the distributed lock; judging whether the distributed lock is acquired, and monitoring the distributed lock if the distributed lock is not acquired; and when the distributed lock is monitored to be released by the application node acquiring the distributed lock, sending a resource application to the distributed lock again. The invention also provides a resource allocation method, a resource acquisition and allocation device and a computer readable storage medium. The invention can realize the ordered access to the critical resource and prevent the consequence of dirty data.
Description
Technical Field
The present invention relates to the field of distributed system technologies, and in particular, to a method and an apparatus for resource acquisition and allocation, and a computer-readable storage medium.
Background
With the development of internet technology, a centralized system cannot meet a service scene with high concurrency of complex services, and then evolves to a distributed system to solve the problem of system expansibility, maintainability and performance bottleneck of the centralized system. However, distributed systems also entail certain complexity problems. In a distributed system, since there is a case where one application is issued by multiple nodes, when multiple requests perform concurrent operations on stateful data, i.e., critical resources, there may be an error case where the operation result does not conform to the expected result, i.e., there is dirty data.
Disclosure of Invention
In view of the above, it is necessary to provide a resource acquisition and allocation method, apparatus and computer readable storage medium for solving the above problems.
A resource acquisition method is applied to a distributed system and comprises the following steps: generating a resource application according to a service to be executed, and sending the resource application to a distributed lock; judging whether the distributed lock is acquired, and monitoring the distributed lock if the distributed lock is not acquired; and when monitoring that the distributed lock is released by the application node acquiring the distributed lock, sending the resource application to the distributed lock again.
After the step of determining whether the distributed lock is acquired, the method includes: if the distributed lock is acquired, accessing critical resources by using the distributed lock to execute the service; and releasing the distributed lock after the service is executed.
The step of generating a resource application according to the service to be executed includes: judging whether the service to be executed needs to access critical resources, and if so, generating the resource application; the step of sending the resource application to the distributed lock includes: and sending the resource application to the distributed lock corresponding to the critical resource.
Wherein the step of sending the resource application to the distributed lock again comprises: if the distributed lock is not acquired, monitoring the distributed lock repeatedly, and sending the resource application to the distributed lock when the distributed lock is released until the distributed lock is acquired.
A resource allocation method is applied to a distributed system and comprises the following steps: acquiring resource applications sent by at least two application nodes, wherein the resource applications are generated by the at least two application nodes according to a service to be executed; and distributing the distributed lock to one of the application nodes according to a preset selection mechanism, so that the application nodes access the critical resource based on the distributed lock to complete the service.
A resource acquisition apparatus, comprising: the application module is used for generating a resource application according to the service to be executed and sending the resource application to the distributed lock; the judging module is used for judging whether to acquire the distributed lock or not, and monitoring the distributed lock if the distributed lock is not acquired; and the monitoring module is used for sending the resource application to the distributed lock again when monitoring that the distributed lock is released by the application node which acquires the distributed lock.
A resource allocation apparatus, comprising: an obtaining module, configured to obtain resource applications sent by at least two application nodes, where the resource applications are generated by the at least two application nodes according to a service to be executed; and the distribution module is used for distributing the distributed lock to one of the application nodes according to a preset selection mechanism, so that the application nodes access the critical resource to complete the service based on the distributed lock.
A resource acquisition apparatus, comprising: a processor, a memory and a communication circuit, the processor being coupled to the memory and the communication circuit, the memory having stored therein a computer program, the processor executing the computer program to implement the method as described above.
A resource allocation apparatus, comprising: a processor, a memory and a communication circuit, the processor being coupled to the memory and the communication circuit, the memory having stored therein a computer program, the processor executing the computer program to implement the method as described above.
A computer-readable storage medium storing a computer program executable by a processor to implement a method as described above.
The embodiment of the invention has the following beneficial effects:
the method comprises the steps of generating a resource application according to a service to be executed, sending the resource application to a distributed lock, enabling the distributed lock to judge whether the distributed lock is distributed or not based on the resource application, monitoring the distributed lock when the distributed lock is not acquired, and continuously sending the resource application when the distributed lock is released, so that ordered access to critical resources can be achieved, and the consequence of dirty data is prevented.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Wherein:
fig. 1 is a schematic flow chart of a resource acquisition method according to a first embodiment of the present invention;
FIG. 2 is a flowchart illustrating a resource obtaining method according to a second embodiment of the present invention;
FIG. 3 is a flowchart illustrating a resource obtaining method according to a third embodiment of the present invention;
FIG. 4 is a flowchart illustrating a resource allocation method according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a resource acquisition apparatus according to a first embodiment of the present invention;
fig. 6 is a schematic structural diagram of a resource allocation apparatus according to a first embodiment of the present invention;
fig. 7 is a schematic structural diagram of a resource acquisition apparatus according to a second embodiment of the present invention;
fig. 8 is a schematic structural diagram of a resource allocation apparatus according to a second embodiment of the present invention;
FIG. 9 is a schematic structural diagram of an embodiment of a computer-readable storage medium provided in the present application.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In a distributed system, since there is a case where one application is issued by multiple nodes, when multiple requests perform concurrent operations on stateful data, i.e., critical resources, there may be an error case where the operation result does not conform to the expected result, i.e., there is dirty data.
In this embodiment, in order to solve the above problem, a resource obtaining method is provided, which can implement ordered access of multiple application nodes to a critical resource, and prevent the consequences of dirty data.
Referring to fig. 1, fig. 1 is a schematic flowchart illustrating a resource obtaining method according to a first embodiment of the present invention. The resource acquisition method provided by the invention comprises the following steps:
s101: and generating a resource application according to the service to be executed, and sending the resource application to the distributed lock.
In a specific implementation scenario, in a distributed system, several different application nodes are interconnected with each other through a communication network, and a user on one application node can use resources on other application nodes, for example, the distributed system allows device sharing; allowing data sharing to enable a plurality of users to access a common database; remote files may be shared, remote specific hardware devices (e.g., high speed array processors) used, and other operations performed.
A critical resource is a shared resource that is only allowed to be used by one process at a time. The processes adopt a mutual exclusion mode, and the resource for realizing sharing is called critical resource. Hardware belonging to critical resources includes printers, tape machines, and the like; the software has message queues, variables, arrays, buffers, etc. And mutually exclusive modes are adopted among the processes to realize the sharing of the resource.
When an application node needs to access a critical resource, in order to avoid an error condition that an operation result does not accord with an expected result when a plurality of application nodes simultaneously perform concurrent operation on the critical resource, the application node generates a resource application according to a service to be executed before the application node needs to access the critical resource, and sends the resource application to a distributed lock. In this implementation scenario, the resource application includes at least one item of content, such as a service content to be executed, a priority, and an identifier of the application node, so that after receiving the resource application, the distributed lock may determine whether to allocate the distributed lock according to a preset selection mechanism based on the resource application.
S102: and judging whether the distributed lock is acquired, and monitoring the distributed lock if the distributed lock is not acquired.
In the implementation scenario, whether the distributed lock is acquired is judged, if the distributed lock is not acquired, it indicates that a plurality of application nodes currently need to access the critical resource, and the distributed lock allocates the distributed lock to other application nodes based on a preset selection mechanism, so that other application nodes can access the critical resource, and the node cannot access the critical resource.
At this time, the application node monitors the distributed lock, and obtains the current state of the distributed lock to determine whether the distributed lock is released by the application node that obtained the distributed lock.
S103: and when the distributed lock is monitored to be released by the application node acquiring the distributed lock, sending a resource application to the distributed lock again.
In this implementation scenario, when it is monitored that the distributed lock is released by an application node that previously acquired the distributed lock, the resource application is sent to the distributed lock again, and the resource application is generated according to a service to be executed, and the number of times that the application node sends the resource application may also be included to provide reference for the distributed lock, so that after receiving the resource application, the distributed lock determines whether to allocate the distributed lock to the application node according to a preset selection mechanism, so that the application node may access a critical resource based on the distributed lock to complete the service to be executed.
As can be seen from the above description, in this embodiment, an application node generates a resource application according to a service to be executed, and sends the resource application to a distributed lock, so that the distributed lock can determine whether to allocate the distributed lock to the application node based on a preset selection mechanism according to the resource application, so that the application node can access a critical resource according to the distributed lock to complete the service to be executed, if the application node does not acquire the distributed lock, the distributed lock is monitored, and when it is monitored that the distributed lock is released, the resource application occurs again, thereby implementing ordered access of multiple application nodes to the critical resource, and avoiding a situation that dirty data occurs in concurrent operations.
Referring to fig. 2, fig. 2 is a flowchart illustrating a resource obtaining method according to a second embodiment of the present invention. The resource acquisition method provided by the invention comprises the following steps:
s201: and generating a resource application according to the service to be executed, and sending the resource application to the distributed lock.
In a specific implementation scenario, this step is substantially the same as step S101 in the first embodiment of the resource obtaining method provided by the present invention, and details are not repeated here.
S202: and judging whether to acquire the distributed lock.
In this implementation scenario, only one application node that sends a resource application may successfully acquire the distributed lock, and a common method is to regard one znode on zk as a distributed lock and implement the znode in a mode of creating the znode. All clients create the znode, and finally, the successfully created application node acquires the distributed lock. Therefore, in this implementation scenario, it is determined whether the application node acquires the distributed lock by determining whether the application node successfully creates the znode.
S203: and if the distributed lock is acquired, accessing the critical resource by using the distributed lock to execute the service.
In this implementation scenario, if the distributed lock is acquired, the distributed lock is used to access the critical resource, and the critical resource is used to execute the service.
S204: and releasing the distributed lock after the execution of the service is finished.
In this implementation scenario, after the application node completes the execution of the service using the critical resource, the distributed lock is released, and at this time, the released distributed lock is in an acquirable state again. Other application nodes can apply for acquiring the distributed lock in a mode of sending a resource application.
S205: and if the distributed lock is not acquired, monitoring the distributed lock.
S206: and when the distributed lock is monitored to be released by the application node acquiring the distributed lock, sending a resource application to the distributed lock again.
In a specific implementation scenario, steps S205 to S206 are substantially the same as steps S102 to S103 in the first embodiment of the resource obtaining method provided by the present invention, and are not described herein again.
As can be seen from the above description, in this embodiment, an application node sends a resource application to a distributed lock, so that the distributed lock determines whether to allocate the distributed lock to the application node according to the resource application based on a preset selection mechanism, if the application node acquires the distributed lock, the distributed lock is used to access a critical resource, thereby executing a service, and after the service execution is completed, the distributed lock is released, so that other application nodes can acquire the distributed lock by sending the resource application, thereby also accessing the critical resource, and executing a task. The method and the device realize the ordered access to the critical resources and avoid the condition of dirty data in concurrent operation.
Referring to fig. 3, fig. 3 is a schematic flowchart of a resource obtaining method according to a third embodiment of the present invention, where the resource obtaining method includes:
s301: and judging whether the service to be executed needs to access the critical resource, and if so, generating a resource application.
In a specific implementation scenario, an application node determines whether a service to be executed needs to access a critical resource, if the service needs not to access the critical resource, the application node directly accesses the required resource, and if the service needs to access the critical resource, since the critical resource can only be accessed by one application node in the same time period, the application node generates a resource application according to the service to be executed, so as to apply for a distributed lock to obtain the distributed lock, thereby accessing the critical resource.
S302: and sending the resource application to the distributed lock corresponding to the critical resource.
In this implementation scenario, after a resource application is generated, the resource application is sent to the distributed lock corresponding to the critical resource that needs to be accessed. A plurality of critical resources may exist in a distributed system, and each critical resource has a corresponding distributed lock, so before the critical resource needs to be accessed, a resource application needs to be sent to the distributed lock corresponding to the critical resource, so that the distributed lock determines whether to allocate the distributed lock to the application node based on a preset selection mechanism.
S303: and judging whether to acquire the distributed lock.
In this implementation scenario, step S303 is substantially the same as step S202 in the second embodiment of the resource obtaining method provided by the present invention, and details are not repeated here.
S304: and if the distributed lock is not acquired, monitoring the distributed lock repeatedly, and sending a resource application to the distributed lock when the distributed lock is released until the distributed lock is acquired.
In this implementation scenario, if the application node fails to acquire the distributed lock, the distributed lock is monitored, and after the distributed lock is monitored to be released by the application node that acquires the distributed lock, a resource application is sent to the distributed lock again. Therefore, the ordered access to the critical resource can be maintained all the time, and the condition that the concurrent operation has dirty data can be effectively avoided.
As can be seen from the above description, in this embodiment, when a service to be executed needs to access a critical resource, a resource application is sent to a distributed lock corresponding to the critical resource, so that the distributed lock can determine whether to allocate the distributed lock to the application node based on a preset selection mechanism, if the application node fails to acquire the distributed lock, the step of monitoring the distributed lock is repeated all the time, and when it is monitored that the distributed lock is released, the step of sending the resource application is sent until the distributed lock is acquired. Therefore, the ordered access to the critical resource can be maintained all the time, and the condition that the concurrent operation has dirty data can be effectively avoided.
Referring to fig. 4, fig. 4 is a flowchart illustrating a resource allocation method according to an embodiment of the present invention. The resource allocation method provided by the invention comprises the following steps:
s401: the method comprises the steps of obtaining resource applications sent by at least two application nodes, wherein the resource applications are generated by the at least two application nodes according to services to be executed.
In a specific implementation scenario, in a distributed system, several different application nodes are interconnected with each other through a communication network, and a user on one application node can use resources on other application nodes, for example, the distributed system allows device sharing; allowing data sharing to enable a plurality of users to access a common database; remote files may be shared, remote specific hardware devices (e.g., high speed array processors) used, and other operations performed.
A critical resource is a shared resource that is only allowed to be used by one process at a time. The processes adopt a mutual exclusion mode, and the resource for realizing sharing is called critical resource. Hardware belonging to critical resources includes printers, tape machines, and the like; the software has message queues, variables, arrays, buffers, etc. And mutually exclusive modes are adopted among the processes to realize the sharing of the resource.
In a distributed system, there may be multiple critical resources, each having a corresponding distributed lock, and when multiple application nodes need to access the critical resource at the same time, the distributed lock is used to select one of the application nodes that can access the critical resource, and the other application nodes that cannot access the critical resource at the same time.
In this implementation scenario, at least two application nodes need to access the same critical resource, and the at least two application nodes generate resource applications according to respective to-be-executed services, and send the resource applications to the distributed locks corresponding to the critical resource. The distributed lock receives resource applications sent by the at least two application nodes.
S402: and distributing the distributed lock to one of the application nodes according to a preset selection mechanism, so that the application nodes access the critical resource based on the distributed lock to complete the service.
In a specific application scenario, according to a preset selection mechanism, one application node is selected from at least two application nodes sending a resource application, and a distributed lock is allocated to the application node, so that the application node can acquire the critical resource based on the distributed lock, thereby completing the service to be executed.
Specifically, the distributed lock may select one application node based on the sequence of the received resource applications, for example, select an application node corresponding to the resource application received first. The distributed lock may also select an application node based on the timeliness of the service to be executed, e.g., selecting the service to be executed as a real-time service. The distributed lock may also select an application node based on the number of times the application node sends the resource application, e.g., the application node that sends the resource application the most number of times. The distributed lock may also randomly select an application node.
In other implementation scenarios, only one application node may need to access the critical resource, the distributed lock may be assigned to the application node directly, or based on a selection mechanism.
In this implementation scenario, after the application node executes a task, the distributed lock is released, the distributed lock continues to receive resource applications sent by at least two application nodes, and the distributed lock is allocated to one of the application nodes according to a preset selection mechanism, so that the application node accesses a critical resource based on the distributed lock to complete a service.
As can be seen from the above description, in this embodiment, at least two application nodes need to access a critical resource, one application node is selected according to a resource application sent by the at least two application nodes, and a distributed lock is allocated to the application node, so that the application node can access the critical resource by using the distributed lock to complete a service, and thus, a plurality of application nodes can access the critical resource in order, and a condition that dirty data occurs in concurrent operations can be effectively avoided.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a resource obtaining apparatus according to a first embodiment of the present invention. The resource acquiring device 10 includes an application module 11, a judgment module 12 and a monitoring module 13. In this implementation scenario, the resource acquiring apparatus 10 may be an application node in a distributed system. The application module 11 is configured to generate a resource application according to a service to be executed, and send the resource application to the distributed lock. The judging module 12 is configured to judge whether to acquire the distributed lock, and monitor the distributed lock if the distributed lock is not acquired. The monitoring module 13 is configured to send a resource application to the distributed lock again when it is monitored that the distributed lock is released by the application node that acquires the distributed lock.
The resource acquiring apparatus further includes an executing module 14, where the executing module 14 is configured to, when the distributed lock is acquired, access the critical resource to execute the service by using the distributed lock. The resource acquiring apparatus further includes a releasing module 15, where the releasing module 15 is configured to release the distributed lock after the service is executed.
The application module 11 is further configured to determine whether a service to be executed needs to access a critical resource, generate a resource application if the service needs to access the critical resource, and send the resource application to a distributed lock corresponding to the critical resource.
The monitoring module 13 is further configured to, if the distributed lock is not acquired, repeatedly monitor the distributed lock, and send a resource application to the distributed lock when the distributed lock is released until the distributed lock is acquired.
As can be seen from the above description, the resource obtaining apparatus in this embodiment can generate a resource application according to a service to be executed, and send the resource application to the distributed lock, so that the distributed lock can determine whether to allocate the distributed lock to the application node based on a preset selection mechanism according to the resource application, so that the application node can access the critical resource according to the distributed lock to complete the service to be executed, if the application node does not obtain the distributed lock, the distributed lock is monitored, and when it is monitored that the distributed lock is released, the resource application occurs again, thereby implementing ordered access of multiple application nodes to the critical resource, and avoiding a situation that dirty data occurs in concurrent operations.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a resource allocation apparatus according to a first embodiment of the present invention. In this implementation scenario, the resource allocation apparatus 20 may be a distributed lock in a distributed system. The resource allocation apparatus 20 includes an acquisition module 21 and an allocation module 22. The obtaining module 21 is configured to obtain resource applications sent by at least two application nodes, where the resource applications are generated by the at least two application nodes according to a service to be executed. The allocating module 22 is configured to allocate the distributed lock to one of the application nodes according to a preset selection mechanism, so that the application node completes a service based on the distributed lock accessing the critical resource.
As can be seen from the above description, in the resource allocation apparatus in this embodiment, when at least two application nodes need to access a critical resource, one application node is selected according to a resource application sent by the at least two application nodes, and a distributed lock is allocated to the application node, so that the application node can access the critical resource by using the distributed lock to complete a service, and thus, a plurality of application nodes can access the critical resource in order, and a condition that dirty data occurs in concurrent operations can be effectively avoided.
Referring to fig. 7, fig. 7 is a schematic structural diagram of a resource obtaining apparatus according to a second embodiment of the present invention. The resource acquisition device 30 comprises a processor 31, a memory 32 and a communication circuit 33. The processor 31 is coupled to the communication circuit 33 and the memory 32. The memory 32 has stored therein a computer program which is executed by the processor 31 when it is operated to carry out the method as shown in fig. 1-3. The detailed methods can be referred to above and are not described herein.
As can be seen from the above description, in this embodiment, the resource obtaining apparatus can generate a resource application according to a service to be executed, and send the resource application to the distributed lock, so that the distributed lock can determine whether to allocate the distributed lock to the application node based on a preset selection mechanism according to the resource application, so that the application node can access the critical resource according to the distributed lock to complete the service to be executed, if the application node does not obtain the distributed lock, the distributed lock is monitored, and when it is monitored that the distributed lock is released, the resource application occurs again, thereby implementing ordered access to the critical resource by multiple application nodes, and avoiding a situation that dirty data occurs in concurrent operations.
Referring to fig. 8, fig. 8 is a schematic structural diagram of a resource allocation apparatus according to a second embodiment of the present invention. The resource acquisition device 40 comprises a processor 41, a memory 42 and a communication circuit 43. Processor 41 is coupled to communication circuitry 43 and memory 42. The memory 42 has stored therein a computer program which is executed by the processor 41 when in operation to implement the method as shown in fig. 4. The detailed methods can be referred to above and are not described herein.
As can be seen from the above description, in the resource allocation apparatus in this embodiment, when at least two application nodes need to access a critical resource, one application node is selected according to a resource application sent by the at least two application nodes, and a distributed lock is allocated to the application node, so that the application node can access the critical resource by using the distributed lock to complete a service, and thus, a plurality of application nodes can access the critical resource in order, and a condition that dirty data occurs in concurrent operations can be effectively avoided.
Referring to fig. 9, fig. 9 is a schematic structural diagram of an embodiment of a computer-readable storage medium provided in the present application. The computer-readable storage medium 50 stores at least one computer program 51, and the computer program 51 is used for being executed by a processor to implement the method shown in fig. 1 to 4, and the detailed method can be referred to above and is not described herein again. In one embodiment, the computer readable storage medium 50 may be a memory chip in a terminal, a hard disk, or other readable and writable storage tool such as a removable hard disk, a flash disk, an optical disk, or the like, and may also be a server or the like.
As can be seen from the above description, the computer program stored in the computer-readable storage medium in this embodiment may be used to enable a plurality of application nodes to sequentially access a critical resource when the plurality of application nodes need to access the critical resource simultaneously, so as to effectively avoid a situation that dirty data occurs in concurrent operations.
Different from the prior art, the method selects one application node according to the resource application sent by each application node, and distributes the distributed lock to the application node, so that the application node can access the critical resource by using the distributed lock, the sequential access of a plurality of application nodes to the critical resource is realized, and the condition of dirty data in concurrent operation is effectively avoided.
The above disclosure is only for the purpose of illustrating the preferred embodiments of the present invention, and it is therefore to be understood that the invention is not limited by the scope of the appended claims.
Claims (10)
1. A resource acquisition method is applied to a distributed system and comprises the following steps:
generating a resource application according to a service to be executed, and sending the resource application to a distributed lock;
judging whether the distributed lock is acquired, and monitoring the distributed lock if the distributed lock is not acquired;
and when monitoring that the distributed lock is released by the application node acquiring the distributed lock, sending the resource application to the distributed lock again.
2. The method according to claim 1, wherein the step of determining whether the distributed lock is acquired comprises:
if the distributed lock is acquired, accessing critical resources by using the distributed lock to execute the service;
and releasing the distributed lock after the service is executed.
3. The method according to claim 1, wherein the step of generating the resource application according to the service to be executed includes:
judging whether the service to be executed needs to access critical resources, and if so, generating the resource application;
the step of sending the resource application to the distributed lock includes:
and sending the resource application to the distributed lock corresponding to the critical resource.
4. The method of claim 1, wherein the step of sending the resource request to the distributed lock again comprises:
if the distributed lock is not acquired, monitoring the distributed lock repeatedly, and sending the resource application to the distributed lock when the distributed lock is released until the distributed lock is acquired.
5. A resource allocation method is applied to a distributed system and comprises the following steps:
acquiring resource applications sent by at least two application nodes, wherein the resource applications are generated by the at least two application nodes according to a service to be executed;
and distributing the distributed lock to one of the application nodes according to a preset selection mechanism, so that the application nodes access the critical resource based on the distributed lock to complete the service.
6. A resource acquisition apparatus, comprising:
the application module is used for generating a resource application according to the service to be executed and sending the resource application to the distributed lock;
the judging module is used for judging whether to acquire the distributed lock or not, and monitoring the distributed lock if the distributed lock is not acquired;
and the monitoring module is used for sending the resource application to the distributed lock again when monitoring that the distributed lock is released by the application node which acquires the distributed lock.
7. A resource allocation apparatus, comprising:
an obtaining module, configured to obtain resource applications sent by at least two application nodes, where the resource applications are generated by the at least two application nodes according to a service to be executed;
and the distribution module is used for distributing the distributed lock to one of the application nodes according to a preset selection mechanism, so that the application nodes access the critical resource to complete the service based on the distributed lock.
8. A resource acquisition apparatus, comprising: a processor, a memory and a communication circuit, the processor coupled to the memory and the communication circuit, the memory having stored therein a computer program, the processor executing the computer program to implement the method of any of claims 1-4.
9. A resource allocation apparatus, comprising: a processor, a memory and a communication circuit, the processor coupled to the memory and the communication circuit, the memory having stored therein a computer program, the processor executing the computer program to implement the method of claim 5.
10. A computer-readable storage medium, in which a computer program is stored, which computer program is executable by a processor to implement the method according to any one of claims 1-5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911324766.4A CN111163140A (en) | 2019-12-20 | 2019-12-20 | Method, apparatus and computer readable storage medium for resource acquisition and allocation |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911324766.4A CN111163140A (en) | 2019-12-20 | 2019-12-20 | Method, apparatus and computer readable storage medium for resource acquisition and allocation |
Publications (1)
Publication Number | Publication Date |
---|---|
CN111163140A true CN111163140A (en) | 2020-05-15 |
Family
ID=70557421
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201911324766.4A Pending CN111163140A (en) | 2019-12-20 | 2019-12-20 | Method, apparatus and computer readable storage medium for resource acquisition and allocation |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111163140A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111930503A (en) * | 2020-08-05 | 2020-11-13 | 浪潮云信息技术股份公司 | Resource lock acquisition method based on ETCD |
CN113434272A (en) * | 2021-06-25 | 2021-09-24 | 中国工商银行股份有限公司 | Thread scheduling method and device based on distributed cache |
CN113806388A (en) * | 2021-09-22 | 2021-12-17 | 中国工商银行股份有限公司 | Service processing method and device based on distributed lock |
CN116405509A (en) * | 2023-06-09 | 2023-07-07 | 深圳前海环融联易信息科技服务有限公司 | Distributed monitoring method, computer equipment and storage medium thereof |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20030093524A1 (en) * | 2001-11-13 | 2003-05-15 | Microsoft Corporation | Method and system for locking resources in a distributed environment |
CN103297456A (en) * | 2012-02-24 | 2013-09-11 | 阿里巴巴集团控股有限公司 | Method for accessing sharing resources in distributed system and distributed system |
CN105700939A (en) * | 2016-04-21 | 2016-06-22 | 北京京东尚科信息技术有限公司 | Method and system for multi-thread synchronization in distributed system |
CN107133108A (en) * | 2017-04-27 | 2017-09-05 | 努比亚技术有限公司 | Implementation method, terminal, server and the computer-readable recording medium of distributed complex lock |
CN108319496A (en) * | 2017-01-18 | 2018-07-24 | 阿里巴巴集团控股有限公司 | resource access method, service server, distributed system and storage medium |
CN108897628A (en) * | 2018-05-25 | 2018-11-27 | 北京奇艺世纪科技有限公司 | A kind of implementation method of distributed lock, device and electronic equipment |
-
2019
- 2019-12-20 CN CN201911324766.4A patent/CN111163140A/en active Pending
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20030093524A1 (en) * | 2001-11-13 | 2003-05-15 | Microsoft Corporation | Method and system for locking resources in a distributed environment |
CN103297456A (en) * | 2012-02-24 | 2013-09-11 | 阿里巴巴集团控股有限公司 | Method for accessing sharing resources in distributed system and distributed system |
CN105700939A (en) * | 2016-04-21 | 2016-06-22 | 北京京东尚科信息技术有限公司 | Method and system for multi-thread synchronization in distributed system |
CN108319496A (en) * | 2017-01-18 | 2018-07-24 | 阿里巴巴集团控股有限公司 | resource access method, service server, distributed system and storage medium |
CN107133108A (en) * | 2017-04-27 | 2017-09-05 | 努比亚技术有限公司 | Implementation method, terminal, server and the computer-readable recording medium of distributed complex lock |
CN108897628A (en) * | 2018-05-25 | 2018-11-27 | 北京奇艺世纪科技有限公司 | A kind of implementation method of distributed lock, device and electronic equipment |
Non-Patent Citations (1)
Title |
---|
张鸿涛: "《大数据开发与应用》", 30 September 2018 * |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111930503A (en) * | 2020-08-05 | 2020-11-13 | 浪潮云信息技术股份公司 | Resource lock acquisition method based on ETCD |
CN113434272A (en) * | 2021-06-25 | 2021-09-24 | 中国工商银行股份有限公司 | Thread scheduling method and device based on distributed cache |
CN113434272B (en) * | 2021-06-25 | 2024-03-22 | 中国工商银行股份有限公司 | Thread scheduling method and device based on distributed cache |
CN113806388A (en) * | 2021-09-22 | 2021-12-17 | 中国工商银行股份有限公司 | Service processing method and device based on distributed lock |
CN116405509A (en) * | 2023-06-09 | 2023-07-07 | 深圳前海环融联易信息科技服务有限公司 | Distributed monitoring method, computer equipment and storage medium thereof |
CN116405509B (en) * | 2023-06-09 | 2023-09-01 | 深圳前海环融联易信息科技服务有限公司 | Distributed monitoring method, computer equipment and storage medium thereof |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112099958B (en) | Distributed multi-task management method and device, computer equipment and storage medium | |
CN110647394B (en) | Resource allocation method, device and equipment | |
CN115328663B (en) | Method, device, equipment and storage medium for scheduling resources based on PaaS platform | |
CN111163140A (en) | Method, apparatus and computer readable storage medium for resource acquisition and allocation | |
CN110351384B (en) | Big data platform resource management method, device, equipment and readable storage medium | |
US10686728B2 (en) | Systems and methods for allocating computing resources in distributed computing | |
WO2018108001A1 (en) | System and method to handle events using historical data in serverless systems | |
WO2019037203A1 (en) | Application program performance testing method, device, computer equipment, and storage medium | |
KR100509794B1 (en) | Method of scheduling jobs using database management system for real-time processing | |
US11838384B2 (en) | Intelligent scheduling apparatus and method | |
CN106712981B (en) | Node change notification method and device | |
CN102868573B (en) | Method and device for Web service load cloud test | |
US20090276519A1 (en) | Method and System for Achieving Better Efficiency in a Client Grid Using Node Resource Usage and Tracking | |
US8832215B2 (en) | Load-balancing in replication engine of directory server | |
CN111831504B (en) | Monitoring method, monitoring device, computer equipment and medium | |
CN110557416A (en) | multi-node collaborative blocking method and system | |
US9672073B2 (en) | Non-periodic check-pointing for fine granular retry of work in a distributed computing environment | |
EP3672203A1 (en) | Distribution method for distributed data computing, device, server and storage medium | |
CN111835809B (en) | Work order message distribution method, work order message distribution device, server and storage medium | |
CN113703930A (en) | Task scheduling method, device and system and computer readable storage medium | |
CN109257201B (en) | License sending method and device | |
CN111309467B (en) | Task distribution method and device, electronic equipment and storage medium | |
WO2022001353A1 (en) | Mixed scheduling system and method for virtual machine and container, and scheduler and apparatus | |
US20100199281A1 (en) | Managing the Processing of Processing Requests in a Data Processing System Comprising a Plurality of Processing Environments | |
CN115292176A (en) | Pressure testing method, device, equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200515 |