Network address allocation method and device, equipment and medium

By adopting a multi-level cache architecture in the network address allocation system, the problem of poor performance in the existing technology in high concurrency scenarios is solved, efficient and reliable network address allocation is achieved, and complex CIDR address block allocation is supported.

CN120223674APending Publication Date: 2025-06-27BEIJING VOLCANO ENGINE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510435611.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-08
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

The existing network address allocation technology has poor performance in high concurrency scenarios, resulting in database deadlocks and resource overhead, and it is difficult to allocate IP addresses and small CIDR address blocks at the same time from large CIDR address blocks.

Method used

Adopting a multi-level cache architecture, the first-level cache stores the currently allocable network address, and the second-level cache stores the preset CIDR address block and marks whether the IP address has been allocated. After receiving the address allocation request, the network address is preferred from the first-level cache, and if it is insufficient, the unallocated network address is obtained from the second-level cache.

Benefits of technology

It significantly improves the performance and efficiency of network address allocation, reduces dependence on the database, avoids the problems of database deadlock and resource overhead, and supports the allocation of IP addresses and small CIDR address blocks from large CIDR address blocks at the same time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120223674A_ABST
    Figure CN120223674A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to a network address allocation method and device, equipment and a medium, and the method comprises the steps: responding to a received address allocation request, and preferentially obtaining a first network address from a first-stage cache in a multi-stage cache architecture based on the address allocation request; the multi-level cache architecture at least comprises a first-level cache and a second-level cache; under the condition that the number of the first network addresses does not meet the address allocation request, determining the number of network addresses needing to be acquired from the second-level cache, and acquiring second network addresses which are not allocated currently from the second-level cache until the number of the second network addresses reaches the number of the network addresses; and taking the first network address and the second network address as target network addresses required by the address allocation request, and responding to the address allocation request. According to the embodiment of the invention, the network address allocation performance can be remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technologies, and in particular, to a network address allocation method, apparatus, device, and medium. Background Art

[0002] In elastic batch creation scenarios such as ECS (Elastic Compute Service) and cloud native, or other business scenarios, it is necessary to allocate IP (Internet Protocol) addresses, and in some scenarios, it may also be necessary to allocate CIDR (Classless Inter-Domain Routing) address blocks. The inventor has found through research that with the continuous development of cloud network control technologies, network address allocation technologies have become the main bottleneck restricting the performance of the above scenarios. Existing network address allocation technologies have problems such as poor performance. Therefore, there is an urgent need for a new network address allocation technology currently. Summary of the Invention

[0003] To solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a network address allocation method, apparatus, device, and medium.

[0004] An embodiment of the present disclosure provides a network address allocation method, the method including: in response to receiving an address allocation request, preferentially obtaining a first network address from a primary cache in a multi-level cache architecture based on the address allocation request; wherein, the address allocation request is used to request allocation of an available target network address, the multi-level cache architecture at least includes a primary cache and a secondary cache; the primary cache is used to store currently allocable network addresses; the secondary cache is used to store a preset first Classless Inter-Domain Routing (CIDR) address block, and each IP address included in the first CIDR address block in the secondary cache is marked with whether it has been currently allocated; in a case where the number of the first network addresses does not meet the address allocation request, determining the number of network addresses to be obtained from the secondary cache, and obtaining a second network address that has not been currently allocated from the secondary cache until the number of the second network addresses reaches the number of network addresses; using the first network address and the second network address as the target network address required by the address allocation request, and responding to the address allocation request.

[0005] Optionally, obtaining the currently unallocated second network addresses from the secondary cache until the number of the second network addresses reaches the number of network addresses includes: performing at least one pointer movement operation on the first CIDR address block to find the currently unallocated second network addresses from the IP addresses within the first CIDR address block corresponding to the pointer movement operation until the number of the second network addresses reaches the number of network addresses; wherein, the number of bits moved in the first pointer movement operation is a preset first number of bits, and the number of bits moved in a non-first pointer movement operation is not less than the number of bits moved in the previous movement operation corresponding to the non-first movement operation.

[0006] Optionally, in the case where the number of bits moved in the previous movement operation corresponding to the non-first movement operation is less than a preset second number of bits, the number of bits moved in the non-first pointer movement operation is a specified multiple of the number of bits moved in the previous movement operation corresponding to the non-first movement operation; in the case where the number of bits moved in the previous movement operation corresponding to the non-first movement operation is equal to the second number of bits, the number of bits moved in the non-first pointer movement operation is equal to the second number of bits.

[0007] Optionally, the secondary cache marks whether each IP address in the first CIDR address block has been currently allocated through a target bitmap; in the case where the target network address includes an IP address, the target bitmap includes at least a first bitmap, and the number of IP addresses corresponding to each bit of the first bitmap is one.

[0008] Optionally, the target bitmap further includes a second bitmap, the number of IP addresses corresponding to each bit of the second bitmap is a specified number, and the specified number is greater than one; in the case where the second network addresses obtained through the at least one pointer movement operation do not reach the number of network addresses, obtaining the currently unallocated second network addresses from the secondary cache until the number of the second network addresses reaches the number of network addresses further includes: finding the currently unallocated second network addresses based on the first bitmap until the number of the second network addresses reaches the number of network addresses or until a preset stop condition is reached; in the case where the preset stop condition is reached, finding a second CIDR address block with available IP addresses to be allocated based on the second bitmap, and finding second network addresses from the IP addresses within the second CIDR address block based on the first bitmap until the number of the second network addresses reaches the number of network addresses; wherein, the number of IP addresses included in the second CIDR address block is equal to the specified number.

[0009] Optionally, the method further includes: when more available network addresses than the number of the network addresses are obtained from the secondary cache, storing the remaining network addresses other than the second network address in the available network addresses into the primary cache.

[0010] Optionally, the method further includes: in response to receiving the address allocation request, generating a target identifier corresponding to the address allocation request, and after obtaining the target network address, storing the target identifier into the primary cache; the allocating the target network address to the sender of the address allocation request includes: associating a callback function with the target network address and returning the result to the sender of the address allocation request; the method further includes: in response to the sender invoking the callback function, deleting the target identifier in the primary cache.

[0011] Optionally, the network address allocation method is executed by a target server, and the sender of the address allocation request is a service side; the method further includes: based on a preset first time interval, determining whether a difference amount between a first allocated address and a second allocated address is greater than a preset difference threshold, and if so, performing a synchronization operation on the allocated network addresses for the service side and the target server; where the first allocated address is the latest network address allocated by the target server to the service side, and the second allocated address is the latest network address allocated to the service side recorded by the service side; and / or, based on a preset second time interval, determining whether there is a difference between a third allocated address and a fourth allocated address, and if there is, performing a synchronization operation on the allocated network addresses for the service side and the target server; where the third allocated address is all the network addresses allocated by the target server to the service side, and the fourth allocated address is all the network addresses allocated to the service side recorded by the service side; the second time interval is greater than the first time interval.

[0012] An embodiment of the present disclosure also provides a network address allocation device, including: a first acquisition module, configured to, in response to receiving an address allocation request, preferentially acquire a first network address from a first-level cache in a multi-level cache architecture based on the address allocation request; wherein, the address allocation request is used to request the allocation of an available target network address, and the multi-level cache architecture at least includes a first-level cache and a second-level cache; the first-level cache is used to store currently allocable network addresses; the second-level cache is used to store a preset first Classless Inter-Domain Routing (CIDR) address block, and each IP address included in the first CIDR address block in the second-level cache is marked with whether it has been allocated currently; a second acquisition module, configured to, when the number of the first network addresses does not meet the address allocation request, determine the number of network addresses to be acquired from the second-level cache, and acquire a second network address that has not been allocated currently from the second-level cache until the number of the second network addresses reaches the number of network addresses; an address allocation module, configured to use the first network address and the second network address as the target network addresses required by the address allocation request, and respond to the address allocation request.

[0013] An embodiment of the present disclosure also provides an electronic device, including: a processor; a memory for storing executable instructions executable by the processor; the processor is configured to read the executable instructions from the memory and execute the instructions to implement the network address allocation method provided by the embodiment of the present disclosure.

[0014] An embodiment of the present disclosure also provides a computer-readable storage medium, storing a computer program, and the computer program is used to execute the network address allocation method provided by the embodiment of the present disclosure.

[0015] An embodiment of the present disclosure also provides a computer program product, including a computer program, and the computer program implements the network address allocation method provided by the embodiment of the present disclosure when executed by a processor.

