CN114116848A - Data identifier generation method and device, computer equipment and storage medium - Google Patents

Data identifier generation method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN114116848A
CN114116848A CN202111441984.3A CN202111441984A CN114116848A CN 114116848 A CN114116848 A CN 114116848A CN 202111441984 A CN202111441984 A CN 202111441984A CN 114116848 A CN114116848 A CN 114116848A
Authority
CN
China
Prior art keywords
time
identifier
node
data
generating
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
CN202111441984.3A
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.)
Chongqing Unisinsight Technology Co Ltd
Original Assignee
Chongqing Unisinsight 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 Chongqing Unisinsight Technology Co Ltd filed Critical Chongqing Unisinsight Technology Co Ltd
Priority to CN202111441984.3A priority Critical patent/CN114116848A/en
Publication of CN114116848A publication Critical patent/CN114116848A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2474Sequence data queries, e.g. querying versioned data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9537Spatial or temporal dependent retrieval, e.g. spatiotemporal queries
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0638Clock or time synchronisation among nodes; Internode synchronisation
    • H04J3/0658Clock or time synchronisation among packet nodes
    • H04J3/0661Clock or time synchronisation among packet nodes using timestamps
    • H04J3/0667Bidirectional timestamps, e.g. NTP or PTP for compensation of clock drift and for compensation of propagation delays

Abstract

The invention relates to the technical field of distributed systems, and provides a data identifier generation method, a data identifier generation device, computer equipment and a storage medium, which are applied to nodes in a distributed system, wherein the method comprises the following steps: acquiring a preset starting time and a current time; determining a time identifier according to a preset starting time and the current time, wherein the precision of the time identifier is second; determining a node identification for uniquely characterizing a node; generating a serial number; and generating a data identifier according to the time identifier, the node identifier and the serial number. Compared with the prior art, the method and the device determine the time identification according to the preset starting time and the current time, set the precision of the time identification to be second, and finally generate the data identification according to the time identification, the determined node identification and the generated serial number, so that the generated data identification can meet the requirements of most scenes, and the data identification repetition caused by millisecond-level time callback is avoided.

Description

