A distributed sequence number generation method and device

By obtaining and updating the serial number parameters in the configuration file, a preset number of serial numbers are generated and used, which solves the problems of high pressure on the database and complex operation and maintenance in the existing technology, and achieves efficient and simplified distributed serial number generation. Reduces the computing pressure and operation and maintenance complexity of the computer.

CN111949324BActive Publication Date: 2024-08-30SI-TECH INFORMATION TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202010705878.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-21
Publication Date
2024-08-30
Estimated Expiration
2040-07-21

AI Technical Summary

Technical Problem

The existing distributed serial number generation method puts a lot of pressure on the database, and the method that relies on the database is not applicable. The UUID generation method cannot solve the sorting problem. The Redis ID generation method requires the installation of new components and is highly complex, increasing the complexity of operation and maintenance. .

Method used

By obtaining the configuration parameters in the preset configuration file, including the first maximum serial number and queue length, a preset number of serial numbers are generated, and the target serial numbers are obtained from these serial numbers according to the number of program calls, without the need to update the configuration each time files, reducing computer calculation pressure and improving efficiency.

Benefits of technology

It realizes the efficient generation of serial numbers in a distributed system, reduces the computing pressure of the computer, saves time, improves efficiency, and simplifies the operation and maintenance process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111949324B
    Figure CN111949324B
Patent Text Reader

Abstract

The present invention provides a distributed sequence number generation method and device. The method obtains configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length; generates a preset number of sequence numbers according to the first maximum sequence number and the queue length and determines a second maximum sequence number, wherein the preset number is the same as the queue length, and updates the first maximum sequence number in the configuration file according to the second maximum sequence number; obtains a target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls, generates a preset number of sequence numbers once, and selects corresponding sequence numbers from the generated sequence numbers in sequence according to the number of program calls, without updating the configuration file each time, thereby reducing the computing pressure of the computer, saving time, and improving efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a distributed serial number generation method and device, a computing device and a storage medium. Background Art

[0002] With the rapid development of computer technology, more and more software applications are now used in distributed systems.

[0003] Among the existing distributed sequence generation methods, some are automatically generated using the serial number generator that comes with the database, but this method requires the database to have a single database and a single table, which puts a lot of pressure on the database, and some databases do not have a serial number generator. There is also a method of generating a hexadecimal string through UUID, but this method cannot solve the sorting problem. Another method is to generate an ID through Redis. Although Redis does not rely on the database and is flexible and convenient, if there is no Redis in the computer, new components need to be installed, which increases the complexity of the computer, and the workload of coding and configuration is relatively large, and multi-environment operation and maintenance is very complicated.

[0004] The above methods all have obvious disadvantages, so a more convenient method for generating serial numbers is needed. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a distributed serial number generation method and apparatus, a computing device and a storage medium to solve the technical defects existing in the prior art.

[0006] The embodiment of the present invention discloses a distributed sequence number generation method, including:

[0007] S1. Obtain configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length;

[0008] S2. Generate a preset number of sequence numbers according to the first maximum sequence number and the queue length and determine a second maximum sequence number, wherein the preset number is the same as the queue length;

[0009] S3. Update the first maximum sequence number in the configuration file according to the second maximum sequence number;

[0010] S4. Obtain the target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls.

[0011] Optionally, after step S4, the method further includes:

[0012] S5. Count the number of program calls, and when the number of program calls is greater than the queue length, execute steps S1 to S4.

[0013] Optionally, the configuration parameters also include a sequence initial value;

[0014] Generating a preset number of serial numbers according to the configuration parameters includes:

[0015] When a preset number of sequence numbers are generated according to the configuration parameters for the first time, the sequence initial value is used as the first maximum sequence number.

[0016] Optionally, the configuration parameters also include a machine identifier;

[0017] Obtaining a target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls, including:

[0018] Reading an initial sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls;

[0019] A target sequence number corresponding to the current program call is generated according to the initial sequence number and the machine identifier.

[0020] The embodiment of the present invention further discloses a distributed sequence number generating device, including:

[0021] A generating module is configured to obtain configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length;

[0022] a determination module, configured to generate a preset number of sequence numbers and determine a second maximum sequence number according to the first maximum sequence number and the queue length, wherein the preset number is the same as the queue length;

[0023] an updating module, configured to update the first maximum sequence number in the configuration file according to the second maximum sequence number;

[0024] The acquisition module is configured to sequentially acquire the target sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls.

