Identifier generation method, device, storage medium and system

By adopting a dual cache number segment mechanism in the identifier generation system and alternately using the first segment cache area and the second segment cache area to obtain the identifier, the problems of wasting resources and extending response time in the existing technology are solved. The timeliness of identifier acquisition and efficient use of resources are achieved.

CN114444440BActive Publication Date: 2024-10-29AGRICULTURAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210113902.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-30
Publication Date
2024-10-29
Estimated Expiration
2042-01-30

AI Technical Summary

Technical Problem

In the existing technology, when identifiers are generated in a distributed system, the client restarts abnormally, resulting in a waste of number segment resources, and network jitter or slow system query results in slow response time.

Method used

The dual cache number segment mechanism is adopted to obtain identifiers alternately through the first segment cache area and the second segment cache area to avoid resource waste and prolonged response time, and ensure the timeliness of identifier acquisition.

Benefits of technology

It effectively avoids machine downtime and resource waste caused by the surge in business volume, improves the timeliness of identifier acquisition, and avoids request thread blocking.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114444440B_ABST
    Figure CN114444440B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses an identifier generation method, device, storage medium and system, the method comprising: in response to an identifier acquisition event being triggered, acquiring a target identifier from a segment stored in a current segment cache based on an identifier configuration parameter; when the target identifier is greater than a preset threshold in the segment stored in the current segment cache, determining the target segment and storing the target segment in another segment cache; when the identifier in the segment stored in the current segment cache is exhausted, using another segment cache as the current segment cache, and returning to execute the acquisition of the target identifier from the segment stored in the current segment cache based on the identifier configuration parameter. The technical solution provided by the embodiment of the present invention can obtain an identifier from a system database without blocking through a double-buffered segment, which can effectively avoid the problems of machine downtime and resource waste caused by a surge in business volume.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of data processing technology, and in particular, to an identifier generation method, device, storage medium and system. Background Art

[0002] In today's big data era, a large amount of data and messages are generated every day. In order to better distinguish different data and messages, it is often necessary to uniquely identify the data and messages. Among them, the most common identification method is to add a unique identifier to the data and messages. The identifier can be used as the main element of the information system to analyze user behavior, locate system failures, and count system performance.

[0003] In the related art, the globally unique identifier is generated by the number generator component using the number segment mode to ensure its uniqueness in the distributed system architecture. Specifically, each service instance first obtains identifiers in batches from the system and caches them locally. When a business application requests an identifier, it will be automatically incremented and returned locally until the number segment is exhausted and the next number segment is obtained from the system again.

[0004] However, this solution has great limitations. If an exception suddenly occurs on the client, but the number segment has not been used up, when the client restarts, it will access the system again to obtain a new number segment, resulting in a large waste of number segment resources. In addition, this solution is to synchronously obtain the next number segment after the number segment is exhausted. If the network jitters or the system has a slow query at this time, the response time of the entire system will be slowed down. Summary of the invention

[0005] The embodiments of the present invention provide an identifier generation method, device, storage medium and system, which can obtain identifiers from the system without blocking through double-buffered number segments, and can effectively avoid machine downtime and resource waste caused by a surge in business volume.

[0006] In a first aspect, an embodiment of the present invention provides an identifier generation method, which is applied to an identifier generation system, wherein the identifier generation system includes a first number segment cache area and a second number segment cache area, and the method includes:

[0007] In response to the identifier acquisition event being triggered, acquiring a target identifier from a number segment stored in a current number segment cache based on an identifier configuration parameter; wherein the current number segment cache is the first number segment cache or the second number segment cache;

[0008] When the target identifier is greater than a preset threshold value in the number segment stored in the current number segment cache, determine the target number segment, and store the target number segment in another number segment cache; wherein the another number segment cache is a number segment cache of the first number segment cache and the second number segment cache except the current number segment cache;

[0009] When the identifiers in the number segment stored in the current number segment cache are exhausted, the other number segment cache area is used as the current number segment cache area, and the process returns to execute obtaining the target identifier from the number segment stored in the current number segment cache area based on the identifier configuration parameter.

[0010] In a second aspect, an embodiment of the present invention further provides an identifier generation device, which is applied to an identifier generation system, wherein the identifier generation system includes a first number segment cache area and a second number segment cache area, and the device includes:

[0011] A target identifier acquisition module, configured to acquire a target identifier from a number segment stored in a current number segment cache area based on an identifier configuration parameter in response to an identifier acquisition event being triggered; wherein the current number segment cache area is the first number segment cache area or the second number segment cache area;

[0012] a target number segment determination module, configured to determine a target number segment when the target identifier is greater than a preset threshold value in the number segment stored in the current number segment cache, and store the target number segment in another number segment cache; wherein the another number segment cache is a number segment cache of the first number segment cache and the second number segment cache except the current number segment cache;

[0013] The target identifier cyclic acquisition module is used to use the other segment cache area as the current segment cache area when the identifiers in the segment stored in the current segment cache area are exhausted, and return to execute the acquisition of the target identifier from the segment stored in the current segment cache area based on the identifier configuration parameters.

[0014] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements an identifier generation method as provided in an embodiment of the present invention.

[0015] In a fourth aspect, an embodiment of the present invention provides an identifier generation system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, an identifier generation method as provided in an embodiment of the present invention is implemented.

