CN110677511A - Identification generation method, device, equipment and storage medium in distributed system - Google Patents

Identification generation method, device, equipment and storage medium in distributed system Download PDF

Info

Publication number
CN110677511A
CN110677511A CN201910936832.7A CN201910936832A CN110677511A CN 110677511 A CN110677511 A CN 110677511A CN 201910936832 A CN201910936832 A CN 201910936832A CN 110677511 A CN110677511 A CN 110677511A
Authority
CN
China
Prior art keywords
timestamp
identifier
maximum
self
batch 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.)
Granted
Application number
CN201910936832.7A
Other languages
Chinese (zh)
Other versions
CN110677511B (en
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 Sankuai Online Technology Co Ltd
Original Assignee
Beijing Sankuai Online 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 Sankuai Online Technology Co Ltd filed Critical Beijing Sankuai Online Technology Co Ltd
Priority to CN201910936832.7A priority Critical patent/CN110677511B/en
Publication of CN110677511A publication Critical patent/CN110677511A/en
Application granted granted Critical
Publication of CN110677511B publication Critical patent/CN110677511B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/30Managing network names, e.g. use of aliases or nicknames
    • H04L61/3015Name registration, generation or assignment
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2101/00Indexing scheme associated with group H04L61/00
    • H04L2101/30Types of network names
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/51Discovery or management thereof, e.g. service location protocol [SLP] or web services

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application discloses a method, a device, equipment and a storage medium for generating an identifier in a distributed system, wherein the method comprises the following steps: the server generates a first timestamp in real time according to the system time in the distributed nodes; acquiring a first batch number and a first self-increment number based on a first timestamp; and generating a first identifier according to the first timestamp, the first batch number and the first self-increment number, wherein the first identifier is used as a unique identifier of the service data. The method is that the batch number is added in the mark; in the process of generating the identifier based on one timestamp, if the number of increments reaches the upper limit, the identifier can be continuously generated by incrementing the batch number. The method can generate more identifiers by dividing batches, can provide corresponding identifier generation service for a large amount of service data in a scene of high concurrent service requests, meets a large amount of requirements of a service system on the identifiers, and avoids the waiting problem caused by insufficient number of generated identifiers.

Description

Identification generation method, device, equipment and storage medium in distributed system
Technical Field
The application relates to an identification generation method, an identification generation device, identification generation equipment and a storage medium in a distributed system.
Background
In a distributed system, a unique Identifier (ID) needs to be generated for data in many service scenarios to ensure uniqueness of the data and provide a valid identifier for locating and distinguishing the data. For example, the take-away business system needs to ensure the uniqueness of the order number for each order.
A typical unique ID generation method depends on a time stamp, for example, the principle of the most representative unique ID generation algorithm is to generate IDs according to a time stamp of millisecond order, thereby ensuring the uniqueness of each ID; specifically, the distributed node generates a unique ID by combining a millisecond-level timestamp, a node identifier and a self-increment number.
Disclosure of Invention
The embodiment of the application provides a method, a device, equipment and a storage medium for generating an identifier in a distributed system, wherein the technical scheme is as follows:
according to an aspect of the present application, there is provided an identifier generation method in a distributed system, which is applied to distributed nodes in the distributed system, and the method includes:
generating a first timestamp in real time according to the system time in the distributed nodes;
acquiring a first batch number and a first self-increment number based on a first timestamp; the first batch number is used for marking the identified batch generated under the first time stamp; the first self-increment number is an integer which increases at a constant rate, and the first self-increment number is used for generating a plurality of identifications under the first batch number of the first time stamp;
and generating a first identifier according to the first timestamp, the first batch number and the first self-increment number, wherein the first identifier is used as a unique identifier of the service data.
In some embodiments, obtaining the first lot number and the first augmentation number based on the first timestamp comprises:
when a first time stamp exists in the distributed nodes, acquiring a maximum batch number corresponding to the first time stamp;
when the maximum batch number corresponding to the first timestamp is smaller than the first batch threshold value, adding x to the maximum batch number corresponding to the first timestamp to obtain a first batch number, and correspondingly assigning a first initial value to a first self-increment number; wherein x is a preset value.
In some embodiments, when the maximum lot number corresponding to the first timestamp is smaller than the first lot threshold, before adding x to the maximum lot number corresponding to the first timestamp to obtain the first lot number, the method includes:
acquiring a self-increment number corresponding to the maximum batch number of the first timestamp;
and when the self-increment number corresponding to the maximum batch number of the first timestamp is equal to the self-increment threshold, executing a step of adding x to the maximum batch number corresponding to the first timestamp to obtain the first batch number when the maximum batch number corresponding to the first timestamp is less than the first batch threshold.
In some embodiments, the method further comprises:
acquiring a self-increment number corresponding to the maximum batch number of the first timestamp;
and when the self-increment number corresponding to the maximum batch number of the first timestamp is smaller than the self-increment number threshold value, determining the maximum batch number of the first timestamp as the first batch number, and determining the self-increment number corresponding to the maximum batch number of the first timestamp as the first self-increment number.
In some embodiments, generating the first identification from the first timestamp, the first batch number, and the first self increment includes:
splicing and combining the first timestamp, the first batch number and the first self-increment number, and periodically generating the first identification in batches;
storing the first identifier in an identifier pool;
the method further comprises the following steps:
when receiving an identifier generation request of service data of the distributed node, preferentially acquiring a first identifier from an identifier pool.
In some embodiments, the system time is calibrated system time, and the calibrated system time is obtained by performing periodic calibration according to time data provided by a time center;
generating a first timestamp in real time according to system time in a distributed node, comprising:
acquiring calibrated system time and a maximum timestamp before calibration, wherein the maximum timestamp before calibration is the maximum timestamp included in a generated identifier in the distributed system;
and when the calibrated system time is greater than the maximum timestamp before calibration, generating a first timestamp in real time according to the calibrated system time.
In some embodiments, the system time is calibrated system time, and the calibrated system time is obtained by performing periodic calibration according to time data provided by a time center;
the method further comprises the following steps:
acquiring calibrated system time and a maximum timestamp before calibration, wherein the maximum timestamp before calibration is the maximum timestamp included in a generated identifier in the distributed system;
when the calibrated system time is less than the maximum timestamp before calibration, generating a second timestamp in real time according to the calibrated system time;
when a second timestamp exists in the distributed node, increasing the maximum batch number corresponding to the second timestamp to obtain a second batch number, and acquiring a second self-increment number;
and generating a second identifier according to the second timestamp, the second batch number and the second self-increment number.
In some embodiments, incrementing the maximum batch number corresponding to the second timestamp to obtain a second batch number, and obtaining a second self-increment number includes:
and when the maximum batch number corresponding to the second timestamp is smaller than the second batch threshold value, adding y to the maximum batch number corresponding to the second timestamp to obtain a second batch number, and correspondingly assigning a second initial value to a second self-increment number, wherein y is a preset value.
According to another aspect of the present application, there is provided an identifier generating apparatus in a distributed system, the apparatus being a distributed node in the distributed system, the apparatus including:
the generating module is used for generating a first timestamp in real time according to the system time in the distributed nodes;
the acquisition module is used for acquiring a first batch number and a first self-increment number based on a first timestamp; the first batch number is used for marking the identified batch generated under the first time stamp; the first self-increment number is an integer which increases at a constant rate, and the first self-increment number is used for generating a plurality of identifications under the first batch number of the first time stamp;
and the generating module is used for generating a first identifier according to the first timestamp, the first batch number and the first self-increment number, wherein the first identifier is used as a unique identifier of the service data.
In some embodiments, the obtaining module comprises:
the acquisition submodule is used for acquiring the maximum batch number corresponding to the first timestamp when the first timestamp exists in the distributed nodes;
the determining submodule is used for adding x to the maximum batch number corresponding to the first timestamp to obtain a first batch number when the maximum batch number corresponding to the first timestamp is smaller than a first batch threshold value, and correspondingly assigning a first initial value to a first self-increment number; wherein x is a preset value.
In some embodiments of the present invention, the,
the obtaining submodule is used for obtaining the self-increment number corresponding to the maximum batch number of the first timestamp;
and the determining submodule is used for executing the step of adding x to the maximum batch number corresponding to the first timestamp to obtain the first batch number when the self-increment number corresponding to the maximum batch number of the first timestamp is equal to the self-increment threshold and the maximum batch number corresponding to the first timestamp is smaller than the first batch threshold.
In some embodiments of the present invention, the,
the obtaining submodule is used for obtaining the self-increment number corresponding to the maximum batch number of the first timestamp;
the determining submodule is used for determining the maximum batch number of the first timestamp as the first batch number when the self-increment number corresponding to the maximum batch number of the first timestamp is smaller than the self-increment threshold, and determining the self-increment number corresponding to the maximum batch number of the first timestamp as the first self-increment number.
In some embodiments of the present invention, the,
the generation module is used for splicing and combining the first time stamp, the first batch number and the first self-increment number and periodically generating the first identification in batches; storing the first identifier in an identifier pool;
the obtaining module is further configured to preferentially obtain the first identifier from the identifier pool when receiving an identifier generation request of the service data of the distributed node.
In some embodiments, the system time is calibrated system time, and the calibrated system time is obtained by performing periodic calibration according to time data provided by a time center;
the acquisition module is used for acquiring the calibrated system time and the maximum timestamp before calibration, wherein the maximum timestamp before calibration is the maximum timestamp included in the generated identifier in the distributed system;
and the generating module is used for generating a first time stamp in real time according to the calibrated system time when the calibrated system time is greater than the maximum time stamp before calibration.
In some embodiments, the system time is calibrated system time, and the calibrated system time is obtained by performing periodic calibration according to time data provided by a time center;
the acquisition module is used for acquiring the calibrated system time and the maximum timestamp before calibration, wherein the maximum timestamp before calibration is the maximum timestamp included in the generated identifier in the distributed system;
the generating module is used for generating a second timestamp in real time according to the calibrated system time when the calibrated system time is less than the maximum timestamp before calibration;
the acquisition module is used for increasing the maximum batch number corresponding to the second timestamp to obtain a second batch number and acquiring a second self-increment number when the second timestamp exists in the distributed nodes;
and the generating module is used for generating a second identifier according to the second timestamp, the second batch number and the second self increment.
In some embodiments of the present invention, the,
and the determining submodule is used for adding y to the maximum batch number corresponding to the second timestamp to obtain a second batch number when the maximum batch number corresponding to the second timestamp is smaller than a second batch threshold value, and correspondingly assigning a second initial value to a second self-increment number, wherein y is a preset value.
According to another aspect of the present application, there is provided a distributed node comprising a processor and a memory, the memory having stored therein at least one instruction, at least one program, set of codes, or set of instructions, which is loaded and executed by the processor to implement the method of identity generation in a distributed system as described above.
According to another aspect of the present application, there is provided a computer readable storage medium having stored therein at least one instruction, at least one program, set of codes, or set of instructions, which is loaded and executed by a processor to implement the method of identity generation in a distributed system as described above.
The beneficial effects brought by the technical scheme provided by the embodiment of the application at least comprise:
the server generates a first timestamp in real time according to the system time in the distributed nodes; acquiring a first batch number and a first self-increment number based on a first timestamp; the first batch number is used for marking the identified batch generated under the first time stamp; the first self-increment number is an integer which increases at a constant rate, and the first self-increment number is used for generating a plurality of identifications under the first batch number of the first time stamp; and generating a first identifier according to the first timestamp, the first batch number and the first self-increment number, wherein the first identifier is used as a unique identifier of the service data.
In the identification generation method in the distributed system, the batch number is added in the identification; in the process of generating the identifier based on one timestamp, if the number of increments reaches the upper limit, the identifier can be continuously generated by incrementing the batch number. That is to say, a greater number of identifiers can be generated by dividing batches, and in a scenario with high concurrent service requests, corresponding identifier generation service can be provided for a large amount of service data, so that a large amount of requirements of a service system on the identifiers are met, and the waiting problem caused by insufficient number of generated identifiers is avoided.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic block diagram of a distributed system provided by an exemplary embodiment of the present application;
FIG. 2 is a flow chart of a method for generating an identity in a distributed system as provided by an exemplary embodiment of the present application;
FIG. 3 is a flow chart of a method for identifier generation in a distributed system provided by another exemplary embodiment of the present application;
FIG. 4 is a schematic illustration of a mosaic of markers provided by an exemplary embodiment of the present application;
FIG. 5 is a schematic block diagram of an identity generation system provided in an exemplary embodiment of the present application;
FIG. 6 is a flow chart of a method for identifier generation in a distributed system provided by another exemplary embodiment of the present application;
FIG. 7 is a block diagram of an identification generation apparatus in a distributed system as provided by an exemplary embodiment of the present application;
fig. 8 is a schematic device structure diagram of a server according to an exemplary embodiment of the present application.
Detailed Description
To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
First, terms referred to in the embodiments of the present application are described:
marking: refers to a mark for identifying things. The identifier in the embodiment of the application has uniqueness, and can be applied to different service scenes, and when the server generates service data, the server marks the different service data through the identifier so as to distinguish the different service data. For example, in the process of online transaction, each order corresponds to an order number, which is an identifier of the order, and each order number is unique.
Time callback: the server synchronizes the calibration time from the time center, calibrates the system time of the local computer through the calibration time, and when the system time is faster than the calibration time, the server dials back the system time, that is, a phenomenon that a clock jumps back occurs, which is time dial-back.
Distributed system: refers to a system formed by connecting a client, a plurality of nodes (computer equipment in any form of access network, such as server, user terminal) through a network communication form. Referring To fig. 1, which shows an alternative structural diagram of a distributed system, a Peer-To-Peer (P2P) network is formed among nodes 100, and the P2P Protocol is an application layer Protocol operating on a Transmission Control Protocol (TCP). In a distributed system, any machine, such as a server or a terminal, can join to become a node, and the node comprises a hardware layer, a middle layer, an operating system layer and an application layer.
Various types of service events exist in the online network service, and a unique identifier needs to be generated for service data to ensure the uniqueness of the service data. The present application provides an identifier generation method in a distributed system, which can generate unique identifiers for service data of various types of service events in the distributed system, and the identifier generation method in the distributed system is described in the following embodiments.
Referring to fig. 2, a flowchart of an identifier generation method in a distributed system according to an exemplary embodiment of the present application is shown, where the method is applied to distributed nodes in the distributed system, and the method includes the following steps:
step 201, the server generates a first timestamp in real time according to the system time in the distributed node.
In this embodiment, the server is a distributed node in the distributed system. The distributed nodes provide identification generation service, identification is continuously generated for the service data, and each generated identification has uniqueness. The identifier includes a timestamp, the timestamp refers to a credential document with time information as a parameter, and the time information may include a date and a time.
Optionally, the distributed node generates the first timestamp periodically according to the system time, for example, the distributed node generates a first timestamp every one millisecond (ms).
In step 202, the server obtains a first lot number and a first augmentation number based on a first timestamp.
Wherein the first lot number is used to mark the identified lot generated under the first timestamp; the first increment is an integer that increases at a constant rate, the first increment being used to generate a number of tokens at a first batch number at a first time stamp.
It should be noted that the self-increment number is a value that has a starting value and is increased at a constant rate; constant rate refers to the rate of generation of the marker; that is, each time an id is generated, the increment number is increased by one until the upper limit is reached, for example, an initial value of the increment number is "0000", the first id correspondingly generated is "0000", the second id is "0001", the third id is "0010", and so on until the upper limit "1111" is reached. Therefore, the server stores a first incremental threshold value of the incremental number.
The batch number indicates the identified batch generated under one time stamp, for example, under a 41-bit time stamp "00010100000000000100100010010100111001001", the identification of different batch numbers with batches of "0000", "0001", "0010", etc. can be generated. The batch number has an initial value, which may be any integer, such as 0 or 1.
Illustratively, a batch number is composed of a set of binary numbers, and the number of bits occupied by the batch number is limited, so that the value of the batch number has an upper limit, i.e., the batch number corresponds to a batch threshold. For example, if the lot number is a set of 4-bit binary numbers, the lot number is 15 at maximum. Therefore, the server stores the first lot threshold corresponding to the first lot number.
In a possible case, the server starts to generate the identifier based on the first timestamp, if the first timestamp does not exist in the distributed nodes, the server assigns the initial value to the first batch number, and correspondingly assigns the first initial value to the first self-increment number. For example, the server assigns an initial value of 0 to a first batch number as a batch number of the identifier of the initial batch; correspondingly, a first initial value 0 is assigned to the first self-increment number.
Under another possible condition, the server continuously generates the identifier based on the first time stamp, and if the first time stamp exists in the distributed nodes, the server acquires the maximum batch number corresponding to the first time stamp after determining that the first time stamp exists in the distributed nodes; when the maximum batch number corresponding to the first timestamp is smaller than the first batch threshold value, adding x to the maximum batch number corresponding to the first timestamp to obtain a first batch number, and correspondingly assigning a first initial value to a first self-increment number; wherein x is a preset value and x is a positive integer.
It should be further noted that, in order to enable each incremental number to generate as many identifiers as possible, after one incremental number reaches an upper limit, the server generates the identifier of the next batch, and therefore, after the server obtains the maximum batch number corresponding to the first timestamp, the server obtains the incremental number corresponding to the maximum batch number of the first timestamp; judging whether the self-increment number corresponding to the maximum batch number of the first timestamp is smaller than a first batch threshold value or not; and when the self-increment number corresponding to the maximum batch number of the first timestamp is equal to the self-increment threshold, determining that the self-increment number corresponding to the maximum batch number of the first timestamp reaches an upper limit, and executing a step of adding x to the maximum batch number corresponding to the first timestamp to obtain the first batch number when the maximum batch number corresponding to the first timestamp is smaller than the first batch threshold.
When the self-increment number corresponding to the maximum batch number of the first timestamp is smaller than the self-increment number threshold value, the server determines that the self-increment number corresponding to the maximum batch number of the first timestamp does not reach the upper limit, determines the maximum batch number of the first timestamp as the first batch number, and determines the self-increment number corresponding to the maximum batch number of the first timestamp as the first self-increment number.
Step 203, the server generates a first identifier according to the first timestamp, the first batch number and the first self-increment number.
The first identifier is used as a unique identifier of the service data. And the server splices and combines the first timestamp, the first batch number and the first self-increment number to generate a first identifier. Optionally, the first identifier further includes a node identifier of the distributed node; and the server generates a first identifier for the first timestamp, the first batch number, the node identifier and the first self-increment splicing combination.
For example, the first timestamp is "01010100000010000100100010010000101001000", the first lot number is "00000", the node identifier is "00010", and the incremental number is "000000000000"; the first flag is "0010101000000100001001000100100001010010000000000010000000000000" with 64 bits.
The node identification refers to a mark of each distributed node, and each node identification is unique.
In summary, in the identifier generating method in the distributed system provided in this embodiment, the server generates the first timestamp in real time according to the system time in the distributed node; acquiring a first batch number and a first self-increment number based on a first timestamp; the first batch number is used for marking the identified batch generated under the first time stamp; the first self-increment number is an integer which increases at a constant rate, and the first self-increment number is used for generating a plurality of identifications under the first batch number of the first time stamp; and generating a first identifier according to the first timestamp, the first batch number and the first self-increment number, wherein the first identifier is used as a unique identifier of the service data. The method is that the batch number is added in the mark; in the process of generating the identifier based on one timestamp, if the number of increments reaches the upper limit, the identifier can be continuously generated by incrementing the batch number. That is to say, a greater number of identifiers can be generated by dividing batches, and in a scenario with high concurrent service requests, corresponding identifier generation service can be provided for a large amount of service data, so that a large amount of requirements of a service system on the identifiers are met, and the waiting problem caused by insufficient number of generated identifiers is avoided.
The distributed nodes can synchronize time data from the time center regularly to calibrate the system time; the calibrated system time is the time obtained by periodic calibration according to the time data provided by the time center. Wherein, the time center can be a national time service center, and the organization provides standard time.
In the process of generating the identifier, the distributed node calibrates the system time, and if the system time before calibration is faster than the calibration time provided by the time center, the distributed node may have a time callback phenomenon after the system time calibration is completed, so that the timestamp acquired by the distributed node is repeated. In the process of generating the identifier, the distributed node acquires the calibrated system time and the maximum timestamp before calibration, and determines whether a time callback phenomenon occurs in the distributed node by comparing the time of the calibrated system time and the time of the maximum timestamp before calibration. Wherein the maximum timestamp before calibration is the maximum timestamp included in the generated identity in the distributed system.
Referring to fig. 3, a flowchart of an identifier generation method in a distributed system according to an exemplary embodiment of the present application is shown, where the method is applied to a distributed node of the distributed system, and may be used to solve the above time callback problem, and the method includes the following steps:
step 301, the server obtains the calibrated system time and the maximum timestamp before calibration.
Step 302, the server determines whether the calibrated system time is greater than the maximum timestamp before calibration.
The server judges whether the calibrated system time is greater than the maximum timestamp before calibration; when the calibrated system time is greater than the maximum timestamp before calibration, executing steps 303 to 305; when the calibrated system time is less than or equal to the maximum timestamp before calibration, steps 306 to 310 are performed.
Step 303, the server generates a first timestamp in real time according to the calibrated system time.
Optionally, the server periodically generates a first timestamp according to the calibrated system time.
At step 304, the server obtains a first lot number and a first accrual number based on the first timestamp.
If the calibrated system time is greater than the maximum timestamp before calibration, the original system time in the distributed nodes is slower than the calibration time, and after the system time is calibrated according to the calibration time, the distributed nodes do not have a time callback phenomenon, so that the situation of repeated timestamps does not occur, the server assigns the initial value to the first batch number and correspondingly assigns the first initial value to the first self-increment number. For example, the server assigns an initial value 1 to a first batch number as a batch number of the identifier of the initial batch; correspondingly, a first initial value 0 is assigned to the first self-increment number.
Step 305, the server generates a first identifier according to the first timestamp, the first batch number and the first self-increment number.
For a detailed description of this step, refer to step 203, which is not described herein again.
Step 306, the server generates a second timestamp in real time according to the calibrated system time.
Optionally, the server generates the second timestamp periodically according to the calibrated system time, for example, the distributed node generates a second timestamp every 2 ms.
In step 307, the server determines whether a second timestamp exists in the distributed node.
If the calibrated system time is less than or equal to the maximum timestamp before calibration, it is indicated that the original system time in the distributed nodes is faster than the calibration time, and after the system time is calibrated according to the calibration time, a time callback phenomenon exists in the distributed nodes, so that a situation of repeated timestamps occurs, and a second timestamp may exist in the distributed nodes.
The server judges whether a second timestamp exists in the distributed nodes or not; when the second timestamp is present in the distributed node, performing step 308; when the second timestamp is not present in the distributed node, step 310 is performed.
Step 308, the server increments the maximum batch number corresponding to the second timestamp to obtain a second batch number, and obtains a second self-increment number.
In order to distinguish the mark generated based on the second timestamp before and after the system time calibration, the server increments the batch number corresponding to the second timestamp to determine the second batch number, and the second batch number is used as the batch of the mark generated after the calibration. Accordingly, the server obtains the initialized second augmentation number, that is, the second augmentation number is assigned as the initial value.
Since the identifier corresponding to the second timestamp generated by the distributed node before time calibration may include i batches, where i is a positive integer, the batch number corresponding to the second timestamp may be obtained by incrementing the maximum batch number corresponding to the second timestamp before time calibration. That is, the server increments the maximum lot number corresponding to the second timestamp to determine the second lot number. For example, if the maximum batch number corresponding to the second timestamp is 3, the second batch number is determined to be 4; the batch number corresponding to the identifier generated based on the second timestamp before the system time calibration is 3, and the batch number corresponding to the identifier generated based on the second timestamp after the system time calibration is 4.
Illustratively, the batch number is composed of a set of binary numbers, and the number of bits occupied by the batch number is limited, so the value of the batch number has an upper limit, and thus the second batch number corresponds to the second batch threshold. Optionally, the server determines whether the maximum batch number corresponding to the second timestamp is less than a second batch threshold; and when the maximum batch number corresponding to the second timestamp is smaller than the second batch threshold value, the server adds y to the maximum batch number corresponding to the second timestamp to obtain a second batch number, and correspondingly assigns a second initial value to a second self-increment number, wherein y is a preset value and y is a positive integer.
It should be noted that, if the requirement for the identifier at the same time is large, and a batch of identifiers cannot meet the service requirement, the server may generate the identifiers of multiple batches at the same time stamp, so that the batch number corresponding to the identifier of the second time stamp may be an initial batch number, the identifier corresponding to the second time stamp may also correspond to multiple batch numbers, and when the second batch number is calculated, the server adds y to the maximum batch number corresponding to the second time stamp before calibration, so as to obtain the second batch number.
And when the maximum batch number corresponding to the second timestamp is equal to the second batch threshold, indicating that the batch number of the identifier under the second timestamp has reached the upper limit, waiting and reacquiring the calibrated system time, and continuing to execute the step of generating the first identifier or the second identifier in the distributed system based on the reacquired calibrated system time. That is, if the second batch number is equal to the second batch threshold, the server enters a wait state; after waiting for a certain time, the calibrated system time is acquired again, and the process returns to step 301.
Step 309, the server generates a second identifier according to the second timestamp, the second batch number and the second self-increment number.
Optionally, the second identifier further includes a node identifier of the distributed node; and the server splices and combines the second timestamp, the second batch number, the node identification and the second self-increment number to obtain a second identification.
Illustratively, the second identifier includes a second timestamp, a second batch number, a node identifier of the distributed node, and a second self-increment number. As shown in fig. 4, the structure of the second identifier may be a sequential concatenation of the second timestamp, the second batch number, the node identifier, and the second addendum number, which includes a 41-bit second timestamp, a 5-bit second batch number, a 5-bit node identifier, and a 12-bit second addendum number; also including one bit unused. The second batch number and the bit number of the node identifier may be adjusted according to the actual condition of the distributed system and/or the requirement of each node for the identifier amount at the same time, for example, the batch number may be set to 3 bits, and the corresponding node identifier may be set to 7 bits, so that 128 servers may be supported to generate the identifier at the same time, and at most 8 batches of identifiers may be generated under the same timestamp.
In step 310, the server generates a second identifier according to the second timestamp, the third batch number and the third incrementation number.
The third lot number is set as an initial value, and the third incrementation number is also set as an initial value; optionally, the server concatenates the second timestamp, the third batch number, the node identifier, and the third incremental number to generate a second identifier.
In summary, in the identifier generating method in the distributed system provided in this embodiment, the calibrated system time and the maximum timestamp before calibration are obtained, and the calibrated system time and the maximum timestamp before calibration are compared; when the calibrated system time is greater than the maximum timestamp before calibration, the distributed node generates a first timestamp in real time according to the calibrated system time, and generates a first identifier according to the first timestamp and the first batch number; when the calibrated system time is less than the maximum timestamp before calibration, indicating that time callback occurs, and generating a second timestamp by the distributed node in real time according to the calibrated system time; and when the second timestamp before calibration exists in the distributed system, increasing the maximum batch number of the second timestamp before calibration to obtain a second batch number, and generating a second identifier according to the second timestamp and the second batch number.
According to the identification generation method in the distributed system, the batch numbers are added in the identification, and the identification generated before time callback and the identification generated after time callback under the same timestamp are distinguished by adopting different batch numbers, so that in the identification generation process, even if the time callback phenomenon occurs, the distributed node can still continue to generate the identification, repeated identification cannot occur, and the uniqueness of the generated identification can be ensured.
Secondly, if a large number of identifiers need to be generated at the same time, the identifiers can also be realized by adopting batch numbers, for example, in one distributed node, a 12-bit self-increment number can correspondingly generate 1024 identifiers, and if a batch number with a batch threshold value of n is added and n is a positive integer, in one distributed node, n times of 1024 identifiers can be generated under the same timestamp, so that the service requirements can be better met.
In a scenario of a high concurrent service request, due to a machine performance problem, a waiting problem may occur, and an identifier generation service cannot be provided for service data in an instant manner. Taking the pre-generated first flag as an example, the following is described:
1) and the server combines the first timestamp, the first batch number and the first self-increment number and periodically generates the first identifier in batches.
Wherein the first auto-increment number is an integer value which has an initial value and is incremented at a constant rate; optionally, the constant rate refers to a generation rate of the distributed node pair identifiers, for example, 1024 identifiers are generated by the server every millisecond, and the first increment is increased from 0 to 1023 in the one millisecond.
The server sequentially splices the first timestamp, the first batch number and the first self-increment number, wherein the first self-increment number starts from an initial value, and a first identifier is generated every time j is added, wherein the first identifier comprises the first identifier corresponding to the initial value, and j is a positive integer; the first identifiers are generated in batches periodically, for example, the server generates a batch of the first identifiers every two milliseconds, and each batch of the first identifiers may include at least two.
2) The server stores the first identifier in an identifier pool.
An identification pool is arranged in the server and used for storing a first identification to be used. And the server generates a second identifier and then stores the second identifier in the identifier pool in advance. It should be noted that the first identifier pre-stored in the identifier pool is preferentially used in case of a need, as in step 3).
3) When receiving an identifier generation request of service data of the distributed nodes, the server preferentially acquires a first identifier from the identifier pool.
The identification generation request is used for requesting the distributed nodes to generate unique identifications for the service data and storing the unique identifications; after receiving the identifier generation request, the server preferentially acquires the first identifier from the identifier pool, and uses the first identifier as the unique identifier of the service data.
It should be noted that the identifier pool is further configured to store a second identifier to be used, that is, the first identifier and the second identifier that are generated in advance by the server are both stored in the identifier pool, and when receiving an identifier generation request of the service data, the distributed node acquires the first identifier or the second identifier from the identifier pool as the unique identifier of the service data.
Schematically, as shown in fig. 5, a schematic structural diagram of an alternative service data identifier generation system is shown, and a distributed node includes a service system 31, an identifier pool 32, a process data providing module 33, an identifier generator 34, and a time trigger 35. Wherein the time trigger 35 issues an excitation signal to the identifier generator 34, triggering the generation of the first identifier and/or the second identifier by the identifier generator 34. In the process of generating the identifier, the identifier generator 34 acquires process data from the process data providing module 33, where the process data includes a timestamp and a batch number, and may further include a node identifier and a self-increment number of the distributed node; the identification generator 34 periodically generates a first identification and/or a second identification for the batch from the process data; the identifier generator 34 further stores the generated first identifier and/or second identifier in the identifier pool 32, and waits for the service system 31 to use. When generating the identifier for the service data, the service system 31 obtains the first identifier or the second identifier from the identifier pool 32 as the unique identifier of the service data. If the first identifier and/or the second identifier does not exist in the identifier pool 32, the generation of the first identifier and/or the second identifier is waited.
In summary, the identifier generation method in the distributed system provided by this embodiment can continuously provide a unique identifier for the identifier generation of the service data by pre-storing the identifier, and solve the waiting problem caused by the machine performance, and particularly, can respond to the sudden request in real time.
For example, the existing identifier generation algorithm is limited to machine performance under a sudden high concurrent request, and may not respond to the request in time to generate an identifier, thereby causing a waiting problem. Illustratively, in a double 11 scenario, limited to machine performance, a problem that an order is generated based on an identifier because a high-concurrency request on an e-commerce platform cannot be responded to in time occurs, and even a server is paralyzed in a severe case. In the identifier generation method for the distributed system provided by this embodiment, the identifiers are periodically generated in batches in the server and are pre-stored in the buffer area, and when a high concurrency request occurs, the current consumption of the identifiers can be met through the identifiers pre-stored in the buffer area, or the current partial consumption of the identifiers can be met, so that a buffer stage is formed, and the machine can timely supplement the identifiers stored in the buffer area, thereby avoiding the waiting problem and improving the stability and performance of the system.
In some embodiments, if the system time is calibrated by the distributed node, the calibrated system time is still equal to the maximum timestamp before calibration, and the distributed node generates the identifier at this moment and adopts the maximum timestamp before calibration, which is schematically illustrated in fig. 3 by adding step 311 to step 312, as shown in fig. 6, as follows:
in step 311, the server increments the lot number corresponding to the maximum timestamp before calibration to obtain a fourth lot number.
And when the calibrated system time is equal to the maximum timestamp before calibration, the original system time is consistent with the calibration time provided by the time center, and the maximum timestamp before calibration is the current timestamp. If the server is using the current timestamp to generate the first identifier before calibration, the server still uses the current timestamp to generate the first identifier after calibration.
Since the server may have generated k batches of the first identifiers before time calibration, where k is an integer greater than 0, the server determines the maximum batch number corresponding to the current timestamp from the generated first identifiers, and increments the maximum batch number corresponding to the maximum timestamp before calibration to obtain the fourth batch number. The maximum batch number corresponding to the current timestamp may be an initial batch number.
It should be noted that, the server may not generate the first identifier corresponding to the current timestamp before time calibration, and the server may directly generate the first identifier by using the initial batch number.
Optionally, if a first identifier corresponding to the current timestamp already exists in the server, the first identifier further includes a fourth incremental number corresponding to the maximum batch number of the current timestamp; the server also judges whether a fourth self-increment number corresponding to the maximum batch number of the current timestamp is equal to a self-increment threshold value; and if the fourth self-increment number corresponding to the maximum batch number of the current timestamp is equal to the self-increment number threshold, the server performs the step of incrementally increasing the maximum batch number corresponding to the maximum timestamp before calibration to obtain the fourth batch number. Wherein, since the number of bits occupied by the auto-increment number is limited, there is an upper limit for the auto-increment number, i.e. there is an auto-increment threshold.
Optionally, if the fourth self-increment number corresponding to the maximum batch number of the current timestamp is smaller than the self-increment threshold, the server generates the first identifier according to the maximum timestamp before calibration, the maximum batch number corresponding to the maximum timestamp before calibration, and the fourth self-increment number. That is, when the fourth increment corresponding to the maximum batch number of the current timestamp has not reached the upper limit, the server continues to generate the first identifier based on the maximum batch number of the current timestamp.
In step 312, the server generates a first identifier according to the maximum timestamp before calibration, the fourth batch number, and the first self-increment number.
Illustratively, the distributed node splices the maximum timestamp before calibration, the fourth batch number, the node identifier of the distributed node, and the bit of the first self-increment number to obtain the first identifier, and for a more detailed description, reference is made to the corresponding description of fig. 3, which is not repeated herein.
In summary, in the identifier generation method for the distributed system provided in this embodiment, batches are set in the identifier, more unique identifiers can be generated under the same timestamp through the batches in the identifier and the incremental logic of the self-increment number, and sufficient identifiers are provided for the service system as unique identifiers of service data, so that the problem of long-time waiting caused by too much service data and failure to generate identifiers of service data in time at the same time can be avoided, and the instantaneity of the identifier provision can improve user experience.
The following are embodiments of the apparatus of the present application, and for details that are not described in detail in the embodiments of the apparatus, reference may be made to corresponding descriptions in the above method embodiments, and details are not described herein again.
Referring to fig. 7, a schematic structural diagram of an identifier generation apparatus in a distributed system according to an exemplary embodiment of the present application is shown. The apparatus, which may be implemented by software, hardware or a combination of both as all or a part of a terminal, is a distributed node in a distributed system, and includes:
a generating module 401, configured to generate a first timestamp in real time according to system time in a distributed node;
an obtaining module 402, configured to obtain a first batch number and a first self-increment number based on a first timestamp; the first batch number is used for marking the identified batch generated under the first time stamp; the first self-increment number is an integer which increases at a constant rate, and the first self-increment number is used for generating a plurality of identifications under the first batch number of the first time stamp;
a generating module 401, configured to generate a first identifier according to the first timestamp, the first batch number, and the first self-increment number, where the first identifier is used as a unique identifier of the service data.
In some embodiments, the obtaining module 402 includes:
the obtaining sub-module 4021 is configured to obtain a maximum batch number corresponding to a first timestamp when the first timestamp exists in the distributed nodes;
the determining submodule 4022 is configured to, when the maximum batch number corresponding to the first timestamp is smaller than the first batch threshold, add x to the maximum batch number corresponding to the first timestamp to obtain a first batch number, and assign a first initial value to the first self-increment number correspondingly; wherein x is a preset value.
In some embodiments of the present invention, the,
the obtaining sub-module 4021 is configured to obtain a self-increment number corresponding to the maximum batch number of the first timestamp;
the determining sub-module 4022 is configured to, when the self-increment number corresponding to the maximum batch number of the first timestamp is equal to the self-increment threshold, perform a step of adding x to the maximum batch number corresponding to the first timestamp to obtain the first batch number when the maximum batch number corresponding to the first timestamp is smaller than the first batch threshold.
In some embodiments of the present invention, the,
the obtaining sub-module 4021 is configured to obtain a self-increment number corresponding to the maximum batch number of the first timestamp;
the determining sub-module 4022 is configured to determine the maximum batch number of the first timestamp as the first batch number and determine the self-increment number corresponding to the maximum batch number of the first timestamp as the first self-increment number when the self-increment number corresponding to the maximum batch number of the first timestamp is smaller than the self-increment threshold.
In some embodiments of the present invention, the,
the generating module 401 is configured to splice and combine the first timestamp, the first batch number, and the first self-increment number, and periodically generate the first identifier in batches; storing the first identifier in an identifier pool;
the obtaining module 402 is further configured to preferentially obtain the first identifier from the identifier pool when receiving an identifier generation request of the service data of the distributed node.
In some embodiments, the system time is calibrated system time, and the calibrated system time is obtained by performing periodic calibration according to time data provided by a time center;
an obtaining module 402, configured to obtain a calibrated system time and a maximum timestamp before calibration, where the maximum timestamp before calibration is a maximum timestamp included in a generated identifier in a distributed system;
the generating module 401 is configured to generate a first timestamp in real time according to the calibrated system time when the calibrated system time is greater than the maximum timestamp before calibration.
In some embodiments, the system time is calibrated system time, and the calibrated system time is obtained by performing periodic calibration according to time data provided by a time center;
an obtaining module 402, configured to obtain a calibrated system time and a maximum timestamp before calibration, where the maximum timestamp before calibration is a maximum timestamp included in a generated identifier in a distributed system;
a generating module 401, configured to generate a second timestamp in real time according to the calibrated system time when the calibrated system time is less than the maximum timestamp before calibration;
an obtaining module 402, configured to, when a second timestamp exists in the distributed node, increment a maximum batch number corresponding to the second timestamp to obtain a second batch number, and obtain a second self-increment number;
a generating module 401, configured to generate a second identifier according to the second timestamp, the second batch number, and the second self-increment number.
In some embodiments of the present invention, the,
the determining sub-module 4022 is configured to, when the maximum batch number corresponding to the second timestamp is smaller than the second batch threshold, add y to the maximum batch number corresponding to the second timestamp to obtain a second batch number, and correspondingly assign a second initial value to the second self-increment number, where y is a preset value.
To sum up, the identifier generating apparatus in the distributed system provided in this embodiment generates the first timestamp in real time according to the system time in the distributed node; acquiring a first batch number and a first self-increment number based on a first timestamp; the first batch number is used for marking the identified batch generated under the first time stamp; the first self-increment number is an integer which increases at a constant rate, and the first self-increment number is used for generating a plurality of identifications under the first batch number of the first time stamp; and generating a first identifier according to the first timestamp, the first batch number and the first self-increment number, wherein the first identifier is used as a unique identifier of the service data. The method is that the batch number is added in the mark; in the process of generating the identifier based on one timestamp, if the number of increments reaches the upper limit, the identifier can be continuously generated by incrementing the batch number. That is to say, a greater number of identifiers can be generated by dividing batches, and in a scenario with high concurrent service requests, corresponding identifier generation service can be provided for a large amount of service data, so that a large amount of requirements of a service system on the identifiers are met, and the waiting problem caused by insufficient number of generated identifiers is avoided.
The identification generation device in the distributed system also adopts different batch numbers to distinguish the identifications generated before time callback and after time callback under the same timestamp, so that in the identification generation process, even if the time callback phenomenon occurs, the device can still continue to generate the identifications, repeated identifications cannot occur, and the uniqueness of the generated identifications can be ensured.
Secondly, if a large number of identifiers need to be generated at the same time, the identifiers can also be realized by adopting batch numbers, for example, in one distributed node, a 12-bit self-increment number can correspondingly generate 1024 identifiers, and if a batch number with a batch threshold value of n is added and n is a positive integer, in one distributed node, n times of 1024 identifiers can be generated under the same timestamp, so that the service requirements can be better met.
Referring to fig. 8, a schematic structural diagram of a server according to an exemplary embodiment of the present application is shown. The server is any distributed node in the distributed system 100, and is configured to execute the identifier generation method in the distributed system in the above-described alternative embodiment, specifically:
the server 500 includes a Central Processing Unit (CPU)501, a system memory 504 including a Random Access Memory (RAM)502 and a Read Only Memory (ROM)503, and a system bus 505 connecting the system memory 504 and the central processing unit 501. The server 500 also includes a basic input/output system (I/O system) 506, which facilitates transfer of information between devices within the computer, and a mass storage device 507, which stores an operating system 513, application programs 514, and other program modules 515.
The basic input/output system 506 comprises a display 508 for displaying information and an input device 509, such as a mouse, keyboard, etc., for user input of information. Wherein a display 508 and an input device 509 are connected to the central processing unit 501 through an input output controller 510 connected to the system bus 505. The basic input/output system 506 may also include an input/output controller 510 for receiving and processing input from a number of other devices, such as a keyboard, mouse, or electronic stylus. Similarly, input-output controller 510 also provides output to a display screen, a printer, or other type of output device.
The mass storage device 507 is connected to the central processing unit 501 through a mass storage controller (not shown) connected to the system bus 505. The mass storage device 507 and its associated computer-readable media provide non-volatile storage for the server 500. That is, the mass storage device 507 may include a computer readable medium (not shown) such as a hard disk or CD-ROM drive.
Without loss of generality, computer readable media may comprise computer storage media and communication media. Computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media includes RAM, ROM, EPROM, EEPROM, flash memory or other solid state memory technology, CD-ROM, DVD, or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that computer storage media is not limited to the foregoing. The system memory 504 and mass storage device 507 described above may be collectively referred to as memory.
According to various embodiments of the present application, server 500 may also operate as a remote computer connected to a network through a network, such as the Internet. That is, the server 500 may be connected to the network 512 through the network interface unit 511 connected to the system bus 505, or may be connected to other types of networks or remote computer systems (not shown) using the network interface unit 511.
The memory further includes one or more programs, and the one or more programs are stored in the memory and configured to be executed by the CPU.
The present application also provides a distributed node in a distributed system, where the distributed node includes: a processor and a memory, the storage medium having stored therein at least one instruction, at least one program, a set of codes, or a set of instructions, which is loaded and executed by the processor to implement the method for generating an identity in a distributed system provided by the above-mentioned method embodiments.
The present application further provides a computer-readable storage medium, in which at least one instruction, at least one program, a code set, or a set of instructions is stored, and the at least one instruction, the at least one program, the code set, or the set of instructions is loaded and executed by a processor to implement the identifier generation method in the distributed system provided by the above method embodiments.
It should be understood that reference to "a plurality" herein means two or more. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only exemplary of the present application and should not be taken as limiting, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the protection scope of the present application.

