An internet protocol address allocation method, device, apparatus and storage medium
Patent Information
- Application Number
- CN202611087817.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-21
- Publication Date
- 2026-09-29
AI Technical Summary
[0003]有鉴于此,本发明的目的在于提供一种互联网协议地址分配方法、装置、设备及存储介质,解决了现有技术中算力实例创建过程中可用互联网协议地址判断准确性差的问题
[0015]由上述技术方案可以看出,本发明通过接收目标算力实例的创建请求;创建请求包括目标虚拟专有网络标识;分别从各实例系统中获取目标虚拟专有网络标识对应的已分配互联网协议地址列表,并进行合并得到全局已分配互联网协议地址列表;实例系统用于维护对应算力实例的互联网协议地址占用记录;基于目标虚拟专有网络标识对应的网关地址、子网掩码以及全局已分配互联网协议地址列表,确定空闲互联网协议地址列表;从空闲互联网协议地址列表中选取目标互联网协议地址,并将目标互联网协议地址分配给目标算力实例。本发明的有益效果在于:本发明通过从各实例系统获取已分配IP(InternetProtocol,互联网协议)地址并合并为全局已分配IP地址列表,使空闲IP确定能综合多系统占用情况,避免单一来源导致的地址遗漏,降低已占用IP被误判为空闲的风险;基于网关地址、子网掩码及全局已分配IP列表计算空闲IP,结合VPC(虚拟专有网络)实际网络范围,提升判断准确性;从空闲列表中选取IP分配给实例,降低同一VPC内IP重复分配风险,提高分配可靠性与实例通信稳定性。
Smart Images