[0016] An embodiment of the present invention provides an identifier generation scheme, in response to an identifier acquisition event being triggered, obtaining a target identifier from a number segment stored in a current number segment cache based on an identifier configuration parameter; wherein the current number segment cache is a first number segment cache or a second number segment cache; when the target identifier is greater than a preset threshold in the number segment stored in the current number segment cache, determining the target number segment and storing the target number segment in another number segment cache; wherein the other number segment cache is a number segment cache in the first number segment cache and the second number segment cache except the current number segment cache; when the identifier in the number segment stored in the current number segment cache is exhausted, the other number segment cache is used as the current number segment cache, and returning to execute the acquisition of the target identifier from the number segment stored in the current number segment cache based on the identifier configuration parameter. The technical solution provided by the embodiment of the present invention can obtain identifiers from the system database without blocking by double-caching number segments, which not only effectively avoids the problem of request thread blocking when obtaining number segments from the database and updating number segments, thereby effectively ensuring the timeliness of identifier acquisition, but also can effectively avoid machine downtime and resource waste caused by a surge in business volume. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 is a flow chart of an identifier generation method provided by an embodiment of the present invention;

[0018] Figure 2 is a schematic diagram of a number segment buffer area provided by an embodiment of the present invention;

[0019] Figure 3 is a flow chart of an identifier generation method provided by another embodiment of the present invention;

[0020] Figure 4 is a flowchart of a preferred identifier generation method provided by another embodiment of the present invention;

[0021] Figure 5 is a structural diagram of an identifier generation system provided by another embodiment of the present invention;

[0022] Figure 6 is a structural schematic diagram of an identifier generating device provided by another embodiment of the present invention;

[0023] Figure 7 It is a structural diagram of an identifier generation system provided by another embodiment of the present invention. DETAILED DESCRIPTION

[0024] Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.

[0025] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.

[0026] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0027] It should be noted that the concepts such as "first" and "second" mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0028] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0029] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only used for illustrative purposes, and are not used to limit the scope of these messages or information.

[0030] Figure 1 A flowchart of an identifier generation method provided by an embodiment of the present invention. The embodiment of the present invention is applicable to the case of obtaining a target identifier by using a double-buffered number segment. The method is applied to an identifier generation system, wherein the identifier generation system includes a first number segment buffer area and a second number segment buffer area. The method can be executed by an identifier generation device, which can be composed of hardware and / or software and can generally be integrated in the identifier generation system. Figure 1 As shown, the method specifically comprises the following steps:

[0031] Step 110, in response to the identifier acquisition event being triggered, acquiring a target identifier from a number segment stored in a current number segment cache based on an identifier configuration parameter; wherein the current number segment cache is a first number segment cache or a second number segment cache.

[0032] Among them, the identifier may refer to an identifier of data or a message, which can be used to uniquely identify the data or the message. Exemplarily, the identifier may be an ID number. The identifier acquisition event may refer to a task event for indicating the acquisition of the identifier. When the system detects an instruction for obtaining the identifier, the identifier acquisition event may be triggered to instruct the system to obtain the identifier from the database. The identifier configuration parameter may refer to a parameter for configuring the identifier, for example, the identifier configuration parameter may include a modulus value and a remainder, etc. The number segment may refer to an interval segment containing multiple identifiers. Exemplarily, if the identifier is set to an ID number, 1-1000 in the ID number may be used as a number segment, and 1001-2000 may be used as another number segment. The number segment cache may refer to an area in the system for pre-storing the number segment. The first number segment cache and the second number segment cache are only used to illustrate two different number segment caches in the system, and do not distinguish between the order of precedence. The current number segment cache may be understood as the cache where the current number segment is located, wherein the current number segment cache is the first number segment cache or the second number segment cache.

[0033] In an embodiment of the present invention, when an identifier acquisition event is triggered, the target identifier can be obtained from the number segment stored in the current number segment cache in different ways according to the identifier configuration parameters. Specifically, the target identifier can be directly obtained in an incrementing manner by adding one, or the target identifier can be obtained by configuring the modulus value and the remainder. Exemplarily, if the current number segment is 1-10000, that is, the starting value is 1 and the maximum value is 10000, when the modulus value is 2 and the remainder is 0, the target identifiers obtained are 2, 4, 6, ..., 9998, 10000 respectively; when the modulus value is 2 and the remainder is 1, the target identifiers obtained are 1, 3, 5, ..., 9997, 9999 respectively.

[0034] In an embodiment of the present invention, conversion between identifiers of different formats can be supported. For example, it can support the conversion of numerical values ​​into hexadecimal strings, and it can also support the conversion of strings into hexadecimal values. Specifically, the conversion between positive integer values ​​and strings within 2 to 62 hexadecimal can be achieved according to actual needs. For example, if the obtained identifier is an integer value 1234567890, after converting it to hexadecimal, the string KF12OI can be obtained, and the original 10-bit value is converted into a 6-bit string.

[0035] The advantage of this setting is that it can support the use of identifiers in multiple formats through simple data compression and encoding mechanisms, and can improve information security, thereby effectively avoiding information leakage and crawling.

[0036] Step 120, when the target identifier is greater than a preset threshold in the number segment stored in the current number segment cache, determine the target number segment and store the target number segment in another number segment cache; wherein the other number segment cache is a number segment cache in the first number segment cache and the second number segment cache except the current number segment cache.

[0037] Among them, the preset threshold value may refer to a low water level value in a preset number segment, which may be used to indicate that the number segment stored in the current number segment cache is about to be exhausted. Specifically, the preset threshold value may be set to a fixed value in the number segment stored in the current number segment cache, in which case the preset threshold value remains unchanged, or the preset threshold value may be set as a percentage, in which case the preset threshold value may change according to the number segment stored in the current number segment cache. Exemplarily, the preset threshold value may be set to 90% of the maximum value of the number segment stored in the current number segment cache. Assuming that the current number segment is 1-1000, the preset threshold value is 1000×90%=900; assuming that the current number segment is 1-900, the preset threshold value is 900×90%=810.

