Serial number generation method, device, electronic device and computer readable medium

By detecting and filling the sequence number pool in the Redis cluster, ensuring the sequence number consistency between the master and slave clusters, the problem of repeated generation of serial numbers caused by Redis cluster delay is solved, and the reliability of the sequence number generation service is improved.

CN113822015BActive Publication Date: 2025-01-14BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010548691.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-16
Publication Date
2025-01-14
Estimated Expiration
2040-06-16

AI Technical Summary

Technical Problem

The delay between the master and slave clusters of the Redis cluster causes repeated generation of serial numbers, and the existing serial number generation service is prone to cause serious business problems in error situations.

Method used

By obtaining the sequence number pool in the container cluster, check whether the sequence numbers of the master cluster and the slave cluster are consistent, and fill in the sequence number when they are consistent, so as to ensure that the sequence numbers filled in the master cluster and the slave cluster are strongly consistent and avoid the sequence number Repeat generation.

Benefits of technology

It effectively avoids repeated generation of serial numbers, improves the accuracy of serial number generation services, and reduces the occurrence of business problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113822015B_ABST
    Figure CN113822015B_ABST
Patent Text Reader

Abstract

The embodiments of the present disclosure provide a method, device, electronic device and computer-readable medium for generating a serial number, the method comprising: obtaining a serial number pool in a container cluster, the container cluster comprising a master cluster and a slave cluster; detecting whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, and filling the serial number in the serial number pool when the serial numbers are consistent; receiving a serial number request, the serial number request comprising a target business key value; matching the serial number pool according to the target business key value, and determining the target serial number pool according to the matching result; obtaining the serial number in the target serial number pool in response to the serial number request. The technical solution provided by the embodiments of the present disclosure can ensure that the serial numbers filled in the master cluster and the slave cluster have strong consistency, thereby avoiding the phenomenon of duplicate generation of serial numbers. When creating a serial number pool, the serial number pool is filled in advance to form an active serial number generation service, which can avoid business problems that are easily caused by passively generated serial numbers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a method and device for generating a serial number, an electronic device, and a computer-readable medium. Background Art

[0002] In application systems involving computer technology, serial number generation service is an indispensable service. To increase the speed of serial number generation, most of them currently use distributed cache frameworks of container clusters (such as Redis cluster, an open source distributed cache framework with multiple cache containers for data access operations) to separate services and couple them to increase reliability and efficiency.

[0003] However, when a delay occurs between the master and slave clusters of the Redis cluster, resulting in a master-slave switch (failover), the serial number will be generated repeatedly due to the communication delay or disconnection between the master and slave clusters. The reason for the duplicate serial number is that the data in the slave cluster lags behind the data in the master cluster due to the delay, resulting in the serial number data being old after the slave is promoted to the master, resulting in the generation of duplicate serial numbers.

[0004] At the same time, the existing serial number generation service is a passive generation operation, which only passively generates a serial number to feedback the serial number request when a serial number request is received. During the serial number request process, if a serial number generation service error is encountered, it will most likely cause serious business problems.

[0005] Therefore, a new method, device, electronic device and computer-readable medium for generating a serial number are needed.

[0006] The above information disclosed in this Background section is only for enhancement of understanding of the background of the present disclosure and therefore it may contain information that does not constitute the prior art that is already known to one of ordinary skill in the art. Summary of the invention

[0007] In view of this, the embodiments of the present disclosure provide a method, device, electronic device and computer-readable medium for generating a serial number, thereby avoiding, at least to a certain extent, the repeated generation of serial numbers in a distributed framework and the business problems easily caused by the passive generation of serial numbers.

[0008] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.

[0009] According to a first aspect of an embodiment of the present disclosure, a method for generating a sequence number is provided, the method comprising: obtaining a sequence number pool in a container cluster, the container cluster comprising a master cluster and a slave cluster;

[0010] Detect whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, and fill the serial numbers in the serial number pool when the serial numbers are consistent; receive a serial number request, the serial number request including a target business key value; match the serial number pool according to the target business key value, and determine the target serial number pool according to the matching result; obtain the serial number in the target serial number pool in response to the serial number request.

[0011] In an exemplary embodiment of the present disclosure, detecting whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, and filling the serial numbers in the serial number pool when the serial numbers are consistent includes: when the number of serial numbers in the serial number pool of the master cluster is less than a preset value, obtaining the largest first serial number data in the serial number pool in the master cluster and the largest second serial number data in the serial number pool in the slave cluster; if the first serial number data is the same as the second serial number data, filling the serial number pool according to the first serial number data; looping through the above two steps, and stopping the loop when the number of serial numbers in the serial number pool in the master cluster is equal to the preset value.

