CN118138562A - Identification generation method and device, electronic equipment and readable storage medium - Google Patents

Identification generation method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN118138562A
CN118138562A CN202410250202.5A CN202410250202A CN118138562A CN 118138562 A CN118138562 A CN 118138562A CN 202410250202 A CN202410250202 A CN 202410250202A CN 118138562 A CN118138562 A CN 118138562A
Authority
CN
China
Prior art keywords
zookeeper
server
identifier
distributed
node
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
CN202410250202.5A
Other languages
Chinese (zh)
Inventor
张霖
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and 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 QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN202410250202.5A priority Critical patent/CN118138562A/en
Publication of CN118138562A publication Critical patent/CN118138562A/en
Pending legal-status Critical Current

Links

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The embodiment of the invention provides a method and a device for generating an identifier, electronic equipment and a readable storage medium. The method comprises the following steps: a registration request is sent to a distributed application coordination service Zookeeper, wherein the registration request is used for requesting the Zookeeper, and a temporary node corresponding to the server is created under a pre-created permanent node; receiving a creation result returned by the Zookeeper, and caching a node path of a temporary node carried in the creation result as a machine identifier of the server; a first generating operation is performed. By utilizing the characteristics of the temporary node of the Zookeeper, the server can obtain the corresponding unique machine identifier by registering with the Zookeeper without manually maintaining the machine IP and the machine identifier.

Description

