CN112055099A - Single number generation method and electronic equipment - Google Patents

Single number generation method and electronic equipment Download PDF

Info

Publication number
CN112055099A
CN112055099A CN202010846900.3A CN202010846900A CN112055099A CN 112055099 A CN112055099 A CN 112055099A CN 202010846900 A CN202010846900 A CN 202010846900A CN 112055099 A CN112055099 A CN 112055099A
Authority
CN
China
Prior art keywords
service
machine
machine number
zookeeper
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
CN202010846900.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.)
Shanghai Qinggan Intelligent Technology Co Ltd
Original Assignee
Shanghai Qinggan Intelligent 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 Shanghai Qinggan Intelligent Technology Co Ltd filed Critical Shanghai Qinggan Intelligent Technology Co Ltd
Priority to CN202010846900.3A priority Critical patent/CN112055099A/en
Publication of CN112055099A publication Critical patent/CN112055099A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/30Managing network names, e.g. use of aliases or nicknames

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application relates to a single number generation method and electronic equipment, wherein the single number generation method comprises the following steps: when the server side starts the service, applying for the machine number of the service to the Zookeeper service cluster; responding to the application, the Zookeeper service cluster generates a machine number, creates a corresponding temporary node and sends the machine number to the server; and the server generates a single number according to the machine number. Through the mode, the zookeeper temporary node can be used for managing the machine number, and the machine number is prevented from being repeated based on the distributed coordination capacity of the zookeeper, so that the single number is prevented from being repeated.

Description

