CN113255293A - Control method and device for distributed architecture scalable order number generator - Google Patents

Control method and device for distributed architecture scalable order number generator Download PDF

Info

Publication number
CN113255293A
CN113255293A CN202110573983.8A CN202110573983A CN113255293A CN 113255293 A CN113255293 A CN 113255293A CN 202110573983 A CN202110573983 A CN 202110573983A CN 113255293 A CN113255293 A CN 113255293A
Authority
CN
China
Prior art keywords
generator
machine code
order number
timestamp
starting
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
CN202110573983.8A
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.)
Shouyue Technology Beijing Co Ltd
Original Assignee
Shouyue Technology Beijing 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 Shouyue Technology Beijing Co Ltd filed Critical Shouyue Technology Beijing Co Ltd
Priority to CN202110573983.8A priority Critical patent/CN113255293A/en
Publication of CN113255293A publication Critical patent/CN113255293A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/126Character encoding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q30/00Commerce
    • G06Q30/06Buying, selling or leasing transactions
    • G06Q30/0601Electronic shopping [e-shopping]
    • G06Q30/0633Lists, e.g. purchase orders, compilation or processing
    • G06Q30/0635Processing of requisition or of purchase orders

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention discloses a control method and a device for a distributed architecture scalable order number generator, wherein the method comprises the following steps: starting a generator; generating an order number based on the machine code, the timestamp, the sequence number and the custom data; the generator is destroyed. By the method and the device, a method for starting and destroying the order number generator device is provided, the machine code and the starter are effectively bound by utilizing a distributed coordination thought, and the safety of the generator under a distributed architecture is ensured; the generator under the distributed architecture can be freely stretched and contracted in the machine code binding link in the starting and destroying processes of the generator, so that the utilization rate of the bit number of the machine code is improved, and the problem possibly caused by human intervention is avoided; the order number generation method is provided, and the characteristics of self-increment, high generation efficiency, distributed safety and the like of the order number are met.

Description