Data identifier generation method and device, computer equipment and storage medium
Technical Field
The present invention relates to the field of distributed system technologies, and in particular, to a data identifier generation method, an apparatus, a computer device, and a storage medium.
Background
A distributed system consists of multiple computers that are geographically dispersed and may be spread throughout a single unit, a single city, a single country, or even globally. The functions of the whole distributed system are realized in a distributed mode on each node, and therefore the distributed system has the data processing distributivity. Each node in the distributed system comprises a processor and a memory thereof, and each node has an independent function of processing data. Generally, they are equal in rank, have no primary or secondary points, and can work autonomously, and can coordinate task processing by transmitting information through a shared communication line.
In many application scenarios, data of each node in the distributed system needs to be distinguished from each other to ensure uniqueness of the data, and how to generate a unique identifier for each data is one of the main problems concerned by those skilled in the art.
Disclosure of Invention
The invention provides a data identifier generation method, a data identifier generation device, computer equipment and a storage medium, which can ensure that the generated data identifier can meet the requirements of most scenes and avoid data identifier repetition caused by millisecond time callback.
In order to achieve the purpose, the technical scheme adopted by the invention is as follows:
in a first aspect, the present invention provides a data identifier generating method, applied to a node in a distributed system, where the method includes: acquiring a preset starting time and a current time; determining a time identifier according to the preset starting time and the current time, wherein the precision of the time identifier is second; determining a node identification for uniquely characterizing the node; generating a serial number; and generating the data identifier according to the time identifier, the node identifier and the serial number.
In a second aspect, the present invention provides a data identifier generating apparatus, applied to a node in a distributed system, the apparatus including: the acquisition module is used for acquiring preset starting time and current time; the determining module is used for determining a time identifier according to the preset starting time and the current time, wherein the precision of the time identifier is second; the determining module is further used for determining a node identifier for uniquely characterizing the node; the generating module is used for generating a serial number; and the generating module is further used for generating the data identifier according to the time identifier, the node identifier and the serial number.
In a third aspect, the present invention provides a computer device comprising a memory and a controller, wherein the controller implements the above-mentioned data identifier generation method when executing the computer program.
In a fourth aspect, the present invention provides a computer-readable storage medium having stored thereon a computer program which, when executed by a controller, implements the data identifier generation method described above.
Compared with the prior art, the method and the device determine the time identification according to the preset starting time and the current time, set the precision of the time identification to be second, and finally generate the data identification according to the time identification, the determined node identification and the generated serial number, so that the generated data identification can meet the requirements of most scenes, and the data identification repetition caused by millisecond-level time callback is avoided.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.
Fig. 1 is an application scenario diagram provided in the embodiment of the present invention.
Fig. 2 is a block diagram of a computer device according to an embodiment of the present invention.
Fig. 3 is a structural example of a data identifier generated by the snowfall algorithm according to the embodiment of the present invention.
Fig. 4 is a flowchart illustrating a data identifier generating method according to an embodiment of the present invention.
Fig. 5 is a flowchart illustrating another data identifier generating method according to an embodiment of the present invention.
Fig. 6 is a flowchart illustrating another data identifier generating method according to an embodiment of the present invention.
Fig. 7 is a structural example of improved data identification provided by the embodiment of the present invention.
Fig. 8 is a block diagram illustrating a data identifier generating apparatus according to an embodiment of the present invention.
Icon: 10-a computer device; 11-a controller; 12-a memory; 13-a bus; 20-a client; 30-node; 100-data identification generation means; 110-an obtaining module; 120-a determination module; 130-generation module.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
In the description of the present invention, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. indicate an orientation or a positional relationship based on that shown in the drawings or that the product of the present invention is used as it is, this is only for convenience of description and simplification of the description, and it does not indicate or imply that the device or the element referred to must have a specific orientation, be constructed in a specific orientation, and be operated, and thus should not be construed as limiting the present invention.
Furthermore, the appearances of the terms "first," "second," and the like, if any, are used solely to distinguish one from another and are not to be construed as indicating or implying relative importance.
It should be noted that the features of the embodiments of the present invention may be combined with each other without conflict.
Referring to fig. 1, fig. 1 is an application scenario diagram provided by an embodiment of the present invention, in fig. 1, a distributed system includes a plurality of nodes 30, and uniformly provides services to a plurality of clients 20 through agents, and in many application scenarios, each node 30 needs to generate a unique data identifier for data when interacting with the client 20.
The client 20 is usually a user of the distributed system, and the client 20 may be a mobile terminal such as a mobile phone and a tablet computer, or may be a physical or virtual host, an application server, or the like.
The node 30 is a physical computer device, and includes a physical host device or a server device, and may also be a cluster composed of a plurality of host devices or server devices, or a storage array, etc.
Referring to fig. 2, fig. 2 is a block diagram of a computer device 10 according to an embodiment of the present invention, where the computer device 10 may be any node 30 in fig. 1, and fig. 2 is the block diagram of the computer device 10 according to the embodiment of the present invention, and the computer device 10 includes a controller 11, a memory 12, and the controller 11 is connected to the memory 12 through a bus 13.
The memory 12 is used for storing a program, for example, a data identifier generating device in the embodiment of the present invention, the data identifier generating device includes at least one software functional module which can be stored in the memory 12 in a form of software or firmware (firmware), and the controller 11 executes the program after receiving an execution instruction to implement the data identifier generating method disclosed in the embodiment of the present invention.
The Memory 12 may include a Random Access Memory (RAM) and may also include a non-volatile Memory (NVM).
The controller 11 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the method described below may be performed by instructions in the form of hardware, integrated logic circuits, or software in the controller 11. The controller 11 may be a general-purpose processor, and includes a Central Processing Unit (CPU), a Micro Control Unit (MCU), a Complex Programmable Logic Device (CPLD), a Field Programmable Gate Array (FPGA), and an embedded ARM.
In the distributed system based on fig. 1, in order to ensure the uniqueness of data, the node 30 generally directly uses a universal Unique Identifier UUID (UUID) as a Unique Identifier of the data, but the length of the UUID is 128 bits, the occupied storage space is relatively large, and the UUID is stored in a character string, when comparing identifiers, the data of the character string type is much slower than the data of the numerical type, and more importantly, the UUID cannot guarantee the trend to increase, which results in a very large limitation in the application scenario.
In order to overcome the above defects of the UUID, a snowfly algorithm is usually adopted to generate a numerical data identifier, the length of the identifier generated by the algorithm is 64 bits, which is much smaller than that of the UUID, and the trend can be ensured to increase progressively. Referring to fig. 3, fig. 3 is a structural example of a data identifier generated by the snowfall algorithm according to the embodiment of the present invention, and in fig. 3, the data identifier includes a sign bit of 1bit, a timestamp of 41bit, a machine number of 10bit, and a serial number of 12 bit. Wherein, the sign bit is 1 to indicate that the data identifier is a negative number, and 0 to indicate that the data identifier is not a negative number; the timestamp is accurate to milliseconds, and the maximum usable life is 69 years; the machine number is used for representing nodes in the distributed system, and 1024 nodes can be deployed by a machine number of 10 bits; a 12bit sequence number, meaning 1 millisecond, may be 4096 maximum numbers of generated data identifications.
Although the algorithm can generate the data identifier with the identifier length of 64 bits and can ensure that the trend is increased progressively, due to the fact that the uniqueness of the timestamp is ensured, when the time of the node is set to the past time (namely, the time callback occurs), the timestamp may have a repeated situation, the generated data identifier is repeated, and the uniqueness of the data identifier cannot be ensured at this time.
In order to solve the above problems, the prior art also uses auto _ increment function provided by an open source component itself, such as a database or Redis, to generate a unique data identifier, but this approach needs to rely on a corresponding third-party component, and both fault tolerance and performance are poor.
The prior art also has an improved scheme aiming at the snowfall algorithm, and one of the schemes is as follows: caching the generated data identification, after the data identification is generated by using a snowfall algorithm, searching whether repeated data identification exists from the cache, and if the data identification is stored, regenerating the data identification until no repeated data identification exists. According to the scheme, data needs to be cached, so that the memory is occupied on one occasion, and the data needs to be retrieved every time, so that the performance is influenced. The second scheme is as follows: the 10-bit machine number is subdivided into a plurality of bits to be used as callback bits, each time when the data identifier is generated, whether callback conditions exist needs to be checked, and if callback occurs, the callback bits need to be increased progressively. The proposal can only process the time callback for limited times due to the limited callback position, and occupies machine numbers, so that the maximum machine number supported by the distributed system is reduced.
In view of this, embodiments of the present invention provide a data identifier generation method and apparatus, a computer device, and a storage medium, which can ensure that the generated data identifier can meet the needs of most scenes, and avoid data identifier duplication caused by millisecond-level time callback, and are described in detail below.
Referring to fig. 4, fig. 4 is a flowchart illustrating a data identifier generating method according to an embodiment of the present invention, where the method includes the following steps:
step S100, acquiring a preset starting time and a current time.
In this embodiment, the preset starting time may be set as needed when the distributed system is deployed, for example, the preset starting time is set as an initialization time of the distributed system. It may also be automatically generated, for example, with the zero point of the day on which the distributed system is installed as the preset start time. The current time is obtained from the operating system of the node 30.
Step S110, determining a time identifier according to a preset starting time and the current time, wherein the precision of the time identifier is second.
In this embodiment, the time indicator may be expressed by a time length between the preset starting time and the current time, and the time length is in seconds. Because the precision of the time identifier is second, the time identifier does not need to occupy 41 bits like the existing snowfall algorithm, and only needs to occupy 30 bits. In the case of being accurate to seconds, the time stamp in the embodiment of the present invention can be expressed as 2 at maximum30The second, namely the maximum service life of the solar water heater is 34 years, and the requirements of most scenes can be met.
Step S120, determining a node identifier for uniquely characterizing the node.
In this embodiment, the node identifier may be obtained by numbering each node in the distributed system in advance, or may be obtained by a middleware specially allocating an identifier, for example, allocating a preset sequence number by the Zookeeper middleware, processing the preset sequence number into a value between [0 and the maximum node number of-1 ], and using the value as the node identifier.
Step S130, a serial number is generated.
In this embodiment, since the time identification is accurate to seconds, the sequence numbers of the data processed by each node 30 within 1 second may be generated in an increasing or decreasing order, for example, if the number of the data processed by the node 30 within 1 second at the current time is 1000, the sequence numbers of the 1000 data are integers between [0, 999 ].
Step S140, generating a data identifier according to the time identifier, the node identifier and the serial number.
In this embodiment, the data identifier generated according to the time identifier, the node identifier, and the serial number may uniquely represent data generated by different nodes 30 within 1 second.
It should be noted that the snowfall algorithm also has a sign bit, and as a specific generation mode, the sign bit, the time identifier, the node identifier, and the serial number may be sequentially arranged to obtain the data identifier.
The method provided by the embodiment of the invention can be used for accurately marking the time to the second, not only can meet the requirement of processing the data volume in most scenes, but also can avoid the problem of repeated data marking caused by millisecond-level time callback, and meanwhile, the method does not need to depend on other third-party components, and can realize better fault tolerance and performance.
On the basis of fig. 4, an embodiment of the present invention further provides a specific implementation manner of determining a time identifier, please refer to fig. 5, fig. 5 is a flowchart illustrating another data identifier generating method provided in the embodiment of the present invention, and step S110 includes the following sub-steps:
in sub-step S1101, a time length between a preset start time and the current time is calculated.
In this embodiment, the duration may be a difference between a preset starting time represented by seconds and a current time.
And a substep S1102, determining the time length as the time identifier.
In this embodiment, the preset start time is different, and the time identifier obtained under the same condition is also different, and since the preset start time can be set as required, the timestamp can not be directly used like the existing snowfall algorithm, that is, the preset start time is fixedly set to 1 month and 1 day zero in 1970, and the bit of the time identifier is prevented from being occupied by the overlong historical time period.
In this embodiment, the time identifier is represented by a duration, which saves bits of the time identifier, and can represent more time identifiers, thereby generating more data identifiers.
On the basis of fig. 4, an embodiment of the present invention further provides a specific implementation manner of determining a node identifier, please refer to fig. 6, where fig. 6 is a flowchart illustrating another data identifier generating method provided in the embodiment of the present invention, and step S120 includes the following sub-steps:
and a substep S1201, if the time callback occurs, regenerating the node identifier.
In this embodiment, the clock callback is related to a hardware clock and a Network Time Protocol NTP (NTP) service. The hardware clock may be inaccurate for various reasons, and the NTP service is provided in the network to perform time calibration, and when the calibration is performed, the problem of clock jump or callback occurs.
In this embodiment, as a specific time callback determination method, the specific implementation manner may be:
first, the generation time of the initial identifier is acquired.
In this embodiment, the initial identifier is a node identifier generated by the node 30 last time, and when the time callback does not occur, the initial identifier is a node identifier generated for the first time.
Then, if the current time is earlier than the generation time, determining that the generation time is dialed back; and if the current time is not earlier than the generation time, judging that time callback does not occur.
In this embodiment, as a specific implementation manner, in order to facilitate unifying the flow of generating the node identifier each time, the generation time of the initial identifier may be initialized to a preset time later than the current time, and when the node identifier is generated for the first time, it is determined that the current time is earlier than the generation time, the node identifier is regenerated again.
In this embodiment, there is a risk that the data identifier is repeated only when the time callback occurs, and at this time, in order to avoid generating a repeated data identifier, special processing needs to be performed, so that the embodiment of the present invention provides a method for avoiding the problem of the generated data identifier being repeated due to the time callback by regenerating the node identifier, and a specific implementation manner of the method may be:
firstly, a registration message is sent to a Zookeeper component to indicate the Zookeeper component to generate a preset sequence number for a node based on the registration message, and the preset sequence number is returned to the node.
In this embodiment, the Zookeeper component is pre-deployed in the distributed system, and is mainly responsible for data synchronization between the nodes 30 in the distributed system, configuration maintenance of the distributed system, and the like. After the distributed system is started, each node 30 sends a registration message to the Zookeeper component to register a temporal-sequence (Ephemeral-sequential) node, and after the node 30 is created, it obtains a preset sequence number: ZK-ID.
And secondly, receiving a preset sequence number, and generating a node identifier according to the preset sequence number.
In this embodiment, the range of the preset serial number generated by the Zookeeper is 0-231For obtaining the node identifier, as a specific implementation manner, taking the node identifier occupying 21 bits as an example, the node identifier may be obtained by calculating according to the following formula: Machine-ID ═ ZK-ID% 221And the Machine-ID is a node identifier, and the ZK-ID is a preset serial number.
In this embodiment, the node identifier is dynamically obtained through the Zookeeper component, and the problem of data identifier repetition caused by time callback is solved.
In this embodiment, in order to correctly recognize and timely perform corresponding processing when callback occurs in the subsequent time, after the node identifier is regenerated, the following processing needs to be performed:
the initial identity is updated with the node identity.
It is understood that after the initial identifier is updated, the generation time of the initial identifier is also updated accordingly. And when the data identifier is generated next time, judging whether time callback occurs according to the updated generation time of the initial identifier and the current time.
According to the embodiment of the invention, the generated data identification does not need to be cached to judge whether the repeated data identification exists, and only the time of the node identification generated last time needs to be stored, so that the space occupation is reduced, and the data identification generation speed is increased.
And a substep S1202, if the time callback does not occur, determining the initial identifier as the node identifier.
In this embodiment, if the time callback does not occur, the node identifier does not change, that is, the node identifier generated when the node registers with the Zookeeper component for the last time.
In order to more clearly show the improvement of the embodiment of the present invention over the prior art, this embodiment further provides a structural example diagram of the improved data identifier according to the above embodiment, please refer to fig. 7, fig. 7 is a structural example of the improved data identifier provided by the embodiment of the present invention, in fig. 7, the most significant bit in the data identifier is still not a sign bit, and 1 is represented as a negative number; the time mark occupies 30 bits, and the maximum can represent 230Seconds, that is to say a maximum useful life of 34 years; the node identifier occupies 21 bits and can represent 2 at most21And one node, namely about 210 ten thousand nodes can be represented at most.
In fig. 7, the time stamp is shortened from original 41 bits to 30 bits, and in most application scenarios, it is already basically sufficient for each node to process 4096 pieces of data per second, and it is not necessary in most scenarios to use too many bits to make the time accurate to milliseconds. And many time callbacks actually occur in the millisecond level, and another advantage of being accurate to the second is that the time callbacks in the millisecond level do not need to be additionally processed, and the influence on most application scenes is avoided.
In fig. 7, the node identifiers are increased from the original 10 bits to 21 bits, mainly because the node identifier of each node is not fixed, and when the time callback occurs, the node will reapply for a node identifier, 221The identification of the node of the machine can process time callback for a plurality of times, and if 1024 nodes exist in the distributed system, 2 occurs in a short time21/210=211The situation that repeated data identification is possible only after 2048 time callbacks, which is almost impossible to happen in a practical application scenario, can be well avoided, so that the problem that the data identification is repeated due to the time callback can be well avoided.
In fig. 7, the data identification may be generated by the following equation: Unique-ID ═ Delta-Seconds<<33|Machine-ID<<12| Sequence, wherein, the uniform-ID represents data identification, and the Delta-Seconds represents time identification; the Machine-ID indicates a node identification and the Sequence indicates a Sequence number. The sequence number may be as followsGenerating a formula: sequence ═ 2% (Sequence + 1)%12
In order to perform the corresponding steps in the above embodiments and various possible implementations, an implementation of the data identifier generating apparatus 100 is given below. Referring to fig. 8, fig. 8 is a block diagram illustrating a data identifier generating apparatus 100 according to an embodiment of the present invention. It should be noted that the basic principle and the resulting technical effect of the data identifier generating apparatus 100 provided in the present embodiment are the same as those of the above-mentioned embodiments, and for the sake of brief description, no reference is made to this embodiment.
The data identifier generating apparatus 100 includes an obtaining module 110, a determining module 120, and a generating module 130.
The obtaining module 110 is configured to obtain a preset starting time and a current time.
A determining module 120, configured to determine a time identifier according to the preset starting time and the current time, where the precision of the time identifier is second.
The determining module 120 is further configured to determine a node identifier for uniquely characterizing the node.
A generating module 130, configured to generate the sequence number.
The generating module 130 is further configured to generate the data identifier according to the time identifier, the node identifier, and the serial number.
As a specific implementation manner, the determining module 120 is specifically configured to: calculating the time length between the preset starting time and the current time; and determining the duration as the time identifier.
As a specific implementation manner, the node generates an initial identifier in advance, and the determining module 120 is further specifically configured to: if the time callback occurs, the node identifier is regenerated; and if the time callback does not occur, determining the initial identifier as the node identifier.
As a specific implementation manner, the determining module 120 is specifically configured to, when determining the node identifier for uniquely characterizing the node, specifically: acquiring the generation time of the initial identifier; if the current time is earlier than the generation time, determining that the generation time is dialed back; and if the current time is not earlier than the generation time, judging that time callback does not occur.
As a specific implementation manner, the Zookeeper component is deployed in advance in the distributed system, and the generating module 130 is specifically configured to: sending a registration message to the Zookeeper component to indicate the Zookeeper component to generate a preset sequence number for the node based on the registration message, and returning the preset sequence number to the node; and receiving the preset sequence number, and generating the node identification according to the preset sequence number.
As a specific implementation manner, after the generating module 130 is configured to receive the preset sequence number and generate the node identifier according to the preset sequence number, the generating module is specifically configured to: updating the initial identity with the node identity.
As a specific implementation manner, in the data identifier generated by the data identifier generating apparatus 100, the time identifier occupies 30 bits, the node identifier occupies 21 bits, and the sequence number occupies 12 bits.
Embodiments of the present invention also provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the data identifier generating method as described above.
In summary, embodiments of the present invention provide a data identifier generation method, an apparatus, a computer device, and a storage medium, which are applied to a node in a distributed system, where the method includes: acquiring a preset starting time and a current time; determining a time identifier according to a preset starting time and the current time, wherein the precision of the time identifier is second; determining a node identification for uniquely characterizing a node; generating a serial number; and generating a data identifier according to the time identifier, the node identifier and the serial number. Compared with the prior art, the embodiment of the invention determines the time identification according to the preset starting time and the current time, sets the precision of the time identification to be second, and finally generates the data identification according to the time identification, the determined node identification and the generated serial number, thereby not only ensuring that the generated data identification can meet the requirements of most scenes, but also avoiding the data identification repetition caused by millisecond-level time callback.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.