Single number generation method and electronic equipment
Technical Field
The application relates to the technical field of service order numbers, in particular to an order number generation method and electronic equipment.
Background
Many services need a globally unique single number for related recording, for example, deployment related recording of a single-service multi-microservice container needs to have a globally unique single number, and a single number in a high concurrency scenario needs to be correctly generated and guaranteed to be globally unique. However, in the prior art, the machine numbers used for generating the single number are all allocated in advance, that is, how many machines to be deployed in total are fixed in advance, and since the machines can dynamically expand and contract in the distributed micro-service environment, the way of allocating the machine numbers in advance easily causes machine number duplication, and further causes the single number duplication.
Disclosure of Invention
An object of the present application is to provide a method for generating a single number and an electronic device, which can solve the above technical problems and avoid repetition of the single number.
In order to solve the above technical problem, the present application provides a method for generating a single number, including:
when the service end starts the service, applying for the machine number of the service to the Zookeeper service cluster;
responding to the application, the Zookeeper service cluster generates a machine number, creates a corresponding temporary node and sends the machine number to the server;
and the server generates a single number according to the machine number.
Wherein the single number comprises a fixed number field, a current timestamp number field, a machine number field, and a self-incrementing sequence number field.
The single number is represented by 64-bit binary digits, wherein the 1 st bit is the fixed number field and is fixed to 0, the 2 nd bit to the 42 th bit are the current timestamp number field, the 43 rd bit to the 52 th bit are the machine number field, and the 53 th bit to the 64 th bit are the self-increment serial number field.
Wherein, the Zookeeper service cluster generates a machine number and creates a corresponding temporary node, including:
the Zookeeper service cluster generates a machine number and judges whether the machine number exists or not;
and if not, creating a corresponding temporary node.
Wherein, the Zookeeper service cluster generates a machine number and creates a corresponding temporary node, further comprising:
if yes, judging whether the machine numbers are completely distributed;
if not, returning a result of failed creation, and executing the steps of generating a machine number by the Zookeeper service cluster and judging whether the machine number exists or not when the server side applies for the machine again;
if the allocation is finished, the result that all the machine numbers are allocated is returned.
After the server generates the single number according to the machine number, the method further comprises the following steps:
during the service operation period, the server side sends heartbeat to the Zookeeper service cluster at regular time so as to determine that the machine number of the service is still used;
and when the Zookeeper service cluster does not receive the heartbeat sent by the server within the preset time length, clearing the machine number of the corresponding service.
Wherein the service is a distributed service and/or a microservice.
The application also provides a second single number generation method, which is applied to a server and comprises the following steps:
when the service is started, applying for a machine number of the service to a Zookeeper service cluster, so that the Zookeeper service cluster generates the machine number and returns the machine number after creating a corresponding temporary node;
and generating a single number according to the machine number.
In a second method for generating a single number, after generating a single number according to the machine number, the method further includes:
and during the running of the service, sending heartbeat to the Zookeeper service cluster at regular time so as to determine that the machine number of the service is still used.
The present application further provides an electronic device, which includes a memory and a processor, wherein the memory is configured to store at least one program instruction, and the processor is configured to implement the second method for generating a single number as described above by loading and executing the at least one program instruction.
According to the single number generation method and the electronic equipment, when the server side starts the service, the server side applies for the machine number of the service to the Zookeeper service cluster; responding to the application, the Zookeeper service cluster generates a machine number, creates a corresponding temporary node and sends the machine number to the server; and the server generates a single number according to the machine number. Through the mode, the zookeeper temporary node can be used for managing the machine number, and the machine number is prevented from being repeated based on the distributed coordination capacity of the zookeeper, so that the single number is prevented from being repeated.
The foregoing description is only an overview of the technical solutions of the present application, and in order to make the technical means of the present application more clearly understood, the present application may be implemented in accordance with the content of the description, and in order to make the above and other objects, features, and advantages of the present application more clearly understood, the following preferred embodiments are described in detail with reference to the accompanying drawings.
Drawings
Fig. 1 is a technical architecture diagram illustrating a single number generation method according to a first embodiment;
fig. 2 is a flowchart illustrating a single number generation method according to the first embodiment;
FIG. 3 is a timing diagram illustrating the application and maintenance of machine numbers according to a first embodiment;
fig. 4 is a flowchart illustrating a single number generation method according to a second embodiment;
fig. 5 is a schematic structural diagram of an electronic device shown in accordance with a third embodiment.
Detailed Description
To further clarify the technical measures and effects taken by the present application to achieve the intended purpose, the following detailed description is given, along with the accompanying drawings and preferred embodiments, of specific embodiments, methods, steps, structures, features and effects thereof.
The foregoing and other technical matters, features and effects of the present application will be apparent from the following detailed description of preferred embodiments, which is to be read in connection with the accompanying drawings. While the present application is susceptible to embodiment and specific details, specific reference will now be made in detail to the present disclosure for the purpose of illustrating the general principles of the invention.
First embodiment
Fig. 1 is a schematic diagram of a technical architecture of a single number generation method according to a first embodiment. As shown in fig. 1, Maven is a project management and integration tool, which uses a standard directory structure and a default construction life cycle, and a Maven private warehouse is used for acting a remote warehouse and deploying a third-party component, and after the private warehouse is built, when Maven needs to download a component, the Maven directly requests the private warehouse, and if the private warehouse exists, the Maven downloads the component to a local warehouse, otherwise, the Maven requests an external remote warehouse, downloads the component to the private warehouse, and then provides the component to the local warehouse for downloading. And (2) packaging (a sequence-num-generator, a serial number generator) to a Maven private warehouse through Gitlab in a spring boot startup mode.
The functions of the implementation (sequence-num-generator) include generating a unique single number, requesting and maintaining a machine number from the zookeeper, and periodically sending a heartbeat to the zookeeper to maintain the relationship between the current container and the machine number. All the spring group micro-services can be directly introduced into the algorithm implementation in a spring boot startup mode, and relevant zookeeper addresses and service names are configured, and the micro-services can acquire the unique single number by means of the implementation only by introducing one algorithm class.
The PAAS Platform (Platform-as-a-Service) is used for providing cloud components for software, the cloud components are mainly used for application programs, the PAAS can realize a Maven warehouse management function through specific components, and a jar package is uploaded through a Maven warehouse to construct a java application.
The Zookeeper service cluster is used for providing coordination service for the distributed application program of the user, and the service A and the service B running in the PAAS platform can create corresponding temporary node service A and service B in the Zookeeper service cluster.
Through the framework, the unique single number can be generated by combining the java language with the zookeeper distributed temporary node function, the framework is simple, the realization is easy, and the development cost is low. The following describes a specific process of the single number generation method based on the above technical architecture.
Fig. 2 is a flowchart illustrating a single number generation method according to the first embodiment. Referring to fig. 2, the method for generating a single number of the present embodiment includes:
step 110, when the service is started, the server applies for the machine number of the service to the Zookeeper service cluster;
step 120, responding to the application, the Zookeeper service cluster generates a machine number and creates a corresponding temporary node, and the machine number is sent to the server;
and step 130, the server generates a single number according to the machine number.
The order service, the transaction service or any other scene needing unique recording can use a single number, and the single number comprises a fixed number field, a current timestamp number field, a machine number field and a self-increment serial number field. In this embodiment, the single number is represented by 64-bit binary digits, wherein the 1 st bit is a fixed number field and is fixed to 0, so as to avoid the single number being a negative number; the 2 nd bit to the 42 th bit are the current time stamp digital field, and the unit is millisecond; the 43 rd to 52 th bits are machine number fields, the machine number is used for identifying each container in a single service, the single service supports 1024 micro-service containers at most, and the generation and management of the machine number are completed by a zookeeper service; bits 53 through 64 are incrementing sequence number fields, and a single micro service container can support 4096 incrementing sequence numbers per millisecond. Thus, a single microservice container can support 4096000 unique single number generations per second, with unique single number generation being implemented by a unified SDK and reused for different business services, the services being distributed services and/or microservices.
Referring to fig. 3, the process of generating a machine number and creating a corresponding temporary node by the Zookeeper service cluster may include:
the Zookeeper service cluster generates a machine number and judges whether the machine number exists or not;
if not, creating a corresponding temporary node;
if yes, judging whether the machine numbers are completely distributed;
if not, returning a result of failed creation, and executing a Zookeeper service cluster to generate a machine number and judging whether the machine number exists or not when the server side applies for the machine again;
if the allocation is finished, the result that all the machine numbers are allocated is returned.
After the server generates the single number according to the machine number, the method further comprises the following steps:
during the service operation, the server side sends heartbeat to the Zookeeper service cluster at regular time so as to determine that the machine number of the service is still used;
and when the Zookeeper service cluster does not receive the heartbeat sent by the server within the preset time length, clearing the machine number of the corresponding service.
The method comprises the steps of managing machine numbers by using a zookeeper temporary node, applying for the machine numbers (from 1 to 1024) when the service is started each time, trying to create the temporary node by the zookeeper according to the machine numbers, creating the temporary node if the machine numbers do not exist, and returning a result of failed creation to a server if the machine numbers exist. The server side receives the result of successful creation, and then the server side can generate the single number according to the machine number, so that the globally unique generation function of the single number is realized, and the server side can apply for the machine number circularly until the machine number is successfully applied or is full. After a single number is generated, the service sends heartbeat to the zookeeper at regular time to determine that the machine number of the service is still used, and when the service loses the heartbeat due to downtime, restart or reissue for various reasons, the zookeeper can clear the machine number losing the heartbeat for recycling. In this way, the single service multi-micro service container can be ensured to correctly generate a unique single number and be globally unique.
In the method for generating the single number, when the server starts the service, the server applies for the machine number of the service to the Zookeeper service cluster; responding to the application, the Zookeeper service cluster generates a machine number, creates a corresponding temporary node and sends the machine number to the server; and the server generates a single number according to the machine number. Through the mode, the zookeeper temporary node can be used for managing the machine number, and the machine number is prevented from being repeated based on the distributed coordination capacity of the zookeeper, so that the single number is prevented from being repeated.
Second embodiment
Fig. 4 is a flowchart illustrating a single number generation method according to a second embodiment. Referring to fig. 4, the method for generating a single number in this embodiment is applied to a server, and includes:
step 210, when the service is started, applying for a machine number of the service to the Zookeeper service cluster, so that the Zookeeper service cluster generates the machine number and returns the machine number after creating a corresponding temporary node;
step 220, generating a single number according to the machine number.
Wherein, after the step 220 generates the single number according to the machine number, the method further comprises:
during the service operation, a heartbeat is sent to the Zookeeper service cluster at regular intervals to determine that the machine number of the service is still in use.
Wherein, the single number comprises a fixed number field, a current time stamp number field, a machine number field and a self-increment serial number field. The single number is represented by 64-bit binary digits, wherein the 1 st bit is a fixed number field and is fixed to 0, the 2 nd bit to the 42 th bit are current timestamp digit fields, the 43 rd bit to the 52 th bit are machine number digit fields, and the 53 th bit to the 64 th bit are self-increasing serial number digit fields.
The Zookeeper service cluster generates a machine number and creates a corresponding temporary node, and the steps comprise:
the Zookeeper service cluster generates a machine number and judges whether the machine number exists or not;
if not, creating a corresponding temporary node;
if yes, judging whether the machine numbers are completely distributed;
if not, returning a result of failed creation, and executing a Zookeeper service cluster to generate a machine number and judging whether the machine number exists or not when the server side applies for the machine again;
if the allocation is finished, the result that all the machine numbers are allocated is returned.
And when the Zookeeper service cluster does not receive the heartbeat sent by the server within the preset time length, clearing the machine number of the corresponding service.
In this embodiment, the service is a distributed service and/or a microservice.
The specific implementation process of the single number generation method in this embodiment may refer to the description of the second embodiment, and is not described herein again.
In the method for generating the single number, when the service is started, the server applies for the machine number of the service to the Zookeeper service cluster, so that the Zookeeper service cluster generates the machine number and returns the machine number after creating the corresponding temporary node, and then generates the single number according to the machine number. Through the mode, the zookeeper temporary node can be used for managing the machine number, and the machine number is prevented from being repeated based on the distributed coordination capacity of the zookeeper, so that the single number is prevented from being repeated.
Third embodiment
Fig. 5 is a schematic structural diagram of an electronic device shown in accordance with a third embodiment. As shown in fig. 5, the electronic device of the present embodiment includes a memory 310 and a processor 320, where the memory 310 stores at least one program instruction, and the processor 320 implements the single number generating method according to the second embodiment by loading and executing the at least one program instruction.
The method steps executed by the processor 320 are described in detail in the second embodiment, and are not described in detail here.
The electronic device of this embodiment, when the service is started, applies for the machine number of the service to the Zookeeper service cluster, so that the Zookeeper service cluster generates the machine number and creates a corresponding temporary node, and then returns the machine number, and further generates the single number according to the machine number. Through the mode, the zookeeper temporary node can be used for managing the machine number, and the machine number is prevented from being repeated based on the distributed coordination capacity of the zookeeper, so that the single number is prevented from being repeated.
Although the present application has been described with reference to a preferred embodiment, it should be understood that various changes, substitutions and alterations can be made herein without departing from the spirit and scope of the application, and all changes, substitutions and alterations that fall within the spirit and scope of the application are to be understood as being included within the following description of the preferred embodiment.