[0016] The above technical solutions provided by the embodiments of the present disclosure fully consider the problems such as insufficient performance that may exist when the related art completely relies on the database for network address allocation. Therefore, a cache is used in the process of network address allocation, and a multi-level cache architecture is specifically set up. This architecture at least includes a first-level cache and a second-level cache. The currently allocable network addresses are stored in the first-level cache, and the preset first CIDR address block is stored in the second-level cache, and each IP address included in the first CIDR address block is marked with whether it has been allocated currently. After receiving an address allocation request, the first network address can be directly obtained from the first-level cache preferentially, which greatly improves the efficiency of network address allocation. Only when the number of the first network addresses does not meet the address allocation request, the number of network addresses to be obtained from the second-level cache is determined, and the unallocated second network addresses are obtained from the second-level cache until the number of the second network addresses reaches the number of network addresses. Then, the first network addresses and the second network addresses can be used as the target network addresses to respond to the address allocation request. The above method can allocate network addresses more efficiently and reliably with the help of the multi-level cache architecture, shorten the allocation time, and can significantly improve the performance of network address allocation compared with the related art that completely relies on the database for network address allocation.

[0017] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it used to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. Brief Description of the Drawings

[0018] The accompanying drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present disclosure and used together with the specification to explain the principles of the present disclosure.

[0019] To more clearly illustrate the technical solutions in the embodiments of the present disclosure or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0020] Figure 1 It is a schematic flowchart of a network address allocation method provided by an embodiment of the present disclosure;

[0021] Figure 2 It is a schematic flowchart of a network address allocation method provided by an embodiment of the present disclosure;

[0022] Figure 3 It is a schematic interaction diagram of network address allocation provided by an embodiment of the present disclosure;

[0023] Figure 4Schematic structural diagram of a network address allocation device provided by an embodiment of the present disclosure;

[0024] Figure 5 Schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. Detailed implementation manners

[0025] In order to more clearly understand the above objects, features and advantages of the present disclosure, the solutions of the present disclosure will be further described below. It should be noted that, without conflict, the embodiments of the present disclosure and the features in the embodiments may be combined with each other.

[0026] Many specific details are set forth in the following description in order to fully understand the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some embodiments of the present disclosure, rather than all embodiments.

[0027] The above-mentioned defects existing in the network address allocation scheme in the related art are the results obtained by the applicant through practice and careful research. Therefore, the process of discovering the above-mentioned defects and the solutions proposed by the embodiments of the present disclosure below for the above-mentioned defects should be recognized as the contributions made by the applicant to this application.

[0028] In the related art, network address allocation completely depends on the database. In high-concurrency scenarios, due to repeated reading and writing of the database, database deadlocks may occur, resulting in high overhead of database resources. Moreover, the methods adopted in the related art are mainly IP allocation technologies such as the binary search method, with a relatively low upper limit of performance bottlenecks, low allocation efficiency, and prone to problems where the allocation results do not meet expectations, such as allocation failures. In addition, in the related art, only IP addresses can be allocated individually, and it is impossible to simultaneously allocate IP addresses and smaller CIDR address blocks from a larger CIDR address block. To improve at least one of the above problems, embodiments of the present disclosure provide a network address allocation method, device, equipment and medium, which will be elaborated in detail below.

[0029] Figure 1 Schematic flow chart of a network address allocation method provided by an embodiment of the present disclosure. This method can be executed by a network address allocation device, where the device can be implemented by software and / or hardware and is generally integrated in an electronic device. As Figure 1 shown, this method mainly includes the following steps S102 to step S106:

[0030] Step S102: In response to receiving an address allocation request, obtain a first network address from a level-1 cache in a multi-level cache architecture preferentially based on the address allocation request; wherein, the address allocation request is used to request the allocation of an available target network address, and the multi-level cache architecture includes at least a level-1 cache and a level-2 cache; the level-1 cache is used to store currently allocable network addresses; the level-2 cache is used to store a preset first Classless Inter-Domain Routing (CIDR) address block, and each IP address included in the first CIDR address block in the level-2 cache is marked with whether it has been allocated currently; exemplarily, the target network address includes an Internet Protocol (IP) address and / or a Classless Inter-Domain Routing (CIDR) address block.

[0031] Embodiments of the present disclosure do not limit the sender of the address allocation request. For example, the sender of the address allocation request may be a service side. Embodiments of the present disclosure also do not limit the application scenario in which the sender obtains a network address. For example, it may be in elastic batch creation scenarios such as ECS and cloud native. As instances are frequently created and deleted, the cloud network needs to continuously create or release network cards and allocate auxiliary private IPs. Also, for example, a customer first creates a VPC (Virtual Private Cloud), and a VPC can be regarded as a CIDR address block. Then, several subnets are created from it, which is equivalent to requiring several CIDR address blocks. Several network cards can be created in each subnet to build upper-layer services such as ECS. There are several IPs or CIDR address blocks inside each network card. The above are all examples and are not listed one by one here. Any scenario that requires the allocation of network addresses is acceptable. Among them, Classless Inter-Domain Routing (CIDR) is a method for representing the range of IP addresses. The network range is defined by "IP address / prefix length". Among them, the IP address in "IP address / prefix length" is used to represent the starting address of the CIDR address block (that is, the network starting address), and the prefix length is used to represent the number of bits of the network part. For example, the CIDR address block "10.0.0.0 / 24" represents that the starting address is 10.0.0.0, and / 24 means that the first 24 bits are the network part. Correspondingly, the last 8 bits are the host part. Then, the starting IP address included in this CIDR address block is 10.0.0.0, and the ending IP address is 10.0.0.255, that is, it includes a total of 256 IP addresses.

[0032] The network addresses in the first-level cache can be individual IP addresses and / or CIDR address blocks. In the initial stage, some available network addresses can be randomly placed in the first-level cache in advance. Each time a network address allocation is performed for the received address allocation request, if the first-level cache does not meet the requirements, available network addresses can be further obtained from the second-level cache. When the number of available network addresses obtained is more than the number of required addresses, the excess network addresses can be placed in the first-level cache for subsequent direct allocation. The device that executes the network address allocation method mentioned in the embodiments of the present disclosure can be referred to as a network address allocation server, which is mainly used to allocate network addresses. After receiving an address allocation request, it can preferentially obtain the first network address from the first-level cache. Since the first-level cache stores the currently allocable network addresses, in other words, the currently unallocated network addresses, the network addresses in the first-level cache can be directly allocated to the sender of the address allocation request, without the need to spend time searching for currently unallocated available network addresses, and it also directly interacts with the cache, so it is very efficient and fast and can quickly respond to most network address allocation requests.

[0033] In addition, compared with the related art where only an IP address or a CIDR address block can be applied for, in the embodiments of the present disclosure, not only can an IP address or a CIDR address block be applied for individually, but also an IP address and a CIDR address block can be applied for and obtained simultaneously, that is, it is possible to apply for and obtain N individual IP addresses and M second CIDR address blocks available from the first CIDR address block at the same time. For example, a / 24 CIDR address block can be divided from a / 8 CIDR address block.

[0034] Step S104, when the number of the first network addresses does not meet the address allocation request, determine the number of network addresses to be obtained from the second-level cache, and obtain the second network addresses that have not been allocated currently from the second-level cache until the number of the second network addresses reaches the number of network addresses; as mentioned above, the second-level cache is used to store the preset first CIDR address block, and each IP address included in the first CIDR address block in the second-level cache is marked with whether it has been allocated currently. In some specific examples, in the second-level cache, a target bitmap can be used to simply and efficiently mark whether each IP address included in the first CIDR address block has been allocated currently.

[0035] In practical applications, the available network addresses stored in the first-level cache may not meet the address allocation request. In this case, the second network addresses that have not been allocated currently can be further obtained from the second-level cache. For example, if the address allocation request needs to obtain m1 IP addresses and n1 CIDR address blocks, and there are only m2 IP addresses and n2 CIDR address blocks currently in the first-level cache, then it is determined that m1 - m2 IP addresses and n1 - n2 CIDR address blocks need to be obtained from the second-level cache.

[0036] The above secondary cache stores a first CIDR address block. The first CIDR address block can be based on the address blocks in the target database. That is to say, the secondary cache can pre-synchronize and cache the network addresses in the target database. If the primary cache cannot meet the requirements, only the remaining available network addresses needed can be additionally searched in the secondary cache. On the one hand, the number of available network addresses searched in the secondary cache is reduced, further shortening the query time of available network addresses. On the other hand, searching for available network addresses by means of the secondary cache without relying on the database effectively saves the resources and time required for interacting with the database. Compared with the related technologies, the network address allocation efficiency is comprehensively improved, and it has high network address allocation performance.