[0012] In an exemplary embodiment of the present disclosure, if the first sequence number data is the same as the second sequence number data, then filling the sequence number pool according to the first sequence number data also includes: if the first sequence number data is different from the second sequence number data, then eliminating the larger one of the first sequence number data and the second sequence number data.

[0013] In an exemplary embodiment of the present disclosure, detecting whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, and filling the serial numbers in the serial number pool when the serial numbers are consistent also includes: if the number of serial numbers in the serial number pool is equal to a preset value, cyclically detecting whether the number of serial numbers in the serial number pool is less than a preset value according to a preset time period.

[0014] In an exemplary embodiment of the present disclosure, matching the target business key value with the serial number pool, and determining the target serial number pool according to the matching result also includes: if the target business key value fails to match the serial number pool, creating the target serial number pool in the container cluster according to the target business key value.

[0015] In an exemplary embodiment of the present disclosure, the method further includes: generating a sequence number pool fill notification after successfully obtaining a sequence number in the target sequence number pool in response to the business request; in response to the sequence number pool fill notification, detecting whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and filling the sequence numbers in the sequence number pool when the sequence numbers are consistent.

[0016] According to a second aspect of an embodiment of the present disclosure, a serial number generating device is proposed, which includes: a serial number pool acquiring module, configured to acquire a serial number pool in a container cluster, the container cluster including a master cluster and a slave cluster; a serial number filling module, configured to detect whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, and to fill the serial number in the serial number pool when the serial numbers are consistent; a business request receiving module, configured to receive a serial number request, the serial number request including a target business key value; a serial number pool determining module, configured to match the serial number pool according to the target business key value, and determine the target serial number pool according to the matching result; a serial number acquiring module, configured to acquire a serial number in the target serial number pool in response to the serial number request.

[0017] In an exemplary embodiment of the present disclosure, the serial number filling module includes: a serial number acquisition unit, configured to acquire the largest first serial number data in the serial number pool in the main cluster and the largest second serial number data in the serial number pool in the slave cluster when the number of serial numbers in the serial number pool of the main cluster is less than a preset value; a serial number filling unit, configured to fill the serial number pool according to the first serial number data if the first serial number data is the same as the second serial number data; and a loop filling unit, configured to loop the above two steps and stop the loop when the number of serial numbers in the serial number pool in the main cluster is equal to a preset value.

[0018] According to the third aspect of an embodiment of the present disclosure, an electronic device is proposed, which includes: one or more processors; a storage device for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement any of the serial number generation methods described above.

[0019] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for generating a serial number as described in any one of the above items is implemented.

[0020] According to the sequence number generation method, device, electronic device and computer-readable medium provided by certain embodiments of the present disclosure, the sequence number pool will be pre-filled with sequence numbers. In the sequence number filling process, firstly check whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and perform the sequence number filling operation when they are consistent, which can ensure that the sequence numbers filled in the master cluster and the slave cluster have strong consistency, thereby avoiding the phenomenon of repeated generation of sequence numbers. When creating a sequence number pool, the sequence number pool is filled in advance to form an active sequence number generation service, which can avoid business problems that are easily caused by passive generation of sequence numbers.

[0021] It is to be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. The drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other drawings can also be obtained based on these drawings without creative work.

[0023] Figure 1 is a system block diagram of a method and device for generating a serial number according to an exemplary embodiment;

[0024] Figure 2 is a flow chart of a method for generating a sequence number according to an exemplary embodiment;

[0025] Figure 3 is a flow chart of a method for generating a sequence number according to an exemplary embodiment;

[0026] Figure 4 is a flow chart of a method for generating a sequence number according to an exemplary embodiment;

[0027] Figure 5 is a flow chart of a method for generating a sequence number according to another exemplary embodiment;

[0028] Figure 6 is a block diagram of a serial number generating device according to an exemplary embodiment;

[0029] Figure 7 is a block diagram of an electronic device according to an exemplary embodiment;

[0030] Figure 8 The present invention is a schematic diagram showing a computer-readable storage medium according to an exemplary embodiment. DETAILED DESCRIPTION

[0031] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that the present invention will be comprehensive and complete and fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.

[0032] The described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present invention. However, those skilled in the art will appreciate that the technical solution of the present invention may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring various aspects of the present invention.