Claims (10)

1. A method for generating a single number, comprising:
when the service end starts the service, applying for the machine number of the service to the Zookeeper service cluster;
responding to the application, the Zookeeper service cluster generates a machine number, creates a corresponding temporary node and sends the machine number to the server;
and the server generates a single number according to the machine number.
2. The single number generation method of claim 1, wherein the single number includes a fixed number field, a current timestamp number field, a machine number field, and a self-incrementing sequence number field.
3. The single number generating method according to claim 2, wherein the single number is represented by a 64-bit binary number, wherein bit 1 is the fixed number field and is fixed to 0, bits 2 to 42 are the current time stamp number field, bits 43 to 52 are the machine number field, and bits 53 to 64 are the self-incrementing sequence number field.
4. The single number generation method of claim 1, wherein the Zookeeper service cluster generating a machine number and creating a corresponding temporary node comprises:
the Zookeeper service cluster generates a machine number and judges whether the machine number exists or not;
and if not, creating a corresponding temporary node.
5. The single number generation method of claim 4, wherein the Zookeeper service cluster generates a machine number and creates a corresponding temporary node, further comprising:
if yes, judging whether the machine numbers are completely distributed;
if not, returning a result of failed creation, and executing the steps of generating a machine number by the Zookeeper service cluster and judging whether the machine number exists or not when the server side applies for the machine again;
if the allocation is finished, the result that all the machine numbers are allocated is returned.
6. The method for generating the single number according to claim 1, wherein after the server generates the single number according to the machine number, the method further comprises:
during the service operation period, the server side sends heartbeat to the Zookeeper service cluster at regular time so as to determine that the machine number of the service is still used;
and when the Zookeeper service cluster does not receive the heartbeat sent by the server within the preset time length, clearing the machine number of the corresponding service.
7. The ticket number generating method according to claim 1, wherein the service is a distributed service and/or a micro-service.
8. A single number generation method is applied to a server and is characterized by comprising the following steps:
when the service is started, applying for a machine number of the service to a Zookeeper service cluster, so that the Zookeeper service cluster generates the machine number and returns the machine number after creating a corresponding temporary node;
and generating a single number according to the machine number.
9. The method of generating a sheet number according to claim 8, further comprising, after generating the sheet number from the machine number:
and during the running of the service, sending heartbeat to the Zookeeper service cluster at regular time so as to determine that the machine number of the service is still used.
10. An electronic device, comprising a memory for storing at least one program instruction and a processor for implementing the single number generation method of any one of claims 8 or 9 by loading and executing the at least one program instruction.
CN202010846900.3A 2020-08-21 2020-08-21 Single number generation method and electronic equipment Pending CN112055099A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010846900.3A CN112055099A (en) 2020-08-21 2020-08-21 Single number generation method and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010846900.3A CN112055099A (en) 2020-08-21 2020-08-21 Single number generation method and electronic equipment

