Method, device, equipment and storage medium for creating a virtual machine

By using virtual machines to create lists and distributed locks in the OpenStack platform, the concurrent creation process of virtual machines is solved, and the creation success rate and platform stability are improved.

CN114896022BActive Publication Date: 2025-09-02SUGON INFORMATION IND
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210328154.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-30
Publication Date
2025-09-02
Estimated Expiration
2042-03-30

AI Technical Summary

Technical Problem

The OpenStack platform can easily lead to creation failure when creating virtual machines concurrently, reducing the probability of successful creation of virtual machines.

Method used

Control the concurrent creation process of virtual machines by using virtual machines to create lists and distributed locks in the OpenStack platform. The specific steps include obtaining the target computing node, sending resource occupancy requests, occupying distributed locks, setting the task status to the block map state, and releasing the lock after the creation is completed to ensure the order and concurrent control of the creation process.

Benefits of technology

It improves the probability of successful creation of virtual machines, improves the stability of the virtual machine management platform, and avoids failures caused by high concurrent creation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114896022B_ABST
    Figure CN114896022B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, equipment and storage medium for creating a virtual machine. The method includes: when a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table; when it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to a virtual machine creation list, and then a distributed lock occupation request is sent to a preset database through the target computing node; when a distributed lock occupation success message is detected, the target virtual machine is set to a block mapping state; thereafter, the distributed lock occupied by the target computing node is released, and the target virtual machine is deleted from the virtual machine creation list to complete the creation of the target virtual machine. The technical solution of this embodiment, by adopting a virtual machine creation list and a distributed lock, can change the concurrent creation of virtual machines to queue creation, which can improve the probability of successful creation of virtual machines, thereby improving the stability of the virtual machine management platform.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a method, apparatus, device and storage medium for creating a virtual machine. Background Art

[0002] With the rapid development of information technology, the demand for flexibly configurable servers continues to grow. As an important part of software-defined infrastructure, virtual machines are receiving more and more attention.

[0003] Currently, OpenStack is a widely used virtual machine management platform. Virtual machines can be created and managed through OpenStack's pre-defined components, such as Nova and Cinder. Furthermore, OpenStack can connect to storage devices with varying creation speeds and limitations. However, for storage devices with slow creation speeds and limited concurrent creation support, OpenStack does not impose a limit on the number of concurrent virtual machine creations. Consequently, when concurrent virtual machine creation is required through OpenStack, virtual machine creation can easily fail, reducing the probability of successful virtual machine creation. Summary of the Invention

[0004] The embodiments of the present invention provide a method, apparatus, device and storage medium for creating a virtual machine, which can avoid the failure of virtual machine creation and increase the probability of successful virtual machine creation, thereby improving the stability of the virtual machine management platform.

[0005] In a first aspect, an embodiment of the present invention provides a method for creating a virtual machine, comprising:

[0006] When a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, and a resource occupation request is sent to the target computing node;

[0007] When it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to the virtual machine creation list, and a distributed lock occupation request is sent to a preset database through the target computing node;

[0008] When a distributed lock occupation success message fed back by a preset database is detected, the task state corresponding to the target virtual machine in the virtual machine creation list is set to a block mapping state;

[0009] The distributed lock occupied by the target computing node is released, and when it is detected that the task state corresponding to the target virtual machine is changed to the block mapping end state, the target virtual machine is deleted from the virtual machine creation list to complete the creation of the target virtual machine.

[0010] Optionally, setting the task state corresponding to the target virtual machine in the virtual machine creation list to a block mapping state includes:

[0011] Determine whether the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are all in block mapping state;

[0012] If so, obtain the number of virtual machines whose task status is block mapping state, and determine whether the number of virtual machines whose task status is block mapping state is less than the preset maximum concurrent number;

[0013] If it is determined that the number of virtual machines whose task status is the block mapping state is less than the preset maximum concurrent number, the task status corresponding to the target virtual machine is set to the block mapping state.

[0014] By adopting the above technical solution, it is possible to ensure that virtual machines are created one by one while ensuring that the number of concurrent creation of virtual machines is less than the maximum concurrent number supported by the storage device, thereby avoiding the failure of virtual machine creation and increasing the probability of successful virtual machine creation.

[0015] Optionally, setting the task state corresponding to the target virtual machine in the virtual machine creation list to a block mapping state includes:

[0016] If it is determined that the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are not all in the block mapping state, or if it is determined that the number of virtual machines whose task states are in the block mapping state is greater than or equal to the preset maximum concurrent number, releasing the distributed lock occupied by the target computing node;

[0017] After waiting for a preset time, the distributed lock occupation request is resent to the preset database through the target computing node until it is detected that the task states corresponding to the virtual machines in the virtual machine creation list that are located before the target virtual machine are all in block mapping state, and the number of virtual machines with task states in block mapping state is less than the preset maximum concurrent number, and the task state corresponding to the target virtual machine is set to block mapping state.

[0018] By adopting the above technical solution, it is possible to ensure that the task state of the target virtual machine is set to the block mapping state, thereby confirming the successful creation of the target virtual machine and further improving the success probability of the virtual machine creation.

[0019] Optionally, after sending the distributed lock occupation request to the preset database through the target computing node, the method further includes:

[0020] When a distributed lock occupation failure message fed back by the preset database is detected, after waiting for a preset time, a distributed lock occupation request is resent to the preset database through the target computing node until a distributed lock occupation success message fed back by the preset database is detected.