[0033] The accompanying drawings are only schematic illustrations of the present invention, and the same reference numerals in the drawings represent the same or similar parts, so their repeated description will be omitted. Some block diagrams shown in the accompanying drawings do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0034] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and steps, nor must they be executed in the order described. For example, some steps can be decomposed, and some steps can be combined or partially combined, so the actual execution order may change according to actual conditions.

[0035] Exemplary embodiments of the present invention will be described in detail below with reference to the accompanying drawings.

[0036] Figure 1 The present invention is a system block diagram showing a method and device for generating a serial number according to an exemplary embodiment.

[0037] The server 105 may be a server that provides various services, such as a background management server (only an example) that provides support for the serial number generation system operated by the user using the terminal devices 101, 102, and 103. The background management server may analyze and process the received data such as the serial number request, and feed back the processing result (such as the serial number obtained in the target serial number pool - only an example) to the terminal device.

[0038] The server 105 may, for example, obtain a sequence number pool in a container cluster, the container cluster including a master cluster and a slave cluster. The server 105 may, for example, detect whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and fill the sequence numbers in the sequence number pool when the sequence numbers are consistent. The server 105 may, for example, receive a sequence number request, the sequence number request including a target business key value. The server 105 may, for example, match the sequence number pool according to the target business key value, and determine the target sequence number pool according to the matching result. The server 105 may, for example, obtain a sequence number in the target sequence number pool according to the sequence number request.

[0039] The server 105 may be a physical server, or may be composed of a plurality of servers, a portion of the server 105 may be used as a serial number generation task submission system in the present disclosure, for obtaining a task to execute a serial number request command; and a portion of the server 105 may be used as a serial number generation system in the present disclosure, for obtaining a serial number pool in a container cluster, the container cluster including a master cluster and a slave cluster; detecting whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, and filling the serial number in the serial number pool when the serial numbers are consistent; receiving a serial number request, the serial number request including a target business key value; matching the target business key value with the serial number pool, and determining the target serial number pool according to the matching result; and obtaining a serial number in the target serial number pool according to the serial number request.

[0040] According to the sequence number generation method and device provided by the embodiment of the present disclosure, the sequence number pool will be pre-filled with sequence numbers. During the sequence number filling process, firstly check whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and perform the sequence number filling operation when they are consistent, which can ensure that the sequence numbers filled in the master cluster and the slave cluster have strong consistency, thereby avoiding the phenomenon of repeated generation of sequence numbers. When creating a sequence number pool, the sequence number pool is filled in advance to form an active sequence number generation service, which can avoid business problems that are easily caused by passive generation of sequence numbers.

[0041] Figure 2 1 is a flowchart of a method for generating a serial number according to an exemplary embodiment. The method for generating a serial number provided in the embodiment of the present disclosure can be executed by any electronic device with computing and processing capabilities, such as terminal devices 101, 102, 103 and / or server 105. In the following embodiments, the server execution method is used as an example for illustration, but the present disclosure is not limited thereto. The method for generating a serial number 20 provided in the embodiment of the present disclosure can include steps S202 to S208.

[0042] like Figure 2 As shown, in step S201, a serial number pool in a container cluster is obtained, and the container cluster includes a master cluster and a slave cluster.

[0043] In the embodiment of the present disclosure, the container cluster may be, for example, a Redis cluster. A Redis cluster is a collection of multiple Redis instances, which are usually deployed on different network ends. The container cluster includes a master cluster and a slave cluster, and the master cluster and the slave cluster communicate with each other through the network.

[0044] In step S202, it is detected whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and the sequence numbers are filled in the sequence number pools if the sequence numbers are consistent.

[0045] In the disclosed embodiment, when detecting whether the sequence numbers in the sequence number pools of the main cluster and the slave cluster are consistent, the largest sequence number can be obtained in the sequence number pool of the main cluster, the largest sequence number can be obtained in the sequence number pool of the slave cluster, and it can be determined whether the largest sequence number obtained in the main cluster and the largest sequence number obtained from the slave cluster are consistent. And when they are consistent, the sequence number is filled in the sequence number pool. The filled sequence number can be incremented according to the largest sequence number obtained in the main cluster (that is, the largest sequence number obtained from the slave cluster) to generate a sequence number for filling. Before filling the sequence number, by checking whether the sequence numbers in the sequence number pools of the main cluster and the slave cluster are consistent, the sequence number filling operation is performed only when they are consistent, which can ensure the strong consistency of the written sequence number, thereby avoiding the phenomenon of repeated generation of sequence numbers.