[0025] Optionally, the device further comprises:

[0026] The statistical module is configured to count the number of program calls, and execute the generating module when the number of program calls is greater than the queue length.

[0027] Optionally, the configuration parameters also include a sequence initial value;

[0028] The generating module is further configured to use the sequence initial value as the first maximum sequence number when a preset number of sequence numbers are generated according to the configuration parameters for the first time.

[0029] Optionally, the configuration parameters also include a machine identifier;

[0030] The acquisition module is further configured to:

[0031] Reading an initial sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls;

[0032] A target sequence number corresponding to the current program call is generated according to the initial sequence number and the machine identifier.

[0033] An embodiment of the present invention discloses a computing device, including a memory, a processor, and computer instructions stored in the memory and executable on the processor. When the processor executes the instructions, the steps of the distributed serial number generation method as described above are implemented.

[0034] An embodiment of the present invention discloses a storage medium storing computer instructions, which implement the steps of the distributed serial number generation method as described above when executed by a processor.

[0035] The present invention provides a distributed sequence number generation method and apparatus, a computing device and a storage medium. The method obtains configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length; generates a preset number of sequence numbers according to the first maximum sequence number and the queue length and determines a second maximum sequence number, wherein the preset number is the same as the queue length, and updates the first maximum sequence number in the configuration file according to the second maximum sequence number; obtains a target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls, generates a preset number of sequence numbers once, and selects corresponding sequence numbers from the generated sequence numbers in sequence according to the number of program calls, without updating the configuration file each time, thereby reducing the computing pressure of the computer, saving time and improving efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 It is a flow chart of a distributed sequence number generation method according to an embodiment of the present invention;

[0037] Figure 2 It is a schematic diagram of the structure of a distributed sequence number generating device according to an embodiment of the present invention;

[0038] Figure 3 It is a schematic diagram of the structure of a computing device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0039] Many specific details are set forth in the following description to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present invention, so the present invention is not limited to the specific implementation disclosed below.

[0040] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.

[0041] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0042] The invention provides a distributed sequence number generation method and apparatus, a computing device and a storage medium. Figure 1 The present invention is described in detail.

[0043] Figure 1 A schematic flow chart of a distributed sequence number generation method according to an embodiment of the present invention is shown, including steps 102 to 108.

[0044] Step 102: Obtain configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length.

[0045] The present invention generates a preset number of serial numbers without relying on other software and applications, and can generate unique serial numbers under distributed deployment through configuration parameters in a preset configuration file.

[0046] The configuration parameters in the file include the first maximum sequence number and the queue length. The number of sequence numbers generated at one time can be determined based on the queue length. For example, if the queue length is 100, 100 sequence numbers are generated. The first maximum sequence number is the largest sequence number in the system under the current state. The maximum sequence number is identified by cur_max. When cur_max=100000000, it means that the maximum sequence number in the distributed system is 100000000.

[0047] Optionally, the configuration parameter further includes a sequence initial value; and generating a preset number of sequence numbers according to the configuration parameter includes:

[0048] When a preset number of sequence numbers are generated according to the configuration parameters for the first time, the sequence initial value is used as the first maximum sequence number.

[0049] In actual applications, the configuration parameters also include a sequence initial value. For example, if the sequence initial value is set to 100000000, it means that the serial number starts counting from 100000000. When a preset number of sequence numbers are generated for the first time, the sequence initial value is the first maximum sequence number, that is, when a preset number of sequence numbers are generated for the first time, the sequence numbers are generated based on the sequence initial value.

[0050] Step 104: Generate a preset number of sequence numbers according to the first maximum sequence number and the queue length and determine a second maximum sequence number, wherein the preset number is the same as the queue length.

[0051] Specifically, a preset number of sequence numbers can be generated according to the first maximum sequence number and the queue length, including the queue length being the preset number value. For example, if the queue length is 100, 100 sequence numbers are generated; if the queue length is 200, 200 sequence numbers are generated. At this time, the second maximum sequence number can be determined according to the first maximum sequence number and the queue length.

[0052] The second maximum sequence number is the maximum sequence number existing in the system after a preset number of sequence numbers are generated. Taking the first maximum sequence number as 100000000 and the queue length as 100 as an example, 100 sequence numbers are generated, and the second maximum sequence number is 100000100.

[0053] Step 106: Update the first maximum sequence number in the configuration file according to the second maximum sequence number.