[0021] The above technical solution can overcome the problem of target computing node failing to occupy the distributed lock and improve the probability of target computing node successfully occupying the distributed lock.

[0022] Optionally, when a creation request for a target virtual machine is detected, obtaining a target computing node from a preset database table includes:

[0023] When a creation request for a target virtual machine is detected, the remaining computing resources corresponding to each computing node in the preset database table are obtained;

[0024] According to the remaining computing resources corresponding to each of the computing nodes, obtaining a candidate computing node corresponding to the maximum remaining computing resources from each of the computing nodes;

[0025] When it is detected that the remaining computing resources corresponding to the candidate computing node meet a preset computing resource detection condition, the candidate computing node is determined as a target computing node.

[0026] By adopting the above technical solution, when creating a target virtual machine, a computing node with the largest remaining computing resources can be allocated to the target virtual machine, thereby improving the creation efficiency and task processing efficiency of the target virtual machine.

[0027] Optionally, sending a distributed lock occupation request to a preset database through the target computing node includes:

[0028] An asynchronous remote call request is sent to the target computing node, and when the target computing node receives the asynchronous remote call request, a distributed lock occupation request is sent to a preset database.

[0029] By adopting the above technical solution, the target computing node occupies the distributed lock, which can achieve successful occupation of the distributed lock and improve the probability of successful occupation of the distributed lock.

[0030] Optionally, the types of the preset database include key-value database and relational database.

[0031] By adopting the above technical solution and implementing distributed locks based on a key-value database or a relational database, the efficiency of creating distributed locks can be improved, as well as the efficiency of allocating and releasing distributed locks can be improved.

[0032] In a second aspect, an embodiment of the present invention further provides a device for creating a virtual machine, comprising:

[0033] A target computing node acquisition module is configured to, when a creation request for a target virtual machine is detected, acquire a target computing node from a preset database table and send a resource occupation request to the target computing node;

[0034] A distributed lock occupation request sending module is used to add the target virtual machine to the virtual machine creation list when detecting that the resources of the target computing node are successfully occupied, and send a distributed lock occupation request to a preset database through the target computing node;

[0035] A block mapping state setting module is used to set the task state corresponding to the target virtual machine in the virtual machine creation list to the block mapping state when a distributed lock occupation success message fed back by the preset database is detected;

[0036] The target virtual machine creation module is used to release the distributed lock occupied by the target computing node and delete the target virtual machine from the virtual machine creation list when detecting that the task state corresponding to the target virtual machine is changed to the block mapping end state to complete the creation of the target virtual machine.

[0037] In a third aspect, an embodiment of the present invention further provides an electronic device, including:

[0038] one or more processors;

[0039] a memory for storing one or more programs,

[0040] When the one or more programs are executed by the one or more processors, the one or more processors implement the method for creating a virtual machine as described in any embodiment of the present invention.

[0041] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for creating a virtual machine as described in any embodiment of the present invention.

[0042] The technical solution provided by the embodiment of the present invention is as follows: when a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, and a resource occupation request is sent to the target computing node; when it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to the virtual machine creation list, and a distributed lock occupation request is sent to the preset database through the target computing node; when a distributed lock occupation success message fed back by the preset database is detected, the task state corresponding to the target virtual machine in the virtual machine creation list is set to a block mapping state; and then the distributed lock occupied by the target computing node is released, and when it is detected that the task state corresponding to the target virtual machine is changed to a block mapping end state, the target virtual machine is deleted from the virtual machine creation list to complete the creation of the target virtual machine. By adopting a virtual machine creation list and a distributed lock, the concurrent creation of virtual machines can be changed to queue creation, which can avoid the occurrence of virtual machine creation failures, improve the probability of successful virtual machine creation, and thus improve the stability of the virtual machine management platform. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 This is a flowchart of a method for creating a virtual machine provided by an embodiment of the present invention;

[0044] Figure 2 is a flowchart of another method for creating a virtual machine provided by an embodiment of the present invention;

[0045] Figure 3A is a flowchart of another method for creating a virtual machine provided by an embodiment of the present invention;

[0046] Figure 3B This is a flow chart of another method for creating a virtual machine provided by an embodiment of the present invention;

[0047] Figure 4 This is a structural block diagram of a device for creating a virtual machine provided by an embodiment of the present invention;

[0048] Figure 5 This is a structural block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0049] The present invention will be further described in detail below with reference to the accompanying drawings and examples. It will be understood that the specific embodiments described herein are intended only to illustrate the present invention and are not intended to limit the present invention. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions relevant to the present invention, not all structures.

[0050] Figure 1A flowchart of a method for creating a virtual machine is provided in an embodiment of the present invention. The embodiment of the present invention is applicable to creating a virtual machine in an OpenStack platform. The method can be executed by a virtual machine creation device in an embodiment of the present invention. The device can be implemented by software and / or hardware and integrated into an electronic device, typically a computer device or a server. The method specifically includes the following steps:

[0051] S110 : When a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, and a resource occupation request is sent to the target computing node.

[0052] The target virtual machine can be the virtual machine that needs to be created. The preset database table can be a collection of multiple compute nodes, including the computing resources corresponding to each compute node and the remaining computing resources. Compute nodes are an important component of the OpenStack platform, primarily responsible for providing computing services, network services, and monitoring services.