[0046] In step S203, a sequence number request is received, where the sequence number request includes a target service key.

[0047] In the disclosed embodiment, the requester of the serial number request may be a client or a service interface. The serial number request is used to request to apply for a serial number generated in a serial number pool. The target business key value is used to identify the business category corresponding to the serial number request. The business category may be, for example, but not limited to, a coupon serial number business, an order serial number business, etc.

[0048] In step S204, a match is performed between the target service key value and the sequence number pool, and a target sequence number pool is determined according to the matching result.

[0049] In the disclosed embodiment, the target business key value and the sequence number pool may be in a corresponding relationship, and each sequence number pool corresponds to a unique target business key value. When a container cluster (such as a Redis cluster) receives a sequence number request, it determines that the sequence number pool corresponding to the target business key value in the sequence number request is the target sequence number pool.

[0050] In an exemplary embodiment, if the target business key value fails to match the sequence number pool, a target sequence number pool is created in the container cluster according to the target business key value. The operations of steps S201 to S202 in the embodiment of the present disclosure may also be performed on the created target sequence number pool to implement a filling operation on the target sequence number pool.

[0051] In step S205, a sequence number is obtained from a target sequence number pool in response to the sequence number request.

[0052] In an exemplary embodiment, if the acquisition of a sequence number in the target sequence number pool in response to a sequence number request fails, a request queue is generated according to the sequence number request to wait and acquire a sequence number in the target sequence number pool according to the request queue. When the sequence numbers in the sequence number pool are used up but new sequence numbers cannot be generated (for example, during the failover process of the master-slave cluster), the sequence number request can be blocked on the sequence number pool, etc., until the failover is completed and the sequence number request in the request queue is continued to be acquired in the sequence number pool. This will avoid the occurrence of large-scale sequence number request failures due to the unavailability of the container cluster.

[0053] The sequence number generation method provided by the embodiment of the present disclosure will pre-fill the sequence number pool. During the sequence number filling process, firstly check whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and perform the sequence number filling operation when they are consistent, which can ensure that the sequence numbers filled in the master cluster and the slave cluster have strong consistency, thereby avoiding the phenomenon of duplicate generation of sequence numbers. When creating a sequence number pool, the sequence number pool is filled in advance to form an active sequence number generation service, which can avoid business problems that are easily caused by passive generation of sequence numbers.

[0054] Figure 3 The flowchart of a method for generating a serial number according to an exemplary embodiment is shown. The method 30 for generating a serial number provided in the embodiment of the present disclosure may include steps S301 to S304.

[0055] like Figure 3 As shown, in step S301, a serial number pool in a container cluster is obtained, and the container cluster includes a master cluster and a slave cluster.

[0056] In step S302, when the number of sequence numbers in the sequence number pool of the master cluster is less than a preset value, the largest first sequence number data in the sequence number pool of the master cluster and the largest second sequence number data in the sequence number pool of the slave cluster are obtained.

[0057] In the embodiment of the present disclosure, the preset value refers to the maximum number of sequence numbers that can be stored in the sequence number pool. The preset value can be determined according to relevant parameters when the sequence number pool is created, or can be adjusted and determined according to actual conditions, and the present disclosure does not make any special restrictions on this.

[0058] In an exemplary embodiment, if the number of sequence numbers in the sequence number pool is equal to a preset value, the number of sequence numbers in the sequence number pool is cyclically detected according to a preset time period to see whether it is less than the preset value. The preset time period may be 2s, but the present disclosure is not limited thereto. In this embodiment, by cyclically detecting the number in the sequence number pool, the active generation function of the sequence number service can be realized, and the availability of the sequence number resources is guaranteed with the greatest possibility, avoiding the business problems that are easily caused by the passive generation of sequence numbers.

[0059] In step S303, if the first sequence number data is the same as the second sequence number data, the sequence number pool is filled according to the first sequence number data.

[0060] In the disclosed embodiment, the first sequence number data (i.e., the second sequence number data in this embodiment) can be incremented to generate a new sequence number, and the new sequence number is filled into the sequence number pool. In this embodiment, when it is determined that the first sequence number data is the same as the second sequence number data, the sequence number pool is filled, which can ensure the strong consistency of the sequence number data in the master cluster and the slave cluster. There will be no duplication of sequence numbers, which improves the accuracy of the sequence number generation service.

[0061] In step S304, the above steps S302 to S303 are executed in a loop, and the loop is stopped when the number of sequence numbers in the sequence number pool in the main cluster is equal to a preset value.