Control method and device for distributed architecture scalable order number generator
Technical Field
The invention belongs to the technical field of generators, and particularly relates to a control method and a control device for a distributed architecture scalable order number generator.
Background
Currently, three popular unique identifier generation techniques are:
1. uuid (universal Unique identifier): the universal unique identification code generated by the computer according to the algorithm comprises 36 characters (32 alphanumeric characters and 4 connectors) and has uniqueness;
2. generating Sequence by using a database (Sequence is a table which is specially stored with an arithmetic progression in the database and is controlled by a database system, and the database system can obtain the next record of the table according to the current record number and the step length): reading the database Sequence each time and adding by itself 1;
3. SnowFlake algorithm (SnowFlake): a group of digits with the increasing trend of 64bit size is generated by the computer according to an algorithm, the digits comprise a sign bit of 1bit, a time stamp of 41bit, a working machine id of 10bit and a serial number of 12bit, and the digits have uniqueness.
The prior defects are as follows:
(1) characters generated by the UUID do not contain valuable information and do not meet the characteristic of incredibility;
(2) the Sequence is generated by a database, needs to be connected with the database, has network overhead and low performance;
(3) the snowFlake working machine id is lack of a distributed coordination link, and when hundreds of order number generators are deployed in a distributed architecture environment at the same time, errors easily occur in manual setting; in addition, when the order number generator is newly added and destroyed, the management is not easy. The requirement of free scaling of the distributed architecture machine is not met.
Disclosure of Invention
In view of the above technical problems in the related art, the present invention provides a method and an apparatus for controlling a scalable order number generator with a distributed architecture, which can overcome the above disadvantages in the prior art.
In order to achieve the technical purpose, the technical scheme of the invention is realized as follows:
a method of controlling a distributed architecture scalable order number generator, the method comprising:
starting a generator;
generating an order number based on the machine code, the timestamp, the sequence number and the custom data;
the generator is destroyed.
Further, the start generator includes:
determining an identity of a generator;
judging whether the generator is started or not according to the identifier, wherein when the generator is not started, the machine code is determined in the distributed coordination module, the binding relationship between the generator identifier and the machine code is established, and the machine code is set to be in an unavailable state;
the machine code is stored in the generator memory.
Further, the generating an order number based on the machine code, the timestamp, the sequence number, and the custom data includes:
acquiring a machine code;
acquiring a timestamp;
acquiring a serial number;
obtaining custom data;
and combining the machine code, the timestamp, the serial number and the custom data to generate an order number.
Further, the timestamp is the number of seconds from the current time of the system to the target time.
Further, the destruction generator comprises:
determining an identity of a generator;
releasing the machine code into an available state in the distributed coordination module;
and removing the machine code stored in the memory of the generator.
Further, in the distributed coordination module, in the process of releasing the machine code into an available state, the binding relationship between the generator unique identifier and the machine code is reserved.
Further, in the distributed coordination module, the machine code is released into an available state, and if the machine code is in the available state when the generator is started next time, the machine code is reused.
In another aspect, the present invention provides a control apparatus for a distributed architecture scalable order number generator, the apparatus comprising:
a starting unit for starting the generator;
the generating unit is used for generating an order number based on the machine code, the timestamp, the serial number and the user-defined data;
and the destroying unit is used for destroying the generator.
The invention has the beneficial effects that: by the method and the device, a method for starting and destroying the order number generator device is provided, the machine code and the starter are effectively bound by utilizing a distributed coordination thought, and the safety of the generator under a distributed architecture is ensured; the generator under the distributed architecture can be freely stretched and contracted in the machine code binding link in the starting and destroying processes of the generator, so that the utilization rate of the bit number of the machine code is improved, and the problem possibly caused by human intervention is avoided; the order number generation method is provided, and the characteristics of self-increment, high generation efficiency, distributed safety and the like of the order number are met.
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, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a flowchart of a method for starting a distributed architecture order number generator according to an embodiment of the present invention;
fig. 2 is a flowchart of a method for destroying a distributed architecture order number generator according to an embodiment of the present invention;
FIG. 3 is a flowchart of a method for generating an order number by a distributed architecture order number generator according to an embodiment of the present invention;
fig. 4 is a schematic diagram illustrating a bit structure of a distributed architecture order number according to an embodiment of the present invention;
fig. 5 is a block diagram illustrating an apparatus of a distributed architecture order number generator according to an embodiment of the present invention;
fig. 6 is a block diagram of a structure of a device for starting and destroying a distributed order number generator according to an embodiment of the present invention;
fig. 7 is a block diagram of an apparatus for generating an order number by a distributed order number generator according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1 to 3, a method for controlling a distributed architecture scalable order number generator includes:
starting a generator;
generating an order number based on the machine code, the timestamp, the sequence number and the custom data;
the generator is destroyed.
In some embodiments of the invention, the start-up generator comprises:
determining an identity of a generator;
judging whether the generator is started or not according to the identifier, wherein when the generator is not started, the machine code is determined in the distributed coordination module, the binding relationship between the generator identifier and the machine code is established, and the machine code is set to be in an unavailable state;
the machine code is stored in the generator memory.
In some embodiments of the present invention, the generating an order number based on the machine code, the timestamp, the sequence number, and the custom data includes:
acquiring a machine code;
acquiring a timestamp;
acquiring a serial number;
obtaining custom data;
and combining the machine code, the timestamp, the serial number and the custom data to generate an order number.
In some embodiments of the present invention, the timestamp is the number of seconds that the current time of the system is from the target time.
In some embodiments of the invention, the destruction generator comprises:
determining an identity of a generator;
releasing the machine code into an available state in the distributed coordination module;
and removing the machine code stored in the memory of the generator.
In some embodiments of the present invention, in the distributed coordination module, the binding relationship between the generator unique identifier and the machine code is reserved in the process of releasing the machine code into the usable state.
In some embodiments of the invention, in the distributed coordination module, the machine code is released into an available state, and if the machine code is in the available state the next time the generator is started, the machine code is reused.
As shown in fig. 5 to 7, in another aspect, the present invention provides a control apparatus for a distributed architecture scalable order number generator, the apparatus comprising:
a starting unit for starting the generator;
the generating unit is used for generating an order number based on the machine code, the timestamp, the serial number and the user-defined data;
and the destroying unit is used for destroying the generator.
The invention provides a control method and a control device for a distributed architecture scalable order number generator, wherein the generator can be deployed in batches of thousands in a distributed architecture environment and supports free scaling, and the deployed generator can efficiently generate high-quality order numbers.
A scalable order number generator under a distributed architecture needs to satisfy several characteristics: 1. scalability: the generator can be safely and efficiently started or destroyed in batches; 2. high throughput: the generator can safely and efficiently deploy hundreds of machines, and the requirement of high concurrence of distribution and a system is met; 3. the order number has uniqueness: the generated order number is not repeatable and is a unique identifier; 4. order number has an increasing nature: order numbers need to be added in order, and the next order number must be larger than the previous order number; 5. high efficiency: the order number is generated to meet the characteristic of low resource consumption; 6. the storage and transmission are convenient: easier to store and identify between computer systems.
The embodiment of the invention provides a method for starting a distributed architecture order number generator, and referring to fig. 1, the method comprises the following steps:
step 1, determining a unique identifier of a generator, wherein in the embodiment of the invention, the unique identifier can be a character string formed by a machine IP and a port.
And 2, judging whether the generator is newly added in the distributed environment or not according to the unique identifier determined in the step 1, namely whether the generator is not started before.
And 3, after confirming that the generator is newly added, determining an available machine code in the distributed coordination module, establishing a binding relationship between the generator unique identifier and the machine code, and setting the machine code to be in an unavailable state.
For example, referring to the bit number structure diagram of the order number shown in fig. 4, the bit number of the machine code may be determined to be 10 bits, and then 0 to 1023 different machine codes may be represented.
The machine code itself does not contain any characters uniquely identifying the generator, but rather maintains a binding relationship in the distributed coordination module, which allows a unique generator to be represented safely and efficiently using a machine code with a short number of bits. The generator determines the machine code without human intervention, thereby avoiding errors caused by human factors and improving the starting efficiency.
And 4, storing the machine code in a generator memory so as to obtain the machine code at a high speed when the order number is generated. This is the completion of the generator start.
The embodiment of the invention provides a method for destroying a distributed architecture order number generator, and referring to fig. 2, the method comprises the following steps:
step 1, determining a unique identifier of a generator, wherein in the embodiment of the invention, the unique identifier can be a character string formed by a machine IP and a port.
And 2, releasing the machine code into an available state in the distributed coordination module, but keeping the binding relationship between the unique identifier of the generator and the machine code, and multiplexing the machine code if the machine code is still in the available state when the generator is started next time.
And 3, removing the machine codes stored in the memory of the generator until the generator is destroyed.
The embodiment of the invention provides a method for generating an order number by a distributed architecture order number generator, and referring to fig. 3, the method comprises the following steps:
and step 1, acquiring a machine code.
In the embodiment of the present invention, the machine code may be a unique machine code that is determined and generated by the distributed coordination module when the generator is started, and referring to the schematic diagram of the bit number structure of the order number shown in fig. 4, the bit number of the machine code may be determined to be 10 bits, that is, one of the numbers 0 to 1023, and the machine code has been determined and stored in the memory when the generator is started, so that the efficiency is very high when the machine code is acquired.
And 2, acquiring the time stamp.
In the embodiment of the present invention, the timestamp is the number of seconds from the current time of the system to the target time, for example, the target time is set to be 2020, 01, 00, min and 00 seconds, referring to the schematic diagram of the bit number structure of the order number shown in fig. 4, the bit number of the timestamp can be determined to be 32 bits, 42 billions of timestamps accurate to seconds can be represented by the 32 bits, and if the timestamp is calculated from the target time 2020, the timestamp can be used for 2156 years.
And step 3, acquiring the serial number.
In the embodiment of the invention, if the bit number of the sequence number is determined to be 12, the 12-bit sequence number supports generation of 4096 orders at most in the same second, if the number exceeds 4096, the system waiting time is suspended for entering the next second, and the sequence number is regenerated from 0 after entering the next second. Specifically, the number of bits of the serial number is determined according to actual requirements, and the embodiment of the present invention is not limited specifically.
And 4, acquiring custom data.
In the embodiment of the invention, if the bit number of the custom data is determined to be 9, the definable range of the custom data is 0-511, and the extensible characteristic of the order number generation is satisfied. The custom data may be determined as a parameter when the order number generation method enters, and the embodiment of the present invention is not particularly limited.
And 5, combining the machine code, the timestamp, the serial number and the custom data to generate an order number.
In the embodiment of the invention, the order number can be obtained by combining the machine code, the timestamp, the serial number and the custom data. It should be noted that the machine code, the timestamp, the serial number, and the custom data may be combined in any order, and the embodiment of the present invention is not limited specifically.
By the method and the device, a method for starting and destroying the order number generator device is provided, the machine code and the starter are effectively bound by utilizing a distributed coordination thought, and the safety of the generator under a distributed architecture is ensured; the generator under the distributed architecture can be freely stretched and contracted in the machine code binding link in the starting and destroying processes of the generator, so that the utilization rate of the bit number of the machine code is improved, and the problem possibly caused by human intervention is avoided; the order number generation method is provided, and the characteristics of self-increment, high generation efficiency, distributed safety and the like of the order number are met.
Although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (8)