[0038] In the embodiment of the present invention, another number segment cache area may refer to a number segment cache area other than the current number segment cache area in the first number segment cache area and the second number segment cache area. It should be noted that the current number segment cache area and another number segment cache area are relative, and only involve two cache areas in the system, and the current number segment cache area and another number segment cache area are not fixed, but are alternately changed according to the cache area position where the current number segment is located. Figure 2 It is a schematic diagram of a number segment cache area provided by an embodiment of the present invention. Therein, two number segment cache areas A and B are included, and the number segment in A is 1-1000, and the number segment in B is 1001-2000. Specifically, if the current number segment is in A, then A is the current number segment cache area, and B is another number segment cache area at this time; if the current number segment is in B, then B is the current number segment cache area, and A is another number segment cache area at this time. Therefore, both A and B can be used as the current number segment cache area or another number segment cache area, and one of them is used as the current number segment cache area, and the other is used as another number segment cache area.

[0039] In an embodiment of the present invention, the obtained target identifier can be compared with the preset threshold value in the number segment stored in the current number segment cache area. When the target identifier is greater than the preset threshold value, it indicates that the number segment stored in the current number segment cache area is about to be exhausted. At this time, the target number segment is determined and stored in another number segment cache area. Exemplarily, assuming that the current number segment is 1-1000 and the preset threshold value is 900, when the obtained target identifier is greater than 900, the target number segment is determined and stored in another number segment cache area. It should be noted that the target number segment and the number segment stored in the current number segment cache area can be continuous or discontinuous, and the length of the target number segment and the length of the number segment stored in the current number segment cache area can be the same or different, and no limitation is made here.

[0040] Step 130, when the identifiers in the number segment stored in the current number segment cache are exhausted, the other number segment cache area is used as the current number segment cache area, and the process returns to execute obtaining the target identifier from the number segment stored in the current number segment cache area based on the identifier configuration parameters.

[0041] In an embodiment of the present invention, when the last identifier that can be obtained is obtained from the number segment stored in the current number segment cache, it can be considered that the identifiers in the number segment stored in the current number segment cache are exhausted. It should be noted that the exhaustion of identifiers does not mean that the identifier of the end position of the number segment stored in the current number segment cache can be obtained, that is, the last identifier that can be obtained is not necessarily the identifier of the end position of the number segment stored in the current number segment cache, but may also be an identifier at other positions before the end position. Exemplarily, assuming that the current number segment is 1-10000, the identifiers obtained are 1, 3, 5, ..., 9997, 9999 respectively. At this time, the end value 10000 cannot be obtained. Therefore, when 9999 is obtained, it means that the identifiers in the number segment stored in the current number segment cache are exhausted.

[0042] In the embodiment of the present invention, when the target identifier is greater than the preset threshold value in the number segment stored in the current number segment buffer, if the target number segment is not updated, the asynchronous thread in the asynchronous thread pool can be used to update the target number segment. If the identifiers in the number segment stored in the current number segment cache are exhausted, that is, after all the current number segments have been sent down, another number segment cache can be used as the current number segment cache, that is, the current number segment is switched to the target number segment, and the identifiers are sent back and forth in a cycle.

[0043] An embodiment of the present invention provides an identifier generation method, in response to an identifier acquisition event being triggered, obtaining a target identifier from a number segment stored in a current number segment cache based on an identifier configuration parameter; wherein the current number segment cache is a first number segment cache or a second number segment cache; when the target identifier is greater than a preset threshold in the number segment stored in the current number segment cache, determining the target number segment and storing the target number segment in another number segment cache; wherein the other number segment cache is a number segment cache in the first number segment cache and the second number segment cache except the current number segment cache; when the identifier in the number segment stored in the current number segment cache is exhausted, the other number segment cache is used as the current number segment cache, and returning to execute the acquisition of the target identifier from the number segment stored in the current number segment cache based on the identifier configuration parameter. The technical solution provided by the embodiment of the present invention can obtain identifiers from the system database without blocking through double-caching number segments, which not only effectively avoids the problem of request thread blocking when obtaining number segments from the database and updating number segments, thereby effectively ensuring the timeliness of identifier acquisition, but also can effectively avoid machine downtime and resource waste caused by a surge in business volume.

[0044] In some embodiments, when the target identifier is greater than a preset threshold in the number segment stored in the current number segment cache, the target number segment is determined, including: when the target identifier is greater than a preset threshold in the number segment stored in the current number segment cache, the target number segment is determined based on the number segment stored in the current number segment cache; the difference between the starting value of the target number segment and the ending value of the number segment stored in the current number segment cache is 1.

[0045] Among them, the starting value and the ending value may refer to the identifiers corresponding to the starting position and the ending position in the number segment, respectively. In an embodiment of the present invention, when the target identifier is greater than the preset threshold value in the number segment stored in the current number segment cache, the target number segment can be determined according to the number segment stored in the current number segment cache. Among them, the difference between the starting value of the target number segment and the ending value of the number segment stored in the current number segment cache is 1, that is, the ending value of the number segment stored in the current number segment cache plus 1 is the starting value of the target number segment. It can be understood that the difference between the starting value of the target number segment and the ending value of the number segment stored in the current number segment cache is 1, indicating that the target number segment and the number segment stored in the current number segment cache are continuous. Exemplarily, assuming that the number segment stored in the current number segment cache is 1-1000, that is, the initial value of the number segment stored in the current number segment cache is 1 and the ending value is 1000, then the initial value of the target number segment is 1000+1=1001.