[0062] In the disclosed embodiment, by cyclically executing the consistency check operation of the sequence numbers in the master cluster and the slave cluster and the sequence number pool filling operation, the sequence number pool can be filled while ensuring the consistency of the sequence numbers in the master and slave clusters, thereby ensuring the accuracy of the sequence number resources in the sequence number pool.

[0063] In an exemplary embodiment, the serial number generating method S303 provided based on the above embodiment may further include the following steps S3031.

[0064] In step S3031, if the first sequence number data is different from the second sequence number data, the larger one of the first sequence number data and the second sequence number data is eliminated.

[0065] In this embodiment, since inconsistent data in the master cluster and the slave cluster is removed, the strong consistency of the sequence numbers in the master cluster and the slave cluster can be guaranteed. Even if a failover occurs in the container cluster and the slave cluster replaces the master cluster, due to the consistency of the master and slave data, duplicate sequence numbers will not be generated. A set of automatic disaster recovery sequence number generation solutions is provided to ensure the accuracy of sequence number resources.

[0066] In an exemplary embodiment, step S3031 may include: if the first sequence number data is greater than the second sequence number data, then removing the first sequence number data from the main cluster; if the first sequence number data is less than the second sequence number data, then removing the second sequence number data from the main cluster.

[0067] In an exemplary embodiment, the serial number generation method S301 to S304 provided based on the above embodiments may further include the following steps S305 to S307.

[0068] In step S305, a sequence number request is received, where the sequence number request includes a target service key value.

[0069] In step S306, the target service key value is matched with the sequence number pool, and the target sequence number pool is determined according to the matching result.

[0070] In step S307, a sequence number is obtained from a target sequence number pool according to the sequence number request.

[0071] Figure 4 4 is a flowchart of a method for generating a serial number according to an exemplary embodiment. The method 40 for generating a serial number provided in the embodiment of the present disclosure may include steps S401 to S407.

[0072] In step S401, a serial number pool in a container cluster is obtained, where the container cluster includes a master cluster and a slave cluster.

[0073] In step S402, it is detected whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and the sequence numbers are filled in the sequence number pools if the sequence numbers are consistent.

[0074] In step S403, a sequence number request is received, where the sequence number request includes a target service key value.

[0075] In step S404, the target service key value is matched with the sequence number pool, and the target sequence number pool is determined according to the matching result.

[0076] In step S405, a sequence number is obtained from a target sequence number pool in response to the sequence number request.

[0077] In step S406, after successfully acquiring a sequence number from the target sequence number pool in response to the service request, a sequence number pool filling notification is generated.

[0078] In step S407 , in response to the sequence number pool filling notification, it is detected whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and the sequence numbers are filled in the sequence number pools if the sequence numbers are consistent.

[0079] In the embodiment of the present disclosure, after receiving the sequence number filling notification, the operations of steps S401 to S402 may be performed according to the sequence number filling notification to complete the filling operation of the sequence number pool.

[0080] According to the sequence number generation method provided by the embodiment of the present disclosure, after successfully obtaining the sequence number in the target sequence number pool in response to the service request, the sequence number pool is filled according to the generated sequence number filling notification, which can further realize the active filling function of the sequence number and avoid the business problems easily caused by the passive generation of sequence numbers. In the filling process, firstly check whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and perform the filling sequence number operation when they are consistent, which can ensure that the sequence numbers filled in the master cluster and the slave cluster have strong consistency, thereby avoiding the phenomenon of repeated generation of sequence numbers.

[0081] It should be clearly understood that the present disclosure describes how to form and use specific examples, but the principles of the present disclosure are not limited to any details of these examples. On the contrary, based on the teachings of the contents disclosed in the present disclosure, these principles can be applied to many other embodiments.

[0082] Figure 5 1 is a flowchart of a method for generating a sequence number according to another exemplary embodiment. The method for generating a sequence number 50 at least includes steps S501 to S510. Steps S501 to S504 can be encapsulated in a child thread, and the operations of steps S501 to S504 are performed by receiving notifications from the main thread.

[0083] like Figure 5 As shown, in step S501, a serial number pool in a container cluster is obtained, and the container cluster includes a master cluster and a slave cluster.

[0084] In the embodiment of the present disclosure, the sequence number pool in the container cluster may be created according to the target business key value, or may be at least one sequence number pool created before the sequence number request is obtained.

[0085] In step S502, when the number of sequence numbers in the sequence number pool of the master cluster is less than a preset value, the largest first sequence number data in the sequence number pool of the master cluster and the largest second sequence number data in the sequence number pool of the slave cluster are obtained.

