Search

CN-115983201-B - Global unique identifier generation method and device, electronic equipment and storage medium

CN115983201BCN 115983201 BCN115983201 BCN 115983201BCN-115983201-B

Abstract

The embodiment of the invention provides a global unique identifier generation method, a device, electronic equipment and a storage medium, which comprise the steps of receiving a global unique identifier generation request of target data; the method comprises the steps of generating a machine identifier of a machine to which target data belong by utilizing a shift algorithm, randomly generating a sequence identifier and a sub-table identifier, and generating a global unique identifier of the target data based on the machine identifier, the sequence identifier and the sub-table identifier. Because the machine identifier of the machine to which the target data belongs is generated by utilizing the raft algorithm, and then the global unique identifier is generated, and the third party software is not required to be relied on, the additional deployment of resources is not required, and the generation of the global unique identifier under the condition of less resource deployment is realized.

Inventors

  • ZHANG YONGJIE
  • HAN HAIWEN

Assignees

  • 北京奇艺世纪科技有限公司

Dates

Publication Date
20260505
Application Date
20221228

Claims (6)

  1. 1. A method of globally unique identification generation, the method deployed on a machine capable of generating target data, one machine being a node, the method comprising: receiving a global unique identification generation request of target data; The method for generating the machine identification of the machine to which the target data belongs by utilizing the shift algorithm specifically comprises the steps of selecting one node from a plurality of nodes to serve as a leading node by utilizing the shift algorithm; The method comprises the steps of generating a machine identification array, reading a message storage file to obtain the number which is currently allocated, traversing the machine identification array based on the number which is allocated, obtaining the number which is not allocated and sending the number to snowflake algorithm as the machine identification; randomly generating a sequence identifier and a sub-table identifier; And generating a globally unique identifier of the target data based on the machine identifier, the sequence identifier and the sub-table identifier.
  2. 2. The method according to claim 1, wherein the method further comprises: recording the unassigned digits into the message storage file.
  3. 3. The method according to claim 1, wherein the method further comprises: Setting a symbol bit; generating a time stamp of the target data according to preset time and time for receiving the request; a globally unique identification of the target data is generated based on the sign bit, the timestamp, the machine identification, the sequence identification, and the sub-table identification.
  4. 4. A globally unique identification generation apparatus deployed on a machine capable of generating target data, one machine being a node, the apparatus comprising: the request receiving module is used for receiving a global unique identification generation request of target data; The machine identification generation module is used for generating a machine identification of a machine to which the target data belong by utilizing a shift algorithm, and concretely comprises the steps of selecting one node from a plurality of nodes by utilizing the shift algorithm to serve as a leading node, and utilizing the leading node to allocate the machine identification, wherein the machine identification generation module comprises the steps of generating a machine identification array, reading a message storage file to obtain a currently allocated number; The sequence identifier and sub-table identifier generation module is used for randomly generating a sequence identifier and a sub-table identifier; And the first global unique identifier generating module is used for generating the global unique identifier of the target data based on the machine identifier, the sequence identifier and the sub-table identifier.
  5. 5. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus; a memory for storing a computer program; a processor for implementing the steps of the method of any one of claims 1-3 when executing a program stored on a memory.
  6. 6. A computer readable storage medium, characterized in that the computer readable storage medium has stored therein a computer program which, when executed by a processor, implements the steps of the method of any of claims 1-3.

Description

Global unique identifier generation method and device, electronic equipment and storage medium Technical Field The present invention relates to the field of distributed systems, and in particular, to a method and apparatus for generating a global unique identifier, an electronic device, and a storage medium. Background In complex distributed systems, it is often necessary to uniquely identify large amounts of data and messages. There are often multiple business systems in a distributed system, and the data in various business systems is growing, at this time, how to generate a globally unique identifier is an urgent problem to be solved. The solution mainly adopted at present is to use a database self-increasing sequence, but the data volume that can be borne by the method is limited, the situation that the data volume is too large cannot be met, and various ways of generating identifiers depending on the third party middleware appear, for example, global unique identifiers are generated by adopting a way of generating identifiers based on MySQL (My Structured Query Language, structured query language) and snowflake (snowflake) algorithms, or global unique identifiers are generated by adopting a way of generating identifiers based on zookeeper (a distributed application coordination service) and snowflake algorithms, but because the way of depending on the third party middleware needs to depend on the third party software, the third party software needs to additionally deploy resources, and more resources need to be deployed by adopting the way of generating identifiers depending on the third party middleware. Disclosure of Invention The embodiment of the invention aims to provide a global unique identifier generation method, a global unique identifier generation device, electronic equipment and a storage medium, so as to generate a global unique identifier under the condition of less resource deployment. The specific technical scheme is as follows: In a first aspect of the present invention, there is provided a globally unique identifier generation method, including: receiving a global unique identification generation request of target data; Generating a machine identifier of a machine to which the target data belong by using a raft algorithm; randomly generating a sequence identifier and a sub-table identifier; And generating a globally unique identifier of the target data based on the machine identifier, the sequence identifier and the sub-table identifier. Optionally, the generating, by using a shift algorithm, a machine identifier of a machine to which the target data belongs includes: generating a machine identification array; Reading the message storage file to obtain the number which is currently allocated; traversing the machine identification array based on the allocated numbers, acquiring unallocated numbers, and taking the unallocated numbers as unallocated machine identifications. Optionally, the method further comprises: recording the unassigned digits into the message storage file. Optionally, before generating the machine identification array, the method includes: One node is elected from the plurality of nodes as a leader node. Optionally, the method further comprises: Setting a symbol bit; generating a time stamp of the target data according to preset time and time for receiving the request; a globally unique identification of the target data is generated based on the sign bit, the timestamp, the machine identification, the sequence identification, and the sub-table identification. In a second aspect of the present invention, there is also provided a globally unique identification generation apparatus, the apparatus including: the request receiving module is used for receiving a global unique identification generation request of target data; the machine identification generation module is used for generating a machine identification of a machine to which the target data belong by using a shift algorithm; The sequence identifier and sub-table identifier generation module is used for randomly generating a sequence identifier and a sub-table identifier; And the first global unique identifier generating module is used for generating the global unique identifier of the target data based on the machine identifier, the sequence identifier and the sub-table identifier. Optionally, the machine identifier generating module includes: A machine identification array generating unit for generating a machine identification array; a message storage file reading unit for reading the message storage file to obtain the currently allocated number; And the unassigned machine identifier generating unit is used for traversing the machine identifier array based on the assigned numbers, acquiring unassigned numbers and taking the unassigned numbers as unassigned machine identifiers. Optionally, the machine identifier generating module is further configured to: recording the unassigned digits into the message stora