1. A control method for a distributed architecture scalable order number generator is characterized by comprising the following steps:
starting a generator;
generating an order number based on the machine code, the timestamp, the sequence number and the custom data;
the generator is destroyed.
2. The method of claim 1, wherein the starting the generator comprises:
determining an identity of a generator;
judging whether the generator is started or not according to the identifier, wherein when the generator is not started, the machine code is determined in the distributed coordination module, the binding relationship between the generator identifier and the machine code is established, and the machine code is set to be in an unavailable state;
the machine code is stored in the generator memory.
3. The method of claim 1, wherein generating the order number based on the machine code, the timestamp, the sequence number, and the custom data comprises:
acquiring a machine code;
acquiring a timestamp;
acquiring a serial number;
obtaining custom data;
and combining the machine code, the timestamp, the serial number and the custom data to generate an order number.
4. The method of claim 3, wherein the timestamp is a number of seconds from a current time of the system to a target time.
5. The method of claim 1, wherein the destruction generator comprises:
determining an identity of a generator;
releasing the machine code into an available state in the distributed coordination module;
and removing the machine code stored in the memory of the generator.
6. The method according to claim 5, wherein the binding relationship between the generator unique identifier and the machine code is reserved in the distributed coordination module for releasing the machine code into the available state.
7. The method as claimed in claim 6, wherein the releasing the machine code to the available state in the distributed coordination module, and if the machine code is available at the next start of the generator, the machine code is reused.
8. A control apparatus for a distributed architecture scalable order number generator, comprising:
a starting unit for starting the generator;
the generating unit is used for generating an order number based on the machine code, the timestamp, the serial number and the user-defined data;
and the destroying unit is used for destroying the generator.
CN202110573983.8A 2021-05-25 2021-05-25 Control method and device for distributed architecture scalable order number generator Pending CN113255293A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110573983.8A CN113255293A (en) 2021-05-25 2021-05-25 Control method and device for distributed architecture scalable order number generator

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110573983.8A CN113255293A (en) 2021-05-25 2021-05-25 Control method and device for distributed architecture scalable order number generator

