CN113822015A - Serial number generation method and device, electronic equipment and computer readable medium - Google Patents

Serial number generation method and device, electronic equipment and computer readable medium Download PDF

Info

Publication number
CN113822015A
CN113822015A CN202010548691.4A CN202010548691A CN113822015A CN 113822015 A CN113822015 A CN 113822015A CN 202010548691 A CN202010548691 A CN 202010548691A CN 113822015 A CN113822015 A CN 113822015A
Authority
CN
China
Prior art keywords
serial number
serial
pool
cluster
sequence number
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010548691.4A
Other languages
Chinese (zh)
Inventor
石朝阳
赵辉
任银龙
张衡
李品
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202010548691.4A priority Critical patent/CN113822015A/en
Publication of CN113822015A publication Critical patent/CN113822015A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/126Character encoding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0796Safety measures, i.e. ensuring safe condition in the event of error, e.g. for controlling element

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Quality & Reliability (AREA)
  • Retry When Errors Occur (AREA)

Abstract

The embodiment of the disclosure provides a serial number generation method, a serial number generation device, electronic equipment and a computer readable medium, wherein the method comprises the following steps: acquiring a serial number pool in a container cluster, wherein the container cluster comprises 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 pools when the serial numbers are consistent; receiving a sequence number request, wherein the sequence number request comprises a target business key value; matching the target service key value with the serial number pool, and determining the target serial number pool according to a matching result; a sequence number is obtained in the target sequence number pool in response to the sequence number request. The technical scheme provided by the embodiment of the disclosure can ensure that the serial numbers filled in the master cluster and the slave cluster have strong consistency, thereby avoiding the occurrence of the phenomenon of repeated generation of the serial numbers. When the serial number pool is created, the serial number pool is filled in advance to form a serial number active generation service, so that the service problem easily caused by passive serial number generation can be avoided.

Description