[0053] In this embodiment, a request to create a target virtual machine can be issued in the OpenStack platform through the interface or command line. For example, an HTTP (HyperText Transfer Protocol) request or an HTTPS (Hypertext Transfer Protocol Secure) request can be issued to the nova-api control via the novaclient control of the Nova component to create the target virtual machine. Correspondingly, the compute node can be implemented by the nova-comoute control of the Nova component's computing workstation. In an actual production environment, many compute nodes are set up, and a virtual machine instance can be deployed on any available compute node based on the scheduling algorithm.

[0054] In this embodiment, when a request to create a target virtual machine is detected, the computing nodes currently included in the preset database table and the remaining computing resources corresponding to each computing node can be obtained. Then, based on the remaining computing resources corresponding to each computing node, the computing node that performs the task of creating the target virtual machine can be selected from the computing nodes as the target computing node. For example, the computing node with the largest remaining computing resources can be selected as the target computing node, or computing nodes whose remaining computing resources are greater than a preset remaining computing resource threshold can be first screened and then a computing node can be randomly selected from the screened computing nodes as the target computing node.

[0055] Furthermore, after determining the target computing node, a resource occupation request may be sent to the target computing node to pre-occupy computing resources of the target computing node. The pre-occupied computing resources of the target computing node are mainly used for subsequent creation of the target virtual machine.

[0056] S120: When it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to a virtual machine creation list, and a distributed lock occupation request is sent to a preset database through the target computing node.

[0057] The virtual machine creation list is a newly created list used to record virtual machines being created. In this embodiment, when a virtual machine needs to be created, each virtual machine is added to the virtual machine creation list in the order in which it was created. When a virtual machine is created, its corresponding record is deleted from the virtual machine creation list. It is worth noting that each virtual machine in the virtual machine creation list is created in the order in which it was stored, i.e., the virtual machine added first is created first.

[0058] In this embodiment, after sending a resource occupation request to the target computing node, if the computing resources of the target computing node are successfully occupied, a record of the target virtual machine can be added to the pre-established virtual machine creation list. Then, a distributed lock occupation request is sent to the preset database through the target computing node to attempt to occupy the distributed lock.

[0059] Distributed locks are a method for controlling synchronized access to shared resources between distributed systems. In this embodiment, when concurrent virtual machine creation occurs, some storage devices may not support high concurrency, which can easily lead to virtual machine creation failures. To address this issue, distributed locks are implemented so that only virtual machine creation tasks that have occupied the distributed lock can access the storage device. This prevents virtual machine creation failures caused by high concurrency and increases the probability of successful virtual machine creation.

[0060] Optionally, the types of preset databases may include key-value databases and relational databases; wherein, the key-value database may be a Redis database or an ETCD database. In a key-value database, data is stored in the form of key-value pairs, the key may be a pre-set global string, which is a fixed value, and the value may correspond to the identifier of the computing node occupied by the virtual machine to be created. In this embodiment, if it is detected that the value corresponding to the key value is the identifier of the target computing node, it means that the target virtual machine creation task of the target computing node currently occupies the distributed lock. The relational database may be a MySQL database; in a MySQL database, a distributed lock may be established by creating a lock table. When the target computing node successfully occupies the distributed lock, a record corresponding to the identifier of the target computing node may be added to the lock table, and when the distributed lock needs to be released, the record may be deleted accordingly.

[0061] It is understandable that the preset database can manage distributed locks, for example, the allocation of distributed locks, the release of distributed locks, and the timeout release of distributed locks.

[0062] In this embodiment, a distributed lock can be pre-set based on a preset database. Each computing node sequentially occupies the distributed lock to sequentially create virtual machines, thereby achieving concurrent control over virtual machine creation. Specifically, each computing node that needs to create a virtual machine requests to occupy the distributed lock at preset intervals. When the preset database detects that the distributed lock is initially unoccupied, it can determine the computing node that first requested to occupy the distributed lock as the computing node that successfully occupied the distributed lock.

[0063] The advantage of the above setting is that distributed locks can be implemented based on key-value databases or relational databases, and existing database instructions can be used to improve the efficiency of distributed lock implementation and the efficiency of distributed lock management.

[0064] In an optional implementation of this embodiment, sending a distributed lock occupation request to a preset database through the target computing node may include: sending an asynchronous remote call request to the target computing node, and sending a distributed lock occupation request to the preset database through the target computing node when receiving the asynchronous remote call request.

[0065] Specifically, when a distributed lock seizure request is sent to a preset database via a target computing node, an asynchronous remote call request to create a virtual machine may be first sent to the target computing node. After receiving the remote asynchronous call request, the target computing node may then send a distributed lock seizure request to the preset database in an attempt to seize the distributed lock. In this embodiment, the above configuration enables the seizure of the distributed lock request, thereby achieving successful application of the distributed lock.

[0066] S130: When a distributed lock occupation success message fed back by a preset database is detected, the task state corresponding to the target virtual machine in the virtual machine creation list is set to a block mapping state.

[0067] In this embodiment, when a distributed lock seizure success message is detected from the preset database, it indicates that the target virtual machine creation task has successfully seized the distributed lock. At this point, a block mapping between the target virtual machine and the storage device can be established. Once the block mapping is successfully established, the task status corresponding to the target virtual machine in the virtual machine creation list can be set to the block mapping status. The task status indicates the virtual machine creation process currently in progress.

