Serial number generation method and device, computer equipment and readable storage medium
By receiving and processing the service terminal's serial number acquisition request, querying and generating serial number sets in a distributed system, the problem of high database load on multiple servers is solved, and the serial number generation efficiency and system scalability are improved.
Patent Information
- Application Number
- CN202411178307.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2044-08-26
AI Technical Summary
In distributed systems, multiple servers need to generate a large number of service serial numbers, resulting in high performance requirements for the database, excessive load, and slow serial number generation efficiency.
By receiving the target service number acquisition request from the service side, querying the target service number rules and maximum value of the number segment, generating the serial number set based on the acquisition number and rules, reducing the number number number number number number number numbering is requested to the database, and using queue and process lock mechanisms to ensure the uniqueness and efficiency of serial number.
It reduces the performance requirements and load on the database, improves the efficiency of serial number generation, reduces the number of database accesses, and improves the scalability of the system.
Smart Images

Figure CN119066069A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and apparatus for generating a serial number, a computer device, a computer-readable storage medium, and a computer program product. Background Art
[0002] When running applications in a distributed system, various businesses will be executed, and the execution of various businesses requires business serial numbers as data support. Therefore, during the execution of the business, the business serial number will be generated through the serial number generation method.
[0003] In the current method for generating a sequence number, the server sends a request for generating a target service sequence number to the database. In response to the request, the database generates a target service sequence number and returns the target service sequence number to the server.
[0004] However, in the current method of generating serial numbers, there are multiple servers in the distributed system, and each server needs to generate multiple service serial numbers. Therefore, each server will send a large number of generation requests to the database, resulting in the serial number generation method having high performance requirements on the database and excessive database load. At the same time, the efficiency of serial number generation is slow. Summary of the invention
[0005] Based on this, it is necessary to provide a serial number generation method, device, computer equipment, computer readable storage medium and computer program product to address the above technical problems.
[0006] In a first aspect, the present application provides a method for generating a sequence number, the method comprising:
[0007] Receive a target service serial number acquisition request sent by a service end; the target service serial number acquisition request includes a target service number and an acquisition quantity;
[0008] Query the target service sequence number rule according to the target service number, and obtain the maximum value of the number segment;
[0009] The number of service sequence numbers to be generated is determined based on the acquired quantity, and a first service sequence number set of the number of sequence numbers is generated based on the maximum value of the number segment and the target service sequence number rule.
[0010] In one embodiment, before receiving the target service sequence number acquisition request sent by the service end, the method further includes:
[0011] Receive the target business sequence number rule of the target business sequence number sent by the management end;
[0012] A target service sequence number queue corresponding to the target service sequence number is established based on the target service sequence number rule; the target service sequence number queue is used to store the target service sequence number.
[0013] In one embodiment, after receiving the target service sequence number acquisition request sent by the service end, the method further includes:
[0014] Querying a target service sequence number queue according to the target service number, and determining the number of target service sequence numbers in the target service sequence number queue as the number of queue sequence numbers;
[0015] Determine whether the number of queue sequence numbers is less than the acquired number;
[0016] If the number of queue sequence numbers is less than the acquisition number, it is determined that the target service sequence number acquisition request meets a preset sequence number generation condition.
[0017] In one embodiment, querying the target service sequence number rule according to the target service number and obtaining the maximum value of the number segment includes:
[0018] In the case where the target service sequence number acquisition request meets the sequence number generation condition, querying the target service sequence number rule according to the target service number;
[0019] Sending a status acquisition request to the database; the status acquisition request is used to query the process lock status of the maximum value of the segment;
[0020] The process lock state of the maximum value of the number segment returned by the database is received, and the maximum value of the number segment is obtained based on the process lock state.
[0021] In one embodiment, obtaining the maximum value of the number segment based on the process lock state includes:
[0022] If the process lock state is a locked state, executing the step of sending a state acquisition request to a database according to a preset time period until the process lock state is an unlocked state;
[0023] If the process lock state is unlocked, the maximum value of the number segment is obtained, and the maximum value of the number segment is locked.
[0024] In one of the embodiments, generating the first service sequence number set of the number of sequence numbers based on the maximum value of the number segment and the target service sequence number rule includes:
[0025] Determine the starting target service sequence number based on the maximum value of the number segment and the step length in the target service sequence number rule;
[0026] Starting from the starting target service sequence number, generating the target service sequence number of the sequence number based on the target service sequence number rule;
[0027] A first service sequence number set is constructed according to each of the target service sequence numbers.
[0028] In one of the embodiments, after generating the first service sequence number set of the number of sequence numbers based on the maximum value of the number segment and the target service sequence number rule, the method further includes:
[0029] Determine the largest target service sequence number in the first service sequence number set as the maximum value of the target number segment, and unlock the maximum value of the number segment;
[0030] The maximum value of the unlocked number segment is updated according to the maximum value of the target number segment.
[0031] In a second aspect, the present application also provides a sequence number generating device, comprising:
[0032] A receiving module, used for receiving a target service serial number acquisition request sent by a service end; the target service serial number acquisition request includes a target service number and an acquisition quantity;
[0033] An acquisition module, used to query the target service sequence number rule according to the target service number, and obtain the maximum value of the number segment;
[0034] A generation module is used to determine the number of service serial numbers to be generated based on the acquired quantity, and to generate a first service serial number set of the number of serial numbers based on the maximum value of the number segment and the target service serial number rule.
[0035] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0036] Receive a target service serial number acquisition request sent by a service end; the target service serial number acquisition request includes a target service number and an acquisition quantity;
[0037] Query the target service sequence number rule according to the target service number, and obtain the maximum value of the number segment;
[0038] The number of service sequence numbers to be generated is determined based on the acquired quantity, and a first service sequence number set of the number of sequence numbers is generated based on the maximum value of the number segment and the target service sequence number rule.
[0039] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0040] Receive a target service serial number acquisition request sent by a service end; the target service serial number acquisition request includes a target service number and an acquisition quantity;
[0041] Query the target service sequence number rule according to the target service number, and obtain the maximum value of the number segment;
[0042] The number of service sequence numbers to be generated is determined based on the acquired quantity, and a first service sequence number set of the number of sequence numbers is generated based on the maximum value of the number segment and the target service sequence number rule.
[0043] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0044] Receive a target service serial number acquisition request sent by a service end; the target service serial number acquisition request includes a target service number and an acquisition quantity;
[0045] Query the target service sequence number rule according to the target service number, and obtain the maximum value of the number segment;
[0046] The number of service sequence numbers to be generated is determined based on the acquired quantity, and a first service sequence number set of the number of sequence numbers is generated based on the maximum value of the number segment and the target service sequence number rule.
[0047] The above-mentioned sequence number generation method, device, computer equipment, computer-readable storage medium and computer program product receive a target service sequence number acquisition request sent by a service end; the target service sequence number acquisition request includes a target service number and an acquisition quantity; the target service sequence number rule is queried according to the target service number, and the maximum value of the number segment is acquired; the sequence number of the service sequence number to be generated is determined based on the acquisition quantity, and the first service sequence number set of the sequence number is generated based on the maximum value of the number segment and the target service sequence number rule. By adopting this method, the sequence number of the service sequence number to be generated is determined based on the acquisition quantity in the target service sequence number acquisition request, and the first service sequence number set of the sequence number is generated based on the maximum value of the number segment and the target service sequence number rule, so that multiple target service sequence numbers can be generated in batches, which reduces the number of requests sent to the database, thereby reducing the performance requirements and database load on the database. At the same time, the sequence number generation efficiency is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0049] Figure 1 An application environment diagram of a sequence number generation method in an embodiment;
[0050] Figure 2 A schematic diagram of a flow chart of a method for generating a sequence number in an embodiment;
[0051] Figure 3 A schematic diagram of a process for receiving a target service sequence number rule in one embodiment;
[0052] Figure 4 A schematic diagram of a process for determining whether a target service sequence number acquisition request satisfies sequence number generation conditions in an embodiment;
[0053] Figure 5 A schematic diagram of a process of querying a target service sequence number rule and obtaining a maximum value of a number segment in one embodiment;
[0054] Figure 6 A schematic diagram of a process for obtaining the maximum value of a number segment in one embodiment;
[0055] Figure 7 A schematic diagram of a process for generating a first service sequence number set in an embodiment;
[0056] Figure 8 A schematic diagram of a process for updating the maximum value of a number segment in one embodiment;
[0057] Fig. 9 A schematic diagram of the architecture of a method for generating a sequence number in an embodiment;
[0058] Fig.10 is a structural block diagram of a sequence number generating device in an embodiment;
[0059] Fig.11 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0060] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0061] The serial number generation method provided in the embodiment of the present application can be applied to Figure 1In the distributed system 100 shown. Among them, the distributed system 100 includes a management terminal 110, multiple service terminals 120, a business terminal 130 and a database 140. The management terminal 110 is used to generate a target sequence number rule configuration module. The server terminal 120 batch generates business sequence numbers of target businesses according to the target business sequence number rules. The business terminal 130 is used to execute the target business according to the business sequence number. Among them, the management terminal 110 can be but is not limited to various personal computers, laptops, smart phones and tablets. The server terminal 120 or the business terminal 130 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.
[0062] In an exemplary embodiment, Figure 2 As shown, a method for generating a sequence number is provided, and the method is applied to Figure 1 The server 120 (hereinafter, the reference numeral is omitted, referred to as the server) in the embodiment is used as an example to illustrate the method, which includes the following steps 202 to 206. Among them:
[0063] Step 202: Receive a target service sequence number acquisition request sent by the service end.
[0064] The target service serial number acquisition request includes the target service serial number and the acquisition quantity. The target service serial number is an identifier of the target service serial number rule, which is used to identify the target service serial number rule and the target service serial number to be generated.
[0065] In implementation, when the target business serial number in the business end is short of, the business end will construct a target business serial number acquisition request based on the target business number and the acquisition quantity, and send the target business serial number acquisition request to the server. The server receives the target business serial number acquisition request, parses the target business serial number acquisition request, and obtains the target business number and the acquisition quantity.
[0066] Specifically, the business end is pre-set with an acquisition quantity. While the business end executes the target business based on the target business sequence number, the business end simultaneously monitors the sequence number quantity of the target business sequence number in the business end. When the sequence number quantity meets the acquisition condition, the business end constructs a target business sequence number acquisition request for the target business sequence number according to the target business number and the acquisition quantity. Then, the business end sends the target business sequence number acquisition request to the server. The server receives the target business sequence number acquisition request, and parses the target business sequence number acquisition request to obtain the target business number and the acquisition quantity.
[0067] In an exemplary embodiment, the acquisition quantity preset in the service end is 100, and the target service number is ORD0100. While the service end executes the target service based on the target service number, the service end simultaneously monitors the number of the target service number. When the number of numbers is less than the preset alarm number, the service end constructs a target service number acquisition request in the form of HTTP (Hypertext Transfer Protocol) according to the acquisition quantity 100 and the target service number ORD0100. The service end receives the target service number acquisition request based on the network, and parses the target service number acquisition request to obtain the acquisition quantity 100 and the target service number ORD0100.
[0068] Optionally, the acquisition quantity is determined according to the execution frequency of the target business, and the embodiment of the present application does not limit the acquisition quantity.
[0069] Step 204, query the target service sequence number rule according to the target service number, and obtain the maximum value of the number segment.
[0070] In implementation, the server queries the target service sequence number queue according to the target service number. Then, the server determines whether the target service sequence number request meets the preset sequence number generation conditions based on the target service sequence number queue and the acquisition quantity. If the target service sequence number request meets the sequence number generation conditions, the server queries the target service sequence number rule corresponding to the target service number in each service sequence number rule. Then, the server sends a status acquisition request to the database and obtains the maximum value of the number segment based on the status acquisition request.
[0071] Specifically, the server queries the target service sequence number queue according to the target service number. Then, the server determines the number of sequence numbers in the target service sequence number queue as the number of queue sequence numbers. Then, the server determines whether the target service sequence number request meets the preset sequence number generation condition based on the number of queue sequence numbers and the number of acquisitions. In the case where the target service sequence number request meets the sequence number generation condition, the server determines the target service sequence number rule in each service sequence number rule according to the target service number. Then, the server sends a status acquisition request to the database, obtains the process lock state, and obtains the maximum value of the number segment according to the process lock state.
[0072] Step 206, determining the number of service serial numbers to be generated based on the acquired quantity, and generating a first service serial number set of serial numbers based on the maximum value of the number segment and the target service serial number rule.
[0073] In implementation, the server determines the number of service numbers to be generated based on the acquired quantity. Then, the server determines the starting target service number based on the maximum value of the number segment, and generates target service numbers of the same number according to the target service number rule and the starting target service number. The server constructs a first service number set based on each target service number.
[0074] Specifically, the server determines the acquired quantity as the number of sequence numbers of the service sequence numbers to be generated. Then, the server determines the starting target service sequence number based on the maximum value of the number segment, and generates the target service sequence number of the sequence number according to the target service sequence number rule and the starting target service sequence number. The server constructs a first service sequence number set according to each target service sequence number. If the target service requires the target service sequence number to be continuous, the server updates the target service sequence number queue according to the first service sequence number set. Then, the server determines the acquired number of target service sequence numbers from the updated target service sequence number queue, and constructs a second service sequence number set according to the acquired number of target service sequence numbers. Then, the server sends the second service sequence number set to the service end through a network connection. If the target service requires the target service sequence number to be discontinuous, the server directly sends the first service sequence number set to the service end through a network connection. In the case where the target service sequence number is continuous, for example, only one service end can execute the target service. In the case where the target service sequence number may not be continuous, for example, only multiple service ends can execute the target service.
[0075] In an optional embodiment, the server performs a difference operation on the acquired quantity and the queue sequence number quantity to obtain the sequence number of the service sequence number to be generated. The server determines the starting target service sequence number based on the maximum value of the number segment, and generates the target service sequence number of the sequence number according to the target service sequence number rule and the starting target service sequence number. The server constructs a first service sequence number set according to each target service sequence number. Then, the server directly sends the first service sequence number set to the server through a network connection.
[0076] In the above sequence number generation method, the sequence number of the service sequence number to be generated is determined based on the acquisition number in the target service sequence number acquisition request, and the first service sequence number set of the sequence number is generated according to the maximum value of the number segment and the target service sequence number rule, which can batch generate multiple target service sequence numbers, reduce the number of requests sent to the database, and thus reduce the performance requirements and database load on the database. At the same time, the efficiency of sequence number generation is improved.
[0077] In an exemplary embodiment, before querying the target service sequence number rule, it is necessary to first obtain the target service sequence number rule from the management end. Figure 3 As shown, before step 202 is executed, the specific processing process of the serial number generation method also includes steps 302 to 304. Among them:
[0078] Step 302, receiving a target service sequence number rule of a target service sequence number sent by a management terminal.
[0079] In implementation, the management end sends the target service sequence number rule of the target service sequence number to the service end through a network connection. The service end receives the target service sequence number rule of the target service sequence number sent by the management end to generate the target service sequence number according to the target service sequence number rule.
[0080] Specifically, when the management end completes constructing the target service sequence number rule of the target service sequence number, the management end sends the target service sequence number rule to the service end through the network connection. The service end receives the target service sequence number rule and saves the target service sequence number rule.
[0081] In an exemplary embodiment, the target service sequence number is an order service sequence number. The target service sequence number rule is an order service sequence number rule. When the management end constructs the order service sequence number rule of the order service sequence number, the management end sends the order service sequence number rule to the service end through a network connection. The service end receives the order service sequence number rule and saves the order service sequence number rule.
[0082] Step 304: Establish a target service sequence number queue corresponding to the target service sequence number based on the target service sequence number rule.
[0083] The target service sequence number queue is used to store the target service sequence number. The target service sequence number rule includes the target service number and the pre-generated quantity.
[0084] In implementation, the server establishes a target business sequence number queue corresponding to the target business sequence number according to the target business number and the pre-generated quantity.
[0085] Specifically, the server uses the pre-generated quantity as a reference to establish a target service number queue that can store the pre-generated number of target service numbers. Then, the server establishes an association between the target service number and the target service queue, so as to facilitate subsequent query of the target service number queue according to the target service number.
[0086] In an exemplary embodiment, the target business number is ORD0100, the target business sequence number is the order business sequence number, and the pre-generated quantity is 100. The server uses the pre-generated quantity as a reference to establish an order business sequence number queue capable of storing 100 order business sequence numbers, and then the server establishes an association relationship between ORD0100 and the order business sequence number queue.
[0087] Optionally, the pre-generated quantity is generally the same as the acquired quantity at the business end, and is set according to the execution frequency of the target business. The embodiment of the present application does not limit the pre-generated quantity.
[0088] In this embodiment, by receiving the target service sequence number rule, it is convenient to generate the target service sequence number according to the target service sequence number rule. Then, by establishing a target service sequence number queue to store the target service sequence number, the target service sequence number can be sent to the service end immediately, thereby improving the efficiency of sequence number acquisition.
[0089] In an exemplary embodiment, after receiving the target service sequence number acquisition request, it is necessary to determine whether the target service sequence number acquisition request satisfies the sequence number generation condition. Figure 4 As shown, after step 202 is executed, the specific processing process of the sequence number generation method also includes steps 402 to 406. Among them:
[0090] Step 402: query the target service sequence number queue according to the target service number, and determine the number of target service sequence numbers in the target service sequence number queue as the queue sequence number number.
[0091] In implementation, the server queries the target service number corresponding to the target service number and then counts the target service numbers in the target service number queue to obtain the number of queue numbers.
[0092] Specifically, the server searches for a target service number queue associated with the target service number in each service number queue. Then, the server counts the target service numbers in the target service queue to obtain the total number of target service numbers in the target service number queue, and determines the number as the queue number.
[0093] In an exemplary embodiment, the target business number is ORD0100. The server searches for the order business number queue associated with ORD0100 in each business number queue. Then, the server counts the order business numbers in the order business queue, obtains the total number of order business numbers in the order business number queue, 50, and determines 50 as the queue number.
[0094] Step 404, determine whether the number of queue numbers is less than the acquisition number.
[0095] In implementation, the server determines whether the number of queue numbers is less than the number of acquisitions. If the number of queue numbers is less than the number of acquisitions, it indicates that there are not enough target business numbers in the target business number queue to send to the server, and it is necessary to generate target business numbers. If the number of queue numbers is greater than or equal to the number of acquisitions, it indicates that there are enough target business numbers in the target business number queue to send to the server.
[0096] In an optional embodiment, if the number of queue sequence numbers is greater than or equal to the number of acquisitions, the server determines the target service sequence numbers of the acquired number in the target service sequence number queue, and constructs a third service sequence number set based on the target service sequence numbers of the acquired number. Then, the server sends the third service sequence number set to the service end via a network connection.
[0097] Step 406: If the number of queue sequence numbers is less than the acquisition number, it is determined that the target service sequence number acquisition request meets the preset sequence number generation condition.
[0098] The sequence number generation condition is that the number of queue sequence numbers is less than the number of acquisitions.
[0099] In implementation, if the number of queue sequence numbers is less than the acquisition number, the server determines that the target service sequence number acquisition request meets the sequence number generation condition and executes the following step 502.
[0100] Specifically, the server pre-sets a sequence number generation condition. If the number of queue sequence numbers is less than the acquisition number, the server determines to trigger the sequence number generation process and determines that the target service sequence number acquisition request meets the preset sequence number generation condition.
[0101] In this embodiment, by judging whether the number of queue sequence numbers is less than the acquired number, it is determined whether the current service end has sufficient number of service sequence numbers to send to the service end, and when the number of queue sequence numbers is less than the acquired number, the sequence number generation process is triggered.
[0102] In an exemplary embodiment, Figure 5 As shown, the specific processing process of step 204 also includes steps 502 to 506. Among them:
[0103] Step 502: When the target service sequence number acquisition request satisfies the sequence number generation condition, the target service sequence number rule is searched according to the target service number.
[0104] In implementation, when the target service sequence number acquisition request meets the sequence number generation conditions, the server searches for the target service sequence number rule corresponding to the target service number in each service sequence number rule.
[0105] Specifically, when the target service sequence number acquisition request meets the sequence number generation condition, the server searches for the target service sequence number rule associated with the target service number in each service sequence number rule.
[0106] In an exemplary embodiment, the target business number is ORD0100. When the target business serial number acquisition request meets the serial number generation condition, the server triggers the serial number generation process. The server searches for the order business serial number rule associated with ORD0100 in each business serial number rule.
[0107] Step 504: Send a status acquisition request to the database.
[0108] Among them, the status acquisition request is used to query the process lock status of the maximum value of the segment.
[0109] In implementation, the server sends a status acquisition request to the database to obtain the process lock status of the maximum value of the number segment in the database. If the maximum value of the number segment in the database is in a locked state, the database returns the process lock status of the maximum value of the number segment as a locked state to the server. If the maximum value of the number segment in the database is in an unlocked state, the database returns the process lock status of the maximum value of the number segment as an unlocked state to the server.
[0110] Specifically, there are multiple servers and a database in a distributed system. While one server sends a status acquisition request to the database, another server is generating service serial numbers in batches based on the maximum value of the segment. At this time, the process lock state of the maximum value of the segment in the database is in a locked state. The database returns the process lock state of the maximum value of the segment to the server as a locked state. If there is no server in the distributed system generating service serial numbers while a server sends a status acquisition request to the database, the maximum value of the segment is in an unlocked state. The database returns the process lock state of the maximum value of the segment to the server as an unlocked state. Among them, the process lock here is an exclusive lock, that is, only one server is allowed to read and use the maximum value of the segment at the same time.
[0111] Step 506, receiving the process lock state of the maximum value of the number segment returned by the database, and obtaining the maximum value of the number segment based on the process lock state.
[0112] In implementation, the server receives the process lock status of the maximum value of the segment returned by the database. Then, the server obtains the maximum value of the segment from the database according to the process lock status.
[0113] Specifically, the server receives the process lock status of the maximum value of the segment returned by the database through a network connection. The process lock status ensures whether the maximum value of the segment is locked by the process lock. If the maximum value of the segment is locked by the process lock, the process lock status is locked. At this time, the server cannot read the maximum value of the segment from the database. The server executes the step of sending a status acquisition request to the database according to a preset time period until the process lock status is unlocked. If the maximum value of the segment is not locked by the process lock, the process lock status is unlocked. The server directly reads the maximum value of the segment from the database and locks the maximum value of the segment.
[0114] In this embodiment, by obtaining the process lock state, it is clear whether there are other servers in the distributed system that are generating service serial numbers. When the process lock state is unlocked, the maximum value of the number segment is obtained, so that the server is the only device that generates the target service serial number based on the maximum value of the number segment, avoiding service serial number conflicts and ensuring the uniqueness of the service serial number.
[0115] In an exemplary embodiment, Figure 6As shown, the specific processing process of obtaining the maximum value of the number segment based on the process lock state in step 506 also includes steps 602 to 604. Among them:
[0116] Step 602: If the process lock state is in the locked state, the step of sending a state acquisition request to the database is executed according to a preset time period until the process lock state is in the unlocked state.
[0117] In implementation, a time period is pre-set in the server. If the process lock state is locked, the maximum value of the number segment at this time has been locked by the process lock and cannot be read by the server. Therefore, the server executes the step of sending a status acquisition request to the database according to the time interval corresponding to the preset time period until the process lock state is unlocked. Among them, sending a status acquisition request to the database is the above-mentioned step 504. The specific processing process of step 504 has been described in detail in the above-mentioned embodiment, and the embodiment of this application will not be repeated here.
[0118] Step 604: If the process lock state is unlocked, obtain the maximum value of the segment and lock the maximum value of the segment.
[0119] In implementation, if the process lock state is unlocked, the server directly obtains the maximum value of the segment from the database. Then, the server locks the maximum value of the segment according to the process lock, so that the process lock state of the maximum value of the segment becomes locked.
[0120] Specifically, if the process lock state is unlocked, the server can use the maximum value of the segment, so the server reads the maximum value of the segment from the database. Then, the server locks the maximum value of the segment according to the process lock, so that the process lock state of the maximum value of the segment becomes locked, to prevent other servers from reading the maximum value of the segment to generate a service number, causing confusion in the service number.
[0121] In this embodiment, when the process lock state is unlocked, the maximum sequence number is obtained and locked, which prevents other servers from obtaining the maximum sequence number and ensures the uniqueness of the target business sequence number.
[0122] In an exemplary embodiment, if Figure 7 As shown, the specific processing process of generating the first service sequence number set based on the maximum value of the number segment and the target service sequence number rule in step 206 includes steps 702 to 706. Among them:
[0123] Step 702, determining the starting target service sequence number based on the maximum value of the number segment and the step length in the target service sequence number rule.
[0124] The step length is the interval between two target service numbers.
[0125] In implementation, the server determines the step length in the target service sequence number rule, and performs addition operation on the maximum value of the segment and the step length to obtain the starting target service sequence number.
[0126] In an exemplary embodiment, the step length is 1, and the maximum value of the number segment is 1000. The server performs an addition operation on the maximum value of the number segment 1000 and the step length, and obtains the starting target service sequence number 10001.
[0127] Step 704, starting with the initial target service sequence number, generating a target service sequence number based on a target service sequence number rule.
[0128] In implementation, the server starts with the starting target service sequence number and sequentially generates target service sequence numbers according to the target service sequence number rule.
[0129] Specifically, the target business serial number rule includes a string module, a date module and a digital module. The digital module is used to generate the digital component of the business serial number. The server starts with the starting target business serial number, and increments the starting target business serial number according to the step length in the target business serial number rule to obtain the digital component of the serial number. Then, the server generates the date component according to the date module, and generates the string component according to the string module. The server concatenates the string component, the date component and each digital component to obtain the target business serial number of the serial number.
[0130] In an exemplary embodiment, the target business sequence number rule is an order business sequence number rule. The order business sequence number includes a string module, a date module and a digital module. The starting target business sequence number is 1001, and the step length is 1. The number of sequences is 100. The digital module is used to generate the digital component of the business sequence number. The server starts with 1001 and increments 1001 according to the step length 1 in the target business sequence number rule to obtain the digital component of the sequence number. The digital component of the sequence number is a set of 1001 to 1100. Then, the server generates a date component of 20240814 according to the date module, and generates a string component of ORD according to the string module. The server concatenates the string components, the date component and each digital component to obtain the target business sequence number of the sequence number. The target business sequence number of the sequence number is a set of ORD202408141001 to ORD202408141100.
[0131] Step 706: construct a first service sequence number set according to each target service sequence number.
[0132] In implementation, the server combines the target service sequence numbers into a first service sequence number set according to the size order of the target service sequence numbers.
[0133] In this embodiment, by determining the maximum value of the number segment and the first service sequence number set of the target service sequence number rule to generate the number of sequence numbers, batch generation of service sequence numbers is completed, the number of database accesses is reduced, the requirements for the database are reduced, and the load on the database is reduced. In addition, by generating the target service sequence number in the memory of the server, the dependence on the database is reduced. In addition, by adjusting the acquisition quantity to adapt to different service requirements, the sequence number generation method has good scalability.
[0134] In an exemplary embodiment, after the first service sequence number set is generated, the maximum value of the number segment in the database needs to be unlocked and the maximum value of the number segment needs to be updated. Figure 8 As shown, after step 206 is executed, the specific processing process of the sequence number generation method further includes steps 802 to 804. Among them:
[0135] Step 802, determining the largest target service sequence number in the first service sequence number set as the maximum value of the target number segment, and unlocking the maximum value of the number segment.
[0136] In implementation, the server determines the target service sequence number with the largest value in the first service sequence number set as the target number segment maximum value. Then, the server performs unlocking processing on the number segment maximum value based on the process lock.
[0137] Specifically, the server determines the target service sequence number with the largest value in the first service sequence number set, and determines the digital component of the target service sequence number. Then, the server determines the digital component of the target service sequence number with the largest value as the target segment maximum value. The server unlocks the segment maximum value in the database according to the process lock to obtain the unlocked segment maximum value.
[0138] Step 804: Update the maximum value of the unlocked number segment according to the maximum value of the target number segment.
[0139] During implementation, the server determines the maximum value of the target number segment as the new maximum value of the number segment to obtain the updated maximum value of the number segment.
[0140] Specifically, the server constructs a segment maximum value update request according to the target segment maximum value. Then, the server sends the segment maximum value update request to the database. The database receives the segment maximum value update request and determines the target segment maximum value as the new segment maximum value according to the segment maximum value update request.
[0141] In an exemplary embodiment, the target segment maximum value is 1100. The server constructs a segment maximum value update request according to 1100. Then, the server sends the segment maximum value update request to the database. The database receives the segment maximum value update request and determines the target segment maximum value 1100 as the new segment maximum value according to the segment maximum value update request.
[0142] In this embodiment, by unlocking the maximum value of the sequence number and updating the maximum value of the number segment, the subsequent service end can generate a service sequence number based on the updated maximum value of the number segment, thereby ensuring the uniqueness of the service sequence number. In addition, the database only needs to save the maximum value of the number segment, which reduces the resource occupation of the database. In addition, the implementation of the sequence number generation method is relatively simple, and only requires the design of the database table structure for saving the number segment, as well as the corresponding application and update logic.
[0143] In an exemplary embodiment, Fig. 9 FIG. 1 is a schematic diagram of the architecture of a method for generating a sequence number in an embodiment. Fig. 9 As shown, the distributed system 100 includes a control terminal 110, a server (serial number server) 120, a business terminal (application terminal) 130 and a database 140. The control terminal 110 is responsible for setting the serial number rules, supporting the combination of multiple serial number rules, and can realize personalized configuration of serial number generation strategies. The configured business serial number rules are saved in the database and the server 120. The server 120 is responsible for generating serial numbers according to the business serial number rules set by the control terminal, and generates a certain number of business serial numbers each time. Each time a batch of serial numbers is generated, the database 140 is updated only once (the maximum value of the number segment of this batch of serial numbers is updated). The business terminal 130 connects to the server 120 to obtain business serial numbers for use. Each time the obtained number of business serial numbers is obtained, the business serial numbers are cached locally, and directly obtained from the cache the next time they are used. When the serial numbers are exhausted, another batch is obtained from the server 120. The business terminal 130 saves the cache type and data structure of the business serial numbers. For example, a multi-queue method or a data table method is used to save the business serial numbers. According to Fig. 9 The complete process of generating business sequence numbers in the distributed system shown is:
[0144] 1. The management terminal 110 determines each target component factor among the component factors according to the characteristic information of the target service.
[0145] 2. The management end 110 constructs a target service sequence number rule according to each target component factor, saves the target service sequence number rule to a database, and notifies the service end 120 .
[0146] 3. The service end 130 monitors the service sequence number of each queue or table in the cache to determine whether the current number segment needs to generate a service sequence number. If it is detected that the sequence number needs to be supplemented, it sends a target service sequence number acquisition request to the service end 120 according to its own service sequence number and acquisition quantity to obtain the target service sequence number.
[0147] 4. The server 120 queries the target business sequence number rule according to the business sequence number.
[0148] 5. The server 120 obtains the maximum value of the number segment and determines the number of service sequence numbers to be generated based on the obtained number. Then, the server 120 generates the target service sequence number based on the maximum value of the number segment and the target service sequence number rule. When obtaining the maximum value of the number segment, the database distributed lock capability is used. When multiple threads or processes simultaneously obtain the sequence number, they need to join the action of snatching the lock to ensure that each number segment can only be obtained by one thread.
[0149] 6. The server 120 sends a batch of generated target service serial numbers to the service terminal 130.
[0150] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0151] Based on the same inventive concept, the embodiment of the present application also provides a sequence number generating device for implementing the sequence number generating method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more sequence number generating device embodiments provided below can refer to the limitations of the sequence number generating method above, and will not be repeated here.
[0152] In an exemplary embodiment, Fig.10 As shown, a sequence number generating device 1000 is provided, comprising: a receiving module 1001, an acquiring module 1002 and a generating module 1003, wherein:
[0153] The receiving module 1001 is used to receive a target service serial number acquisition request sent by a service end; the target service serial number acquisition request includes a target service number and an acquisition quantity.
[0154] The acquisition module 1002 is used to query the target service sequence number rule according to the target service number and obtain the maximum value of the number segment.
[0155] The generating module 1003 is used to determine the number of service sequence numbers to be generated based on the acquired quantity, and to generate a first service sequence number set of the number of sequence numbers based on the maximum value of the number segment and the target service sequence number rule.
[0156] In an exemplary embodiment, the sequence number generation module 1000 further includes:
[0157] The second receiving module is used to receive the target service sequence number rule of the target service sequence number sent by the management end.
[0158] An establishment module is used to establish a target business sequence number queue corresponding to the target business sequence number based on the target business sequence number rule; the target business sequence number queue is used to store the target business sequence number.
[0159] In an exemplary embodiment, the sequence number generation module 1000 further includes:
[0160] The query module is used to query the target business sequence number queue according to the target business number, and determine the number of target business sequence numbers in the target business sequence number queue as the queue sequence number number.
[0161] The judgment module is used to judge whether the number of queue numbers is less than the acquisition number.
[0162] The first determination module is used to determine whether the target service sequence number acquisition request meets a preset sequence number generation condition if the number of queue sequence numbers is less than the acquisition number.
[0163] In an exemplary embodiment, the generating module 1002 includes:
[0164] The first query submodule is used to query the target business sequence number rule according to the target business number when the target business sequence number acquisition request meets the sequence number generation condition.
[0165] The first sending submodule is used to send a status acquisition request to the database; the status acquisition request is used to query the process lock state of the maximum value of the number segment.
[0166] The first receiving submodule is used to receive the process lock status of the maximum value of the number segment returned by the database, and obtain the maximum value of the number segment based on the process lock status.
[0167] In an exemplary embodiment, the first receiving submodule includes a second receiving submodule and a first acquiring submodule. The first acquiring submodule includes:
[0168] The second sending submodule is used to execute the step of sending a status acquisition request to the database according to a preset time period if the process lock state is in the locked state, until the process lock state is in the unlocked state.
[0169] The second acquisition submodule is used to obtain the maximum value of the number segment if the process lock state is the unlocked state, and lock the maximum value of the number segment.
[0170] In an exemplary embodiment, the generation module 1003 includes a first determination submodule and a first generation submodule. The first generation submodule includes:
[0171] The second determination submodule is used to determine the starting target service sequence number based on the maximum value of the number segment and the step length in the target service sequence number rule.
[0172] The second generating submodule is used to start with the initial target service sequence number and generate a target service sequence number based on the target service sequence number rule.
[0173] The first construction submodule is used to construct a first service sequence number set according to each target service sequence number.
[0174] In an exemplary embodiment, the sequence number generation module 1000 further includes:
[0175] The unlocking module is used to determine the largest target service sequence number in the first service sequence number set as the maximum value of the target number segment, and to unlock the maximum value of the number segment.
[0176] The update module is used to update the maximum value of the unlocked number segment according to the maximum value of the target number segment.
[0177] Each module in the above-mentioned sequence number generating device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0178] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Fig.11As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data used in the serial number generation method. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a serial number generation method is implemented.
[0179] Those skilled in the art will understand that Fig.11 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0180] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0181] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0182] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0183] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0184] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0185] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for generating a sequence number, It is characterized in that The method comprises: Receive a target service serial number acquisition request sent by a service end; the target service serial number acquisition request includes a target service number and an acquisition quantity; Query the target service sequence number rule according to the target service number, and obtain the maximum value of the number segment; The number of service sequence numbers to be generated is determined based on the acquired quantity, and a first service sequence number set of the number of sequence numbers is generated based on the maximum value of the number segment and the target service sequence number rule.
2. The method according to claim 1, It is characterized in that Before receiving the target service sequence number acquisition request sent by the service end, the method further includes: Receive the target business sequence number rule of the target business sequence number sent by the management end; A target service sequence number queue corresponding to the target service sequence number is established based on the target service sequence number rule; the target service sequence number queue is used to store the target service sequence number.
3. The method according to claim 1, It is characterized in that After receiving the target service sequence number acquisition request sent by the service end, the method further includes: Querying a target service sequence number queue according to the target service number, and determining the number of target service sequence numbers in the target service sequence number queue as the number of queue sequence numbers; Determine whether the number of queue sequence numbers is less than the acquired number; If the number of queue sequence numbers is less than the acquisition number, it is determined that the target service sequence number acquisition request meets a preset sequence number generation condition.
4. The method according to claim 3, It is characterized in that The querying of the target service sequence number rule according to the target service number and obtaining the maximum value of the number segment includes: In the case where the target service sequence number acquisition request meets the sequence number generation condition, querying the target service sequence number rule according to the target service number; Sending a status acquisition request to the database; the status acquisition request is used to query the process lock status of the maximum value of the segment; The process lock state of the maximum value of the number segment returned by the database is received, and the maximum value of the number segment is obtained based on the process lock state.
5. The method according to claim 4, It is characterized in that The obtaining the maximum value of the number segment based on the process lock state includes: If the process lock state is a locked state, executing the step of sending a state acquisition request to a database according to a preset time period until the process lock state is an unlocked state; If the process lock state is unlocked, the maximum value of the number segment is obtained, and the maximum value of the number segment is locked.
6. The method according to claim 1, It is characterized in that The first service sequence number set of the number of sequence numbers generated based on the maximum value of the number segment and the target service sequence number rule includes: Determine the starting target service sequence number based on the maximum value of the number segment and the step length in the target service sequence number rule; Starting from the starting target service sequence number, generating the target service sequence number of the sequence number based on the target service sequence number rule; A first service sequence number set is constructed according to each of the target service sequence numbers.
7. The method according to claim 1, It is characterized in that After generating the first service sequence number set of the number of sequence numbers based on the maximum value of the number segment and the target service sequence number rule, the method further includes: Determine the largest target service sequence number in the first service sequence number set as the maximum value of the target number segment, and unlock the maximum value of the number segment; The maximum value of the unlocked number segment is updated according to the maximum value of the target number segment.
8. A sequence number generating device, It is characterized in that The device comprises: A receiving module, used for receiving a target service serial number acquisition request sent by a service end; the target service serial number acquisition request includes a target service number and an acquisition quantity; An acquisition module, used to query the target service sequence number rule according to the target service number, and obtain the maximum value of the number segment; A generation module is used to determine the number of service serial numbers to be generated based on the acquired quantity, and to generate a first service serial number set of the number of serial numbers based on the maximum value of the number segment and the target service serial number rule.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data query method and system
CN105718452A
Service number assignment method and device, computer equipment and storage medium
CN107786628A
ID management method and apparatus
CN108874946A
Serial number generation method, apparatus and system, and storage medium
CN109450987A
Service scene element serial number generation method and device, medium and computer equipment
CN109597853A