[0037] Step S106: Use the first network address and the second network address as the target network addresses required for the address allocation request, and respond to the address allocation request. In a specific example of responding to the address allocation request, the target network address can be allocated to the sender of the address allocation request.

[0038] In addition, when the number of the first network addresses does not meet the address allocation request, directly use the first network address as the target network address required for the address allocation request, and allocate the target network address to the sender of the address allocation request.

[0039] The above technical solution provided by the embodiments of the present disclosure fully considers that there are problems such as insufficient performance in the related technologies that completely rely on the database for network address allocation. Therefore, a cache is used in the process of network address allocation, and a multi-level cache architecture is specifically set up. This architecture at least includes a primary cache and a secondary cache. The current available network addresses are stored in the primary cache, and a preset first CIDR address block is stored in the secondary cache, and each IP address included in the first CIDR address block is marked whether it has been allocated currently. After receiving the address allocation request, the first network address can be directly obtained from the primary cache preferentially, greatly improving the network address allocation efficiency. Only when the number of the first network addresses does not meet the address allocation request, then determine the number of network addresses to be obtained from the secondary cache, and obtain the second network addresses that have not been allocated currently from the secondary cache until the number of the second network addresses reaches the number of network addresses. After that, the first network address and the second network address can be used as the target network addresses to respond to the address allocation request. The above method can allocate network addresses more efficiently and reliably by means of the multi-level cache architecture, shortening the allocation time. Compared with the related technologies that completely rely on the database for network address allocation, the performance of network address allocation can be significantly improved. For example, the efficiency of network address allocation can be effectively improved, and the ability of the system to process requests can be significantly improved.

[0040] The embodiments of the present disclosure do not limit the implementation manners of the first-level cache and the second-level cache. Exemplarily, the first-level cache and the second-level cache can be implemented by Redis (Remote Dictionary Server). Redis is an open-source, memory-based key-value storage system that supports various data structures such as strings, hashes, lists, sets, sorted sets, etc., and has high performance and strong flexibility, making it suitable as a cache. In some specific examples, the first-level cache can be implemented by means of Redis sorted sets, and the second-level cache can be implemented by means of Redis bitmaps, thus fully ensuring the reliability of the second-level cache architecture.

[0041] In order to efficiently and reliably obtain the second network address in the second-level cache, in some embodiments, the step of obtaining the currently unallocated second network address from the second-level cache until the number of second network addresses reaches the number of network addresses can be executed in the following manner: perform at least one pointer movement operation on the first CIDR address block to find the currently unallocated second network address from the IP addresses within the first CIDR address block corresponding to the pointer movement operation until the number of second network addresses reaches the number of network addresses, or until a preset first stop condition is reached. It can be understood that if the required second network address has been found, the pointer movement operation can be stopped. In addition, considering that it may be possible that the required second network address has still not been found after multiple pointer movement operations, in order to avoid inefficiently and endlessly executing the pointer movement operation, a first stop condition can be set. In some specific implementation examples, the first stop condition includes that the number of operations of the pointer movement operation is greater than a preset number threshold, or the duration of the pointer movement operation is greater than a preset duration threshold. That is, if the first stop condition is reached, it indicates that it is no longer suitable to find available second network addresses by means of the pointer movement operation, so it can be stopped in a timely manner and other search strategies can be adopted. Through the above method, the reliability of finding available network addresses can be effectively ensured.

[0042] In the embodiments of the present disclosure, the number of bits moved in the first pointer movement operation is a preset first number of bits. The embodiments of the present disclosure do not limit the first number of bits. Exemplarily, the first number of bits is equal to 16 bits. The number of bits moved in a non-first pointer movement operation is not less than the number of bits moved in the previous movement operation of the non-first movement operation, so as to improve the efficiency of finding available network addresses.

[0043] To further improve the search efficiency, in some specific implementation examples, when the number of bits of the previous movement operation corresponding to the non-first movement operation is less than a preset second number of bits, the number of bits of the non-first pointer movement operation is a specified multiple of the number of bits of the previous movement operation corresponding to the non-first movement operation; when the number of bits of the previous movement operation corresponding to the non-first movement operation is equal to the second number of bits, the number of bits of the non-first pointer movement operation is equal to the second number of bits. The embodiments of the present disclosure do not limit the second number of bits. Exemplarily, the second number of bits is equal to 128 bits. For example, it can be moved at least 16 bits each time. If the available network addresses found by the pointer movement operation for the current time are not sufficient to meet the requirements, the next pointer movement operation is executed. As the number of pointer movement operations increases, the number of bits moved each time doubles, and it can be moved up to 128 bits at most. Through the above method, on the one hand, the probability of finding an available network address can be increased by increasing the movement range each time the pointer movement operation is executed, and on the other hand, by limiting the maximum movement range interval of the pointer, the reliability of finding an available network address by the pointer movement method can be better guaranteed.

[0044] In some embodiments, the secondary cache marks whether each IP address in the first CIDR address block has been currently allocated through a target bitmap; specifically, the minimum unit of the bitmap is a bit, and the value of each bit is 0 or 1. Whether the network address corresponding to the bit has been allocated is represented by 0 or 1. For example, 1 indicates that the corresponding network address has been allocated (i.e., unavailable), and 0 indicates that the corresponding network address has not been allocated (i.e., available). In this way, it is possible to record concisely and efficiently whether the network address has been currently allocated, and it helps to quickly find available network addresses through the bitmap. For example, assuming 16 IPs are applied for and the corresponding value of the bitmap is 4, that is, 00000000, 00000100, which means the 14th IP address has been allocated and there are 15 IP addresses available. The above network address can be an IP address or a CIDR address. One or more bitmaps can be set according to actual requirements. For example, a bitmap corresponding to the IP address and bitmaps corresponding to CIDR address blocks of different capacities can be set. For the convenience of processing, the embodiments of the present disclosure can regard an IP address as a special CIDR address block, that is, a CIDR address block with a prefix length of 32, which can also be simply referred to as a / 32 CIDR address block. This address block actually contains only 1 IP address. Based on this, in order to accelerate the search for network addresses, when the target network address includes an IP address, the target bitmap includes at least a first bitmap, and the number of IP addresses corresponding to each bit of the first bitmap is one. That is, the embodiments of the present disclosure regard an IP address as a special CIDR address block, that is, a / 32 CIDR address block that contains only one address. Therefore, the allocation of IP addresses and / or CIDR address blocks can be converted into the allocation of CIDR address blocks of the required size. This method is more flexible and convenient and also helps to realize the simultaneous allocation of IP addresses and CIDR address blocks. Further, the target bitmap further includes a second bitmap, and the number of IP addresses corresponding to each bit of the second bitmap is a specified number, and the specified number is greater than one. That is, the first bitmap can be a bitmap corresponding to the IP address, that is, a / 32 bitmap, and the second bitmap can be a bitmap corresponding to a CIDR address block of a specified size, such as a / 22 bitmap. The second bitmap can be used as an aggregated index bit for the first bitmap. Each bit represents the whole of multiple / 32 bits. For example, the / 22 second bitmap can be used as an aggregated index bit for the / 32 first bitmap. Each bit in the / 22 second bitmap can represent the IP addresses of 1024 / 32 first bitmaps. It is possible to first find an available CIDR address block from the / 22 second bitmap, and then further find available IP addresses from within this address block by means of the / 32 first bitmap, thereby effectively improving the search efficiency.

[0045] On the basis described above, embodiments of the present disclosure can further optimize the process of obtaining the second network address. Exemplarily, when the second network address obtained through at least one pointer movement operation does not reach the number of network addresses (such as reaching the aforementioned first stop condition), the step of obtaining the currently unallocated second network address from the secondary cache until the number of second network addresses reaches the number of network addresses further includes the following steps a to b:

[0046] Step a, based on the first bitmap, find the currently unallocated second network address until the number of second network addresses reaches the number of network addresses or until a preset stop condition is reached. This preset stop condition can also be referred to as the second stop condition. Embodiments of the present disclosure can first attempt to find available IP addresses based on the first bitmap again. In some specific implementation examples, starting from the IP address corresponding to the current pointer, find the currently unallocated IP address based on the first bitmap and use the found IP address as the second network address. Specifically, if the required IP addresses have not been fully obtained when the first stop condition is reached, it means that the available IP addresses are relatively scattered. Therefore, it can be achieved by moving the pointer to skip the allocated IP addresses. Specifically, start querying from the current pointer to find the next 0 in the / 32 first bitmap, so as to quickly find the next unallocated IP address. However, this way of finding one by one has low efficiency. Therefore, a second stop condition can be set. In some specific implementation examples, the second stop condition includes: when the number of bits searched in the first bitmap reaches a preset bit threshold, the number of second network addresses still has not reached the number of network addresses. For example, at most 1024 bits are searched in the above manner and do not cross the boundary. By setting the second stop condition, the scenario that is currently not applicable to this method can be identified in time and interrupted, which helps to avoid the subsequent long time-consuming of continuing to use this method to find available IP addresses, but can timely change to other strategies to further improve the obtaining rate of available IP addresses.

