Distributed serial number generation method, node, system, device, medium and program
By decoupling the deployment of the distributed serial number generation system and the serial number generation method, the problems of insufficient scenario adaptability and disaster recovery capability in the existing technology are solved, realizing the independence and efficiency of serial number generation, adapting to general scenarios and improving system scalability.
Patent Information
- Application Number
- CN202511439138.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-09
- Publication Date
- 2026-01-30
AI Technical Summary
In existing technologies, distributed sequence number generation schemes are highly dependent on specific scenarios, making them difficult to adapt to general scenarios. Furthermore, they are prone to transaction anomalies when applications crash or containers scale elastically, resulting in insufficient disaster recovery capabilities.
A distributed sequence number generation system is adopted, which decouples the sequence number generation node and the resource block allocation node. It uses global allocation pointers and atomic operations to generate sequence numbers, and combines a dual-caching structure and memory block identifier management to ensure the independence and efficiency of sequence number generation.
The generated serial numbers are independent of the scenario, adaptable to common scenarios, improving the system's scalability and disaster recovery capabilities, and avoiding transaction anomalies and resource waste.
Smart Images

Figure CN121435289A_ABST
Abstract
Description
Technical Field
[0001] This application pertains to the fields of computer science and finance, and particularly relates to a distributed serial number generation method, node, system, device, medium, and program. Background Technology
[0002] With the widespread adoption of electronic payments, the financial sector's payment transaction systems are constantly innovating in terms of technology to support the rapid development of electronic payment services. Currently, distributed transaction systems have become a common technical solution in the payment field, and distributed sequence number generation, as an application that uniquely identifies transactions, plays a crucial role in the payment process.
[0003] Among related technologies, the main scheme for generating distributed sequence numbers includes the allocation of sequence numbers by a unified management node. However, this method has the disadvantage of being highly dependent on application scenarios and difficult to adapt to general scenarios. Summary of the Invention
[0004] This application provides a distributed serial number generation method, node, system, device, medium, and program that can generate scenario-independent serial numbers, thereby adapting to general scenarios.
[0005] In a first aspect, embodiments of this application provide a distributed sequence number generation method, applied to a sequence number generation node, the sequence number generation node having: a sequence number generation device BG and a sequence number resource block cache management device CM, the method comprising: The BG receives a serial number generation request sent by the application, and the generation request includes the target serial number resource name; The CM determines the target memory block corresponding to the target serial number resource name from the preset correspondence between serial number resource names and memory blocks based on the target serial number resource name. Obtain the last currently allocated sequence number pointed to by the global allocation pointer in the target memory block through CM; The first global request sequence number is obtained by updating the last currently allocated sequence number through atomic operations based on the first sequence number interval update step size by CM. The first sequence number interval update step size is the update step size of the first sequence number interval currently cached in the target memory block. The CM sends the first global request sequence number, the maximum value of the first sequence number range, and the memory block identifier of the target memory block to the BG. The maximum value of the first sequence number range is the maximum value of the first sequence number range. If the first global request sequence number is less than the maximum value of the first sequence number range, the BG will return the first global request sequence number to the application.
[0006] Secondly, embodiments of this application provide a serial number generation node, which includes: a serial number generation device BG and a serial number resource block cache management device CM; BG is used to receive serial number generation requests sent by applications. The generation request includes the target serial number resource name. CM is used to determine the target memory block corresponding to the target serial number resource name from the preset correspondence between serial number resource name and memory block, based on the target serial number resource name. CM is also used to obtain the first currently allocated last sequence number pointed to by the global allocation pointer in the target memory block; CM is also used to update the last currently allocated sequence number through atomic operations based on the first sequence number interval update step size to obtain the first global request sequence number; the first sequence number interval update step size is the update step size of the first sequence number interval currently cached in the target memory block; CM is also used to send the first global request sequence number, the maximum value of the first sequence number range, and the memory block identifier of the target memory block to BG, where the maximum value of the first sequence number range is the maximum value of the first sequence number range. BG is also used to return the first global request sequence number to the application if the first global request sequence number is less than the maximum value of the first sequence number range.
[0007] Thirdly, embodiments of this application provide a distributed serial number generation system, including at least one serial number generation node as described in the second aspect.
[0008] Fourthly, embodiments of this application provide an electronic device, which includes: a processor and a memory storing computer program instructions; When the processor executes computer program instructions, it implements a distributed serial number generation method as described in the first aspect.
[0009] Fifthly, embodiments of this application provide a computer-readable storage medium storing computer program instructions, which, when executed by a processor, implement the distributed serial number generation method of the first aspect.
[0010] Sixthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the distributed serial number generation method as described in the first aspect.
[0011] The technical solution of this application embodiment receives a serial number generation request sent by an application, the generation request including a target serial number resource name; based on the target serial number resource name, it obtains the first currently allocated last serial number pointed to by the global allocation pointer in the target memory block; it updates the first currently allocated last serial number through atomic operations according to the first serial number interval update step size to obtain a first global request serial number; if the first global request serial number is less than the maximum value of the first serial number interval, it returns the first global request serial number to the application. According to this application embodiment, a serial number required by the application can be generated by the serial number generation node based on the serial number resource name sent by the application. The generated serial number is independent of the scenario, therefore, it can be adapted to general scenarios. Attached Figure Description
[0012] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 This is a schematic diagram of a distributed serial number generation system provided in some embodiments of this application; Figure 2 This is a schematic diagram of the distributed serial number generation process provided in some embodiments of this application; Figure 3 This is a schematic diagram of the distributed serial number generation process provided in some embodiments of this application; Figure 4 This is a flowchart illustrating the implementation of step 510 provided in some embodiments of this application; Figure 5 These are schematic diagrams of the structure of electronic devices provided in some embodiments of this application. Detailed Implementation
[0014] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.
[0015] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element.
[0016] Before providing a detailed description of the embodiments of the present invention, a method for generating distributed sequence numbers in related technologies will be introduced. In related technologies, there are two main methods for generating distributed sequence numbers. The first method involves adding application host uniqueness information to the generated sequence number to separate different intervals and generate non-repeating sequence numbers; for example, the Snowflake algorithm. The second method involves dividing the sequence number into intervals based on the total number of application nodes, with a centrally managed node uniformly allocating the sequence number segments.
[0017] However, the two methods mentioned above have the following problems: For schemes using the snowflake algorithm, it is usually necessary to focus on the information of the application node itself, resulting in long sequence numbers that cannot meet the requirements for sequence numbers within a certain range. For schemes where allocation is performed by a unified management node, the application scenarios are highly correlated, making it difficult to determine whether they are suitable for cross-scenario applications. In addition, if the receiving node application crashes, additional processing is required when recovering data. The technical complexity of different scenarios may need to be evaluated separately, resulting in poor scalability.
[0018] Furthermore, to enhance the disaster recovery capabilities of information systems, it is necessary to ensure that previously generated serial number records are not lost when the application restarts; otherwise, serial number conflicts may occur, leading to a large number of transaction anomalies. However, the aforementioned technologies face the problem of transaction anomalies caused by the elastic scaling of containers; simultaneously, if the serial number generation application is deployed in a single centralized manner, disaster recovery and fault tolerance issues arise.
[0019] Therefore, to improve the applicability and scalability of distributed serial number generation, this application provides a distributed serial number generation system, a distributed serial number generation method, an apparatus, a device, a storage medium, and an application program.
[0020] See Figure 1This is a schematic diagram of a distributed serial number generation system provided in an exemplary embodiment of this application, as shown below. Figure 1 As shown, the distributed sequence number generation system comprises two main parts that function as application node entities: a sequence number generation node 110 and a sequence number resource block allocation node 120. The sequence number generation node 110 includes a sequence number generation device 111, a sequence number resource block routing device 112, and a sequence number resource block cache management device 113. The sequence number resource block allocation node 120 includes a sequence number resource block allocation device 121. The sequence number resource block allocation node 120 is used to allocate sequence number ranges to the sequence number resource block cache management device 113 of the sequence number generation node 110. For the serial number generation node 110, an independently implemented application node can be used, and the programming language used for implementation is not limited.
[0021] For the sequence number resource block allocation node 120, commonly used storage media components can be selected. For example, caching technology components such as Redis and memcached can be used, as well as relational databases such as MySQL and DB2. Alternatively, a self-organized and independently implemented application node can be used to operate on the resource blocks. In this embodiment, the sequence number resource block allocation node 120 using MySQL is used as an example to illustrate the technical solution.
[0022] It should be noted that the distributed sequence number generation system may include m sequence number generation nodes 110 and n sequence number resource block allocation nodes 120. Both m and n are integers greater than or equal to 1. There is no necessary relationship between m and n, and the values of m and n can be set according to actual business needs. Figure 1 Taking m=2 and n=3 as an example only, it does not constitute a limitation on the number of sequence number generation nodes 110 and sequence number resource block allocation nodes 120.
[0023] In the aforementioned distributed serial number generation system, the serial number generation nodes and serial number resource block allocation nodes are deployed in a distributed manner, which decouples serial number generation from resource allocation. The serial number generation nodes and serial number resource block allocation nodes can be dynamically scaled up and down in a stateless manner as business develops, and there is no data recovery problem.
[0024] The distributed serial number generation method provided in the embodiments of this application will be described below.
[0025] The distributed sequence number generation method provided in this application embodiment can be applied to electronic payment scenarios to generate distributed sequence numbers for transactions.
[0026] See Figure 2The above is a flowchart of a distributed sequence number generation method provided in some embodiments of this application. The distributed sequence number generation method provided in these embodiments can be applied to a sequence number generation node; that is, the execution body of this method is the sequence number generation node. The sequence number generation node has: a sequence number generation device (Bill Generator, BG) and a sequence number resource block cache management device (Cache Manager, CM). Figure 2 As shown, the method includes steps 210-260, which will be explained in detail below.
[0027] Step 210. Receive the serial number generation request sent by the application through BG. The generation request includes the target serial number resource name.
[0028] The application here can be any application that needs to generate a serial number; for example, the application can be a QR code application.
[0029] When a serial number needs to be generated, the application can randomly select one node from the m serial number generation nodes in the distributed serial number generation system and send a serial number generation request to the selected node. The selected serial number generation node can then generate the corresponding serial number through steps 210-260.
[0030] The key elements in the generation request include: the `Generate Sequence Number Command` and the `Sequence Number Resource Name`. The `Generate Sequence Number Command` is a predefined, unique string or numeric code. It tells the sequence number generation node that the specific operation to be performed in this request is to generate a sequence number. The `Sequence Number Resource Name` is a logical identifier that tells the sequence number generation node the customized requirements for the sequence number to be generated in this request. Through the `Sequence Number Resource Name`, a general-purpose distributed sequence number generation physical infrastructure can simultaneously provide isolated sequence number generation services to multiple different business parties.
[0031] The target sequence number resource name refers to the sequence number resource name carried in the generation request received by the sequence number generation node this time.
[0032] For example, when application A needs to generate a serial number, application A constructs a generation request, which contains at least two core fields: command: "generateBillNo" / / This is the command to generate a serial number. resourceName: "QR_CODE_PAYMENT" / / This is the "serial number resource name" Application A sends this generation request to a randomly selected sequence number generation node B. Node B's network receiving layer (such as an API Gateway or Web Server) parses the generation request and, seeing the command "generateBillNo", recognizes it as a request to generate a serial number. It then hands the request over to the BG module for processing. The BG module is invoked, and it extracts the resourceName "QR_CODE_PAYMENT" from the generation request, thus beginning its interaction with the CM to generate a serial number for Application A's business logic.
[0033] Step 220. Based on the target serial number resource name, the CM determines the target memory block corresponding to the target serial number resource name from the preset correspondence between serial number resource names and memory blocks.
[0034] A CM can include one or more memory blocks, each of which can be used to cache a sequence number range. The CM can retrieve the sequence number corresponding to the target sequence number resource name from the sequence number range cached in the memory block.
[0035] Internally, CM maintains a pre-defined mapping between serial number resource names and memory blocks (such as a Map dictionary). Based on this, after obtaining the target serial number resource name transmitted by BG, CM can quickly determine the memory block corresponding to the target serial number resource name, i.e., the target memory block, based on the above mapping.
[0036] Step 230. Obtain the first currently allocated last sequence number pointed to by the global allocation pointer in the target memory block through CM.
[0037] Each memory block in the CM has its own independent global allocation pointer X, which points to the last allocated sequence number in the cached sequence number range within the memory block. Therefore, the CM can determine the last currently allocated sequence number in the current memory block based on the global allocation pointer in the target memory block, i.e., the first currently allocated last sequence number.
[0038] Step 240. The first global request sequence number is obtained by updating the last currently allocated sequence number using atomic operations based on the first sequence number interval update step size through CM; the first sequence number interval update step size is the update step size of the first sequence number interval currently cached in the target memory block.
[0039] As mentioned earlier, each memory block caches a sequence number range, and different memory blocks cache different sequence number ranges. Each sequence number range cached in a memory block corresponds to an update step size, which controls the increment interval of the sequence numbers within a single sequence number range. The update step size is an integer greater than or equal to 1.
[0040] After determining the last currently assigned sequence number, the CM updates this last currently assigned sequence number based on the first sequence number interval update step size, thereby determining the sequence number to be assigned this time, i.e., the first global request sequence number. The first sequence number interval update step size is the update step size corresponding to the first sequence number interval.
[0041] In some embodiments, the update step size can be the number m of sequence number generation nodes included in the distributed sequence number generation system. The first global request sequence number can be obtained by adding the first currently assigned last sequence number to the first sequence number interval update step size. For example, if the first currently assigned last sequence number is 10001 and the first sequence number interval update step size is 1, then the first global request sequence number is 10002.
[0042] In a cloud-native environment, a distributed sequence number generation system typically has multiple sequence number generation nodes running simultaneously to achieve load balancing and high availability. This update step size mechanism ensures that the same sequence number range can be shared by multiple sequence number generation nodes and generate sequence numbers simultaneously without any conflicts. By setting the update step size, within a given sequence number range, staggered increments are used—one sequence number generation node takes even-numbered positions, and another takes odd-numbered positions—ensuring that every number within the range is allocated without waste. This achieves 100% sequence number utilization, eliminating issues of transaction downtime and wasted sequence number resources. Furthermore, by setting the update step size, sequence number generation nodes do not need to communicate or coordinate to decide "who gets the next number." Each sequence number generation node only needs to perform a simple local atomic addition based on its own "node number" and a fixed sequence number generation node to work lock-free and efficiently, improving node performance.
[0043] In a memory block, X is not a fixed value but a dynamically changing variable. The value of X is dynamically updated as sequence numbers within the sequence number range of the memory block are allocated. Specifically, the minimum value of the cached sequence number range in the memory block is represented by the minimum value of bill_no. The initial value of X = minimum value of bill_no + node index, where the node index refers to the index of the sequence number generating node of the memory block. Different sequence numbers correspond to different indexes. The changing pattern of X can be expressed as: X = X + step, where step represents the update step size. That is, after each allocation of a sequence number in the memory block, the value of X increases by one update step size. Thus, after allocating the first global request sequence number, X can be updated from pointing to the last currently allocated sequence number to pointing to the first global request sequence number.
[0044] Step 250. Send the first global request sequence number, the maximum value of the first sequence number range, and the memory block identifier of the target memory block to the BG through the CM. The maximum value of the first sequence number range is the maximum value of the first sequence number range.
[0045] The maximum value of the first sequence number interval refers to the upper limit of the first sequence number interval.
[0046] If the first global request sequence number is greater than or equal to the maximum value of the first sequence number range, it indicates that the cached sequence numbers in the target memory block are about to run out. Continuing to use sequence numbers from the target memory block at this point may result in duplicate or invalid sequence numbers being allocated. Therefore, to prevent the allocation of invalid or duplicate sequence numbers, the first global request sequence number is only allocated to the application if it is less than the maximum value of the first sequence number range. Based on this, after determining the first global request sequence number, the CM sends the first global request sequence number, the maximum value of the first sequence number range, and the memory block identifier of the target memory block to the BG, so that the BG can determine whether the first global request sequence number is less than the maximum value of the first sequence number range.
[0047] Step 260. If the first global request sequence number is less than the maximum value of the first sequence number range, return the first global request sequence number to the application via BG.
[0048] After receiving the first global request sequence number and the maximum value of the first sequence number range transmitted by the CM, the BG compares the first global request sequence number and the maximum value of the first sequence number range. If it is determined that the first global request sequence number is less than the maximum value of the first sequence number range, the BG uses the first global request sequence number as the sequence number to be assigned to the application and returns it to the application.
[0049] In the technical solution provided in this embodiment, the serial number required by the application can be generated by the serial number generation node based on the serial number resource name sent by the application. The generated serial number is independent of the scenario, so it can be adapted to general scenarios.
[0050] In some embodiments, to improve the success rate of serial number generation, the CM can adopt a dual-caching structure, i.e., the CM has two memory blocks that can be switched between. When one memory block is in use, the other serves as a backup. Both memory blocks cache serial number ranges, and the serial number ranges cached in the two memory blocks are different. The target memory block mentioned above is one of the two memory blocks. Based on this, see [link to relevant documentation]. Figure 3 After step 250 above, steps 310-350 can also be performed.
[0051] Step 310. If the first global request sequence number is greater than or equal to the maximum value of the first sequence number range, determine whether the memory block identifier of the target memory block is consistent with the memory block identifier of the memory block currently used by the CM.
[0052] Each memory block in CM has a corresponding memory block identifier. Different memory blocks correspond to different memory block identifiers, and different memory blocks can be distinguished by the memory block identifier.
[0053] Considering that multiple different services can request sequence numbers from the sequence number generation node, after the CM transmits the first global request sequence number and the maximum value of the first sequence number range to the RG, it may continue to process sequence number generation requests from other services. During this process, the CM may switch the memory block it is using. In this embodiment, different processing methods are adopted for cases where the first global request sequence number is greater than or equal to the maximum value of the first sequence number range, depending on whether the memory block has been switched or not. Therefore, when the first global request sequence number is greater than or equal to the maximum value of the first sequence number range, the CM first determines whether a memory block switch has occurred.
[0054] If the RG determines that the first global request sequence number is greater than or equal to the maximum value of the first sequence number range, the RG can transmit a message to the CM indicating that the first global request sequence number is greater than or equal to the maximum value of the first sequence number range. After receiving the message, the CM determines the memory block currently in use and obtains the memory identifier of the currently used memory block. The CM compares the memory identifier of the currently used memory block with the memory identifier of the target memory block to determine whether the currently used memory block is still the target memory block.
[0055] If the memory block identifier of the target memory block is the same as the memory block identifier of the memory block currently used by CM, it is determined that no memory block switching has occurred, and the currently used memory block is still the target memory block. If the memory block identifier of the target memory block is different from the memory block identifier of the memory block currently used by CM, it is determined that CM has performed a memory switching, and the currently used memory block is another memory block other than the target memory block.
[0056] Step 320. If the memory block identifier of the target memory block is inconsistent with the memory block identifier of the currently used memory block, determine the second currently allocated last sequence number pointed to by the global allocation pointer in the currently used memory block through CM.
[0057] As mentioned earlier, the discrepancy between the memory block identifier of the target memory block and the memory block identifier of the currently used memory block indicates that a memory block switch has occurred in the CM. The currently used memory block is no longer the target memory block, but another memory block. This memory block may still have enough sequence number resources available for allocation. Therefore, in this case, the second currently allocated last sequence number pointed to by the global allocation pointer in the currently used memory block can be determined through the CM, so as to determine the second global request sequence number based on the second currently allocated last sequence number.
[0058] Step 330. The second global request sequence number is obtained by updating the last currently allocated sequence number using atomic operations through CM based on the second sequence number interval update step size. The second sequence number interval update step size is the update step size of the second sequence number interval cached in the currently used memory block.
[0059] Here, the second sequence number range refers to the sequence number range cached in the currently used memory block, and the update step size of the second sequence number range is the update step size corresponding to the second sequence number range.
[0060] The method by which CM updates the last currently assigned sequence number based on the second sequence number interval update step size to obtain the second global request sequence number is the same as the method by which CM updates the last currently assigned sequence number based on the first sequence number interval update step size to obtain the first global request sequence number. Please refer to the relevant description in the above embodiments. To avoid repetition, it will not be elaborated further here.
[0061] Step 340. Send the second global request sequence number, the maximum value of the second sequence number range, and the region identifier of the currently used memory block to the BG through the CM. The maximum value of the second sequence number range is the maximum value of the sequence number range.
[0062] After obtaining the second global request sequence number, the CM sends the second global request sequence number, the maximum value of the second sequence number range, and the region identifier of the currently used memory block to the BG. The BG then determines whether the second global request sequence number is less than the maximum value of the second sequence number range, thereby determining whether the cached sequence number in the currently used memory block has been exhausted.
[0063] Step 350. If the BG determines that the second global request sequence number is less than the maximum value of the second sequence number range, it returns the second global request sequence number to the application.
[0064] If the BG determines that the second global request sequence number is less than the maximum value of the second sequence number range, it determines that the cached sequence number in the currently used memory block is not exhausted, thus determining that the second global request sequence number is a valid and unique sequence number. Therefore, the second global request sequence number is determined as the sequence number to be assigned to the application, and the second global request sequence number is returned to the application.
[0065] In this technical solution, CM adopts a double-buffering structure. After the serial numbers cached in one memory block are exhausted, the serial numbers cached in the other memory block can be used, thereby improving the success rate of serial number generation.
[0066] In some embodiments, see Figure 3 After step 340 above, step 360 can also be performed.
[0067] Step 360. If the BG determines that the second global request sequence number is greater than or equal to the maximum value of the second sequence number range, it returns the first error message to the application.
[0068] If the second global request sequence number is greater than or equal to the maximum value of the second sequence number range, it means that all the cached sequence numbers in the two memory blocks of CM have been used up. At this time, it is impossible to allocate a sequence number to the application, so the first error message is returned to the application, so that the application can select other sequence number generation nodes to generate sequence numbers.
[0069] In some embodiments, where the CM employs a dual-buffered structure, see [link to relevant documentation]. Figure 3 After step 250 above, steps 410-430 can also be performed.
[0070] Step 410. If the memory block identifier of the target memory block is consistent with the memory block identifier of the currently used memory block, the third currently allocated last sequence number is updated by the global allocation pointer in the spare memory block through atomic operation based on the third sequence number interval update step size, so as to obtain the third global request sequence number. The third sequence number interval update step size is the update step size of the third sequence number interval cached in the spare memory block.
[0071] Here, the spare memory block refers to the memory block in CM other than the currently used memory block. The third sequence number range refers to the sequence number range cached in the spare memory block. The update step size of the third sequence number range refers to the update step size corresponding to the third sequence number range.
[0072] As mentioned earlier, the memory block identifier of the target memory block is the same as that of the currently used memory block, indicating that CM has not switched memory blocks and the currently used memory block is still the target memory block. However, the fact that the first global request sequence number is greater than or equal to the maximum value of the first sequence number range indicates that the currently cached sequence numbers in the target memory block have been exhausted, and the first sequence number range currently cached in the target memory block cannot be used to generate the application's corresponding sequence number. In this case, to improve the success rate of sequence number generation, CM can attempt to use the sequence numbers cached in the spare memory block to allocate a third global request sequence number to the application.
[0073] The method by which CM updates the last currently assigned sequence number based on the third sequence number interval update step size to obtain the third global request sequence number is the same as the method by which CM updates the last currently assigned sequence number based on the first sequence number interval update step size to obtain the first global request sequence number. Please refer to the relevant description in the above embodiments. To avoid repetition, it will not be elaborated further here.
[0074] Step 420. If the third global request sequence number is less than the maximum value of the third sequence number range, switch the spare memory block to the currently used memory block through CM, and switch the target memory block to the spare memory block.
[0075] After obtaining the third global request sequence number, the CM independently determines whether the third global request sequence number is less than the maximum value of the third sequence number range. If the third global request sequence number is less than the maximum value of the third sequence number range, it means that the sequence number of the current spare memory block cache is not exhausted. At this time, the CM can switch the memory block through the cache switching switch, thereby switching the spare memory block to the currently used memory block and switching the target memory block to the spare memory block, that is, swapping the identities of the two memory blocks.
[0076] Step 430. Perform step 320 above.
[0077] After the memory block switch is completed, the memory block currently used by CM changes from the previous target memory block to another memory block; that is, the currently used memory block becomes the previous spare memory block. At this time, a new global request sequence number is allocated to the application based on the new currently used memory block. The BG (Browser Group) checks whether the newly generated global request sequence number is less than the maximum value of the cached sequence number range in the new currently used memory block. If it is less, the newly generated global request sequence number is used as the application's corresponding sequence number, and thus the newly generated global request sequence number is returned to the application. This process is consistent with steps 320-350 above. Therefore, after the memory block switch is completed, the third currently allocated last sequence number range is updated to the second currently allocated last sequence number, the update step size of the third sequence number range is updated to the update step size of the second sequence number range, and the maximum value of the third sequence number range is the maximum value of the third sequence number range, thus returning to execute step 320 above.
[0078] In some embodiments, the distributed sequence number generation system further includes a sequence number resource block allocation node, which is used to allocate sequence number ranges to memory blocks in the CM of the sequence number generation node. Based on this, to further improve the success rate of sequence number generation, see [link to relevant documentation]. Figure 3 After step 410 above, steps 510 and 520 can also be performed.
[0079] Step 510. If the third global request sequence number is greater than or equal to the maximum value of the third sequence number range, apply for a new sequence number range from the sequence number resource block allocation node asynchronously through CM to update the cached sequence number range in the currently used memory block.
[0080] If the third global request sequence number is greater than or equal to the maximum value of the third sequence number range, it means that the sequence numbers cached in the spare memory block have also been exhausted. At this time, CM can apply to the sequence number resource block allocation node for a new sequence number range to update the cached sequence number range in the currently used memory block.
[0081] Step 520. Perform step 320 above.
[0082] After updating the cached sequence number range in the currently used memory block, the cached second sequence number range in the currently used memory block is updated to the updated sequence number range, that is, the updated sequence number range is used as the second sequence number range. At this time, step 320 is executed so that the application can be reassigned a sequence number based on the updated sequence number range.
[0083] In some embodiments, the distributed sequence number generation system may include multiple sequence number resource block allocation nodes, and the sequence number generation node can obtain different sequence number ranges from different sequence number resource block allocation nodes. The sequence number generation node also includes a sequence number resource block routing device (Cache Router, CR), whose core responsibility is to determine which sequence number resource block allocation node the CM (Continuous Message Controller) should obtain the sequence number resource block and sequence number range from. Based on this, see [link to relevant documentation]. Figure 4 In step 510 above, CM can update the sequence number range in the currently used memory block through the following steps 5101-5104.
[0084] Step 5101. Send routing information instructions to CR via CM.
[0085] Here, the routing information instruction is used to request the CR to determine which sequence number resource block allocation node the CM should go to to obtain the sequence number range.
[0086] Step 5102. The CR responds to the routing information command and returns the target fragment number to the CM.
[0087] Here, the shard number is the identifier of the sequence number resource block allocation node. One shard number corresponds to one sequence number resource block allocation node, and different shard numbers correspond to different sequence number resource block allocation nodes. In this embodiment, taking MySQL as an example, one sequence number resource block allocation node is equivalent to one MySQL shard. The target shard number is used to instruct the CM to obtain the sequence number range from the target sequence number resource block allocation node corresponding to the target shard number.
[0088] Internally, the CR can maintain a preset fragment number sequence that is consistent with the number of nodes allocating the sequence number resource block. This preset fragment number sequence can be a preset random sequence. In response to routing information instructions, the CR can determine the target fragment number based on the fragment number sequence.
[0089] In some embodiments, the CM can send different types of routing information commands to the CR. In response to these different types of routing information commands, the CR can determine the target fragment number in different ways. These routing information commands may include, but are not limited to, random routing information commands, specified routing information commands, and commands to terminate specified routing information.
[0090] In some embodiments, when the routing information instruction is a random routing information instruction, the first fragment number in the preset fragment number sequence can be returned to the CM as the target fragment number through the CR.
[0091] In some embodiments, when the routing information instruction is a specified routing information instruction that includes a specified fragment number, the CR updates the preset fragment number sequence to the specified fragment number sequence and returns the specified fragment number as the target fragment number to the CM. All fragment numbers in the specified fragment number sequence are the specified fragment number. Specifically, when the CM sends a specified routing information instruction to the CR, the CR rewrites the preset fragment number sequence to the specified fragment number and returns the specified fragment number value to the CM.
[0092] In some embodiments, when the routing information instruction is a termination specified routing information instruction, a random sequence of fragment numbers is regenerated by CR, and the first fragment number in the random sequence is returned to CM as the target fragment number.
[0093] Step 5103. Determine the target sequence number resource block allocation node corresponding to the target fragment number through CM.
[0094] As mentioned earlier, the fragment number is the identifier of the sequence number resource block allocation node. One fragment number corresponds to one sequence number resource block allocation node. Therefore, after the CM obtains the target fragment number returned by the CR, it can determine the target sequence number resource block allocation node corresponding to the target fragment number.
[0095] Step 5104. Request a new sequence number range from the target sequence number resource block allocation node through CM to update the cached sequence number range in the currently used memory block.
[0096] In some embodiments, the CM maintains a sequence number resource block allocation node link pool, which includes links corresponding to each sequence number resource block allocation node in the distributed sequence number generation system. The CM can interact with the target sequence number resource block allocation node based on the target link corresponding to the target sequence number resource block allocation node, thereby updating the cached sequence number range in the currently used memory block.
[0097] In some embodiments, in step 5104 above, CM can update the cached sequence number range in the currently used memory block through the following steps 51041-51045.
[0098] Step 51041. Generate a target operation record serial number through CM and record the target operation record serial number in the first current inventory ledger of the target sequence number resource block allocation node; the target operation record serial number includes: target fragment number, host IP address information of the target sequence number resource block allocation node, current time, and the local incrementing sequence pointed to by the global allocation pointer in the currently used memory block.
[0099] Based on the target fragment number returned by the CR, the CM generates a target operation record sequence number. The main components of this sequence number are: fragment number + host IP information + current time + local incrementing sequence. Therefore, the target operation record sequence number includes: the target fragment number, the host IP address information of the resource block allocation node, the current time, and the local incrementing sequence pointed to by the global allocation pointer in the currently used memory block. The local incrementing sequence refers to the global request sequence number currently pointed to by the global allocation pointer, which increments with each outgoing request from the CM.
[0100] Step 51042. Determine the target link corresponding to the target sequence number resource block allocation node from the sequence number resource block allocation node link pool using CM.
[0101] After generating the target operation record serial number, the CM can select the target link corresponding to the target sequence number resource block allocation node from the sequence number resource block allocation node link pool based on the target fragment number, and then perform update operations on the target sequence number resource block allocation node based on the target link.
[0102] Step 51043. Based on the target link, the CM requests the target sequence number resource block allocation node to allocate a new sequence number range based on the operation flow account.
[0103] CM performs an application operation on the target sequence number resource block allocation node based on the target link, in order to request the target sequence number resource block allocation node to allocate a new sequence number range corresponding to the target operation record serial number.
[0104] In some embodiments, the CM may use update SQL statements to perform the application operation. Key information in the update SQL statements may include: "UPDATE tbl_bill_no SET bill_no = MOD(bill_no, maximum value of bill_no) + resource block length, Operation log serial number = '[newly generated serial number]' WHERE Serial number resource name = '[requested resource name]' Among them, "bill_no = MOD(bill_no, maximum value of bill_no) + resource block length" is the core of the sequence number range allocation logic. It completes two things at once: "MOD(bill_no, maximum value of bill_no)" and "+ resource block length".
[0105] "MOD(bill_no, bill_no maximum value)" means that through the modulo operation, when bill_no is approaching the maximum value, this operation will reset bill_no back to the starting point. bill_no refers to the global request serial number pointed to by the global allocation pointer. For example: Suppose the current bill_no = 9999998, bill_no maximum value = 9999999, and the resource block length = 1000. MOD(9999998, 9999999) = 9999998 (because 9999998 <9999999>), 9999998 + 1000 = 10000998, this value is already greater than the maximum value 9999999, so for the next allocation, bill_no = 10000998, MOD(10000998, 9999999) = 10000998 % 9999999 = 1000 (because 10000998 - 9999999 = 1000), 1000 + 1000 = 2000. Through MOD(bill_no, bill_no maximum value), the memory block is recycled. Instead of ending directly after 9999998, it wraps back to 1000 and continues. This greatly extends the service life of the distributed serial number system.
[0106] The role of "+ resource block length" is to perform the actual resource allocation. By "+ resource block length", the global request serial number bill_no pointed to by the global allocation pointer is advanced by the distance of a "segment", that is, the resource block length, indicating that this block of resources has been allocated.
[0107] Through the above "+ resource block length" operation, CM can successfully apply for a new serial number range from "the old bill_no value" to "(the old bill_no value + resource block length)".
[0108] "Operation record serial number = '[newly generated serial number]'" is used to stamp a "timestamp" and "unique identifier" on this application operation. Bind this application operation to a globally unique serial number. Its purpose is to provide a key for subsequent query operations. CM can then use this serial number to accurately query the meta-information of the serial number range allocated in this application in the tbl_bill_no_logs table.
[0109] "WHERE serial number resource name = '[requested resource name]'" is used to specify the operation object. Its purpose is to ensure that the serial number resource records of a specific service (such as the "QR code payment" service of an application) are updated, and other service resources are not misoperated, thus achieving multi-service isolation.
[0110] By requesting data, non-atomic operations that require querying, calculating, and updating can be avoided, thus eliminating the possibility of concurrent conflicts.
[0111] Step 51044. Query the metadata of the sequence number range allocated by the target sequence number resource block allocation node through CM. The metadata includes the maximum and minimum values of the sequence number range allocated this time, the sequence number generation node number, and the sequence number range update step size of the sequence number range allocated this time.
[0112] After completing the application operation for the target sequence number resource block allocation node, the CM can perform a query operation on the target sequence number resource block allocation node to determine the metadata of the sequence number range allocated by the target sequence number resource block allocation node this time. The metadata may include the minimum value, maximum value, corresponding update step size, node sequence number and other information of the sequence number range allocated by the node this time.
[0113] In some embodiments, the CM can perform query operations on the target sequence number resource block allocation node using a query SQL statement. Key information in the query SQL statement may include: SELECT This time, the minimum value of bill_no is allocated. This time, the maximum value of bill_no is allocated. Update step size, Node number FROM tbl_bill_no_logs WHERE Operation record serial number = '[Operation record serial number generated and passed in by CM]' Here, "minimum value of bill_no for this allocation" is the starting number, i.e., the minimum value, of the sequence number range allocated to CM this time, and it forms the basis for initializing the global allocation pointer X. "maximum value of bill_no for this allocation" is the ending number, i.e., the maximum value, of the sequence number range allocated to CM this time, and it is used to determine whether the cached sequence numbers in the memory block are exhausted. "Update step size" is the update step size corresponding to the sequence number range allocated to CM this time. CM determines the increment step size of the sequence number range based on the "update step size," achieving parallel, conflict-free generation by multiple nodes. "Node sequence number" is the unique identifier of the sequence number generation node to which CM resides.
[0114] Step 51045. Update the cached sequence number range in the currently used memory block based on metadata using CM.
[0115] After obtaining the metadata of the sequence number range allocated this time, CM can update the metadata to the currently used memory block, thereby updating the cached sequence number range in the currently used memory block.
[0116] For example, CM takes the minimum and maximum values of bill_no obtained in step 51044 above, updates the step size step, updates the node sequence number to the memory block currently used by CM, initializes the global allocation pointer X used to generate the sequence number, the initial value of X = minimum bill_no + node sequence number, and updates the maximum value of the sequence number range X_max to the maximum value of bill_no + node sequence number.
[0117] The above technical solution can reallocate new serial number ranges for the CM in the serial number generation node, realize the reuse of memory blocks in the CM, and improve the success rate of serial number generation by the serial number generation node.
[0118] In some embodiments, before executing the above-described distributed sequence number generation method, m sequence number generation nodes and n sequence number resource block allocation nodes are deployed, and each sequence number generation node and each sequence number resource block allocation node is initialized.
[0119] When initializing the sequence number resource block allocation node, resource block information can be pre-configured in each node according to actual business needs. For example, if four sequence number resource block allocation nodes are created in the distributed sequence number generation system, one piece of resource block information can be added to each node to improve throughput and disaster recovery fault tolerance. Information records can be added for different business scenarios, meaning that the resource block information in each sequence number resource block allocation node is not limited to one piece.
[0120] The sequence number included in the resource block information can be a random number with no pattern, or it can be a regularly increasing number. The specific settings can be configured according to business requirements.
[0121] In some embodiments, for each sequence number resource block allocation node, two data tables can be created in the sequence number resource block allocation node during initialization: the sequence number resource pool main table tbl_bill_no and the sequence number allocation log table tbl_bill_no_logs. The tbl_bill_no table is used to store sequence number resource block information, and the tbl_bill_no_logs table is used to store operation information for obtaining resource blocks. Here, resource blocks refer to sequence number ranges.
[0122] The key fields of the data table tbl_bill_no may include: fragment number, sequence number, resource name (PrimaryKey, PK), operation record serial number, bill_no, node sequence number, update step size, resource block length, and maximum value of bill_no.
[0123] The key fields of the data table tbl_bill_no_logs are: shard number, operation record serial number PK, minimum bill_no value for this allocation, maximum bill_no value for this allocation, update step size, and node sequence number.
[0124] Each sequence number resource block allocation node can create a trigger. The triggering condition can include: when a record in tbl_bill_no is updated, insert a record in tbl_bill_no_logs. The record data consists of: fragment number: the fragment number of the updated record in tbl_bill_no; operation record serial number: the updated operation record serial number in tbl_bill_no; minimum bill_no value for this allocation: the bill_no in tbl_bill_no before the record was updated; maximum bill_no value for this allocation: the bill_no in tbl_bill_no after the record was updated; update step size: the step size of the updated record in tbl_bill_no; and node sequence number: the node sequence number of the updated record in tbl_bill_no.
[0125] The initialization of the serial number generation node may include the following steps a1-a8.
[0126] Step a1. When the serial number generation node starts, a serial number resource block cache management device CM is created. This device maintains a dual-cache memory structure CM_cache, a serial number resource block allocation node connection pool, a cache switching controller, a global request serial number, host IP information, a list of serial number resource names, etc. Among them, the cache switching controller has the ability to process sequentially, and the global request serial number is incremented each time a generation request is received from an external application.
[0127] Step a2. The CM sends a random routing information instruction to the sequence number resource block routing device CR.
[0128] Step a3. The CR internally maintains a fragment number sequence that matches the number of nodes allocating the sequence number resource blocks. When the CM requests random routing information, the CR returns the first value of the fragment number sequence to the CM. When the CM sends a command to the CR to specify routing information, the CR will rewrite the fragment number sequence to the specified fragment number and return the specified fragment number value to the CM. When the CM sends a command to end the specified routing to the CR, the CR will reallocate a random sequence of fragment numbers and return the first value of the sequence to the CM.
[0129] Step a4.CM generates an operation record serial number based on the fragment number returned by CR. The main components of this serial number are: fragment number + host IP information + current time + local incrementing sequence. CM selects the corresponding sequence number resource block allocation node from the sequence number resource block allocation node connection pool based on the fragment number to perform the update operation. The specific method of the update operation can be found in the relevant description of step 51043 above, and will not be elaborated further here.
[0130] Step a5.CM selects the corresponding sequence number resource block allocation node in the sequence number resource block allocation node link pool based on the fragment number and performs a search operation to obtain the metadata of the sequence number range allocated by the sequence number resource block allocation node.
[0131] For details on the search operation, please refer to the relevant description in step 51044 above, which will not be elaborated further here.
[0132] Step a6.CM updates the metadata obtained in step a5 to the currently used memory block of CM_cache, and obtains the variable X used to generate the sequence number. The initial value of X = minimum bill_no + node sequence number, and the maximum value of the sequence number X_max = maximum bill_no for this allocation + node sequence number.
[0133] Step a7.CM repeats steps a2-a6 above to update the information in the CM_cache spare memory block. In this way, the corresponding sequence number range is cached in both memory blocks of CM.
[0134] Step a8.CM can repeat steps a2-a7 above until all the maintained resource sequence number name sequences have been processed.
[0135] Based on the distributed sequence number generation method provided in the above embodiments, this application also provides a specific implementation of the sequence number generation node. Please refer to the following embodiments.
[0136] See Figure 1 The serial number generation node provided in this application embodiment includes a serial number generation device BG and a serial number resource block cache management device CM.
[0137] Among them, BG is used to receive the serial number generation request sent by the application, and the generation request includes the target serial number resource name; CM is used to determine the target memory block corresponding to the target serial number resource name from the preset correspondence between serial number resource name and memory block, based on the target serial number resource name. CM is also used to obtain the first currently allocated last sequence number pointed to by the global allocation pointer in the target memory block; CM is also used to update the last currently allocated sequence number through atomic operations based on the first sequence number interval update step size to obtain the first global request sequence number; the first sequence number interval update step size is the update step size of the first sequence number interval currently cached in the target memory block; CM is also used to send the first global request sequence number, the maximum value of the first sequence number range, and the memory block identifier of the target memory block to BG, where the maximum value of the first sequence number range is the maximum value of the first sequence number range. BG is also used to return the first global request sequence number to the application if the first global request sequence number is less than the maximum value of the first sequence number range.
[0138] In some embodiments, the CM includes two memory blocks, the target memory block is one of the two memory blocks, and the CM is also used for: If the first global request sequence number is greater than or equal to the maximum value of the first sequence number range, determine whether the memory block identifier of the target memory block is consistent with the memory block identifier of the memory block currently used by CM; If the memory block identifier of the target memory block is inconsistent with the memory block identifier of the currently used memory block, determine the second currently allocated last sequence number pointed to by the global allocation pointer in the currently used memory block; The second global request sequence number is obtained by updating the last currently allocated sequence number using atomic operations based on the second sequence number interval update step size. The second sequence number interval update step size is the update step size of the second sequence number interval cached in the currently used memory block. Send the second global request sequence number, the maximum value of the second sequence number range, and the region identifier of the currently used memory block to the BG. The maximum value of the second sequence number range is the maximum value of the sequence number range. BG is also used for: If it is determined that the second global request sequence number is less than the maximum value of the second sequence number range, the second global request sequence number is returned to the application.
[0139] In some embodiments, BG is also used for: If it is determined that the second global request sequence number is greater than or equal to the maximum value of the second sequence number range, the first error message is returned to the application.
[0140] In some embodiments, CM is also used for: If the memory block identifier of the target memory block is consistent with the memory block identifier of the currently used memory block, the third currently allocated last sequence number is updated by atomic operation according to the third sequence number interval update step size, and the third global request sequence number is obtained. The third sequence number interval update step size is the update step size of the third sequence number interval cached in the spare memory block. The spare memory block is the memory block in CM other than the currently used memory block. If the third global request sequence number is less than the maximum value of the third sequence number interval, the spare memory block is switched to the currently used memory block, and the target memory block is switched to the spare memory block; the third currently allocated last sequence number interval is updated to the second currently allocated last sequence number, the third sequence number interval update step size is updated to the second sequence number interval update step size, and the maximum value of the third sequence number interval is the maximum value of the third sequence number interval. Return to the execution and determine the second currently allocated last sequence number pointed to by the global allocation pointer in the currently used memory block.
[0141] In some embodiments, CM is also used for: If the third global request sequence number is greater than or equal to the maximum value of the third sequence number range, a new sequence number range is asynchronously requested from the sequence number resource block allocation node to update the cached sequence number range in the currently used memory block; Return to the execution and determine the second currently allocated last sequence number pointed to by the global allocation pointer in the currently used memory block.
[0142] In some embodiments, the serial number generation node further includes a serial number resource block routing device (CR); CM is used to send routing information commands to CR; The CR is used to respond to routing information commands and return the target fragment number to the CM; CM is used to determine the target sequence number resource block allocation node corresponding to the target fragment number; CM is used to request a new sequence number range from the target sequence number resource block allocation node in order to update the cached sequence number range in the currently used memory block.
[0143] In some embodiments, CM is specifically used for: Generate a target operation record serial number, which includes: target fragment number, target sequence number, host IP address information of the resource block allocation node, current time, and the local incrementing sequence pointed to by the global allocation pointer in the currently used memory block; Determine the target link corresponding to the target sequence number resource block allocation node from the sequence number resource block allocation node link pool; Based on the target link, request the target sequence number resource block allocation node to allocate a new sequence number range based on the target operation record serial number; Query the metadata of the sequence number range allocated by the resource block allocation node for the target sequence number. The metadata includes the maximum and minimum values of the allocated sequence number range, the sequence number generation node number, and the sequence number range update step size. Based on metadata, update the cached sequence number range in the currently used memory block.
[0144] In some embodiments, CR is specifically used for: When the routing information command is a random routing information command, the first fragment number in the preset fragment number sequence will be returned to the CM as the target fragment number; When the routing information instruction is a specified routing information instruction that includes a specified fragment number, the preset fragment number sequence is updated to the specified fragment number sequence, and the specified fragment number is returned to the CM as the target fragment number. All fragment numbers in the specified fragment number sequence are specified fragment numbers. If the routing information instruction is not the end of the specified routing information instruction, a random sequence of fragment numbers is regenerated, and the first fragment number in the random sequence is returned to the CM as the target fragment number.
[0145] The serial number generation node provided in this application embodiment can achieve... Figures 2 to 4 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.
[0146] Figure 5 A schematic diagram of the hardware structure of the electronic device provided in an embodiment of this application is shown.
[0147] Electronic device 500 may include processor 501 and memory 502 storing computer program instructions.
[0148] Specifically, the processor 501 may include a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0149] Memory 502 may include a large-capacity memory for data or instructions. For example, and not limitingly, memory 502 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 502 may include removable or non-removable (or fixed) media. Where appropriate, memory 502 may be internal or external to the integrated gateway disaster recovery device. In a particular embodiment, memory 502 is non-volatile solid-state memory. Memory 502 may include read-only memory (ROM), random access memory (RAM), disk storage media devices, optical storage media devices, flash memory devices, electrical, optical, or other physical / tangible memory storage devices. Thus, typically, memory 502 includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it performs the operations described in any of the distributed serial number generation methods in the above embodiments.
[0150] The processor 501 reads and executes computer program instructions stored in the memory 502 to implement any of the distributed serial number generation methods in the above embodiments.
[0151] In one example, the electronic device 500 may also include a communication interface 503 and a bus 510. For example, Figure 5 As shown, the processor 501, memory 502, and communication interface 503 are connected through bus 510 and complete communication with each other.
[0152] The communication interface 503 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.
[0153] Bus 510 includes hardware, software, or both, that couples components of an online data traffic metering device together. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Microchannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 510 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, this application contemplates any suitable bus or interconnect.
[0154] Furthermore, in conjunction with the distributed serial number generation method in the above embodiments, this application embodiment can provide a computer storage medium for implementation. This computer storage medium stores computer program instructions; when these computer program instructions are executed by a processor, they implement any of the distributed serial number generation methods in the above embodiments.
[0155] This application also provides a computer program product, including a computer program, which, when executed, implements any of the distributed serial number generation methods described in the above embodiments.
[0156] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.
[0157] The functional blocks shown in the above-described structural diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.
[0158] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.
[0159] The aspects of this disclosure have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by special-purpose hardware performing the specified functions or actions, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0160] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.
Claims
1. A method for distributed serial number generation, the method comprising: The method is applied to a serial number generation node, and the serial number generation node has a serial number generation device BG and a serial number resource block cache management device CM, and the method comprises the following steps: receiving, by the BG, a serial number generation request sent by an application, wherein the generation request comprises a target serial number resource name; determining, by the CM, a target memory block corresponding to the target serial number resource name from a preset correspondence between serial number resource names and memory blocks according to the target serial number resource name; obtaining, by the CM, a first currently allocated last serial number pointed to by a global allocation pointer in the target memory block; updating, by the CM, the first currently allocated last serial number by an atomic operation according to a first serial number interval update step to obtain a first global request serial number, wherein the first serial number interval update step is an update step of a first serial number interval currently cached in the target memory block; sending, by the CM, the first global request serial number, a first serial number interval maximum value and a memory block identifier of the target memory block to the BG, wherein the first serial number interval maximum value is a maximum value of the first serial number interval; returning, by the BG, the first global request serial number to the application in a case where the first global request serial number is less than the first serial number interval maximum value.
2. The method of claim 1, wherein, The CM comprises two memory blocks, the target memory block is one of the two memory blocks, and the method further comprises the following steps: in a case where the first global request serial number is greater than or equal to the first serial number interval maximum value, determining, by the CM, whether a memory block identifier of the target memory block is consistent with a memory block identifier of a currently used memory block of the CM; in a case where the memory block identifier of the target memory block is inconsistent with the memory block identifier of the currently used memory block, determining, by the CM, a second currently allocated last serial number pointed to by a global allocation pointer in the currently used memory block; updating, by the CM, the second currently allocated last serial number by an atomic operation according to a second serial number interval update step to obtain a second global request serial number, wherein the second serial number interval update step is an update step of a second serial number interval cached in the currently used memory block; sending, by the CM, the second global request serial number, a second serial number interval maximum value and a region identifier of the currently used memory block to the BG, wherein the second serial number interval maximum value is a maximum value of the serial number interval; returning, by the BG, the second global request serial number to the application in a case where it is determined that the second global request serial number is less than the second serial number interval maximum value.
3. The method of claim 2, wherein, The method further comprises the following steps: returning, by the BG, first error information to the application in a case where it is determined that the second global request serial number is greater than or equal to the second serial number interval maximum value.
4. The method of claim 2, wherein, The method further comprises the following steps: In a case where the memory block identifier of the target memory block is consistent with the memory block identifier of the currently used memory block, the CM updates a third currently allocated last sequence number pointed to by a global allocation pointer in a standby memory block through an atomic operation according to a third sequence number interval update step, to obtain a third global request sequence number, the third sequence number interval update step being an update step of a third sequence number interval cached in the standby memory block, the standby memory block being a memory block other than the currently used memory block in the CM; In a case where the third global request sequence number is less than a third sequence number interval maximum value, the CM switches the standby memory block to a currently used memory block, and switches the target memory block to a standby memory block; the third currently allocated last sequence number interval is updated to a second currently allocated last sequence number, and the third sequence number interval update step is updated to a second sequence number interval update step, the third sequence number interval maximum value being a maximum value of the third sequence number interval; The method further comprises:
5. The method of claim 4, wherein, In a case where the third global request sequence number is greater than or equal to the third sequence number interval maximum value, the CM asynchronously applies for a new sequence number interval from a sequence number resource block allocation node, to update the sequence number interval cached in the currently used memory block; The method further comprises: The sequence number generation node further comprises a sequence number resource block routing device CR, and the CM asynchronously applies for a new sequence number interval from a sequence number resource block allocation node, to update the sequence number interval cached in the currently used memory block, which comprises:
6. The method of claim 5, wherein, The CM sends routing information instructions to the CR; The CR returns a target shard number to the CM in response to the routing information instructions; The CM determines a target sequence number resource block allocation node corresponding to the target shard number; The CM applies for a new sequence number interval from the target sequence number resource block allocation node, to update the sequence number interval cached in the currently used memory block. The CM applies for a new sequence number interval from the target sequence number resource block allocation node, to update the sequence number interval cached in the currently used memory block, which comprises:
7. The method of claim 6, wherein, The CM generates a target operation record serial number, the target operation record serial number comprising: the target shard number, host IP address information to which the target sequence number resource block allocation node belongs, a current time, and a local incremental sequence pointed to by a global allocation pointer in the currently used memory block; The CM determines a target link corresponding to the target sequence number resource block allocation node from a sequence number resource block allocation node link pool; allocating, by the CM, a node of the target sequence number resource block based on the target operation record flow number to apply for a new sequence number interval based on the target link; inquiring, by the CM, meta information of a sequence number interval allocated by the target sequence number resource block allocation node this time, the meta information including a maximum value and a minimum value of the sequence number interval allocated this time, a sequence number of the sequence number generation node, and a sequence number interval update step of the sequence number interval allocated this time; updating, by the CM, the sequence number interval cached in the current used memory block based on the meta information.
8. The method of claim 6, wherein, the CR returns a target shard number to the CM in response to the routing information instruction, including: in a case where the routing information instruction is a random routing information instruction, the CR returns a first shard number in a preset shard number sequence as the target shard number to the CM; in a case where the routing information instruction is a specified routing information instruction including a specified shard number, the CR updates the preset shard number sequence to a specified shard number sequence in which all shard numbers are the specified shard number, and returns the specified shard number as the target shard number to the CM; in a case where the routing information instruction is an end specified routing information instruction, the CR regenerates a random sequence of shard numbers, and returns a first shard number in the random sequence as the target shard number to the CM.
9. A sequence number generating node, characterized by The sequence number generation node has a sequence number generation device BG and a sequence number resource block cache management device CM. The BG is configured to receive a sequence number generation request sent by an application, the generation request including a target sequence number resource name. The CM is configured to determine a target memory block corresponding to the target sequence number resource name from a preset correspondence between sequence number resource names and memory blocks according to the target sequence number resource name. The CM is further configured to obtain a first currently allocated last sequence number pointed to by a global allocation pointer in the target memory block. The CM is further configured to update the first currently allocated last sequence number by an atomic operation according to a first sequence number interval update step to obtain a first global request sequence number, the first sequence number interval update step being an update step of a first sequence number interval currently cached in the target memory block. The CM is further configured to send the first global request sequence number, a first sequence number interval maximum value, and a memory block identifier of the target memory block to the BG, the first sequence number interval maximum value being a maximum value of the first sequence number interval. The BG is further configured to return the first global request sequence number to the application in a case where the first global request sequence number is less than the first sequence number interval maximum value.
10. A distributed serial number generation system, characterized by, The system further includes at least one sequence number resource block allocation node configured to allocate a sequence number interval to the sequence number resource block cache management device in each of the sequence number generation nodes.
11. The system of claim 10, wherein, The system further includes at least one sequence number resource block allocation node configured to allocate a sequence number interval to the sequence number resource block cache management device in each of the sequence number generation nodes.
12. An electronic device, comprising: The electronic device comprises a processor and a memory storing computer program instructions; The processor executes the computer program instructions to implement the distributed serial number generation method according to any one of claims 1-8.
13. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer program instructions, and the computer program instructions are executed by the processor to implement the distributed serial number generation method according to any one of claims 1-8.
14. A computer program product, characterised in that, The computer program is executed by the processor to implement the distributed serial number generation method according to any one of claims 1-8.