Figure CN122845558A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of cloud computing distributed systems, and in particular to an Internet Protocol address allocation method, apparatus, device, and storage medium. Background Technology
[0002] In cloud computing platforms, when creating computing instances, an Internet Protocol (IP) address needs to be assigned to the instance within a specified Virtual Private Network (VPN) to ensure the instance can access the network normally. However, in the current address allocation process, inaccurate determination of available IP addresses may lead to the reassignment of already occupied IP addresses, causing IP address conflicts within the same VPN and affecting the reliability of instance communication. Therefore, improving the accuracy of determining available IP addresses during computing instance creation and reducing the risk of duplicate IP address allocation is a pressing technical problem that needs to be solved. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide an Internet Protocol address allocation method, apparatus, device and storage medium, which solves the problem of poor accuracy in determining the available Internet Protocol addresses during the creation of computing power instances in the prior art.
[0004] To solve the above-mentioned technical problems, the present invention provides an Internet Protocol address allocation method, comprising: Receive a request to create a target computing power instance; the creation request includes a target virtual private network identifier; The allocated Internet Protocol (IP) address lists corresponding to the target Virtual Private Network (VPN) identifier are obtained from each instance system and merged to obtain a global allocated IP address list; the instance system is used to maintain the IP address occupancy records of the corresponding computing power instance; Based on the gateway address and subnet mask corresponding to the target virtual private network identifier and the globally allocated Internet Protocol address list, determine the list of idle Internet Protocol addresses; Select a target Internet Protocol address from the list of available Internet Protocol addresses and assign the target Internet Protocol address to the target computing power instance.
[0005] Optionally, the allocated Internet Protocol (IP) address lists corresponding to the target Virtual Private Network (VPN) identifier are obtained from each instance system and merged to obtain a global allocated IP address list, including: Obtain the assigned Internet Protocol address of the cloud system instance corresponding to the target virtual private network identifier from the cloud system instance system; Obtain the assigned Internet Protocol address of the virtual machine instance corresponding to the target virtual private network identifier from the virtual machine instance system; The allocated Internet Protocol addresses of the cloud system instance and the allocated Internet Protocol addresses of the virtual machine instance are merged to obtain the global list of allocated Internet Protocol addresses.
[0006] Optionally, based on the gateway address and subnet mask corresponding to the target virtual private network identifier and the globally allocated Internet Protocol (IP) address list, a list of idle IP addresses is determined, including: Obtain the gateway address and the subnet mask from the cloud system instance system; The address range corresponding to the target virtual private network identifier is determined based on the gateway address and the subnet mask; The list of free Internet Protocol addresses is obtained by excluding the gateway address and the Internet Protocol addresses in the globally allocated Internet Protocol address set from the address range.
[0007] Optionally, selecting a target Internet Protocol address from the list of available Internet Protocol addresses includes: Determine the target data center area identifier corresponding to the target computing power instance; For the candidate Internet Protocol addresses in the list of available Internet Protocol addresses, generate a lock identifier that includes the target data center area identifier and the candidate Internet Protocol address; A distributed lock is obtained based on the lock identifier to determine the target Internet Protocol address.
[0008] Optionally, obtaining a distributed lock based on the lock identifier to determine the target Internet Protocol address includes: According to the order of Internet protocol addresses in the list of available Internet protocol addresses, a distributed lock is acquired sequentially for each candidate Internet protocol address in the list of available Internet protocol addresses. If the distributed lock for the current candidate Internet Protocol address is successfully acquired, then the current candidate Internet Protocol address is determined as the target Internet Protocol address, and the traversal stops. If the acquisition of the distributed lock for the current candidate Internet Protocol address fails, the process continues to acquire the distributed lock for the next candidate Internet Protocol address.
[0009] Optional, also includes: If the distributed lock is not successfully acquired for any of the candidate Internet Protocol addresses in the list of idle Internet Protocol addresses, an address resource unavailable exception message is generated. Accordingly, after selecting a target Internet Protocol address from the list of available Internet Protocol addresses, or after generating the address resource unavailable exception information, the acquired distributed lock is released.
[0010] Optionally, after assigning the target Internet Protocol address to the target computing power instance, the method further includes: Store the target computing instance information carrying the target Internet Protocol address in the local transaction; After the local transaction is committed, an external system is invoked to create or schedule the target computing power instance; If the call to the external system fails, the target computing instance information is marked as logically deleted in a new transaction, and a release event is published to release the target Internet Protocol address.
[0011] The present invention also provides an Internet Protocol address allocation device, comprising: A receiving module is used to receive a creation request for a target computing power instance; the creation request includes a target virtual private network identifier; The merging module is used to obtain the list of allocated Internet Protocol addresses corresponding to the target Virtual Private Network identifier from each instance system, and merge them to obtain a global list of allocated Internet Protocol addresses; the instance system is used to maintain the Internet Protocol address occupancy record of the corresponding computing power instance; The determination module is used to determine the list of idle Internet Protocol addresses based on the gateway address and subnet mask corresponding to the target virtual private network identifier and the globally allocated Internet Protocol address list. The allocation module is used to select a target Internet Protocol address from the list of idle Internet Protocol addresses and allocate the target Internet Protocol address to the target computing power instance.
[0012] The present invention also provides an Internet Protocol address allocation device, comprising: Memory, used to store computer programs; A processor, used to implement the Internet Protocol address allocation method as described above when executing the computer program.
[0013] The present invention also provides a computer-readable storage medium storing computer-executable instructions, which, when loaded and executed by a processor, implement the Internet Protocol address allocation method as described above.
[0014] The present invention also provides a computer program product, including a computer program / instruction that, when executed by a processor, implements the steps of the Internet Protocol address allocation method described above.
[0015] As can be seen from the above technical solution, the present invention receives a creation request for a target computing power instance; the creation request includes a target virtual private network identifier; obtains the allocated Internet Protocol (IP) address list corresponding to the target IP address from each instance system, and merges them to obtain a global allocated IP address list; the instance system is used to maintain the IP address occupancy record of the corresponding computing power instance; based on the gateway address, subnet mask, and global allocated IP address list corresponding to the target IP address, a list of idle IP addresses is determined; a target IP address is selected from the list of idle IP addresses, and the target IP address is allocated to the target computing power instance. The beneficial effects of this invention are as follows: By obtaining allocated IP (Internet Protocol) addresses from each instance system and merging them into a global allocated IP address list, this invention enables the determination of idle IPs to comprehensively consider the occupancy status of multiple systems, avoiding address omissions caused by a single source and reducing the risk of occupied IPs being misjudged as idle; by calculating idle IPs based on gateway addresses, subnet masks, and the global allocated IP list, and combining this with the actual network range of the VPC (Virtual Private Network), the accuracy of the judgment is improved; by selecting IPs from the idle list and allocating them to instances, the risk of duplicate IP allocation within the same VPC is reduced, improving allocation reliability and instance communication stability.
[0016] In addition, the present invention also provides an Internet Protocol address allocation device, equipment and storage medium, which also have the above-mentioned beneficial effects. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0018] Figure 1 A flowchart illustrating an Internet Protocol address allocation method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of an Internet Protocol address allocation device provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of an Internet Protocol address allocation device provided in an embodiment of the present invention. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] Please refer to Figure 1 , Figure 1 A flowchart illustrating an Internet Protocol address allocation method provided in an embodiment of the present invention. The method may include: S101: Receive the creation request for the target computing instance; the creation request includes the target virtual private network identifier.
[0021] It should be noted that this method can be executed by a server, cloud platform management node, or other electronic devices with computing and communication capabilities, and no specific limitations are made here. In this embodiment, allocated Internet Protocol addresses, used Internet Protocol addresses, and occupied Internet Protocol addresses can be used interchangeably without ambiguity.
[0022] In this embodiment, the target computing instance is not specifically limited. For example, the computing instance can be a Cloud System Instance (COSI), a Virtual Machine Instance (VMI), or other computing resource instances that need to be bound to an Internet Protocol address in a Virtual Private Network (VPN). This embodiment also does not specifically limit the creation request. For example, the creation request can carry a target VPN identifier, as well as information such as a data center identifier, target data center region identifier, tenant identifier, contract identifier, and instance specifications. The target VPN identifier is used to determine the address space required for this creation process.
[0023] S102: Obtain the list of allocated Internet Protocol addresses corresponding to the target Virtual Private Network identifier from each instance system, and merge them to obtain a global list of allocated Internet Protocol addresses; the instance system is used to maintain the Internet Protocol address occupancy record of the corresponding computing power instance.
[0024] Since different instance systems may be maintained by different services and return address occupancy records through different interfaces, this embodiment aggregates records from multiple sources before address selection, rather than directly using address records from a single system as the total occupancy status of the target virtual private network. In this embodiment, the instance system can be a system used to maintain address occupancy records for one or more types of computing power instances, such as a cloud system instance system and a virtual machine instance system, or other systems. In specific implementation, the address selection component can call the query interfaces of multiple instance systems respectively to obtain the list of allocated Internet Protocol addresses under the target virtual private network identifier.
[0025] S103: Determine the list of idle Internet Protocol addresses based on the gateway address, subnet mask, and globally allocated Internet Protocol address list corresponding to the target Virtual Private Network identifier.
[0026] In this embodiment, the address range is determined based on the network configuration parameters of the target virtual private network (VPN). This address range determination process reflects the network segment boundaries of the target VPN and excludes unassignable and assigned addresses from this range, thereby obtaining a list of free Internet Protocol (IP) addresses. Unassignable addresses may include gateway addresses, and assigned addresses may include IP addresses from the globally allocated IP address set. This embodiment does not specifically limit the method of obtaining the gateway address and subnet mask. For example, the gateway address and subnet mask can be obtained from the cloud system instance system, or they can be obtained separately from the network configuration system or database. Then, the address range corresponding to the target VPN identifier is determined based on the gateway address and subnet mask.
[0027] S104: Select a target Internet Protocol address from the list of available Internet Protocol addresses and assign the target Internet Protocol address to the target computing instance.
[0028] This embodiment does not specifically limit the selection process of the target Internet Protocol (IP) address. For example, the target IP address can be selected from the list of idle IP addresses according to a preset load balancing strategy; or, a distributed lock mechanism can be used to perform concurrent and mutually exclusive selection of candidate IP addresses in the list of idle IP addresses to determine the target IP address.
[0029] The present invention provides an Internet Protocol (IP) address allocation method, which includes the following steps: S101: Receiving a creation request for a target computing power instance; the creation request includes a target Virtual Private Network (VPN) identifier; S102: Obtaining the allocated IP address lists corresponding to the target VPN identifier from each instance system, and merging them to obtain a global allocated IP address list; the instance system is used to maintain the IP address occupancy records of the corresponding computing power instance; S103: Determining a list of idle IP addresses based on the gateway address, subnet mask, and global allocated IP address list corresponding to the target VPN identifier; S104: Selecting a target IP address from the list of idle IP addresses and allocating the target IP address to the target computing power instance. It is evident that in a cloud computing power platform, an IP address within the same VPN may simultaneously serve cloud system instances, virtual machine instances, or other computing power instances; the address occupancy records of various instances may be scattered across different instance systems. This embodiment obtains allocated IP (Internet Protocol) addresses from each instance system and merges them into a global allocated IP address list. This allows for the determination of free IPs to take into account the occupancy status of multiple systems, avoiding address omissions due to a single source and reducing the risk of occupied IPs being misjudged as free. Free IPs are calculated based on the gateway address, subnet mask, and global allocated IP list, combined with the actual network range of the VPC, to improve the accuracy of the judgment. IPs are selected from the free list and allocated to instances, reducing the risk of duplicate IP allocation within the same VPC and improving allocation reliability and instance communication stability.
[0030] Based on the above embodiments, this embodiment further explains the merging process of the globally allocated Internet Protocol address list. Specifically, obtaining the allocated Internet Protocol address lists corresponding to the target Virtual Private Network (VPN) identifier from each instance system and merging them to obtain the globally allocated Internet Protocol address list may include: obtaining the allocated Internet Protocol addresses of the cloud system instance corresponding to the target VPN identifier from the cloud system instance system; obtaining the allocated Internet Protocol addresses of the virtual machine instance corresponding to the target VPN identifier from the virtual machine instance system; and merging the allocated Internet Protocol addresses of the cloud system instance and the allocated Internet Protocol addresses of the virtual machine instance to obtain the globally allocated Internet Protocol address list.
[0031] It should be noted that this embodiment is not limited to two instance systems: the cloud system instance system and the virtual machine instance system. When other instance systems exist on the cloud platform, the allocated Internet Protocol addresses from these other instances can also be obtained and added to the global list. This embodiment can call the cloud system instance system interface to obtain the allocated Internet Protocol addresses of the cloud system instance, or it can call the virtual machine instance system interface to obtain the allocated Internet Protocol addresses of the virtual machine instance. Specifically, the address selection component (IpChooser component) can call OsiGateway.getUsedIps(dccId, regionId, vpcId) to obtain the list of COSI addresses allocated to the cloud system instance system's OSI under the target virtual private network; it can also call VmiGateway.getUsedIps(dccId, regionId, vpcId) to obtain the list of VMI addresses bound to the virtual machine instance system's VMI under the target virtual private network; finally, the global list of allocated Internet Protocol addresses can be obtained through collection merging methods such as usedOsiIps.addAll(usedVmiIps).
[0032] As can be seen, in scenarios where cloud system instances and virtual machine instances share the same virtual private network address space, the cloud system instance system and the virtual machine instance system may maintain address occupancy records for their respective instance types, and their data models and query interfaces may differ. This embodiment no longer relies on address occupancy records from a single source, but instead comprehensively considers the Internet Protocol addresses already allocated in multiple instance systems, thereby reducing the risk of omissions caused by the dispersion of address occupancy records between systems.
[0033] Based on the above embodiments, this embodiment further explains the process of determining the list of idle Internet Protocol (IP) addresses. The determination of the list of idle IP addresses based on the gateway address, subnet mask, and globally allocated IP address list corresponding to the target Virtual Private Network (VPN) identifier may specifically include: obtaining the gateway address and subnet mask from the cloud system instance system; determining the address range corresponding to the target VPN identifier based on the gateway address and subnet mask; excluding the gateway address and the IP addresses in the globally allocated IP address set from the address range to obtain the list of idle IP addresses.
[0034] It should be noted that `OsiGateway.getUsedIps(dccId, regionId, vpcId)` can return the list of OSI-assigned Internet Protocol (IP) addresses, as well as the VPC gateway address and subnet mask; alternatively, the gateway and subnet mask can be obtained through separate interfaces. Calling `IPUtils.chooseIdleIps("gateway", "subnetMask", merged global list of assigned IP addresses)` will calculate the available IP addresses within the network segment, excluding gateway and assigned addresses.
[0035] Compared to the method of generating the address list by simple arithmetic based solely on the starting address and number, this embodiment determines the address range of the target virtual private network by combining the gateway address and subnet mask, and excludes occupied addresses based on the globally allocated Internet Protocol address set. This makes the calculation of the free address list both consistent with the actual network range and able to perceive the address occupancy of multiple systems, thereby improving the accuracy of available address judgment.
[0036] Based on the above embodiments, this embodiment further explains the process of selecting the target Internet Protocol address. To avoid multiple requests selecting the same Internet Protocol address simultaneously in concurrent creation scenarios, the selection of the target Internet Protocol address from the list of available Internet Protocol addresses may specifically include: determining the target data center region identifier corresponding to the target computing power instance; generating a lock identifier containing the target data center region identifier and the candidate Internet Protocol address for the candidate Internet Protocol addresses in the list of available Internet Protocol addresses; and acquiring a distributed lock based on the lock identifier to determine the target Internet Protocol address.
[0037] It should be noted that the lock identifier in this embodiment is not based on the granularity of the entire instance creation process, nor is it based solely on the target virtual private network identifier. Instead, it uses a combination of the target data center area identifier and the specific candidate Internet Protocol (IP) address. This is because in scenarios involving batch creation or multiple creation requests arriving in parallel, different requests may select from the same candidate IP address within the same list of available addresses. In other words, the same IP address may exist in different data center areas. If the mutual exclusion scope does not match the address resource granularity, the creation process for different addresses may be unnecessarily delayed, or the same address may be simultaneously occupied and judged by multiple requests within a short period. Therefore, this embodiment uses both the target data center area identifier and the candidate IP address to define the lock identifier, ensuring that the mutual exclusion object corresponds to the actual resource unit where address contention occurs. This improves the consistency between the lock granularity and the actual resource contention granularity.
[0038] By applying this embodiment, by generating lock identifiers with the target data center area identifier and candidate Internet Protocol addresses as the granularity, the lock granularity can be made consistent with the actual address contention granularity. This avoids both erroneous mutual exclusion between the same addresses in different data center areas and global serialization between different addresses in the same data center area, thus balancing concurrency capabilities and address allocation security.
[0039] Based on the above embodiments, this embodiment further explains the process of determining the target Internet Protocol address. The process of obtaining a distributed lock based on a lock identifier to determine the target Internet Protocol address specifically includes: acquiring a distributed lock for each candidate Internet Protocol address in the list of available Internet Protocol addresses in the order of the Internet Protocol addresses in the list of available Internet Protocol addresses; if the distributed lock for the current candidate Internet Protocol address is successfully acquired, then the current candidate Internet Protocol address is determined as the target Internet Protocol address, and the traversal stops; if the distributed lock for the current candidate Internet Protocol address fails to be acquired, then the process continues to acquire a distributed lock for the next candidate Internet Protocol address.
[0040] It should be noted that when multiple creation requests simultaneously apply for addresses from the same Virtual Private Network (VPN), if an address conflict is only discovered during the database write phase, subsequent requests may need to re-execute a lengthy creation process. Therefore, this embodiment attempts to lock candidate addresses during the candidate address selection phase and, if locking fails, sequentially yields to the next candidate address, thereby reducing the probability of repeatedly selecting the same address during the address selection phase. Specifically, the address selection component can process candidate Internet Protocol (IP) addresses sequentially according to the order of addresses in the list of available IP addresses. For the current candidate IP address, the address selection component can determine the target data center region identifier corresponding to the target computing instance and generate a lock identifier containing the target data center region identifier and the current candidate IP address. For example, the lock identifier can be "Lock:Instance:ChoosingIp:{regionId}_{ip}", where regionId represents the target data center region identifier and ip represents the candidate IP address. When a distributed lock is successfully acquired based on this lock identifier, it indicates that the current candidate IP address can be occupied by the current creation request in this concurrent contention, and therefore the current candidate IP address can be determined as the target IP address, and further traversal stops. If acquiring the distributed lock based on the lock identifier fails, it indicates that the current candidate Internet Protocol address is being processed by another concurrent request. The current creation request can automatically yield to the next candidate Internet Protocol address, and the distributed lock can be acquired sequentially for each candidate IP (globalLock.tryLock). In practical applications, distributed locks can be configured with expiration times to reduce the risk of locks being held for extended periods under abnormal circumstances. For example, in cloud system instance creation scenarios, the expiration time of the distributed lock can be set to 30 seconds; in virtual machine instance creation scenarios, the expiration time can be set to 10 seconds. The above values are merely examples and do not constitute a limitation on the scope of protection of this invention.
[0041] By applying this embodiment, through the above-described distributed lock selection process, creation requests competing for different Internet Protocol addresses can be executed concurrently, with mutual exclusion and yielding only occurring when competing for the same Internet Protocol address, thus balancing concurrent processing capabilities and address allocation reliability.
[0042] Based on the above embodiments, the method may further include: if the distributed lock is not successfully acquired for each candidate Internet Protocol address in the list of idle Internet Protocol addresses, an address resource unavailable exception message is generated; correspondingly, after selecting a target Internet Protocol address from the list of idle Internet Protocol addresses, or after generating the address resource unavailable exception message, the acquired distributed lock is released.
[0043] In this embodiment, if the distributed lock is not successfully acquired after traversing all candidate Internet Protocol addresses in the list of idle Internet Protocol addresses, an exception message indicating that the address resource is unavailable is generated. In high-concurrency creation scenarios, each candidate Internet Protocol address may be in a state where it is temporarily locked by other requests. In this case, continuing to retain the lock already acquired by the current request or continuing the subsequent creation process may cause inconsistencies between the address resource state and the creation state. Therefore, this embodiment, after generating the exception message indicating that the address resource is unavailable, performs lock release processing to enable subsequent requests to be processed again based on the new address contention state.
[0044] By applying this embodiment, generating anomaly information when a distributed lock cannot be obtained for all candidate Internet Protocol addresses, and releasing the acquired distributed lock after the address is determined or after the anomaly is generated, the risk of candidate addresses being unavailable for a long time due to lock resource leakage can be reduced, and the creation of link resources can be avoided if an available address is not determined, thereby improving the recoverability and stability of the concurrent address allocation process.
[0045] Based on the above embodiments, after allocating the target Internet Protocol address to the target computing power instance, the method may further include: storing the target computing power instance information carrying the target Internet Protocol address in a local transaction; after the local transaction is committed, calling an external system to create or schedule the target computing power instance; if the call to the external system fails, marking the target computing power instance information as logically deleted in a new transaction, and publishing a release event for releasing the target Internet Protocol address.
[0046] It should be noted that in this type of cross-system creation scenario, local database persistence and external system RPC calls may be completed by different systems. If the local instance information has been submitted but the external system has not completed creation or scheduling, a recorded but unconfigured instance state may be formed, causing the corresponding Internet Protocol address to remain occupied on the local side. Therefore, this embodiment marks logical deletion and publishes a release event in a new transaction, enabling the address to be released or participate in allocation in subsequent processes. Specifically, the target computing power instance information may include instance identifier, target virtual private network identifier, target data center area identifier, target Internet Protocol address, tenant identifier, instance status, etc. After the local transaction is submitted, the external system can be called outside the transaction to create or schedule the target computing power instance. For example, in the cloud system instance creation scenario, the cloud system instance system can be called to create the cloud system instance; in the virtual machine instance creation scenario, the media access control address can be obtained first, and then the virtual machine scheduling system can be called to create or schedule the virtual machine instance. After the external system call is successful, the configuration state can be persisted or the instance creation state can be updated again in the local transaction. If the external system call fails, compensation processing can be performed in a new transaction. Compensation processing may include marking the target computing instance information as logically deleted and publishing a release event to release the target Internet Protocol address. Because the compensation transaction is independent of the previous creation transaction, the logical deletion and release event can reduce the occupancy of address resources by invalid records, even if external system calls fail.
[0047] Applying this embodiment, the out-of-transaction call and failure compensation mechanism is applicable to cross-system creation scenarios without distributed transaction coordination, and can provide eventual consistency guarantees when the local database and external system states are inconsistent.
[0048] In a comprehensive application example, tenant contract 1000 creates a COSI in data center A with regionId 10, vpcId 50, gateway address 10.0.0.1, and subnet mask 255.255.255.0 (network segment 10.0.0.0 / 24). `OsiGateway.getUsedIps()` returns the OSI allocated address [10.0.0.10, 10.0.0.20], and `VmiGateway.getUsedIps()` returns the VMI allocated address [10.0.0.15]. After merging, the system obtains the globally allocated address [10.0.0.10, 10.0.0.20, 10.0.0.15], and then calls `IPUtils.chooseIdleIps()` to calculate the list of free addresses excluding the gateway address and allocated addresses.
[0049] During the address selection phase, the system iterates through the list of free addresses sequentially. For candidate address 10.0.0.2, a lock identifier "Lock:Instance:ChoosingIp:10_10.0.0.2" is generated. If globalLock.tryLock is successfully acquired, the address is bound to the target computing instance and the iteration ends; if acquisition fails, the system continues to try the next candidate address 10.0.0.3. Regardless of whether subsequent external system calls are successful, the acquired distributed lock is released in the finally block. In one concurrent processing example, the idle IPs corresponding to the three concurrent requests are [10.0.0.2, 10.0.0.3, 10.0.0.4]. Request A successfully acquires a lock on 10.0.0.2; Request B fails to acquire a lock on 10.0.0.2 but backs down to 10.0.0.3 and successfully acquires a lock there; Request C fails to acquire locks on both 10.0.0.2 and 10.0.0.3 but backs down to 10.0.0.4 and successfully acquires a lock there. Thus, multiple create requests can be processed in parallel on different candidate addresses, only mutually exclusive waiting or backing down occurs when contention arises for the same candidate address.
[0050] During the compensation phase, if the local transaction has already saved the instance metadata carrying the target Internet Protocol address, but `OsiGateway.createOsi()` fails due to a network timeout, the `catch` block marks the instance as logically deleted (`isDelete=DELETED`, operator "sys") in a new, independent transaction and publishes a release event to release the target Internet Protocol address. Thus, although a distributed transaction coordinator is not used, eventual consistency can be achieved through compensation soft deletion and release events. Specifically, the compensation transaction is isolated from the creation transaction; the compensation process does not roll back the committed creation transaction, but instead records the logical deletion status and triggers the release event within the new transaction boundary. The distributed lock is released in the `finally` block, allowing the corresponding Internet Protocol address to be reselected by subsequent creation requests after compensation is completed or the lock is released.
[0051] In another comprehensive application example, if the target computing instance is a VMI, after the local transaction is committed, the MAC address can be obtained first via `vmiMacAddressPool.getMacAddress()`, and then `VmSchedulerGateway.createVmScheduler()` can be called to create the virtual machine for scheduling. If the virtual machine scheduling system call fails, the local instance information can be logically deleted and a release event can be published in a new transaction so that subsequent requests can reuse the Internet Protocol address.
[0052] The Internet Protocol address allocation device provided in the embodiments of the present invention will be described below. The Internet Protocol address allocation device described below can be referred to in correspondence with the Internet Protocol address allocation method described above.
[0053] Please refer to the details. Figure 2 , Figure 2 A schematic diagram of an Internet Protocol address allocation device provided in an embodiment of the present invention may include: The receiving module 100 is used to receive a creation request for a target computing power instance; the creation request includes a target virtual private network identifier; The merging module 200 is used to obtain the list of allocated Internet Protocol addresses corresponding to the target virtual private network identifier from each instance system, and merge them to obtain a global list of allocated Internet Protocol addresses; the instance system is used to maintain the Internet Protocol address occupancy record of the corresponding computing power instance; The determination module 300 is used to determine the list of idle Internet Protocol addresses based on the gateway address and subnet mask corresponding to the target virtual private network identifier and the globally allocated Internet Protocol address list. The allocation module 400 is used to select a target Internet Protocol address from the list of idle Internet Protocol addresses and allocate the target Internet Protocol address to the target computing power instance.
[0054] Furthermore, based on the above embodiments, the merging module 200 may include: The first address acquisition unit is used to obtain the allocated Internet Protocol address of the cloud system instance corresponding to the target virtual private network identifier from the cloud system instance system. The second address acquisition unit is used to obtain the allocated Internet Protocol address of the virtual machine instance corresponding to the target virtual private network identifier from the virtual machine instance system. The merging unit is used to merge the Internet Protocol addresses allocated to the cloud system instance and the Internet Protocol addresses allocated to the virtual machine instance to obtain the global list of allocated Internet Protocol addresses.
[0055] Furthermore, based on the above embodiments, the determining module 300 may include: The acquisition unit is used to obtain the gateway address and the subnet mask from the cloud system instance system; The address range determination unit is used to determine the address range corresponding to the target virtual private network identifier based on the gateway address and the subnet mask. The free list determination unit is used to exclude the gateway address and the Internet Protocol address in the globally allocated Internet Protocol address set from the address range to obtain the free Internet Protocol address list.
[0056] Furthermore, based on the above embodiments, the allocation module 400 may include: A region identifier determination unit is used to determine the target data center region identifier corresponding to the target computing power instance; The lock identifier generation unit is used to generate a lock identifier containing the target data center area identifier and the candidate Internet Protocol address from the list of available Internet Protocol addresses. The target address determination unit is used to obtain a distributed lock based on the lock identifier in order to determine the target Internet Protocol address.
[0057] Furthermore, based on the above embodiments, the target address determination unit may include: An attempt is made to acquire a subunit, which is used to acquire a distributed lock for each candidate Internet Protocol address in the list of idle Internet Protocol addresses in the order of Internet Protocol addresses in the list of idle Internet Protocol addresses. The target address determination subunit is used to determine the current candidate Internet Protocol address as the target Internet Protocol address and stop traversing if the distributed lock for the current candidate Internet Protocol address is successfully acquired. Traverse the sub-units to continue acquiring the distributed lock for the next candidate Internet Protocol address if the acquisition of the distributed lock for the current candidate Internet Protocol address fails.
[0058] Furthermore, based on the above embodiments, the Internet Protocol address allocation device may further include: The exception information generation module is used to generate an address resource unavailable exception if the distributed lock is not successfully acquired for each candidate Internet Protocol address in the list of idle Internet Protocol addresses; accordingly, after selecting a target Internet Protocol address from the list of idle Internet Protocol addresses, or after generating the address resource unavailable exception information, the acquired distributed lock is released.
[0059] Furthermore, based on any of the above embodiments, the Internet Protocol address allocation device may further include: The storage module is used to store the target computing instance information carrying the target Internet Protocol address in a local transaction after the target Internet Protocol address is assigned to the target computing instance. The calling module is used to call an external system to create or schedule the target computing power instance after the local transaction is committed; The deletion and release module is used to mark the target computing power instance information as logically deleted in a new transaction and publish a release event for releasing the target Internet Protocol address if the call to the external system fails.
[0060] It should be noted that the order of the modules and units in the aforementioned Internet Protocol address allocation device can be changed without affecting the logic.
[0061] An Internet Protocol address allocation device provided in this embodiment of the invention includes a receiving module 100 for receiving a creation request for a target computing power instance, the creation request including a target Virtual Private Network (VPN) identifier; a merging module 200 for obtaining the allocated Internet Protocol address lists corresponding to the target VPN identifier from each instance system and merging them to obtain a global allocated Internet Protocol address list; the instance system is used to maintain Internet Protocol address occupancy records for the corresponding computing power instance; a determining module 300 for determining a list of idle Internet Protocol addresses based on the gateway address, subnet mask, and the global allocated Internet Protocol address list corresponding to the target VPN identifier; and an allocation module 400 for selecting a target Internet Protocol address from the list of idle Internet Protocol addresses and allocating the target Internet Protocol address to the target computing power instance. This device obtains allocated IP (Internet Protocol) addresses from each instance system and merges them into a global list of allocated IP addresses. This allows for the determination of free IPs by comprehensively considering the occupancy status of multiple systems, avoiding address omissions due to a single source, and reducing the risk of occupied IPs being mistakenly identified as free. Free IPs are calculated based on the gateway address, subnet mask, and the global list of allocated IPs. Combined with the actual network range of the VPC (Virtual Private Cloud), the accuracy of the judgment is improved. IPs are selected from the free list and allocated to instances, reducing the risk of duplicate IP allocation within the same VPC and improving allocation reliability and instance communication stability.
[0062] The Internet Protocol address allocation device provided in the embodiments of the present invention will be described below. The Internet Protocol address allocation device described below can be referred to in correspondence with the Internet Protocol address allocation method described above.
[0063] Please refer to Figure 3 , Figure 3 A schematic diagram of the structure of an Internet Protocol address allocation device provided in an embodiment of the present invention may include: Memory 10 is used to store computer programs; Processor 20 is used to execute computer programs to implement the Internet Protocol address allocation method described above.
[0064] The memory 10, processor 20, and communication interface 31 all communicate with each other through the communication bus 32.
[0065] In this embodiment of the invention, the memory 10 is used to store one or more programs. The programs may include program code, which includes computer operation instructions. In this embodiment of the invention, the memory 10 may store programs for implementing the following functions: Receive a request to create a target computing instance; the creation request includes the target virtual private network identifier; The allocated Internet Protocol (IP) address lists corresponding to the target Virtual Private Network (VPN) identifiers are obtained from each instance system and then merged to obtain a global allocated IP address list; the instance system is used to maintain the IP address occupancy records of the corresponding computing power instance. Based on the gateway address, subnet mask, and globally allocated Internet Protocol address list corresponding to the target Virtual Private Network identifier, determine the list of idle Internet Protocol addresses; Select the target Internet Protocol address from the list of available Internet Protocol addresses and assign the target Internet Protocol address to the target computing instance.
[0066] In one possible implementation, the memory 10 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; and the data storage area may store data created during use.
[0067] Furthermore, memory 10 may include read-only memory and random access memory, providing instructions and data to the processor. A portion of the memory may also include NVRAM. The memory stores operating systems and operating instructions, executable modules, or data structures, or subsets thereof, or extended sets thereof, wherein the operating instructions may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic tasks and handling hardware-based tasks.
[0068] Processor 20 can be a central processing unit (CPU), an application-specific integrated circuit, a digital signal processor, a field-programmable gate array, or other programmable logic device. Processor 20 can be a microprocessor or any conventional processor. Processor 20 can call programs stored in memory 10.
[0069] Communication interface 31 can be an interface for the communication module, used to connect with other devices or systems.
[0070] Of course, it should be noted that, Figure 3 The structure shown does not constitute a limitation on the Internet Protocol address allocation device in the embodiments of the present invention. In practical applications, the Internet Protocol address allocation device may include devices such as... Figure 3More or fewer components as shown, or combinations of certain components.
[0071] It is understood that if the Internet Protocol address allocation method in the above embodiments is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the current technology, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods in the various embodiments of the present invention. The aforementioned storage medium includes: USB flash drive, mobile hard drive, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk or optical disk, and other media capable of storing program code.
[0072] Based on this, embodiments of the present invention also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the Internet Protocol address allocation method described above.
[0073] The following describes a computer program product provided by an embodiment of this application. The computer program product described below can be referred to in conjunction with other embodiments described herein.
[0074] A computer program product includes a computer program / instructions that, when executed by a processor, implement the steps of the aforementioned disclosed Internet Protocol address allocation method.
[0075] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0076] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0077] Finally, it should be noted that in this document, relationships such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0078] The present invention provides a detailed description of an Internet Protocol address allocation method, apparatus, device, and computer-readable storage medium. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. An Internet Protocol address allocation method, characterized by, include: Receive the request to create the target computing power instance; The creation request includes the target virtual private network identifier; The allocated Internet Protocol (IP) address lists corresponding to the target Virtual Private Network (VPN) identifier are obtained from each instance system and merged to obtain a global allocated IP address list; the instance system is used to maintain the IP address occupancy records of the corresponding computing power instance; Based on the gateway address and subnet mask corresponding to the target virtual private network identifier and the globally allocated Internet Protocol address list, determine the list of idle Internet Protocol addresses; Select a target Internet Protocol address from the list of available Internet Protocol addresses and assign the target Internet Protocol address to the target computing power instance.
2. The Internet Protocol address allocation method of claim 1, wherein, The allocated Internet Protocol (IP) address lists corresponding to the target Virtual Private Network (VPN) identifier are obtained from each instance system and merged to obtain a global allocated IP address list, including: Obtain the assigned Internet Protocol address of the cloud system instance corresponding to the target virtual private network identifier from the cloud system instance system; Obtain the assigned Internet Protocol address of the virtual machine instance corresponding to the target virtual private network identifier from the virtual machine instance system; The allocated Internet Protocol addresses of the cloud system instance and the allocated Internet Protocol addresses of the virtual machine instance are merged to obtain the global list of allocated Internet Protocol addresses.
3. The Internet Protocol address allocation method of claim 1, wherein, Based on the gateway address and subnet mask corresponding to the target virtual private network identifier, and the globally allocated Internet Protocol (IP) address list, a list of idle IP addresses is determined, including: Obtain the gateway address and the subnet mask from the cloud system instance system; The address range corresponding to the target virtual private network identifier is determined based on the gateway address and the subnet mask; The list of free Internet Protocol addresses is obtained by excluding the gateway address and the Internet Protocol addresses in the globally allocated Internet Protocol address set from the address range.
4. The Internet Protocol address allocation method of claim 1, wherein, Selecting a target Internet Protocol address from the list of available Internet Protocol addresses includes: Determine the target data center area identifier corresponding to the target computing power instance; For the candidate Internet Protocol addresses in the list of available Internet Protocol addresses, generate a lock identifier that includes the target data center area identifier and the candidate Internet Protocol address; A distributed lock is obtained based on the lock identifier to determine the target Internet Protocol address.
5. The Internet Protocol address allocation method according to claim 4, characterized in that, Obtaining a distributed lock based on the lock identifier to determine the target Internet Protocol address includes: According to the order of Internet protocol addresses in the list of available Internet protocol addresses, a distributed lock is acquired sequentially for each candidate Internet protocol address in the list of available Internet protocol addresses; If the distributed lock for the current candidate Internet Protocol address is successfully acquired, then the current candidate Internet Protocol address is determined as the target Internet Protocol address, and the traversal stops. If the acquisition of the distributed lock for the current candidate Internet Protocol address fails, the process continues to acquire the distributed lock for the next candidate Internet Protocol address.
6. The Internet Protocol address allocation method according to claim 5, characterized in that, Also includes: If the distributed lock is not successfully acquired for any of the candidate Internet Protocol addresses in the list of idle Internet Protocol addresses, an address resource unavailable exception message is generated. Accordingly, after selecting a target Internet Protocol address from the list of available Internet Protocol addresses, or after generating the address resource unavailable exception information, the acquired distributed lock is released.
7. The Internet Protocol address allocation method according to any one of claims 1 to 6, characterized in that, After assigning the target Internet Protocol address to the target computing power instance, the method further includes: Store the target computing instance information carrying the target Internet Protocol address in the local transaction; After the local transaction is committed, an external system is invoked to create or schedule the target computing power instance; If the call to the external system fails, the target computing instance information is marked as logically deleted in a new transaction, and a release event is published to release the target Internet Protocol address.
8. An Internet Protocol address allocation device, characterized in that, include: The receiving module is used to receive the creation request of the target computing power instance; The creation request includes the target virtual private network identifier; The merging module is used to obtain the list of allocated Internet Protocol addresses corresponding to the target Virtual Private Network identifier from each instance system, and merge them to obtain a global list of allocated Internet Protocol addresses; the instance system is used to maintain the Internet Protocol address occupancy record of the corresponding computing power instance; The determination module is used to determine the list of idle Internet Protocol addresses based on the gateway address and subnet mask corresponding to the target virtual private network identifier and the globally allocated Internet Protocol address list. The allocation module is used to select a target Internet Protocol address from the list of idle Internet Protocol addresses and allocate the target Internet Protocol address to the target computing power instance.
9. An Internet Protocol address allocation device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the Internet Protocol address allocation method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when loaded and executed by a processor, implement the Internet Protocol address allocation method as described in any one of claims 1 to 7.