Serial number generation method and device, electronic equipment and computer readable medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for generating a serial number, an electronic device, and a computer-readable medium.
Background
In an application system involving computer technology, a serial number generation service is an indispensable service. In order to increase the generation speed of the serial number, at present, a distributed cache framework of a container cluster (for example, a Redis cluster, an open-source distributed cache framework, and a plurality of built-in cache containers for data access operations) is mostly adopted to separate services, and contact coupling is performed to increase reliability and efficiency.
However, when a delay occurs between the master and slave clusters of the Redis cluster to cause a master-slave switching (failover), a sequence number is repeatedly generated due to a communication delay or a communication disconnection between the master and slave clusters. Sequence number duplication occurs because data in the slave cluster lags data in the master cluster due to latency, resulting in the data of the sequence number being old after the slave is referenced as the master, resulting in the generation of duplicate sequence numbers.
Meanwhile, the existing sequence number generation service belongs to a passive generation operation, and a sequence number is only passively generated to feed back a sequence number request when the sequence number request is received. In the sequence number request process, if a sequence number generation service error is encountered, serious business problems can be caused at a high probability.
Therefore, a new serial number generation method, apparatus, electronic device, and computer readable medium are needed.
The above information disclosed in this background section is only for enhancement of understanding of the background of the disclosure and therefore it may contain information that does not constitute prior art that is already known to a person of ordinary skill in the art.
Disclosure of Invention
In view of this, embodiments of the present disclosure provide a method and an apparatus for generating a serial number, an electronic device, and a computer-readable medium, so as to avoid, at least to a certain extent, a service problem easily caused by repeated generation of a serial number and passive generation of a serial number in a distributed framework.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows, or in part will be obvious from the description, or may be learned by practice of the disclosure.
According to a first aspect of the embodiments of the present disclosure, a method for generating a sequence number is provided, where the method includes: acquiring a serial number pool in a container cluster, wherein the container cluster comprises 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 or not, and filling the serial numbers in the serial number pools when the serial numbers are consistent; receiving a sequence number request, wherein the sequence number request comprises a target business key value; matching the target service key value with the serial number pool, and determining the target serial number pool according to a matching result; obtaining a sequence number in the target sequence number pool in response to the sequence number request.
In an exemplary embodiment of the present disclosure, detecting whether sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and filling sequence numbers in the sequence number pools when the sequence numbers are consistent includes: when the number of serial numbers in the serial number pool of the master cluster is smaller than a preset value, acquiring the largest first serial number data in the serial number pool of the master cluster and the largest second serial number data in the serial number pool of 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; and circularly executing the two steps, and stopping circulation when the number of the serial numbers in the serial number pool in the main cluster is equal to a preset value.
In an exemplary embodiment of the present disclosure, if the first sequence number data is the same as the second sequence number data, the filling the sequence number pool according to the first sequence number data further includes: and if the first serial number data is different from the second serial number data, removing larger data in the first serial number data and the second serial number data.
In an exemplary embodiment of the present disclosure, detecting whether sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and filling sequence numbers in the sequence number pools when the sequence numbers are consistent further includes: and if the number of the serial numbers in the serial number pool is equal to a preset value, circularly detecting whether the number of the serial numbers in the serial number pool is smaller than the preset value according to a preset time period.
In an exemplary embodiment of the present disclosure, 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: and if the matching of the target business key value and the serial number pool fails, establishing the target serial number pool in a container cluster according to the target business key value.
In an exemplary embodiment of the present disclosure, the method further comprises: after the service request is responded and the serial number is successfully obtained in the target serial number pool, generating a serial number pool filling notice; and responding to the serial number pool filling notification, 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 pools when the serial numbers are consistent.
According to a second aspect of the embodiments of the present disclosure, there is provided a serial number generation apparatus, including: the serial number pool acquisition module is configured to acquire a serial number pool in a container cluster, and the container cluster comprises a master cluster and a slave cluster; a serial number filling module configured to detect whether 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 pools when the serial numbers are consistent; a service request receiving module configured to receive a sequence number request, the sequence number request including a target service key value; a serial number pool determining module configured to match the target service key value with the serial number pool and determine the target serial number pool according to a matching result; a sequence number acquisition module configured to acquire a sequence number in the target sequence number pool in response to the sequence number request.
In an exemplary embodiment of the present disclosure, the sequence number padding module includes: a serial number obtaining unit, configured to obtain, when the number of serial numbers in the serial number pool of the master cluster is smaller than a preset value, a first serial number data that is the largest in the serial number pool of the master cluster and a second serial number data that is the largest in the serial number pool of the slave cluster; a serial number filling unit configured to perform a filling operation on 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 the circulating filling unit is configured to circularly execute the two steps and stop circulating when the number of the serial numbers in the serial number pool in the main cluster is equal to a preset value.
According to a third aspect of the embodiments of the present disclosure, an electronic device is provided, which includes: one or more processors; storage means for storing one or more programs; when executed by the one or more processors, cause the one or more processors to implement the method for serial number generation as described in any one of the above.
According to a fourth aspect of embodiments of the present disclosure, a computer-readable medium is proposed, on which a computer program is stored, which when executed by a processor implements the serial number generation method according to any one of the above.
According to the serial number generation method, the serial number generation device, the electronic device and the computer readable medium provided by some embodiments of the present disclosure, serial number filling is performed on a serial number pool in advance. In the serial number filling process, whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent or not is detected, and the operation of filling the serial numbers is executed when the serial numbers are consistent, so that the strong consistency of the serial numbers filled in the master cluster and the slave cluster can be ensured, and the phenomenon of repeated generation of the serial numbers is avoided. When the serial number pool is created, the serial number pool is filled in advance to form a serial number active generation service, so that the service problem easily caused by passive serial number generation can be avoided.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure. The drawings described below are merely some embodiments of the present disclosure, and other drawings may be derived from those drawings by those of ordinary skill in the art without inventive effort.
FIG. 1 is a system block diagram illustrating a method and apparatus for serial number generation in accordance with an exemplary embodiment;
FIG. 2 is a flow diagram illustrating a method of sequence number generation in accordance with an exemplary embodiment;
FIG. 3 is a flow diagram illustrating a method of sequence number generation in accordance with an exemplary embodiment;
FIG. 4 is a flow diagram illustrating a method of sequence number generation in accordance with an exemplary embodiment;
FIG. 5 is a flow diagram illustrating a method of sequence number generation in accordance with another illustrative embodiment;
FIG. 6 is a block diagram illustrating a serial number generation apparatus in accordance with an exemplary embodiment;
FIG. 7 is a block diagram illustrating an electronic device in accordance with an exemplary embodiment;
FIG. 8 is a schematic diagram illustrating a computer-readable storage medium according to an example embodiment.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The same reference numerals denote the same or similar parts in the drawings, and thus, a repetitive description thereof will be omitted.
The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to provide a thorough understanding of embodiments of the invention. One skilled in the relevant art will recognize, however, that the invention may be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known methods, devices, implementations or operations have not been shown or described in detail to avoid obscuring aspects of the invention.
The drawings are merely schematic illustrations of the present invention, in which the same reference numerals denote the same or similar parts, and thus, a repetitive description thereof will be omitted. Some of the block diagrams shown in the figures do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
The flow charts shown in the drawings are merely illustrative and do not necessarily include all of the contents and steps, nor do they necessarily have to be performed in the order described. For example, some steps may be decomposed, and some steps may be combined or partially combined, so that the actual execution sequence may be changed according to the actual situation.
The following detailed description of exemplary embodiments of the invention refers to the accompanying drawings.
Fig. 1 is a system block diagram illustrating a serial number generation method and apparatus according to an example embodiment.
The server 105 may be a server providing various services, such as a background management server (for example only) providing support for a serial number generation system operated by a user with the terminal device 101, 102, 103. The backend management server may analyze and otherwise process data such as the received serial number request, and feed back a processing result (for example, a serial number obtained from the target serial number pool — only an example) to the terminal device.
The server 105 may, for example, obtain a pool of sequence numbers 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 and slave clusters coincide and fill the sequence numbers in the sequence number pools when the sequence numbers coincide. The server 105 may, for example, receive a sequence number request that includes a target traffic key value. The server 105 may, for example, match the sequence number pool with the target service key value, and determine the target sequence number pool according to the matching result. The server 105 may obtain the sequence number in the target sequence number pool, for example, from a sequence number request.
The server 105 may be a server of one entity, and may also be composed of a plurality of servers, for example, a part of the servers 105 may be, for example, a serial number generation task submitting system in the present disclosure, configured to obtain a task to be executed with a serial number request command; and a portion of the servers 105 may also be used, for example, as a serial number generation system in the present disclosure, to obtain a serial number pool in a container cluster, where 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 pools when the serial numbers are consistent; receiving a sequence number request, wherein the sequence number request comprises a target business key value; matching the target service key value with the serial number pool, and determining the target serial number pool according to a matching result; and acquiring the sequence number in the target sequence number pool according to the sequence number request.
According to the serial number generation method and device provided by the embodiment of the disclosure, serial number filling is performed on a serial number pool in advance. In the serial number filling process, whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent or not is detected, and the operation of filling the serial numbers is executed when the serial numbers are consistent, so that the strong consistency of the serial numbers filled in the master cluster and the slave cluster can be ensured, and the phenomenon of repeated generation of the serial numbers is avoided. When the serial number pool is created, the serial number pool is filled in advance to form a serial number active generation service, so that the service problem easily caused by passive serial number generation can be avoided.
Fig. 2 is a flow diagram illustrating a method for sequence number generation in accordance with an example embodiment. The serial number generation method provided by the embodiments of the present disclosure may be executed by any electronic device with computing processing capability, for example, the terminal devices 101, 102, and 103 and/or the server 105, and in the following embodiments, a server execution method is taken as an example for illustration, but the present disclosure is not limited thereto. The serial number generation method 20 provided by the embodiment of the present disclosure may include steps S202 to S208.
As shown in fig. 2, in step S201, a serial number pool in a container cluster is obtained, where the container cluster includes a master cluster and a slave cluster.
In embodiments of the present disclosure, a container cluster may be, for example, a Redis cluster. A Redis cluster is a collection of multiple Redis instances, typically deployed on different network sides. The container cluster comprises a master cluster and a slave cluster, and the master cluster and the slave cluster are communicated through a network.
In step S202, it is detected whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, and when the serial numbers are consistent, the serial numbers are filled in the serial number pools.
In this embodiment of the present disclosure, when detecting whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, the maximum serial number may be obtained in the serial number pool of the master cluster, the maximum serial number may be obtained in the serial number pool of the slave cluster, and whether the maximum serial number obtained in the master cluster is consistent with the maximum serial number obtained in the slave cluster is determined. And fills the sequence number in the sequence number pool when the sequence numbers are consistent. The padding sequence number may be incremented according to the largest sequence number obtained from the master cluster (i.e., the largest sequence number obtained from the cluster) to generate a sequence number for padding. Before the serial number is filled, whether the serial numbers in the serial number pools in the master cluster and the slave cluster are consistent or not is detected, and the serial number filling operation is executed when the serial numbers are consistent, so that the strong consistency of the written serial numbers can be ensured, and the phenomenon that the serial numbers are repeatedly generated is avoided.
In step S203, a sequence number request is received, the sequence number request including a target traffic key value (key).
In the embodiment of the present disclosure, the requestor of the serial number request may be a client or a service interface. The serial number request is used for requesting to obtain the serial numbers generated in the serial number pool. The target service key value is used for identifying the service class corresponding to the sequence number request. The traffic class may be, for example, but not limited to, a coupon serial number traffic, an order serial number traffic, and the like.
In step S204, the target service key value is matched with the serial number pool, and the target serial number pool is determined according to the matching result.
In the embodiment of the present disclosure, the target service key value and the sequence number pool may be in a corresponding relationship, and each sequence number pool corresponds to a unique target service key value. When a container cluster (e.g., a Redis cluster) receives a sequence number request, a sequence number pool corresponding to a target service key value in the sequence number request is determined as a target sequence number pool.
In an exemplary embodiment, if the matching of the target service key value and the sequence number pool fails, a target sequence number pool is created in the container cluster according to the target service key value. The operations in steps S201 to S202 in the embodiment of the present disclosure may also be performed on the created target sequence number pool, so as to implement the filling operation on the target sequence number pool.
In step S205, a sequence number is acquired in the target sequence number pool in response to the sequence number request.
In an exemplary embodiment, if the serial number is not obtained in the target serial number pool in response to the serial number request, a request queue is generated according to the serial number request, so as to wait in the target serial number pool according to the request queue and obtain the serial number. When the sequence number in the sequence number pool is used up but a new sequence number cannot be generated (for example, during failover of a master-slave cluster), blocking a sequence number request on the sequence number pool, and the like, and continuing responding to the sequence number request in the request queue after failover is finished, and acquiring the sequence number in the sequence number pool. The large area of serial number request failures due to container cluster unavailability will be avoided.
The serial number generation method provided by the embodiment of the disclosure fills the serial number in the serial number pool in advance. In the serial number filling process, whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent or not is detected, and the operation of filling the serial numbers is executed when the serial numbers are consistent, so that the strong consistency of the serial numbers filled in the master cluster and the slave cluster can be ensured, and the phenomenon of repeated generation of the serial numbers is avoided. When the serial number pool is created, the serial number pool is filled in advance to form a serial number active generation service, so that the service problem easily caused by passive serial number generation can be avoided.
Fig. 3 is a flow diagram illustrating a method for sequence number generation in accordance with an example embodiment. The serial number generation method 30 provided by the embodiment of the present disclosure may include steps S301 to S304.
As shown in fig. 3, in step S301, a serial number pool in a container cluster is obtained, where the container cluster includes a master cluster and a slave cluster.
In step S302, when the number of sequence numbers in the sequence number pool of the master cluster is smaller 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.
In the embodiment of the present disclosure, the preset value refers to the number of the largest sequence numbers that can be stored in the sequence number pool. The preset value can be determined according to the relevant parameters when the serial number pool is created, and can also be adjusted and determined according to the actual situation, which is not particularly limited by the present disclosure.
In an exemplary embodiment, if the number of the serial numbers in the serial number pool is equal to a preset value, cyclically detecting whether the number of the serial numbers in the serial number pool is smaller than the preset value according to a preset time period. The preset time period may be 2s, but the disclosure is not limited thereto. In the embodiment, the number in the serial number pool is detected circularly, so that the active generation function of the serial number service can be realized, the available state of the serial number resource is ensured with the maximum possibility, and the service problem easily caused by the passive generation of the serial number is avoided.
In step S303, if the first serial number data is the same as the second serial number data, the serial number pool is filled according to the first serial number data.
In the embodiment of the present disclosure, the first sequence number data (i.e., the second sequence number data in this embodiment) may be incremented to generate a new sequence number, and the new sequence number may be 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 serial number pool is filled, so that strong consistency of the sequence number data in the master cluster and the slave cluster can be ensured. The situation of repeated production of the serial number can not occur, and the accuracy of the serial number generation service is improved.
In step S304, the above steps S302 to S303 are executed in a loop, and the loop is stopped when the number of the serial numbers in the serial number pool in the master cluster is equal to a preset value.
In the embodiment of the present disclosure, the consistency detection operation of the serial numbers in the master cluster and the slave cluster and the serial number pool filling operation are performed in a circulating manner, so that the serial number pool can be filled up under the condition that the serial numbers in the master cluster and the slave cluster are consistent, and the accuracy of the serial number resources in the serial number pool is ensured.
In an exemplary embodiment, the serial number generation method S303 provided based on the above-described embodiment may further include the following step S3031.
In step S3031, if the first serial number data is different from the second serial number data, the larger data of the first serial number data and the second serial number data is removed.
In this embodiment, because inconsistent data in the master cluster and the slave cluster are removed, strong consistency of sequence numbers in the master cluster and the slave cluster can be ensured. Even if failover occurs in the container cluster, the slave cluster replaces the master cluster, and due to the consistency of the master data and the slave data, the situation of generating repeated serial numbers does not occur. A set of sequence number generation scheme capable of automatically tolerating disasters is provided, and the accuracy of sequence number resources is guaranteed.
In an exemplary embodiment, step S3031 may include: if the first serial number data is larger than the second serial number data, the first serial number data is removed from the main cluster; and if the first serial number data is smaller than the second serial number data, removing the second serial number data from the main cluster.
In an exemplary embodiment, the serial number generation methods S301 to S304 provided based on the above embodiments may further include the following steps S305 to S307.
In step S305, a sequence number request is received, the sequence number request including a target traffic key value.
In step S306, the target service key value is matched with the serial number pool, and the target serial number pool is determined according to the matching result.
In step S307, a sequence number is acquired in the target sequence number pool according to the sequence number request.
Fig. 4 is a flow diagram illustrating a method for sequence number generation in accordance with an example embodiment. The serial number generation method 40 provided by the embodiment of the present disclosure may include steps S401 to S407.
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.
In step S402, it is detected whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent, and when the serial numbers are consistent, the serial numbers are filled in the serial number pools.
In step S403, a sequence number request is received, the sequence number request including the target traffic key value.
In step S404, the target service key value is matched with the serial number pool, and the target serial number pool is determined according to the matching result.
In step S405, a sequence number is acquired in the target sequence number pool in response to the sequence number request.
In step S406, after the serial number is successfully obtained in the target serial number pool in response to the service request, a serial number pool filling notification is generated.
In step S407, in response to the notification of the serial number pool filling, it is detected whether the serial numbers in the serial number pools of the master cluster and the slave cluster coincide, and when the serial numbers coincide, the serial numbers are filled in the serial number pools.
In the embodiment of the present disclosure, after receiving the serial number padding notification, the operations in steps S401 to S402 may be performed according to the serial number padding notification, so as to complete the padding operation of the serial number pool.
According to the serial number generation method provided by the embodiment of the disclosure, after the serial number is successfully acquired in the target serial number pool in response to the service request, the serial number pool is filled according to the generated serial number filling notification, so that the active filling function of the serial number can be further realized, and the service problem easily caused by passively generating the serial number is avoided. In the filling process, whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent or not is detected, and the operation of filling the serial numbers is executed when the serial numbers are consistent, so that the strong consistency of the serial numbers filled in the master cluster and the slave cluster can be ensured, and the phenomenon of repeated generation of the serial numbers is avoided.
It should be clearly understood that this disclosure describes how to make and use particular examples, but the principles of this disclosure are not limited to any details of these examples. Rather, these principles can be applied to many other embodiments based on the teachings of the present disclosure.
Fig. 5 is a flow chart illustrating a method of sequence number generation according to another exemplary embodiment. The serial number generation method 50 includes at least steps S501 to S510. Wherein, the steps S501 to S504 may be packaged in a sub thread, and the operations of the steps S501 to S504 are performed by receiving a notification of a main thread.
As shown in fig. 5, in step S501, a serial number pool in a container cluster is obtained, where the container cluster includes a master cluster and a slave cluster.
In this embodiment of the present disclosure, the sequence number pool in the container cluster may be created according to the target service key value, or may be at least one sequence number pool created before the sequence number request is obtained.
In step S502, when the number of sequence numbers in the sequence number pool of the master cluster is smaller 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.
In step S503, if the first serial number data is the same as the second serial number data, performing a filling operation on the serial number pool according to the first serial number data; and if the first serial number data is different from the second serial number data, removing larger data in the first serial number data and the second serial number data.
When the first serial number data is different from the second serial number data, if the first serial number data is larger than the second serial number data, the first serial number data is removed from the main cluster; and if the first serial number data is smaller than the second serial number data, removing the second serial number data from the main cluster.
In step S504, steps S502 to S503 are executed in a loop, and the loop is stopped when the number of sequence numbers in the sequence number pool in the primary cluster is equal to a preset value.
In an exemplary embodiment, step S504 may be performed after sleeping for 2S.
When the number of the serial numbers in the serial number pool is equal to a preset value, circularly detecting whether the number of the serial numbers in the serial number pool is smaller than the preset value according to a preset time period, and when the number of the serial numbers in the serial number pool is smaller than the preset value, returning to execute the steps S502 to S504. The preset time period may be, for example, but not limited to, 2 s.
In step S505, a sequence number request is received, the sequence number request including a target traffic key value.
In step S506, matching is performed on the sequence number pool in the container cluster according to the target service key value to obtain a target sequence number pool, if matching is successful, step S508 is executed, otherwise, step S507 is executed.
In step S507, a target sequence number pool is created in the container cluster according to the target service key value.
In the embodiment of the present disclosure, after the target serial number pool is created, steps S501 to S504 may be performed to perform a padding operation on the created target serial number pool.
In step S508, a sequence number is obtained in the target sequence number pool in response to the sequence number request.
In step S509, after the serial number is successfully obtained in the target serial number pool in response to the service request, a serial number pool filling notification is generated.
In an exemplary embodiment, if the serial number is not obtained in the target serial number pool in response to the serial number request, a request queue is generated according to the serial number request, so as to block and wait in the target serial number pool according to the request queue and retry obtaining the serial number.
In step S510, in response to the notification of filling the sequence number pool, it is detected whether the sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and when the sequence numbers are consistent, the sequence numbers are filled in the sequence number pool.
In the embodiment of the present disclosure, after the serial number pool filling notification is received, steps S502 to S504 may be performed according to the serial number filling notification, so as to implement an active filling function of the serial number.
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 executed by a central processing unit CPU, performs the above-described functions defined by the above-described methods provided by the present disclosure. The program of (a) may be stored in a computer readable storage medium, which may be a read-only memory, a magnetic or optical disk, or the like.
Furthermore, it should be noted that the above-mentioned figures are only schematic illustrations of the processes involved in the methods according to exemplary embodiments of the present disclosure, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
The following are embodiments of the disclosed apparatus that may be used to perform embodiments of the disclosed methods. For details not disclosed in the embodiments of the apparatus of the present disclosure, refer to the embodiments of the method of the present disclosure.
Fig. 6 is a block diagram illustrating a serial number generation apparatus according to an example embodiment. Referring to fig. 6, a serial number generation apparatus 60 provided in an embodiment of the present disclosure may include: a sequence number pool obtaining module 601, a sequence number filling module 602, a request receiving module 603, a sequence number pool determining module 604 and a sequence number obtaining module 605.
In the serial number generating apparatus 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.
The sequence number padding module 602 may be configured to detect whether sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and pad the sequence numbers in the sequence number pools when the sequence numbers are consistent.
In an exemplary embodiment, the sequence number padding module 602 may include a sequence number acquisition unit, a sequence number padding unit, and a cyclic padding unit. The serial number obtaining unit is configured to obtain 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 when the number of the serial numbers in the serial number pool of the master cluster is smaller than a preset value. And the serial number filling unit is configured to perform filling operation on 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 the circulating filling unit is configured to circularly execute the two steps and stop circulating when the number of the serial numbers in the serial number pool in the main cluster is equal to a preset value.
In an exemplary embodiment, the serial number padding module 602 may further include a data culling unit configured to cull larger data of the first serial data and the second serial data if the first serial data and the second serial data are different.
In an exemplary embodiment, the data culling unit may include a first culling sub-unit and a second culling sub-unit. The first removing subunit may be configured to remove the first sequence number data from the main cluster if the first sequence number data is greater than the second sequence number data. The second culling subunit may be configured to cull the second sequence number data in the master cluster if the first sequence number data is less than the second sequence number data.
In an exemplary embodiment, the serial number padding module 602 may further include a period detecting unit, which may be configured to cyclically detect whether the number of serial numbers in the serial number pool is smaller than a preset value according to a preset time period if the number of serial numbers in the serial number pool is equal to the preset value.
The service request receiving module 603 may be configured to receive a sequence number request, the sequence number request including a target service key value.
The sequence number pool determining module 604 may be configured to match the sequence number pool according to the target service key value, and determine the target sequence number pool according to a matching result.
In an exemplary embodiment, the sequence number pool determining module 604 may further include a sequence number pool creating unit, which may be configured to create a target sequence number pool in the container cluster according to the target service key value if the target service key value fails to match the sequence number pool.
The sequence number acquisition module 605 may be configured to acquire a sequence number in the target sequence number pool in response to a sequence number request.
In an exemplary embodiment, the serial number generation apparatus 60 may further include a padding notification generation module and a serial number active padding module. The filling notification generating module may be configured to generate a serial number pool filling notification after successfully obtaining the serial number in the target serial number pool in response to the service request. The serial number active filling module can be configured to respond to the serial number pool filling notification, 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 pools when the serial numbers are consistent.
According to the serial number generation device provided by the embodiment of the disclosure, serial number filling is performed on the serial number pool in advance. In the serial number filling process, whether the serial numbers in the serial number pools of the master cluster and the slave cluster are consistent or not is detected, and the operation of filling the serial numbers is executed when the serial numbers are consistent, so that the strong consistency of the serial numbers filled in the master cluster and the slave cluster can be ensured, and the phenomenon of repeated generation of the serial numbers is avoided. When the serial number pool is created, the serial number pool is filled in advance to form a serial number active generation service, so that the service problem easily caused by passive serial number generation can be avoided.
FIG. 7 is a block diagram illustrating an electronic device in accordance with an example embodiment.
An electronic device 200 according to this embodiment of the present disclosure is described below with reference to fig. 7. The electronic device 200 shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 7, the electronic device 200 is embodied in the form of a general purpose 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 memory unit 220, a bus 230 connecting different system components (including the memory unit 220 and the processing unit 210), a display unit 240, and the like.
Wherein the storage unit stores program code executable by the processing unit 210 to cause the processing unit 210 to perform the steps according to various exemplary embodiments of the present disclosure described in the above-mentioned electronic prescription flow processing method section of the present specification. For example, the processing unit 210 may perform the steps as shown in fig. 2, 3, 4, 5.
The memory unit 220 may include readable media in the form of volatile memory units, 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.
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 thereof, may comprise an implementation of a network environment.
Bus 230 may be 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.
The electronic device 200 may also communicate with one or more external devices 300 (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a user to interact with the electronic device 200, and/or with any devices (e.g., router, modem, etc.) that enable the electronic device 200 to communicate with one or more other computing devices. Such communication may occur via an input/output (I/O) interface 250. Also, the electronic device 200 may 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 the network adapter 260. The network adapter 260 may communicate with other modules of the electronic device 200 via the bus 230. It should be appreciated that although not shown in the figures, 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, among others.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, or a network device, etc.) to execute the above method according to the embodiments of the present disclosure.
Fig. 8 schematically illustrates a computer-readable storage medium in an exemplary embodiment of the disclosure.
Referring to fig. 8, a program product 400 for implementing the above method according to an embodiment of the present disclosure is described, which may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto, and in this document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The computer readable storage medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable storage medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a readable storage medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind 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).
The computer readable medium carries one or more programs which, when executed by a device, cause the computer readable medium to perform the functions of: acquiring a serial number pool in a container cluster, wherein the container cluster comprises 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 pools when the serial numbers are consistent; receiving a sequence number request, wherein the sequence number request comprises a target business key value; matching the target service key value with the serial number pool, and determining the target serial number pool according to a matching result; a sequence number is obtained in the target sequence number pool in response to the sequence number request.
Those skilled in the art will appreciate that the modules described above may be distributed in the apparatus according to the description of the embodiments, or may be modified accordingly in one or more apparatuses unique from the embodiments. The modules of the above embodiments may be combined into one module, or further split into multiple sub-modules.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.
Exemplary embodiments of the present disclosure are specifically illustrated and described above. It is to be understood that the present disclosure is not limited to the precise arrangements, instrumentalities, or instrumentalities described herein; on the contrary, the disclosure is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.