[0068] In another optional implementation of this embodiment, after sending a distributed lock occupation request to the preset database through the target computing node, it may also include: when a distributed lock occupation failure message is detected from the preset database, after waiting for a preset time, the distributed lock occupation request is re-sent to the preset database through the target computing node until a distributed lock occupation success message is detected from the preset database.

[0069] When a distributed lock acquisition failure message is received from the preset database, it indicates that no distributed lock is currently available. At this point, the target compute node can retry to seize the distributed lock after waiting for a preset time. This process is repeated until a distributed lock acquisition success message is received from the preset database, successfully acquiring the distributed lock.

[0070] In this embodiment, through the above settings, the situation where the distributed lock cannot be obtained can be avoided, the target computing node can be ensured to successfully occupy the distributed lock, and the probability of the target computing node successfully occupying the distributed lock can be increased.

[0071] S140. Release the distributed lock occupied by the target computing node, and when detecting that the task state corresponding to the target virtual machine is changed to the block mapping end state, delete the target virtual machine from the virtual machine creation list to complete the creation of the target virtual machine.

[0072] In this embodiment, after detecting that the task status corresponding to the target virtual machine is in the block mapping state, the target compute node can send a distributed lock release request to the preset database to release the currently occupied distributed lock. The regular OpenStack virtual machine creation process then continues. Upon detecting that the task status corresponding to the target virtual machine has changed to the block mapping end state, the target virtual machine's record is deleted from the virtual machine creation list. The subsequent OpenStack virtual machine creation process then continues until the target virtual machine is created.

[0073] In this embodiment, by adopting a virtual machine creation list and a distributed lock, the concurrent creation of virtual machines can be changed to queue creation of virtual machines, thereby greatly avoiding the failure of virtual machine creation caused by high-concurrency virtual machine creation, and further improving the probability of successful virtual machine creation.

[0074] The technical solution provided by the embodiment of the present invention is as follows: when a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, and a resource occupation request is sent to the target computing node; when it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to the virtual machine creation list, and a distributed lock occupation request is sent to the preset database through the target computing node; when a distributed lock occupation success message fed back by the preset database is detected, the task state corresponding to the target virtual machine in the virtual machine creation list is set to a block mapping state; and then the distributed lock occupied by the target computing node is released, and when it is detected that the task state corresponding to the target virtual machine is changed to a block mapping end state, the target virtual machine is deleted from the virtual machine creation list to complete the creation of the target virtual machine. By adopting a virtual machine creation list and a distributed lock, the concurrent creation of virtual machines can be changed to queue creation, which can avoid the occurrence of virtual machine creation failures, improve the probability of successful virtual machine creation, and thus improve the stability of the virtual machine management platform.

[0075] Figure 2 A flowchart of another method for creating a virtual machine provided by an embodiment of the present invention is provided. This embodiment is specific based on the above embodiment. In this embodiment, when it is detected that the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are all in the block mapping state, and the number of virtual machines in the block mapping state is less than a preset maximum concurrent number, the task state corresponding to the target virtual machine is set to the block mapping state. The method specifically includes:

[0076] S210: When a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, and a resource occupation request is sent to the target computing node.

[0077] In an optional implementation of this embodiment, when a creation request for a target virtual machine is detected, obtaining a target computing node in a preset database table may include: when a creation request for a target virtual machine is detected, obtaining the remaining computing resources corresponding to each computing node in the preset database table; based on the remaining computing resources corresponding to each of the computing nodes, obtaining a candidate computing node corresponding to the maximum remaining computing resources among the computing nodes; when it is detected that the remaining computing resources corresponding to the candidate computing node meet the preset computing resource detection conditions, determining the candidate computing node as the target computing node.

[0078] Among them, the preset computing resource detection condition can be a pre-set condition for determining whether the remaining computing resources corresponding to the candidate computing node meet the requirements; for example, the preset computing resource detection condition can be that the remaining computing resources are greater than a preset remaining computing resource threshold.

[0079] In a specific example, when a request to create a target virtual machine is detected, the remaining computing resources corresponding to each computing node in a preset database table can be first obtained. Then, the remaining computing resources corresponding to each computing node are compared to obtain the maximum remaining computing resource, and the computing node corresponding to the maximum remaining computing resource is determined as a candidate computing node. Furthermore, a determination is made as to whether the maximum remaining computing resource corresponding to the candidate computing node is greater than a preset remaining computing resource threshold. If so, the candidate computing node can be determined as the target computing node.

[0080] Optionally, obtaining the target computing node in the preset database table may also include: obtaining the remaining computing resources corresponding to each computing node in the preset database table, and screening out the first computing node whose remaining computing resources are greater than a preset remaining computing resource threshold among each computing node; thereafter, the preset weight calculation rules may be adopted to calculate the multiple weights corresponding to each first computing node according to the remaining computing resources corresponding to each first computing node; further, the weights corresponding to each first computing node are added to obtain the total weight corresponding to each first computing node, and the first computing nodes are sorted in reverse order according to the total weight corresponding to each first computing node; finally, computing resources are requested from each sorted first computing node in turn until it is detected that the resources of a first computing node are successfully occupied.

[0081] When sorting the first computing nodes in descending order, if there are multiple first computing nodes with the same total weight, the first computing nodes can be randomly sorted. The preset weight calculation rules can be different preset events (for example, the remaining hard disk space, the idle percentage of the CPU, the number of historical virtual machine creation failures, etc.) corresponding to different weight coefficients.