[0046] The advantage of such a setting is that it can ensure that the target number segment is continuous with the number segment stored in the current number segment buffer, thus avoiding resource waste of the identifier in the number segment.

[0047] Optionally, determining the target number segment based on the number segment stored in the current number segment cache includes: determining the step size and end value of the number segment stored in the current number segment cache; determining the target number segment based on the step size and end value of the number segment stored in the current number segment cache.

[0048] In an embodiment of the present invention, when the number segment stored in the current number segment buffer is known, the starting value, step size and end value of the number segment can be determined. Among them, the step size can be expressed as the difference between the end value and the start value, that is, step size = end value - start value. Then, the end value of the number segment stored in the current number segment buffer plus 1 is the starting value of the target number segment. Then, the target number segment can be determined based on the starting value and step size of the target number segment. It should be noted that the step size of the target number segment can be greater than, less than or equal to the step size of the number segment stored in the current number segment buffer, that is, the two can be the same or different.

[0049] Optionally, the target number segment is determined based on the step size and end value of the number segment stored in the current number segment cache, including: calculating the step size of the target number segment based on the step size of the number segment stored in the current number segment cache and a preset adjustment factor; determining the end value of the target number segment based on the end value of the number segment stored in the current number segment cache and the step size of the target number segment; wherein the end value of the target number segment is the sum of the end value of the number segment stored in the current number segment cache, the step size of the target number segment and 1.

[0050] Among them, the preset adjustment factor may refer to a preset value for adjusting the step length. In an embodiment of the present invention, the step length of the target segment may be calculated based on the step length of the segment stored in the current segment buffer and the preset adjustment factor. Exemplarily, the product of the step length of the segment stored in the current segment buffer and the preset adjustment factor may be used as the step length of the target segment, or the ratio of the step length of the segment stored in the current segment buffer to the preset adjustment factor may be used as the step length of the target segment, without any limitation here.

[0051] In the embodiment of the present invention, the termination value of the target number segment can be calculated based on the termination value of the number segment stored in the current number segment buffer and the step size of the target number segment. Specifically, the termination value of the target number segment can be expressed as the sum of the termination value of the number segment stored in the current number segment buffer, the step size of the target number segment and 1, that is, the termination value of the target number segment = the termination value of the number segment stored in the current number segment buffer + the step size of the target number segment + 1. Among them, the termination value of the number segment stored in the current number segment buffer + 1 is the starting value of the target number segment.

[0052] The advantage of this setting is that, on the basis of ensuring the continuity of the number segment, the step size of the target number segment can be flexibly adjusted according to actual needs through the preset adjustment factor, thereby enhancing the flexibility and adaptability of the target number segment.

[0053] Optionally, the preset adjustment factor is greater than 1; before calculating the step size of the target number segment according to the step size of the number segment stored in the current number segment cache and the preset adjustment factor, it also includes: determining the update period of the number segment stored in the current number segment cache; wherein the update period is the difference between the asynchronous update number segment time and the start time of using the number segment stored in the current number segment cache; the asynchronous update number segment time is the time when the target identifier starts to be greater than a preset threshold in the number segment stored in the current number segment cache; accordingly, according to the step size of the number segment stored in the current number segment cache and the preset adjustment factor, calculate The step size of the target number segment includes: when the update period is less than the first time threshold, calculating the product of the step size of the number segment stored in the current number segment cache area and the preset adjustment factor, and determining the product as the step size of the target number segment; when the update period is greater than the first time threshold and less than the second time threshold, using the step size of the number segment stored in the current number segment cache area as the step size of the target number segment; when the update period is greater than the second time threshold, calculating the ratio of the step size of the number segment stored in the current number segment cache area to the preset adjustment factor, and determining the ratio as the step size of the target number segment.

[0054] Among them, the update period may refer to the time period used to update the number segment. Specifically, the update period may be expressed as the difference between the time of asynchronously updating the number segment and the time of starting to use the number segment stored in the current number segment cache. Among them, the asynchronous update number segment time may refer to the time when the target identifier begins to be greater than the preset threshold in the number segment stored in the current number segment cache, which is equivalent to the first time that the target identifier appears to be greater than the preset threshold in the number segment stored in the current number segment cache. Exemplarily, assuming that the current number segment is 1-1000, the preset threshold is 900, and the acquired target identifiers are 1, 3, 5, 7, ..., 997, 999 respectively, then the update period is the time difference corresponding to when the acquired target identifier is 901 and when the acquired target identifier is 1.

[0055] In an embodiment of the present invention, the preset adjustment factor is greater than 1. After determining the update period of the number segment stored in the current number segment cache, the update period can be compared with a preset time threshold, and the step length of the target number segment can be adjusted according to the comparison result using the step length of the number segment stored in the current number segment cache and the preset adjustment factor. The time threshold may include a first time threshold and a second time threshold, and the first time threshold is less than the second time threshold. Specifically, when the update cycle is less than the first time threshold, it indicates that the current business volume has surged, and therefore the demand for obtaining identifiers has increased. At this time, the product of the step size of the number segment stored in the current number segment cache and the preset adjustment factor can be used as the step size of the target number segment, thereby increasing the step size of the target number segment to meet the larger business volume demand; when the update cycle is greater than the first time threshold and less than the second time threshold, it indicates that the current demand for obtaining identifiers is within a normal range. At this time, the step size of the number segment stored in the current number segment cache can be directly used as the step size of the target number segment; when the update cycle is greater than the second time threshold, it indicates that the current demand for obtaining identifiers is within a lower range. At this time, the ratio of the step size of the number segment stored in the current number segment cache to the preset adjustment factor can be used as the step size of the target number segment, thereby reducing the step size of the target number segment to avoid wasting number segment resources.

[0056] Exemplarily, it is assumed that the initial value and step size of the number segment stored in the current number segment cache are 0 and 3000 respectively, the preset adjustment factor is 3, the preset threshold is 30% of the termination value, and the first time threshold and the second time threshold are 5 minutes and 10 minutes respectively. When the single server throughput in the system is 1.5-3TPS, there is no need to adjust the step size of the target number segment. When the single server throughput surges to 50TPS, when the asynchronous number segment update is triggered for the first time, the step size of the target number segment can be changed to 3×3000, that is, 9000. At this time, the target number segment becomes 3000-12000, and the iterative cycle is repeated until the step size is 54000, and the target number segment range falls between 50000-100000. When the single server throughput is reduced to 2TPS, it will be iterated from a step size of 54000 to 3000. Preferably, the step size of the target number segment can be set to 600 times the system server throughput during the peak service period. Among them, throughput can refer to the number of identifiers that need to be obtained. In this case, even if the system server is down, the number issuing device can continue to issue numbers for 10-20 minutes without being affected. In addition, the time threshold and the preset threshold in the present invention can also refer to this configuration.

[0057] The advantage of this setting is that the target segment step size can be adaptively iteratively adjusted according to the current business throughput through preset adjustment factors, preset thresholds, segment update cycles and time thresholds to better meet current business needs.

[0058] In some embodiments, in response to an identifier acquisition event being triggered, before acquiring the target identifier from the segment stored in the current segment cache based on the identifier configuration parameters, it also includes: reading the initial segment from any segment database in the segment database set, and storing the initial segment in the current segment cache.

[0059] The number segment database may refer to a database for generating and storing number segments. The database set may refer to a set consisting of multiple databases, that is, the database set includes at least two databases. The initial number segment may refer to the number segment read from the number segment database for the first time. In an embodiment of the present invention, multiple number segment databases may be provided for use by the server. Different number segment databases may configure the identifier configuration parameters autonomously without interfering with each other. Exemplarily, the same number segment and different modulus values ​​and remainders may be configured, or different number segments and the same modulus value and remainder may be configured. Assuming there are two number segment databases, number segment database 1 configures the number segment as a starting value of 1, a maximum value of 10000, a modulus value of 2, and a remainder of 0, then the generated identifiers are 2, 4, 6, ..., 9998, 10000. Number segment database 2 configures the number segment as a starting value of 1, a maximum value of 10000, a modulus value of 2, and a remainder of 1, then the generated identifiers are 1, 3, 5, ..., 9997, 9999. After the initial number segment is read from any one of the number segment databases in the number segment database set, the initial number segment may be stored in the current number segment buffer.

[0060] The advantage of this setting is that it can provide multiple number segment databases for the server to use, thereby realizing a multi-master database mode, which can effectively avoid availability problems caused by a single database downtime and hot database problems caused by frequent access to a single database.

[0061] Figure 3 A flowchart of an identifier generation method provided by another embodiment of the present invention. The method is applied to an identifier generation system, wherein the identifier generation system includes a first number segment buffer area and a second number segment buffer area. Figure 3 As shown, the method specifically comprises the following steps:

[0062] Step 310: In response to an identifier acquisition event being triggered, a service type matching the identifier acquisition event is acquired.

[0063] Among them, the business type can be used to distinguish different businesses. In an embodiment of the present invention, the table creation and data foundation of the segment can be done in the segment database according to the data type, and the step size of the segment can be divided according to the business type. Among them, the data type can include Oracle and Mysql, etc. It should be noted that the initialization creation of the generator can be completed when the segment generator is accessed for the first time, and it can be used directly when it is accessed again later without having to create it again. In addition, there are two segment buffers inside the segment generator of any business type. When it is detected that the identifier acquisition event is triggered, the business type that matches the identifier acquisition event can be obtained.

[0064] Step 320: Determine the identifier configuration parameter corresponding to the service type according to the pre-stored correspondence between the service type and the identifier configuration parameter.

[0065] In the embodiment of the present invention, the business type and the identifier configuration parameter have a corresponding relationship, and the corresponding relationship between the business type and the identifier configuration parameter can be pre-stored in the system. When a business type matching the identifier acquisition event is obtained, the identifier configuration parameter corresponding to the business type can be obtained according to the pre-stored corresponding relationship between the business type and the identifier configuration parameter.

[0066] Step 330: Obtain a target identifier from the number segment stored in the current number segment cache based on the identifier configuration parameter; wherein the current number segment cache is the first number segment cache or the second number segment cache.

[0067] Step 340, when the target identifier is greater than a preset threshold in the number segment stored in the current number segment cache, determine the target number segment and store the target number segment in another number segment cache; wherein the other number segment cache is a number segment cache in the first number segment cache and the second number segment cache except the current number segment cache.

[0068] Step 350, when the identifiers in the segment stored in the current segment cache are exhausted, the other segment cache is used as the current segment cache, and the process returns to obtain the target identifier from the segment stored in the current segment cache based on the identifier configuration parameters.