[0047] Step b, when the preset stop condition is met, search for the second CIDR address block with available IP addresses currently based on the second bitmap, and search for the second network address from the IP addresses within the second CIDR address block based on the first bitmap until the number of second network addresses reaches the number of network addresses; wherein, the number of IP addresses included in the second CIDR address block is equal to the specified number. That is to say, the second bitmap is preferentially used to quickly find the available second CIDR address block without searching for IP addresses one by one. On the basis of finding the available second CIDR address block, then search for the available IP addresses from it. This hierarchical way of searching for IP addresses is more efficient and can greatly improve the efficiency of finding available IP addresses. Exemplarily, the first CIDR address block can be divided into multiple second CIDR address blocks of / 22. That is, the second CIDR address block is a subnet containing 1024 IP addresses. For example, if the first CIDR address block contains a total of N IP addresses, then it can be divided into N / 1024 second CIDR address blocks. The N / 1024 second CIDR address blocks jointly correspond to a second bitmap of / 22. Each bit of the second bitmap is used to represent whether all the IP addresses in the second CIDR address block corresponding to this bit have been allocated. Through the above method, assuming that the available second CIDR address block is found first through the second bitmap, and then the available IP addresses are further found from the second CIDR address block based on the first bitmap of / 32, this way of searching for network addresses through multiple-level bitmaps is more efficient and can be well applied to the scenario of finding available network addresses from a relatively large CIDR address block (such as 10.0.0.0 / 8 with 16 million IP addresses).

[0048] In some embodiments, the foregoing at least one pointer movement operation is performed on the first CIDR address block to search for the currently unallocated second network address from the IP addresses within the first CIDR address block corresponding to the pointer movement operation until the number of second network addresses reaches the number of network addresses, or until the preset first stop condition is met. Specifically, it can also be implemented with reference to the following steps (1) to (2):

[0049] Step (1), perform at least one pointer movement operation on the first CIDR address block to search for the currently unallocated available network address from the IP addresses within the first CIDR address block corresponding to the pointer movement operation until the number of available network addresses is not less than the number of network addresses, or until the preset first stop condition is met. It can be understood that the pointer movement operation obtains available network addresses in batches, so the total number of available network addresses obtained by at least one pointer movement operation may be more than the required number of network addresses.

[0050] Step (2), when the number of available network addresses is not less than the number of network addresses, extract a second network address equal to the number of network addresses from the found available network addresses; when the number of available network addresses is less than the number of network addresses, use all available network addresses as the second network address. Exemplarily, when the number of available network addresses is not less than the number of network addresses, the obtained available network addresses ranked at the front can be used as the second network address in sequence, and the remaining network addresses among the available network addresses except the second network address are stored in the first-level cache. In other words, when more available network addresses than the number of network addresses are obtained from the second-level cache, the remaining network addresses among the available network addresses except the second network address are stored in the first-level cache for subsequent provision to other requesters in need of network addresses, thus helping to make full use of the currently obtained network addresses.

[0051] Further, the network address allocation method provided by the embodiments of the present disclosure further includes: saving the target network address as the allocated network address to the target database; on this basis, the above-mentioned step of allocating the first network address and the second network address as the target network address to the sender of the address allocation request includes: when the target network address is successfully saved to the target database, allocating the first network address and the second network address as the target network address to the sender of the address allocation request. That is, the embodiments of the present disclosure will only allocate the target network address to the sender of the address allocation request when it is ensured that the found target network address is successfully saved in the target database. It should be understood that although the allocation process of network addresses is implemented with the help of caches, the allocation results will be persistently saved in the database for subsequent persistent recording, and a unique index can be used to ensure that network addresses are not duplicated. The above algorithm logic for accelerating network address allocation through database persistence and the second-level cache architecture can allocate network addresses with higher performance. Compared with the related art, it can significantly improve the allocation efficiency and reliability of network addresses.

[0052] On the basis of the above, the method further includes: when the target network address includes a target IP address, locking the CIDR address block related to the target IP address in the target database; when the target network address includes a target CIDR address block, locking the IP addresses related to the target CIDR address block in the target database. This locking can specifically be an upper read lock (shared lock). The CIDR address block related to the target IP address can be, for example, the CIDR address block containing the target IP address in the target database, and the IP addresses related to the target CIDR address block can be, for example, the IP addresses included in the target CIDR address block. By means of locking, it is possible to effectively prevent the locked network addresses from being allocated to other requests, effectively avoiding problems such as concurrent request conflicts.

[0053] On the basis described above, the above method further includes: when the target network address is successfully saved to the target database, marking in the secondary cache that the target network address has been allocated. If the target network address fails to be successfully saved in the target database, the target network address will not be allocated to the sender of the address allocation request, and the target network address can be released, that is, it is still regarded as an available state and can be allowed to be allocated to other requests. By preferentially persistently saving the database and then marking in the secondary cache that the address has been allocated, the reliability of network address allocation is further improved.

[0054] On the basis described above, an embodiment of the present disclosure further provides a Figure 2 flow schematic diagram of a network address allocation method as shown, mainly including the following steps:

[0055] Step S202, in response to receiving an address allocation request, preferentially obtain a first network address from the primary cache in the multi-level cache architecture based on the address allocation request; wherein, the address allocation request is used to request the allocation of an available target network address, and the multi-level cache architecture includes at least a primary cache and a secondary cache; the primary cache is used to store currently allocable network addresses; the secondary cache is used to store a preset first Classless Inter-Domain Routing (CIDR) address block, and each IP address included in the first CIDR address block in the secondary cache is marked with whether it has been allocated currently; the target network address includes an Internet Protocol (IP) address and / or a Classless Inter-Domain Routing (CIDR) address block.

[0056] Step S204, when the number of first network addresses does not meet the address allocation request, determine the number of network addresses to be obtained from the secondary cache, and obtain a second network address that has not been allocated currently from the secondary cache until the number of second network addresses reaches the number of network addresses.

[0057] Step S206, save the target network address as an allocated network address to the target database.

[0058] Step S208, when the target network address is successfully saved to the target database, allocate the first network address and the second network address as the target network address to the sender of the address allocation request; and mark in the secondary cache that the target network address has been allocated.

[0059] The specific implementation manners of the above steps S202 to S208 may refer to the foregoing related content and will not be elaborated herein. Compared with the related art where network address allocation completely depends on the database, problems such as poor performance, database deadlocks caused by repeated reading and writing of the database in high-concurrency scenarios, and large overhead on database resources are likely to occur. Through the above method, the process of network address allocation can be executed in the cache, and the network allocation can be accelerated by means of the secondary cache architecture. Finally, the result is saved by database persistence, and the target network address will be allocated to the sender of the address allocation request only when it is successfully saved in the database, and the target network address is marked as allocated in the secondary cache, comprehensively ensuring the reliability of network address allocation.

[0060] On this basis, for the sake of understanding, the embodiments of the present disclosure respectively provide specific examples of IP address allocation and specific examples of CIDR address block allocation. The above specific examples are all implemented on the basis of the foregoing network address allocation process, and the following is a schematic description:

[0061] (1) The specific example of IP address allocation can be implemented with reference to the following steps 1 to 9.

[0062] Step 1: Pop n available IP addresses in ascending order through the Redis sorted set (i.e., the first-level cache). The specific result can be executed with reference to steps 1.1 and 1.2:

[0063] Step 1.1, if the pop is successful, combine the IP addresses according to the Redis CIDR + subscript, and directly jump to step 7 to save in the database.

[0064] Step 1.2, if the pop fails or the number of IP addresses is insufficient, continue to execute step 2.

[0065] Step 2, query the information of the specified CIDR address block through Redis, such as the size of the CIDR address block, bitmap information, and whether the specified CIDR address block is in the cache. The specified CIDR address block can be, for example, the foregoing first CIDR address block.

[0066] Step 3, query the number of available IPs through Redis. The specific result can be executed with reference to steps 3.1 and 3.2:

[0067] Step 3.1, if the quantity is sufficient, continue to execute step 4.

[0068] Step 3.2, if the quantity is insufficient, return with an error.

[0069] Step 4, specifically, it can be executed with reference to the following steps 4.1 and 4.2:

[0070] Step 4.1: Move the pointer, moving at least 16 bits each time. As the number of retries increases, the movement doubles each time, with a maximum query of 128 bits.

[0071] Step 4.2: Check if the pointer is occupied, that is, check if the IP address corresponding to the pointer has been allocated. Specifically, each bit can be analyzed. If it is 0, it means it can be allocated. For example, when applying for 16 IPs and the returned result is 4 (0000000000000100), it indicates that the 14th IP has been allocated and there are 15 IP addresses available for use.

[0072] Step 5: If Step 4 is successful, it means the pre-allocation of the IP is successful, and Step 7 can be continued. It should be noted that at this time, the bitmap is not modified, only the pointer position is modified (the subsequent requests do not use the previous subscripts). At this time, several more IP addresses may also be applied for. After saving the IP addresses required by the service request to the database, the extra IP addresses are placed in the first-level cache.

[0073] Step 6: If Step 4 fails, it can be executed according to the following Step 6.1 and Step 6.2:

[0074] Step 6.1: If the pointer exceeds the IP range after executing Step 4.1, the pointer can be reset to 0 and Step 2 can be executed again to continue applying for IP addresses.

[0075] Step 6.2: If Step 4.2 is still not successfully applied, it means the IP address allocation is relatively scattered, and the pointer needs to be moved first to skip the allocated IP addresses. Specifically, starting from the current pointer, query the next 0 in the / 32 bitmap, looking for a maximum of 1024 bits without going out of bounds. If the / 32 bitmap fails to find an IP address that meets the requirements, the available CIDR address block can be found through the / 22 bitmap first, and then the specific available IP address can be found through the / 32 bitmap. After that, update the pointer position and execute Step 2 again.

[0076] Step 7: Save the specified IP address in the database. The specified IP address is the allocable IP address found previously.

[0077] Specifically, it can be executed according to the following Step 7.1 and Step 7.3:

[0078] Step 7.1: Start a transaction. In actual applications, a transaction may not be started, and a distributed lock can be used to ensure.

[0079] Step 7.2: Take a shared lock (read lock) on the CIDR address block related to the specified IP address. If the CIDR address block is still in an allocable state after being queried in the database, an error can be reported.

[0080] Step 7.3, save the specified IP address. If you apply for multiple IP addresses at the same time, you can sort them first and then insert them one by one. Even if an IP address fails to be inserted, you can continue to insert it to see which IP addresses are available. If any IP address fails to be saved, the entire error will be reported.

[0081] Step 8: The database is saved successfully and the cache is updated. You can refer to the following steps 8.1 and 8.4 for execution. Specifically, you can use Lua script atomic operations to ensure atomicity and ensure data consistency between caches as much as possible.

[0082] Step 8.1, update the number of IP addresses that can be allocated to Redis.

[0083] Step 8.2, update the Redis bitmap to mark the specified IP address as allocated.

[0084] Step 8.3, update other bitmaps in the cache, such as / 28 bitmap, / 22 bitmap, etc. In actual applications, if the total number of IP addresses exceeds 1024, there can be a / 22 bitmap.

[0085] Step 8.4, put the extra available IP addresses into the first-level cache.

[0086] Step 9: If the database save fails, update the cache, align the database data with the Redis data, and execute step 2 again to set the retry limit.

[0087] The effect that can be achieved by the above method can refer to the relevant content of the aforementioned allocation of network addresses. The above mainly provides a specific example using the network address as an example, specifically an IP address. In actual applications, the specific execution details can be flexibly adjusted and are not limited here.

[0088] (II) A specific example of CIDR address block allocation can be implemented by referring to the following steps (1) to (9).

[0089] Step (1): Pop up n available CIDR address blocks in ascending order through the Redis ordered set (i.e., the first-level cache). For the specific results, refer to steps (1.1) and (1.2):

[0090] In step (1.1), if the pop-up is successful, the CIDR address block is assembled according to the Redis CIDR+subscript, and the process directly jumps to step (7) and saves it in the database.

[0091] Step (1.2), if the ejection fails or the CIDR address block is insufficient, continue to step (2).

[0092] Step (2), query the information of the specified CIDR address block through Redis, such as the size of the CIDR address block, bitmap information, and whether the specified CIDR address block is in the cache. The specified CIDR address block can be, for example, the aforementioned first CIDR address block.

[0093] Step (3), query the number of available IPs through Redis and calculate the theoretically minimum number of available CIDR address blocks. The specific results can be executed according to steps (3.1) to (3.3):

[0094] Step (3.1), if the calculation result is sufficient, continue to execute Step (4).

[0095] Step (3.2), if the calculation result is definitely insufficient, return with an error.

[0096] Step (3.3), if the calculation result may be insufficient, it can be further confirmed. If the bitmap is all 1, it means the allocation is exhausted. If there is 0 in the bitmap, it means there is still available allocation.

[0097] Step (4), the specific execution can refer to the following steps (4.1) and (4.2):

[0098] Step (4.1), move the pointer, move at least 4 bits each time. As the number of retries increases, the movement doubles each time, and at most 128 bits are queried.

[0099] Step (4.2), check whether the pointer is occupied, that is, check whether the CIDR address block corresponding to the pointer has been allocated. Specifically, each bit can be analyzed. If it is 0, it means it can be allocated. For example, when applying for 16 CIDR address blocks, the return result is 4 (00000000 00000100), indicating that the 14th CIDR address block has been allocated and there are 15 CIDR address blocks available for use.

[0100] Step (5), if Step (4) is successful, it means the pre-allocation of the CIDR address block is successful, and Step (7) can be continued. It should be noted that at this time, the bitmap is not modified, only the pointer position is modified (the subsequent requests do not use the previous subscripts). At this time, several more CIDR address blocks may be applied. After saving the CIDR address blocks required by the service request to the database, the extra IP addresses are placed in the first-level cache.

[0101] Step (6), if Step (4) fails, it can be executed according to the following steps (6.1) and (6.2):

[0102] Step (6.1), if after executing Step (4.1), the pointer exceeds the CIDR address block range, the pointer can be reset to 0 and start from Step (2) again to continue applying for CIDR address blocks.

[0103] Step (6.2), if step (4.2) is executed and the application is still not successful, it indicates that the CIDR address block allocation is relatively scattered. It is necessary to move the pointer first to skip the allocated CIDR address blocks. Specifically, starting from the current pointer, query the previous 0 in the bitmap, up to 64 bits at most, and then update the pointer position and execute from step (2) again.

[0104] Step (7), the database saves the specified CIDR address block. The specified CIDR address block is also the allocable CIDR address block found previously. Specifically, it can be executed according to the following steps (7.1) and step (7.4):

[0105] Step (7.1), start a transaction. In actual applications, a transaction may not be started, and a distributed lock can be used to ensure it.

[0106] Step (7.2), lock the IP addresses related to the specified CIDR address block with a shared lock (read lock).

[0107] Step (7.3), save the specified CIDR address block. If multiple CIDR address blocks are applied for simultaneously, they can be sorted first and then inserted one by one. Even if the insertion of a CIDR address block fails, the insertion can continue to check which CIDR address blocks are available. If the saving of any CIDR address block fails, an overall error is reported.

[0108] Step (7.4), check whether the IP addresses related to the specified CIDR address block have been allocated. If any IP address has been allocated, an error is reported.

[0109] Step (8), after the database saves successfully, update the cache. It can be executed according to the following steps (8.1) and step (8.4). Specifically, Lua script atomic operations can be used to ensure atomicity and as much as possible ensure data consistency between caches.

[0110] Step (8.1), update the number of allocable CIDR address blocks in Redis.

[0111] Step (8.2), update the Redis bitmap to mark the specified CIDR address block as allocated.

[0112] Step (8.3), update other bitmaps in the cache, such as the / 32 bitmap, etc. In actual applications, if the total number of IP addresses exceeds 1024, a / 22 bitmap can be available.

[0113] Step (8.4), put the redundant available CIDR address blocks into the first-level cache.

[0114] Step (9), if the database save fails, update the cache, align the database data with the Redis data, and execute step (2) again, setting the retry limit.

[0115] The effects that can be achieved by the above method can refer to the relevant content of the aforementioned network address allocation. The above mainly provides a specific example with the network address being a CIDR address block. In actual applications, the specific implementation details can be flexibly adjusted, which will not be limited here.