[0082] S220: When it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to the virtual machine creation list, and a distributed lock occupation request is sent to a preset database through the target computing node.

[0083] S230: When a distributed lock occupation success message fed back by a preset database is detected, it is determined whether the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are all in a block mapping state.

[0084] After confirming that the distributed lock has been successfully acquired, the task status of the other virtual machines preceding the target virtual machine in the virtual machine creation list can be obtained. If the task status of each of the other virtual machines is determined to be in the block mapping state, this indicates that the volumes required by the virtual machines to be created before the target virtual machine are being created or connections to the volumes are being established. At this point, after confirming that the number of virtual machine creations does not exceed the maximum number of concurrent connections supported by the storage device, the block mapping between the target virtual machine and the storage device can be established.

[0085] S240: If yes, obtain the number of virtual machines whose task status is block mapping state, and determine whether the number of virtual machines whose task status is block mapping state is less than the preset maximum concurrent number.

[0086] The preset maximum concurrent number may be a pre-acquired maximum concurrent number supported by the storage device.

[0087] S250: If it is determined that the number of virtual machines whose task status is the block mapping state is less than the preset maximum concurrent number, set the task status corresponding to the target virtual machine to the block mapping state.

[0088] In this embodiment, if it is determined that the task status corresponding to each virtual machine located before the target virtual machine in the virtual machine creation list is all in the block mapping state, and the number of virtual machines with the task status in the block mapping state is less than the preset maximum concurrent number, then the block mapping between the target virtual machine and the storage device can be established, and the task status corresponding to the target virtual machine is set to the block mapping state.

[0089] S260. Release the distributed lock occupied by the target computing node, and when detecting that the task state corresponding to the target virtual machine is changed to the block mapping end state, delete the target virtual machine from the virtual machine creation list to complete the creation of the target virtual machine.

[0090] The technical solution provided by the embodiment of the present invention, when a distributed lock occupation success message fed back by a preset database is detected, determines whether the task statuses corresponding to the virtual machines located before the target virtual machine in the virtual machine creation list are all in block mapping status; if so, obtains the number of virtual machines with task statuses in block mapping status, and determines whether the number of virtual machines with task statuses in block mapping status is less than the preset maximum concurrent number; if it is determined that the number of virtual machines with task statuses in block mapping status is less than the preset maximum concurrent number, sets the task status corresponding to the target virtual machine to block mapping status; by judging the task statuses corresponding to the virtual machines located before the target virtual machine and the number of virtual machines with task statuses in block mapping status, it is determined whether the task status corresponding to the target virtual machine can be set to block mapping status at present, thereby further avoiding the failure of virtual machine creation and further improving the probability of successful virtual machine creation.

[0091] Figure 3A A flowchart of another virtual machine creation method provided by an embodiment of the present invention is provided. This embodiment is specific based on the above embodiment. In this embodiment, if it is determined that the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are not all in the block mapping state, or if it is determined that the number of virtual machines with the task state in the block mapping state is greater than or equal to the preset maximum concurrent number, the distributed lock occupied by the target computing node is released, and after waiting for a preset time, a distributed lock occupation request is resent to the preset database through the target computing node until it is detected that the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are all in the block mapping state, and the number of virtual machines with the task state in the block mapping state is less than the preset maximum concurrent number, and the task state corresponding to the target virtual machine is set to the block mapping state. The method specifically includes:

[0092] S310, start and execute S320.

[0093] S320. When a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, a resource occupation request is sent to the target computing node, and S330 is executed.

[0094] S330. When it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to the virtual machine creation list, and S340 is executed.

[0095] S340 . Send a distributed lock occupation request to a preset database through the target computing node, and execute S350 .

[0096] S350: When a distributed lock occupation success message fed back by a preset database is detected, it is determined whether the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are all in a block mapping state.

[0097] If yes, execute S360; if no, execute S370.

[0098] S360: Obtain the number of virtual machines whose task status is the block mapping state, and determine whether the number of virtual machines whose task status is the block mapping state is less than a preset maximum concurrent number.

[0099] If it is determined that the number of virtual machines in the block mapping state is greater than or equal to the preset maximum concurrent number, execute S370; if it is determined that the number of virtual machines in the block mapping state is less than the preset maximum concurrent number, execute S380.

[0100] S370: Release the distributed lock occupied by the target computing node, and after waiting for a preset time, return to execute S340.

[0101] Specifically, when the task states corresponding to the virtual machines that precede the target virtual machine in the virtual machine creation list are not all in the block mapping state, or the number of virtual machines with the task state in the block mapping state is greater than or equal to the preset maximum concurrent number, the block mapping between the target virtual machine and the storage device cannot be successfully established at this time. It is necessary to wait until the task states corresponding to other virtual machines that precede the target virtual machine are all changed to the block mapping state, and the number of virtual machines with the task state in the block mapping state is less than the preset maximum concurrent number before the block mapping between the target virtual machine and the storage device can be established, and the task state corresponding to the target virtual machine can be set to the block mapping state.

[0102] Furthermore, while the target VM is waiting to be created, to avoid long-term, ineffective use of the distributed lock and to improve distributed lock utilization efficiency, the distributed lock held by the target compute node must be released. Subsequently, when attempting to reestablish a block mapping between the target VM and the storage device, the target compute node can re-request the distributed lock. This process repeats until the detection conditions are met, at which point the task status corresponding to the target VM is set to the block mapping state.

