Serial number distribution method and device, equipment and storage medium
By using a primary and backup number segment caching mechanism and atomic increment operations, the performance bottleneck and availability issues of sequence number allocation in high-concurrency environments are resolved, achieving continuity and accuracy in sequence number allocation and improving system stability and user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- INDUSTRIAL AND COMMERCIAL BANK OF CHINA
- Filing Date
- 2025-12-29
- Publication Date
- 2026-04-17
AI Technical Summary
In high-concurrency and large-data-volume scenarios, traditional serial number allocation methods are prone to performance bottlenecks and availability issues, leading to intermittent serial number allocation and affecting system stability and user experience.
The system employs a primary number segment cache and a backup number segment cache mechanism. Sequence numbers are allocated to the requesting client in the primary number segment cache through atomic increment operations, and the backup number segment cache is started asynchronously when the consumption rate or usage conditions are met. This reduces the frequency of database access and ensures the continuity and availability of sequence numbers.
It improves the continuity and availability of serial number allocation, reduces the frequency of database access, ensures the accuracy of serial number allocation and the stability of the system, and enhances the user experience.
Smart Images

Figure CN121880342A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology and can be applied to the field of financial technology, especially the field of big data technology. Specifically, it relates to a serial number allocation method, apparatus, device and storage medium. Background Technology
[0002] In complex distributed systems, it is often necessary to uniquely identify large amounts of data and messages, such as bank transaction serial numbers. The allocation of sequence numbers is crucial to ensuring the uniqueness and order of data records.
[0003] However, in scenarios with high concurrency and large data volumes, traditional serial number allocation methods often encounter performance bottlenecks and availability issues. These problems may lead to interruptions in serial number allocation, thereby affecting the stability of the entire system and the user experience. Summary of the Invention
[0004] This application provides a serial number allocation method, apparatus, device, and storage medium to improve the continuity and availability of serial number allocation.
[0005] According to one aspect of this application, a serial number allocation method is provided, the method comprising:
[0006] In response to the serial number retrieval request from the requesting end, a number segment is requested from the pre-configured serial number database according to the serial number retrieval request, and the requested number segment is stored in the main number segment cache area;
[0007] If the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area, the backup number segment cache area is started asynchronously.
[0008] If the serial number usage in the primary number segment cache area is determined to meet the switching conditions, then the backup number segment cache area will be switched to the primary number segment cache area.
[0009] An atomic increment operation is used to allocate a sequence number to the requesting client in the main number segment cache.
[0010] According to another aspect of this application, a serial number allocation device is provided, the device comprising:
[0011] The main number segment cache area startup module is used to respond to the serial number acquisition request from the requesting end, apply for a number segment from the pre-configured serial number database according to the serial number acquisition request, and store the acquired number segment into the main number segment cache area.
[0012] The backup number segment cache area startup module is used to asynchronously start the backup number segment cache area if the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area.
[0013] The switching module is used to switch the backup number segment cache to the main number segment cache if the serial number usage is determined to meet the switching conditions based on the serial number usage of the main number segment cache.
[0014] The serial number allocation module is used to allocate a serial number to the requesting client in the main number segment cache area using an atomic increment operation.
[0015] According to another aspect of this application, an electronic device is provided, the electronic device comprising:
[0016] One or more processors;
[0017] Memory, used to store one or more programs;
[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement any of the serial number allocation methods provided in the embodiments of this application.
[0019] According to another aspect of this application, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements any of the serial number allocation methods provided in the embodiments of this application.
[0020] According to another aspect of this application, a computer program product is provided, including a computer program that, when executed by a processor, implements any of the serial number allocation methods provided in the embodiments of this application.
[0021] This application responds to the requesting client's serial number retrieval request, requests a number segment from a pre-configured serial number database based on the serial number retrieval request, and stores the requested number segment in the main number segment cache area. If the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area, a backup number segment cache area is asynchronously started. If the serial number usage in the main number segment cache area meets the switching conditions based on the serial number usage of the main number segment cache area, the backup number segment cache area is switched to the main number segment cache area. An atomic increment operation is used to allocate a serial number to the requesting client in the main number segment cache area. The above solution reduces frequent access to the serial number database and improves system response speed through a caching mechanism; it improves the continuity and availability of serial number allocation by asynchronously preloading new number segments and switching the cache to allocate serial numbers to the requesting end; atomic increment operations ensure the accuracy of serial number allocation and avoid duplication or omission; through real-time monitoring and asynchronous operations, the serial number cache can be dynamically expanded according to actual needs, ensuring service continuity and stability; asynchronously starting the backup number segment cache can reduce latency when the cache is exhausted, improving user experience while efficiently managing serial number allocation in high-concurrency environments. Attached Figure Description
[0022] Figure 1 This is a flowchart of a serial number allocation method provided according to Embodiment 1 of this application;
[0023] Figure 2 This is a flowchart of a serial number allocation method provided according to Embodiment 2 of this application;
[0024] Figure 3 This is a schematic diagram of a serial number allocation device according to Embodiment 3 of this application;
[0025] Figure 4 This is a schematic diagram of the structure of an electronic device that implements the serial number allocation method of Embodiment 4 of this application. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0028] Furthermore, it should be noted that the collection, storage, use, processing, transmission, provision, and disclosure of data related to serial number acquisition requests in the technical solution of this application all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0029] Example 1
[0030] Figure 1 This is a flowchart of a serial number allocation method according to Embodiment 1 of this application. This embodiment is applicable to efficient serial number processing based on pre-allocation of number segments in the financial field. It can be executed by a serial number allocation device, which can be implemented in hardware and / or software and can be configured in a computer device, such as a server. Figure 1 As shown, the method includes:
[0031] S110. In response to the serial number acquisition request from the requesting end, apply for a number segment from the pre-configured serial number database according to the serial number acquisition request, and store the acquired number segment in the main number segment cache area.
[0032] The request for a serial number can originate from different services needing a serial number. The requesting service can include various internal bank services, such as account management, transaction processing, and loan approval services. The pre-configured serial number database is a pre-set database used to store and manage serial numbers, ensuring the uniqueness and continuity of each serial number. The main serial number segment cache stores the currently used serial number segments; when the requesting service needs a serial number, it will be allocated from this cache.
[0033] Optionally, there are at least two requesting ends. Correspondingly, based on the sequence number retrieval request, a number segment is requested from a pre-configured sequence number database, including: performing conflict verification on the number segments requested in the sequence number retrieval requests of the at least two requesting ends, and obtaining a conflict verification result; based on the conflict verification result, determining the duplicated number segments and the at least two requesting ends corresponding to the duplicated number segments; determining the currently allocable requesting ends and the pending requesting ends based on the priority of the sequence number retrieval requests of the at least two requesting ends corresponding to the duplicated number segments; for the currently allocable requesting ends, requesting a number segment from the pre-configured sequence number database based on the sequence number retrieval request of the currently allocable requesting ends; for the pending requesting ends, using an exponential backoff algorithm for intelligent retries, and rejecting the sequence number retrieval request of the pending requesting ends if the number of retries exceeds a preset number of retries.
[0034] The conflict verification process verifies sequence number retrieval requests from multiple requesting clients to check for duplicate number ranges and avoid conflicts. The priority of sequence number retrieval requests can be set based on the importance of the business, etc., and this embodiment does not impose specific limitations. The exponential backoff algorithm is a dynamically adjusted retry interval algorithm, where the retry interval increases exponentially with each retry. The preset number of retries can be set according to actual needs, and this embodiment does not impose specific limitations on this. When the number of retries exceeds the preset number, the system stops attempting retries and directly rejects the sequence number retrieval request. By gradually increasing the retry interval, the load on the server is reduced, and the probability of success is increased.
[0035] Specifically, conflict checking is performed on requests from at least two requesters to determine if duplicate number segments exist, thus avoiding duplicate allocation of sequence numbers. If conflict checking reveals duplicate number segments, it identifies which segments were requested repeatedly and the corresponding requesting clients. Then, based on request priority, it determines which requests can be processed immediately and which need to wait. For higher-priority requesting clients, number segments are immediately requested from the sequence number database to fulfill their requests; for lower-priority requesting clients or those requiring waiting, an exponential backoff algorithm is used for retries. If the request is unsuccessful after a preset number of retries, it is rejected to avoid resource waste and system overload.
[0036] S120. If the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area, the backup number segment cache area is started asynchronously.
[0037] The serial number consumption rate is used to characterize the usage of serial numbers in the current number segment cache, dynamically managing and optimizing the serial number allocation process to ensure system efficiency and stability. The serial number consumption rate can be calculated as the ratio of the number of allocated serial numbers to the total number of serial numbers. For example, if the current number segment cache has 100 serial numbers and 80 have been allocated, the consumption rate is 80%. A high consumption rate means that the serial numbers in the current number segment cache are about to be exhausted, while a low consumption rate indicates that there are still many serial numbers available for allocation. For example, when the serial number consumption rate reaches a preset prefetch threshold (e.g., 50%), a cache replacement operation can be triggered to ensure a continuous supply of serial numbers. The backup number segment cache is used to store pre-loaded serial number segments, ready to take over when the main number segment cache is exhausted. By monitoring and analyzing the serial number consumption rate, resource allocation can be dynamically adjusted to ensure a continuous supply of serial numbers, while also promptly detecting and handling abnormal situations.
[0038] S130. If the serial number usage in the primary number segment cache area is determined to meet the switching conditions, then the backup number segment cache area is switched to the primary number segment cache area.
[0039] The serial number usage in the primary number segment cache can include the serial number consumption rate, the number of allocated serial numbers, the number of remaining serial numbers, the request frequency, and the system load. When the serial number usage meets the switching conditions, the backup number segment cache is switched to the primary number segment cache. For example, the switch can be triggered when the serial number consumption rate in the primary number segment cache exceeds a preset threshold; it can also be triggered when the frequency of requesting serial numbers exceeds a preset threshold; or it can be triggered when the system load (such as CPU utilization, memory utilization, etc.) exceeds a preset threshold. The preset threshold can be set according to actual needs, and this embodiment does not specifically limit it.
[0040] Optionally, the step of switching the backup number segment cache to the main number segment cache if the serial number usage in the main number segment cache meets the switching conditions includes: determining the remaining number of serial numbers in the main number segment cache based on the serial number usage in the main number segment cache; determining that the serial number usage meets the switching conditions when the remaining number of serial numbers is less than a preset number threshold; and switching the backup number segment cache to the main number segment cache when the serial number usage meets the switching conditions.
[0041] Specifically, the system monitors the serial number usage in the primary number segment cache area, calculates the remaining number of serial numbers (the number of unallocated serial numbers in the primary number segment cache area), and compares this remaining number with a preset threshold. If the remaining number is less than the preset threshold, the switching condition is met, and the backup number segment cache area is switched to the primary number segment cache area to continue allocating serial numbers. This ensures the efficiency and reliability of serial number allocation when processing a large number of transactions and account numbers. The preset threshold can be set according to actual needs; this embodiment does not impose specific limitations on it.
[0042] S140. Using an atomic increment operation, a sequence number is allocated to the requesting end in the main number segment cache.
[0043] Atomic increment operations are a type of operation that maintains consistency in multithreaded or distributed environments. An atomic operation means that its execution will not be interrupted by other operations, thus guaranteeing the integrity and correctness of the operation. In a multithreaded environment, multiple threads may simultaneously request sequence number allocation. Atomic increment operations ensure that each allocated sequence number is unique, preventing duplicates or conflicts. Using atomic increment operations to allocate sequence numbers ensures that each allocated sequence number is unique and will not conflict with other operations.
[0044] This application responds to the requesting client's serial number retrieval request, requests a number segment from a pre-configured serial number database based on the serial number retrieval request, and stores the requested number segment in the main number segment cache area. If the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area, a backup number segment cache area is asynchronously started. If the serial number usage in the main number segment cache area meets the switching conditions based on the serial number usage of the main number segment cache area, the backup number segment cache area is switched to the main number segment cache area. An atomic increment operation is used to allocate a serial number to the requesting client in the main number segment cache area. The above solution reduces frequent access to the serial number database and improves system response speed through a caching mechanism; it improves the continuity and availability of serial number allocation by asynchronously preloading new number segments and switching the cache to allocate serial numbers to the requesting end; atomic increment operations ensure the accuracy of serial number allocation and avoid duplication or omission; through real-time monitoring and asynchronous operations, the serial number cache can be dynamically expanded according to actual needs, ensuring service continuity and stability; asynchronously starting the backup number segment cache can reduce latency when the cache is exhausted, improving user experience while efficiently managing serial number allocation in high-concurrency environments.
[0045] Example 2
[0046] Figure 2This is a flowchart of a serial number allocation method according to Embodiment 2 of this application. Based on the technical solutions of the above embodiments, this embodiment refines the statement "if the main number segment cache area meets the cache area replacement condition based on the serial number consumption rate of the main number segment cache area, then asynchronously start the backup number segment cache area" to "real-time monitoring of the serial number consumption rate of the main number segment cache area; if the serial number consumption rate is greater than a preset prefetch threshold, determining that the main number segment cache area meets the cache area replacement condition; if the main number segment cache area meets the cache area replacement condition, asynchronously starting the backup number segment cache area, applying for a new number segment from the pre-configured serial number database, and performing overlap verification on the new number segment to obtain a verification result; if the verification result is successful, storing the new number segment in the backup number segment cache area; if the verification result is unsuccessful, reapplying for a new number segment from the serial number database until the verification result is successful." It should be noted that for parts not detailed in this embodiment, please refer to the relevant descriptions in other embodiments. Figure 2 As shown, the method includes:
[0047] S210. In response to the serial number acquisition request from the requesting end, apply for a number segment from the pre-configured serial number database according to the serial number acquisition request, and store the acquired number segment in the main number segment cache area.
[0048] S220. Real-time monitoring of the serial number consumption rate of the main number segment cache area. If the serial number consumption rate is greater than the preset prefetch threshold, it is determined that the main number segment cache area meets the cache area replacement conditions.
[0049] Specifically, the serial number consumption rate of the main number segment cache is continuously monitored to ensure timely detection of changes in the consumption rate. When the serial number consumption rate of the main number segment cache exceeds a preset prefetch threshold, it is determined that the main number segment cache meets the replacement conditions and a cache switch is required. For example, each transaction requires a unique transaction number. By monitoring the serial number consumption rate of the main number segment cache in real time, the cache is switched promptly when the consumption rate exceeds the preset prefetch threshold to prevent transaction number exhaustion. When issuing instruments (such as checks, drafts, etc.), the serial number consumption rate of the main number segment cache is monitored in real time to ensure timely switching of the cache when the consumption rate exceeds the preset prefetch threshold to prevent instrument number exhaustion. The preset prefetch threshold can be set according to actual needs; for example, the preset prefetch threshold can be 50%, but this embodiment does not specifically limit it. Through a database prefetching mechanism, request blocking when a number segment is exhausted is eliminated. When the current number segment in memory is consumed to 50% (customizable), a new number segment is asynchronously preloaded to ensure continuous availability of serial number allocation.
[0050] S230. If the main number segment cache area meets the cache area replacement conditions, the backup number segment cache area is started asynchronously, a new number segment is applied for from the pre-configured serial number database, and the new number segment is subjected to overlap verification to obtain the verification result.
[0051] The overlap check is used to check whether the newly applied number segment overlaps with the already allocated number segment, ensuring the uniqueness of the new number segment. The check result can include failure and success.
[0052] Optionally, an overlap check is performed on the new number segment to obtain a check result, including: obtaining the start and end serial numbers of the new number segment; querying the currently allocated serial number range; comparing the new number segment with the allocated serial number range to determine whether there is overlap; if the new number segment overlaps with the allocated serial number range, the check result is determined to be a failure; if the new number segment does not overlap with the allocated serial number range, the check result is determined to be a pass.
[0053] The new number segment's start and end sequence numbers are the initial and final sequence numbers of the newly applied number segment, used to identify the range of that segment. The allocated sequence number range is the currently allocated sequence number range, stored in the sequence number database to record the allocated number segments. The new number segment is compared with the allocated sequence number ranges to determine if there is overlap. If overlap exists, the verification result is determined to be a failure; if no overlap exists, the verification result is determined to be a success, ensuring the uniqueness of the new number segment.
[0054] S240. If the verification result is successful, the new number segment is stored in the backup number segment cache area.
[0055] S250. If the verification result is a failure, a new number segment is applied for again from the serial number database until the verification result is a success.
[0056] Specifically, in the event of a verification failure, a new number segment is requested from the sequence number database, and an overlap verification is performed until a new number segment that does not overlap with the already allocated number segment is found, at which point the verification result is considered successful. Each time a verification fails, detailed information about the failure is recorded, including the range of the new number segment, the reason for the failure, and the timestamp. This detailed information is stored in a pre-configured log database for subsequent analysis and auditing. Combined with real-time monitoring logs, this enables visualized tracking of the number segment lifecycle, second-level alerts for abnormal allocation patterns, and improved resource utilization.
[0057] S260. If the serial number usage in the primary number segment cache area is determined to meet the switching conditions, then the backup number segment cache area is switched to the primary number segment cache area.
[0058] S270. Using an atomic increment operation, a sequence number is allocated to the requesting end in the main number segment cache.
[0059] In one optional implementation, the system further includes notifying the caller to execute a custom degradation strategy when a system-level anomaly is detected; wherein the system-level anomaly includes configuration anomaly, database consistency anomaly, resource exhaustion anomaly, and service availability anomaly; the custom degradation strategy includes using an alternative sequence number generation algorithm or service, limiting the rate of business processing, and returning error information.
[0060] System-level anomalies indicate a serious problem or an unrecoverable abnormal state. Upper-layer applications should implement circuit breaker mechanisms (e.g., application termination). These anomalies require intervention from system administrators or developers to conduct detailed log analysis and system checks to determine the root cause and implement appropriate remedial measures. Specifically, configuration anomalies are caused by internal system configuration errors, such as incorrect or missing parameters in configuration files, leading to system malfunction. Database consistency anomalies involve database state issues, such as illegal values in configuration tables or unexplained consistency problems in the database. These issues typically require database administrator intervention. Resource exhaustion anomalies occur when all pre-allocated sequence numbers are exhausted, and the system configuration does not allow for sequence number recycling, indicating that a critical system resource has been depleted. Service availability anomalies indicate that a service or component has failed to initialize or cannot complete initialization for some reason, thus failing to provide service. This could be due to dependent service failures, network problems, or other errors during startup.
[0061] The caller can be the client that initiates the serial number retrieval request. A custom degradation strategy is a backup strategy that the caller can execute when the request cannot be fulfilled, ensuring that some functions remain available. Using a backup serial number generation algorithm or service means that the system predefines one or more backup serial number generation mechanisms. When the primary serial number generation service becomes unavailable due to a failure, it automatically switches to these backup mechanisms to continue generating serial numbers. For example, the backup serial number generation algorithm could be retrieving serial numbers from another database, or generating serial numbers using an algorithm based on timestamps and machine identifiers; the backup service could be another independent serial number generation service instance, which can be deployed on different servers or data centers to improve availability and fault tolerance, reducing business interruptions caused by primary service failures. A circuit breaker mechanism is established, allowing the caller to customize a degradation strategy when serial number generation is abnormal, ensuring that serial number generation in core business processes is not affected.
[0062] In one optional implementation, the method further includes employing an exponential backoff algorithm for intelligent retries when a retryable exception is detected, and rejecting the sequence number acquisition request from the requesting end if the number of retries exceeds a preset number of retries; wherein the retryable exception includes database operation exception, retry policy exception, operation timeout exception, and retryable interruption exception.
[0063] Retryable exceptions typically indicate exceptions caused by unexpected or unpredictable temporary unavailability of external systems, which are expected to recover on their own. Specifically, database operation exceptions usually occur when database operations (such as queries, updates, and inserts) fail, possibly due to network problems, temporary database service unavailability, or timeouts. Retry policy exceptions are thrown when the internal retries reach or exceed the limit set by the configuration class. This indicates that multiple attempts have been made without success, and the upper-layer application needs to decide whether to continue retrying. Operation timeout exceptions occur when a system operation fails to complete within a predetermined time; for example, a request does not receive a response within a specified timeout period. Retryable interruption exceptions occur when a thread is interrupted while performing a retry operation, but this interruption is recoverable, and retrying can continue after the interruption is handled. Exception handling and retry strategies can improve system robustness and user experience.
[0064] This application responds to the requesting client's serial number retrieval request, requests a number segment from a pre-configured serial number database based on the serial number retrieval request, and stores the requested number segment in the main number segment cache area. If the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area, a backup number segment cache area is asynchronously started. If the serial number usage in the main number segment cache area meets the switching conditions based on the serial number usage of the main number segment cache area, the backup number segment cache area is switched to the main number segment cache area. An atomic increment operation is used to allocate a serial number to the requesting client in the main number segment cache area. The above solution reduces frequent access to the serial number database and improves system response speed through a caching mechanism; it improves the continuity and availability of serial number allocation by asynchronously preloading new number segments and switching the cache to allocate serial numbers to the requesting end; atomic increment operations ensure the accuracy of serial number allocation and avoid duplication or omission; through real-time monitoring and asynchronous operations, the serial number cache can be dynamically expanded according to actual needs, ensuring service continuity and stability; asynchronously starting the backup number segment cache can reduce latency when the cache is exhausted, improving user experience while efficiently managing serial number allocation in high-concurrency environments.
[0065] Example 3
[0066] Figure 3This is a schematic diagram of a serial number allocation device according to Embodiment 3 of this application. This embodiment is applicable to efficient serial number processing based on pre-allocation of number segments in the financial field. The serial number allocation device can be implemented in hardware and / or software and can be configured in computer equipment, such as a server. Figure 3 As shown, the device includes:
[0067] The main number segment cache area startup module 310 is used to respond to the serial number acquisition request from the requesting end, apply for a number segment from the pre-configured serial number database according to the serial number acquisition request, and store the acquired number segment into the main number segment cache area.
[0068] The backup number segment cache area startup module 320 is used to asynchronously start the backup number segment cache area if the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area.
[0069] The switching module 330 is used to switch the backup number segment cache to the main number segment cache if the serial number usage is determined to meet the switching conditions based on the serial number usage of the main number segment cache.
[0070] The serial number allocation module 340 is used to allocate a serial number to the requesting end in the main number segment cache area using an atomic increment operation.
[0071] Optionally, the backup number segment cache startup module 320 includes:
[0072] The buffer replacement condition satisfaction unit is used to monitor the serial number consumption rate of the main number segment buffer in real time, and determine that the main number segment buffer meets the buffer replacement condition when the serial number consumption rate is greater than a preset prefetch threshold.
[0073] The verification result determination unit is used to asynchronously start the backup number segment cache area when the main number segment cache area meets the cache area replacement conditions, apply for a new number segment from the pre-configured serial number database, and perform overlap verification on the new number segment to obtain the verification result.
[0074] The new number segment storage unit is used to store the new number segment into the spare number segment cache area if the verification result is successful.
[0075] The new number segment application unit is used to reapply for a new number segment from the serial number database if the verification result is unsuccessful, until the verification result is successful.
[0076] Optionally, the verification result determination unit includes:
[0077] The serial number acquisition subunit is used to acquire the start serial number and end serial number of the new number segment;
[0078] The serial number range query sub-unit is used to query the currently assigned serial number range;
[0079] The overlap determination subunit is used to compare the new number segment with the already allocated sequence number range to determine whether there is overlap.
[0080] The failure verification result determination subunit is used to determine the verification result as a failure if the new number segment overlaps with the allocated sequence number range.
[0081] The sub-unit is determined by the verification result, which is used to determine that the verification result is passed if the new number segment does not overlap with the allocated sequence number range.
[0082] Optionally, the switching module 330 includes:
[0083] The remaining serial number quantity determination unit is used to determine the remaining serial number quantity in the main number segment cache based on the serial number usage in the main number segment cache.
[0084] The switching condition fulfillment unit is used to determine that the serial number usage meets the switching condition when the number of remaining serial numbers is less than a preset number threshold.
[0085] The switching unit is used to switch the backup number segment cache area to the main number segment cache area when the serial number usage meets the switching conditions.
[0086] Optionally, there are at least two requesting clients, and correspondingly, the main number segment cache startup module 310 includes:
[0087] The conflict verification result determination unit is used to perform conflict verification on the number segments requested in the sequence number acquisition requests of at least two requesting parties, and obtain the conflict verification result.
[0088] The conflict requester determination unit is used to determine the number segment of the duplicate application and at least two requesters corresponding to the number segment of the duplicate application based on the conflict verification result.
[0089] The request end determination unit is used to obtain the priority of the request based on the sequence numbers of at least two request ends corresponding to the number segment of the duplicate application, and to determine the currently allocable request ends and the request ends to be processed.
[0090] The conflict handling unit is used to, for the currently allocable requesting end, obtain a request based on the sequence number of the currently allocable requesting end and apply for a number segment from a pre-configured sequence number database; for the pending requesting end, it uses an exponential backoff algorithm for intelligent retry, and rejects the sequence number acquisition request of the pending requesting end if the number of retries exceeds the preset number of retries.
[0091] Optionally, the device further includes:
[0092] The system-level exception handling module is used to notify the caller to execute a custom degradation strategy when a system-level exception is detected. The system-level exceptions include configuration exceptions, database consistency exceptions, resource exhaustion exceptions, and service availability exceptions. The custom degradation strategies include using an alternative sequence number generation algorithm or service, limiting the rate of business processing, and returning error information.
[0093] Optionally, the device further includes:
[0094] The retryable exception handling module is used to perform intelligent retries using an exponential backoff algorithm when a retryable exception is detected, and to reject the sequence number acquisition request from the requesting end if the number of retries exceeds the preset number of retries; wherein, the retryable exceptions include database operation exceptions, retry policy exceptions, operation timeout exceptions, and retryable interruption exceptions.
[0095] This application responds to the requesting client's serial number retrieval request, requests a number segment from a pre-configured serial number database based on the serial number retrieval request, and stores the requested number segment in the main number segment cache area. If the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area, a backup number segment cache area is asynchronously started. If the serial number usage in the main number segment cache area meets the switching conditions based on the serial number usage of the main number segment cache area, the backup number segment cache area is switched to the main number segment cache area. An atomic increment operation is used to allocate a serial number to the requesting client in the main number segment cache area. The above solution reduces frequent access to the serial number database and improves system response speed through a caching mechanism; it improves the continuity and availability of serial number allocation by asynchronously preloading new number segments and switching the cache to allocate serial numbers to the requesting end; atomic increment operations ensure the accuracy of serial number allocation and avoid duplication or omission; through real-time monitoring and asynchronous operations, the serial number cache can be dynamically expanded according to actual needs, ensuring service continuity and stability; asynchronously starting the backup number segment cache can reduce latency when the cache is exhausted, improving user experience while efficiently managing serial number allocation in high-concurrency environments.
[0096] The serial number allocation device provided in this application embodiment can execute the serial number allocation method provided in any embodiment of this application, and has the corresponding functional modules and beneficial effects for executing each serial number allocation method.
[0097] According to embodiments of this application, this application also provides an electronic device, a readable storage medium, and a computer program product.
[0098] Example 4
[0099] Figure 4 This is a schematic diagram of the structure of an electronic device 410 implementing the serial number allocation method of the embodiments of this application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.
[0100] like Figure 4 As shown, the electronic device 410 includes at least one processor 411 and a memory, such as a read-only memory 412 or a random access memory 413, communicatively connected to the at least one processor 411. The memory stores computer programs executable by the at least one processor. The processor 411 can perform various appropriate actions and processes based on the computer program stored in the read-only memory 412 or loaded from storage unit 418 into the random access memory 413. The random access memory 413 can also store various programs and data required for the operation of the electronic device 410. The processor 411, read-only memory 412, and random access memory 413 are interconnected via a bus 414. An input / output interface 415 is also connected to the bus 414.
[0101] Multiple components in electronic device 410 are connected to input / output interface 415, including: input unit 416, such as keyboard, mouse, etc.; output unit 417, such as various types of monitors, speakers, etc.; storage unit 418, such as disk, optical disk, etc.; and communication unit 419, such as network card, modem, wireless transceiver, etc. Communication unit 419 allows electronic device 410 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0102] Processor 411 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 411 include, but are not limited to, central processing units, graphics processing units, various special-purpose artificial intelligence computing chips, various processors running machine learning model algorithms, digital signal processors, and any suitable processor, controller, microcontroller, etc. Processor 411 performs the various methods and processes described above, such as the serial number allocation method.
[0103] In some embodiments, the serial number allocation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 418. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 410 via read-only memory 412 and / or communication unit 419. When the computer program is loaded into random access memory 413 and executed by processor 411, one or more steps of the serial number allocation method described above may be performed. Alternatively, in other embodiments, processor 411 may be configured as the serial number allocation method by any other suitable means (e.g., by means of firmware).
[0104] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays, application-specific integrated circuits (ASICs), application-specific standard products (ASICs), systems-on-a-chip (SoCs), payload programmable logic devices, computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0105] Computer programs used to implement the methods of this application may be written in any combination of one or more programming languages. These computer programs may be provided to the processor of a general-purpose computer, special-purpose computer, or other programmable serial number allocation device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0106] In the context of this application, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory, optical fibers, portable compact disk read-only memory, optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0107] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a cathode ray tube or liquid crystal display monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0108] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0109] A computing system can include requesters and servers. Requesters and servers are generally geographically separated and typically interact via communication networks. The relationship between a requester and a server is established by computer programs running on the respective computers and having a requester-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product within the cloud computing service system to address the shortcomings of traditional physical hosts and virtual private servers, such as high management difficulty and weak business scalability.
[0110] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this application can be achieved, and this is not limited herein.
[0111] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A serial number assignment method characterized by comprising: include: In response to the serial number retrieval request from the requesting end, a number segment is requested from the pre-configured serial number database according to the serial number retrieval request, and the requested number segment is stored in the main number segment cache area; If the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area, the backup number segment cache area is started asynchronously. If the serial number usage in the primary number segment cache area is determined to meet the switching conditions, then the backup number segment cache area will be switched to the primary number segment cache area. An atomic increment operation is used to allocate a sequence number to the requesting client in the main number segment cache.
2. The method of claim 1, wherein, If the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area, the asynchronous startup of the backup number segment cache area includes: The serial number consumption rate of the main number segment cache is monitored in real time. If the serial number consumption rate is greater than the preset prefetch threshold, it is determined that the main number segment cache meets the cache replacement condition. If the main number segment cache meets the cache replacement conditions, the backup number segment cache is started asynchronously, a new number segment is requested from the pre-configured serial number database, and the new number segment is subjected to overlap verification to obtain the verification result. If the verification result is successful, the new number segment will be stored in the backup number segment cache area; If the verification result is unsuccessful, a new number segment will be requested from the serial number database again until the verification result is successful.
3. The method of claim 2, wherein, The new number segment is subjected to overlap verification to obtain the verification result, including: Obtain the start and end sequence numbers of the new number segment; Query the range of currently assigned sequence numbers; Compare the new number segment with the already allocated sequence number range to determine if there is any overlap; If the new number segment overlaps with the already allocated sequence number range, the verification result is determined to be a failure; If the new number segment does not overlap with the already allocated sequence number range, the verification result is determined to be passed.
4. The method of claim 1, wherein, If the serial number usage in the primary number segment cache area is determined to meet the switching conditions based on the serial number usage in the primary number segment cache area, then the backup number segment cache area is switched to the primary number segment cache area, including: Based on the serial number usage in the main number segment cache area, determine the remaining number of serial numbers in the main number segment cache area; When the number of remaining serial numbers is less than a preset threshold, it is determined that the serial number usage meets the switching conditions; If the usage of the serial number meets the switching conditions, the backup number segment cache area will be switched to the main number segment cache area.
5. The method of claim 1, wherein, The requesting end is at least two, and accordingly, based on the sequence number, a request is made to apply for a number range from a pre-configured sequence number database, including: Perform conflict checking on the number ranges requested in the sequence number retrieval requests from at least two requesting parties, and obtain the conflict checking results; Based on the conflict verification results, the number segment with duplicate applications and at least two requesting ends corresponding to the number segment with duplicate applications are determined. The priority of the request is obtained based on the sequence numbers of at least two requesters corresponding to the duplicate application number segment, and the currently allocable requesters and pending requesters are determined. For the currently allocable request terminal, obtain the request according to the sequence number of the currently allocable request terminal, and apply for a number segment from the pre-configured sequence number database; For the pending request, an exponential backoff algorithm is used for intelligent retries, and if the number of retries exceeds the preset number of retries, the request to obtain the sequence number from the pending request is rejected.
6. The method according to any one of claims 1-5, characterized in that, The method further includes: Upon detecting a system-level anomaly, the caller is notified to execute a custom degradation strategy. The system-level anomaly includes configuration anomalies, database consistency anomalies, resource exhaustion anomalies, and service availability anomalies. The custom degradation strategy includes using an alternative sequence number generation algorithm or service, limiting the rate of business processing, and returning error information.
7. The method according to any one of claims 1-5, characterized in that, The method further includes: In the event of a retryable exception, an exponential backoff algorithm is used for intelligent retries, and if the number of retries exceeds the preset number of retries, the request for obtaining the sequence number from the requesting end is rejected; wherein, the retryable exception includes database operation exception, retry policy exception, operation timeout exception, and retryable interruption exception.
8. A serial number allocation device, characterized in that, include: The main number segment cache area startup module is used to respond to the serial number acquisition request from the requesting end, apply for a number segment from the pre-configured serial number database according to the serial number acquisition request, and store the acquired number segment into the main number segment cache area. The backup number segment cache area startup module is used to asynchronously start the backup number segment cache area if the main number segment cache area meets the cache area replacement conditions based on the serial number consumption rate of the main number segment cache area. The switching module is used to switch the backup number segment cache to the main number segment cache if the serial number usage is determined to meet the switching conditions based on the serial number usage of the main number segment cache. The serial number allocation module is used to allocate a serial number to the requesting client in the main number segment cache area using an atomic increment operation.
9. An electronic device, characterized in that, include: One or more processors; Memory, used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the serial number allocation method as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the serial number allocation method as described in any one of claims 1-7.