Claims (11)

1. An identifier generation method in a distributed system, which is applied to distributed nodes in the distributed system, the method comprising:
generating a first timestamp in real time according to the system time in the distributed nodes;
acquiring a first batch number and a first self-increment number based on the first timestamp; the first lot number is used to mark the identified lot generated under the first timestamp; the first incrementing number is an integer that increments at a constant rate, the first incrementing number being used to generate a number of tokens at the first lot number of the first timestamp;
and generating a first identifier according to the first timestamp, the first batch number and the first self-increment number, wherein the first identifier is used as a unique identifier of the service data.
2. The method of claim 1, wherein obtaining a first lot number and a first self-increment number based on the first timestamp comprises:
when the first timestamp exists in the distributed nodes, acquiring a maximum batch number corresponding to the first timestamp;
when the maximum batch number corresponding to the first timestamp is smaller than a first batch threshold value, adding x to the maximum batch number corresponding to the first timestamp to obtain the first batch number, and correspondingly assigning a first initial value to the first self-increment number; wherein x is a preset value.
3. The method of claim 2, wherein when the maximum lot number corresponding to the first timestamp is less than a first lot threshold, adding x to the maximum lot number corresponding to the first timestamp to obtain the first lot number comprises:
acquiring a self-increment number corresponding to the maximum batch number of the first timestamp;
and when the self-increment number corresponding to the maximum batch number of the first timestamp is equal to a self-increment threshold, executing the step of adding x to the maximum batch number corresponding to the first timestamp to obtain the first batch number when the maximum batch number corresponding to the first timestamp is smaller than a first batch threshold.
4. The method of claim 2, further comprising:
acquiring a self-increment number corresponding to the maximum batch number of the first timestamp;
and when the self-increment number corresponding to the maximum batch number of the first timestamp is smaller than a self-increment threshold, determining the maximum batch number of the first timestamp as the first batch number, and determining the self-increment number corresponding to the maximum batch number of the first timestamp as the first self-increment number.
5. The method of any of claims 1 to 4, wherein generating a first identifier from the first timestamp, the first lot number, and the first self-increment number comprises:
splicing and combining the first timestamp, the first batch number and the first self-increment number, and periodically generating the first identifier in batches;
storing the first identifier in an identifier pool;
the method further comprises the following steps:
and when receiving an identifier generation request of the service data of the distributed node, preferentially acquiring the first identifier from the identifier pool.
6. The method according to any one of claims 1 to 4, wherein the system time is the calibrated system time, and the calibrated system time is obtained by performing periodic calibration according to time data provided by a time center;
the generating a first timestamp in real time according to the system time in the distributed node includes:
acquiring the calibrated system time and a maximum timestamp before calibration, wherein the maximum timestamp before calibration is the maximum timestamp included in the generated identifier in the distributed system;
and when the calibrated system time is greater than the maximum timestamp before calibration, generating the first timestamp in real time according to the calibrated system time.
7. The method according to any one of claims 1 to 4, wherein the system time is the calibrated system time, and the calibrated system time is obtained by performing periodic calibration according to time data provided by a time center;
the method further comprises the following steps:
acquiring the calibrated system time and a maximum timestamp before calibration, wherein the maximum timestamp before calibration is the maximum timestamp included in the generated identifier in the distributed system;
when the calibrated system time is smaller than the maximum timestamp before calibration, generating a second timestamp in real time according to the calibrated system time;
when the second timestamp exists in the distributed node, increasing the maximum batch number corresponding to the second timestamp to obtain a second batch number, and acquiring a second self-increment number;
and generating a second identifier according to the second timestamp, the second batch number and the second self-increment number.
8. The method according to claim 7, wherein the incrementing the maximum batch number corresponding to the second timestamp to obtain a second batch number and obtaining a second self-increment number comprises:
and when the maximum batch number corresponding to the second timestamp is smaller than a second batch threshold value, adding y to the maximum batch number corresponding to the second timestamp to obtain the second batch number, and correspondingly assigning a second initial value to the second self-increment number, wherein y is a preset value.
9. An apparatus for generating an identifier in a distributed system, the apparatus being in a distributed node of the distributed system, the apparatus comprising:
the generating module is used for generating a first timestamp in real time according to the system time in the distributed nodes;
the acquisition module is used for acquiring a first batch number and a first self-increment number based on the first timestamp; the first lot number is used to mark the identified lot generated under the first timestamp; the first incrementing number is an integer that increments at a constant rate, the first incrementing number being used to generate a number of tokens at the first lot number of the first timestamp;
the generating module is configured to generate a first identifier according to the first timestamp, the first batch number, and the first self-increment number, where the first identifier is used as a unique identifier of the service data.
10. A distributed node, comprising a processor and a memory having stored therein at least one instruction, at least one program, a set of codes, or a set of instructions, which is loaded and executed by the processor to implement an identity generation method in a distributed system as claimed in any one of claims 1 to 8.
11. A computer-readable storage medium having stored therein at least one instruction, at least one program, a set of codes, or a set of instructions, which is loaded and executed by a processor to implement an identity generation method in a distributed system as claimed in any one of claims 1 to 8.
CN201910936832.7A 2019-09-29 2019-09-29 Identification generation method, device, equipment and storage medium in distributed system Active CN110677511B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910936832.7A CN110677511B (en) 2019-09-29 2019-09-29 Identification generation method, device, equipment and storage medium in distributed system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910936832.7A CN110677511B (en) 2019-09-29 2019-09-29 Identification generation method, device, equipment and storage medium in distributed system