[0103] In this embodiment, the above settings can ensure the creation of a queue for virtual machines, and at the same time avoid the failure of virtual machine creation caused by the number of virtual machine creation exceeding the maximum concurrent number supported by the storage device, thereby further improving the probability of successful virtual machine creation.

[0104] S380: Set the task state corresponding to the target virtual machine to a block mapping state, and execute S390.

[0105] S390. Release the distributed lock occupied by the target computing node, and when it is detected that the task status corresponding to the target virtual machine is changed to the block mapping end state, delete the target virtual machine from the virtual machine creation list to complete the creation of the target virtual machine, and execute S3100.

[0106] S3100, end.

[0107] The technical solution provided by the embodiment of the present invention is as follows: if it is determined that the task states corresponding to the virtual machines located before the target virtual machine in the virtual machine creation list are not all block mapping states, or if it is determined that the number of virtual machines with task states in the block mapping state is greater than or equal to the preset maximum concurrent number, the distributed lock occupied by the target computing node is released, which can improve the utilization efficiency of the distributed lock; then, after waiting for a preset time, the distributed lock occupation request is re-sent to the preset database through the target computing node until it is detected that the task states corresponding to the virtual machines located before the target virtual machine in the virtual machine creation list are all block mapping states, and the number of virtual machines with task states in the block mapping state is less than the preset maximum concurrent number, and the task state corresponding to the target virtual machine is set to block mapping state, which can further improve the probability of successful virtual machine creation, thereby further improving the stability of the virtual machine management platform.

[0108] In a specific implementation of this embodiment, the process of the method for creating a virtual machine can be as follows: Figure 3B As shown. First, when a creation request for a target virtual machine is detected, the computing resources of the target computing node are pre-occupied in the preset database table, and a record of the target virtual machine is added to the virtual machine creation list create_queue. Then, a remote asynchronous call request to create a virtual machine is sent to the target computing node to seize the distributed lock from the preset database through the target computing node. If it is determined that the distributed lock preemption has failed, a random period of time is waited, and the distributed lock is re-seized from the preset database through the target computing node until the distributed lock is successfully preempted.

[0109] Afterwards, after determining that the distributed lock has been successfully preempted, determine whether the task states corresponding to the virtual machines located before the target virtual machine in the create_queue are all in the block mapping state, and whether the number of virtual machines with the task state in the block mapping state is less than the preset maximum concurrent number; if not, release the distributed lock occupied by the target computing node, wait for a random period of time, and re-preempt the distributed lock from the preset database through the target computing node until it is detected that the task states corresponding to the virtual machines located before the target virtual machine in the create_queue are all in the block mapping state, and the number of virtual machines with the task state in the block mapping state is less than the preset maximum concurrent number, and set the task state of the target virtual machine to the block mapping state.

[0110] Finally, the distributed lock occupied by the target compute node is released, and when the block mapping state of the target virtual machine is detected to have changed to the block mapping end state, the record of the target virtual machine is deleted from the create_queue. Then, the OpenStack virtual machine creation process continues until the target virtual machine is created.

[0111] Figure 4 This is a structural block diagram of a virtual machine creation device provided by an embodiment of the present invention, which specifically includes: a target computing node acquisition module 410, a distributed lock occupation request sending module 420, a block mapping state setting module 430 and a target virtual machine creation module 440; wherein,

[0112] The target computing node acquisition module 410 is configured to acquire the target computing node from a preset database table when a creation request for a target virtual machine is detected, and to send a resource occupation request to the target computing node;

[0113] A distributed lock occupation request sending module 420 is configured to, when detecting that the resources of the target computing node are successfully occupied, add the target virtual machine to the virtual machine creation list and send a distributed lock occupation request to a preset database through the target computing node;

[0114] The block mapping state setting module 430 is configured to set the task state corresponding to the target virtual machine in the virtual machine creation list to the block mapping state when a distributed lock occupation success message fed back by the preset database is detected;

[0115] The target virtual machine creation module 440 is used to release the distributed lock occupied by the target computing node, and when it detects that the task status corresponding to the target virtual machine is changed to the block mapping end state, delete the target virtual machine from the virtual machine creation list to complete the creation of the target virtual machine.

[0116] The technical solution provided by the embodiment of the present invention is as follows: when a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, and a resource occupation request is sent to the target computing node; when it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to the virtual machine creation list, and a distributed lock occupation request is sent to the preset database through the target computing node; when a distributed lock occupation success message fed back by the preset database is detected, the task state corresponding to the target virtual machine in the virtual machine creation list is set to a block mapping state; and then the distributed lock occupied by the target computing node is released, and when it is detected that the task state corresponding to the target virtual machine is changed to a block mapping end state, the target virtual machine is deleted from the virtual machine creation list to complete the creation of the target virtual machine. By adopting a virtual machine creation list and a distributed lock, the concurrent creation of virtual machines can be changed to queue creation, which can avoid the occurrence of virtual machine creation failures, improve the probability of successful virtual machine creation, and thus improve the stability of the virtual machine management platform.

[0117] Optionally, based on the above technical solution, the block mapping state setting module 430 includes:

[0118] a block mapping state determining unit, configured to determine whether the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are all in a block mapping state;

