Sequence identifier generation method and device, equipment, medium and program product
By establishing a target number segment pool in the server's memory, allocating serial numbers using atomic long integers, and asynchronously loading number segments, the problem of high database pressure in high-concurrency scenarios is solved, and more stable serial number generation is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- INDUSTRIAL AND COMMERCIAL BANK OF CHINA
- Filing Date
- 2026-01-23
- Publication Date
- 2026-05-12
Smart Images

Figure CN122019539A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically to a method, apparatus, device, medium, and program product for generating sequence identifiers. Background Technology
[0002] With the rapid development of the internet and mobile internet, order numbers, message identifiers, device codes, and tracing identifiers all need to be globally unique. Related technologies typically require inserting an empty record into the database or calling an auto-increment function each time business data is received. The database then returns the primary key, and the business data is written back. However, this method requires multiple database accesses when dealing with large volumes of business data, leading to significant database pressure. Summary of the Invention
[0003] In view of the above problems, this application provides a method, apparatus, device, medium and program product for generating sequence identifiers.
[0004] According to a first aspect of this application, a sequence identifier generation method is provided, comprising: sending a number segment acquisition request for at least one first number segment to the database, wherein each of the first number segments includes multiple sequence numbers; receiving the at least one first number segment allocated by the database based on the number segment acquisition request, and storing the at least one first number segment in a target number segment pool in the memory of a server; in response to receiving newly added first service data, determining a target sequence number from the at least one first number segment in the target number segment pool; allocating the target sequence number to the first service data, and storing the first service data in the database based on the target sequence number.
[0005] According to an embodiment of this application, the target number segment pool includes a primary number segment pool and a backup number segment pool. The target number segment pool that stores the at least one first number segment in the server's memory includes: distributing and storing multiple serial numbers from the at least one first number segment to the primary number segment pool and the backup number segment pool.
[0006] According to an embodiment of this application, the method further includes: when the serial numbers in the main number segment pool have been allocated and the serial numbers of the first quantity proportion in the multiple serial numbers in the backup number segment pool have been allocated, sending a request to the database for obtaining the second number segment, and storing the second number segment in the main number segment pool.
[0007] According to an embodiment of this application, the target number segment pool includes a primary number segment pool and a backup number segment pool. The method of storing the at least one first number segment in the server's memory includes: storing all the serial numbers in the at least one first number segment into the primary number segment pool; the method further includes: when the serial numbers with a second quantity ratio in the multiple serial numbers in the primary number segment pool have been allocated, sending a request to the database to obtain a third number segment, and storing the third number segment into the backup number segment pool.
[0008] According to an embodiment of this application, the above-mentioned number segment acquisition request for at least one first number segment includes a target number segment step size, which is determined by the following method: acquiring the historical number segment consumption rate, and determining the consumed number segment step size based on the historical number segment consumption rate, a preset baseline rate, a preset base step size, and a preset buffer parameter; determining the target number segment step size from a preset first step size, a preset second step size, and the consumed number segment step size, wherein the preset first step size is greater than the preset second step size.
[0009] According to an embodiment of this application, determining the target number segment step length from the preset first step length, the preset second step length, and the consumed number segment step length includes: determining a candidate number segment step length from the consumed number segment step length and the preset second step length, wherein the candidate number segment step length is the larger of the consumed number segment step length and the preset second step length; and determining the target number segment step length from the candidate number segment step length and the preset first step length, wherein the target number segment step length is the smaller of the candidate number segment step length and the preset first step length.
[0010] According to an embodiment of this application, after determining the target sequence number from at least one first number segment in the target number segment pool, the method further includes: obtaining a first timestamp corresponding to the time of addition of the first service data, and assembling the first timestamp and the target sequence number to obtain a verification sequence number; storing the verification sequence number in the database; and in response to receiving newly added second service data, obtaining a second timestamp corresponding to the time of addition of the second service data, and performing error processing if the second timestamp is less than the first timestamp in the verification sequence number.
[0011] A second aspect of this application provides a sequence identifier generation apparatus, which is assembled in multiple distributed servers connected to a database, comprising: a sending module for sending a number segment acquisition request for at least one first number segment to the database, wherein each first number segment includes multiple sequence numbers; a receiving module for receiving the at least one first number segment allocated by the database based on the number segment acquisition request, and storing the at least one first number segment in a target number segment pool in the memory of the server; a determining module for determining a target sequence number from at least one first number segment in the target number segment pool in response to receiving newly added first service data; and an allocation module for allocating the target sequence number to the first service data, and storing the first service data in the database based on the target sequence number.
[0012] A third aspect of this application provides an electronic device comprising: one or more processors; and a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the method described above.
[0013] A fourth aspect of this application also provides a computer-readable storage medium having a computer program or instructions stored thereon, which, when executed by a processor, implement the steps of the above-described method.
[0014] The fifth aspect of this application also provides a computer program product, including a computer program or instructions that, when executed by a processor, implement the steps of the above-described method.
[0015] According to the embodiments of this application, by storing a first number segment containing multiple serial numbers in a target number segment pool in the server's memory, when new first business data is received, there is no need to access the database in real time. The target serial number can be directly allocated from the target number segment pool to the first business data, thereby reducing the number of data interactions between the distributed server and the database. Even in the event of a database failure, a serial number can still be allocated to the business data. This at least partially eliminates the latency and lock contention caused by frequent database connections in high-parallel operation scenarios, reduces the interaction pressure on the database, and thus improves the stability of the system. Attached Figure Description
[0016] The above-mentioned contents, other objects, features and advantages of this application will become clearer from the following description of embodiments with reference to the accompanying drawings, in which:
[0017] Figure 1 This illustration schematically depicts an application scenario of the sequence identifier generation method and apparatus according to embodiments of this application.
[0018] Figure 2A flowchart illustrating a sequence identifier generation method according to an embodiment of this application is shown schematically.
[0019] Figure 3 A schematic diagram illustrating the structure of a sequence identifier generation apparatus according to an embodiment of this application is shown; and
[0020] Figure 4 A block diagram schematically illustrates an electronic device suitable for implementing a sequence identifier generation method according to an embodiment of this application. Detailed Implementation
[0021] The embodiments of this application will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of this application. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of this application for ease of explanation. However, it will be apparent that one or more embodiments may be implemented without these specific details. Furthermore, descriptions of well-known structures and technologies are omitted in the following description to avoid unnecessarily obscuring the concepts of this application.
[0022] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The terms “comprising,” “including,” etc., as used herein indicate the presence of the stated features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0023] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.
[0024] When using expressions such as "at least one of A, B and C", they should generally be interpreted in accordance with the meaning that is commonly understood by those skilled in the art (e.g., "a system having at least one of A, B and C" should include, but is not limited to, a system having A alone, a system having B alone, a system having C alone, a system having A and B, a system having A and C, a system having B and C, and / or a system having A, B and C, etc.).
[0025] In scenarios involving automated decision-making using personal information, the methods, devices, and systems provided in this application all offer users corresponding entry points for choosing to agree to or reject the automated decision-making results. If the user chooses to reject, the process proceeds to the expert decision-making stage. Here, "automated decision-making" refers to the activity of automatically analyzing and evaluating an individual's behavioral habits, interests, or economic, health, and credit status through computer programs, and then making a decision. Here, "expert decision-making" refers to the activity of making decisions by personnel who specialize in a particular field, possess specialized experience, knowledge, and skills, and have reached a certain level of professional expertise.
[0026] In distributed business systems, a fixed-format sequence number (including timestamp and incrementing sequence number) is generally used as the unique identifier for the corresponding business data in the database. Related technologies typically use an auto-incrementing field in the database to generate the unique identifier for the business data. However, in high-concurrency scenarios, the database faces significant pressure due to frequent writes.
[0027] In view of this, embodiments of this application provide a sequence identifier generation method. The method is applied to multiple distributed servers connected to a database. The method includes: sending a number segment acquisition request to the database for at least one first number segment, wherein each first number segment includes multiple sequence numbers; receiving at least one first number segment allocated by the database based on the number segment acquisition request, and storing the at least one first number segment in a target number segment pool in the server's memory; in response to receiving newly added first service data, determining a target sequence number from at least one first number segment in the target number segment pool; allocating the target sequence number to the first service data, and storing the first service data in the database based on the target sequence number.
[0028] Figure 1 The illustration shows an application scenario of the sequence identifier generation method and apparatus according to embodiments of this application.
[0029] like Figure 1 As shown, application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 serves as a medium for providing a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0030] Users can use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 via the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).
[0031] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0032] Server 105 can be a server that provides various services, such as a backend management server that supports websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103 (this is just an example). The backend management server can analyze and process data such as received user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal devices.
[0033] It should be noted that the sequence identifier generation method provided in this application embodiment can generally be executed by server 105. Correspondingly, the sequence identifier generation device provided in this application embodiment can generally be located in server 105. The sequence identifier generation method provided in this application embodiment can also be executed by a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105. Correspondingly, the sequence identifier generation device provided in this application embodiment can also be located in a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105.
[0034] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0035] The following will be based on Figure 1 The described scene, through Figure 2 The sequence identifier generation method according to the embodiments of this application will be described in detail.
[0036] Figure 2 A flowchart illustrating a sequence identifier generation method according to an embodiment of this application is shown schematically.
[0037] like Figure 2 As shown, the sequence identifier generation method of this embodiment includes operations S210 to S240.
[0038] In operation S210, a number segment retrieval request for at least one first number segment is sent to the database.
[0039] Each of the first number segments includes multiple serial numbers.
[0040] According to an embodiment of this application, the number segment is a range of numbers continuously allocated by a database at one time, containing multiple globally unique and monotonically increasing sequence numbers. For example, the first number segment can be [1, 10000], that is, covering all integers from sequence number 1 to sequence number 10000. The above sequence numbers can be numbers of any length, and this application does not impose any restrictions on this.
[0041] According to the embodiments of this application, after the distributed server starts, it can immediately send a request to the database to obtain the number segment for the first number segment, so as to store the first number segment in the target number segment pool in a timely manner.
[0042] In operation S220, at least one first number segment is received from the database based on the number segment acquisition request, and at least one first number segment is stored in the target number segment pool in the server's memory.
[0043] According to the embodiments of this application, atomic long integers can be used for memory segment allocation, thereby avoiding the performance bottleneck of traditional locking mechanisms. The lock-free operation of atomic long integers ensures efficient allocation under high concurrency, reducing memory allocation latency. Since atomic long integers can achieve lock-free thread safety through optimistic locking, database performance issues caused by lock contention can be avoided.
[0044] In operation S230, in response to receiving newly added first service data, a target sequence number is determined from at least one first number segment in the target number segment pool.
[0045] In operation S240, the target sequence number is assigned to the first service data, and the first service data is stored in the database based on the target sequence number.
[0046] For example, when the newly added first service data is received, the currently used first number segment (set to [0, 10000]) can be found from the target number segment pool, and an unused minimum serial number (set to 999) can be taken from the first number segment as the target serial number. The target serial number is then assigned to the first service data. At the same time, the target serial numbers that have been used are deleted from the target number segment pool. Furthermore, the first service data with the assigned target serial number can be stored in the database.
[0047] According to the embodiments of this application, the serial number table stored in the database can store a business identifier, the current value, the target number segment step size, whether it is cyclic, and whether it is an optimistic lock. When a request to obtain the first number segment is received, it is necessary to verify the old version identifier carried in the request. If the old version identifier is consistent with the current version identifier stored in the database, the first number segment is returned to the server, thereby ensuring that the same number segment is not assigned to multiple different distributed servers. At the same time, the current version identifier in the database is updated. If the acquisition of the number segment fails, the current version identifier is returned to the server that failed to acquire the number segment, so that the server can retry multiple times until the first number segment is acquired.
[0048] According to the embodiments of this application, by storing a first number segment containing multiple sequence numbers in a target number segment pool in the server's memory, when new first business data is received, there is no need to access the database in real time. The target sequence number can be directly allocated from the target number segment pool to the first business data, thereby reducing the number of data interactions between the distributed server and the database. Even in the event of a database failure, a sequence number can still be allocated to the business data. This at least partially eliminates the latency and lock contention caused by frequent database connections in high-parallel operation scenarios, reduces the interaction pressure on the database, and thus improves the stability of the system.
[0049] According to the embodiments of this application, the target number segment pool includes a primary number segment pool and a backup number segment pool. The target number segment pool that stores at least one first number segment in the memory of the server includes: distributing and storing multiple serial numbers in at least one first number segment to the primary number segment pool and the backup number segment pool.
[0050] For example, given two first number segments, [1, 10000] and [10001, 20000], during the selection process for storing number segments in the target number segment pool, the first number segment [0, 10000] can be stored in the primary number segment pool, and the first number segment [10001, 20000] can be stored in the backup number segment pool. Furthermore, during the determination of the target sequence number, the target sequence number is preferentially determined from the number segment pool storing the smaller number segment. In this example, the target sequence number can be determined from the first number segment [1, 10000] in the primary number segment pool. Once the number segments in the primary number segment pool are exhausted (i.e., no sequence number exists in the primary number segment pool), a sequence number is selected from the backup number segment pool as the target sequence number for distribution to business data.
[0051] According to the embodiments of this application, the above method further includes: when the serial numbers in the main number segment pool have been allocated and the serial numbers of the first quantity proportion in the multiple serial numbers in the backup number segment pool have been allocated, sending a request to the database to obtain the second number segment, and storing the second number segment in the main number segment pool.
[0052] According to the embodiments of this application, the above-mentioned preset number segment threshold can be any value between 0% and 100%, and in this application it can be set to 50%.
[0053] For example, when the primary number segment pool is empty and the first number segment in the backup number segment pool has been consumed to 75% (preset number segment threshold), the distributed server can perform asynchronous number segment loading. The number segments in the current backup number segment pool are set to [10001, 20000]. When the sequence number 175001 is allocated, the server sends a request to the database to obtain the second number segment [20001, 30000] and stores the second number segment in the primary number segment pool. When the backup number segment pool is empty, it can instantly switch to the primary number segment pool to ensure that the sequence number allocation is not interrupted and improve system stability.
[0054] According to the embodiments of this disclosure, when the first number segment in the backup number segment pool is consumed to a preset number segment threshold, a second number segment is asynchronously acquired and stored in the main number segment pool. This ensures that there are already loaded backup number segments stored in memory, allowing direct switching to another number segment pool when either number segment pool is empty. This avoids interruption in sequence number allocation, achieves seamless switching, and improves the user experience. Furthermore, by asynchronously loading number segments, there is no need to block business threads while waiting for the database to return the second number segment, enabling continuous and high-throughput sequence number generation in high-concurrency scenarios.
[0055] According to the embodiments of this disclosure, the target number segment pool includes a primary number segment pool and a backup number segment pool. The method of storing at least one first number segment in the memory of the server includes: storing all the serial numbers in the at least one first number segment into the primary number segment pool; the method further includes: when the serial numbers of the second quantity ratio in the multiple serial numbers in the primary number segment pool have been allocated, sending a request to the database to obtain a third number segment, and storing the third number segment into the backup number segment pool.
[0056] For example, the first number segment [1, 10000] can be stored in the main number segment pool. When the first number segment in the main number segment pool is consumed to 75%, a request to retrieve the third number segment [10001, 20000] can be sent to the database to retrieve the third number segment and store it in the backup number segment pool.
[0057] It should be noted that the ordinal numbers such as first, second, and third in this application are only used to distinguish data / number segments from different steps, batches, or sources, and do not imply any limitation on their priority, time sequence, or quantity; in any embodiment, the terms "first number segment", "second number segment", and "third number segment" can be used interchangeably, and can also be expanded to more number segments according to business needs, without departing from the protection scope of this application.
[0058] According to embodiments of this disclosure, the target number segment pool can contain two backup number segment pools (a first backup number segment pool and a second backup number segment pool). After obtaining a first number segment, multiple first number segments can be stored in the primary number segment pool and the first backup number segment pool, respectively. When the primary number segment pool is empty and a switch to the first backup number segment pool is required, the number segments that need to be stored in the second backup number segment pool are asynchronously loaded. The buffering effect of multiple backup number segment pools provides a larger security boundary.
[0059] According to an embodiment of this disclosure, the above-mentioned number segment acquisition request for at least one first number segment includes a target number segment step size, which is determined by the following method: acquiring the historical number segment consumption rate, and determining the consumption number segment step size based on the historical number segment consumption rate, a preset baseline rate, and a preset buffer parameter; determining the target number segment step size from a preset first step size, a preset second step size, and the consumption number segment step size, wherein the preset first step size is greater than the preset second step size.
[0060] According to the embodiments of this disclosure, the aforementioned historical number segment consumption rate is the number of serial numbers consumed within a preset time period, and the preset baseline rate is the average consumption rate determined based on multiple tests.
[0061] According to an embodiment of this disclosure, determining the target number segment step length from the preset first step length, the preset second step length, and the consumed number segment step length includes: determining a candidate number segment step length from the consumed number segment step length and the second step length, wherein the candidate number segment step length is the larger of the consumed number segment step length and the second step length; and determining the target number segment step length from the candidate number segment step length and the first step length, wherein the target number segment step length is the smaller of the candidate number segment step length and the first step length.
[0062] The step size of the target number segment can be determined by the following formula (1).
[0063] (1)
[0064] in, The target number segment step size, To preset the length of the first step, To preset the second step length, To preset the base step size, This refers to the historical number segment consumption rate. For the preset reference rate, For preset buffer parameters, This is to consume the segment step size.
[0065] For example, if the preset first step length is set to 10000, the preset second step length is set to 500, the preset base step length is set to 1000, the historical number segment consumption rate is set to 1500, the preset base rate is set to 1000, and the preset buffer parameter is set to 1.2, then the consumption number segment step length is 1000 × (1500 / 1000) × 1.2 = 1800. Therefore, the determined candidate number segment step length is 1800 (because the preset second step length of 500 is less than the consumption number segment step length of 1800). Furthermore, the preset first step length and the candidate number segment step length are compared, and the determined target number segment step length is 1800 (because the preset first step length of 10000 is greater than the candidate number segment step length of 1800).
[0066] According to the embodiments of this application, the traffic volume is monitored in real time by monitoring the historical number segment consumption rate, thereby dynamically adjusting the step size of the target number segment prefetched from the database. When the traffic volume is low, the step size is automatically reduced to avoid loading too many unused number segments at once, reducing unnecessary database updates and memory usage. At the same time, when the traffic volume is high, the target number segment step size is automatically increased, thereby reducing the frequency of database connections. This ensures that the number segments in memory are not consumed too quickly in high-concurrency scenarios, which would require interrupting operations and waiting. This can smoothly cope with sudden traffic surges and avoid the instability caused by fixed number segment step sizes when the traffic volume fluctuates.
[0067] According to an embodiment of this application, after determining the target sequence number from at least one first number segment in the target number segment pool, the method further includes: obtaining a first timestamp corresponding to the time when the first service data is added, and assembling the first timestamp and the target sequence number to obtain a verification sequence number; storing the verification sequence number in a database; and in response to receiving newly added second service data, obtaining a second timestamp corresponding to the time when the second service data is added, and performing error processing if the second timestamp is less than the first timestamp in the verification sequence number.
[0068] For example, if the first timestamp in the verification sequence number is "1719567890123" (Unix timestamp, corresponding to 2025-07-01 17:44:50.123) and the target sequence number is "999", then when the server receives the second business data, it needs to first verify the size of the second timestamp "1719564290123" (Unix timestamp, corresponding to 2025-07-01 16:44:50.123) and the first timestamp. If the second timestamp is smaller than the first timestamp, it is determined that a clock rollback operation has occurred. To avoid conflicts in the verification sequence number, error handling can be performed.
[0069] According to the embodiments of this application, since the verification serial number contains a new time corresponding to the business data, it can support fast retrieval by time index.
[0070] According to the embodiments of this application, after the verification sequence number assembled from the target sequence number and the first timestamp is stored in the database, the second timestamp corresponding to the second business data is not earlier than the first timestamp as a constraint. Even if the system clock jumps, an error can be triggered in time before writing, thereby reducing the risk of verification sequence number disorder and data overwriting caused by clock back-off and ensuring the monotonicity of the global verification sequence number.
[0071] Based on the above sequence identifier generation method, this application also provides a sequence identifier generation apparatus. The following will be combined with... Figure 3 The device is described in detail.
[0072] Figure 3 A schematic block diagram of a sequence identifier generation apparatus according to an embodiment of this application is shown.
[0073] like Figure 3 As shown, the sequence identifier generation device 300 of this embodiment includes a sending module 310, a receiving module 320, a determining module 330, and an allocation module 340.
[0074] The sending module 310 is used to send a number segment retrieval request to the database for at least one first number segment, wherein each first number segment includes multiple sequence numbers. In one embodiment, the sending module 310 can be used to perform the operation S210 described above, which will not be repeated here.
[0075] The receiving module 320 is used to receive at least one first number segment allocated by the database based on the number segment acquisition request, and to store the at least one first number segment in the target number segment pool in the server's memory. In one embodiment, the receiving module 320 can be used to perform the operation S220 described above, which will not be repeated here.
[0076] The determining module 330 is configured to determine a target sequence number from at least one first number segment in the target number segment pool in response to receiving newly added first service data. In one embodiment, the determining module 330 may be used to perform the operation S230 described above, which will not be repeated here.
[0077] The allocation module 340 is used to allocate a target sequence number to the first service data and store the first service data in the database based on the target sequence number. In one embodiment, the allocation module 340 can be used to perform the operation S240 described above, which will not be repeated here.
[0078] According to an embodiment of this application, the target number segment pool includes a primary number segment pool and a backup number segment pool. The receiving module 320 includes a distributed storage submodule, which is used to distribute and store multiple serial numbers from at least one first number segment into the primary number segment pool and the backup number segment pool.
[0079] According to an embodiment of this application, the above-mentioned device further includes: a main number segment pool renewal submodule, which sends a request to the database to obtain the second number segment when the serial numbers in the main number segment pool have been allocated and the serial numbers of the first quantity proportion in the multiple serial numbers in the backup number segment pool have been allocated, and stores the second number segment in the main number segment pool.
[0080] According to an embodiment of this application, the target number segment pool includes a primary number segment pool and a backup number segment pool. The receiving module 320 includes: a full storage submodule, used to store at least one first number segment into the primary number segment pool. The above device also includes: a backup number segment pool continuation submodule, used to send a request to the database for obtaining a third number segment when the sequence numbers with a second quantity ratio in the multiple sequence numbers in the primary number segment pool have been allocated, and to store the third number segment into the backup number segment pool.
[0081] According to an embodiment of this application, a number segment acquisition request for at least one first number segment includes a target number segment step size. The device further includes: a number segment consumption step size determination module, used to acquire historical number segment consumption rates and determine the number segment consumption step size based on historical number segment consumption rates, a preset baseline rate, a preset base step size, and preset buffer parameters; and a target number segment step size determination module, used to determine the target number segment step size from a preset first step size, a preset second step size, and the number segment consumption step size, wherein the preset first step size is greater than the preset second step size.
[0082] According to an embodiment of this application, the target number segment step size determination module includes: a candidate number segment step size determination submodule, used to determine a candidate number segment step size from the consumed number segment step size and a preset second step size, wherein the candidate number segment step size is the larger step size between the consumed number segment step size and the preset second step size; and a target number segment determination submodule, used to determine a target number segment step size from the candidate number segment step size and a preset first step size, wherein the target number segment step size is the smaller step size between the candidate number segment step size and the preset first step size.
[0083] According to an embodiment of this application, the above-mentioned apparatus further includes: a first timestamp acquisition module, configured to acquire a first timestamp corresponding to the time of addition of the first service data, and assemble the first timestamp and a target sequence number to obtain a verification sequence number; a verification storage module, configured to store the verification sequence number in a database; and a second timestamp acquisition module, configured to, in response to receiving newly added second service data, acquire a second timestamp corresponding to the time of addition of the second service data, and perform error processing if the second timestamp is less than the first timestamp in the verification sequence number.
[0084] According to embodiments of this application, any plurality of modules among the transmitting module 310, receiving module 320, determining module 330, and allocation module 340 can be combined into one module, or any one of these modules can be split into multiple modules. Alternatively, at least part of the functionality of one or more of these modules can be combined with at least part of the functionality of other modules and implemented in one module. According to embodiments of this application, at least one of the transmitting module 310, receiving module 320, determining module 330, and allocation module 340 can be at least partially implemented as hardware circuitry, such as a field-programmable gate array (FPGA), a programmable logic array (PLA), a system-on-a-chip, a system-on-a-substrate, a system-on-package, an application-specific integrated circuit (ASIC), or any other reasonable means of integrating or packaging circuitry, or implemented in software, hardware, or firmware, or in any appropriate combination of any of these three implementation methods. Alternatively, at least one of the transmitting module 310, receiving module 320, determining module 330, and allocation module 340 can be at least partially implemented as a computer program module, which, when run, can perform corresponding functions.
[0085] Figure 4 A block diagram schematically illustrates an electronic device suitable for implementing a sequence identifier generation method according to an embodiment of this application.
[0086] like Figure 4 As shown, an electronic device 400 according to an embodiment of this application includes a processor 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage portion 408 into a random access memory (RAM) 403. The processor 401 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 401 may also include onboard memory for caching purposes. The processor 401 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of this application.
[0087] RAM 403 stores various programs and data required for the operation of electronic device 400. Processor 401, ROM 402, and RAM 403 are interconnected via bus 404. Processor 401 executes various operations of the method flow according to embodiments of this application by executing programs in ROM 402 and / or RAM 403. It should be noted that the programs may also be stored in one or more memories other than ROM 402 and RAM 403. Processor 401 may also execute various operations of the method flow according to embodiments of this application by executing programs stored in said one or more memories.
[0088] According to embodiments of this application, the electronic device 400 may further include an input / output (I / O) interface 405, which is also connected to a bus 404. The electronic device 400 may also include one or more of the following components connected to the input / output (I / O) interface 405: an input section 406 including a keyboard, mouse, etc.; an output section 407 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 408 including a hard disk, etc.; and a communication section 409 including a network interface card such as a LAN card, modem, etc. The communication section 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the input / output (I / O) interface 405 as needed. A removable medium 411, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 410 as needed so that computer programs read from it can be installed into the storage section 408 as needed.
[0089] This application also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs, which, when executed, implement the method according to the embodiments of this application.
[0090] According to embodiments of this application, the computer-readable storage medium can be a non-volatile computer-readable storage medium, such as including but not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to embodiments of this application, the computer-readable storage medium may include ROM 402 and / or RAM 403 and / or one or more memories other than ROM 402 and RAM 403 described above.
[0091] Embodiments of this application also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowchart. When the computer program product is run on a computer system, the program code is used to enable the computer system to implement the sequence identifier generation method provided in the embodiments of this application.
[0092] When the computer program is executed by the processor 401, it performs the functions defined in the system / apparatus of this application embodiment. According to the embodiments of this application, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0093] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and downloaded and installed via communication section 409, and / or installed from removable medium 411. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.
[0094] In such an embodiment, the computer program can be downloaded and installed from a network via communication section 409, and / or installed from removable medium 411. When the computer program is executed by processor 401, it performs the functions defined in the system of this application embodiment. According to embodiments of this application, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0095] According to embodiments of this application, program code for executing the computer programs provided in the embodiments of this application can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0096] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0097] Those skilled in the art will understand that the features described in the various embodiments of this application can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this application. In particular, the features described in the various embodiments of this application can be combined and / or combined in various ways without departing from the spirit and teachings of this application. All such combinations and / or combinations fall within the scope of this application.
Claims
1. A sequence identifier generation method, characterized in that, The method is applied to multiple distributed servers connected to the database, and the method includes: Send a number segment retrieval request to the database for at least one first number segment, wherein each first number segment includes multiple sequence numbers; The database receives at least one first number segment allocated based on the number segment acquisition request, and stores the at least one first number segment in the target number segment pool in the server's memory. In response to receiving newly added first service data, a target sequence number is determined from at least one first number segment in the target number segment pool; The target sequence number is assigned to the first service data, and the first service data is stored in the database based on the target sequence number.
2. The method according to claim 1, characterized in that, The target number segment pool includes a primary number segment pool and a backup number segment pool. The target number segment pool for storing the at least one first number segment in the server's memory includes: Multiple serial numbers from at least one first number segment are distributed and stored in the primary number segment pool and the backup number segment pool.
3. The method according to claim 2, characterized in that, The method further includes: When all serial numbers in the primary number segment pool have been allocated, and all serial numbers in the backup number segment pool that represent the first percentage of serial numbers have been allocated, a request to obtain the second number segment is sent to the database, and the second number segment is stored in the primary number segment pool.
4. The method according to claim 1, characterized in that, The target number segment pool includes a primary number segment pool and a backup number segment pool. The target number segment pool for storing the at least one first number segment in the server's memory includes: Store all serial numbers from at least one first number segment into the main number segment pool; The method further includes: When the sequence numbers with the second proportion in the primary number segment pool have been allocated, a request to obtain the third number segment is sent to the database, and the third number segment is stored in the backup number segment pool.
5. The method according to claim 1, characterized in that, The number segment acquisition request for at least one first number segment includes a target number segment step size, which is determined by the following method: Obtain the historical number segment consumption rate, and determine the consumption number segment step size based on the historical number segment consumption rate, preset baseline rate, preset basic step size and preset buffer parameters; The target number segment step length is determined from the preset first step length, the preset second step length, and the consumed number segment step length, wherein the preset first step length is greater than the preset second step length.
6. The method according to claim 2, characterized in that, Determining the target number segment step length from the preset first step length, the preset second step length, and the consumed number segment step length includes: A candidate number segment step size is determined from the consumed number segment step size and the preset second step size, wherein the candidate number segment step size is the larger of the consumed number segment step size and the preset second step size; The target number segment step size is determined from the candidate number segment step size and the preset first step size, wherein the target number segment step size is the smaller of the candidate number segment step size and the preset first step size.
7. The method according to claim 1, characterized in that, After determining the target sequence number from at least one first number segment in the target number segment pool, the method further includes: Obtain the first timestamp corresponding to the time of addition of the first business data, and assemble the first timestamp with the target sequence number to obtain the verification sequence number; Store the verification serial number in the database; In response to receiving newly added second service data, a second timestamp corresponding to the time the second service data was added is obtained. If the second timestamp is less than the first timestamp in the verification sequence number, an error is reported.
8. A sequence identifier generation device, characterized in that, The device is assembled on multiple distributed servers connected to the database, and the device includes: The sending module is used to send a number segment retrieval request for at least one first number segment to the database, wherein each first number segment includes multiple sequence numbers; The receiving module is used to receive at least one first number segment allocated by the database based on the number segment acquisition request, and to store the at least one first number segment in the target number segment pool in the memory of the server. The determination module is configured to determine a target sequence number from at least one first number segment in the target number segment pool in response to receiving newly added first service data; The allocation module is used to allocate the target sequence number to the first service data and store the first service data in the database based on the target sequence number.
9. An electronic device, comprising: One or more processors; Memory, used to store one or more computer programs. The characteristic feature is that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program or instructions stored thereon, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method according to any one of claims 1 to 7.