[0069] The specific implementation of steps 330-350 may refer to the detailed description of steps 110-130.

[0070] The embodiment of the present invention provides an identifier generation method, which can not only obtain the identifier from the system database without blocking through double-caching number segments, effectively avoiding the problem of request thread blocking when obtaining number segments from the database and updating number segments, thereby effectively ensuring the timeliness of identifier acquisition, but also effectively avoid the problem of machine downtime and resource waste caused by a surge in business volume, and can obtain the corresponding identifier according to the business type.

[0071] Figure 4 This is a flowchart of a preferred identifier generation method provided by another embodiment of the present invention. The method can monitor the consumption speed of the identifier in real time for the number segment issuers of different service types through the management interface. The initial value, step size, preset threshold and time threshold of the identifier in the number segment database can also be modified through the management interface, and after the modification is completed, it will take effect when the number segment is obtained again by the issuer.

[0072] Figure 5 It is a structural diagram of an identifier generation system provided by another embodiment of the present invention. The identifier generation system includes a segment number generator table configuration module, a segment number generator service module and a segment number generator retrieval module. The segment number generator table configuration module can be used to configure the corresponding segment in the segment database according to the service type to avoid duplicate numbers in segments of different service types. The segment number generator service module can be used to load the service type and segment configured in the table into the cache service, and after obtaining the identifier, the identifier can be formatted and shortened according to the service requirements to obtain the final identifier. It should be noted that the segment number generator service module can be used for this application to obtain a unique identifier in the segment cache area, and can also be used for the segment number generator retrieval module to obtain a unique identifier through a network request. In addition, if this application does not need to use the segment number generator service module, it can also send an http request to the application that uses the segment number generator service module to obtain a unique identifier required for the service.

[0073] Specifically, the execution process of the identifier generation system is as follows: (1) Based on factors such as system scale and business volume, plan the service name and the overall interval, step size, modulus value, remainder, preset adjustment factor and time threshold of the segment; (2) When a user service request accesses the application server, the application can obtain the identifier from the local segment generator service module, or initiate a network request to other applications through the generator retrieval module to obtain the identifier; (3) The segment generator service module generates a double-buffered segment generator in the memory according to the configuration in the table; (4) When the segment generator triggers the preset threshold to asynchronously update the segment, the step size and termination value of the segment can be adaptively iterated according to the throughput and updated to the segment database; (5) According to the business application rules, conversion between identifiers of different formats can be performed.

[0074] Figure 6 A schematic diagram of the structure of an identifier generation device provided by another embodiment of the present invention. The device is applied to an identifier generation system, wherein the identifier generation system includes a first number segment buffer area and a second number segment buffer area. Figure 6 As shown, the device includes: a target identifier acquisition module 610, a target number segment determination module 620 and a target identifier cyclic acquisition module 630. Among them,

[0075] A target identifier acquisition module 610 is configured to acquire a target identifier from a number segment stored in a current number segment cache based on an identifier configuration parameter in response to an identifier acquisition event being triggered; wherein the current number segment cache is the first number segment cache or the second number segment cache;

[0076] A target number segment determination module 620 is used to determine a target number segment when the target identifier is greater than a preset threshold value in the number segment stored in the current number segment cache, and store the target number segment in another number segment cache; wherein the another number segment cache is a number segment cache of the first number segment cache and the second number segment cache except the current number segment cache;

[0077] The target identifier loop acquisition module 630 is used to use the other segment cache area as the current segment cache area when the identifiers in the segment stored in the current segment cache area are exhausted, and return to execute the acquisition of the target identifier from the segment stored in the current segment cache area based on the identifier configuration parameters.

[0078] An embodiment of the present invention provides an identifier generating device, which, in response to an identifier acquisition event being triggered, acquires a target identifier from a number segment stored in a current number segment cache based on an identifier configuration parameter; wherein the current number segment cache is a first number segment cache or a second number segment cache; when the target identifier is greater than a preset threshold in the number segment stored in the current number segment cache, determines the target number segment and stores the target number segment in another number segment cache; wherein the other number segment cache is a number segment cache in the first number segment cache and the second number segment cache except the current number segment cache; when the identifier in the number segment stored in the current number segment cache is exhausted, uses the other number segment cache as the current number segment cache, and returns to execute the acquisition of the target identifier from the number segment stored in the current number segment cache based on the identifier configuration parameter. The technical solution provided by the embodiment of the present invention can obtain identifiers from the system database without blocking by double-caching number segments, which not only effectively avoids the problem of request thread blocking when obtaining number segments from the database and updating number segments, thereby effectively ensuring the timeliness of identifier acquisition, but also can effectively avoid machine downtime and resource waste caused by a surge in business volume.

[0079] Optionally, the target number segment determination module includes:

[0080] The target number segment determination submodule is used to determine the target number segment according to the number segment stored in the current number segment cache when the target identifier is greater than a preset threshold in the number segment stored in the current number segment cache; the difference between the starting value of the target number segment and the ending value of the number segment stored in the current number segment cache is 1.

[0081] Optionally, the target number segment determination submodule includes:

[0082] A current number segment step length determining unit, used to determine the step length and end value of the number segment stored in the current number segment buffer area;

[0083] The target number segment determining unit is used to determine the target number segment according to the step size and end value of the number segment stored in the current number segment buffer.

[0084] Optionally, the target number segment determination unit includes:

[0085] A target number segment step length determination subunit, configured to calculate the step length of the target number segment according to the step length of the number segment stored in the current number segment buffer and a preset adjustment factor;