[0116] To further ensure the reliability of network address allocation and avoid problems in network address allocation or release due to exceptions, the above method further includes: in response to receiving an address allocation request, generating a target identifier corresponding to the address allocation request, and after obtaining the target network address, storing the target identifier in a first-level cache; the target identifier can be, for example, a universally unique identifier, which can be used to distinguish address allocation requests. On this basis, the aforementioned allocating the target network address to the sender of the address allocation request includes: associating a callback function with the target network address and returning it to the sender of the address allocation request; further, the above method further includes: in response to the sender calling the callback function, deleting the target identifier in the first-level cache. By introducing a callback mechanism, it can be ensured that the target identifier in the first-level cache is deleted only when the sender receives the target network address, determining that the allocation event corresponding to the corresponding address allocation request has been successfully completed, further guaranteeing the reliability of the processing of the network address allocation result.

[0117] On the basis of the above, the step of storing the target identifier in the first-level cache specifically includes: associating the target identifier with a rollback function and storing it in the first-level cache; based on this, the above method further includes: in response to the callback function not being called by the sender within a specified duration, based on the rollback function, performing a rollback operation corresponding to the target identifier through the first-level cache. The rollback operation is to revoke the previously executed operations and restore to the state at a specific time point. For example, if the callback function times out without being called by the sender, it indicates that the sender has not successfully received the target network address or the target network address allocation fails. At this time, a rollback operation can be performed to timely release the target network address for subsequent allocation to other requests, avoiding wasting the target network address.

[0118] For ease of understanding, some specific examples applying the above content are provided in the embodiments of the present disclosure, which can be executed with reference to the following key steps S1 to S6:

[0119] Step S1: Generate a UUID (Universally Unique Identifier): When the network address allocation module receives a service request, it generates a unique UUID corresponding to the request. Herein, the UUID is the aforementioned target identifier, and the service request corresponds to the aforementioned address allocation request.

[0120] Step S2: Execute the network address allocation process: For details, please refer to the relevant content above and will not be elaborated here.

[0121] Step S3: Register a rollback function: Before returning the result, the network address allocation module stores a rollback function together with the UUID in the first-level cache, specifically in the sorted set of Redis.

[0122] Step S4: Return the network address and the callback function: The network address allocation module returns the network address and attaches a callback function, requiring the service module to call it after completing the operation.

[0123] Step S5: Complete the request: When the service module calls the callback function, the UUID in the first-level cache is deleted, indicating that this request has ended.

[0124] Step S6: Timeout rollback: If the callback function is not called, the first-level cache checks and pops the timed-out UUID every second and executes the rollback operation.

[0125] Through the above method, the network address allocation module can be decoupled from the service code, made into an independent service module, and the callback function and the rollback function are introduced to ensure the stability of the service code, which can not only avoid problems such as abnormal network address allocation or release, but also effectively avoid waste of network address resources.

[0126] In practical applications, the network address allocation module can be implemented by means of a target server. That is, the network address allocation method is executed by the target server, and the sender of the address allocation request can be the service side, also referred to as the service module. Considering that various factors such as the network may cause the inconsistency of the allocated network address data recorded by the target server and the service side, in order to ensure the data consistency between the target server and the service side, the embodiments of the present disclosure may further include the following Step 1 and / or Step 2, which are described separately below:

[0127] Step 1 includes: Based on a preset first time interval, determine whether the difference between the first allocated address and the second allocated address is greater than a preset difference threshold. If so, perform a synchronization operation of the allocated network address for the service end and the target server; wherein, the first allocated address is the network address that the target server records as the latest one allocated to the service end, and the second allocated address is the network address that the service end records as the latest one allocated to it. In a specific implementation example of Step 1, the embodiments of the present disclosure can be implemented with reference to the following steps (1a) and (2a):

[0128] Step (1a), perform a first verification operation according to a preset first time interval to obtain a first verification result; wherein, the first verification result is used to indicate the difference between the first allocated address and the second allocated address; the first time interval can be flexibly set according to requirements, such as being set to 1 second. The above steps can be simply understood as fast reconciliation, that is, triggering the target server and the service end to verify the latest allocated network address data within a short time such as 1 second to determine the size of the difference between the two.

[0129] Step (2a), in the case where the difference is greater than the preset difference threshold, perform a synchronization operation of the allocated network address for the service end and the target server. That is, only when the difference in the latest allocated network address data between the target server and the service end is large, synchronization is triggered. Among them, the synchronization operation can be to adjust the allocated network address recorded by the target server based on the allocated network address recorded by the service end. Exemplarily, the allocated network address can be all the previously allocated network addresses. It can be understood that the key point of fast reconciliation is to ensure allocation availability, rather than pursuing strong data consistency (that is, data inconsistency can be tolerated). As long as the difference is not large, the network address can still be normally allocated, which can avoid the situation where the network address is available but cannot be allocated. The above method can effectively balance performance consumption and high concurrency requirements.

[0130] Step 2 includes: Based on a preset second time interval, determine whether there is a difference between the third allocated address and the fourth allocated address. If there is, perform a synchronization operation of the allocated network address for the service end and the target server; wherein, the third allocated address is all the network addresses that the target server records as allocated to the service end, and the fourth allocated address is all the network addresses that the service end records as allocated to it; the second time interval is greater than the first time interval. In a specific implementation example of Step 2, the embodiments of the present disclosure can be implemented with reference to the following steps (1b) and (2b):

[0131] Step (1b): Perform a second verification operation at a preset second time interval to obtain a second verification result. The second verification result is used to indicate whether there is a difference between the third allocated address and the fourth allocated address. The second time interval is greater than the first time interval and can be flexibly set according to requirements, such as set to one day. The above steps can be simply understood as slow reconciliation, that is, triggering the verification of the full amount of allocated network address data between the target server and the service side in units of a relatively long period such as a day, and determining whether there is a difference between the two.

[0132] Step (2b): In the case where the second verification result indicates that there is a difference between the third allocated address and the fourth allocated address, perform a synchronization operation of the allocated network addresses for the service side and the target server. That is, in slow reconciliation, perform a consistency synchronization adjustment for the full amount of data.

[0133] In practical applications, the above step one (i.e., fast reconciliation method) and / or step two (i.e., slow reconciliation method) can be flexibly adopted according to requirements to achieve data consistency processing. If both the fast reconciliation and slow reconciliation methods are adopted, it can not only ensure the allocation availability in a short time, balance the performance consumption and high concurrency requirements, but also regularly synchronize the network address data between the target server and the service side to ensure the consistency of the network address data. Accurate network address data helps to further ensure the reliability of network address allocation.

[0134] The embodiments of the present disclosure also provide as Figure 3An interactive schematic diagram of network address allocation is shown, mainly showing the interaction between the service side and the network address allocation server. Specifically, the network address allocation server can be divided into a server, a first-level cache, a second-level cache, and a database. Among them, the network address allocation server can be, for example, an IPAM (IP Address Management) server. The service side can first send a request to allocate a network address to the server. Here, the server can serve as a service interface for interacting with the service side. Then, the server directly obtains a network address from the first-level cache. If the first-level cache runs out of network addresses, it will then obtain a batch of available network addresses from the second-level cache. The second-level cache can find unallocated network addresses based on Redis bitmap traversal and return a batch of available network addresses (unallocated) to the first-level cache. The first-level cache will correspondingly return available network addresses to the server. The server will first synchronize the database, that is, save the available network addresses to be allocated in the database. In the case of confirming successful synchronization based on the feedback message returned by the database, it will notify the first-level cache to update the cache. The first-level cache will cache the excess network addresses and further synchronize the cache with the second-level cache. After the second-level cache confirms that the network address has been allocated, it will return a feedback message. Finally, the server will return available network addresses, callback functions, etc. to the service side. The service side can confirm through the callback function. If the service side fails to call the callback function within the timeout period, a rollback operation can be performed, that is, otherwise roll back. For details, please refer to the relevant content above and will not be elaborated here. In addition, consistency check processes such as fast reconciliation and slow reconciliation as described above can also be performed between the service side and the network address allocation server. In Figure 3 it is not shown again.

[0135] In summary, the above network address allocation method provided by the embodiments of the present disclosure can allocate network addresses more efficiently and reliably by means of database persistent storage and multi-level cache acceleration for allocation, improving the network address allocation performance. Moreover, the IP address can be regarded as a special CIDR address block, and the allocation of the IP address can be converted into the allocation of the CIDR address block, so as to conveniently and reliably achieve the purpose of simultaneously allocating the IP address and the CIDR address block, further improving the flexibility of network address allocation. Further, the embodiments of the present disclosure can represent the status of whether a network address is available through a bitmap, and can adopt a multi-level bitmap form (such as the aforementioned first bitmap and second bitmap) to accelerate the query of network addresses. In addition, problems such as abnormal network address allocation or release can be effectively avoided by introducing callback functions and rollback functions, preventing waste of network address resources. Moreover, through the fast and slow reconciliation mechanism, the data accuracy of the allocated network addresses can be effectively guaranteed, and a good balance can be achieved between performance consumption and data accuracy.

[0136] Corresponding to the aforementioned network address allocation method, the embodiments of the present disclosure further provide a network address allocation device.Figure 4 The following is a schematic structural diagram of a network address allocation device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware, and is generally integrated in an electronic device, such as Figure 4 As shown, the network address allocation device includes:

[0137] A first acquisition module 402, configured to, in response to receiving an address allocation request, preferentially acquire a first network address from a primary cache in a multi-level cache architecture based on the address allocation request; wherein, the address allocation request is used to request the allocation of an available target network address, and the multi-level cache architecture includes at least a primary cache and a secondary cache; the primary cache is used to store currently allocable network addresses; the secondary cache is used to store a preset first Classless Inter-Domain Routing (CIDR) address block, and each IP address included in the first CIDR address block is marked with whether it has been currently allocated or not;

[0138] A second acquisition module 404, configured to, when the number of first network addresses does not meet the address allocation request, determine the number of network addresses to be acquired from the secondary cache, and acquire currently unallocated second network addresses from the secondary cache until the number of second network addresses reaches the number of network addresses;

[0139] An address allocation module 406, configured to use the first network address and the second network address as the target network addresses required by the address allocation request, and respond to the address allocation request.

[0140] For the above device provided by the embodiment of the present disclosure, it fully considers that there are problems such as insufficient performance in the related art that completely relies on a database for network address allocation. Therefore, a cache is used in the process of network address allocation. Specifically, a multi-level cache architecture is set up, which includes at least a primary cache and a secondary cache. Currently allocable network addresses are stored in the primary cache, and a preset first CIDR address block is stored in the secondary cache, and each IP address included in the first CIDR address block is marked with whether it has been currently allocated or not. After receiving an address allocation request, the first network address can be preferentially and directly acquired from the primary cache, greatly improving the efficiency of network address allocation. Only when the number of first network addresses does not meet the address allocation request, then determine the number of network addresses to be acquired from the secondary cache, and acquire currently unallocated second network addresses from the secondary cache until the number of second network addresses reaches the number of network addresses. After that, the first network address and the second network address can be used as the target network addresses to respond to the address allocation request. The above device can allocate network addresses more efficiently and reliably with the help of the secondary cache architecture, shortening the allocation time. Compared with the related art that completely relies on a database for network address allocation, the performance of network address allocation can be significantly improved.

[0141] In some embodiments, the second acquisition module 404 is specifically configured to: perform at least one pointer movement operation on the first CIDR address block to find an unallocated second network address from the IP addresses within the first CIDR address block corresponding to the pointer movement operation until the number of second network addresses reaches the number of network addresses or until a preset first stop condition is reached; wherein the number of bits moved in the first pointer movement operation is a preset first number of bits, and the number of bits moved in a non-first pointer movement operation is not less than the number of bits moved in the previous movement operation of the non-first movement operation.

[0142] In some embodiments, when the number of bits moved in the previous movement operation of the non-first movement operation is less than a preset second number of bits, the number of bits moved in the non-first pointer movement operation is a specified multiple of the number of bits moved in the previous movement operation of the non-first movement operation; when the number of bits moved in the previous movement operation of the non-first movement operation is equal to the second number of bits, the number of bits moved in the non-first pointer movement operation is equal to the second number of bits.

[0143] In some embodiments, the first stop condition includes that the number of operations of the pointer movement operation is greater than a preset number threshold, or the duration of the pointer movement operation is greater than a preset duration threshold.

[0144] In some embodiments, the secondary cache marks whether each IP address in the first CIDR address block has been allocated currently through a target bitmap; when the target network address includes an IP address, the target bitmap includes at least a first bitmap, and the number of IP addresses corresponding to each bit of the first bitmap is one.

[0145] In some embodiments, the target bitmap further includes a second bitmap, the number of IP addresses corresponding to each bit of the second bitmap is a specified number, and the specified number is greater than one; when the second network addresses obtained through at least one pointer movement operation do not reach the number of network addresses, the second acquisition module 404 is further specifically configured to: find unallocated second network addresses based on the first bitmap until the number of second network addresses reaches the number of network addresses or until a preset stop condition is reached; when the preset stop condition is reached, find a second CIDR address block with available IP addresses to be allocated based on the second bitmap, and find second network addresses from the IP addresses within the second CIDR address block based on the first bitmap until the number of second network addresses reaches the number of network addresses; wherein the number of IP addresses included in the second CIDR address block is equal to the specified number.

[0146] In some embodiments, the second acquisition module 404 is specifically configured to: starting from the IP address corresponding to the current pointer, search for an unallocated IP address currently based on the first bitmap, and use the found IP address as the second network address; the preset stop condition includes: when the number of bits searched in the first bitmap reaches a preset bit threshold, the number of the second network addresses still does not reach the number of network addresses.

[0147] In some embodiments, the second acquisition module 404 is specifically configured to: perform at least one pointer movement operation on the first CIDR address block to search for an available network address that is not currently allocated from the IP addresses within the first CIDR address block corresponding to the pointer movement operation until the number of available network addresses is not less than the number of network addresses, or until a preset first stop condition is reached; in the case where the number of available network addresses is not less than the number of network addresses, extract the second network addresses equal to the number of network addresses from the found available network addresses; in the case where the number of available network addresses is less than the number of network addresses, use all the available network addresses as the second network addresses.

[0148] The device further includes a cache saving module, configured to, in the case of obtaining more available network addresses than the number of network addresses from the secondary cache, store the remaining network addresses other than the second network addresses among the available network addresses into the primary cache.

[0149] In some embodiments, the device further includes a database saving module, configured to save the target network address as an allocated network address to a target database; the address allocation module 406 is specifically configured to: in the case where the target network address is successfully saved to the target database, allocate the first network address and the second network address as the target network address to the sender of the address allocation request.

[0150] In some embodiments, the device further includes a locking module, configured to lock the CIDR address block related to the target IP address in the target database in the case where the target network address includes the target IP address; and lock the IP addresses related to the target CIDR address block in the target database in the case where the target network address includes the target CIDR address block.

[0151] In some embodiments, the device further includes a marking module, configured to mark that the target network address has been allocated in the secondary cache in the case where the target network address is successfully saved to the target database.

[0152] In some embodiments, the device further includes an identifier storage module, configured to generate a target identifier corresponding to the address allocation request in response to receiving the address allocation request, and store the target identifier in the first-level cache after obtaining the target network address; the address allocation module 406 is specifically configured to: associate a callback function with the target network address and return the result to the sender of the address allocation request; the device further includes an identifier deletion module, configured to delete the target identifier in the first-level cache in response to the sender invoking the callback function.

[0153] In some embodiments, the identifier storage module is specifically configured to: associate the target identifier with a rollback function and store the result in the first-level cache; the device further includes a rollback module, configured to perform a rollback operation corresponding to the target identifier through the first-level cache based on the rollback function in response to the callback function not being invoked by the sender within a specified duration.

[0154] In some embodiments, the network address allocation method is executed by a target server, and the sender of the address allocation request is a service end; the device further includes a synchronization module, configured to: based on a preset first time interval, determine whether the difference between a first allocated address and a second allocated address is greater than a preset difference threshold, and if so, perform a synchronization operation on the allocated network addresses for the service end and the target server; where the first allocated address is the latest network address allocated by the target server to the service end, and the second allocated address is the latest network address allocated to the service end recorded by the service end; and / or, based on a preset second time interval, determine whether there is a difference between a third allocated address and a fourth allocated address, and if there is, perform a synchronization operation on the allocated network addresses for the service end and the target server; where the third allocated address is all the network addresses allocated by the target server to the service end, and the fourth allocated address is all the network addresses allocated to the service end recorded by the service end; the second time interval is greater than the first time interval.

[0155] The network address allocation device provided by the embodiments of the present disclosure can execute the network address allocation method provided by any embodiment of the present disclosure, and has corresponding functional modules and beneficial effects for executing the method.

[0156] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the device embodiments described above can refer to the corresponding process in the method embodiments, and will not be elaborated here.