Publications (2)

Publication Number Publication Date
CN110677511A true CN110677511A (en) 2020-01-10
CN110677511B CN110677511B (en) 2021-01-01

Family

ID=69080266

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910936832.7A Active CN110677511B (en) 2019-09-29 2019-09-29 Identification generation method, device, equipment and storage medium in distributed system

Country Status (1)

Country Link
CN (1) CN110677511B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112256930A (en) * 2020-10-09 2021-01-22 北京沃东天骏信息技术有限公司 Method, device and system for batch generation of identification codes for distributed services
CN112925618A (en) * 2021-02-22 2021-06-08 北京达佳互联信息技术有限公司 Distributed task processing method and device
CN114900497A (en) * 2022-05-09 2022-08-12 上海极豆科技有限公司 Identification serial number generation method and device, electronic equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140019536A1 (en) * 2012-07-12 2014-01-16 International Business Machines Corporation Realtime collaboration system to evaluate join conditions of potential participants
CN106899654A (en) * 2016-08-10 2017-06-27 阿里巴巴集团控股有限公司 A kind of sequence value generation method, apparatus and system
CN107800733A (en) * 2016-08-31 2018-03-13 阿里巴巴集团控股有限公司 The generation method and equipment of session identification in distributed system
CN108804545A (en) * 2018-05-18 2018-11-13 深圳市彬讯科技有限公司 Distributed globally unique ID generation methods and equipment
CN109491772A (en) * 2018-09-28 2019-03-19 深圳财富农场互联网金融服务有限公司 Business serial number gencration method, apparatus, computer equipment and storage medium
CN109697133A (en) * 2018-12-28 2019-04-30 广州华多网络科技有限公司 ID generation method, apparatus and system

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140019536A1 (en) * 2012-07-12 2014-01-16 International Business Machines Corporation Realtime collaboration system to evaluate join conditions of potential participants
CN106899654A (en) * 2016-08-10 2017-06-27 阿里巴巴集团控股有限公司 A kind of sequence value generation method, apparatus and system
CN107800733A (en) * 2016-08-31 2018-03-13 阿里巴巴集团控股有限公司 The generation method and equipment of session identification in distributed system
CN108804545A (en) * 2018-05-18 2018-11-13 深圳市彬讯科技有限公司 Distributed globally unique ID generation methods and equipment
CN109491772A (en) * 2018-09-28 2019-03-19 深圳财富农场互联网金融服务有限公司 Business serial number gencration method, apparatus, computer equipment and storage medium
CN109697133A (en) * 2018-12-28 2019-04-30 广州华多网络科技有限公司 ID generation method, apparatus and system

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112256930A (en) * 2020-10-09 2021-01-22 北京沃东天骏信息技术有限公司 Method, device and system for batch generation of identification codes for distributed services
CN112925618A (en) * 2021-02-22 2021-06-08 北京达佳互联信息技术有限公司 Distributed task processing method and device
CN114900497A (en) * 2022-05-09 2022-08-12 上海极豆科技有限公司 Identification serial number generation method and device, electronic equipment and storage medium
CN114900497B (en) * 2022-05-09 2023-09-26 上海极豆科技有限公司 Identification sequence number generation method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN110677511B (en) 2021-01-01