Publications (1)

Publication Number Publication Date
CN113255293A true CN113255293A (en) 2021-08-13

Family

ID=77184368

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110573983.8A Pending CN113255293A (en) 2021-05-25 2021-05-25 Control method and device for distributed architecture scalable order number generator

Country Status (1)

Country Link
CN (1) CN113255293A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102769667A (en) * 2012-06-29 2012-11-07 北京奇虎科技有限公司 Method, equipment and system for generating ID
CN110634052A (en) * 2019-09-20 2019-12-31 中国银行股份有限公司 Method and device for generating order number by distributed architecture
CN111831757A (en) * 2020-06-09 2020-10-27 时时同云科技(成都)有限责任公司 Method and device for generating and managing distributed global unique identification information
CN112054919A (en) * 2020-08-03 2020-12-08 华人运通(江苏)技术有限公司 Method, device, storage medium and system for generating ID (identity) of container cluster under stateless condition
WO2021052029A1 (en) * 2019-09-17 2021-03-25 苏宁云计算有限公司 Data object identifier generation method and apparatus, computer device, and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102769667A (en) * 2012-06-29 2012-11-07 北京奇虎科技有限公司 Method, equipment and system for generating ID
WO2021052029A1 (en) * 2019-09-17 2021-03-25 苏宁云计算有限公司 Data object identifier generation method and apparatus, computer device, and storage medium
CN110634052A (en) * 2019-09-20 2019-12-31 中国银行股份有限公司 Method and device for generating order number by distributed architecture
CN111831757A (en) * 2020-06-09 2020-10-27 时时同云科技(成都)有限责任公司 Method and device for generating and managing distributed global unique identification information
CN112054919A (en) * 2020-08-03 2020-12-08 华人运通(江苏)技术有限公司 Method, device, storage medium and system for generating ID (identity) of container cluster under stateless condition

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
尼恩: "《Java高并发核心编程 NIO Netty Redis ZooKeeper 卷1》", 30 April 2021, 机械工业出版社, pages: 441 - 448 *
李慧琴: "基于动态令牌的网关服务访问认证的研究与实现", 中国优秀硕士学位论文全文数据库 信息科技辑, no. 02, pages 136 - 392 *