[0086] The target number segment termination value determination subunit is used to determine the termination value of the target number segment based on the termination value of the number segment stored in the current number segment cache area and the step size of the target number segment; wherein the termination value of the target number segment is the sum of the termination value of the number segment stored in the current number segment cache area, the step size of the target number segment and 1.

[0087] Optionally, the preset adjustment factor is greater than 1; and the target number segment determination unit further includes:

[0088] An update period determination subunit is used to determine the update period of the number segment stored in the current number segment cache before calculating the step length of the target number segment according to the step length of the number segment stored in the current number segment cache and a preset adjustment factor; wherein the update period is the difference between the asynchronous update time of the number segment and the time when the number segment stored in the current number segment cache starts to be used; the asynchronous update time of the number segment is the time when the target identifier starts to be greater than a preset threshold value in the number segment stored in the current number segment cache;

[0089] Correspondingly, the target number segment step size determination subunit is used to:

[0090] When the update period is less than the first time threshold, calculating the product of the step length of the number segment stored in the current number segment buffer and the preset adjustment factor, and determining the product as the step length of the target number segment;

[0091] When the update period is greater than the first time threshold and less than the second time threshold, taking the step length of the number segment stored in the current number segment buffer as the step length of the target number segment;

[0092] When the update period is greater than the second time threshold, the ratio of the step length of the number segment stored in the current number segment cache to the preset adjustment factor is calculated, and the ratio is determined as the step length of the target number segment.

[0093] Optionally, the target identifier acquisition module is used to:

[0094] In response to an identifier acquisition event being triggered, acquiring a service type matching the identifier acquisition event;

[0095] Determine the identifier configuration parameter corresponding to the service type according to the pre-stored correspondence between the service type and the identifier configuration parameter;

[0096] A target identifier is obtained from the number segment stored in the current number segment cache based on the identifier configuration parameter.

[0097] Optionally, the device further comprises:

[0098] The initial number segment reading module is used to read the initial number segment from any number segment database in the number segment database set, and store the initial number segment in the current number segment buffer area.

[0099] The above device can execute the identifier generation method provided by all the above embodiments of the present invention, and has the corresponding functional modules and beneficial effects of executing the above methods. For technical details not fully described in the embodiments of the present invention, please refer to the identifier generation method provided by all the above embodiments of the present invention.

[0100] An embodiment of the present invention further provides a storage medium containing computer executable instructions, and when the computer executable instructions are executed by a computer processor, they are used to execute the identifier generation method provided by the embodiment of the present invention.

[0101] Storage medium - any of various types of memory devices or storage devices. The term "storage medium" is intended to include: installation media, such as CD-ROM, floppy disk or tape device; computer system memory or random access memory, such as DRAM, DDRRAM, SRAM, EDORAM, Rambus RAM, etc.; non-volatile memory, such as flash memory, magnetic media (such as hard disk or optical storage); registers or other similar types of memory elements, etc. The storage medium may also include other types of memory or combinations thereof. In addition, the storage medium may be located in the first computer system in which the program is executed, or may be located in a different second computer system, which is connected to the first computer system via a network (such as the Internet). The second computer system can provide program instructions to the first computer for execution. The term "storage medium" may include two or more storage media that may reside in different locations (for example, in different computer systems connected by a network). The storage medium may store program instructions (for example, embodied as a computer program) that can be executed by one or more processors.

[0102] Of course, the computer executable instructions of a storage medium including computer executable instructions provided by an embodiment of the present invention are not limited to the identifier generation operation described above, and can also execute related operations in the identifier generation method provided by any embodiment of the present invention.

[0103] An embodiment of the present invention provides an identifier generation system, into which the identifier generation device provided by the embodiment of the present invention can be integrated. Figure 7 The structural block diagram of an identifier generation system provided by an embodiment of the present invention. The identifier generation system 700 may include: a memory 701, a processor 702, and a computer program stored in the memory 701 and executable by the processor, and the processor 702 implements the identifier generation method as described in the embodiment of the present invention when executing the computer program.

[0104] An identifier generation system provided in an embodiment of the present invention, in response to an identifier acquisition event being triggered, acquires a target identifier from a number segment stored in a current number segment cache based on an identifier configuration parameter; wherein the current number segment cache is a first number segment cache or a second number segment cache; when the target identifier is greater than a preset threshold in the number segment stored in the current number segment cache, determines the target number segment and stores the target number segment in another number segment cache; wherein the other number segment cache is a number segment cache other than the current number segment cache in the first number segment cache and the second number segment cache; when the identifier in the number segment stored in the current number segment cache is exhausted, the other number segment cache is used as the current number segment cache, and returns to execute the acquisition of the target identifier from the number segment stored in the current number segment cache based on the identifier configuration parameter. The technical solution provided by the embodiment of the present invention can obtain identifiers from the system database without blocking by double-caching number segments, which not only effectively avoids the problem of request thread blocking when obtaining number segments from the database and updating number segments, thereby effectively ensuring the timeliness of identifier acquisition, but also can effectively avoid machine downtime and resource waste caused by a surge in business volume.

[0105] The identifier generation device, storage medium, and identifier generation system provided in the above embodiments can execute the identifier generation method provided in any embodiment of the present invention, and have the corresponding functional modules and beneficial effects of executing the method. For technical details not described in detail in the above embodiments, please refer to the identifier generation method provided in any embodiment of the present invention.