[0054] Specifically, the second maximum sequence number is used to update the first maximum sequence number in the configuration file, which means that the largest sequence number in the system is the second maximum sequence number.

[0055] Using the above example, the first maximum sequence number is 100000000. After a preset number of sequence numbers are generated, the second maximum sequence number is 100000100. At this time, 100000100 is updated to the configuration file, and 100000000 is updated to 100000100.

[0056] Step 108: Obtain the target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls.

[0057] According to the number of times the program is called, the serial number corresponding to the current program call is obtained from the generated serial numbers. For example, if the preset number of serial numbers is from 100000000 to 100000100, the serial number corresponding to the first program call is 100000001, the serial number corresponding to the second program call is 100000002, and so on.

[0058] Optionally, the configuration parameters also include a machine identifier;

[0059] Obtaining a target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls, including:

[0060] Reading an initial sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls;

[0061] A target sequence number corresponding to the current program call is generated according to the initial sequence number and the machine identifier.

[0062] In actual applications, the configuration parameters of the configuration file also include the machine ID. For example, if the machine ID is 01, the serial number corresponding to the current program call is used as the initial serial number, and the initial serial number and the machine ID are combined to generate the target serial number. The target serial number for the first program call is 01100000001, the target serial number for the second program call is 01100000002, and so on.

[0063] Optionally, after step 108, the method further includes:

[0064] The number of program calls is counted, and when the number of program calls is greater than the queue length, steps 102 to 108 are executed.

[0065] The number of calls is counted after each program call. When the number of calls is less than or equal to the queue length, it means that the pre-generated serial number has not been used up and can continue to be used. When the number of calls is greater than the queue length, it is necessary to re-execute step 102 to generate a new preset serial number, and update the current queue maximum value with the new queue maximum value, and then loop through steps 102 to 108.

[0066] The present invention provides a distributed sequence number generation method, which obtains configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length; generates a preset number of sequence numbers according to the first maximum sequence number and the queue length and determines a second maximum sequence number, wherein the preset number is the same as the queue length, and updates the first maximum sequence number in the configuration file according to the second maximum sequence number; obtains a target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls, generates a preset number of sequence numbers once, and selects corresponding sequence numbers from the generated sequence numbers in sequence according to the number of program calls, without updating the configuration file each time, thereby reducing the computing pressure of the computer, saving time, and improving efficiency.

[0067] Figure 2 The structure diagram of a distributed sequence number generating device according to an embodiment of the present specification is shown, including:

[0068] The generating module 202 is configured to obtain configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length;

[0069] The determination module 204 is configured to generate a preset number of sequence numbers and determine a second maximum sequence number according to the first maximum sequence number and the queue length, wherein the preset number is the same as the queue length,

[0070] An updating module 206, configured to update the first maximum sequence number in the configuration file according to the second maximum sequence number;

[0071] The acquisition module 208 is configured to sequentially acquire the target sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls.

[0072] Optionally, the device further comprises:

[0073] The statistical module is configured to count the number of program calls, and execute the generating module when the number of program calls is greater than the queue length.

[0074] Optionally, the configuration parameters also include a sequence initial value;

[0075] The generating module 202 is further configured to use the sequence initial value as the first maximum sequence number when a preset number of sequence numbers are generated according to the configuration parameters for the first time.

[0076] Optionally, the configuration parameters also include a machine identifier;

[0077] The acquisition module 208 is further configured to:

[0078] Reading an initial sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls;

[0079] A target sequence number corresponding to the current program call is generated according to the initial sequence number and the machine identifier.

[0080] The present invention provides a distributed sequence number generation device, which obtains configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length; generates a preset number of sequence numbers according to the first maximum sequence number and the queue length and determines a second maximum sequence number, wherein the preset number is the same as the queue length, and updates the first maximum sequence number in the configuration file according to the second maximum sequence number; obtains a target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls, generates a preset number of sequence numbers once, and selects corresponding sequence numbers from the generated sequence numbers in sequence according to the number of program calls, without updating the configuration file each time, thereby reducing the computing pressure of the computer, saving time, and improving efficiency.

[0081] Figure 3 3 is a block diagram showing a computing device 300 according to an embodiment of the present specification. The components of the computing device 300 include but are not limited to a memory 310 and a processor 320. The processor 320 is connected to the memory 310 via a bus 330, and the database 350 is used to store data.