Similar Documents

Publication Publication Date Title
CN110677511B (en) Identification generation method, device, equipment and storage medium in distributed system
CN107733708B (en) Equipment parameter configuration method and device, computer equipment and storage medium
CN109697133A (en) ID generation method, apparatus and system
CN109379448B (en) File distributed deployment method and device, electronic equipment and storage medium
CN111163130B (en) Network service system and data transmission method thereof
CN109388626B (en) Method and apparatus for assigning numbers to services
CN111177081A (en) Game log content query method and device, computer equipment and storage medium
CN112836152B (en) Page rendering method, system, computer device and computer readable storage medium
US20190044741A1 (en) Methods And Apparatus To Manage Timing In A Blockchain Network
CN111159612B (en) Countdown method, system, device, computer equipment and storage medium
EP2458811B1 (en) Method, apparatus and system for processing user identity information in gigabit passive optical network system
CN111459676A (en) Node resource management method, device and storage medium
US20190372825A1 (en) Communication apparatus, communication method, and recording medium
CN111275495A (en) Advertisement putting monitoring method, device and system based on block chain
CN109271193B (en) Data processing method, device, equipment and storage medium
CN111163140A (en) Method, apparatus and computer readable storage medium for resource acquisition and allocation
CN112653632A (en) Flow control realization method and device
CN111405027A (en) Block chain consensus result screening method and device, computer equipment and storage medium
CN111338607A (en) Method and device for selecting service data for testing and electronic equipment
US10033817B2 (en) Stateless technique for distributing data uploads
JP6233846B2 (en) Variable-length nonce generation
CN110935168B (en) Distributed ID generation method, device and equipment for global uniform architecture
CN113746918A (en) Hypertext transfer protocol proxy method and system
CN113326242A (en) Data processing method and device, electronic equipment and computer storage medium
EP3046307A1 (en) Processing method, device and system for data of distributed storage system

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
GR01 Patent grant
GR01 Patent grant