Claims (10)

1. A method for generating a sequence number, comprising:
acquiring a serial number pool in a container cluster, wherein the container cluster comprises 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 or not, and filling the serial numbers in the serial number pools when the serial numbers are consistent;
receiving a sequence number request, wherein the sequence number request comprises a target business key value;
matching the target service key value with the serial number pool, and determining the target serial number pool according to a matching result;
obtaining a sequence number in the target sequence number pool in response to the sequence number request.
2. The method of claim 1, wherein detecting whether sequence numbers in the sequence number pools of the master cluster and the slave cluster are consistent, and wherein filling sequence numbers in the sequence number pools when the sequence numbers are consistent comprises:
when the number of serial numbers in the serial number pool of the master cluster is smaller than a preset value, acquiring the largest first serial number data in the serial number pool of the master cluster and the largest second serial number data in the serial number pool of 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;
and circularly executing the two steps, and stopping circulation when the number of the serial numbers in the serial number pool in the main cluster is equal to a preset value.
3. The method of claim 2, wherein if the first sequence number data is the same as the second sequence number data, populating the sequence number pool with the first sequence number data further comprises:
and if the first serial number data is different from the second serial number data, removing larger data in the first serial number data and the second serial number data.
4. The method of claim 2, wherein detecting whether sequence numbers in the sequence number pool of the master cluster and the slave cluster are consistent, and wherein populating the sequence number pool with sequence numbers when the sequence numbers are consistent further comprises:
and if the number of the serial numbers in the serial number pool is equal to a preset value, circularly detecting whether the number of the serial numbers in the serial number pool is smaller than the preset value according to a preset time period.
5. The method of claim 1, wherein matching the target traffic key value with the sequence number pool and determining the target sequence number pool according to the matching result further comprises:
and if the matching of the target business key value and the serial number pool fails, establishing the target serial number pool in a container cluster according to the target business key value.
6. The method of claim 1, further comprising:
after the service request is responded and the serial number is successfully obtained in the target serial number pool, generating a serial number pool filling notice;
and responding to the serial number pool filling notification, 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 pools when the serial numbers are consistent.
7. A serial number generation apparatus, comprising:
the serial number pool acquisition module is configured to acquire a serial number pool in a container cluster, and the container cluster comprises a master cluster and a slave cluster;
a serial number filling module configured to detect whether 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 pools when the serial numbers are consistent;
a service request receiving module configured to receive a sequence number request, the sequence number request including a target service key value;
a serial number pool determining module configured to match the target service key value with the serial number pool and determine the target serial number pool according to a matching result;
a sequence number acquisition module configured to acquire a sequence number in the target sequence number pool in response to the sequence number request.
8. The apparatus of claim 7, wherein the sequence number padding module comprises:
a serial number obtaining unit, configured to obtain, when the number of serial numbers in the serial number pool of the master cluster is smaller than a preset value, a first serial number data that is the largest in the serial number pool of the master cluster and a second serial number data that is the largest in the serial number pool of the slave cluster;
a serial number filling unit configured to perform a filling operation on 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 the circulating filling unit is configured to circularly execute the two steps and stop circulating when the number of the serial numbers in the serial number pool in the main cluster is equal to a preset value.
9. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN202010548691.4A 2020-06-16 2020-06-16 Serial number generation method and device, electronic equipment and computer readable medium Pending CN113822015A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010548691.4A CN113822015A (en) 2020-06-16 2020-06-16 Serial number generation method and device, electronic equipment and computer readable medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010548691.4A CN113822015A (en) 2020-06-16 2020-06-16 Serial number generation method and device, electronic equipment and computer readable medium