Publications (1)

Publication Number Publication Date
CN112055099A true CN112055099A (en) 2020-12-08

Family

ID=73599239

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010846900.3A Pending CN112055099A (en) 2020-08-21 2020-08-21 Single number generation method and electronic equipment

Country Status (1)

Country Link
CN (1) CN112055099A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116112569A (en) * 2023-02-23 2023-05-12 安超云软件有限公司 Micro-service scheduling method and management system

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106572165A (en) * 2016-10-26 2017-04-19 宜人恒业科技发展(北京)有限公司 Distributed global unique ID application method
US20180176120A1 (en) * 2016-12-21 2018-06-21 Juniper Networks, Inc. Maintaining coherency in distributed operating systems for network devices
CN110795399A (en) * 2019-09-29 2020-02-14 北京淇瑀信息科技有限公司 Method, device and system for generating machine ID for application
CN111338647A (en) * 2018-12-18 2020-06-26 杭州海康威视数字技术股份有限公司 Big data cluster management method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106572165A (en) * 2016-10-26 2017-04-19 宜人恒业科技发展(北京)有限公司 Distributed global unique ID application method
US20180176120A1 (en) * 2016-12-21 2018-06-21 Juniper Networks, Inc. Maintaining coherency in distributed operating systems for network devices
CN111338647A (en) * 2018-12-18 2020-06-26 杭州海康威视数字技术股份有限公司 Big data cluster management method and device
CN110795399A (en) * 2019-09-29 2020-02-14 北京淇瑀信息科技有限公司 Method, device and system for generating machine ID for application

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116112569A (en) * 2023-02-23 2023-05-12 安超云软件有限公司 Micro-service scheduling method and management system