Claims (10)

1. A data identification generation method is applied to nodes in a distributed system, and comprises the following steps:
acquiring a preset starting time and a current time;
determining a time identifier according to the preset starting time and the current time, wherein the precision of the time identifier is second;
determining a node identification for uniquely characterizing the node;
generating a serial number;
and generating the data identifier according to the time identifier, the node identifier and the serial number.
2. The method for generating data identifier according to claim 1, wherein the step of determining the time identifier according to the preset starting time and the current time comprises:
calculating the time length between the preset starting time and the current time;
and determining the duration as the time identifier.
3. The data identifier generation method of claim 1, wherein the node is pre-generated with an initial identifier, and the step of determining the node identifier for uniquely characterizing the node comprises:
if the time callback occurs, the node identifier is regenerated;
and if the time callback does not occur, determining the initial identifier as the node identifier.
4. The data identifier generating method according to claim 3, wherein the distributed system is pre-deployed with a Zookeeper component, and the step of regenerating the node identifier includes:
sending a registration message to the Zookeeper component to indicate the Zookeeper component to generate a preset sequence number for the node based on the registration message, and returning the preset sequence number to the node;
and receiving the preset sequence number, and generating the node identification according to the preset sequence number.
5. The method according to claim 4, wherein the step of receiving the preset sequence number and generating the node identifier according to the preset sequence number further comprises:
updating the initial identity with the node identity.
6. The data identity generation method of claim 3, wherein the step of determining a node identity for uniquely characterizing the node further comprises:
acquiring the generation time of the initial identifier;
if the current time is earlier than the generation time, determining that the generation time is dialed back;
and if the current time is not earlier than the generation time, judging that time callback does not occur.
7. The method for generating data identifier according to any of claims 1 to 6, wherein the time identifier occupies 30 bits, the node identifier occupies 21 bits, and the serial number occupies 12 bits.
8. A data identifier generating apparatus, applied to a node in a distributed system, the apparatus comprising:
the acquisition module is used for acquiring preset starting time and current time;
the determining module is used for determining a time identifier according to the preset starting time and the current time, wherein the precision of the time identifier is second;
the determining module is further used for determining a node identifier for uniquely characterizing the node;
the generating module is used for generating a serial number;
and the generating module is further used for generating the data identifier according to the time identifier, the node identifier and the serial number.
9. A computer device comprising a memory and a controller, wherein the controller implements the data identity generation method of any one of claims 1-7 when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a controller, carries out the data identity generation method according to any one of claims 1 to 7.
CN202111441984.3A 2021-11-30 2021-11-30 Data identifier generation method and device, computer equipment and storage medium Pending CN114116848A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111441984.3A CN114116848A (en) 2021-11-30 2021-11-30 Data identifier generation method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111441984.3A CN114116848A (en) 2021-11-30 2021-11-30 Data identifier generation method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114116848A true CN114116848A (en) 2022-03-01