[0086] In step S503, if the first sequence number data and the second sequence number data are the same, the sequence number pool is filled according to the first sequence number data; if the first sequence number data and the second sequence number data are different, the larger one of the first sequence number data and the second sequence number data is removed.

[0087] Among them, when the first sequence number data and the second sequence number data are different, if the first sequence number data is greater than the second sequence number data, the first sequence number data is removed from the main cluster; if the first sequence number data is less than the second sequence number data, the second sequence number data is removed from the main cluster.

[0088] In step S504, step S502 to step S503 are executed in a loop, and the loop is stopped when the number of sequence numbers in the sequence number pool in the main cluster is equal to a preset value.

[0089] In an exemplary embodiment, step S504 may be performed after sleeping for 2 seconds.

[0090] When the number of serial numbers in the serial number pool is equal to a preset value, the number of serial numbers in the serial number pool is detected according to a preset time period to see whether it is less than the preset value, and when the number of serial numbers in the serial number pool is less than the preset value, the process returns to execute steps S502 to S504. The preset time period may be, for example but not limited to, 2s.

[0091] In step S505, a sequence number request is received, where the sequence number request includes a target service key value.

[0092] In step S506, a target serial number pool is obtained by matching the target business key value with the serial number pool in the container cluster. If the match is successful, step S508 is executed, otherwise step S507 is executed.

[0093] In step S507, a target sequence number pool is created in the container cluster according to the target business key value.

[0094] In the embodiment of the present disclosure, after the target sequence number pool is created, steps S501 to S504 may be executed to fill the created target sequence number pool.

[0095] In step S508, a sequence number is obtained from a target sequence number pool in response to the sequence number request.

[0096] In step S509, after successfully acquiring a sequence number from the target sequence number pool in response to the service request, a sequence number pool filling notification is generated.

[0097] In an exemplary embodiment, if the acquisition of a sequence number in the target sequence number pool in response to a sequence number request fails, a request queue is generated according to the sequence number request to block and wait in the target sequence number pool according to the request queue and retry to acquire the sequence number.

[0098] In step S510 , in response to the sequence number pool filling notification, it is detected whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and the sequence numbers are filled in the sequence number pools if the sequence numbers are consistent.

[0099] In the embodiment of the present disclosure, after receiving the sequence number pool filling notification, steps S502 to S504 may be executed according to the sequence number filling notification to implement the active filling function of the sequence number.

[0100] Those skilled in the art will appreciate that all or part of the steps for implementing the above embodiments are implemented as a computer program executed by a central processing unit (CPU). When the computer program is executed by the central processing unit (CPU), the above functions defined by the above method provided by the present disclosure are executed. The program may be stored in a computer-readable storage medium, which may be a read-only memory, a disk or an optical disk, etc.

[0101] In addition, it should be noted that the above figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.

[0102] The following are embodiments of the device disclosed herein, which can be used to execute the method embodiments disclosed herein. For details not disclosed in the device embodiments disclosed herein, please refer to the method embodiments disclosed herein.

[0103] Figure 6 is a block diagram of a serial number generating device according to an exemplary embodiment. Figure 6 The sequence number generating device 60 provided in the embodiment of the present disclosure may include: a sequence number pool acquiring module 601, a sequence number filling module 602, a request receiving module 603, a sequence number pool determining module 604 and a sequence number acquiring module 605.

[0104] In the serial number generating device 60 , the serial number pool obtaining module 601 may be configured to obtain a serial number pool in a container cluster, where the container cluster includes a master cluster and a slave cluster.

[0105] The sequence number filling module 602 may be configured to detect whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and fill the sequence numbers in the sequence number pools when the sequence numbers are consistent.

[0106] In an exemplary embodiment, the sequence number filling module 602 may include a sequence number acquisition unit, a sequence number filling unit, and a loop filling unit. The sequence number acquisition unit is configured to acquire the largest first sequence number data in the sequence number pool in the master cluster and the largest second sequence number data in the sequence number pool in the slave cluster when the number of sequence numbers in the sequence number pool of the master cluster is less than a preset value. The sequence number filling unit is configured to fill the sequence number pool according to the first sequence number data if the first sequence number data is the same as the second sequence number data. The loop filling unit is configured to loop through the above two steps and stop the loop when the number of sequence numbers in the sequence number pool in the master cluster is equal to the preset value.

[0107] In an exemplary embodiment, the sequence number filling module 602 may further include a data elimination unit configured to eliminate the larger data of the first sequence number data and the second sequence number data if the first sequence number data is different from the second sequence number data.

