Water flow number generation method and device, computer device and readable storage medium
By creating ordered sets for projects, pre-generating serial numbers, and periodically checking and replenishing them, the uniqueness and performance issues of serial numbers under high concurrency were resolved. This achieved efficient and unique serial number generation, reduced database pressure, and improved business performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-04
- Publication Date
- 2026-03-24
AI Technical Summary
Under high concurrency, existing technologies cannot guarantee the uniqueness of serial numbers, which increases the pressure on the database. Furthermore, using database locks or distributed locks will degrade project performance and affect business performance.
By creating an ordered set for the project, serial numbers are pre-generated and stored in the set. The serial numbers are checked and replenished periodically, avoiding real-time queries for the maximum number in the database, thus reducing database pressure and performance overhead.
This ensures the uniqueness and efficient generation of serial numbers, reduces the database load, and improves the project's business performance.
Smart Images

Figure CN116483892B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, computer device, and readable storage medium for generating serial numbers. Background Technology
[0002] With the development of computer technology, more and more business scenarios involve retrieving serial numbers, such as exam numbers, bank transaction numbers, industrial product numbers, and transaction serial numbers. Because serial numbers are unique, simple to encode, and easy to use, they are often used as keywords to distinguish data records. In project requirements, it is sometimes necessary to generate unique serial numbers according to certain rules, and the serialization of these numbers must be maintained even after a system restart.
[0003] In related technologies, the server queries the corresponding table in the database for the maximum existing serial number, and then increments the serial number based on the obtained maximum value to generate new serial numbers, or stores the current maximum serial number in a third-party storage component to generate new serial numbers in real time when needed by the project. However, the applicant recognizes that the uniqueness of the generated serial numbers cannot be guaranteed under high concurrency, which increases the pressure on the database. Even using database-related locks or distributed locks will still degrade project performance, making it unfriendly to high-concurrency scenarios and the project's business performance. Summary of the Invention
[0004] In view of this, this application provides a serial number generation method, apparatus, computer device, and readable storage medium. The main purpose is to solve the problem that the uniqueness of serial number generation cannot be guaranteed under high concurrency, which increases the pressure on the database. Even if database-related locks or distributed locks are used, the performance of the project will be degraded. This is not friendly to high concurrency scenarios and the business performance of the project.
[0005] According to a first aspect of this application, a method for generating serial numbers is provided, the method comprising:
[0006] In response to a project initiation request, the target project indicated by the project initiation request is determined, and an ordered set is generated for the target project, the ordered set being used to store the serial numbers to be used by the target project;
[0007] Query the target serial number corresponding to the target project in the database, and add the serial number sequence generated by using preset business rules and the target serial number to the ordered set;
[0008] A preset inspection cycle is determined, and the number of serial numbers included in the ordered set is counted every preset inspection cycle;
[0009] If the quantity is less than a preset storage threshold, a backup serial number sequence is generated, and the backup serial number sequence is added to the ordered set.
[0010] Optionally, the step of querying the target serial number corresponding to the target project in the database, and adding the serial number sequence generated using preset business rules and the target serial number to the ordered set, includes:
[0011] Obtain the server access address corresponding to the target project, and query the database for the target serial number sequence corresponding to the server access address;
[0012] Obtain the last target sequence number from the target sequence numbering sequence;
[0013] Obtain the current date information, the preset business rules corresponding to the target project, and the preset generation quantity;
[0014] According to the preset business rules, the current date information, the server access address, and the target serial number are combined sequentially to obtain the first serial number;
[0015] The first serial number is incremented according to the preset generation quantity to generate the value of the preset generation quantity;
[0016] The values of the first serial number and the preset generation quantity are sorted according to the increasing relationship, and the sorted sequence is used as the serial number sequence, and the serial number sequence is added to the ordered set.
[0017] Optionally, the method further includes:
[0018] If the database query finds that the server access address does not have a corresponding target serial number sequence, then the initial serial number is set to 0;
[0019] According to the preset business rules, the current date information, the server access address, and the initial serial number are combined sequentially to obtain the second serial number;
[0020] The second serial number is incremented according to the preset generation quantity to generate the value of the preset generation quantity;
[0021] The values of the second serial number and the preset generation quantity are sorted according to the increasing relationship, and the sorted sequence is used as the serial number sequence, and the serial number sequence is added to the ordered set.
[0022] Optionally, determining the preset inspection cycle and counting the number of serial numbers included in the ordered set every preset inspection cycle includes:
[0023] Obtain the preset inspection cycle, and create a scheduled inspection task for the target project according to the preset inspection cycle;
[0024] The timed check task is executed every preset check cycle so that the number of serial numbers included in the ordered set is counted every preset check cycle.
[0025] Optionally, the step of generating a backup serial number sequence if the quantity is less than a preset storage threshold, and adding the backup serial number sequence to the ordered set, includes:
[0026] If the quantity is less than the preset storage threshold, then the last specified serial number is obtained from the serial number sequence included in the ordered set.
[0027] Obtain the current date information, the preset generation quantity, the preset business rules, and the server access address corresponding to the target project;
[0028] According to the preset business rules, the current date information, the server access address, and the specified serial number are combined sequentially to obtain the third serial number;
[0029] The third serial number is incremented according to the preset generation quantity to generate the value of the preset generation quantity;
[0030] The values of the third serial number and the preset generation quantity are sorted according to the increasing relationship, and the sorted sequence is used as the backup serial number sequence, and the backup serial number sequence is added to the ordered set.
[0031] Optionally, the method further includes:
[0032] When a serial number retrieval request is received, it is checked whether a serial number exists in the ordered set;
[0033] When a serial number is detected in the ordered set, the first number of serial numbers indicated by the serial number acquisition request is obtained;
[0034] Obtain the first number of serial numbers from the ordered set, and send the first number of serial numbers to the target project so that the target project uses the first number of serial numbers.
[0035] Optionally, after detecting whether a sequential number exists in the ordered set, the method further includes:
[0036] When it is detected that there is no serial number in the ordered set, the operation of querying the target serial number corresponding to the target project in the database and adding the serial number sequence generated by the preset business rules and the target serial number to the ordered set continues.
[0037] Obtain the second number of serial numbers indicated by the serial number acquisition request, and obtain the second number of serial numbers in the ordered set;
[0038] Send the second number of serial numbers to the target project so that the target project uses the second number of serial numbers.
[0039] According to a second aspect of this application, a serial number generation apparatus is provided, the apparatus comprising:
[0040] A response module is used to respond to a project launch request, determine the target project indicated by the project launch request, and generate an ordered set for the target project, wherein the ordered set is used to store the serial numbers to be used by the target project;
[0041] The generation module is used to query the target serial number corresponding to the target project in the database, and to add the serial number sequence generated by using preset business rules and the target serial number to the ordered set;
[0042] The inspection module is used to determine a preset inspection cycle and to count the number of serial numbers included in the ordered set every preset inspection cycle.
[0043] The supplementary module is used to generate a backup serial number sequence if the quantity is less than a preset storage threshold, and to add the backup serial number sequence to the ordered set.
[0044] Optionally, the generation module is configured to: obtain the server access address corresponding to the target project; query the database for the target serial number sequence corresponding to the server access address; obtain the last target serial number in the target serial number sequence; obtain current date information, the preset business rule corresponding to the target project, and the preset generation quantity; combine the current date information, the server access address, and the target serial number sequentially according to the preset business rule to obtain a first serial number; perform an increment operation on the first serial number according to the preset generation quantity to generate the value of the preset generation quantity; organize the value of the first serial number and the preset generation quantity according to the increment relationship, use the organized sequence as the serial number sequence, and add the serial number sequence to the ordered set.
[0045] Optionally, the generation module is further configured to: if the database query finds that the server access address does not have a corresponding target serial number sequence, set the initial serial number to 0; combine the current date information, the server access address, and the initial serial number sequentially according to the preset business rules to obtain a second serial number; perform an increment operation on the second serial number according to the preset generation quantity to generate the value of the preset generation quantity; organize the value of the second serial number and the preset generation quantity according to the increment relationship, use the organized sequence as the serial number sequence, and add the serial number sequence to the ordered set.
[0046] Optionally, the inspection module is used to obtain the preset inspection cycle, create a timed inspection task for the target project according to the preset inspection cycle, and execute the timed inspection task every preset inspection cycle so as to count the number of serial numbers included in the ordered set every preset inspection cycle.
[0047] Optionally, the supplementary module is configured to: if the quantity is less than the preset storage threshold, obtain the last specified serial number in the serial number sequence included in the ordered set; obtain the current date information, the preset generation quantity, the preset business rule, and the server access address corresponding to the target project; combine the current date information, the server access address, and the specified serial number in sequence according to the preset business rule to obtain a third serial number; perform an increment operation on the third serial number according to the preset generation quantity to generate the value of the preset generation quantity; organize the value of the third serial number and the preset generation quantity according to the increment relationship, use the organized sequence as the backup serial number sequence, and add the backup serial number sequence to the ordered set.
[0048] Optionally, the device further includes:
[0049] The sending module is configured to, when receiving a serial number retrieval request, detect whether a serial number exists in the ordered set; when a serial number is detected in the ordered set, obtain the first number quantity indicated by the serial number retrieval request; obtain the first number quantity of serial numbers in the ordered set; and send the first number quantity of serial numbers to the target project so that the target project uses the first number quantity of serial numbers.
[0050] Optionally, the sending module is further configured to, when detecting that no serial number exists in the ordered set, continue to perform the operations of querying the target serial number corresponding to the target project in the database, and adding the serial number sequence generated using preset business rules and the target serial number to the ordered set; obtain the second number quantity indicated by the serial number acquisition request, obtain the second number quantity of serial numbers in the ordered set; and send the second number quantity of serial numbers to the target project so that the target project uses the second number quantity of serial numbers.
[0051] According to a third aspect of this application, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method described in any of the first aspects above.
[0052] According to a fourth aspect of this application, a readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in any one of the first aspects above.
[0053] By employing the above technical solutions, this application provides a serial number generation method, apparatus, computer equipment, and readable storage medium. In response to a project initiation request, this application determines the target project indicated by the project initiation request, generates an ordered set for the target project, and stores the serial numbers to be used by the target project in the ordered set. It queries the database for the target serial number corresponding to the target project, adds the serial number sequence generated using preset business rules and the target serial number to the ordered set, determines a preset inspection period, and counts the number of serial numbers included in the ordered set every preset inspection period. If the number is less than a preset storage threshold, a backup serial number sequence is generated and added to the ordered set. This avoids the time consumption caused by real-time querying of the maximum serial number in the database, reduces the pressure on the database under high concurrency, ensures the uniqueness of the generated serial numbers, and improves the business performance of the project.
[0054] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description
[0055] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:
[0056] Figure 1 This illustration shows a flowchart of a method for generating serial numbers according to an embodiment of this application;
[0057] Figure 2A This illustration shows a flowchart of a method for generating serial numbers according to an embodiment of this application;
[0058] Figure 2B This paper illustrates a schematic diagram of a system architecture for generating serial numbers according to an embodiment of this application.
[0059] Figure 2C This paper illustrates a flowchart of a serial number generation process provided in an embodiment of this application.
[0060] Figure 3A This illustration shows a schematic diagram of a serial number generation structure provided in an embodiment of this application;
[0061] Figure 3B This illustration shows a schematic diagram of a serial number generation structure provided in an embodiment of this application;
[0062] Figure 4 A schematic diagram of the device structure of a computer device provided in an embodiment of this application is shown. Detailed Implementation
[0063] Exemplary embodiments of the present application will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this application will be thorough and complete, and will fully convey the scope of the present application to those skilled in the art.
[0064] This application provides a method for generating serial numbers, such as... Figure 1 As shown, the method includes:
[0065] 101. In response to a project initiation request, determine the target project indicated by the project initiation request, and generate an ordered set for the target project.
[0066] Serial numbering is crucial for a project system because it serves not only as a unique identifier for business transactions within the system but also for interactions with other systems. Furthermore, serial numbers need to remain sequential after a system restart to ensure continued system operation and normal business processes. Currently, there are two methods for generating serial numbers: one involves querying the database for the maximum existing serial number and generating a new one incrementally based on that maximum; the other uses a third-party storage component to store the current maximum serial number and generate a new one in real-time when needed. However, in high-concurrency scenarios, querying the database for the maximum serial number and generating a new one in real-time cannot guarantee uniqueness. Ensuring uniqueness necessitates the use of database locks or distributed locks, significantly impacting project performance. Similarly, using third-party storage components can lead to discontinuous serial numbers under high concurrency, also negatively affecting business performance.
[0067] To address this issue, this application proposes a serial number generation method. This method creates an ordered set for each project, stores pre-generated serial numbers within this set, and periodically checks the quantity of serial numbers in the ordered set. This avoids the time overhead of constantly querying the database for the maximum serial number and ensures the uniqueness of the generated serial numbers. The serial number generation method proposed in this application can be applied to servers. These servers can be standalone servers or servers providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. This reduces database pressure under high concurrency and guarantees the uniqueness of serial numbers.
[0068] In this embodiment, the server responds to the project initiation request and determines the target project indicated by the request. For example, the target project could be a logistics system, an order system, a banking system, a registration system, etc. Next, the server generates an ordered set for the target project, where the ordered set stores the unused transaction numbers for the target project. This ordered set stores a certain number of unused transaction numbers for the target project, avoiding problems such as excessive time and discontinuous transaction numbers caused by real-time generation.
[0069] 102. Query the target serial number corresponding to the target project in the database, and add the serial number sequence generated by using preset business rules and target serial number to an ordered set.
[0070] Since the serial number is unique throughout the entire project system, it can directly locate specific data within the system. Furthermore, the serial number increments based on business logic or time, allowing for the pre-generation of a certain number of serial numbers and their storage in an ordered set, thus avoiding hindering the system's processing speed. In this embodiment, the server queries the database for the target serial number corresponding to the target project. The target serial number is the maximum serial number corresponding to the target project in the database. Next, the server adds the serial number sequence generated using preset business rules and the target serial number to the ordered set. The preset business rules are user-defined in the business code and can be adjusted according to actual business scenarios. This avoids the time-consuming process of the server constantly querying the database for the corresponding maximum serial number, while also reducing database pressure under high concurrency.
[0071] 103. Determine the preset inspection cycle, and count the number of serial numbers included in the ordered set every preset inspection cycle.
[0072] If serial number generation is not timely, it will affect the normal operation of the corresponding system. Therefore, in order to ensure the stable generation of serial numbers and the business performance of the project system, the ordered set is managed and controlled according to a preset inspection cycle to achieve automatic generation and unified allocation of serial numbers. In this embodiment, the server determines a preset inspection cycle and counts the number of serial numbers included in the ordered set every preset inspection cycle. This allows for timely generation of additional serial numbers when the number of serial numbers in the ordered set is insufficient, avoiding errors that can easily occur when generating serial numbers in real time under high concurrency and ensuring high availability of serial numbers.
[0073] 104. If the quantity is less than the preset storage threshold, a backup serial number sequence is generated and added to the ordered set.
[0074] By periodically counting the number of sequential numbers in the ordered set and replenishing them in a timely manner, the server can ensure efficient generation of sequential numbers. This also prevents time-consuming and concurrency issues associated with retrieving the maximum number from the database or third-party storage components and then generating sequential numbers in real-time under high concurrency scenarios. Therefore, in this embodiment, if the server counts that the number of sequential numbers in the ordered set is less than a preset storage threshold, a backup sequential number sequence is generated and added to the ordered set. This avoids the memory consumption and time overhead associated with real-time sequential number generation under high concurrency conditions.
[0075] The method provided in this application embodiment, in response to a project start request, determines the target project indicated by the project start request, and generates an ordered set for the target project. The ordered set is used to store the serial numbers to be used by the target project. The method queries the database for the target serial number corresponding to the target project, and adds the serial number sequence generated using preset business rules and the target serial number to the ordered set. The method determines a preset inspection period, and counts the number of serial numbers included in the ordered set every preset inspection period. If the number is less than a preset storage threshold, a spare serial number sequence is generated and added to the ordered set. This avoids the time loss caused by querying the maximum serial number in the database in real time, reduces the pressure on the database under high concurrency, ensures the uniqueness of the generated serial numbers, and improves the business performance of the project.
[0076] Furthermore, as a refinement and extension of the specific implementation methods of the above embodiments, and in order to fully illustrate the specific implementation process of this embodiment, this application provides another method for generating serial numbers, such as... Figure 2A As shown, the method includes:
[0077] 201. In response to a project initiation request, determine the target project indicated by the project initiation request, and generate an ordered set for the target project.
[0078] With the rapid development of computer technology, the amount of data and business processes involved is also increasing. Therefore, developing serial numbering systems suitable for actual business processes is a crucial requirement for project development and management. This application recognizes that existing serial numbering methods involve obtaining the maximum serial number from a database or third-party storage component and then generating serial numbers in real time. However, in high-concurrency scenarios, real-time generation of serial numbers not only increases database pressure but also degrades project performance. Therefore, this application proposes a serial numbering method that creates an ordered set for each project, stores pre-generated serial numbers in the ordered set, and periodically checks the quantity of serial numbers in the ordered set. In this embodiment, the server responds to a project startup request, determines the target project indicated by the request, and generates an ordered set for the target project. The ordered set acts as a container to store the serial numbers to be used by the target project. The server pre-generates a certain number of serial numbers and places them in the container when the target project starts. This way, when the server receives a business request, it does not need to spend time regenerating serial numbers but can directly retrieve serial numbers from the container and allocate them to the target project, ensuring high performance of the serial numbering.
[0079] It's important to note that after creating an ordered set for the target project, you can check if the set is empty. Since a check task is created for the ordered set when the project starts, the server may execute the check task and generate a serial number for the ordered set when the target project starts. The target project can then retrieve the serial number as needed through business requests. If the server has not yet executed the check task, it needs to query the database for the maximum serial number of the target project and start a thread in real time to generate a serial number, then add the generated serial number to the ordered set.
[0080] Therefore, the schematic diagram of a serial number generation system architecture proposed in this application is as follows:
[0081] like Figure 2B As shown, to be applicable to most business teams without requiring additional external middleware systems, allowing developers to focus more on code development, developers create ordered sets for each service project within the business system. For example, if the project system has three service projects: Service A, Service B, and Service C, ordered sets are created for each of these services. These ordered sets can be TreeSets (empty tree sets). Then, at project startup, a request is sent to query the database for the maximum serial number corresponding to Service A, Service B, and Service C, and the corresponding serial numbers are pre-generated according to the rules customized by each business system. Finally, the generated serial numbers are stored in the ordered sets corresponding to Service A, Service B, and Service C, respectively.
[0082] 202. Query the target serial number corresponding to the target project in the database.
[0083] Introducing a separate third-party storage component for generating serial numbers is not only unfriendly to high-concurrency scenarios, but also reduces system availability and increases system complexity. Therefore, by querying the corresponding maximum number in the database and pre-generating a certain number of serial numbers, the system can provide convenient and efficient services while reducing database pressure. In this embodiment, the server obtains the server access address corresponding to the target item, such as the MAC (Media Access Control) address, and queries the database for the target serial number sequence corresponding to the server access address. Then, the server obtains the last target serial number in the target serial number sequence. It should be noted that the server access address is a unique variable of the server, so the maximum number corresponding to the server can be found in the database through the server access address, so that a certain number of serial numbers can be generated using the maximum number, ensuring the uniqueness of the serial numbers.
[0084] 203. Add the sequence of serial numbers generated using preset business rules and target serial numbers to an ordered set.
[0085] In this embodiment, the server obtains the current date information, the preset business rules corresponding to the target project, and the preset generation quantity. For example, the current date information could be 20230105, the preset business rules could be the current date information + MAC address + maximum serial number, and the preset generation quantity could be 1000. It should be noted that since the usage of serial numbers differs in different business processes, the generation rules for serial numbers can be adjusted according to the business scenario in actual application scenarios. Next, the server combines the current date information, server access address, and target serial number sequentially according to the preset business rules to obtain the first serial number. For example, if the last six digits of the server MAC address are 26878C, and the maximum serial number value in the database is 88, then the first serial number generated according to the preset business rules is 2023010526878C000089. Subsequently, the server increments the first serial number according to the preset generation quantity to generate the preset generation quantity. Finally, the server organizes the values of the first serial number and the preset number of generated numbers according to an increasing relationship, and uses the resulting sequence as the serial number sequence, such as 2023010526878C000089-2023010526878C001089, and adds the serial number sequence to an ordered set. This ensures the continuity and uniqueness of the serial numbers, while avoiding the time-consuming process of querying the maximum number in the database in real time.
[0086] In an optional implementation, if the server finds no corresponding target sequence number for the server access address in the database, it means the server has not generated a sequence number, and the initial sequence number is set to 0. Next, the server combines the current date information, server access address, and initial sequence number sequentially according to preset business rules to obtain a second sequence number. For example, if the current date information is 20230105 and the last six digits of the server MAC address are 26878C, then according to the preset business rules, the second sequence number is 2023010526878C000001. Subsequently, the server increments the second sequence number according to a preset generation quantity, generating the preset generation quantity. Finally, the server organizes the second sequence number and the preset generation quantity according to the incrementing relationship, uses the resulting sequence as the sequence number sequence, and adds the sequence number sequence to an ordered set. For example, if the preset generation quantity is 1000, the serial number sequence obtained by incrementing is 2023010526878C000001-2023010526878C001001.
[0087] 204. Determine the preset inspection cycle, and count the number of serial numbers included in the ordered set every preset inspection cycle.
[0088] In high-concurrency scenarios, the business demands of the target project are excessive, resulting in a large number of requesting serial numbers to the server. In such cases, the server's method of generating serial numbers in real-time cannot provide timely serial numbers to the target project. Therefore, in this embodiment, the server obtains a preset check period, such as 60 minutes or 180 minutes, and creates a scheduled check task for the target project according to the preset check period. It should be noted that the preset check period can be set according to the concurrency of the business system in the actual application scenario. Then, the server executes the scheduled check task every preset check period, so that the server can count the number of serial numbers included in the ordered set every preset check period. For example, a timer can be created for the target project when it starts. The timer will generate a check task and periodically check whether the ordered set is empty, so that if the number of serial numbers in the ordered set is insufficient, it can be replenished in time, avoiding the time-consuming real-time generation of serial numbers in high-concurrency scenarios, improving the work efficiency of the system business, and enhancing the business performance of the project.
[0089] 205. If the quantity is less than the preset storage threshold, generate a backup serial number sequence and add the backup serial number sequence to the ordered set.
[0090] Because the sequence numbers in an ordered set may be exhausted within a short period of time under high concurrency, in this embodiment, if the server detects that the number of sequence numbers in the ordered set is less than a preset storage threshold, it retrieves the last specified sequence number from the sequence number sequence included in the ordered set. Next, the server obtains the current date information, the preset generation quantity, the preset business rules, and the server access address corresponding to the target project. Subsequently, the server combines the current date information, the server access address, and the specified sequence number sequentially according to the preset business rules to obtain a third sequence number. For example, if the current date information is 20230116, the last six digits of the server MAC address are 26878C, and the specified sequence number is 6523, then according to the preset business rules, the third sequence number is 2023011626878C006524. Then, the server increments the third sequence number according to the preset generation quantity to generate the preset generation quantity. It should be noted that the preset generation value can be set according to the needs of the business system in the actual application scenario. Next, the server organizes the values of the third serial number and the preset generation quantity in an ascending order, and uses the resulting sequence as a backup serial number sequence. For example, if the preset generation quantity is 1000, the backup serial number sequence obtained by ascending and organizing according to the preset generation quantity is 2023011626878C006524-2023011626878C007524. Finally, the server adds the backup serial number sequence to an ordered set, replenishing the serial numbers in the ordered set in a timely manner to ensure high availability of serial numbers and avoid the memory consumption and time loss of real-time generation of serial numbers under high concurrency.
[0091] In an optional implementation, when the server receives a serial number retrieval request, it checks whether a serial number exists in the ordered set. If the server detects a serial number in the ordered set, it indicates that there are unused serial numbers. The target project can retrieve serial numbers according to its business needs using the serial number retrieval request. Therefore, the server retrieves the first number of serial numbers indicated in the serial number retrieval request. Next, the server retrieves the first number of serial numbers from the ordered set. Subsequently, the server sends the first number of serial numbers to the target project so that the target project can use the first number of serial numbers, avoiding the impact of real-time serial number generation on project business performance under high concurrency and ensuring system availability.
[0092] When the server detects that a serial number is missing from the ordered set, the business request cannot obtain a serial number from the ordered set. The server continues to query the database for the target serial number corresponding to the target project, and adds the serial number sequence generated using preset business rules and the target serial number to the ordered set. In practical applications, there are two situations where a serial number is missing from the ordered set. One is when the project just starts, before the timer has had time to check and replenish the ordered set, and the server receives a business request; in this case, the ordered set does not contain a serial number. The other situation is when the request concurrency is high, and the number of business requests is also high, so under high concurrency, the serial numbers in the ordered set will be exhausted in a short time. Next, after generating a certain number of serial numbers and storing them in the ordered set, the server obtains the second number of serial numbers indicated by the serial number retrieval request, and obtains the second number of serial numbers from the ordered set. Subsequently, the server sends the second number of serial numbers to the target project so that the target project can use the second number of serial numbers, solving the problem of the server querying the database for the corresponding maximum number in real time, and reducing the pressure on the database under high concurrency.
[0093] In summary, the serial number generation process proposed in this application is as follows:
[0094] like Figure 2C As shown, after the service starts, each server creates an ordered set for its corresponding service item. Next, each server sends a request to the database to query its maximum ID. Subsequently, each server pre-generates a certain number of sequential IDs based on the maximum ID according to certain business rules, and stores the generated sequential IDs in the ordered set. Simultaneously with service startup, the server creates a timer for the corresponding service item and uses a pre-set check period to check whether the timer has started its check task. If the interval has not reached the check period, the timer does not start its check task. If the interval has reached the check period, the timer starts its check task to check whether the number of sequential IDs in the ordered set is less than a threshold. If the number of sequential IDs in the ordered set is less than the threshold, the maximum ID in the ordered set is retrieved, and a certain number of sequential IDs are pre-generated based on this maximum ID according to certain business rules for use by the service item.
[0095] The method provided in this application embodiment, in response to a project start request, determines the target project indicated by the project start request, and generates an ordered set for the target project. The ordered set is used to store the serial numbers to be used by the target project. The method queries the database for the target serial number corresponding to the target project, and adds the serial number sequence generated using preset business rules and the target serial number to the ordered set. The method determines a preset inspection period, and counts the number of serial numbers included in the ordered set every preset inspection period. If the number is less than a preset storage threshold, a spare serial number sequence is generated and added to the ordered set. This avoids the time loss caused by querying the maximum serial number in the database in real time, reduces the pressure on the database under high concurrency, ensures the uniqueness of the generated serial numbers, and improves the business performance of the project.
[0096] Furthermore, as Figure 1 To specifically implement the method, this application provides a serial number generation device, such as... Figure 3A As shown, the device includes: a response module 301, a generation module 302, a checking module 303, and a supplement module 304.
[0097] The response module 301 is used to respond to the project start request, determine the target project indicated by the project start request, and generate an ordered set for the target project, wherein the ordered set is used to store the serial number to be used by the target project;
[0098] The generation module 302 is used to query the target serial number corresponding to the target project in the database, and to add the serial number sequence generated by using preset business rules and the target serial number to the ordered set;
[0099] The inspection module 303 is used to determine a preset inspection cycle and to count the number of serial numbers included in the ordered set every preset inspection cycle.
[0100] The supplementary module 304 is used to generate a backup serial number sequence if the quantity is less than a preset storage threshold, and to add the backup serial number sequence to the ordered set.
[0101] In a specific application scenario, the generation module 302 is used to obtain the server access address corresponding to the target project, and query the database for the target serial number sequence corresponding to the server access address; obtain the last target serial number in the target serial number sequence; obtain the current date information, the preset business rules corresponding to the target project, and the preset generation quantity; combine the current date information, the server access address, and the target serial number in sequence according to the preset business rules to obtain a first serial number; perform an increment operation on the first serial number according to the preset generation quantity to generate the value of the preset generation quantity; organize the value of the first serial number and the preset generation quantity according to the increment relationship, use the organized sequence as the serial number sequence, and add the serial number sequence to the ordered set.
[0102] In a specific application scenario, the generation module 302 is further configured to: if the database query finds that the server access address does not have a corresponding target serial number sequence, set the initial serial number to 0; combine the current date information, the server access address, and the initial serial number sequentially according to the preset business rules to obtain a second serial number; perform an increment operation on the second serial number according to the preset generation quantity to generate the value of the preset generation quantity; organize the value of the second serial number and the preset generation quantity according to the increment relationship, use the organized sequence as the serial number sequence, and add the serial number sequence to the ordered set.
[0103] In a specific application scenario, the inspection module 303 is used to obtain the preset inspection cycle, create a timed inspection task for the target project according to the preset inspection cycle, and execute the timed inspection task every preset inspection cycle so as to count the number of serial numbers included in the ordered set every preset inspection cycle.
[0104] In a specific application scenario, the supplementary module 304 is used to: if the quantity is less than the preset storage threshold, obtain the last specified serial number in the serial number sequence included in the ordered set; obtain the current date information, the preset generation quantity, the preset business rule, and the server access address corresponding to the target project; combine the current date information, the server access address, and the specified serial number in sequence according to the preset business rule to obtain a third serial number; perform an increment operation on the third serial number according to the preset generation quantity to generate the value of the preset generation quantity; organize the value of the third serial number and the preset generation quantity according to the increment relationship, use the organized sequence as the backup serial number sequence, and add the backup serial number sequence to the ordered set.
[0105] In specific application scenarios, such as Figure 3B As shown, the device also includes a transmitting module 305.
[0106] The sending module 305 is configured to, when receiving a serial number retrieval request, detect whether a serial number exists in the ordered set; when a serial number is detected in the ordered set, obtain the first number quantity indicated by the serial number retrieval request; obtain the first number quantity of serial numbers in the ordered set; and send the first number quantity of serial numbers to the target project so that the target project uses the first number quantity of serial numbers.
[0107] In a specific application scenario, the sending module 305 is further configured to, when it is detected that no serial number exists in the ordered set, continue to perform the operations of querying the target serial number corresponding to the target project in the database, and adding the serial number sequence generated by using preset business rules and the target serial number to the ordered set; obtain the second number quantity indicated by the serial number acquisition request, obtain the second number quantity of serial numbers in the ordered set; and send the second number quantity of serial numbers to the target project so that the target project uses the second number quantity of serial numbers.
[0108] The apparatus provided in this application embodiment, in response to a project start request, determines the target project indicated by the project start request, and generates an ordered set for the target project. The ordered set is used to store the serial numbers to be used by the target project. The apparatus queries the database for the target serial number corresponding to the target project, and adds the serial number sequence generated using preset business rules and the target serial number to the ordered set. The apparatus determines a preset inspection period, and counts the number of serial numbers included in the ordered set every preset inspection period. If the number is less than a preset storage threshold, a spare serial number sequence is generated and added to the ordered set. This avoids the time loss caused by querying the maximum serial number in the database in real time, reduces the pressure on the database under high concurrency, ensures the uniqueness of the generated serial numbers, and improves the business performance of the project.
[0109] It should be noted that other corresponding descriptions of the functional units involved in the serial number generation device provided in this application embodiment can be found by referring to... Figure 1 and Figures 2A to 2C The corresponding descriptions in [the document] will not be repeated here.
[0110] In an exemplary embodiment, see Figure 4 The invention also provides a computer device including a bus, a processor, a memory, and a communication interface. It may also include an input / output interface and a display device, wherein the various functional units can communicate with each other via the bus. The memory stores a computer program, and the processor executes the program stored in the memory, performing the serial number generation method described in the above embodiments.
[0111] A readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the serial number generation method described above.
[0112] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented in hardware or by using software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) and includes several instructions to cause a computer device (such as a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0113] Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of a preferred embodiment, and the modules or processes shown in the drawings are not necessarily essential for implementing this application.
[0114] Those skilled in the art will understand that the modules in the apparatus of the implementation scenario can be distributed within the apparatus of the implementation scenario as described, or they can be located in one or more apparatuses different from this implementation scenario, with corresponding changes. The modules of the above-described implementation scenario can be combined into one module, or they can be further divided into multiple sub-modules.
[0115] The serial numbers in this application are for descriptive purposes only and do not represent the superiority or inferiority of the implementation scenario.
[0116] The above disclosures are only a few specific implementation scenarios of this application. However, this application is not limited to these. Any variations that can be conceived by those skilled in the art should fall within the protection scope of this application.
Claims
1. A method for generating serial numbers, characterized in that, include: In response to a project initiation request, the target project indicated by the project initiation request is determined, and an ordered set is generated for the target project, the ordered set being used to store the serial numbers to be used by the target project; The process of querying the target serial number corresponding to the target project in the database and adding the serial number sequence generated using preset business rules and the target serial number to the ordered set includes: obtaining the server access address corresponding to the target project, querying the target serial number sequence corresponding to the server access address in the database, obtaining the last target serial number in the target serial number sequence, obtaining the current date information, the preset business rules corresponding to the target project, and obtaining the preset generation quantity, combining the current date information, the server access address, and the target serial number in sequence according to the preset business rules to obtain a first serial number, performing an increment operation on the first serial number according to the preset generation quantity to generate the value of the preset generation quantity, organizing the value of the first serial number and the preset generation quantity according to the increment relationship, using the organized sequence as the serial number sequence, and adding the serial number sequence to the ordered set. A preset inspection cycle is determined, and the number of serial numbers included in the ordered set is counted every preset inspection cycle; If the quantity is less than a preset storage threshold, a backup serial number sequence is generated, and the backup serial number sequence is added to the ordered set.
2. The method according to claim 1, characterized in that, The method further includes: If the database query finds that the server access address does not have a corresponding target serial number sequence, then the initial serial number is set to 0; According to the preset business rules, the current date information, the server access address, and the initial serial number are combined sequentially to obtain the second serial number; The second serial number is incremented according to the preset generation quantity to generate the value of the preset generation quantity; The values of the second serial number and the preset generation quantity are sorted according to the increasing relationship, and the sorted sequence is used as the serial number sequence, and the serial number sequence is added to the ordered set.
3. The method according to claim 1, characterized in that, The determination of the preset inspection cycle, and the counting of the number of serial numbers included in the ordered set every preset inspection cycle, include: Obtain the preset inspection cycle, and create a scheduled inspection task for the target project according to the preset inspection cycle; The timed check task is executed every preset check cycle so that the number of serial numbers included in the ordered set is counted every preset check cycle.
4. The method according to claim 1, characterized in that, If the quantity is less than a preset storage threshold, then generating a backup serial number sequence and adding the backup serial number sequence to the ordered set includes: If the quantity is less than the preset storage threshold, then the last specified serial number is obtained from the serial number sequence included in the ordered set. Obtain the current date information, the preset generation quantity, the preset business rules, and the server access address corresponding to the target project; According to the preset business rules, the current date information, the server access address, and the specified serial number are combined sequentially to obtain the third serial number; The third serial number is incremented according to the preset generation quantity to generate the value of the preset generation quantity; The values of the third serial number and the preset generation quantity are sorted according to the increasing relationship, and the sorted sequence is used as the backup serial number sequence, and the backup serial number sequence is added to the ordered set.
5. The method according to claim 1, characterized in that, The method further includes: When a serial number retrieval request is received, it is checked whether a serial number exists in the ordered set; When a serial number is detected in the ordered set, the first number of serial numbers indicated by the serial number acquisition request is obtained; Obtain the first number of serial numbers from the ordered set, and send the first number of serial numbers to the target project so that the target project uses the first number of serial numbers.
6. The method according to claim 5, characterized in that, After detecting whether a sequential number exists in the ordered set, the method further includes: When it is detected that there is no serial number in the ordered set, the operation of querying the target serial number corresponding to the target project in the database and adding the serial number sequence generated by the preset business rules and the target serial number to the ordered set continues. Obtain the second number of serial numbers indicated by the serial number acquisition request, and obtain the second number of serial numbers in the ordered set; Send the second number of serial numbers to the target project so that the target project uses the second number of serial numbers.
7. A serial number generation device, characterized in that, include: A response module is used to respond to a project launch request, determine the target project indicated by the project launch request, and generate an ordered set for the target project, wherein the ordered set is used to store the serial numbers to be used by the target project; The generation module is used to query the target serial number corresponding to the target project in the database, and to add the serial number sequence generated by using preset business rules and the target serial number to the ordered set. This includes: obtaining the server access address corresponding to the target project; querying the target serial number sequence corresponding to the server access address in the database; obtaining the last target serial number in the target serial number sequence; obtaining current date information, the preset business rules corresponding to the target project, and a preset generation quantity; combining the current date information, the server access address, and the target serial number sequentially according to the preset business rules to obtain a first serial number; performing an increment operation on the first serial number according to the preset generation quantity to generate the value of the preset generation quantity; organizing the first serial number and the value of the preset generation quantity according to the increment relationship; using the organized sequence as the serial number sequence; and adding the serial number sequence to the ordered set. The inspection module is used to determine a preset inspection cycle and to count the number of serial numbers included in the ordered set every preset inspection cycle. The supplementary module is used to generate a backup serial number sequence if the quantity is less than a preset storage threshold, and to add the backup serial number sequence to the ordered set.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Serial number generation method, device and equipment and storage medium
CN110807035A
Serial number generation method and device, electronic equipment and computer readable medium
CN113822015A