Publications (1)

Publication Number Publication Date
CN113822015A true CN113822015A (en) 2021-12-21

Family

ID=78924314

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010548691.4A Pending CN113822015A (en) 2020-06-16 2020-06-16 Serial number generation method and device, electronic equipment and computer readable medium

Country Status (1)

Country Link
CN (1) CN113822015A (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7788522B1 (en) * 2007-05-31 2010-08-31 Oracle America, Inc. Autonomous cluster organization, collision detection, and resolutions
WO2014170952A1 (en) * 2013-04-16 2014-10-23 株式会社日立製作所 Computer system, computer-system management method, and program
WO2015000359A1 (en) * 2013-07-02 2015-01-08 华为技术有限公司 Distributed storage system, cluster node and interval management method thereof
CN110457059A (en) * 2019-06-28 2019-11-15 苏宁云计算有限公司 A kind of sequence number generation method and device based on redis
CN110674187A (en) * 2019-09-24 2020-01-10 神州数码融信软件有限公司 Method for generating global unique serial number
CN110674008A (en) * 2019-09-06 2020-01-10 苏州浪潮智能科技有限公司 Problem disk log information collection method, device, equipment and medium of SSD
CN110719209A (en) * 2019-10-31 2020-01-21 北京浪潮数据技术有限公司 Cluster network configuration method, system, equipment and readable storage medium
CN111083228A (en) * 2019-12-24 2020-04-28 腾讯云计算(北京)有限责任公司 Identification number generation method and device and electronic equipment
CN111176588A (en) * 2019-12-11 2020-05-19 中国平安财产保险股份有限公司 Business document issuing method, device, medium and electronic equipment

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7788522B1 (en) * 2007-05-31 2010-08-31 Oracle America, Inc. Autonomous cluster organization, collision detection, and resolutions
WO2014170952A1 (en) * 2013-04-16 2014-10-23 株式会社日立製作所 Computer system, computer-system management method, and program
US20150242481A1 (en) * 2013-04-16 2015-08-27 Hitachi, Ltd. Computer system, computer system management method, and program
WO2015000359A1 (en) * 2013-07-02 2015-01-08 华为技术有限公司 Distributed storage system, cluster node and interval management method thereof
CN110457059A (en) * 2019-06-28 2019-11-15 苏宁云计算有限公司 A kind of sequence number generation method and device based on redis
CN110674008A (en) * 2019-09-06 2020-01-10 苏州浪潮智能科技有限公司 Problem disk log information collection method, device, equipment and medium of SSD
CN110674187A (en) * 2019-09-24 2020-01-10 神州数码融信软件有限公司 Method for generating global unique serial number
CN110719209A (en) * 2019-10-31 2020-01-21 北京浪潮数据技术有限公司 Cluster network configuration method, system, equipment and readable storage medium
CN111176588A (en) * 2019-12-11 2020-05-19 中国平安财产保险股份有限公司 Business document issuing method, device, medium and electronic equipment
CN111083228A (en) * 2019-12-24 2020-04-28 腾讯云计算(北京)有限责任公司 Identification number generation method and device and electronic equipment

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
胡海燕, 郑火国: "利用硬盘序列号实现共享软件的注册", 农业网络信息, no. 11, 26 November 2005 (2005-11-26) *
许旭;潘志刚;: "一种基于"一机一码"的软件激活序列号生成方案", 浙江科技学院学报, no. 04, 15 August 2010 (2010-08-15) *

Similar Documents

Publication Publication Date Title
CN110083455B (en) Graph calculation processing method, graph calculation processing device, graph calculation processing medium and electronic equipment
EP4148579B1 (en) One-sided reliable remote direct memory operations
US20120036345A1 (en) Embedded device and file change notification method of the embedded device
US11636090B2 (en) Method and system for graph-based problem diagnosis and root cause analysis for IT operation
US9374417B1 (en) Dynamic specification auditing for a distributed system
CN111880967A (en) File backup method, device, medium and electronic equipment in cloud scene
CN109901985B (en) Distributed test apparatus and method, storage medium, and electronic device
CN111338834B (en) Data storage method and device
US10873628B2 (en) System and method for non-intrusive context correlation across cloud services
CN112835885B (en) Processing method, device and system for distributed form storage
US20210149709A1 (en) Method and apparatus for processing transaction
CN106911784B (en) Method and device for executing asynchronous event
CN116521639A (en) Log data processing method, electronic equipment and computer readable medium
CN112445860A (en) Method and device for processing distributed transaction
CN113822015A (en) Serial number generation method and device, electronic equipment and computer readable medium
CN113360172B (en) Application deployment method, device, computer equipment and storage medium
CN113220407B (en) Fault exercise method and device
CN114567571A (en) Performance test method and device, electronic equipment and computer readable storage medium
CN109756393B (en) Information processing method, system, medium, and computing device
CN112463514A (en) Monitoring method and device for distributed cache cluster
CN110704222A (en) Dump file analysis method and device, storage medium and electronic equipment
CN111737129A (en) Service control method, service control device, computer readable medium and electronic equipment
CN115334153B (en) Data processing method and device for service grid
CN111682991B (en) Bus error message processing method and device
US11645136B2 (en) Capturing referenced information in a report to resolve a computer problem

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination