Serial number generation method, device, equipment and storage medium
In the new version of the computing system, the target sequence number and segment sequence are obtained from the data storage node and the serial number is generated, which solves the problem of uneven utilization of segments during the parallel period of the old and new systems, improves the efficiency of serial number generation, and satisfies the needs of high concurrency scenarios. needs.
Patent Information
- Application Number
- CN202110745615.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-30
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2041-06-30
AI Technical Summary
During the parallel period between the old and new systems, the new version of the computing system was unable to effectively utilize the segments released by the old version of the computing system to generate serial numbers, resulting in unbalanced segment utilization and low serial number generation efficiency.
The business processing node of the new version of the computing system obtains the target sequence number from the data storage node, and generates the target serial number based on the sequence number and segment sequence. The segments released by the old version of the computing system are used to generate the serial number, realizing segment sharing and sequencing. Efficient allocation of numbers.
It improves the balance of segment utilization and the efficiency of serial number generation, meeting business needs in high-concurrency scenarios.
Smart Images

Figure CN113377427B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to computer technology, and in particular to a method, device, equipment and storage medium for generating a serial number. Background Art
[0002] At present, computing systems are usually deployed in multiple nodes, such as distributed computing systems. In computing systems, the processing of massive businesses is achieved through multiple nodes (i.e., multiple stand-alone machines, such as multiple servers). In order to distinguish different businesses, the computing system assigns a globally unique serial number to each business. The serial number includes a segment (also known as a Region segment, a string of numbers or characters) and a sequence number (an integer that increases based on the natural number sequence). In each segment, a sequence number is generated by a counter, and the segment and the generated sequence number are combined to ensure the global uniqueness of the serial number.
[0003] As the system is used for a long time, when the existing computing system cannot meet business needs and challenges, the computing system needs to be reconstructed. In order to achieve a smooth transition between the computing system before and after the reconstruction, there is usually a parallel period between the old and new systems. During the parallel period between the old and new systems, the old computing system only releases some non-continuous segments, and the new computing system needs to use non-continuous segments to generate serial numbers.
[0004] Usually, the computing system configures multiple segments to multiple nodes, and different nodes are configured with different segments. When different nodes apply for serial numbers for services, they generate sequence numbers under their own configured segments. However, this method requires that available segments be configured for each node. During the period when the new and old systems are in parallel, the new version of the computing system has limited segments, and it is impossible to ensure that segments are configured for each node. In addition, the utilization of different segments in this method is uneven, resulting in a waste of available sequence numbers under the segments. Summary of the invention
[0005] The present application provides a serial number generation method, device, equipment and storage medium to solve the problem of how a new version of a computing system generates serial numbers using a segment released by an old version of a computing system during the parallel operation of the new and old systems.
[0006] In a first aspect, the present application provides a serial number generation method, which is applied to a first device, where the first device is a business processing node in a new version of a computing system, and the serial number generation method includes:
[0007] Obtaining a target sequence number from sequence numbers stored in the first device, the stored sequence numbers coming from a counter in a second device, the second device being a data storage node in the new version computing system;
[0008] Determine, according to the preset number of digits of the sequence number in the serial number and the target sequence number, the sequence number of the target segment corresponding to the target sequence number in the segment sequence, the segment sequence being from a database in the second device, and the segments in the segment sequence being segments released by the old version computing system;
[0009] According to the sequence number of the target segment, searching for the target segment in the segment sequence;
[0010] A target serial number is generated according to the target sequence number and the target section.
[0011] In a possible implementation, determining the sequence number of the target segment corresponding to the target sequence number in the segment sequence according to the preset number of digits of the sequence number in the serial number and the target sequence number includes:
[0012] According to the preset number of bits, a modulo operation is performed on the target sequence number to obtain the sequence number of the target segment in the segment sequence.
[0013] In a possible implementation, generating a target serial number according to the target sequence number and the target segment includes:
[0014] If the target segment is the first segment in the segment sequence, padding the high bits of the target sequence number with zeros according to the preset number of bits;
[0015] The target serial number is obtained according to the target segment and the target sequence number after zero padding.
[0016] In a possible implementation, generating a target serial number according to the target sequence number and the target segment includes:
[0017] If the target segment is the first segment in the segment sequence, determining the total number of sequence numbers corresponding to the target segment and the segments preceding the target segment in the segment sequence according to the sequence number of the target segment and the preset number of bits;
[0018] According to the total number of sequence numbers, a modulo operation is performed on the target sequence number to obtain an operation result;
[0019] Filling the high bits of the calculation result with zeros according to the preset number of bits;
[0020] The target serial number is obtained according to the operation result after zero padding and the target sequence number.
[0021] In a possible implementation, before obtaining the target sequence number, the serial number generating method further includes:
[0022] If the number of sequence numbers stored in the first device is zero, sending a first message to the second device, where the first message is used to apply for a sequence number from the second device;
[0023] Receive and store one or more sequence numbers returned by the second device.
[0024] In a possible implementation, before obtaining the target sequence number, the serial number generating method further includes:
[0025] If the number of sequence numbers stored in the first device meets a preset condition, asynchronously sending a first message to the second device, where the first message is used to apply for a sequence number from the second device;
[0026] The number of sequence numbers stored in the first device satisfying a preset condition includes at least one of the following: the number of sequence numbers stored in the first device is a first threshold, and the ratio of the number of sequence numbers stored in the first device to the preset number is a second threshold.
[0027] In a possible implementation, before determining the segment corresponding to the target sequence number, the serial number generation method further includes:
[0028] sending a second message to the second device, where the second message is used to request the second device to update a segment sequence;
[0029] The segment sequence returned by the second device is received and stored.
[0030] In a possible implementation manner, the sending the second message to the second device includes:
[0031] After a first message is sent to the second device or the first device is started, a request is made to the second device to update a segment sequence.
[0032] In a second aspect, the present application provides a serial number generation method, which is applied to a second device, where the second device is a data storage node in a new version of a computing system, and the serial number generation method includes:
[0033] receiving a first message sent by a first device, where the first message is used to apply for a sequence number from the second device;
[0034] Determine a target step length according to the first message, where the target step length is the number of application sequence numbers of the first device;
[0035] According to the preset number of digits of the sequence number in the serial number, the number of segments in the segment sequence and the target step length, a sequence number is obtained by counting with a counter, wherein the segments in the segment sequence are segments released by the old version computing system;
[0036] The sequence number generated by the counter is sent to the first device, so as to generate a serial number by using the sequence number on the first device.
[0037] In a possible implementation, the obtaining of the sequence number by counting through a counter according to the preset number of digits of the sequence number in the serial number, the number of segments in the segment sequence, and the target step length includes:
[0038] Determining a counting threshold according to the preset number of bits and the number of segments in the segment sequence;
[0039] According to the current value of the counter, counting is performed in sequence to obtain a sequence number until the number of counts reaches the target step length or the sequence number obtained by counting is equal to the counting threshold.
[0040] In a possible implementation, the serial number generating method further includes:
[0041] In response to receiving a segment released by the old version computing system, updating the segment sequence;
[0042] The counting threshold is updated according to the updated segment sequence.
[0043] In a third aspect, the present application provides a serial number generating device, which is applied to a first device, where the first device is a business processing node in a new version computing system, and the serial number generating device includes:
[0044] An acquisition module, configured to acquire a target sequence number from sequence numbers stored in the first device, wherein the stored sequence numbers are from a counter in a second device, and the second device is a data storage node in the new version computing system;
[0045] a determination module, configured to determine, according to a preset number of digits of the sequence number in the serial number and the target sequence number, a sequence number of a target segment corresponding to the target sequence number in a segment sequence, wherein the segment sequence is from a database in the second device, and the segments in the segment sequence are segments released by an old version computing system;
[0046] A search module, configured to search for the target segment in the segment sequence according to the sequence number of the target segment;
[0047] A generating module is used to generate a target serial number according to the target sequence number and the target section.
[0048] In a fourth aspect, the present application provides a serial number generating device, which is applied to a second device, where the second device is a node where a database is located in a new version computing system, including:
[0049] A receiving module, configured to receive a first message sent by a first device, wherein the first message is used to apply for a sequence number from the second device;
[0050] A determination module, configured to determine a target step length according to the first message, wherein the target step length is the number of sequence numbers applied for by the first device;
[0051] A counting module, used for obtaining a sequence number by counting through a counter according to a preset number of digits of the sequence number in the serial number, the number of segments in the segment sequence and the target step length, wherein the segments in the segment sequence are segments released by the old version computing system;
[0052] The sending module is used to send the sequence number generated by the counter to the first device, so as to generate a serial number using the sequence number on the first device.
[0053] In a fifth aspect, an embodiment of the present application provides an electronic device, including:
[0054] Memory and processor;
[0055] The memory is used to store program instructions;
[0056] The processor is used to call the program instructions in the memory to execute the serial number generation method as described in the first aspect, or any possible implementation of the first aspect, or the second aspect, or any possible implementation of the second aspect.
[0057] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed, the serial number generation method as described in the first aspect, or any possible implementation of the first aspect, or the second aspect, or any possible implementation of the second aspect is implemented.
[0058] In the seventh aspect, an embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the serial number generation method as described in the first aspect, or any possible implementation of the first aspect, or the second aspect, or any possible implementation of the second aspect.
[0059] In the serial number generation method, device, equipment and storage medium provided by the present application, the first device obtains the target serial number from the sequence number stored in itself, determines the target segment corresponding to the target serial number in the segment sequence, and generates the target serial number based on the target sequence number and the target segment, wherein the first device is a business processing node in the new version computing system, the second device is a data storage node in the new version computing system, the target sequence number comes from the counter in the second device, the segment sequence comes from the database in the second device, and the segments in the segment sequence are segments released by the old version computing system. Therefore, in the new version computing system, the segments released by the old version computing system are uniformly managed by the data storage node, and the segment sequence is shared by different business processing nodes. The counter of the data processing node is used to count and assign serial numbers to different business processing nodes, thereby enabling the new version computing system to generate serial numbers based on the segments released by the old version computing system, and improving the balance of the utilization of different segments. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0061] Figure 1 An example diagram of the structure of the serial number provided in the embodiment of the present application;
[0062] Figure 2 A schematic diagram of an application scenario provided for an embodiment of the present application;
[0063] Figure 3 A flowchart of a method for generating a serial number provided in one embodiment of the present application;
[0064] Figure 4 A flowchart of a method for generating a serial number provided in another embodiment of the present application;
[0065] Figure 5 A flowchart of a method for generating a serial number provided in another embodiment of the present application;
[0066] Figure 6 A flowchart of a method for generating a serial number according to another embodiment of the present application;
[0067] Figure 7 A schematic diagram of the structure of a serial number generating device provided in one embodiment of the present application;
[0068] Figure 8 A schematic diagram of the structure of a serial number generating device provided in another embodiment of the present application;
[0069] Fig. 9 A schematic diagram of the structure of an electronic device provided in one embodiment of the present application.
[0070] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0071] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0072] First, the terms involved in this application are explained:
[0073] Serial number: During the period when the new and old systems run in parallel, the serial number is a globally unique string in the new and old computing systems, used to distinguish different businesses in the new and old systems.
[0074] Sequence number: refers to an integer that increases based on the order of natural number growth.
[0075] Counter: Counts the number of available serial numbers.
[0076] As the business develops, when the old computing system cannot meet the business needs, it is inevitable to build a new computing system. In order to achieve a smooth transition between the old and new systems, there is usually a parallel period between the old and new systems. During the parallel period, the old and new computing systems provide services to the outside world at the same time. From the user's perspective, the old and new systems provide services to the outside world as a system. Therefore, it is necessary to ensure the uniqueness of the user's data in the old and new systems, including ensuring the uniqueness of the user's business in the old and new systems. Business can be identified by serial numbers, so it is necessary to ensure the uniqueness of serial numbers in the old and new systems.
[0077] Typically, a serial number includes a segment and a sequence number, wherein the number of digits in the segment and the number of digits in the sequence number are fixed. Figure 1 The structure example diagram of the serial number provided in the embodiment of the present application is as follows: Figure 1As shown, the serial number includes a 2-digit segment and a 6-digit sequence number, and multiple 6-digit sequence numbers can be generated on different segments. For example, the 2-digit segments are 01, 02, and 03, and multiple 6-digit sequence numbers can be generated on 01, 02, and 03 respectively: 000001, 000002, ...; in this way, the serial numbers that can be obtained are 01000001, 01000002, ..., 02000001, 02000002, ..., 03000001, 03000002, and so on.
[0078] Optional, such as Figure 1 As shown, the serial number also includes a 12-digit institution number and an 8-digit date. The institution number is, for example, the identifier corresponding to the institution that handles the business, and the date is the business handling date. At this time, the total number of serial numbers that can be generated by the computing system every day is the total number of sequence numbers that can be generated on each segment.
[0079] Among them, the embodiments of the present application mainly involve the determination of the segments and sequence numbers in the serial number.
[0080] During the period when the new and old systems are running in parallel, as some nodes in the old computing system are offline, available segments are continuously added to the new computing system. Therefore, the segments available to the new computing system are discontinuous. The new computing system needs to support the generation of serial numbers under discontinuous segments, and is required to be able to dynamically increase segments and generate serial numbers under the dynamically increased segments to increase the maximum number of serial numbers available to itself.
[0081] In a multi-node computing system, in order to solve the uniqueness of serial number generation in a concurrent situation (multi-node competition), it is necessary to use relational database transactions to ensure the atomicity of obtaining a set of specified number of sequence numbers from the counter. One way is: the computing system configures multiple segments to multiple nodes, and generates sequence numbers through different counters in different segments. When a node applies for a serial number, it generates a sequence number through the corresponding counter in the segment configured by itself.
[0082] For example, the multiple segments include 10 segments 01 to 09, and the computing system assigns 01 to 03 to node 1, 04 to 06 to node 2, 06 to 08 to node 3, and 09 to node 4. When generating a serial number, node 1 traverses different segments from 01 to 03, and during the traversal process determines whether the currently traversed segment has assignable sequence numbers. If not, it traverses the next segment, and generates a sequence number for the segment with an assignable sequence number through a counter in the database.
[0083] The inventors found that the above method has the following shortcomings:
[0084] (1) It is necessary to allocate segments to different nodes in advance. However, during the parallel operation of the new and old systems, the new version of the computing system obtains limited segments and cannot ensure that segments are allocated to each node.
[0085] (2) Since different nodes process different amounts of business, the utilization of different nodes' segments is uneven, resulting in a waste of available sequence numbers under the segments. For example, node 1 processes more business, resulting in fewer available sequence numbers remaining under segments 01 to 03 assigned to node 1, while node 2 processes less business, resulting in more available sequence numbers remaining under segments 04 to 06 assigned to node 2. In this way, it is easy for some nodes to have too many available sequence numbers and other nodes to have insufficient available sequence numbers.
[0086] (3) Since different counters are defined for different segments, each time a set of sequence numbers under a segment is obtained, the database needs to be traversed. However, the database access speed is slow, resulting in low efficiency in serial number generation and failure to meet the business system's requirements for high concurrency scenarios.
[0087] To solve the above problems, the present application provides a method for generating a serial number, in which a business processing node of a new version of a computing system obtains a target serial number from a sequence number stored in itself, determines a target segment corresponding to the target sequence number in a segment sequence, and generates a target serial number based on the target sequence number and the target segment. In the new version of the computing system, the sequence number stored in the business processing node comes from a counter in a data storage node, the segment sequence in the business processing node comes from a database in a data storage node, and the segments in the segment sequence are segments released by the old version of the computing system.
[0088] Therefore, on the one hand, different business processing nodes can share segments in the segment sequence when generating serial numbers. Compared with pre-allocating different segments to different business processing nodes, it is more suitable for new version computing systems with discontinuous segments and dynamically increased segments. On the other hand, the sequence numbers used on the business processing nodes are generated by counters on the data storage nodes. There is no need to design separate counters for different segments, and there is no need to traverse different segments, which reduces the number of database accesses and improves the balance of utilization of different segments. On the other hand, the business processing node obtains the target sequence number from the sequence number stored in itself to generate the serial number, which can improve the efficiency of obtaining the sequence number.
[0089] The serial number generation method provided in this application can be applied to Figure 2 The application scenario shown in Figure 1. Figure 2As shown, the application scenario includes a new version computing system 201 and an old version computing system 202, and multiple nodes are included in the new version computing system 201 and the old version computing system 202. Taking the new version computing system 201 as an example, the new version computing system 201 includes data storage nodes and business processing nodes, and the data storage nodes and business processing nodes can be electronic devices such as servers and computers. Figure 2 In the example, the data storage node and the business processing node are servers. The new version computing system 201 and the old version computing system 202 are, for example, distributed computing systems.
[0090] During the period when the new and old systems are in parallel, the new computing system 201 and the old computing system 202 provide services to the outside at the same time, and the nodes in the old computing system 202 are gradually offline, and the segments used by these offline nodes are released to the new computing system 201. The new computing system 201 uses the segments released by the old computing system 201 to generate serial numbers.
[0091] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0092] First, the generation of serial numbers in the service processing nodes in the new version of the computing system is described. For the sake of simplicity, in each embodiment, the service processing nodes in the new version of the computing system are referred to as first devices, and the data storage nodes in the new version of the computing system are referred to as second devices.
[0093] Figure 3 A flow chart of a method for generating a serial number provided in an embodiment of the present application is applied to a first device. Figure 3 As shown, the serial number generation method includes:
[0094] S301. Obtain a target sequence number from the sequence numbers stored in the first device.
[0095] The sequence number stored in the first device comes from the counter in the second device. The first device may apply for one or more sequence numbers from the second device in advance and store the sequence numbers returned by the second device.
[0096] In this step, the first device can obtain the target sequence number from the sequence numbers stored in itself according to the order of the sequence numbers stored in itself, and delete the target sequence number from the sequence numbers stored in itself. For example, if the first device stores sequence numbers 0 to 99, the target sequence number 0 is obtained from the sequence numbers 0 to 99.
[0097] In a possible implementation, the first device stores the sequence number in its own cache. In this case, S301 includes: obtaining the target sequence number from the sequence number in the cache of the first device. Thus, compared with obtaining the sequence number through a separate counter in the database of the first device, the method of obtaining the sequence number from the cache of the first device can effectively improve the efficiency of obtaining the sequence number.
[0098] In a possible implementation, when the first device receives the serial number application request, it obtains the target serial number from the serial numbers stored in itself. The serial number application request may be a serial number application request input by a user, or may be a serial number application request sent by an upstream or downstream business application of the new version of the computing system, for example, a serial number application request sent by a deposit business.
[0099] Furthermore, the first device may provide a serial number application interface externally, and the business application may send a serial number application request to the first device by calling the serial number application interface.
[0100] Furthermore, the serial number application request can be used to apply for a serial number. Therefore, the business application can call the serial number application interface once each time it processes a business.
[0101] S302. Determine the sequence number of the target segment corresponding to the target sequence number in the segment sequence according to the number of digits of the sequence number in the serial number and the target sequence number. The segment sequence comes from a database in the second device. The segments in the segment sequence are segments released by the old version computing system.
[0102] The number of digits of the sequence number in the serial number is fixed. For example, when the number of digits of the sequence number in the serial number is 6, if the target sequence number is 1, the target sequence number in the serial number is 000001.
[0103] Among them, the segment sequence includes all the segments released by the old version computing system. In the segment sequence, the segments are sorted in sequence according to the time when the old version computing system released the segment. If the release time of multiple segments is the same, the multiple segments can be sorted according to the numerical size. The sequence number of the segment is determined by the sequence of the segment in the segment sequence. For example, the old version computing system released 00, 81-99, and 71 in sequence, then the segment sequence includes 00, 81-99, and 71 in sequence, 00 is the segment with sequence number 0 in the segment sequence, 81 is the segment with sequence number 1 in the segment sequence, and so on. Among them, the segment with sequence number 0 is the first segment in the segment sequence.
[0104] The first device may obtain and store the segment sequence from the second device.
[0105] In this step, after obtaining the target sequence number, the value range of the target sequence number can be determined from multiple value ranges of the sequence number based on the pre-established mapping relationship between the value range of the sequence number and the sequence number of the segment in the segment sequence, and then the sequence number corresponding to the value range to which the target sequence number belongs in the segment sequence is determined, which is the sequence number of the target segment in the segment sequence.
[0106] In one example, by establishing a mapping relationship between the value range of the sequence number and the sequence number of the segment in the segment sequence, the total value range of the sequence number can be determined, and then the total value range of the sequence number is divided to obtain multiple value ranges of the sequence number. According to the order of the value range from large to small and the order of the sequence number of the segment from large to small, a one-to-one mapping relationship between the value range and the sequence number of the segment is established.
[0107] For example, when the total value range of the sequence number is 0-9999, the value range of 0-999 can be determined as the value range of the sequence number corresponding to the segment with sequence number 0, the value range of 0-1999 can be determined as the value range of the sequence number corresponding to the segment with sequence number 1, and so on.
[0108] S303. Search for the target segment in the segment sequence according to the sequence number of the target segment.
[0109] In this step, after the serial number of the target segment is determined, the segment corresponding to the serial number can be searched in the segment sequence, and the segment corresponding to the serial number is the target segment.
[0110] S304: Generate a target serial number according to the target sequence number and the target segment.
[0111] In this step, after obtaining the target sequence number and target segment, the target sequence number and target segment can be combined according to the number of digits and positions of the segment in the serial number, and the number of digits and positions of the sequence number in the serial number, to obtain the target serial number. Figure 1 Taking the serial number style shown as an example, if the target sequence number is 99 and the target segment is 81, the target serial number is composed of the 12-digit institution number, the 8-digit date, 81, and 000099 in sequence.
[0112] In the embodiment of the present application, when generating a serial number, a target serial number is obtained from the sequence number stored in the first device, and based on the mapping relationship between the sequence number and the segment, the target segment corresponding to the target serial number is determined in the segment sequence, and the target serial number is determined by combining the target sequence number and the target segment, wherein the sequence number stored in the first device comes from the counter of the second device, and the segment sequence comes from the database of the second device, and the segment sequence includes all the segments released by the old version computing system. Therefore, on the one hand, the segments are uniformly managed by the second device, and the sharing of the segments released by the old version computing system by different first devices is realized, and the balance of the use of the sequence number under the segment is improved, which is suitable for the situation where the new version computing system receives the discontinuous segments dynamically released by the old version computing system; on the other hand, the calculator in the second device uniformly counts the sequence number and the first device stores the multiple sequence numbers generated by the counter in the second device, which reduces the number of times the first device accesses the database, improves the efficiency of obtaining the sequence number, and then improves the efficiency of generating the serial number, and also improves the balance of the use of the sequence number under different segments.
[0113] Since the serial number includes a segment and a sequence number, different serial numbers include serial numbers with different segments or serial numbers with different sequence numbers. Therefore, under the condition that the serial number is unique in the new and old systems, the value of the sequence number in each segment can vary from 0 to a maximum value, which is determined by the number of digits of the sequence number in the serial number. For example, Figure 1 The number of digits in the sequence number shown is 6, so the maximum value of the sequence number is 999999, and each segment can be combined with a sequence number from 0 to 999999 to obtain a different serial number. For example, if the segments in the segment sequence are 01, 02, and 03, then 01, 02, and 03 can be combined with a sequence number from 0 to 999999 to obtain a different serial number.
[0114] Therefore, optionally, the counting range of the counter in the second device is determined by the number of segments in the segment sequence and the number of digits of the sequence number in the serial number, that is, the number of sequence numbers that can be counted by the counter in the second device is determined by the number of segments in the segment sequence and the number of digits of the sequence number in the serial number. Specifically, the number of sequence numbers that can be counted by the counter in the second device is equal to the sum of the number of sequence numbers that can be combined on the segments in the segment sequence, which is equal to the product of the number of segments in the segment sequence and the number of sequence numbers that can be combined with a single segment, and the formula is as follows: MAXVAL = number of Regions * number of sequence numbers that can be combined in each Region, MAXVAL represents the number of sequence numbers that can be counted by the counter, and Region represents the segments in the segment sequence.
[0115] For example, there are five segments in the segment sequence: 00, 81, 82, 83, and 88. The number of digits in the sequence number is 6, so the number of sequence numbers that can be combined in each segment is 10. 6 , that is, 100,000. The number of serial numbers that can be counted by the counter in the second device is 5*100,000, that is, 500,000. The counting range of the counter in the second device is 0 to 499,999.
[0116] At this time, in order to evenly utilize the sequence numbers under each segment, the mapping relationship between the segment sequence number and the sequence number value range can be determined based on the number of sequence numbers that the counter can count and the sequence number of each segment in the segment sequence. n -1 is the range of sequence numbers corresponding to the segment with sequence number 0, 10 n ~(2*10 n -1) is the range of values of the sequence number corresponding to the segment with sequence number 1, and so on, where n is the number of digits in the sequence number. Therefore, the mapping relationship between the segment sequence number and the range of values of the sequence number is: The range of values of the sequence number corresponding to the segment with sequence number m is: m*10 n ~{(m+1)*10 n -1}, where m is the segment number.
[0117] As an example, there are five segments in the segment sequence, namely 00, 81, 82, 83, and 88. The number of digits in the serial number is 6. The segment 00 with sequence number 0 corresponds to a sequence number ranging from 0 to 999999, the segment 81 with sequence number 1 corresponds to a sequence number ranging from 1000000 to 1999999, the segment 82 with sequence number 2 corresponds to a sequence number ranging from 2000000 to 2999999, the segment 83 with sequence number 3 corresponds to a sequence number ranging from 3000000 to 3999999, and so on.
[0118] The mapping relationship based on the value range of the sequence number is that the value range of the sequence number corresponding to the segment with sequence number m is: m*10 n ~{(m+1)*10 n -1}, Figure 4 A flowchart of a method for generating a serial number provided by another embodiment of the present application is shown below. Figure 4 As shown, the serial number generation method includes:
[0119] S401. Obtain a target sequence number from the sequence numbers stored in the first device.
[0120] The implementation principle and technical effects of S401 may refer to the aforementioned embodiments and will not be described in detail.
[0121] S402. Perform a modulo operation on the target sequence number according to the number of digits in the sequence number in the serial number to obtain the sequence number of the target segment in the segment sequence.
[0122] Among them, according to the number of digits in the sequence number in the serial number, the value range of the sequence number corresponding to the segment with the segment number m in the segment number can be established as m*10 n ~{(m+1)*10 n -1}, taking the number of digits in the sequence number as 6 as an example, when the segment sequence number is 0, the corresponding sequence number ranges from 0 to 999999, when the segment sequence number is 1, the corresponding sequence number ranges from 1000000 to 1999999, when the segment sequence number is 2, the corresponding sequence number ranges from 2000000 to 2999999, and so on.
[0123] In this step, after obtaining the target sequence number, the sequence number of the segment corresponding to the target sequence number can be determined according to the sequence number of the segment and the value range of the sequence number. Specifically, according to the number of digits of the sequence number in the serial number, the target sequence number is modulo operated to obtain the sequence number of the target segment in the segment sequence. For example, when the number of digits of the sequence number in the serial number is 6, the target sequence number is modulo operated according to 10 to the sixth power. The calculation formula of the sequence number of the target segment in the segment sequence is:
[0124] Target segment number = |target sequence number / 10 n |.
[0125] As an example, assuming that the number of digits n in the serial number is 6, if the target sequence number is 1, the sequence number of the target segment can be determined to be 0; if the target sequence number is 999999, the sequence number of the target segment can be determined to be 1; if the target sequence number is 1000000, the sequence number of the target segment can be determined to be 1.
[0126] Of course, if the first segment in the segment sequence is determined to be 1 instead of 0, the mapping relationship between the segment number and the range of the sequence number is: (m-1)*10 n ~{m*10 n -1}. The formula for calculating the sequence number of the target segment in the segment sequence is: Target segment sequence number = |target sequence number / 10 n |+1. In the following embodiments, the sequence number of the first segment in the segment sequence is taken as 1 as an example.
[0127] S403. Search for the target segment in the segment sequence according to the sequence number of the target segment.
[0128] The implementation principle and technical effects of S403 may refer to the aforementioned embodiments and will not be described in detail.
[0129] S404: Generate a target serial number according to the target sequence number and the target segment.
[0130] In this step, after obtaining the target sequence number and the target segment, since the value range of the sequence number obtained by the counter in the second device is 0 to MAXVAL-1, MAXVAL = the number of Regions * the number of sequence numbers that can be combined in each Region, the number of digits of the sequence number counted by the counter may be smaller than the number of digits of the sequence number in the serial number (for example, the sequence number counted by the counter is 0), or it may be larger than the number of digits of the sequence number in the serial number (for example, the number of digits of the sequence number in the serial number is 6, and the sequence number counted by the counter is 1999999). It is necessary to adjust the target sequence number according to the target segment to obtain the target sequence number that meets the number of digits of the sequence number in the serial number, and combine the adjusted target sequence number with the target segment to obtain the target serial number.
[0131] In a possible implementation, S404 includes: if the target segment is the first segment in the segment sequence, padding the high digits of the target sequence number with zeros according to the number of digits of the sequence number in the serial number; and obtaining the target serial number according to the target segment and the zero-padded target sequence number. Thus, the generation of the target serial number is achieved when the target segment is the first segment in the segment sequence.
[0132] Specifically, if the target segment is the first segment in the segment sequence, the value range of the sequence number corresponding to the target segment obtained by counting the counter is 0 to (10 n -1), n is the number of digits of the sequence number in the serial number. Therefore, the number of digits of the sequence number obtained by the counter corresponding to the target segment is less than or equal to the number of digits of the sequence number in the serial number, and the high digits of the target sequence number can be directly padded with zeros according to the number of digits of the sequence number in the serial number, so that the number of digits of the target sequence number after zero padded is the same as the number of digits of the sequence number in the serial number. The target segment is combined with the target sequence number after zero padded to obtain the target serial number.
[0133] For example, the number of digits in the sequence number in the serial number is 6, the sequence number of the target area code is 0 and the target area code is 00, and the target sequence number is 1, then the target sequence number after zero padding is 000001, and the combined target serial number is 00000001.
[0134] In another possible implementation, S404 includes: if the target segment is not the first segment in the segment sequence, determining the total number of sequence numbers corresponding to the target segment and the segments before the target segment in the segment sequence according to the number of digits of the sequence number in the serial number; performing a modulo operation on the target sequence number according to the total number of sequence numbers to obtain an operation result; padding the high digits of the operation result with zeros according to the number of digits of the sequence number in the serial number; and obtaining the target serial number according to the operation result after padding with zeros and the target sequence number. Therefore, the generation of the target serial number is achieved when the target segment is not the first segment in the segment sequence.
[0135] Specifically, if the target segment is not the first segment in the segment sequence, the value range of the sequence number corresponding to the target segment obtained by counting the counter is: m*10 n ~{(m+1)*10 n -1}, m is greater than 0, and the number of digits of the sequence number obtained by counting the counter corresponding to the target segment is greater than the number of digits of the sequence number in the serial number, that is, the number of digits of the target sequence number is greater than the number of digits of the sequence number in the serial number.
[0136] In the case where the number of digits of the target sequence number is greater than the number of digits of the sequence number in the serial number, the total number of sequence numbers corresponding to the target segment and the segment before the target segment in the segment sequence is determined, that is, the sum of the number of sequence numbers that can be combined under the target segment and the number of sequence numbers that can be combined with the segment before the target segment in the segment sequence is determined. According to the total number of sequence numbers calculated, the target sequence number is subjected to a modulo operation to obtain an operation result, and then the operation result is padded with zeros according to the number of digits of the sequence number in the serial number, so that the number of digits of the operation result after the zero padded is the number of digits of the sequence number in the serial number. The target segment is combined with the operation result after the zero padded to obtain the target serial number.
[0137] Specifically, the calculation formula of the operation result is:
[0138] seqId = sequence% (regionIndex*REGION_ID_SIZE), where seqId is the result of the operation, sequence is the target sequence number, regionIndex is the sequence number of the target segment, and REGION_ID_SIZE indicates the number of sequence numbers that can be combined in each segment. For example, if the number of digits in the sequence number in the serial number is 6 and the target sequence number is 1000000, then the sequence number of the target segment corresponding to the target sequence number is 1, and the calculated seqId = 1000000% (1*100000) = 0. According to the number of digits in the serial number, 6, the result of the operation is padded with zeros to obtain 000000. Therefore, assuming that the target segment is 81 with a sequence number of 1, the target serial number is 81000000.
[0139] For another example, if the number of digits in the sequence number is 6 and the target sequence number is 1999999, the target segment sequence number corresponding to the target sequence number is 1, and seqId=1999999%(1*100000)=999999 is calculated. According to the number of digits in the sequence number, 6, the calculation result is padded with zeros to obtain 999999. Therefore, assuming that the target segment is 81 with sequence number 1, the target serial number is 81999999.
[0140] In some embodiments, if the number of sequence numbers stored in the first device is zero, the first device sends a first message to the second device, and the first message is used to apply for a sequence number from the second device. The first device receives and stores one or more sequence numbers returned by the second device. The first device can apply for a fixed number of sequence numbers from the second device each time, for example, 1,000 sequence numbers from the second device each time.
[0141] In some embodiments, during the process of generating a serial number, if the number of sequence numbers stored in the first device meets a preset condition, the first device asynchronously sends a first message to the second device, the first message is used to apply for a sequence number from the second device, and the first device receives and stores one or more sequence numbers returned by the second device. Therefore, during the process of generating a serial number, the first device ensures a sufficient number of sequence numbers at the same time in an asynchronous manner. The number of sequence numbers stored in the first device meeting the preset condition includes at least one of the following: the number of sequence numbers stored in the first device is a first threshold, and the ratio of the number of sequence numbers stored in the first device to the preset number is a second threshold.
[0142] Specifically, during the process of generating a serial number, if the first device detects that the number of sequence numbers stored in the first device is a preset number, the first message is asynchronously sent to the second device without stopping the generation of the serial number of the first device. During the process of generating a serial number, if the first device detects that the ratio of the number of sequence numbers stored in the first device to the preset number is a second threshold, the first message is asynchronously sent to the second device without stopping the generation of the serial number of the first device.
[0143] For example, the first threshold is 800, and when the number of sequence numbers stored in the first device is 800 (or less than 800), the first device asynchronously sends the first message to the second device. For another example, the preset number is a fixed number of serial numbers that the first device applies to the second device each time, and assuming that the fixed number is 1000 and the second threshold is 80%, when the number of sequence numbers stored in the first device and the number of serial numbers are 80% (or less than 80%), the first message is asynchronously sent to the second device.
[0144] Figure 5 A flowchart of a method for generating a serial number provided by another embodiment of the present application is shown below. Figure 5 As shown, the serial number generation method includes:
[0145] S501. A first device sends a first message to a second device, where the first message is used to apply for a sequence number from the second device.
[0146] In this step, as described in the above embodiments, the first device can send a first message to the second device to apply for a sequence number of a target step from the second device when the number of stored sequence numbers is zero, or when the stored sequence numbers meet a preset condition, or when the first device is started, wherein the target step is the number of sequence numbers applied for by the first device.
[0147] S502: The second device determines a target step size according to the first message.
[0148] In this step, the second device obtains the target step size from the first message.
[0149] S503: The second device obtains a sequence number by counting with a counter according to the number of digits of the sequence number in the serial number, the number of segments in the segment sequence, and the target step length.
[0150] In this step, the second device determines the number of sequence numbers that can be combined with each segment according to the number of digits of the sequence number in the serial number, and determines the number of sequence numbers that can be counted by the counter according to the number of segments in the segment sequence and the number of sequence numbers that can be combined with each segment. For details, please refer to the calculation of MAXVAL in the above embodiment, and the counting range of the counter is 0 to (MAXVAL-1). The counter in the second device counts one by one within the counting range to obtain the target step length sequence numbers.
[0151] In one example, the counter determines the counting threshold, i.e., MAXVAL-1, based on the number of digits in the sequence number in the serial number and the number of segments in the segment sequence; and counts sequentially based on the current value of the counter to obtain the sequence number until the number of counts reaches the target step length or the sequence number obtained by counting is equal to the counting threshold. For example, assuming that the current value of the counter is 20000, the target step length is 1000, and the counting threshold is 4999999, the counter starts counting from 20000, adding 1 each time, counting 1000 times, and obtaining 1000 count values, i.e., 1000 sequence numbers: 20001, 20002, ..., 21000.
[0152] Optionally, a relational database SQL operation may be used for counting.
[0153] First, define the counter structure stored in the database. The database table structure of the counter is as follows:
[0154] Column Name Data Types describe BIZTAG VARCHAR2(30) Business Type COUNTER VARCHAR2(30) Counter Name MAXVAL-1 NUMBER(15) The maximum sequence number that the counter can generate ATTACH VARCHAR2(30) Available Region segments, separated by commas CURRENTVAL NUMBER(15) The maximum number of currently allocated sequence numbers STEP NUMBER(15) The number of sequence numbers assigned each time GMT_MODIFIED DATE Modification time
[0155] The data type is the data type in the database. For example, VARCHAR2(30) indicates a VARCHAR2 data type with a data length of 30. The business type is the business identification information of the business to which the serial number belongs. The counter name is the identification information of the counter. The maximum sequence number that the counter can generate is the maximum count value MAXVAL-1 in the counting range of the counter. The available Region segment is the segment in the segment sequence. The maximum value of the currently allocated sequence number is the current value before the counter starts counting. The number of sequence numbers allocated each time is the target step size. The modification time is the counting time.
[0156] The core SQL statements are as follows:
[0157] UPDATE SYSSEQUENCE SET CURRENTVAL=MOD((CURRENTVAL+STEP),MAXVAL-1),GMT_MODIFIED=#{gmtModified,jdbcType=TIMESTA MP}WHERE COUNTER=#{counter,jdbcType=VARCHAR}。 Among them, MOD((CURRENTVAL+STEP),MAXVAL-1) means that the MOD operation (i.e., remainder) is used to count STEP times based on the current value CURRENTVAL of the counter, and each count satisfies that the count value is less than or equal to MAXVAL-1. Among them, gmtModified is the time value of the modification time, and counter is the name of the counter.
[0158] Optionally, if CURRENTVAL+STEP is greater than MAXVAL-1, CURRENTVAL can be cleared. Therefore, each time an UPDATE statement is executed, the MOD operation can be used to automatically generate a cyclic sequence number, avoiding manual intervention to reset the available serial number.
[0159] Optionally, by utilizing the transaction characteristics of a relational database, when the transaction isolation level of the relational database is READ_COMMITTED, performing an UPDATE operation on a row of data in the database will obtain a lock on the row of data, and other processes will wait for operations on the row of data. In other words, when the UPDATE operation is executed, other processes in the database on the second device are suspended. Therefore, there will be no repeated operation to obtain a set of sequence numbers for a target step size on a certain segment.
[0160] Optionally, when the segment sequence is updated, the counting threshold may be updated, that is, the MAXVAL in the SQL statement may be updated to achieve expansion of the counter.
[0161] Optionally, the second device updates the segment sequence in response to receiving the segment released by the old version computing system, and updates the count threshold according to the updated segment sequence. For example, if the old version computing system releases segment 10, the second device adds segment 10 to the end of the existing segment sequence.
[0162] S504: The second device sends a sequence number generated by a counter to the first device.
[0163] In this step, after the counter in the second device generates a sequence number of the target step length, the generated sequence number is sent to the first device to meet the sequence number requirement of the first device.
[0164] S505: The first device generates a serial number using the sequence number.
[0165] In this step, after receiving the sequence numbers returned by the second device, the first device stores these sequence numbers and can use these sequence numbers to generate serial numbers when receiving a serial number application request. The specific process of serial number generation can refer to the description of the above embodiments and will not be repeated here.
[0166] In the embodiment of the present application, the first device requests the target step length sequence number from the second device, the second device counts the sequence number according to the counting range of the counter, returns the counted sequence number to the first device, and the first device stores these sequence numbers and uses these sequence numbers to generate serial numbers. Thus, on the one hand, unified counting of sequence numbers is realized on the second device, without the need to count sequence numbers by separate counters under each segment, which improves the balance of segment utilization, and this method will not lose performance as the segments released by the old version of the computing system increase (the number of calculators in the traditional counter scheme will also increase linearly with the increase of segments), improves the efficiency of sequence number generation, and reduces the maintenance cost of the counter. On the other hand, based on the mapping between the sequence number and the sequence number of the segment, the determination of the segment can be realized on the first device based on the sequence number, reducing the dependence on the database on the second device, and will not bring additional read and write pressure to the database.
[0167] Figure 6 FIG. 1 is a flowchart of a method for generating a serial number according to another embodiment of the present application. Figure 6 As shown, the serial number generation method includes:
[0168] S601: In response to a received serial number application request, the first device detects whether the number of sequence numbers stored in the first device meets a preset condition.
[0169] Among them, the number of sequence numbers stored in the first device satisfies the preset conditions, including at least one of the following: the number of sequence numbers stored in the first device is a first threshold, and the ratio of the number of sequence numbers stored in the first device to the preset number is a second threshold. For details, please refer to the description of the above embodiment.
[0170] In this step, when receiving a serial number application request from a user or a business application, it is detected whether the number of sequence numbers stored in the first device meets the preset condition. If it is detected that the number of sequence numbers stored in the first device meets the preset condition, it indicates that the sequence numbers on the first device may be insufficient, and the sequence numbers can be applied to the second device in an asynchronous manner and stored, and S602 is executed. Otherwise, it indicates that the number of sequence numbers on the first device is sufficient, and S603 is executed.
[0171] S602: Asynchronously send a first message to the second device, where the first message is used to apply for a target step sequence number from the second device.
[0172] In this step, when the number of sequence numbers stored in the first device meets the preset condition, a first message is sent to the second device to supplement the sequence numbers stored in the first device. After receiving the sequence number returned by the second device, the first device stores the sequence number returned by the second device, that is, S605 can be executed. It should be noted that, since the first message is sent asynchronously at this time, the execution of S602 and S605 does not affect the execution of S606. In other words, S602 can be executed synchronously with S606.
[0173] Optionally, when sending the first message to the second device, the first device may send a second message to the second device, wherein the second message is used to request the second device to update the segment sequence, so as to timely update the segment sequence on the first device, ensure that the segment sequence on the first device is consistent with the segment sequence on the second device, and realize the sharing of the segment sequence among multiple nodes in the new version of the computing system.
[0174] Optionally, after the first device is started, the first device may send a second message to the second device, wherein the second message is used to request the second device to update the segment sequence, so as to timely update the segment sequence on the first device, thereby ensuring that the segment sequence is updated in time after the first device is started.
[0175] When updating the segment sequence, the new segment is added at the end of the segment sequence to ensure the order of the segments in the segment sequence and avoid duplication of serial numbers.
[0176] S603: Detect whether the number of sequence numbers stored in the first device is zero.
[0177] In this step, when the number of sequence numbers stored in the first device does not meet the preset conditions, it is determined whether the number of sequence numbers stored in the first device is zero. If so, it is necessary to apply for sequence numbers from the second device and execute S604. Otherwise, execute S606 to generate serial numbers.
[0178] S604: Terminate the generation of the serial number, and send a first message to the second device.
[0179] In this step, when the number of sequence numbers stored in the first device is zero, the serial number cannot be generated, so it is necessary to terminate the serial number generation process and request the sequence number from the second device. After receiving the sequence number returned by the second device, the first device stores the sequence number returned by the second device, and S605 can be executed. It should be noted that since the first message is not sent asynchronously at this time, S603, S604, and S605 are executed before S606.
[0180] S605: Receive and store the sequence number returned by the second device.
[0181] S606: Obtain the target sequence number, and determine the sequence number of the target segment corresponding to the target sequence number in the segment sequence according to the number of digits of the sequence number in the serial number and the target sequence number.
[0182] S607 . Search the target segment in the segment sequence according to the sequence number of the target segment.
[0183] S608. Determine the target serial number according to the target segment and the target sequence number.
[0184] Among them, S605 to S608 can refer to the description of the above-mentioned embodiment and will not be described in detail.
[0185] In the embodiment of the present application, in the process of generating a serial number, the first device first performs two tests on the number of sequence numbers stored in the first device, one is a test to see if a preset condition is met, and the other is a test to see if the number of sequence numbers is zero, so as to timely supplement the sequence numbers stored in the first device, and use the sequence numbers stored in the first device to generate serial numbers. Therefore, in the embodiment, in addition to applying for a sequence number from the second device when the number of sequence numbers stored on the first device is zero, a secondary storage (or secondary cache) is added on the first device by asynchronously sending a first message, which can avoid congestion in obtaining serial numbers at high concurrency.
[0186] Figure 7 This is a schematic diagram of the structure of a serial number generation device provided in an embodiment of the present application. The serial number generation device is applied to a first device, and the first device is a service processing node in a new version computing system. Figure 7 As shown, the serial number generating device includes:
[0187] An acquisition module 701 is used to acquire a target sequence number from sequence numbers stored in a first device, where the stored sequence numbers come from a counter in a second device, and the second device is a data storage node in a new version of the computing system;
[0188] A determination module 702, configured to determine, according to the number of digits of the sequence number in the serial number and the target sequence number, the sequence number of the target segment corresponding to the target sequence number in the segment sequence, the segment sequence being from a database in the second device, and the segments in the segment sequence being segments released by the old version computing system;
[0189] A search module 703 is used to search for a target segment in the segment sequence according to the sequence number of the target segment;
[0190] The generating module 704 is used to generate a target serial number according to the target sequence number and the target section.
[0191] In a possible implementation, the determination module 702 is specifically configured to: perform a modulo operation on the target sequence number according to the number of digits of the sequence number in the serial number to obtain the sequence number of the target segment in the segment sequence.
[0192] In a possible implementation, the generating module 704 is specifically configured to: if the target segment is the first segment in the segment sequence, fill the high bits of the target sequence number with zeros according to the number of digits of the sequence number in the serial number;
[0193] The target serial number is obtained based on the target segment and the target sequence number after zero padding.
[0194] In one possible implementation, the generation module 704 is specifically used to: if the target segment is not the first segment in the segment sequence, determine the total number of sequence numbers corresponding to the target segment and the segments before the target segment in the segment sequence according to the sequence number of the target segment and the number of digits of the sequence number in the serial number; perform a modulo operation on the target sequence number according to the total number of sequence numbers to obtain an operation result; fill the high digits of the operation result with zeros according to the number of digits of the sequence number in the serial number; and obtain the target serial number according to the operation result after filling with zeros and the target sequence number.
[0195] In a possible implementation, the serial number generating device further includes:
[0196] A first sending module (not shown), configured to send a first message to the second device if the number of sequence numbers stored in the first device is zero, wherein the first message is used to apply for a sequence number from the second device;
[0197] The first receiving module (not shown) is used to receive and store one or more sequence numbers returned by the second device.
[0198] In a possible implementation, the serial number generating device further includes:
[0199] A second sending module (not shown) is used to asynchronously send a first message to the second device if the number of sequence numbers stored in the first device meets a preset condition, and the first message is used to apply for a sequence number from the second device; wherein the number of sequence numbers stored in the first device meets the preset condition and includes at least one of the following: the number of sequence numbers stored in the first device is a first threshold, and the ratio of the number of sequence numbers stored in the first device to the preset number is a second threshold.
[0200] In a possible implementation, the serial number generating device further includes:
[0201] A third sending module (not shown), configured to send a second message to the second device, where the second message is used to request the second device to update the segment sequence;
[0202] The second receiving module (not shown) is used to receive and store the segment sequence returned by the second device.
[0203] In a possible implementation manner, the third sending module is specifically configured to: send a second message to the second device after the first message is sent to the second device or the first device is started.
[0204] Figure 8 This is a structural diagram of a serial number generating device provided by another embodiment of the present application, the serial number generating device is applied to a second device, and the second device is a data storage node in a new version of the computing system. Figure 8 As shown, the serial number generating device includes:
[0205] A receiving module 801 is used to receive a first message sent by a first device, where the first message is used to apply for a sequence number from a second device;
[0206] A determination module 802 is used to determine a target step length according to the first message, where the target step length is the number of sequence numbers applied for by the first device;
[0207] The counting module 803 is used to obtain the sequence number by counting the number of digits of the sequence number in the serial number, the number of segments in the segment sequence and the target step length through a counter, wherein the segments in the segment sequence are the segments released by the old version computing system;
[0208] The sending module 804 is used to send the sequence number generated by the counter to the first device, so that the first device generates a serial number using the sequence number.
[0209] In one possible implementation, the counting module 803 is specifically used to: determine the counting threshold based on the number of digits in the sequence number in the serial number and the number of segments in the segment sequence; count in sequence according to the current value of the counter to obtain the sequence number until the number of counts reaches the target step or the sequence number obtained by counting is equal to the counting threshold.
[0210] In a possible implementation, the serial number generating device further includes:
[0211] An update module (not shown) is used to: update the segment sequence in response to receiving the segment released by the old version computing system; and update the counting threshold according to the updated segment sequence.
[0212] Figure 7 and Figure 8 The serial number generating device provided can execute the above-mentioned corresponding method embodiments, and its implementation principle and technical effect are similar, which will not be repeated here.
[0213] Fig. 9 The structure diagram of an electronic device provided by an embodiment of the present application is shown in FIG. 9 . For example, the serial number generating device 900 may be provided as a server or a terminal. Fig. 9 As shown, the serial number generating device 900 includes a processing component 901, which further includes one or more processors, and a memory resource represented by a memory 902, which is used to store instructions that can be executed by the processing component 901, such as an application. The application stored in the memory 902 can include one or more modules, each corresponding to a set of instructions. In addition, the processing component 901 is configured to execute instructions to execute the serial number generating method of any of the above embodiments.
[0214] The serial number generating device 900 may further include a power supply component 903 configured to perform power management of the serial number generating device 900, a wired or wireless network interface 904 configured to connect the serial number generating device 900 to a network, and an input / output (I / O) interface 905. The serial number generating device 900 may operate based on an operating system stored in the memory 902, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.
[0215] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 902 including instructions, and the instructions can be executed by a processor of the serial number generating device 900 to complete the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0216] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute a method for generating a serial number as described in any of the above embodiments.
[0217] An embodiment of the present application also provides a program product, which includes a computer program. The computer program is stored in a storage medium. At least one processor can read the computer program from the storage medium. When the at least one processor executes the computer program, the serial number generation method of any of the above embodiments can be implemented.
[0218] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0219] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for generating a serial number, characterized in that: Applied to a first device, the first device being a service processing node in a new version computing system, the serial number generation method includes: Obtaining a target sequence number from sequence numbers stored in the first device, the stored sequence numbers coming from a counter in a second device, the second device being a data storage node in the new version computing system; Determine, according to the number of digits of the sequence number in the serial number and the target sequence number, the sequence number of the target segment corresponding to the target sequence number in the segment sequence, the segment sequence being from a database in the second device, and the segments in the segment sequence being segments released by the old version computing system; According to the sequence number of the target segment, searching for the target segment in the segment sequence; Generate a target serial number according to the target sequence number and the target section; The step of determining the sequence number of the target segment corresponding to the target sequence number in the segment sequence according to the number of digits of the sequence number in the serial number and the target sequence number comprises: According to the number of digits of the sequence number in the serial number, a modulo operation is performed on the target sequence number to obtain the sequence number of the target segment in the segment sequence; The step of generating a target serial number according to the target sequence number and the target section includes: If the target segment is the first segment in the segment sequence, the high bits of the target sequence number are padded with zeros according to the number of digits of the sequence number in the serial number; Obtaining the target serial number according to the target segment and the target sequence number after the zero padding; If the target segment is not the first segment in the segment sequence, determining the total number of sequence numbers corresponding to the target segment and the segments preceding the target segment in the segment sequence according to the sequence number of the target segment and the number of digits of the sequence number in the serial number; According to the total number of sequence numbers, a modulo operation is performed on the target sequence number to obtain an operation result; Filling zeros at the high digits of the operation result according to the number of digits of the sequence number in the serial number; The target serial number is obtained according to the operation result after zero padding and the target sequence number.
2. The method for generating a serial number according to claim 1, characterized in that: Before obtaining the target sequence number, the serial number generation method further includes: If the number of sequence numbers stored in the first device is zero, sending a first message to the second device, where the first message is used to apply for a sequence number from the second device; Receive and store one or more sequence numbers returned by the second device.
3. The method for generating a serial number according to claim 1, characterized in that: Before obtaining the target sequence number, the serial number generation method further includes: If the number of sequence numbers stored in the first device meets a preset condition, asynchronously sending a first message to the second device, where the first message is used to apply for a sequence number from the second device; The number of sequence numbers stored in the first device satisfying a preset condition includes at least one of the following: the number of sequence numbers stored in the first device is a first threshold, and the ratio of the number of sequence numbers stored in the first device to the preset number is a second threshold.
4. The method for generating a serial number according to claim 1, characterized in that: The determining that the target segment corresponding to the target sequence number is before the sequence number in the segment sequence, the serial number generation method further comprises: sending a second message to the second device, where the second message is used to request the second device to update a segment sequence; The segment sequence returned by the second device is received and stored.
5. The method for generating a serial number according to claim 4, characterized in that: The sending a second message to the second device includes: After the first message is sent to the second device or the first device is started, the second message is sent to the second device.
6. A method for generating a serial number, characterized in that: Applied to a second device, the second device being a data storage node in a new version of a computing system, the serial number generation method includes: receiving a first message sent by a first device, where the first message is used to apply for a sequence number from the second device; Determine a target step length according to the first message, where the target step length is the number of application sequence numbers of the first device; According to the number of digits of the sequence number in the serial number, the number of segments in the segment sequence and the target step length, a sequence number is obtained by counting with a counter, wherein the segments in the segment sequence are segments released by the old version computing system; Send the sequence number generated by the counter to the first device, so that the first device generates a serial number using the serial number generation method described in any one of claims 1-5.
7. The method for generating a serial number according to claim 6, characterized in that: The obtaining of the sequence number by counting with a counter according to the number of digits of the sequence number in the serial number, the number of segments in the segment sequence and the target step length comprises: Determining a counting threshold according to the number of digits of the sequence number in the serial number and the number of segments in the segment sequence; According to the current value of the counter, counting is performed in sequence to obtain a sequence number until the number of counts reaches the target step length or the sequence number obtained by counting is equal to the counting threshold.
8. The method for generating a serial number according to claim 7, characterized in that: The serial number generation method further comprises: In response to receiving a segment released by the old version computing system, updating the segment sequence; The counting threshold is updated according to the updated segment sequence.
9. A serial number generating device, characterized in that: Applied to a first device, the first device being a service processing node in a new version computing system, the serial number generating device comprising: An acquisition module, configured to acquire a target sequence number from sequence numbers stored in the first device, wherein the stored sequence numbers are from a counter in a second device, and the second device is a data storage node in the new version computing system; a determination module, configured to determine, according to the number of digits of the sequence number in the serial number and the target sequence number, a sequence number of a target segment corresponding to the target sequence number in a segment sequence, wherein the segment sequence is from a database in the second device, and the segments in the segment sequence are segments released by an old version computing system; A search module, configured to search for the target segment in the segment sequence according to the sequence number of the target segment; A generating module, used for generating a target serial number according to the target sequence number and the target section; The determination module is specifically configured to perform a modulo operation on the target sequence number according to the number of digits of the sequence number in the serial number to obtain the sequence number of the target segment in the segment sequence; The generating module is specifically used for padding the high digits of the target sequence number with zeros if the target segment is the first segment in the segment sequence according to the number of digits of the sequence number in the serial number; obtaining the target serial number according to the target segment and the target sequence number after padding with zeros; if the target segment is not the first segment in the segment sequence, determining the total number of sequence numbers corresponding to the target segment and the segments before the target segment in the segment sequence according to the sequence number of the target segment and the number of digits of the sequence number in the serial number; performing a modulo operation on the target sequence number according to the total number of sequence numbers to obtain an operation result; padding the high digits of the operation result with zeros according to the number of digits of the sequence number in the serial number; and obtaining the target serial number according to the operation result after padding with zeros and the target sequence number.
10. A serial number generating device, characterized in that: Applied to a second device, the second device is a node where a database is located in a new version computing system, and the serial number generating device includes: A receiving module, configured to receive a first message sent by a first device, wherein the first message is used to apply for a sequence number from the second device; A determination module, configured to determine a target step length according to the first message, wherein the target step length is the number of sequence numbers applied for by the first device; A counting module, used for obtaining a sequence number by counting through a counter according to the number of digits of the sequence number in the serial number, the number of segments in the segment sequence and the target step length, wherein the segments in the segment sequence are segments released by the old version computing system; A sending module is used to send the sequence number generated by the counter to the first device, so that the first device generates a serial number using the serial number generation method described in any one of claims 1-5.
11. An electronic device, comprising: Memory, processor; Memory; a memory for storing instructions executable by the processor; The processor is configured to execute the serial number generating method as claimed in any one of claims 1 to 8.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the serial number generation method according to any one of claims 1 to 8.
13. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method for generating a serial number according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Serial number generation method and device, and server
CN110765732A
Serial number generation method, device and system, terminal equipment and storage medium
CN111124359A
Serial number generation method and device
CN112541040A
Sequence notification apparatus and sequence notification method
WO2009044543A1