[0119] a virtual machine number determination unit, configured to, if yes, obtain the number of virtual machines whose task status is the block mapping state, and determine whether the number of virtual machines whose task status is the block mapping state is less than a preset maximum concurrent number;

[0120] The task state setting unit is configured to set the task state corresponding to the target virtual machine to the block mapping state if it is determined that the number of virtual machines whose task state is the block mapping state is less than a preset maximum concurrent number.

[0121] Optionally, based on the above technical solution, the block mapping state setting module 430 includes:

[0122] a distributed lock releasing unit, configured to release the distributed lock occupied by the target computing node if it is determined that the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are not all in the block mapping state, or if it is determined that the number of virtual machines whose task states are in the block mapping state is greater than or equal to a preset maximum concurrent number;

[0123] A re-request unit is used to re-send a distributed lock occupation request to the preset database through the target computing node after waiting for a preset time, until it is detected that the task status corresponding to each virtual machine located before the target virtual machine in the virtual machine creation list is all in the block mapping state, and the number of virtual machines with the task status of the block mapping state is less than the preset maximum concurrent number, and the task status corresponding to the target virtual machine is set to the block mapping state.

[0124] Optionally, based on the above technical solution, the virtual machine creation device further includes:

[0125] The distributed lock occupation request resending module is used to, when a distributed lock occupation failure message fed back by the preset database is detected, resend the distributed lock occupation request to the preset database through the target computing node after waiting for a preset time, until a distributed lock occupation success message fed back by the preset database is detected.

[0126] Optionally, based on the above technical solution, the target computing node acquisition module 410 includes:

[0127] The remaining computing resource acquisition unit is used to acquire the remaining computing resources corresponding to each computing node in the preset database table when a creation request for a target virtual machine is detected;

[0128] A candidate computing node acquisition unit is configured to acquire, from among the computing nodes, a candidate computing node corresponding to the maximum remaining computing resource based on the remaining computing resources corresponding to the computing nodes;

[0129] The target computing node determining unit is configured to determine the candidate computing node as the target computing node when it is detected that the remaining computing resources corresponding to the candidate computing node meet a preset computing resource detection condition.

[0130] Optionally, based on the above technical solution, the distributed lock occupation request sending module 420 is specifically used to send an asynchronous remote call request to the target computing node, and when the target computing node receives the asynchronous remote call request, it sends a distributed lock occupation request to the preset database.

[0131] Optionally, based on the above technical solution, the types of the preset database include key-value database and relational database.

[0132] The virtual machine creation device provided in the embodiment of the present invention can execute the virtual machine creation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0133] Figure 5 A schematic structural diagram of an electronic device provided in another embodiment of the present invention is shown in FIG. Figure 5 As shown, the electronic device includes a processor 50, a memory 51, an input device 52 and an output device 53; the number of processors 50 in the electronic device can be one or more. Figure 5 In the figure, a processor 50 is used as an example; the processor 50, memory 51, input device 52 and output device 53 in the electronic device can be connected by a bus or other means. Figure 5 The bus connection is taken as an example.

[0134] The memory 51 is a computer-readable storage medium that can be used to store software programs, computer executable programs, and modules, such as program instructions / modules corresponding to the virtual machine creation method in the embodiment of the present invention (for example, the target computing node acquisition module 410, the distributed lock occupation request sending module 420, the block mapping state setting module 430, and the target virtual machine creation module 440 in the virtual machine creation device). The processor 50 executes the various functional applications and data processing of the electronic device by running the software programs, instructions, and modules stored in the memory 51, that is, implementing the above-mentioned virtual machine creation method, namely:

[0135] When a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, and a resource occupation request is sent to the target computing node;

[0136] When it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to the virtual machine creation list, and a distributed lock occupation request is sent to a preset database through the target computing node;

[0137] When a distributed lock occupation success message fed back by a preset database is detected, the task state corresponding to the target virtual machine in the virtual machine creation list is set to a block mapping state;

[0138] The distributed lock occupied by the target computing node is released, and when it is detected that the task state corresponding to the target virtual machine is changed to the block mapping end state, the target virtual machine is deleted from the virtual machine creation list to complete the creation of the target virtual machine.

[0139] The memory 51 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function; the data storage area may store data generated based on the use of the terminal, etc. Furthermore, the memory 51 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state memory device. In some instances, the memory 51 may further include memory remotely located relative to the processor 50, and these remote memories may be connected to the electronic device via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0140] The input device 52 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the electronic device. The output device 53 may include a display device such as a display screen.

[0141] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any embodiment of the present invention. Of course, the computer-readable storage medium provided by an embodiment of the present invention can perform the relevant operations in the method for creating a virtual machine provided in any embodiment of the present invention. That is, when the program is executed by a processor, it implements:

[0142] When a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, and a resource occupation request is sent to the target computing node;

[0143] When it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to the virtual machine creation list, and a distributed lock occupation request is sent to a preset database through the target computing node;

[0144] When a distributed lock occupation success message fed back by a preset database is detected, the task state corresponding to the target virtual machine in the virtual machine creation list is set to a block mapping state;

[0145] The distributed lock occupied by the target computing node is released, and when it is detected that the task state corresponding to the target virtual machine is changed to the block mapping end state, the target virtual machine is deleted from the virtual machine creation list to complete the creation of the target virtual machine.

[0146] Through the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented with the help of software and necessary general-purpose hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for enabling an electronic device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0147] It is worth noting that in the embodiment of the above-mentioned virtual machine creation device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0148] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the concept of the present invention. The scope of the present invention is determined by the scope of the appended claims.