Similar Documents

Publication Publication Date Title
CN108460115B (en) Message pushing method and device, computer equipment and storage medium
CN111917897B (en) Identification generation method, device, equipment and storage medium
CN110851748A (en) Short link generation method, server, storage medium and computer equipment
CN110989922A (en) Distributed data storage method and system
CN111580965A (en) Data request processing method and system
CN110634052A (en) Method and device for generating order number by distributed architecture
CN114040030B (en) Data compression method, device, equipment and medium based on preset rules
CN108762979B (en) Terminal information backup method and backup device based on matching tree
CN113032245A (en) Error positioning identification test method and device, computer equipment and storage medium
CN113255293A (en) Control method and device for distributed architecture scalable order number generator
EP3998754B1 (en) Data distribution method, storage server and subscription server
CN113947207A (en) Management method, system and device applied to model conversion and electronic equipment
CN114970464A (en) Method, device, terminal equipment and storage medium for generating identification
KR102426621B1 (en) Application service server that handles the sending of an efficient push notification message to the client terminal where the application is installed and operating method thereof
CN113297223B (en) Block chain-based electronic data real-time certificate storing system and method
CN112243040B (en) Method and system for generating unique identifier
CN113949690B (en) IPv6 seed address sampling method, device, equipment and storage medium
CN101309276B (en) Processing method and apparatus of LWAAP slicing packet
CN114040028A (en) Data compression method and data decompression method based on three modes
CN115935299A (en) Authorization control method, device, computer equipment and storage medium
CN108964884B (en) Method for generating dynamic password of mobile terminal, storage medium, electronic equipment and system
CN112464263A (en) Data encryption method, system, device and medium
CN112235431A (en) Method and system for automatically configuring machine ID based on snowflake algorithm
CN116880778B (en) User privacy protection method based on regenerative coding and distributed storage
CN106815238B (en) Serialization and deserialization method and device for structured data

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