[0082] The computing device 300 also includes an access device 340 that enables the computing device 300 to communicate via one or more networks 360. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 340 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.

[0083] In one embodiment of the present specification, the above components of the computing device 300 and Figure 3 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 3The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.

[0084] The computing device 300 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 300 may also be a mobile or stationary server.

[0085] An embodiment of the present invention further provides a computing device, including a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein the processor implements the steps of the distributed serial number generation method as described above when executing the instructions.

[0086] An embodiment of the present invention further provides a storage medium storing computer instructions, which, when executed by a processor, implement the steps of the distributed serial number generation method as described above.

[0087] The above is a schematic scheme of a storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the above distributed sequence number generation method belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the above distributed sequence number generation method.

[0088] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0089] It should be noted that, for the convenience of description, the aforementioned method embodiments are all described as a series of action combinations, but those skilled in the art should be aware that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.

[0090] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0091] The preferred embodiments of the present invention disclosed above are only used to help illustrate the present invention. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and changes can be made according to the content of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present invention, so that those skilled in the art can understand and use the present invention well. The present invention is limited only by the claims and their full scope and equivalents.

Claims

1. A distributed sequence number generation method, characterized in that: include: S1. Obtain configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length; S2. Taking the first maximum sequence number as the starting sequence number, generating a preset number of sequence numbers in a step-by-step increasing manner based on the first maximum sequence number, and taking the last sequence number as the second maximum sequence number, wherein the preset number is the same as the queue length; S3. Update the first maximum sequence number in the configuration file to the second maximum sequence number; S4, sequentially obtaining a target sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls; wherein the configuration parameter also includes a machine identifier; sequentially obtaining a target sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls, including: reading an initial sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls; generating a target sequence number corresponding to the current program call according to the initial sequence number and the machine identifier; wherein the initial sequence number is the sequence number corresponding to the current program call, that is, if it is the Nth call, the initial sequence number is the Nth sequence number in the preset number of sequence numbers generated by S2; S5. Count the number of program calls, and when the number of program calls is greater than the queue length, execute steps S1 to S4.

2. The distributed sequence number generation method according to claim 1, characterized in that: The configuration parameters also include a sequence initial value; Generating a preset number of serial numbers according to the configuration parameters includes: When a preset number of sequence numbers are generated according to the configuration parameters for the first time, the sequence initial value is used as the first maximum sequence number.

3. A distributed sequence number generating device, characterized in that: include: A generating module is configured to obtain configuration parameters in a preset configuration file, wherein the configuration parameters include a first maximum sequence number and a queue length; A determination module, taking the first maximum sequence number as the starting sequence number, generating a preset number of sequence numbers in a step-by-step increasing manner based on the first maximum sequence number, and taking the last sequence number as the second maximum sequence number, wherein the preset number is the same as the queue length; an updating module, configured to update the first maximum sequence number in the configuration file according to the second maximum sequence number; The acquisition module is configured to acquire the target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls; wherein the configuration parameter also includes a machine identifier; acquiring the target sequence number corresponding to the current program call from the preset number of sequence numbers in sequence according to the number of program calls, including: reading the initial sequence number corresponding to the current program call from the preset number of sequence numbers according to the number of program calls; generating the target sequence number corresponding to the current program call according to the initial sequence number and the machine identifier; wherein the initial sequence number is the sequence number corresponding to the current program call, that is, if it is the Nth call, the initial sequence number is the Nth sequence number in the preset number of sequence numbers generated by S2; The statistical module is configured to count the number of program calls, and execute the generating module, updating module and acquiring module when the number of program calls is greater than the queue length.

4. The distributed serial number generating device according to claim 3, characterized in that: The configuration parameters also include a sequence initial value; The generating module is further configured to use the sequence initial value as the first maximum sequence number when a preset number of sequence numbers are generated according to the configuration parameters for the first time.

5. A computing device comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the instructions, the steps of the method according to any one of claims 1 to 2 are implemented.

6. A storage medium storing computer instructions, characterized in that: When the instruction is executed by a processor, the steps of the method described in any one of claims 1 to 2 are implemented.

Citation Information

Patent Citations

  • Linux operation system and verification method for installing serial number thereof

    CN102982260A

  • Method and device for generating serial numbers

    CN104951519A

  • Lightweight method and system for generating distributed serial numbers based on JAVA linked list

    CN107045445A

  • Flow control method and device for application program component

    CN111290696A