[0108] In an exemplary embodiment, the data elimination unit may include a first elimination subunit and a second elimination subunit. The first elimination subunit may be configured to eliminate the first sequence number data in the main cluster if the first sequence number data is greater than the second sequence number data. The second elimination subunit may be configured to eliminate the second sequence number data in the main cluster if the first sequence number data is less than the second sequence number data.

[0109] In an exemplary embodiment, the sequence number filling module 602 may further include a period detection unit, which may be configured to cyclically detect whether the number of sequence numbers in the sequence number pool is less than a preset value according to a preset time period if the number of sequence numbers in the sequence number pool is equal to a preset value.

[0110] The service request receiving module 603 may be configured to receive a sequence number request, where the sequence number request includes a target service key value.

[0111] The sequence number pool determination module 604 may be configured to match the target service key value with the sequence number pool, and determine the target sequence number pool according to the matching result.

[0112] In an exemplary embodiment, the sequence number pool determination module 604 may further include a sequence number pool creation unit, which may be configured to create a target sequence number pool in the container cluster according to the target business key value if the target business key value fails to match the sequence number pool.

[0113] The sequence number acquisition module 605 may be configured to acquire a sequence number from a target sequence number pool in response to a sequence number request.

[0114] In an exemplary embodiment, the sequence number generating device 60 may further include a filling notification generating module and a sequence number active filling module. The filling notification generating module may be configured to generate a sequence number pool filling notification after successfully obtaining a sequence number in the target sequence number pool in response to a service request. The sequence number active filling module may be configured to detect whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent in response to the sequence number pool filling notification, and fill the sequence number in the sequence number pool when the sequence numbers are consistent.

[0115] According to the sequence number generating device provided by the embodiment of the present disclosure, the sequence number pool will be pre-filled with sequence numbers. During the sequence number filling process, firstly, it is detected whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and the sequence number filling operation is performed when they are consistent, which can ensure that the sequence numbers filled in the master cluster and the slave cluster have strong consistency, thereby avoiding the phenomenon of repeated generation of sequence numbers. When creating a sequence number pool, the sequence number pool is filled in advance to form an active sequence number generation service, which can avoid business problems that are easily caused by passive generation of sequence numbers.

[0116] Figure 7 It is a block diagram of an electronic device according to an exemplary embodiment.

[0117] Refer to the following Figure 7 The electronic device 200 according to this embodiment of the present disclosure is described. Figure 7 The electronic device 200 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0118] like Figure 7 As shown, the electronic device 200 is in the form of a general computing device. The components of the electronic device 200 may include, but are not limited to: at least one processing unit 210, at least one storage unit 220, a bus 230 connecting different system components (including the storage unit 220 and the processing unit 210), a display unit 240, etc.

[0119] The storage unit stores a program code, which can be executed by the processing unit 210, so that the processing unit 210 executes the steps according to various exemplary embodiments of the present disclosure described in the electronic prescription circulation processing method section of this specification. For example, the processing unit 210 can execute the following steps: Figure 2 , Figure 3 , Figure 4 , Figure 5 Follow the steps shown in .

[0120] The storage unit 220 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 2201 and / or a cache memory unit 2202 , and may further include a read-only memory unit (ROM) 2203 .

[0121] The storage unit 220 may also include a program / utility 2204 having a set (at least one) of program modules 2205, such program modules 2205 including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include the implementation of a network environment.

[0122] Bus 230 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0123] The electronic device 200 may also communicate with one or more external devices 300 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 200, and / or communicate with any device that enables the electronic device 200 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 250. Furthermore, the electronic device 200 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 260. The network adapter 260 may communicate with other modules of the electronic device 200 via the bus 230. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 200, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0124] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, or a network device, etc.) to execute the above method according to the implementation of the present disclosure.

[0125] Figure 8 A schematic diagram of a computer-readable storage medium in an exemplary embodiment of the present disclosure is schematically shown.

[0126] refer to Figure 8 As shown, a program product 400 for implementing the above method according to an embodiment of the present disclosure is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0127] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0128] The computer readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by an instruction execution system, an apparatus, or a device or used in combination with it. The program code contained on the readable storage medium may be transmitted with any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above.

[0129] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0130] The computer-readable medium carries one or more programs. When the one or more programs are executed by a device, the computer-readable medium implements the following functions: obtaining a serial number pool in a container cluster, the container cluster includes a master cluster and a slave cluster; detecting whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, and filling the serial numbers in the serial number pool when the serial numbers are consistent; receiving a serial number request, the serial number request including a target business key value; matching the serial number pool according to the target business key value, and determining the target serial number pool according to the matching result; and obtaining a serial number in the target serial number pool in response to the serial number request.