Similar Documents

Publication Publication Date Title
CN108510389B (en) Intelligent contract calling method and device based on block chain and readable storage medium
CN109445869B (en) Cross-cloud-adaptive micro-service management method and device and storage medium
US7539985B2 (en) Systems and methods for dynamic component versioning
US8713163B2 (en) Monitoring cloud-runtime operations
CN111026414B (en) HDP platform deployment method based on kubernetes
CN106569880B (en) Method and system for dynamically sharing resources between Android applications
CN106610839B (en) Method for issuing upgrade package, lightweight upgrade method, device and system
US10866841B2 (en) Communication system and method for accessing and deploying temporary microservices on a heterogeneous platform
US20150046898A1 (en) System and method for provisioning a dynamic module system within a component oriented application development framework
CN111831757B (en) Method and device for generating and managing distributed global unique identification information
CN104750528A (en) Management method and device for components in Android program
CN111309336A (en) Distributed application deployment method and device
CN111538594A (en) Order ID generation method, device, equipment and medium based on distributed system
CN107465709B (en) Distributed mirror image construction task method, device and system
CN111258742B (en) Data synchronization method, system, computing device and storage medium
CN112055099A (en) Single number generation method and electronic equipment
JP2004151800A (en) Method for creating process of transforming calling convention
CN112565475B (en) Ip address allocation method for adding new node in container cluster service layer
CN112181049B (en) Cluster time synchronization method, device, system, equipment and readable storage medium
CN111124618B (en) Resource deployment method, device, storage medium and equipment
WO2002075541A3 (en) Method and apparatus for providing application specific strategies to a java platform including start and stop policies
CN112379934B (en) Deployment method and device of cloud computing platform and storage medium
CN114900497B (en) Identification sequence number generation method and device, electronic equipment and storage medium
CN116755788A (en) On-line rule modification method, device, equipment and storage medium
CN113391906B (en) Job updating method, job updating device, computer equipment and resource management system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20201208