[0106] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A method for generating an identifier, characterized in that: Applied to an identifier generation system, wherein the identifier generation system includes a first number segment cache area and a second number segment cache area, the method comprising: In response to an identifier acquisition event being triggered, acquiring a target identifier from a number segment stored in a current number segment cache based on an identifier configuration parameter; wherein the current number segment cache is the first number segment cache or the second number segment cache; When the target identifier is greater than a preset threshold value of the number segments stored in the current number segment buffer, determining a target number segment and storing the target number segment in another number segment buffer; wherein the another number segment buffer is a number segment buffer of the first number segment buffer and the second number segment buffer other than the current number segment buffer; When the identifiers in the number segment stored in the current number segment cache are exhausted, the other number segment cache is used as the current number segment cache, and the process returns to executing the process of obtaining the target identifier from the number segment stored in the current number segment cache based on the identifier configuration parameter; The step size of the target number segment is determined as follows: Determine an update period for the number segments stored in the current number segment cache; wherein the update period is the difference between the asynchronous segment update time and the time when the number segments stored in the current number segment cache begin to be used; the asynchronous segment update time is the time when the target identifier begins to be greater than a preset threshold value in the number segments stored in the current number segment cache; When the update period is less than the first time threshold, calculating the product of the step length of the number segment stored in the current number segment buffer and a preset adjustment factor, and determining the product as the step length of the target number segment; wherein the preset adjustment factor is greater than 1; When the update period is greater than the first time threshold and less than the second time threshold, the step length of the number segment stored in the current number segment buffer is used as the step length of the target number segment; When the update period is greater than the second time threshold, the ratio of the step length of the number segment stored in the current number segment cache to the preset adjustment factor is calculated, and the ratio is determined as the step length of the target number segment.

2. The method according to claim 1, characterized in that When the target identifier is greater than a preset threshold value of the number segments stored in the current number segment buffer, determining the target number segment includes: When the target identifier is greater than the preset threshold value in the number segment stored in the current number segment cache, the target number segment is determined based on the number segment stored in the current number segment cache; the difference between the starting value of the target number segment and the ending value of the number segment stored in the current number segment cache is 1.

3. The method according to claim 2, characterized in that Determining a target number segment according to the number segment stored in the current number segment buffer includes: Determining the step size and end value of the number segment stored in the current number segment buffer; The target number segment is determined according to the step size and end value of the number segment stored in the current number segment buffer.

4. The method according to claim 3, characterized in that Determining the target number segment according to the step size and the end value of the number segment stored in the current number segment buffer includes: The end value of the target number segment is determined based on the end value of the number segment stored in the current number segment cache and the step size of the target number segment; wherein the end value of the target number segment is the sum of the end value of the number segment stored in the current number segment cache, the step size of the target number segment and 1.

5. The method according to claim 1, wherein In response to the identifier acquisition event being triggered, acquiring a target identifier from a number segment stored in a current number segment buffer based on the identifier configuration parameter, including: In response to an identifier acquisition event being triggered, acquiring a service type matching the identifier acquisition event; Determining the identifier configuration parameter corresponding to the service type according to the pre-stored correspondence between the service type and the identifier configuration parameter; A target identifier is obtained from the number segments stored in the current number segment buffer based on the identifier configuration parameter.

6. The method according to claim 1, characterized in that Before obtaining the target identifier from the number segment stored in the current number segment buffer based on the identifier configuration parameter in response to the identifier obtaining event being triggered, the method further includes: An initial number segment is read from any one number segment database in the number segment database set, and the initial number segment is stored in the current number segment buffer.

7. An identifier generating device, characterized in that: Applied to an identifier generation system, wherein the identifier generation system includes a first number segment cache area and a second number segment cache area, the apparatus comprising: a target identifier acquisition module, configured to acquire a target identifier from a number segment stored in a current number segment cache based on an identifier configuration parameter in response to an identifier acquisition event being triggered; wherein the current number segment cache is the first number segment cache or the second number segment cache; a target number segment determining module, configured to determine a target number segment when the target identifier is greater than a preset threshold value among the number segments stored in the current number segment cache, and store the target number segment in another number segment cache; wherein the another number segment cache is a number segment cache of the first number segment cache and the second number segment cache excluding the current number segment cache; a target identifier cyclic acquisition module, configured to, when the identifiers in the number segment stored in the current number segment cache are exhausted, use the other number segment cache as the current number segment cache, and return to execute acquisition of the target identifier from the number segment stored in the current number segment cache based on the identifier configuration parameter; The target number segment determination module is configured to: Determine an update period for the number segments stored in the current number segment cache; wherein the update period is the difference between the asynchronous segment update time and the time when the number segments stored in the current number segment cache begin to be used; the asynchronous segment update time is the time when the target identifier begins to be greater than a preset threshold value in the number segments stored in the current number segment cache; When the update period is less than the first time threshold, calculating the product of the step length of the number segment stored in the current number segment buffer and a preset adjustment factor, and determining the product as the step length of the target number segment; wherein the preset adjustment factor is greater than 1; When the update period is greater than the first time threshold and less than the second time threshold, the step length of the number segment stored in the current number segment buffer is used as the step length of the target number segment; When the update period is greater than the second time threshold, the ratio of the step length of the number segment stored in the current number segment cache to the preset adjustment factor is calculated, and the ratio is determined as the step length of the target number segment.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processing device, the identifier generation method according to any one of claims 1 to 6 is implemented.

9. An identifier generation system comprising a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein: When the processor executes the computer program, the identifier generation method as described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Caching processing method and device, computer equipment and storage medium

    CN107665235A

  • Method for generating distributed ID in number segment mode

    CN112181306A