Claims

1. A method for creating a virtual machine, characterized in that: include: When a creation request for a target virtual machine is detected, a target computing node is obtained from a preset database table, and a resource occupation request is sent to the target computing node; When it is detected that the resources of the target computing node are successfully occupied, the target virtual machine is added to the virtual machine creation list, and a distributed lock occupation request is sent to a preset database through the target computing node; When a distributed lock occupation success message fed back by a preset database is detected, the task state corresponding to the target virtual machine in the virtual machine creation list is set to a block mapping state; releasing the distributed lock occupied by the target computing node, and upon detecting that the task state corresponding to the target virtual machine is changed to a block mapping end state, deleting the target virtual machine from the virtual machine creation list to complete the creation of the target virtual machine; Obtaining the target computing node from the preset database table includes: A first computing node whose remaining computing resources are greater than a preset remaining computing resource threshold is obtained from each computing node in the preset database table, and weights corresponding to the hard disk remaining space event, the central processing unit idle percentage event, and the number of historical virtual machine creation failures event are calculated based on the remaining computing resources corresponding to each first computing node; The weights are added together to obtain the total weight corresponding to each first computing node, and the target computing node is obtained based on the total weight.

2. The method according to claim 1, characterized in that Setting the task status corresponding to the target virtual machine in the virtual machine creation list to a block mapping status includes: Determine whether the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are all in block mapping state; If so, obtain the number of virtual machines whose task status is block mapping state, and determine whether the number of virtual machines whose task status is block mapping state is less than the preset maximum concurrent number; If it is determined that the number of virtual machines whose task status is the block mapping state is less than the preset maximum concurrent number, the task status corresponding to the target virtual machine is set to the block mapping state.

3. The method according to claim 2, characterized in that Setting the task status corresponding to the target virtual machine in the virtual machine creation list to a block mapping status includes: If it is determined that the task states corresponding to the virtual machines preceding the target virtual machine in the virtual machine creation list are not all in the block mapping state, or if it is determined that the number of virtual machines whose task states are in the block mapping state is greater than or equal to the preset maximum concurrent number, releasing the distributed lock occupied by the target computing node; After waiting for a preset time, the distributed lock occupation request is resent to the preset database through the target computing node until it is detected that the task states corresponding to the virtual machines in the virtual machine creation list that are located before the target virtual machine are all in block mapping state, and the number of virtual machines with task states in block mapping state is less than the preset maximum concurrent number, and the task state corresponding to the target virtual machine is set to block mapping state.

4. The method according to claim 1, wherein After sending the distributed lock occupation request to the preset database through the target computing node, the method further includes: When a distributed lock occupation failure message fed back by the preset database is detected, after waiting for a preset time, a distributed lock occupation request is resent to the preset database through the target computing node until a distributed lock occupation success message fed back by the preset database is detected.

5. The method according to claim 1, wherein When a request to create a target virtual machine is detected, the target compute node is obtained from a preset database table, including: When a creation request for a target virtual machine is detected, the remaining computing resources corresponding to each computing node in the preset database table are obtained; According to the remaining computing resources corresponding to each of the computing nodes, obtaining a candidate computing node corresponding to the maximum remaining computing resources from each of the computing nodes; When it is detected that the remaining computing resources corresponding to the candidate computing node meet a preset computing resource detection condition, the candidate computing node is determined as a target computing node.

6. The method according to claim 1, wherein Sending a distributed lock occupation request to a preset database through the target computing node includes: An asynchronous remote call request is sent to the target computing node, and when the target computing node receives the asynchronous remote call request, a distributed lock occupation request is sent to a preset database.

7. The method according to any one of claims 1 to 6, characterized in that The types of the preset database include key-value database and relational database.

8. A device for creating a virtual machine, characterized in that: include: A target computing node acquisition module is configured to, when a creation request for a target virtual machine is detected, acquire a target computing node from a preset database table and send a resource occupation request to the target computing node; A distributed lock occupation request sending module is used to add the target virtual machine to the virtual machine creation list when detecting that the resources of the target computing node are successfully occupied, and send a distributed lock occupation request to a preset database through the target computing node; A block mapping state setting module is used to set the task state corresponding to the target virtual machine in the virtual machine creation list to the block mapping state when a distributed lock occupation success message fed back by the preset database is detected; a target virtual machine creation module, configured to release the distributed lock occupied by the target computing node and, upon detecting that the task state corresponding to the target virtual machine has changed to a block mapping end state, delete the target virtual machine from the virtual machine creation list to complete the creation of the target virtual machine; Obtaining the target computing node from the preset database table includes: A first computing node whose remaining computing resources are greater than a preset remaining computing resource threshold is obtained from each computing node in the preset database table, and weights corresponding to the hard disk remaining space event, the central processing unit idle percentage event, and the number of historical virtual machine creation failures event are calculated based on the remaining computing resources corresponding to each first computing node; The weights are added together to obtain the total weight corresponding to each first computing node, and the target computing node is obtained based on the total weight.

9. An electronic device, characterized in that: The electronic device comprises: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method for creating a virtual machine as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for creating a virtual machine as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Virtual machine creation method and apparatus

    CN108614726A

  • Distributed lock implementation method and device and electronic equipment

    CN108897628A

  • Distributed task scheduling method and device

    CN112231073A