Distributed ID generation method, server, readable storage medium and product
By setting multiple cache areas and switching mechanisms on the server, the problem of insufficient ID generation rate and duplication during burst traffic in distributed systems is solved, and efficient and continuous distributed ID generation is achieved, ensuring the uniqueness of IDs and quality.
Patent Information
- Application Number
- CN202411341857.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2025-01-07
AI Technical Summary
In distributed systems, the conventional distributed ID generation algorithm has problems with insufficient ID generation rate and duplication of IDs during burst traffic, resulting in a degradation of the generation quality of distributed IDs.
By setting multiple cache areas on the server, after receiving the ID generation request, obtaining the available ID from the main cache area, and when the number of available IDs is less than the threshold, obtaining the ID cache from the preset database to the backup cache area, and switching the backup cache area For the new main cache area, continuous generation and efficient supply of IDs are realized.
The ID generation rate is improved, the continuous generation and uniqueness of IDs are guaranteed, the ID duplication is avoided, and the generation quality of distributed IDs is ensured.
Smart Images

Figure CN119271720A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data identification technology, and in particular to a distributed ID generation method, a server, a readable storage medium and a product. Background Art
[0002] In a distributed system, a large amount of information usually needs to be uniquely identified. Therefore, multiple IDs (Identity Documents) generated by nodes in the distributed system are usually used to identify multiple pieces of information. In order to uniquely identify multiple pieces of information, it is usually necessary to make the multiple IDs different from each other to ensure the global uniqueness of the ID.
[0003] There are many common algorithms for generating distributed IDs, such as UUID (Universally Unique Identifier), database or other middleware self-increment, snowflake algorithm, segment ID, etc. However, these conventional distributed ID generation algorithms all have problems of insufficient ID generation rate and / or ID duplication when there is burst traffic, resulting in a decrease in the quality of distributed ID generation.
[0004] Therefore, how to ensure the quality of distributed ID generation during burst traffic is a technical problem that needs to be solved urgently in this technical field. Summary of the invention
[0005] The main purpose of this application is to provide a distributed ID generation method, server, readable storage medium and product, aiming to solve the technical problem of how to ensure the quality of distributed ID generation during burst traffic.
[0006] To achieve the above object, the present application provides a distributed ID generation method, which is applied to a server, wherein the server is provided with a plurality of cache areas, each of which is used to cache an ID, and the distributed ID generation method comprises the following steps:
[0007] Receiving an ID generation request, and determining a primary buffer area among the buffer areas;
[0008] Obtain available IDs cached in the main cache area until a preset generation end condition is met, and determine that all the obtained available IDs are generation results;
[0009] In the process of obtaining the available IDs, if the available number of available IDs cached in the main cache area is less than a preset available threshold, a backup cache area in each of the cache areas is determined, and a target number of IDs are obtained from a preset database and cached in the backup cache area;
[0010] During the process of obtaining the available ID, if there is no available ID in the primary cache area, the backup cache area is switched to a new primary cache area, and the step of obtaining the available ID cached in the primary cache area is returned based on the new primary cache area.
[0011] In a possible implementation manner, before the step of acquiring a target number of IDs from a preset database and caching them in the standby cache area, the method further includes:
[0012] Obtaining the number of historical ID generation requests received within a preset time window, and obtaining a current window size of the backup cache area;
[0013] If the request quantity is less than a first preset flow threshold, determining a target quantity based on the current window size, wherein the target quantity is less than the current window size;
[0014] If the requested quantity is greater than a second preset flow threshold, determining a target quantity based on the current window size, wherein the target quantity is greater than the current window size, and wherein the second preset flow threshold is greater than or equal to the first preset flow threshold;
[0015] The window size of the standby buffer area is updated to the target number.
[0016] In a possible implementation manner, the step of determining a primary cache area in each of the cache areas includes:
[0017] Obtaining a business scenario according to the ID generation request, and determining a cache area belonging to the business scenario among the cache areas as a target cache area;
[0018] A primary buffer area in each of the target buffer areas is determined.
[0019] In a possible implementation manner, after the step of receiving the ID generation request, the method further includes:
[0020] Obtain the current fuse status of the server, and if the current fuse status indicates that the fuse is turned on, return a response exception;
[0021] If the current fuse state indicates a half-open fuse, or the current fuse state indicates a closed fuse, then the step of determining the primary cache area in each of the target cache areas is continued.
[0022] In a possible implementation manner, before the step of receiving the ID generation request, the method further includes:
[0023] Obtain the fuse status of the server;
[0024] If the fuse status indicates that the fuse is closed, after the number of response exceptions within the preset time window is greater than the first preset failure threshold, the fuse status of the server is switched to indicate that the fuse is turned on;
[0025] If the fuse state indicates a semi-open fuse, then after the number of response exceptions within the preset time window is greater than a second preset failure threshold, the fuse state of the server is switched to indicate an open fuse, wherein the second preset failure threshold is less than the first preset failure threshold;
[0026] If the fuse status indicates that the fuse is turned on, then after waiting for a preset period of time, the fuse status of the server is switched to indicate a semi-open fuse.
[0027] In a possible implementation manner, after the step of obtaining the available ID cached in the primary cache area, the method further includes:
[0028] In the process of obtaining the available ID, if the primary cache area has no available ID, switching the primary cache area to a new standby cache area;
[0029] After the step of determining that all the available IDs obtained are generated results, the method further includes:
[0030] If the number of available IDs cached in the new primary cache area is less than the preset available threshold, the step of acquiring the target number of IDs from the preset database and caching them in the backup cache area is performed based on the new backup cache area.
[0031] In a possible implementation manner, the ID includes an ascending sequence field, or the ID includes a service prefix field and an ascending sequence field, or the ID includes a service prefix field, an ascending sequence field, and a service suffix field;
[0032] Among them, in different business scenarios, the field values of the business prefix field and / or the business suffix field are different.
[0033] In addition, to achieve the above-mentioned purpose, the present application also provides a server, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the distributed ID generation method as described above.
[0034] In addition, to achieve the above-mentioned purpose, the present application also provides a readable storage medium, which is a computer-readable storage medium, and the computer-readable storage medium stores a program for implementing the distributed ID generation method, and the program for implementing the distributed ID generation method is executed by a processor to implement the steps of the distributed ID generation method as described above.
[0035] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned distributed ID generation method when executed by a processor.
[0036] One or more technical solutions proposed in this application have at least the following technical effects:
[0037] The server is provided with multiple cache areas, each of which is used to cache IDs. The server receives an ID generation request and determines a main cache area among the cache areas; obtains available IDs cached in the main cache area until a preset generation end condition is met, and determines that all the obtained available IDs are generation results; in the process of obtaining the available IDs, if the available number of available IDs cached in the main cache area is less than a preset available threshold, determines a backup cache area among the cache areas, obtains a target number of IDs from a preset database and caches them in the backup cache area; in the process of obtaining the available IDs, if there is no available ID in the main cache area, switches the backup cache area to a new main cache area, and executes the step of obtaining the available IDs cached in the main cache area based on the return in the new main cache area. In this way, in the embodiment of the present application, the server sets up a cache area for caching IDs. After receiving an ID generation request, it obtains the available ID cached in the main cache area and directly obtains the ID from the cache area, thereby improving the ID generation rate. In the process of obtaining the available ID, if the available number of available IDs cached in the main cache area is less than the preset available threshold, the target number of IDs are obtained from the preset database and cached in the backup cache area. In other words, the acquisition of the ID and the cache preparation can be performed asynchronously without waiting for the ID in the main cache area to be obtained and then interrupting the acquisition of the ID for cache preparation. By switching the working cache area, the ID can always be obtained from the main cache area, thereby realizing continuous acquisition of the ID without interrupting the ID acquisition process, that is, the ID is generated continuously. Based on this, even when there is burst traffic, since the ID is obtained from the cache area, the acquisition speed is fast, which ensures the speed of ID generation. When the available ID in the working cache is less than a certain value, the new ID is filled in the backup cache area. When there is no available ID in the main cache area, the backup cache area can be switched to the new main cache area to continue working to ensure the normal supply of IDs, thereby ensuring the continuous generation of IDs, avoiding the generation of duplicate IDs, and thus ensuring the generation quality of distributed IDs. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0040] Figure 1 This is a flow chart of the first embodiment of the distributed ID generation method of the present application;
[0041] Figure 2 A schematic diagram of the switching of the primary and backup cache areas involved in an embodiment of the distributed ID generation method of the present application;
[0042] Figure 3 This is a schematic diagram of switching the buffer window size involved in an embodiment of the distributed ID generation method of the present application;
[0043] Figure 4 This is a schematic diagram of the switching of the server fuse state involved in an embodiment of the distributed ID generation method of the present application;
[0044] Figure 5 This is a schematic diagram of the system architecture of the distributed ID generation method of this application;
[0045] Figure 6 This is a schematic diagram of the device structure of the hardware operating environment involved in the distributed ID generation device in the embodiment of the present application.
[0046] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0047] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.
[0048] Currently, the main ID generation schemes include Redis-based ID generation scheme, snowflake algorithm, UUID, database auto-increment sequence, and segment ID.
[0049] Among them, the ID generation solution based on Redis consumes a lot of resources and is highly dependent on the Redis cluster. Redis itself is a memory cache. If there is an outage, the memory data will be lost, which will lead to problems such as ID duplication. The snowflake algorithm relies on intermediate services such as Zookeeper and has a clock callback problem. The UUID characters are disordered and cannot reflect business semantics. The database auto-increment sequence has brought hidden dangers such as subsequent data migration and sub-library and table sharding, reducing data scalability. The segment ID is a pure digital sequence, which is not suitable for the migration of existing business scenarios, and is difficult to adapt to problems such as sudden traffic and waste of ID sequences when applications are started and stopped.
[0050] Based on this, the main solution of the present application is: the server is provided with multiple cache areas, each of which is used to cache IDs. The server receives an ID generation request and determines the main cache area among the cache areas; obtains the available IDs cached in the main cache area until the preset generation end condition is met, and determines that all the obtained available IDs are generation results; in the process of obtaining the available IDs, if the available number of available IDs cached in the main cache area is less than the preset available threshold, then determines the backup cache area in each of the cache areas, obtains the target number of IDs from the preset database and caches them in the backup cache area; in the process of obtaining the available IDs, if there is no available ID in the main cache area, then switches the backup cache area to a new main cache area, and returns to execute the step of obtaining the available IDs cached in the main cache area.
[0051] The present application sets a cache area for caching IDs through the server side. After receiving an ID generation request, it obtains the available ID cached in the main cache area and directly obtains the ID from the cache area, thereby improving the ID generation rate. In the process of obtaining the available ID, if the available number of available IDs cached in the main cache area is less than the preset available threshold, the target number of IDs are obtained from the preset database and cached in the backup cache area. In other words, the acquisition of the ID and the cache preparation can be performed asynchronously without waiting for the ID in the main cache area to be obtained and then interrupting the ID acquisition for cache preparation. By switching the working cache area, the ID can always be obtained from the main cache area, thereby realizing continuous acquisition of the ID without interrupting the ID acquisition process, that is, the ID is generated continuously. Based on this, even when there is burst traffic, since the ID is obtained from the cache area, the acquisition speed is fast, which ensures the speed of ID generation. When the available ID in the working cache is less than a certain value, the new ID is filled in the backup cache area. When there is no available ID in the main cache area, the backup cache area can be switched to the new main cache area to continue working to ensure the normal supply of IDs, thereby ensuring the continuous generation of IDs, avoiding the generation of duplicate IDs, and thus ensuring the generation quality of distributed IDs.
[0052] It should be noted that the execution subject of each embodiment of the distributed ID generation method of the present application can be a server with data processing, network communication and program running functions, such as a server, a personal computer, a desktop computer, etc. The embodiments of the distributed ID generation method of the present application do not make specific restrictions on this.
[0053] Based on this, the present application proposes a distributed ID generation method of the first embodiment, the distributed ID generation method is applied to the server, the server is provided with multiple cache areas, each of the cache areas is used to cache the ID, please refer to Figure 1 , the distributed ID generation method includes steps S10 to S40:
[0054] Step S10, receiving an ID generation request, and determining a primary buffer area among the buffer areas;
[0055] A plurality of cache areas are set in the server, each of which is used to cache an ID, so that an ID can be obtained from the cache area, and thus it can be understood that the cache area generates an ID as an ID generator.
[0056] The server can be connected to the client, and the ID generation request can specifically be a request sent by the client to the server to request the server to generate an ID and return the generation result to the client.
[0057] It should be noted that each cache area can be divided into a main cache area (also called a working cache area) and a backup cache area. The main cache area is the cache area currently in the working state, and the backup cache area is the cache area currently in the backup state. Among them, the working state refers to being responsible for providing IDs for data interaction, and the backup state refers to being in a waiting state.
[0058] Furthermore, the standby cache area can be divided into a cold standby cache area and a hot standby cache area. The cold standby cache area is the cache area currently in the cold standby state, and the hot standby cache area is the cache area currently in the hot standby state. The cold standby state means that the cache area is not ready (such as no ID is cached in the cache area, the cache area is occupied by other processes, etc.), and cannot be directly switched to the working state. The hot standby state means that the cache area is ready (such as the cache area has cached a certain number of IDs) and can be switched to the working state at any time.
[0059] Exemplarily, the various embodiments of the present application are described and illustrated by taking the division of the cache area into a working cache area, a cold standby cache area, and a hot standby cache area as an example.
[0060] Furthermore, the switching conditions between the three states (working state, cold standby state, hot standby state) of the cache area can be set. When the switching conditions are met, the cache area is switched to the corresponding state.
[0061] For example, the working state is W, the cold standby state is C, the hot standby state is H, the switching condition between W and C is f1, the switching condition between C and H is f2, the switching adjustment from H to W is f3, W cannot be directly switched to H, H cannot be directly switched to C, and C cannot be directly switched to W. Based on this, assuming that the current state of a cache area is W, then during the operation of the server, after detecting that condition f1 is satisfied, the state of the cache area is switched to C, after detecting that condition f2 is satisfied, the state of the cache area is switched to H, and after detecting that condition f3 is satisfied, the state of the cache area is switched to W.
[0062] Furthermore, the initial state of each cache area can be set, and the initial states of different cache areas can be the same or different. Relevant personnel can configure according to actual needs, and no specific restrictions are made here.
[0063] Furthermore, the window size of each cache area is adjustable, wherein the window size of the cache area refers to the maximum number of IDs that can be cached in the cache area. By adjusting the window size of the cache area, the purpose of adaptive traffic is achieved. Specifically, the traffic can be the total number of ID generation requests received by the server in a certain time window, or the average number of ID generation requests received by the server in a unit time window.
[0064] Step S20, obtaining available IDs cached in the main cache area, until a preset generation end condition is met, and executing step S50: determining that all the obtained available IDs are generation results;
[0065] The available ID is an ID that is not allocated or occupied and can be returned to the client for use.
[0066] Regarding the setting of the preset generation end condition, as one of the implementation methods, the required number is obtained based on the ID generation request, and the required number is the total number of IDs that the client needs to obtain this time. The total number of available IDs obtained can be set to be greater than or equal to the required number as the preset generation end condition.
[0067] As another implementation, the required number is obtained based on the ID generation request, and the total number of available IDs obtained can be set to be greater than or equal to the required number, or the server enters a start-stop state (such as a server system update) as a preset generation end condition.
[0068] It should be noted that the above are only two possible implementation methods for setting the preset generation end conditions provided in this embodiment. Relevant personnel can set the preset generation end conditions according to actual needs. This embodiment does not make any specific restrictions on the preset generation end conditions.
[0069] In addition, after the preset end condition is met and it is determined that all the available IDs obtained are generation results, the generation results can be returned to the client to complete the response to the ID generation request.
[0070] Step S30, during the process of obtaining the available IDs, if the available number of available IDs cached in the main cache area is less than a preset available threshold, a backup cache area in each of the cache areas is determined, and a target number of IDs are obtained from a preset database and cached in the backup cache area;
[0071] It should be noted that before obtaining the available ID, it is also possible to detect whether the number of available IDs cached in the main cache area is less than the preset available threshold. If it is less than the preset available threshold, the backup cache area in each cache area is determined, and the target number of IDs are obtained from the preset database and cached in the backup cache area.
[0072] The preset available threshold value may be any value greater than zero that is set in advance, and this embodiment does not impose any specific limitation on this.
[0073] The backup cache area may be a cold backup cache area, that is, a cache area currently in a cold backup state. Further, after obtaining a target number of IDs from a preset database and caching them in the backup cache area, the state of the backup cache area is switched to a hot backup state, that is, the backup cache area is switched from a cold backup cache area to a hot backup cache area.
[0074] The preset database may be an external database connected to the server, in which the IDs to be used are stored.
[0075] Furthermore, if the ID is not successfully obtained from the preset database, the ID can be obtained from the preset database based on the preset retry rule until the preset retry condition is met. The preset retry rule can be a retry rule set in advance according to actual needs, such as a retry rule based on a time interval. Specifically, the retry rule based on the time interval can be a random interval retry, a Fibonacci sequence interval retry, an increasing interval retry (the initial waiting time and the subsequent interval waiting time can be set), etc.
[0076] The preset retry conditions can be to stop retrying after reaching a specified number of retries (the maximum number of retries can be set), to stop retrying after reaching a specified maximum retry time (the maximum retry time can be set), to keep retrying until success, etc.
[0077] In step S40, during the acquisition process of the available ID, if there is no available ID in the primary cache area, the backup cache area is switched to a new primary cache area, and if the preset generation end condition is not met, step S20 is returned to be executed based on the new primary cache area.
[0078] It can be understood that if in the process of obtaining available IDs, after all available IDs in the main cache area have been obtained, the preset generation end condition is still not met, the backup cache area can be switched to a new main cache area. Specifically, the hot backup cache area can be switched to the new main cache area to obtain available IDs from the new main cache area, and obtain the available IDs cached in the new main cache area until the preset generation end condition is met.
[0079] It should be noted that, in the process of obtaining available IDs, when there is no available ID in the primary cache area, the primary cache area is switched to a new backup cache area, specifically, it can be switched to a new cold backup cache area.
[0080] In addition, in the process of obtaining available IDs, the server starts and stops triggering hook functions (such as server system updates). When the service stops, the cached and unused IDs in the cache area can be given to the preset data middleware (such as Redis). When the server is started again, the loaded but unused IDs are loaded from the preset data middleware into the cache area first, until all the IDs in the preset data middleware are loaded into the cache area, and then the IDs are obtained from the preset database, thereby improving the utilization rate of the ID.
[0081] For example, in order to help understand the technical concept or technical principle of the distributed ID generation method in this embodiment, a specific embodiment is now listed. In this specific embodiment, the distributed ID generation process is:
[0082] The server is provided with multiple buffers as ID generators, each buffer can be initialized as a cold standby buffer, and a certain number of ID buffers are obtained from a preset database to a cold standby buffer, and the cold standby buffer is initialized as a working buffer.
[0083] After receiving the ID generation request, obtain the available ID from the working buffer (cache area), and detect the available ID margin in the working buffer (that is, the available number of available IDs) in real time. When the available margin is less than the preset available threshold, the asynchronous working thread will be started to asynchronously check the cold and hot standby status of the standby buffer; if the standby buffer is in the cold standby state, take out a batch of target number of IDs from the preset database to fill the window of the cold standby buffer, and convert it from the cold standby state to the hot standby state. When the available ID margin of the subsequent working buffer is 0, the hot standby buffer is converted to a new working buffer. The old working buffer with a margin of 0 is converted to a cold standby buffer. This is executed alternately back and forth. The buffer not only contains the ID sequence to be used, but also contains a pointer to the sliding window size (that is, the window size of the buffer) and the remaining available ID threshold factor (that is, the preset available threshold).
[0084] It should be noted that the above examples are only used to assist in understanding the present application and do not constitute a limitation on the distributed ID generation method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0085] In this embodiment, a plurality of cache areas are set up through the server, each of which is used to cache IDs. The server receives an ID generation request and determines a main cache area among the cache areas; obtains available IDs cached in the main cache area until a preset generation end condition is met, and determines that all the obtained available IDs are generation results; in the process of obtaining the available IDs, if the available number of available IDs cached in the main cache area is less than a preset available threshold, determines a backup cache area among the cache areas, obtains a target number of IDs from a preset database and caches them in the backup cache area; in the process of obtaining the available IDs, if there is no available ID in the main cache area, switches the backup cache area to a new main cache area, and executes the step of obtaining the available IDs cached in the main cache area based on the return in the new main cache area. In this way, in this embodiment, the server sets up a cache area for caching IDs. After receiving an ID generation request, it obtains the available ID cached in the main cache area and directly obtains the ID from the cache area, thereby improving the ID generation rate. In the process of obtaining the available ID, if the available number of available IDs cached in the main cache area is less than the preset available threshold, the target number of IDs are obtained from the preset database and cached in the backup cache area. In other words, the acquisition of the ID and the cache preparation can be performed asynchronously without waiting for the ID in the main cache area to be obtained and then interrupting the ID acquisition for cache preparation. By switching the working cache area, the ID can always be obtained from the main cache area, thereby realizing continuous acquisition of the ID without interrupting the ID acquisition process, that is, the ID is generated continuously. Based on this, even when there is burst traffic, since the ID is obtained from the cache area, the acquisition speed is fast, which ensures the speed of ID generation. When the available ID in the working cache is less than a certain value, the new ID is filled in the backup cache area. When there is no available ID in the main cache area, the backup cache area can be switched to the new main cache area to continue working to ensure the normal supply of IDs, thereby ensuring the continuous generation of IDs, avoiding the generation of duplicate IDs, and thus ensuring the generation quality of distributed IDs.
[0086] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above description and will not be described in detail later. On this basis, before the step of obtaining the target number of ID caches from the preset database to the standby cache area, the method further includes:
[0087] Step A10, obtaining the number of historical ID generation requests received within a preset time window, and obtaining the current window size of the backup cache area;
[0088] It should be noted that when initializing each cache area, the window size of the cache area can be set to a preset initial window size. The preset initial window size can be any integer greater than zero set in advance by relevant personnel according to actual needs. This embodiment does not impose any specific restrictions on this.
[0089] The preset time window may be a time window before receiving the ID request, such as a time window of 10 seconds before receiving the ID request, a time window of 1 minute before receiving the ID request, etc. This embodiment does not impose any specific limitation on this.
[0090] Historical ID generation requests refer to ID generation requests received within a preset time window.
[0091] The request quantity may specifically be the total request quantity of historical ID generation requests, or may be the average request quantity per unit time of historical ID generation requests, and this embodiment does not make any specific restrictions on this.
[0092] It should be noted that, refer to Figure 3 As shown, from the perspective of window size changes, the cache can be divided into expansion state, contraction state and stable state. Among them, the stable state refers to the state where the window size of the cache area remains unchanged, the expansion state refers to the state where the window size of the cache area is expanding, and the contraction state refers to the state where the window size of the cache area is shrinking. Similar to the above-mentioned working state, cold standby state and hot standby state, the switching conditions between the expansion state, contraction state and stable state can be set, and when the switching conditions are met, it switches to the corresponding state.
[0093] Step A20, if the request quantity is less than a first preset flow threshold, determining a target quantity based on the current window size, wherein the target quantity is less than the current window size;
[0094] When the number of requests is less than the first preset traffic threshold, it indicates that the current request traffic is small. In this case, reducing the window size of the standby cache area can reduce the occupation of storage resources.
[0095] Furthermore, if the number of requests is less than the first preset traffic threshold and the standby cache area is currently in an expansion state or a contraction state, the target number is determined based on the current window size, wherein the target number is less than the current window size; if the number of requests is less than the first preset traffic threshold and the standby cache area is currently in a stable state, the window size of the standby cache area may no longer be adjusted to avoid the window size of the cache area being too small.
[0096] Furthermore, if the number of requests is less than the first preset flow threshold, and the backup cache area is currently in an expansion state, the backup cache area can be switched to a contraction state, and timing is started. If the timing duration reaches the preset time threshold, the backup cache area is switched to a stable state. During the timing process, the number of requests within a certain time window is periodically detected. If the number of requests is greater than or equal to the first preset flow threshold, the timing is ended.
[0097] Furthermore, when the standby cache area is in an expanding state, the reduction speed of the standby cache area window size is a first reduction speed, and when the standby cache area is in a shrinking state, the reduction speed of the standby cache area window size is a second reduction speed. The second reduction speed is greater than the first reduction speed. For example, the first reduction speed is an arithmetic reduction of the window size, and the second reduction speed is an exponential reduction of the window size. When the number of requests is continuously less than the first preset traffic threshold, the window size can be quickly reduced to an appropriate size, and the window size can be gradually reduced, which can also better adapt to abnormal changes in traffic.
[0098] For example, refer to Figure 3 As shown, when the number of requests is less than the first preset traffic threshold and the standby cache area is currently in an expanding state, the result of subtracting M from the current window size can be used as the target number, and the standby cache area is switched to a shrinking state; when the number of requests is less than the first preset traffic threshold and the standby cache area is currently in a shrinking state, the window size of the standby cache area can be exponentially reduced, and if the traffic continues to be less than the first preset traffic threshold, the standby cache area is switched to a stable state; when the number of requests is less than the first preset traffic threshold and the standby cache area is currently in a stable state, the window size of the cache area is not adjusted.
[0099] Step A30, if the request quantity is greater than a second preset flow threshold, determining a target quantity based on the current window size, wherein the target quantity is greater than the current window size, wherein the second preset flow threshold is greater than or equal to the first preset flow threshold;
[0100] When the number of requests is greater than the second preset traffic threshold, the window size is expanded in a manner similar to reducing the window size, which is not described in detail in this embodiment.
[0101] For example, refer to Figure 3 As shown, when the number of requests is greater than the second preset traffic threshold and the standby cache area is currently in a shrinking state, the current window size plus N (N and M can be set in advance separately) can be used as the target number, and the standby cache area is switched to an expanding state; when the number of requests is greater than the first preset traffic threshold and the standby cache area is currently in a stable state, the window size of the standby cache area can be exponentially expanded, and after the window size reaches the preset upper limit window size, it can be switched to an expanding state, thereby achieving slow start of the expanded state and fast growth of the window size.
[0102] Step A40: Update the window size of the standby buffer area to the target number.
[0103] It should be noted that if the request quantity is less than or equal to the second preset traffic threshold and greater than or equal to the first preset traffic threshold, the window size of the standby cache area may not be changed, that is, the target quantity is determined to be the current window size.
[0104] In this embodiment, when the number of historical ID generation requests is less than a certain traffic threshold, the window size of the exchange zone is reduced, and when the number of requests is greater than a certain traffic threshold, the window size of the cache area is expanded. In this way, the window size of the cache area is adaptively adjusted based on the traffic, that is, the cache area is a sliding window type (the window size is adjustable) to achieve adaptive traffic changes, which can significantly reduce the dependence on external databases and reduce the frequency of interaction with the database, thereby improving the system responsiveness as much as possible. In extreme cases, even if the external database is unavailable for a short period of time, it can also provide ID generation services to the outside world uninterruptedly. The sliding window strategy can adapt to the traffic well, prevent traffic shocks, and reduce program response time jitters caused by traffic fluctuations, thereby ensuring the responsiveness and concurrency of the server.
[0105] Based on the first embodiment and / or the second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the first and second embodiments can be referred to the above description, and will not be described in detail later. On this basis, after the step of receiving the ID generation request, the method further includes:
[0106] Step B10, obtaining the current fuse status of the server, and returning a response exception if the current fuse status indicates that the fuse is turned on;
[0107] It should be noted that the response exception can be sent to the client that initiates the ID generation request.
[0108] Furthermore, alarm information can also be output. Specifically, the alarm can be sent to relevant personnel through multiple channels such as text messages and emails, thereby improving the business of the business system.
[0109] Step B20: If the current fuse state indicates a half-open fuse, or the current fuse state indicates a closed fuse, then continue to execute the step of determining the main cache area in each of the target cache areas.
[0110] In addition, you can also set current limiting rules (also called current limiting strategies) and downgrade rules (also called downgrade strategies). After receiving the ID generation request, the server will first perform a current limiting check and a fuse status judgment. When the current limiting and fuse conditions are met, the current request will be fused, and an abnormal interception response will be quickly given. At the same time, a current limiting and fuse alarm will be issued to avoid entering the subsequent ID generation process and occupying system resources. When the downgrade conditions are met, the ID generation request is downgraded (such as generating the required number of IDs based on UUID) to achieve a downgraded response to the ID generation request. When abnormal traffic or short-term repeated calls occur in individual business scenarios, they can be quickly identified and intercepted, thereby avoiding the impact of abnormal traffic on the overall system performance.
[0111] In a possible implementation manner, before the step of receiving the ID generation request, the method further includes:
[0112] Step C10, obtaining the fuse status of the server;
[0113] It should be noted that the fuse status of the server may include an open state (indicating an open fuse), a half-open state (indicating a half-open fuse), and a closed state (indicating a closed fuse).
[0114] Furthermore, the switching conditions between the three blown fuse states can be set, and when the switching conditions are met, the corresponding blown fuse state is switched.
[0115] Furthermore, the initial fuse state of the server can be set. For example, if the initial fuse state is set to a closed state, relevant personnel can configure it according to actual needs, and no specific restrictions are made here.
[0116] Step C20, if the fuse status indicates that the fuse is closed, after the number of response exceptions within the preset time window is greater than the first preset failure threshold, the fuse status of the server is switched to indicate that the fuse is turned on;
[0117] It should be noted that the number of abnormal responses may refer to the number of abnormal responses of the server. The conditions for determining abnormal responses may be set in advance, such as the ID pool has been used up, the database connection is abnormal, etc., so as to facilitate the counting of the number of abnormal responses.
[0118] It should be noted that the preset time window can be a time window, such as 1 minute, 10 minutes, etc.
[0119] When the fuse status indicates that the fuse is closed, the number of response exceptions within the cycle time can be periodically counted. The number of response exceptions can specifically be the total number of response exceptions or the average number of response exceptions per unit time. This embodiment does not impose any specific restrictions on this.
[0120] Step C30, if the fuse state indicates a semi-open fuse, then after the number of response exceptions within the preset time window is greater than a second preset failure threshold, the fuse state of the server is switched to indicate an open fuse, wherein the second preset failure threshold is less than the first preset failure threshold;
[0121] Similar to when the fuse status indicates that the fuse is closed, when the fuse status indicates that the fuse is half-open, the number of response exceptions within this cycle can be periodically counted. If the number of response exceptions is greater than the second preset threshold, the fuse status of the server is switched to indicate that the fuse is open.
[0122] Furthermore, when the fuse state indicates a half-open fuse, if the number of successful responses within a preset time window is greater than a certain threshold, the fuse state of the server is switched to a closed state.
[0123] Similar to response exception, the number of successful responses can refer to the number of successful responses from the server. You can set the conditions for successful responses in advance, such as successful return ID, to facilitate the counting of successful responses.
[0124] Step C40: If the fuse status indicates that the fuse is turned on, after waiting for a preset period of time, the fuse status of the server is switched to indicate a half-open fuse.
[0125] When the circuit breaker status indicates that the circuit breaker is turned on, after waiting for a preset period of time, the circuit breaker status of the server is switched to indicate a semi-open circuit breaker to avoid the server turning on the circuit breaker for a long time and being unable to respond to the ID generation request in time.
[0126] In this embodiment, when the fuse is in a semi-open state, after a certain number of abnormal responses, the fuse will be converted to an open state; only when the number of successful responses reaches a certain threshold within a certain time window will the fuse be converted from a semi-open state to a closed state. In this conversion process, the abnormal response is quickly blown as much as possible, and the fuse is steadily restored to a stable state, so that the fuse current limiting capability can ensure the system robustness and stability as much as possible in a weak environment, and reduce the consumption of system resources by abnormal requests.
[0127] For example, in order to help understand the technical concept or technical principle of the distributed ID generation method in this embodiment, a specific embodiment is now listed. In this specific embodiment, refer to Figure 4 As shown, the distributed ID generation process is:
[0128] After receiving the ID generation request, the current fuse status of the server is obtained. If the current fuse status indicates that the fuse is open, a fuse response is made. Specifically, a response exception or a downgraded response can be returned. If the current fuse status indicates that the fuse is half-open or closed, the cache area can be accessed normally and an ID is generated based on the cache area.
[0129] In the closed state ( Figure 4 The fuse is closed as shown in the figure), and the number of response exceptions is counted periodically ( Figure 4 If the number of failures is greater than a certain threshold, it switches to the on state ( Figure 4 Fuse open state shown in ).
[0130] In the open state, wait for a preset time and then enter the semi-open state ( Figure 4 The fuse is in the semi-open state shown in the figure), that is, the fuse enters the semi-open state after being blown for a certain period of time.
[0131] In the semi-open state, the number of successful responses and the number of failed responses are periodically counted. If the number of successful responses reaches a certain threshold, the system enters the closed state. If the number of failed responses reaches a certain threshold, the system enters the open state. If both the number of successful responses and the number of failed responses reach the corresponding given thresholds, the system enters the open state or the closed state.
[0132] It should be noted that the above examples are only used to assist in understanding the present application and do not constitute a limitation on the distributed ID generation method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0133] Based on the first embodiment, the second embodiment and / or the third embodiment of the present application, in the fourth embodiment of the present application, the same or similar contents as those in the first embodiment, the second embodiment and the third embodiment can be referred to the above introduction, and will not be described in detail later. On this basis, the step of determining the main cache area in each of the cache areas includes:
[0134] Step D10, obtaining a business scenario according to the ID generation request, and determining a cache area belonging to the business scenario among the cache areas as a target cache area;
[0135] It should be noted that different cache areas may be set corresponding to different business scenarios, and at least one group of cache areas may be set corresponding to each business scenario, and each group of cache areas includes at least two cache areas.
[0136] One or more business scenarios can be set in advance, such as Taobao generating order numbers, JD.com generating order codes, banks generating transaction serial numbers, banks generating user IDs, and many other different business scenarios.
[0137] When the client sends an ID generation request, it can package its business scenario in the ID generation request, so that the business scenario can be read from the corresponding field after decapsulating the ID generation request.
[0138] Step D20, determining the main buffer area in each of the target buffer areas.
[0139] A main buffer area is selected from the target buffer areas corresponding to the business scenario. Specifically, the main buffer area can be a target buffer area currently in working state among the target buffer areas.
[0140] In one possible implementation, the ID includes an ascending sequence field, or the ID includes a service prefix field and an ascending sequence field, or the ID includes a service prefix field, an ascending sequence field and a service suffix field; wherein, in different service scenarios, the field values of the service prefix field and / or the service suffix field are different.
[0141] The field value of the increasing sequence field increases in a specific order, such as increasing in time sequence, increasing in chronological order, etc. Specifically, it can be increased based on a known increasing method, which is not described in detail in this embodiment.
[0142] Preferably, the ID includes a service prefix field and an incremental sequence field, or the ID includes a service prefix field, an incremental sequence field and a service suffix field. The service prefix field and the service suffix field are used to distinguish different service scenarios and add service semantics to the ID sequence.
[0143] In this embodiment, the ID supports multiple sequence modes and universal business scenarios. Each sequence field can be configured as a digital sequence, an uppercase letter sequence, a lowercase letter sequence, and various permutations and combinations of numbers, uppercase and lowercase letters, as well as a configuration sequence initial value according to the business scenario needs. By configuring the initial value method, the existing business ID generation function can be quickly, efficiently and cost-effectively migrated to this service.
[0144] For example, in order to help understand the technical concept or technical principle of the distributed ID generation method after the first embodiment, the second embodiment, the third embodiment and the present embodiment are combined, a specific embodiment is now listed. In this specific embodiment, refer to Figure 5 As shown, the server sets up multiple cache areas ( Figure 5 The multi-level cache area shown in ), sliding window strategy and abnormal traffic identification strategy are used to achieve high-performance generation of distributed IDs.
[0145] The multi-level cache includes each cache area for caching ID ( Figure 5 ), and a dual buffer form of a main cache area and a backup cache area is adopted. When there is no available ID in the working cache area, the hot backup cache area is switched to a new working cache area, that is, the cache area is in hot start mode. In addition, the server asynchronously refreshes the cache area, such as asynchronously obtaining an ID from a preset database and caching it in the cold backup cache area while obtaining an available ID, thereby realizing asynchronous refresh of the cold backup cache area.
[0146] The sliding window strategy includes each cache area dynamically adjusting the window size based on traffic adaptively, and switching between three states: expansion state, contraction state, and stable state.
[0147] Abnormal traffic identification strategies include limiting the flow of requests, and fusing requests or downgrading response requests after identifying abnormal traffic.
[0148] When initializing the server, you can configure the distributed ID generation rules, that is, inject the rules into the server, and configure the retry rules for ID acquisition ( Figure 5 ). Specifically, you can configure the current limiting strategy (such as under what conditions the current is limited), the fuse strategy (such as the switching conditions of the fuse state and how to respond to the ID generation request under each fuse state, etc.), the downgrade strategy (such as under what conditions the response to the ID generation request is downgraded), the alarm strategy (such as whether to output an alarm when responding to an abnormality, the alarm content, the alarm output form, the alarm object, etc.), the traffic adaptation strategy (such as how to adjust the window size of the buffer area), the ID mode (such as the fields contained in the ID), the cycle (such as the cycle for detecting the fuse state, the cycle for detecting the number of available IDs in the working buffer area), and other rules. The retry mechanism includes retry rules for configuring time intervals ( Figure 5 The interval strategy shown in ) and the preset retry stop condition ( Figure 5 The stopping strategy shown in ).
[0149] Furthermore, the server can also output traffic trends, TOP scenarios (TOP business scenarios for accessing server requests to generate IDs), and current limiting and fuse notifications to visualize business trends, and output current limiting alarms, fuse alarms, and ID pool balance alarms to visualize alarm notifications.
[0150] During operation, the server monitors the cache balance, fuse status, number of available IDs, and other status, and pushes alarms when abnormalities are detected.
[0151] It should be noted that the above examples are only used to assist in understanding the present application and do not constitute a limitation of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0152] In addition, an embodiment of the present application also proposes a server, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the distributed ID generation method as described above.
[0153] refer to Figure 6, which shows a schematic diagram of the structure of the server suitable for implementing the embodiment of the present application. The server in the embodiment of the present application may also include but is not limited to mobile terminals such as laptop computers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The server shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0154] like Figure 6 As shown, the server may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which may perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. Various programs and data required for the server operation are also stored in RAM1004. The processing device 1001, ROM1002, and RAM1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems may be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the server to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a server with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0155] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0156] The server provided in the embodiment of the present application adopts the distributed ID generation method in the above embodiment, which can solve the technical problem of distributed ID generation. Compared with the prior art, the beneficial effects of the server provided in the present application are the same as the beneficial effects of the distributed ID generation method provided in the above embodiment, and the other technical features in the server are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0157] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0158] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0159] In addition, to achieve the above-mentioned purpose, an embodiment of the present application also provides a readable storage medium having computer-readable program instructions (ie, a computer program) stored thereon, and the computer-readable program instructions are used to execute the distributed ID generation method in the above-mentioned embodiment.
[0160] The computer-readable storage medium provided in the embodiment of the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0161] The computer-readable storage medium may be included in the server, or may exist independently without being assembled into the server.
[0162] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the server, the server: receives an ID generation request and determines a main cache area among the cache areas; obtains available IDs cached in the main cache area until a preset generation end condition is met, and determines that all the available IDs obtained are generation results; in the process of obtaining the available IDs, if the available number of available IDs cached in the main cache area is less than a preset available threshold, determines a backup cache area among the cache areas, obtains a target number of IDs from a preset database and caches them in the backup cache area; in the process of obtaining the available IDs, if there is no available ID in the main cache area, switches the backup cache area to a new main cache area, and returns to execute the step of obtaining the available IDs cached in the main cache area based on the new main cache area.
[0163] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0164] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0165] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0166] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned distributed ID generation method, and can solve the technical problem of distributed ID generation. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the distributed ID generation method provided in the above-mentioned embodiment, and will not be repeated here.
[0167] In addition, an embodiment of the present application also proposes a computer program product, including a distributed ID generation program, which implements the steps of the distributed ID generation method as described above when executed by a processor.
[0168] The specific implementation methods of the computer program product of the present application are basically the same as the above-mentioned embodiments of the distributed ID generation method, and will not be repeated here.
[0169] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0170] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0171] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software sensor, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, including a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0172] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A distributed ID generation method, characterized in that: The distributed ID generation method is applied to a server, wherein the server is provided with a plurality of cache areas, each of which is used to cache an ID. The distributed ID generation method comprises the following steps: Receiving an ID generation request, and determining a primary buffer area among the buffer areas; Obtain available IDs cached in the main cache area until a preset generation end condition is met, and determine that all the obtained available IDs are generation results; In the process of obtaining the available IDs, if the available number of available IDs cached in the main cache area is less than a preset available threshold, a backup cache area in each of the cache areas is determined, and a target number of IDs are obtained from a preset database and cached in the backup cache area; During the process of obtaining the available ID, if there is no available ID in the primary cache area, the backup cache area is switched to a new primary cache area, and the step of obtaining the available ID cached in the primary cache area is returned based on the new primary cache area.
2. The distributed ID generation method according to claim 1, characterized in that: Before the step of acquiring a target number of IDs from a preset database and caching them in the standby cache area, the method further includes: Obtaining the number of historical ID generation requests received within a preset time window, and obtaining a current window size of the backup cache area; If the request quantity is less than a first preset flow threshold, determining a target quantity based on the current window size, wherein the target quantity is less than the current window size; If the requested quantity is greater than a second preset flow threshold, determining a target quantity based on the current window size, wherein the target quantity is greater than the current window size, and wherein the second preset flow threshold is greater than or equal to the first preset flow threshold; The window size of the standby buffer area is updated to the target number.
3. The distributed ID generation method according to claim 1, characterized in that: The step of determining a main buffer area in each of the buffer areas comprises: Obtaining a business scenario according to the ID generation request, and determining a cache area belonging to the business scenario among the cache areas as a target cache area; A primary buffer area in each of the target buffer areas is determined.
4. The distributed ID generation method according to claim 1, characterized in that: After the step of receiving the ID generation request, the method further includes: Obtain the current fuse status of the server, and if the current fuse status indicates that the fuse is turned on, return a response exception; If the current fuse state indicates a half-open fuse, or the current fuse state indicates a closed fuse, then the step of determining the primary cache area in each of the target cache areas is continued.
5. The distributed ID generation method according to claim 1, characterized in that: Before the step of receiving the ID generation request, the method further includes: Obtain the fuse status of the server; If the fuse status indicates that the fuse is closed, after the number of response exceptions within the preset time window is greater than the first preset failure threshold, the fuse status of the server is switched to indicate that the fuse is turned on; If the fuse state indicates a semi-open fuse, then after the number of response exceptions within the preset time window is greater than a second preset failure threshold, the fuse state of the server is switched to indicate an open fuse, wherein the second preset failure threshold is less than the first preset failure threshold; If the fuse status indicates that the fuse is turned on, then after waiting for a preset period of time, the fuse status of the server is switched to indicate a semi-open fuse.
6. The distributed ID generation method according to claim 1, characterized in that: After the step of obtaining the available ID cached in the primary cache area, the method further includes: In the process of obtaining the available ID, if the primary cache area has no available ID, switching the primary cache area to a new standby cache area; After the step of determining that all the available IDs obtained are generated results, the method further includes: If the number of available IDs cached in the new primary cache area is less than the preset available threshold, the step of acquiring the target number of IDs from the preset database and caching them in the backup cache area is performed based on the new backup cache area.
7. The distributed ID generation method according to any one of claims 1 to 6, characterized in that: The ID includes an ascending sequence field, or the ID includes a service prefix field and an ascending sequence field, or the ID includes a service prefix field, an ascending sequence field and a service suffix field; Among them, in different business scenarios, the field values of the business prefix field and / or the business suffix field are different.
8. A server, characterized in that: The server includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the distributed ID generation method according to any one of claims 1 to 7.
9. A readable storage medium, characterized in that: The readable storage medium is a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the distributed ID generation method according to any one of claims 1 to 7 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the distributed ID generation method according to any one of claims 1 to 7 are implemented.