[0157] Embodiments of the present disclosure provide an electronic device, which includes: a storage device storing a computer program thereon; and a processing device configured to execute the computer program in the storage device to implement the steps of any one of the methods in the present disclosure.

[0158] Reference is made below to Figure 5 , which shows a schematic structural diagram of an electronic device 500 suitable for implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Devices), PMPs (Portable Media Players), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is merely an example and should not impose any limitation on the functions and usage scope of the embodiments of the present disclosure.

[0159] As Figure 5 shown, the electronic device 500 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 501, which may perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other through a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0160] Generally, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other devices wirelessly or wirelessly to exchange data. Although Figure 5 the electronic device 500 with various devices is shown, it should be understood that it is not required to implement or include all the shown devices. Instead, more or fewer devices may be implemented or included.

[0161] In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes program code for performing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by a processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are performed.

[0162] In addition to the above methods and devices, an embodiment of the present disclosure may also be a computer program product that includes computer program instructions, and when the computer program instructions are run by a processor, the processor is caused to execute the method provided by the embodiment of the present disclosure. The computer program product may be written in any combination of one or more programming languages for performing the program code of the operations of the embodiment of the present disclosure. The programming languages include object-oriented programming languages such as Java, C++, etc., and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on a user computing device, partially on the user device, executed as a stand-alone software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0163] Furthermore, an embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon, and when the computer program instructions are run by a processor, the processor is caused to execute the network address allocation method provided by the embodiment of the present disclosure.

[0164] The computer-readable storage medium may employ any combination of one or more readable media. The readable media may be a readable signal medium or a readable storage medium. The readable storage medium may, for example, include but is not limited to an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical fiber, a portable compact disk read-only memory, an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0165] An embodiment of the present disclosure also provides a computer program product that includes a computer program / instructions, and when the computer program / instructions are executed by a processor, the network address allocation method in the embodiment of the present disclosure is implemented.

[0166] It is understood that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to users and the authorization of users should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0167] For example, when responding to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested by the user will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, an application program, a server, or a storage medium that performs the operations of the technical solutions of the present disclosure according to the prompt message.

[0168] As an optional but non-limiting implementation manner, the manner of sending a prompt message to the user in response to receiving an active request from the user may be, for example, in the form of a pop-up window, and the prompt message may be presented in text in the pop-up window. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0169] It is understood that the above process of notifying and obtaining user authorization is only illustrative and does not limit the implementation manners of the present disclosure. Other manners that meet relevant laws and regulations can also be applied to the implementation manners of the present disclosure.

[0170] It should be noted that in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of another identical element in the process, method, article or device including the said element.

[0171] The above are only the specific implementation manners of the present disclosure, enabling those skilled in the art to understand or implement the present disclosure. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to these embodiments described herein, but will be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A network address allocation method, characterized in that: The method comprises: In response to receiving an address allocation request, a first network address is preferentially obtained from a first-level cache in a multi-level cache architecture based on the address allocation request; wherein the address allocation request is used to request allocation of an available target network address, and the multi-level cache architecture includes at least a first-level cache and a second-level cache; the first-level cache is used to store currently allocatable network addresses; the second-level cache is used to store a preset first classless inter-domain routing CIDR address block, and the second-level cache is marked with whether each IP address included in the first CIDR address block is currently allocated; In the case that the number of the first network addresses does not satisfy the address allocation request, determining the number of network addresses to be obtained from the secondary cache, and obtaining currently unallocated second network addresses from the secondary cache until the number of the second network addresses reaches the number of network addresses; The first network address and the second network address are used as target network addresses required by the address allocation request, and the address allocation request is responded to.

2. The method according to claim 1, characterized in that The acquiring the currently unallocated second network addresses from the secondary cache until the number of the second network addresses reaches the number of network addresses includes: Perform at least one pointer movement operation on the first CIDR address block to search for currently unassigned second network addresses from the IP addresses in the first CIDR address block corresponding to the pointer movement operation, until the number of the second network addresses reaches the number of network addresses; The number of moving digits corresponding to the first pointer movement operation is a preset first digit, and the number of moving digits corresponding to the non-first pointer movement operation is not less than the number of moving digits corresponding to the last movement operation of the non-first movement operation.

3. The method according to claim 2, characterized in that In the case where the number of moving bits corresponding to the last moving operation of the non-first moving operation is less than the preset second number of bits, the number of moving bits corresponding to the non-first pointer moving operation is a specified multiple of the number of moving bits corresponding to the last moving operation of the non-first moving operation; When the number of movement bits corresponding to the last movement operation of the non-first movement operation is equal to the second number of bits, the number of movement bits corresponding to the non-first pointer movement operation is equal to the second number of bits.

4. The method according to claim 2, characterized in that: The secondary cache marks, through a target bitmap, whether each IP address in the first CIDR address block is currently allocated; In the case where the target network address includes an IP address, the target bitmap includes at least a first bitmap, and the number of IP addresses corresponding to each bit of the first bitmap is one.

5. The method according to claim 4, characterized in that The target bitmap further includes a second bitmap, wherein the number of IP addresses corresponding to each bit of the second bitmap is a specified number, and the specified number is greater than one; In a case where the second network addresses acquired through the at least one pointer movement operation do not reach the number of network addresses, acquiring the currently unallocated second network addresses from the secondary cache until the number of the second network addresses reaches the number of network addresses, further comprising: searching for currently unallocated second network addresses based on the first bitmap until the number of the second network addresses reaches the number of network addresses or until a preset stop condition is reached; When the preset stop condition is reached, a second CIDR address block that currently has assignable IP addresses is searched based on the second bitmap, and a second network address is searched from the IP addresses in the second CIDR address block based on the first bitmap until the number of second network addresses reaches the number of network addresses; wherein the number of IP addresses contained in the second CIDR address block is equal to the specified number.

6. The method according to claim 1, characterized in that The method further comprises: In the case that more available network addresses than the number of network addresses are obtained from the secondary cache, the remaining network addresses except the second network address among the available network addresses are stored in the primary cache.

7. The method according to claim 1, characterized in that The method further comprises: in response to receiving the address allocation request, generating a target identifier corresponding to the address allocation request, and after obtaining the target network address, storing the target identifier in the first-level cache; The allocating the target network address to the sender of the address allocation request comprises: associating a callback function with the target network address and returning it to the sender of the address allocation request; The method further includes: in response to the sender calling the callback function, deleting the target identifier in the first-level cache.

8. The method according to claim 1, characterized in that The network address allocation method is executed by the target service end, and the sender of the address allocation request is the service end; the method also includes: Based on a preset first time interval, determine whether the difference between the first allocated address and the second allocated address is greater than a preset difference threshold, and if so, perform a synchronization operation of the allocated network addresses for the service end and the target service end; wherein the first allocated address is the latest network address allocated to the service end recorded by the target service end, and the second allocated address is the latest network address allocated to the service end recorded by the service end; and / or, Based on a preset second time interval, determine whether there is a difference between the third allocated address and the fourth allocated address. If so, perform a synchronization operation of the allocated network addresses for the business end and the target server end; wherein the third allocated address is all network addresses that have been allocated to the business end and recorded by the target server end, and the fourth allocated address is all allocated network addresses that have been recorded by the business end; and the second time interval is greater than the first time interval.

9. A network address allocation device, characterized in that: include: A first acquisition module is configured to, in response to receiving an address allocation request, preferentially acquire a first network address from a first-level cache in a multi-level cache architecture based on the address allocation request; wherein the address allocation request is used to request allocation of an available target network address, and the multi-level cache architecture includes at least a first-level cache and a second-level cache; the first-level cache is used to store currently allocatable network addresses; the second-level cache is used to store a preset first classless inter-domain routing CIDR address block, and the second-level cache is marked with whether each IP address included in the first CIDR address block is currently allocated; a second acquisition module, configured to determine the number of network addresses to be acquired from the secondary cache when the number of the first network addresses does not satisfy the address allocation request, and acquire currently unallocated second network addresses from the secondary cache until the number of the second network addresses reaches the number of network addresses; The address allocation module is used to respond to the address allocation request by using the first network address and the second network address as target network addresses required by the address allocation request.

10. An electronic device, characterized in that: The electronic device comprises: a storage device having a computer program stored thereon; A processing device, used to execute the computer program in the storage device to implement the steps of the network address allocation method according to any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and the computer program is used to execute the network address allocation method according to any one of claims 1 to 8.

12. A computer program product, characterized in that The invention comprises a computer program, which implements the network address allocation method according to any one of claims 1 to 8 when being executed by a processor.