Family

ID=80368100

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111441984.3A Pending CN114116848A (en) 2021-11-30 2021-11-30 Data identifier generation method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114116848A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114827082A (en) * 2022-06-29 2022-07-29 广州市玄武无线科技股份有限公司 Method, system, device and medium for generating globally unique ID of distributed system

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114827082A (en) * 2022-06-29 2022-07-29 广州市玄武无线科技股份有限公司 Method, system, device and medium for generating globally unique ID of distributed system

Similar Documents

Publication Publication Date Title
CN110554732B (en) Identification number generation method and device, electronic equipment and storage medium
CN113515531B (en) Data access method, device, client and storage medium
CN107666493B (en) Database configuration method and equipment thereof
CN111064626B (en) Configuration updating method, device, server and readable storage medium
CN114116848A (en) Data identifier generation method and device, computer equipment and storage medium
CN114979158A (en) Resource monitoring method, system, equipment and computer readable storage medium
CN112527397A (en) Method and device for modifying basic input output system options and computer equipment
CN111064786B (en) Account identifier management method and device
CN112434278A (en) Bare computer authentication method, apparatus, device and medium
CN106941418B (en) SSL VPN configuration information synchronization method and device
CN109669642B (en) Node joining method, system and device of storage system and readable storage medium
CN113704177B (en) Storage method, system and related components of server firmware upgrade file
CN109634353A (en) Server host cascades BOX topological structure clock synchronizing method, device, terminal and storage medium
CN116737764A (en) Method and device for data synchronization, electronic equipment and storage medium
CN111163100B (en) Data structure, communication method, device, storage medium and equipment
CN114020503A (en) Optimization method, system and device for transparent fault switching of distributed file system
CN114356970A (en) Storage system resource caching method and device
CN110474787B (en) Node fault detection method and device
CN113010263A (en) Method, system, equipment and storage medium for creating virtual machine in cloud platform
CN107332679B (en) Centerless information synchronization method and device
CN111625193A (en) Configuration method, device, equipment and medium of multipath alias
CN111865631A (en) Fault information reporting method and device, electronic equipment and readable storage medium
CN111367885A (en) Database management system, database management method, storage medium, and electronic device
CN111126004A (en) Method, device and equipment for generating product sequence code and computer readable storage medium
CN115225193B (en) BMC time synchronization method, system, device and readable storage medium

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