[0131] Those skilled in the art will appreciate that the above modules can be distributed in the device according to the description of the embodiment, or can be changed accordingly and only used in one or more devices different from the embodiment. The modules of the above embodiments can be combined into one module, or further divided into multiple sub-modules.

[0132] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the embodiment of the present disclosure.

[0133] The exemplary embodiments of the present disclosure are specifically shown and described above. It should be understood that the present disclosure is not limited to the detailed structures, configurations or implementations described herein; on the contrary, the present disclosure is intended to cover various modifications and equivalent configurations included in the spirit and scope of the appended claims.

Claims

1. A method for generating a sequence number, characterized in that: include: Obtain a sequence number pool in a container cluster, where the container cluster includes a master cluster and a slave cluster; Detect whether the sequence numbers in the sequence number pool of the master cluster and the slave cluster are consistent, and fill the sequence numbers in the sequence number pool when the sequence numbers are consistent, so as to form a sequence number active generation service; receiving a sequence number request, wherein the sequence number request includes a target service key value; Matching the target service key value with the sequence number pool, and determining the target sequence number pool according to the matching result; A sequence number is obtained from the target sequence number pool in response to the sequence number request.

2. The method according to claim 1, characterized in that: Detecting whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and filling the sequence numbers in the sequence number pool when the sequence numbers are consistent includes: When the number of sequence numbers in the sequence number pool of the master cluster is less than a preset value, obtaining the largest first sequence number data in the sequence number pool in the master cluster and the largest second sequence number data in the sequence number pool in the slave cluster; If the first sequence number data is the same as the second sequence number data, filling the sequence number pool according to the first sequence number data; The above two steps are executed in a loop, and the loop is stopped when the number of sequence numbers in the sequence number pool in the main cluster is equal to a preset value.

3. The method according to claim 2, characterized in that If the first sequence number data is the same as the second sequence number data, filling the sequence number pool according to the first sequence number data further includes: If the first sequence number data is different from the second sequence number data, the larger one of the first sequence number data and the second sequence number data is eliminated.

4. The method according to claim 2, characterized in that Detecting whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and filling the sequence numbers in the sequence number pool when the sequence numbers are consistent also includes: If the number of sequence numbers in the sequence number pool is equal to a preset value, it is cyclically detected according to a preset time period whether the number of sequence numbers in the sequence number pool is less than a preset value.

5. The method according to claim 1, characterized in that Matching the target service key value with the sequence number pool, and determining the target sequence number pool according to the matching result further includes: If the target business key value fails to match the sequence number pool, the target sequence number pool is created in the container cluster according to the target business key value.

6. The method according to claim 1, characterized in that Also includes: After successfully acquiring a sequence number from the target sequence number pool in response to the service request, generating a sequence number pool filling notification; In response to the sequence number pool filling notification, it is detected whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and the sequence numbers are filled in the sequence number pools when the sequence numbers are consistent.

7. A serial number generating device, characterized in that: include: A sequence number pool acquisition module is configured to acquire a sequence number pool in a container cluster, wherein the container cluster includes a master cluster and a slave cluster; A sequence number filling module is configured to detect whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and fill the sequence numbers in the sequence number pools when the sequence numbers are consistent, so as to form a sequence number active generation service; A service request receiving module, configured to receive a sequence number request, wherein the sequence number request includes a target service key value; A sequence number pool determination module, configured to match the target business key value with the sequence number pool, and determine a target sequence number pool according to the matching result; The sequence number acquisition module is configured to acquire a sequence number from the target sequence number pool in response to the sequence number request.

8. The device according to claim 7, characterized in that The serial number filling module includes: A sequence number acquisition unit, configured to acquire the largest first sequence number data in the sequence number pool in the master cluster and the largest second sequence number data in the sequence number pool in the slave cluster when the number of sequence numbers in the sequence number pool of the master cluster is less than a preset value; a sequence number filling unit, configured to, if the first sequence number data is the same as the second sequence number data, fill the sequence number pool according to the first sequence number data; The loop filling unit is configured to loop through the above two steps and stop the loop when the number of sequence numbers in the sequence number pool in the main cluster is equal to a preset value.

9. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.

10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Redis-based serial number generation method and device

    CN110457059A

  • Method for generating globally unique serial number

    CN110674187A