Identification generation method and device, electronic equipment and readable storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for generating an identifier, an electronic device, and a readable storage medium.
Background
With the development of computer technology, the data volume of different types of data on a network is greatly increased, and the different types of data often originate from different systems, and for a large amount of data of multiple systems, it is often necessary to generate unique identifiers (Identity document, IDs) for each piece of data to distinguish, that is, distributed IDs.
The generation of distributed IDs often depends on a cluster of servers, each server in the cluster providing an ID generation service, in which case machine identification (workerid) needs to be configured for the different servers, so as to avoid ID conflicts generated by the different servers.
At present, for a server cluster, mapping is needed between a machine IP and an allocated machine identifier, and a fixed unique machine identifier is formed for different servers, but when the server cluster expands or a server is offline, management of the machine identifier is needed to be realized by manually maintaining a mapping relation, and management difficulty is high.
Disclosure of Invention
The embodiment of the invention aims to provide an identification generation method, an identification generation device, electronic equipment and a readable storage medium, so as to achieve the technical aim of reducing the management difficulty of machine identifications of different servers. The specific technical scheme is as follows:
in a first aspect of the present invention, there is first provided an identifier generating method, which is applied to any one server in a server cluster, including:
a registration request is sent to a distributed application coordination service Zookeeper, wherein the registration request is used for requesting the Zookeeper, and a temporary node corresponding to the server is created under a pre-created permanent node;
Receiving a creation result returned by the Zookeeper, and caching a node path of a temporary node carried in the creation result as a machine identifier of the server;
and executing a first generation operation, wherein the first generation operation is used for generating a distributed identifier based on the machine identifier in the cache.
In a second aspect of the present invention, there is also provided an identifier generating device, applied to any server in a server cluster, including:
The registration module is used for sending a registration request to a distributed application coordination service Zookeeper, wherein the registration request is used for requesting the Zookeeper, and a temporary node corresponding to the server is created under a pre-created permanent node;
The cache module is used for receiving the creation result returned by the Zookeeper and caching the node path of the temporary node carried in the creation result as the machine identifier of the server;
the first execution module is used for executing a first generation operation, and the first generation operation is used for generating a distributed identifier based on the machine identifier in the cache.
In a third aspect of the present invention, there is also provided an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
A memory for storing a computer program;
And a processor, configured to implement the method according to the first aspect when executing the program stored in the memory.
In a fourth aspect of the invention, there is also provided a computer readable storage medium having instructions stored therein which, when run on a computer, cause the computer to perform the method of the first aspect described above.
In a fifth aspect of the invention there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform the method of the first aspect described above.
In the embodiment of the invention, any server in the server cluster can enable the Zookeeper to create a corresponding temporary node for the server by sending a registration request to the Zookeeper, the server only needs to cache the node path of the temporary node as a machine identifier, and a first generation operation is executed to generate a distributed identifier based on the cached machine identifier. In this way, the characteristics of the temporary node of the Zookeeper can be utilized, the machine IP and the machine identifier are not required to be manually maintained so as to realize the management of the machine identifier, and the server can obtain the corresponding unique machine identifier by registering with the Zookeeper. Correspondingly, when the server cluster expands, the newly added server can acquire the corresponding machine identifier by sending a registration request to the Zookeeper, so that the automation management of the machine identifier can be realized through the Zookeeper, and the management difficulty of the machine identifier is reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.
FIG. 1 is a flowchart of a method for generating a logo according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a label generation process in an embodiment of the present invention;
FIG. 3 is a schematic diagram of another identifier generation process in an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an identifier generating device in an embodiment of the present invention;
fig. 5 is a schematic diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below with reference to the accompanying drawings in the embodiments of the present invention.
Fig. 1 is a flowchart of a method for generating a identifier according to an embodiment of the present invention, where the method may be applied to any server in a server cluster, as shown in fig. 1, and the method includes:
step 101, a registration request is sent to a distributed application coordination service Zookeeper, wherein the registration request is used for requesting the Zookeeper, and a temporary node corresponding to the server is created under a pre-created permanent node.
And 102, receiving a creation result returned by the Zookeeper, and caching a node path of the temporary node carried in the creation result as a machine identifier of the server.
Step 103, executing a first generating operation based on the machine identification in the cache.
It should be noted that the embodiment of the present invention may be applied to any type of application, such as a video application, a music application, a social application, and the like, and accordingly, the server cluster may be a set of servers that provide an identifier generating service for the application, and accordingly, any server in the server cluster is used to execute an identifier generating operation. The Zookeeper refers to an open distributed application coordination service, can provide configuration maintenance, name service, distributed synchronization, group service and the like, and can also serve as a service registry.
Specifically, nodes can be created in the Zookeeper, node paths are similar to file paths and are in tree structures, and accordingly, the node paths are unique, namely, the node paths of different nodes are different. In the Zookeeper, the nodes can be divided into a persistent node and a temporary node, once the persistent node is created, the persistent node can only be actively removed by a creator, and the temporary node is related to the connection between the creator and the Zookeeper, when the creator is connected with the Zookeeper, the temporary node is always valid, and correspondingly, when the creator is disconnected with the Zookeeper, the temporary node is deleted.
Based on the above characteristics of the Zookeeper, the embodiment of the invention can take the Zookeeper as a service registration center, the server can send a registration request to the Zookeeper, and after the Zookeeper receives the registration request, a corresponding temporary node can be created for the server on the Zookeeper. It should be noted that, in order to keep the distribution of temporary nodes corresponding to each server in the server cluster uniform, in the embodiment of the present invention, a persistent node may be created in advance in the Zookeeper, and then the temporary nodes corresponding to each server in the server cluster may be created under the persistent node, that is, the temporary node corresponding to any server in the embodiment of the present invention is a child node of the persistent node created in advance.
Specifically, the embodiment of the invention can embed the Zookeeper client in each server in the server cluster, and interact with the Zookeeper server through the client. It should be noted that, the Zookeeper refers to a Zookeeper server.
Further, after the Zookeeper receives the registration request of the server, the Zookeeper can respond to the registration request to create a temporary node corresponding to the server under the persistent node, and send the creation result to the server. Because of the uniqueness of the nodes of the Zookeeper, the embodiment of the invention can directly take the node path of the temporary node carried in the creation result as a machine identifier, namely workerid, and the server can cache workerid locally and execute a first generation operation based on the cached workerid.
The first generation operation refers to an identifier generation operation requiring use of a machine identifier, and may be a snowflake algorithm (snowflake) or a random self-increasing algorithm. Because the node paths of different nodes in the Zookeeper are unique, the node paths of the temporary nodes obtained by different servers in the server cluster are different, so that the machine identification of the server can be conveniently obtained through the Zookeeper. Due to the characteristics of the temporary nodes of the Zookeeper, when the server is disconnected from the Zookeeper, the Zookeeper can automatically delete the corresponding temporary nodes. Correspondingly, when the server cluster expands, the newly added server can acquire the corresponding machine identifier by sending a registration request to the Zookeeper, so that the automation management of the machine identifier can be realized through the Zookeeper.
In summary, in the embodiment of the present invention, by sending a registration request to the Zookeeper, any server in the server cluster may make the Zookeeper create a corresponding temporary node for the server, and the server may cache a node path of the temporary node as a machine identifier, and execute a first generating operation according to the cached machine identifier. Thus, the characteristics of the temporary nodes of the Zookeeper can be utilized, the machine IP and the machine identification do not need to be maintained manually, the server can obtain the corresponding unique machine identification by registering with the Zookeeper, and when the server is disconnected with the Zookeeper, the Zookeeper can automatically delete the corresponding temporary nodes. Correspondingly, when the server cluster expands, the newly added server can acquire the corresponding machine identifier by sending a registration request to the Zookeeper, so that the automation management of the machine identifier can be realized through the Zookeeper, and the management difficulty of the machine identifier is reduced.
Optionally, in the embodiment of the present invention, the operation of sending the registration request to the distributed application coordination service Zookeeper in the step 101 may specifically include the following steps:
s21, establishing network connection with the Zookeeper, and sending a registration request to the Zookeeper based on the network connection.
Accordingly, after the operation of sending the registration request to the Zookeeper based on the network connection in the above steps, the embodiment of the present invention may further include:
s22, sending a connection maintenance request to the Zookeeper according to a preset period;
And under the condition that the connection maintenance request is not received according to the preset period, the Zookeeper determines that the connection state of the network connection is disconnected, and deletes the temporary node corresponding to the server under the persistent node.
Wherein, the registration request may be sent through a network connection. Specifically, the embodiment of the invention can embed the client of the Zookeeper in each server in the server cluster, the client can be configured with the connection address of the Zookeeper server, and the server can access the connection address by starting the client, so that network connection is established with the Zookeeper server.
Further, after establishing network connection with the Zookeeper, the server can communicate with the Zookeeper periodically, that is, a connection maintaining request is sent to the Zookeeper according to a preset period, so that the Zookeeper can determine that the server is in an on-line state, and a temporary node corresponding to the server is reserved. The connection maintenance request may be in the form of a heartbeat packet or in the form of other preset session, and only needs to communicate with the Zookeeper according to a preset period.
Further, when the Zookeeper can receive the connection maintaining request sent by the server according to the preset period, the connection state of the network connection with the server is determined to be kept connected, so that the temporary node corresponding to the server can be reserved. Correspondingly, when the Zookeeper does not receive the connection maintaining request sent by the server according to the preset period, the Zookeeper can determine that the server is disconnected, so that the connection state of the network connection can be determined to be disconnected, and at the moment, the Zookeeper can delete the temporary node corresponding to the server.
Specifically, the server may send a connection maintenance request to the Zookeeper in a normal operation stage according to a preset period, and when the server is disconnected or the network is interrupted, the connection maintenance request cannot be sent to the Zookeeper. The preset period may be an empirical value of Zookeeper, and may be 20ms, 30ms, 60ms, etc., which is not limited in the embodiment of the present invention.
In the embodiment of the invention, network connection is established with the Zookeeper, and a registration request is sent to the Zookeeper based on the network connection; sending a connection maintenance request to the Zookeeper according to a preset period; and under the condition that the connection maintenance request is not received according to the preset period, the Zookeeper determines that the connection state of the network connection is disconnected, and deletes the temporary node corresponding to the server under the persistent node. In this way, the server can ensure that the machine identifier in the cache maintains an effective state by sending a connection maintaining request to the Zookeeper according to a preset period, and the Zookeeper can effectively manage the connection state of each server in the server cluster by whether the Zookeeper regularly receives the connection maintaining request of the server, so as to manage the corresponding temporary node.
Optionally, the operation of performing the first generating operation in the step 103 may specifically include the following steps:
S1031, determining the machine identification as a first field.
S1032 generates a second field based on the timestamp and the self-increment value.
S1033, splicing the first field and the second field according to a preset rule to obtain the distributed identification.
The embodiment of the invention can be re-executed when the identification generation requirement exists. The identifier generation requirement refers to the situation that newly added data exists, and the data can be types of user information, user accounts, video data, picture data and the like, and particularly, the types of the data are different according to different scenes applied by the server cluster, so that the embodiment of the invention is not limited.
Further, the first generating operation may determine the machine identifier of the server as a first field, and generate a second field based on the timestamp and the self-increment value, where the second field may include a first subfield and a second subfield, and the first subfield may be obtained by the timestamp, specifically, the current timestamp may be directly determined as the first subfield, or a difference between the current timestamp and the initial timestamp may be determined as the first subfield. The second subfield may be self-increment, that is, a value that changes automatically according to a preset rule, an initial value of the self-increment and a specific self-increment rule may be set automatically according to actual requirements, which is not limited in the embodiment of the present invention.
Further, the preset rule refers to a splicing rule of the first field and the second field, which may be a first field+a second field, a second field+a first field, a first sub-field+a first field+a second sub-field, or the like, and specifically may be set according to actual needs, which is not limited in the embodiment of the present invention.
Optionally, in some cases, the third field may also be generated according to a service type, where the service type may be a data source, and illustratively, in a case where the data source is a three-party account, the third field 01 may be generated, in a case where the data source is a mobile phone account, the third field may be generated as 10, and in a case where the data source is a mailbox account, the third field may be generated as 11. Further, the preset rule may be a splicing rule of the first field, the second field and the third field, may be a first field+a second field+a third field, or may be a second field+a first field+a third field, or the like, and specifically may be set according to actual needs, which is not limited in the embodiment of the present invention.
In the embodiment of the invention, the machine identification is determined to be a first field; generating a second field based on the timestamp and the self-increment value; and splicing the first field and the second field according to a preset rule to obtain the distributed identification. The identity is generated through the machine identity and the preset rule, so that the uniqueness of the generated identity can be met.
Optionally, after the step 102 caches the node path of the temporary node carried in the creation result as the machine identifier of the server, the embodiment of the present invention may specifically further include the following steps:
s31, creating a monitor, wherein the monitor is used for monitoring the connection state of the network connection;
And S32, deleting the machine identifier in the cache and executing a second generation operation to generate the distributed identifier under the condition that the connection state monitored by the monitor is disconnected, wherein the second generation operation is a distributed identifier generation operation which does not adopt the machine identifier.
The monitor may be in a software form, may be registered on a client of the Zookeeper through a command line, may be a Listener monitor, may be an oracle monitor, and may not be limited in this regard, and the embodiment of the present invention monitors a connection state of a network connection of the Zookeeper server through the monitor, and may determine a state of a machine identifier through the monitored connection state.
Specifically, when the connection state is monitored to be kept, it is indicated that the temporary node corresponding to the server is still reserved in the Zookeeper, and at this time, the server can continue to use the machine identifier in the cache to execute the first generating operation. Accordingly, when the connection state is monitored to be disconnected, it indicates that the temporary node corresponding to the server has been removed in the Zookeeper, and at this time, the machine identifier in the cache may be allocated to other servers by the Zookeeper, so that in order to avoid a conflict with the machine identifiers of other servers, at this time, the machine identifier in the cache needs to be deleted, that is, the original machine identifier is not used for performing the identifier generation, and the second generating operation is performed.
The second generating operation may be understood as a standby operation, where the second generating operation refers to an operation that can generate the identifier without using workerid, for example, may be a self-increasing manner based on a relational database (MySQL), a number segment manner based on a database, or the like, and may specifically be set by itself according to actual needs, which is not limited in the embodiment of the present invention.
In the prior art, under some service scenes, the length of the distributed identifiers is limited, so that the fields corresponding to the machine identifiers in the distributed identifiers are compressed, and as the machine identifiers of all servers are required to meet uniqueness, the number of digits of the machine identifiers is necessarily increased along with the increase of the number of the servers, the fields corresponding to the machine identifiers are correspondingly increased, and the fields conflict with the requirements of the service scenes, so that the machine identifiers of the servers which are already offline in the prior art are required to be manually recovered at regular intervals, and the maintenance cost is high.
In the embodiment of the invention, the monitor is used for monitoring the connection state of the network connection by creating the monitor; and deleting the machine identification in the cache and executing a second generating operation under the condition that the connection state monitored by the monitor is disconnected. Therefore, through the characteristics of the Zookeeper, when the server is disconnected with the Zookeeper, the Zookeeper can automatically delete the corresponding temporary node, so that the automatic recovery of the machine identification of the server which is already offline is realized, and the maintenance cost is reduced. Meanwhile, as the server monitors that the connection state is disconnected, the Zookeeper always deletes the temporary node corresponding to the server, in order to avoid the identifier generation conflict, the distributed identifier generation operation without adopting the machine identifier, namely the second generation operation, is executed by deleting the machine identifier in the cache, so that the identifier conflict can be avoided to a certain extent while the server is not influenced to provide the identifier generation service.
Optionally, after receiving the creation result returned by the Zookeeper, the embodiment of the present invention specifically further includes the following steps:
And under the condition that the creating result does not carry the node path of the temporary node, executing a second generating operation to generate the distributed identifier, wherein the second generating operation is a distributed identifier generating operation which does not adopt the machine identifier.
In the process of creating the temporary node by the Zookeeper, the Zookeeper may cause an abnormality in creation due to a fault or other reasons, and at this time, the Zookeeper may send an abnormal creation result to the server, where it can be understood that the temporary node path is not carried in the creation result. Accordingly, when the node path of the temporary node is not carried in the creation result, the fact that the temporary node is not successfully created in the Zookeeper is indicated, and at this time, a second generation operation without machine identification can be performed.
In the embodiment of the invention, the degradation mechanism is realized by executing the second generation operation under the condition that the creating result does not carry the node path of the temporary node, and the server can continuously generate the ID when the Zookeeper fails, so that the influence on the server to provide the ID generation service is avoided.
Optionally, the above operation of performing the second generating operation to generate the distributed identifier may include the following steps:
generating self-increment based on a preset step length and a preset base value, and taking the self-increment as a distributed identifier.
The embodiment of the invention can be executed in the condition that the identification generation requirement exists. The identifier generation requirement refers to the situation that newly added data exists, and the data can be types of user information, user accounts, video data, picture data and the like, and particularly, the types of the data are different according to different scenes applied by the server cluster, so that the embodiment of the invention is not limited.
The step length refers to the variation of the numerical value, the basic value refers to the initial value, and the initial value can be preset, and then the self-increment value can be generated as the distributed identifier through the preset step length and the preset basic value. It will be appreciated that the differences between adjacent distributed identifiers generated in this way are all unified to the preset step, that is, each of the distributed identifiers generated based on the second generating operation is obtained by adding the preset step to the previous distributed identifier.
It should be noted that, in the case of performing the second generating operation, different preset step sizes and preset base values may be set for different servers in order to avoid ID collisions.
In the embodiment of the invention, the self-increment value is generated based on the preset step length and the preset base value, and is used as the distributed identifier, the distributed identifier can be generated only by setting the preset step length and the preset base value, the realization cost is lower, the realization process is more convenient, and the efficiency of generating the distributed ID can be improved.
Optionally, the embodiment of the invention specifically may further include the following steps:
And after the server is restarted, the step of sending a registration request to the distributed application coordination service Zookeeper is executed again.
Specifically, the restart refers to the condition that the server is on line again after a period of time, and because the network connection between the server and the Zookeeper is disconnected after the server is off line, correspondingly, the Zookeeper has deleted the temporary node corresponding to the server, and at this time, the server needs to be reconnected with the Zookeeper and re-register the temporary node, so that the Zookeeper can manage the machine identifier of the server after restarting again. Thus, after the server is restarted, the operation of sending a registration request to the Zookeeper may be performed again to reacquire the machine identification.
Fig. 2 is a schematic diagram of a process for generating a tag according to an embodiment of the present invention, as shown in fig. 2, may include a Zookeeper client and a Zookeeper server, where the Zookeeper client runs on any server for executing tag generation. Specifically, the Zookeeper client may send a registration request to the Zookeeper server, the Zookeeper server creates a temporary node for a server where the Zookeeper client is located, and returns information of successful registration, at this time, it may be determined that the server for performing identifier generation is successfully initialized, and a connection maintenance request may be sent to the Zookeeper server through a preset period, so as to maintain long connection between the two servers, and the server may perform the first generating operation.
Further, after the server shuts down or suspends the identifier generating service, the connection between the Zookeeper client and the Zookeeper server is disconnected, when the server restarts or starts to generate the identifier generating service, the server needs to resend the registration request, and when the registration is successful, the first generating operation is continuously executed. Further, in the case of registration failure, the second generation operation is performed at this time.
Fig. 3 is a schematic diagram of another identifier generation process in the embodiment of the present invention, where, as shown in fig. 3, a service backend refers to a service end that needs to generate a distributed ID, and an ID-SDK refers to a server for generating an identifier. Specifically, firstly, whether the server acquires the machine identifier through the Zookeeper is judged, if so, a first generating operation is executed, and the first generating operation can be a snowflake algorithm (Snowflake algorithm), so that the distributed identifier is generated through executing the first generating operation. Correspondingly, under the condition that the machine identifier is not acquired, a registration request can be sent to the Zookeeper to acquire the machine identifier, whether the condition of overtime registration or failure registration exists is further judged, if not, the registration is successful, and the registered machine identifier can be acquired and the first generating operation can be executed.
Further, in the case of registration timeout or registration failure, the second generation operation may be performed. The second generation operation in fig. 3 is exemplified by a relational database (MySQL) manner, where a set of step sizes and base values may be obtained from a specified memory for generating a self-increment as a distributed identifier, where the specified memory may include a plurality of preset step sizes and base values, and a memory lock (Java Virtual Machine memory lock, JVM memory lock) may be set for the specified memory, so as to ensure that only one server may access and obtain the step sizes and base values at the same time. Meanwhile, after any group of step sizes and basic values are read, the memory lock can update the group of step sizes and the basic values, so that other servers are prevented from reading the same step sizes and basic values, and further, the fact that identifiers generated by the server clusters are not repeated to a certain extent is guaranteed. Optionally, when the server generates the distributed identifier by executing the second generating operation, two data centers (DATA CENTER, DC) may be set in the server, so as to record the maximum value of the identifier that has been generated currently, so that the identifier may be continuously generated by the current maximum value and the step length, and meanwhile, by setting two data centers, the problem that the current maximum value cannot be obtained when any data center fails can be avoided, the influence on the execution of the second generating operation is avoided, and the high availability of the second generating operation is ensured. Alternatively, the two DCs may record an odd maximum value and an even maximum value, respectively.
The identifier generating method provided by the embodiment of the invention can be applied to a cloud primary scene, because the servers for generating the IDs in the cloud primary scene are all deployed through containers, the containers have the need of dynamically expanding the capacity and restarting when the resources are scheduled, in the prior art, the machine IDs are distributed through the fixed IP of the machine, namely the corresponding machine IDs are distributed for the machine IDs, the corresponding relation between the machine IDs and the machine IDs is statically recorded in a database, the machine IDs of the servers are changed after restarting in the cloud primary scene, and accordingly, the machine IDs are required to be distributed for the changed machine IDs again, and the records in the database are manually changed to maintain the machine IDs of the servers, but the maintenance difficulty is high in the prior art. According to the embodiment of the invention, through the characteristics of the temporary nodes of the Zookeeper, the corresponding relation between the machine IP and the machine ID and the manual change record do not need to be recorded, the server can obtain the corresponding unique machine identifier by registering with the Zookeeper, and when the server is disconnected with the Zookeeper, the Zookeeper can automatically delete the corresponding temporary nodes. Correspondingly, when the server cluster expands, the newly added server can acquire the corresponding machine identification by sending a registration request to the Zookeeper, so that the machine identification of the server generating the ID can be automatically and dynamically maintained, and the cloud primary scene can be better adapted.
Fig. 4 is a schematic structural diagram of an identifier generating device according to an embodiment of the present invention, where the device is applied to any one of servers in a server cluster, and as shown in fig. 4, the device 20 may include:
A registration module 201, configured to send a registration request to a distributed application coordination service Zookeeper, where the registration request is used to request the Zookeeper, and create a temporary node corresponding to the server under a pre-created persistent node;
the caching module 202 is configured to receive a creation result returned by the Zookeeper, and cache a node path of a temporary node carried in the creation result as a machine identifier of the server;
A first execution module 203 is configured to perform a first generating operation, where the first generating operation is configured to generate a distributed identifier based on the machine identifier in the cache.
Optionally, the registration module 201 is specifically configured to: establishing network connection with the Zookeeper, and sending a registration request to the Zookeeper based on the network connection;
The apparatus 20 further comprises:
the maintenance module is used for sending a connection maintenance request to the Zookeeper according to a preset period;
And under the condition that the connection maintenance request is not received according to the preset period, the Zookeeper determines that the connection state of the network connection is disconnected, and deletes the temporary node corresponding to the server under the persistent node.
Optionally, the apparatus 20 further includes:
The monitoring module is used for creating a monitor, and the monitor is used for monitoring the connection state of the network connection;
and the deleting module is used for deleting the machine identifier in the cache and executing a second generating operation to generate the distributed identifier under the condition that the connection state monitored by the monitor is disconnected, wherein the second generating operation is the distributed identifier generating operation which does not adopt the machine identifier.
Optionally, the apparatus 20 further includes:
And the second execution module is used for executing a second generation operation to generate the distributed identifier under the condition that the creating result does not carry the node path of the temporary node, wherein the second generation operation is the distributed identifier generation operation which does not adopt the machine identifier.
Optionally, the first execution module is specifically configured to:
determining the machine identification as a first field;
generating a second field based on the timestamp and the self-increment value;
And splicing the first field and the second field according to a preset rule to obtain the distributed identification.
Optionally, the second execution module is specifically configured to:
generating self-increment based on a preset step length and a preset base value, and taking the self-increment as a distributed identifier.
Optionally, the apparatus 20 further includes:
And the third execution module is used for executing the transmission of the registration request to the distributed application coordination service Zookeeper again after the server is restarted.
In summary, in the embodiment of the present invention, by sending a registration request to the Zookeeper, any server in the server cluster may make the Zookeeper create a corresponding temporary node for the server, and the server may cache a node path of the temporary node as a machine identifier and execute a first generating operation. Thus, the characteristics of the temporary nodes of the Zookeeper can be utilized, the machine IP and the machine identification do not need to be maintained manually, the server can obtain the corresponding unique machine identification by registering with the Zookeeper, and when the server is disconnected with the Zookeeper, the Zookeeper can automatically delete the corresponding temporary nodes. Correspondingly, when the server cluster expands, the newly added server can acquire the corresponding machine identifier by sending a registration request to the Zookeeper, so that the automation management of the machine identifier can be realized through the Zookeeper, and the management difficulty of the machine identifier is reduced.
The embodiment of the invention also provides an electronic device, as shown in fig. 5, which comprises a processor 9001, a communication interface 9002, a memory 9003 and a communication bus 9004, wherein the processor 9001, the communication interface 9002 and the memory 9003 complete communication between each other through the communication bus 9004,
A memory 9003 for storing a computer program;
the processor 9001 is configured to execute a program stored in the memory 9003, and implement the following steps:
a registration request is sent to a distributed application coordination service Zookeeper, wherein the registration request is used for requesting the Zookeeper, and a temporary node corresponding to the server is created under a pre-created permanent node;
Receiving a creation result returned by the Zookeeper, and caching a node path of a temporary node carried in the creation result as a machine identifier of the server;
and executing a first generation operation, wherein the first generation operation is used for generating a distributed identifier based on the machine identifier in the cache.
Optionally, the sending a registration request to the distributed application coordination service Zookeeper includes: establishing network connection with the Zookeeper, and sending a registration request to the Zookeeper based on the network connection;
After the registration request is sent to the Zookeeper based on the network connection, the method further includes:
sending a connection maintenance request to the Zookeeper according to a preset period;
And under the condition that the connection maintenance request is not received according to the preset period, the Zookeeper determines that the connection state of the network connection is disconnected, and deletes the temporary node corresponding to the server under the persistent node.
Optionally, after the caching, as the machine identifier of the server, the node path of the temporary node carried in the creation result, the method further includes:
creating a monitor, wherein the monitor is used for monitoring the connection state of the network connection;
and deleting the machine identifier in the cache and executing a second generation operation to generate the distributed identifier under the condition that the connection state monitored by the monitor is disconnected, wherein the second generation operation is the distributed identifier generation operation which does not adopt the machine identifier.
Optionally, after receiving the creation result returned by the Zookeeper, the method further includes:
And under the condition that the creating result does not carry the node path of the temporary node, executing a second generating operation to generate the distributed identifier, wherein the second generating operation is a distributed identifier generating operation which does not adopt the machine identifier.
Optionally, the performing a first generating operation includes:
determining the machine identification as a first field;
generating a second field based on the timestamp and the self-increment value;
And splicing the first field and the second field according to a preset rule to obtain the distributed identification.
Optionally, the performing a second generating operation to generate the distributed identifier includes:
generating self-increment based on a preset step length and a preset base value, and taking the self-increment as a distributed identifier.
Optionally, after the server is restarted, the sending of the registration request to the distributed application coordination service Zookeeper is performed again.
The communication bus mentioned by the above terminal may be a peripheral component interconnect standard (PERIPHERAL COMPONENT INTERCONNECT, abbreviated as PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, abbreviated as EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the terminal and other devices.
The memory may include random access memory (Random Access Memory, RAM) or may include non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, abbreviated as CPU), a network processor (Network Processor, abbreviated as NP), etc.; but may also be a digital signal processor (DIGITAL SIGNAL Processing, DSP), application Specific Integrated Circuit (ASIC), field-Programmable gate array (FPGA) or other Programmable logic device, discrete gate or transistor logic device, discrete hardware components.
In yet another embodiment of the present invention, a computer readable storage medium is provided, in which instructions are stored, which when run on a computer, cause the computer to perform the method for generating an identification according to any of the above embodiments.
In a further embodiment of the present invention, a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of generating an identification of any of the above embodiments is also provided.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk Solid STATE DISK (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
It should be noted that, in the embodiment of the present application, the related processes of obtaining various data are all performed under the premise of conforming to the corresponding data protection rule policy of the country of the location and obtaining the authorization given by the owner of the corresponding device.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (10)

1. An identification generation method, applied to any one of servers in a server cluster, the method comprising:
a registration request is sent to a distributed application coordination service Zookeeper, wherein the registration request is used for requesting the Zookeeper, and a temporary node corresponding to the server is created under a pre-created permanent node;
Receiving a creation result returned by the Zookeeper, and caching a node path of a temporary node carried in the creation result as a machine identifier of the server;
and executing a first generation operation, wherein the first generation operation is used for generating a distributed identifier based on the machine identifier in the cache.
2. The method of claim 1, wherein the sending a registration request to a distributed application coordination service Zookeeper comprises: establishing network connection with the Zookeeper, and sending a registration request to the Zookeeper based on the network connection;
After the registration request is sent to the Zookeeper based on the network connection, the method further includes:
sending a connection maintenance request to the Zookeeper according to a preset period;
And under the condition that the connection maintenance request is not received according to the preset period, the Zookeeper determines that the connection state of the network connection is disconnected, and deletes the temporary node corresponding to the server under the persistent node.
3. The method according to claim 2, wherein after the caching of the node path of the temporary node carried in the creation result as the machine identifier of the server, the method further comprises:
creating a monitor, wherein the monitor is used for monitoring the connection state of the network connection;
and deleting the machine identifier in the cache and executing a second generation operation to generate the distributed identifier under the condition that the connection state monitored by the monitor is disconnected, wherein the second generation operation is the distributed identifier generation operation which does not adopt the machine identifier.
4. The method of claim 1, wherein after receiving the creation result returned by the Zookeeper, the method further comprises:
And under the condition that the creating result does not carry the node path of the temporary node, executing a second generating operation to generate the distributed identifier, wherein the second generating operation is a distributed identifier generating operation which does not adopt the machine identifier.
5. The method of claim 1, wherein the performing a first generating operation comprises:
determining the machine identification as a first field;
generating a second field based on the timestamp and the self-increment value;
And splicing the first field and the second field according to a preset rule to obtain the distributed identification.
6. The method of claim 3 or 4, wherein the performing a second generating operation to generate a distributed identity comprises:
generating self-increment based on a preset step length and a preset base value, and taking the self-increment as a distributed identifier.
7. The method according to claim 2, wherein the method further comprises:
And after the server is restarted, the step of sending a registration request to the distributed application coordination service Zookeeper is executed again.
8. An identification generating device, applied to any one of servers in a server cluster, the device comprising:
The registration module is used for sending a registration request to a distributed application coordination service Zookeeper, wherein the registration request is used for requesting the Zookeeper, and a temporary node corresponding to the server is created under a pre-created permanent node;
The cache module is used for receiving the creation result returned by the Zookeeper and caching the node path of the temporary node carried in the creation result as the machine identifier of the server;
the first execution module is used for executing a first generation operation, and the first generation operation is used for generating a distributed identifier based on the machine identifier in the cache.
9. 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 method of any of claims 1-7 when executing a program stored on a memory.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-7.
CN202410250202.5A 2024-03-05 2024-03-05 Identification generation method and device, electronic equipment and readable storage medium Pending CN118138562A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410250202.5A CN118138562A (en) 2024-03-05 2024-03-05 Identification generation method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410250202.5A CN118138562A (en) 2024-03-05 2024-03-05 Identification generation method and device, electronic equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN118138562A true CN118138562A (en) 2024-06-04

Family

ID=91229710

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410250202.5A Pending CN118138562A (en) 2024-03-05 2024-03-05 Identification generation method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN118138562A (en)

Similar Documents

Publication Publication Date Title
US9262324B2 (en) Efficient distributed cache consistency
KR101150146B1 (en) System and method for managing cached objects using notification bonds
CN108696581B (en) Distributed information caching method and device, computer equipment and storage medium
CN102333029B (en) Routing method in server cluster system
CN107404509B (en) Distributed service configuration system and information management method
CN110968603B (en) Data access method and device
CN109167819B (en) Data synchronization system, method, device and storage medium
US20150248350A1 (en) Apparatus and method for managing cache in cache distributed environment
CN109522043B (en) Method and device for managing configuration data and storage medium
CN110781149A (en) Method, device, equipment and storage medium for managing live broadcast room information
CN114900449B (en) Resource information management method, system and device
CN111104250B (en) Method, apparatus and computer readable medium for data processing
CN108509296B (en) Method and system for processing equipment fault
CN110855627B (en) Application deployment method, device, equipment and medium
CN112214377B (en) Equipment management method and system
CN110798358B (en) Distributed service identification method and device, computer readable medium and electronic equipment
CN113220342A (en) Centralized configuration method and device, electronic equipment and storage medium
CN113965538B (en) Equipment state message processing method, device and storage medium
CN118138562A (en) Identification generation method and device, electronic equipment and readable storage medium
CN111629054B (en) Message processing method, device and system, electronic equipment and readable storage medium
CN111083182B (en) Distributed Internet of things equipment management method and device
CN111614750A (en) Data updating method, system, equipment and storage medium
CN111522649A (en) Distributed task allocation method, device and system
CN112860708B (en) Data consistency restoration method, system, device and equipment
CN114629783B (en) State monitoring method, system, equipment and computer readable storage medium

Legal Events

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