CN108804442B - Serial number generation method and device - Google Patents

Serial number generation method and device Download PDF

Info

Publication number
CN108804442B
CN108804442B CN201710287039.XA CN201710287039A CN108804442B CN 108804442 B CN108804442 B CN 108804442B CN 201710287039 A CN201710287039 A CN 201710287039A CN 108804442 B CN108804442 B CN 108804442B
Authority
CN
China
Prior art keywords
data
node
version number
data node
stored
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.)
Active
Application number
CN201710287039.XA
Other languages
Chinese (zh)
Other versions
CN108804442A (en
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 Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information 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 Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201710287039.XA priority Critical patent/CN108804442B/en
Publication of CN108804442A publication Critical patent/CN108804442A/en
Application granted granted Critical
Publication of CN108804442B publication Critical patent/CN108804442B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The application discloses a serial number generation method and a serial number generation device. One embodiment of the method comprises: in response to receiving the sequence number generation instruction, performing processing steps to determine a sequence number; determining a comparison value based on data saved by a second data node in the data node storage server and a second preset value; determining whether the sequence number is less than the comparison value; if the serial number is not smaller than the comparison value, further determining whether the serial number is larger than the comparison value and whether a child node version number of a first data node in the data node storage server is larger than data stored in a second data node stored in a memory in advance; and if the serial number is not greater than the comparison value and the version number of the child node is not greater than the data stored in the second data node stored in the memory in advance, returning the serial number. This embodiment enables the generation of ordered sequence numbers with high availability.

Description

Serial number generation method and device
Technical Field
The present application relates to the field of computer technologies, and in particular, to the field of internet technologies, and in particular, to a method and an apparatus for generating a serial number.
Background
At present, there are many scenarios using ordered serial numbers, for example, in a distributed system, the ordered serial numbers are generated as database primary keys or as service numbers (such as order numbers, personnel numbers, etc.), and so on.
However, the maximum length of the sequence number generated by the prior art is generally short, and the generation of the ordered sequence number with high availability cannot be realized, so that the method is applied to an application scene such as a distributed system and the like which needs to use the whole ordered sequence number.
Disclosure of Invention
It is an object of the present application to provide an improved serial number generation method and apparatus to solve the technical problems mentioned in the background section above.
In a first aspect, an embodiment of the present application provides a method for generating a serial number, where the method includes: in response to receiving the sequence number generation instruction, performing the following processing steps: modifying data stored by a first data node in a data node storage server to update a data version number of the first data node, obtaining a current data version number and a child node version number of the first data node, determining whether the data version number is equal to a first preset value, in response to determining that the data version number is not equal to the first preset value, further determining whether said data version number is equal to a second preset value, in response to determining that said data version number is not equal to said second preset value, determining a sequence number based on said data version number and said child node version number, wherein the data node storage server stores a second data node and the first data node including a child node in advance, the first data node and the second data node respectively store data, and the first data node comprises the data version number and the child node version number; determining a comparison value based on the data stored in the second data node and the second preset value; determining whether the sequence number is less than the comparison value; in response to determining that the serial number is not less than the comparison value, further determining whether the serial number is greater than the comparison value and whether the child node version number is greater than data stored in a second data node pre-stored in a memory; and returning the serial number in response to the fact that the serial number is not larger than the comparison value and the version number of the child node is not larger than the data stored in a second data node stored in a memory in advance.
In some embodiments, the processing step comprises: and in response to determining that the data version number is equal to the first preset value, adding or deleting child nodes of the first data node to update the child node version number, and re-executing the processing steps.
In some embodiments, the processing step comprises: and in response to determining that the data version number is equal to the second preset value, modifying the data stored by the second data node stored in the memory in advance and the data stored by the second data node in the data node storage server to the current child node version number, and determining a serial number based on the current child node version number and the data version number.
In some embodiments, the above method comprises: and in response to determining that the sequence number is smaller than the comparison value, adding or deleting child nodes of the first data node to update the child node version number, and re-executing the processing steps.
In some embodiments, the above method comprises: and in response to the fact that the serial number is larger than the comparison value and the version number of the child node is larger than the data stored in a second data node which is stored in a memory in advance, updating the data stored in the second data node which is stored in the memory in advance, modifying the data stored in the second data node in the server for storing the data nodes into the current version number of the child node, and returning the serial number.
In a second aspect, the present application provides a serial number generation apparatus, including: a processing unit configured to, in response to receiving the sequence number generation instruction, perform the following processing steps: modifying data stored by a first data node in a data node storage server to update a data version number of the first data node, obtaining a current data version number and a version number of an upper child node of the first data node, determining whether the data version number is equal to a first preset value, in response to determining that the data version number is not equal to the first preset value, further determining whether said data version number is equal to a second preset value, in response to determining that said data version number is not equal to said second preset value, determining a sequence number based on said data version number and said child node version number, wherein the data node storage server stores a second data node and the first data node including a child node in advance, the first data node and the second data node respectively store data, and the first data node comprises the data version number and the child node version number; a comparison value determination unit configured to determine a comparison value based on the data stored in the second data node and the second preset value; a first determination unit configured to determine whether the serial number is smaller than the comparison value; a second determining unit, configured to, in response to determining that the serial number is not less than the comparison value, further determine whether the serial number is greater than the comparison value and whether the child node version number is greater than data stored in a second data node stored in a memory in advance; and the returning unit is configured to return the serial number in response to determining that the serial number is not greater than the comparison value and the version number of the child node is not greater than data stored in a second data node which is stored in a memory in advance.
In some embodiments, the processing unit comprises: a first processing subunit, configured to add or delete a child node of the first data node to update the child node version number in response to determining that the data version number is equal to the first preset value, and to re-execute the processing step.
In some embodiments, the processing unit comprises: and a second processing subunit, configured to modify, in response to determining that the data version number is equal to the second preset value, data stored by a second data node that is pre-stored in the memory and data stored by the second data node in the data node storage server to a current version number of the child node, respectively, and determine a sequence number based on the current version number of the child node and the current version number of the data.
In some embodiments, the apparatus comprises: and the first processing unit is configured to add or delete the child node of the first data node to update the child node version number in response to determining that the sequence number is smaller than the comparison value, and to re-execute the processing step.
In some embodiments, the apparatus comprises: and the second processing unit is configured to update the data stored in the second data node stored in the memory in response to determining that the serial number is greater than the comparison value and the version number of the child node is greater than the data stored in the second data node stored in the memory in advance, modify the data stored in the second data node in the server for storing the data node into the current version number of the child node, and return the serial number.
In a third aspect, an embodiment of the present application provides an electronic device, including: one or more processors; storage means for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the method as described in any implementation manner of the first aspect.
In a fourth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, where the computer program is configured to, when executed by a processor, implement the method described in any implementation manner of the first aspect.
The serial number generation method and device provided by the embodiment of the application are used for determining the serial number by executing the processing steps. Then, a comparison value is determined based on the data held by the second data node in the data node storage server and the second preset value, so as to determine whether the serial number is smaller than the comparison value. Then, when the serial number is determined to be not less than the comparison value, whether the serial number is greater than the comparison value and whether a child node version number of a child node of the first data node in the data storage server is greater than data held by a second data node stored in a memory in advance is further determined, so that the serial number is returned when the serial number is determined to be not greater than the comparison value and the child node version number is not greater than data held by the second data node stored in the memory in advance. The serial number generation method and device provided by the embodiment of the application effectively utilize the data version number of the data stored in the first data node and the version number of the child node, and can generate the overall ordered long serial number so as to be applied to a scene needing the overall ordered serial number in a distributed system, and therefore the generation of the ordered serial number with high availability is realized.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
FIG. 2 is a flow diagram for one embodiment of a method of serial number generation according to the present application;
FIG. 3 is a schematic diagram of an application scenario of a serial number generation method according to the present application;
FIG. 4 is a flow diagram of yet another embodiment of a method of serial number generation according to the present application;
FIG. 5 is a schematic block diagram of one embodiment of a serial number generation apparatus according to the present application;
FIG. 6 is a schematic block diagram of a computer system suitable for use to implement the electronic device of an embodiment of the present application.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
Fig. 1 illustrates an exemplary system architecture 100 to which embodiments of the serial number generation method or serial number generation apparatus of the present application may be applied.
As shown in fig. 1, the system architecture 100 may include terminal devices 101, 102, 103, a serial number generation server 105, a data node storage server 107, and networks 104, 106. The network 104 is used to provide a medium of communication links between the terminal devices 101, 102, 103 and the serial number generation server 105. The network 106 is used to provide a medium of a communication link between the serial number generation server 105 and the data node storage server 107. The networks 104, 106 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may use the terminal devices 101, 102, 103 to interact with the serial number generation server 105 through the network 104 to receive or transmit information or the like. The terminal devices 101, 102, 103 may have installed thereon various communication client applications, such as a web browser application, a shopping-like application, a game-like application, a search-like application, an instant messenger, social platform software, and the like.
The terminal devices 101, 102, 103 may be various electronic devices having a display screen, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, mpeg Audio Layer 3), MP4 players (Moving Picture Experts Group Audio Layer IV, mpeg Audio Layer 4), laptop and desktop computers, and the like.
The serial number generation server 105 may be a server that provides various services, and for example, receives and processes various requests (for example, an account registration request, a data storage request, and the like) transmitted by the terminal apparatuses 101, 102, 103. The sequence number generation server 105 may be preset with a business process for processing the request, and the business process may trigger the sequence number generation instruction when executing the sequence number assignment process in the process of processing the request. The serial number generation server 105 may process the serial number generation instruction and may return a processing result (e.g., a generated serial number).
Here, the serial number generation server 105 may have a command line tool deployed therein, which can communicate with the data node storage server 107, for example, a Zookeeper (Zookeeper is a distributed application program coordination service that is a distributed and open source code and can provide a consistency service for distributed applications) command line tool, and the Zookeeper command line tool may support a create command for creating a data node, a set command for modifying data held by the data node, a delete command for deleting the data node, a get command for acquiring data held by the data node, and the like. Here, the data version number and the child node version number of the data node that are returned may be obtained while the data held by the data node is acquired by the get command.
The data node storage server 107 may be a server for storing data nodes. The data node storage server 107 may be deployed with a distributed, open source distributed application coordination service (e.g., Zookeeper).
It should be noted that the serial number generation method provided in the embodiment of the present application is generally executed by the serial number generation server 105, and accordingly, the serial number generation apparatus is generally disposed in the serial number generation server 105.
It should be understood that the numbers of terminal devices, networks, serial number generation servers, and data node storage servers in fig. 1 are merely illustrative. Any number of terminal devices, networks, serial number generation servers, and data node storage servers may be provided as necessary for implementation.
With continued reference to FIG. 2, a flow 200 of one embodiment of a method of serial number generation according to the present application is shown. The serial number generation method comprises the following steps:
in step 201, in response to receiving the sequence number generation instruction, the processing step is executed.
In the present embodiment, an electronic device (for example, the serial number generation server 105 shown in fig. 1) on which the serial number generation method operates may receive the serial number generation instruction from the local. For example, the electronic device may be preset with a business process for processing a request, and when the business process executes a sequence number assignment process in processing a request (for example, an account registration request, a data storage request, and the like) sent by a client (for example, the terminal devices 101, 102, and 103 shown in fig. 1), a sequence number generation instruction may be triggered.
In this embodiment, after receiving the serial number generation instruction, the electronic device may perform the following processing steps: first, the electronic device may modify data stored by a first data node in a data node storage server (e.g., the data node storage server 107 shown in fig. 1) to update a data version number of the first data node, for example, modify the data stored by the first data node by a set command supported by the deployed command line tool, and the electronic device may modify the data stored by the first data node to an arbitrary value. The data node storage server may store a second data node and the first data node including a child node in advance, the first data node and the second data node may store data, and the first data node may include the data version number and the child node version number. Then, the electronic device may obtain the current data version number and the child node version number of the first data node, for example, obtain the data version number and the child node version number through a get command supported by the command line tool. Next, the electronic device may compare the data version number with a first preset value (e.g., 0) to determine whether the data version number is equal to the first preset value. Then, in response to determining that the data version number is not equal to the first preset value, the electronic device may further determine whether the data version number is equal to a second preset value (e.g., 2147483648). Finally, in response to determining that the data version number is not equal to the second preset value, the electronic device may determine a serial number based on the data version number and the child node version number. As an example, when the child node version number is 1, the data version number is used as a serial number.
The first data node, the child nodes of the first data node, and the second data node in the data node storage server may be created when the electronic device is initialized. For example, when the electronic device determines that the first data node, the second data node, and the child node of the first data node are not stored in the data node storage server at the time of initialization, the electronic device may create the first data node, the second data node, and the child node of the first data node in the data node storage server by a create command supported by the command line tool, may store an arbitrary value in the first data node, may store 0 in the second data node, and may store the second data node in which 0 is stored in a memory of the electronic device.
It should be noted that the data node is generally used for storing data. A data node may have a child node (i.e., a data node that belongs to the data node). A data node may also have a parent node (i.e., the data node to which the data node belongs). The minimum value of the data version number and the child node version number of the data node (for example, the first data node) in the data node storage server is usually 0, and the maximum value thereof is usually 4294967295. Generally, when data stored in a data node is modified, the data version number of the data node is increased, for example, the data is modified once, and the data version number is increased by 1. Similarly, when the child node of the data node is added or deleted, the child node version number of the data node is also added, for example, when a child node is added or deleted to the data node, the child node version number is increased by 1. Here, the first preset value may be a minimum value of the data version number. The second preset value may be a median value between a minimum value and a maximum value of the data version number. For example, if the minimum value is 0 and the maximum value is 4294967295, the intermediate value may be 2147483648.
In some optional implementation manners of this embodiment, the electronic device may further subtract a third preset value (e.g., 1) from the child node version number, multiply the product by a data version number threshold (e.g., 4294967295), and add the obtained product and the data version number to obtain a value as a serial number. Here, the data version number threshold may be a maximum value of the data version number.
In some optional implementation manners of this embodiment, the electronic device may further receive a serial number generation instruction from a connected client and/or server (e.g., a database server), and this embodiment does not limit this aspect in any way.
Step 202, a comparison value is determined based on the data stored in the second data node and a second preset value.
In this embodiment, after determining the serial number, the electronic device may determine a comparison value based on data stored in a second data node in the data node storage server and the second preset value. For example, when the data held by the second data node is equal to 1, the second preset value is used as the comparison value.
In some optional implementation manners of this embodiment, the electronic device may subtract the third preset value from the data stored in the second data node in the data node storage server, and multiply the data version number threshold by the third preset value, and add a value obtained by adding the product and the second preset value to obtain a comparison value.
Step 203, it is determined whether the sequence number is less than the comparison value.
In this embodiment, after determining the comparison value, the electronic device may compare the serial number with the comparison value to determine whether the serial number is smaller than the comparison value. If the serial number is not less than the comparison value, the electronic device may execute step 204.
In response to determining that the serial number is not less than the comparison value, step 204 further determines whether the serial number is greater than the comparison value and the version number of the child node is greater than the data stored in the second data node stored in the memory in advance.
In this embodiment, when the electronic device determines that the serial number is not smaller than the comparison value, the electronic device may further determine whether the serial number is greater than the comparison value and the child node version number is greater than data stored in a second data node pre-stored in the memory of the electronic device. If the electronic device determines that the serial number is not greater than the comparison value and the child node version number is not greater than the data stored in the second data node pre-stored in the memory of the electronic device, the electronic device may perform step 205.
In response to determining that the serial number is not greater than the comparison value and the version number of the child node is not greater than the data stored in the second data node pre-stored in the memory, step 205 returns the serial number.
In this embodiment, in response to the electronic device determining that the serial number is not greater than the comparison value and the version number of the child node is not greater than the data stored in the second data node stored in the memory of the electronic device in advance, the electronic device may return the serial number determined in step 201 to a sender of the serial number generation instruction (e.g., the business process).
With continued reference to fig. 3, fig. 3 is a schematic diagram of an application scenario of the serial number generation method according to the present embodiment. In the application scenario of fig. 3, the serial number generation server may receive a serial number generation instruction triggered by a preset business process, as shown by reference numeral 301. Thereafter, as indicated by reference numeral 302, the serial number generation server may modify data held by the first data node in the data node storage server. Then, as shown by reference numeral 303, the serial number generation server may obtain the current data version number a and the child node version number B of the first data node. Next, as shown by reference numeral 304, the serial number generation server may compare the data version number a with a first preset value C to determine that the data version number a is not equal to the first preset value C. Next, as indicated by reference numeral 305, the electronic device may compare the data version number a with a second preset value D, and determine that the data version number a is not equal to the second preset value D. Thereafter, the serial number generation server may determine a serial number E based on the data version number a and the child node version number B, as indicated by reference numeral 306. Then, as shown by reference numeral 307, the serial number generation server may determine a comparison value F based on data held by a second data node in the data node storage server and a second preset value D. Then, as indicated by reference numeral 308, the serial number generation server may compare the serial number E with the comparison value F, and determine that the serial number E is not less than the comparison value F. Next, as shown by reference numeral 309, the serial number generation server may continue to compare the serial number E with the comparison value F, compare the child node version number B with the data G stored in the second data node in the memory of the serial number generation server in advance, and determine that the serial number E is not greater than the comparison value F and the child node version number B is not greater than the data G. Finally, as shown by reference numeral 310, the serial number generation server may return the serial number E to the preset business process.
The method provided by the above embodiment of the present application effectively utilizes the data version number and the child node version number of the first data node in the data node storage server, and can realize generation of the ordered sequence number with high availability.
With further reference to fig. 4, a flow 400 of yet another embodiment of a method of serial number generation is shown. The process 400 of the serial number generation method includes the following steps:
step 401, modifying the data stored by the first data node in the data node storage server to update the data version number of the first data node.
In the present embodiment, an electronic device (for example, the serial number generation server 105 shown in fig. 1) on which the serial number generation method operates may receive the serial number generation instruction from the local. For example, the electronic device may be preset with a business process for processing a request, and when the business process executes a sequence number assignment process in processing a request (for example, an account registration request, a data storage request, and the like) sent by a client (for example, the terminal devices 101, 102, and 103 shown in fig. 1), a sequence number generation instruction may be triggered. After receiving the serial number generation instruction, the electronic device may modify data stored in a first data node in the data node storage server to update a data version number of the first data node. Here, the electronic device may modify the data held by the first data node by a set command supported by the deployed command line tool, and the electronic device may modify the data held by the first data node to an arbitrary value.
Step 402, acquiring the current data version number and the child node version number of the first data node.
In this embodiment, after the electronic device modifies the data stored in the first data node, the electronic device may obtain a current data version number and a current child node version number of the first data node. For example, the electronic device may obtain the data version number and the child node version number through a get command supported by the command line tool.
In step 403, it is determined whether the data version number is equal to a first preset value.
In this embodiment, after obtaining the data version number and the child node version number, the electronic device may compare the data version number with a first preset value (for example, 0) to determine whether the data version number is equal to the first preset value. If the electronic device determines that the data version number is not equal to the first preset value, the electronic device may perform step 404. If the electronic device determines that the data version number is equal to the first preset value, the electronic device may execute step 405.
Step 404 determines whether the data version number is equal to a second preset value.
In this embodiment, in response to determining that the data version number is not equal to the first preset value in step 403, the electronic device may compare the data version number with a second preset value (e.g., 2147483648) to determine whether the data version number is equal to the second preset value. If the electronic device determines that the data version number is not equal to the second preset value, the electronic device may perform step 406. If the electronic device determines that the data version number is equal to the second preset value, the electronic device may perform step 407.
In step 405, child nodes of the first data node are added or deleted to update the child node version numbers.
In this embodiment, in response to determining that the data version number is equal to the first preset value in step 403, the electronic device may add or delete a child node of the first data node to update the child node version number. For example, when the electronic device determines that the data version number is equal to the first preset value, the electronic device may determine whether the child node version number is divisible by 2, and if the child node version number is divisible by 2, the electronic device may create (e.g., create via a create command supported by the command line tool) a child node of the first data node; if the first data node cannot be divided by 2, the electronic device may delete (e.g., delete via the delete command supported by the command line tool) the child node of the first data node. And adding 1 to the version number of the child node by adding or deleting the child node of the first data node. Here, after the electronic device executes step 405, the electronic device may go to execute step 401.
At step 406, a sequence number is determined based on the data version number and the child node version number.
In this embodiment, in response to determining that the data version number is not equal to the second preset value in step 404, the electronic device may determine a serial number based on the data version number and the child node version number. For example, the value obtained by subtracting a third preset value (for example, 1) from the child node version number and multiplying the result by a data version number threshold (for example, 4294967295) is added to the product and the data version number, and the obtained product is used as the serial number. The electronic device may perform step 408 after determining the serial number.
Step 407, the data stored in the second data node pre-stored in the memory and the data stored in the second data node in the data node storage server are respectively modified to the current child node version number.
In this embodiment, in response to determining that the data version number is equal to the second preset value in step 404, the electronic device may modify (for example, modify by a set command supported by the command line tool) data stored in a second data node pre-stored in the memory of the electronic device and data stored in a second data node of the data node storage server to the current child node version number, respectively. Thereafter, the electronic device may go to step 406.
Step 408, a comparison value is determined based on the data saved by the second data node in the data node storage server and the second preset value.
In this embodiment, after determining the serial number, the electronic device may determine a comparison value based on data stored in a second data node in the data node storage server and the second preset value. For example, the third preset value is subtracted from the data stored in the second data node, and the result is multiplied by the data version number threshold, and the product obtained by adding the product to the second preset value is used as a comparison value. After the electronic device performs step 408, the electronic device may perform step 409.
Step 409, determine if the sequence number is less than the compare value.
In this embodiment, after determining the comparison value, the electronic device may compare the serial number with the comparison value to determine whether the serial number is smaller than the comparison value. If the serial number is not less than the comparison value, the electronic device may perform step 410. If the serial number is smaller than the comparison value, the electronic device may execute step 405.
Step 410, it is determined whether the serial number is greater than the comparison value and the version number of the child node is greater than the data stored in the second data node stored in the memory in advance.
In this embodiment, in response to determining that the serial number is not less than the comparison value in step 409, the electronic device may further determine whether the serial number is greater than the comparison value and whether the child node version number is greater than data stored in a second data node pre-stored in the memory of the electronic device. If the electronic device determines that the serial number is greater than the comparison value and the child node version number is greater than data stored in a second data node pre-stored in the memory of the electronic device, the electronic device may perform step 411. If the electronic device determines that the serial number is not greater than the comparison value and the child node version number is not greater than the data stored in the second data node pre-stored in the memory of the electronic device, the electronic device may perform step 412.
Step 411, updating the data stored in the second data node pre-stored in the memory, and modifying the data stored in the second data node in the data node storage server to the current child node version number.
In this embodiment, in response to determining that the serial number is greater than the comparison value and the child node version number is greater than the data stored in the second data node pre-stored in the memory of the electronic device in step 410, the electronic device may update the data stored in the second data node pre-stored in the memory of the electronic device, for example, add 1 to the data stored in the second data node, and the electronic device may further modify the data stored in the second data node in the data node storage server to the current child node version number. Here, after the electronic device performs step 411, the electronic device may perform step 412.
At step 412, a sequence number is returned.
In this embodiment, when it is determined in step 410 that the serial number is not greater than the comparison value and the child node version number is not greater than data stored in a second data node stored in the memory of the electronic device in advance, or when the electronic device finishes step 411, the electronic device may return the latest determined serial number to the sender of the serial number generation instruction.
As can be seen from fig. 4, compared with the embodiment corresponding to fig. 2, the flow 400 of the serial number generation method in the present embodiment highlights the step of determining the serial number in different situations. Therefore, the scheme described in the embodiment can ensure the validity of the generated sequence number, so that the generation of the ordered sequence number with high availability can be further realized.
With further reference to fig. 5, as an implementation of the methods shown in the above-mentioned figures, the present application provides an embodiment of a serial number generation apparatus, which corresponds to the embodiment of the method shown in fig. 2, and which can be applied to various electronic devices.
As shown in fig. 5, the serial number generation apparatus 500 according to the present embodiment includes: a processing unit 501, a comparison value determination unit 502, a first determination unit 503, a second determination unit 504, and a return unit 505. Wherein the processing unit 501 is configured to, in response to receiving the sequence number generation instruction, perform the following processing steps: modifying data stored by a first data node in a data node storage server to update a data version number of the first data node, obtaining a current data version number and a child node version number of the first data node, determining whether the data version number is equal to a first preset value, in response to determining that the data version number is not equal to the first preset value, further determining whether said data version number is equal to a second preset value, in response to determining that said data version number is not equal to said second preset value, determining a sequence number based on said data version number and said child node version number, wherein the data node storage server stores a second data node and the first data node including a child node in advance, the first data node and the second data node respectively store data, and the first data node comprises the data version number and the child node version number; the comparison value determining unit 502 is configured to determine a comparison value based on the data stored in the second data node and the second preset value; the first determining unit 503 is configured to determine whether the serial number is smaller than the comparison value; a second determining unit 504 is configured to, in response to determining that the serial number is not less than the comparison value, further determine whether the serial number is greater than the comparison value and the child node version number is greater than data stored in a second data node stored in a memory in advance; the returning unit 505 is configured to return the sequence number in response to determining that the sequence number is not greater than the comparison value and the version number of the child node is not greater than the data saved by the second data node pre-stored in the memory.
In the present embodiment, in the serial number generation apparatus 500: the specific processing of the processing unit 501, the comparison value determining unit 502, the first determining unit 503, the second determining unit 504, and the returning unit 505 and the technical effects thereof can refer to the related descriptions of step 201, step 202, step 203, step 204, and step 205 in the corresponding embodiment of fig. 2, which are not repeated herein.
In some optional implementations of this embodiment, the processing unit 501 may include: a first processing subunit (not shown in the figure), configured to add or delete a child node of the first data node to update the child node version number in response to determining that the data version number is equal to the first preset value, and to re-execute the processing step.
In some optional implementations of this embodiment, the processing unit 501 may include: a second processing subunit (not shown in the figure), configured to modify, in response to determining that the data version number is equal to the second preset value, data stored by a second data node that is pre-stored in the memory and data stored by the second data node in the data node storage server to be current version numbers of the child nodes, respectively, and determine a serial number based on the current version numbers of the child nodes and the data version numbers of the data nodes.
In some optional implementations of this embodiment, the apparatus 500 may include: a first processing unit (not shown in the figure) configured to add or delete a child node of the first data node to update the child node version number in response to determining that the sequence number is smaller than the comparison value, and to re-execute the processing step.
In some optional implementations of this embodiment, the apparatus 500 may include: and a second processing unit (not shown in the figure), configured to update the data stored in the second data node stored in the memory in response to determining that the serial number is greater than the comparison value and the version number of the child node is greater than the data stored in the second data node stored in the memory in advance, modify the data stored in the second data node in the data node storage server to the current version number of the child node, and return the serial number.
The apparatus provided in the foregoing embodiment of the present application effectively utilizes the data version number of the data stored in the first data node in the data node storage server and the child node version number of the child node of the first data node, and can generate the ordered sequence number with high availability.
Referring now to FIG. 6, shown is a block diagram of a computer system 600 suitable for use in implementing the electronic device of an embodiment of the present application. The electronic device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The above-described functions defined in the system of the present application are executed when the computer program is executed by the Central Processing Unit (CPU) 601.
It should be noted that the computer readable medium shown in the present application may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present application may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes a processing unit, a comparison value determination unit, a first determination unit, a second determination unit, and a return unit. Where the names of these units do not in some cases constitute a limitation on the unit itself, for example, the first determination unit may also be described as a "unit that determines whether the sequence number is smaller than the comparison value".
As another aspect, the present application also provides a computer-readable medium, which may be contained in the electronic device described in the above embodiments; or may exist separately without being assembled into the electronic device. The computer readable medium carries one or more programs which, when executed by an electronic device, cause the electronic device to include: in response to receiving the sequence number generation instruction, performing the following processing steps: modifying data stored by a first data node in a data node storage server to update a data version number of the first data node, obtaining a current data version number and a child node version number of the first data node, determining whether the data version number is equal to a first preset value, in response to determining that the data version number is not equal to the first preset value, further determining whether said data version number is equal to a second preset value, in response to determining that said data version number is not equal to said second preset value, determining a sequence number based on said data version number and said child node version number, wherein the data node storage server stores a second data node and the first data node including a child node in advance, the first data node and the second data node respectively store data, and the first data node comprises the data version number and the child node version number; determining a comparison value based on the data stored in the second data node and the second preset value; determining whether the sequence number is less than the comparison value; in response to determining that the serial number is not less than the comparison value, further determining whether the serial number is greater than the comparison value and whether the child node version number is greater than data stored in a second data node pre-stored in a memory; and returning the serial number in response to the fact that the serial number is not larger than the comparison value and the version number of the child node is not larger than the data stored in a second data node stored in a memory in advance.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention herein disclosed is not limited to the particular combination of features described above, but also encompasses other arrangements formed by any combination of the above features or their equivalents without departing from the spirit of the invention. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.

Claims (12)

1. A method for generating a sequence number, the method comprising:
in response to receiving the sequence number generation instruction, performing the following processing steps: modifying data saved by a first data node in a data node storage server to update a data version number of the first data node, obtaining a current data version number and a child node version number of the first data node, determining whether the data version number is equal to a first preset value, further determining whether the data version number is equal to a second preset value in response to determining that the data version number is not equal to the first preset value, and determining a serial number based on the data version number and the child node version number in response to determining that the data version number is not equal to the second preset value, wherein the data node storage server stores a second data node and the first data node including child nodes in advance, the first data node and the second data node respectively store data, and the first data node includes the data version number and the child node version number, the first preset value is the minimum value of the data version number, and the second preset value is the middle value of the minimum value and the maximum value of the data version number;
determining a comparison value based on the data saved by the second data node and the second preset value;
determining whether the sequence number is less than the comparison value;
in response to determining that the serial number is not less than the comparison value, further determining whether the serial number is greater than the comparison value and whether the child node version number is greater than data saved by a second data node pre-stored in a memory;
and in response to determining that the serial number is not greater than the comparison value and the version number of the child node is not greater than the data saved by a second data node pre-stored in the memory, returning the serial number.
2. The method of claim 1, wherein the processing step comprises:
and in response to determining that the data version number is equal to the first preset value, adding or deleting child nodes of the first data node to update the child node version number, and re-executing the processing step.
3. The method of claim 2, wherein the processing step comprises:
and in response to determining that the data version number is equal to the second preset value, modifying the data stored by the second data node pre-stored in the memory and the data stored by the second data node in the data node storage server to the current child node version number respectively, and determining a serial number based on the current child node version number and the data version number.
4. A method according to one of claims 1-3, characterized in that the method comprises:
in response to determining that the sequence number is less than the comparison value, adding or deleting child nodes of the first data node to update the child node version number, re-executing the processing step.
5. The method of claim 4, wherein the method comprises:
and in response to the fact that the serial number is larger than the comparison value and the version number of the child node is larger than the data stored in a second data node which is stored in the memory in advance, updating the data stored in the second data node which is stored in the memory in advance, modifying the data stored in the second data node in the server for storing the data node into the current version number of the child node, and returning the serial number.
6. An apparatus for generating a serial number, the apparatus comprising:
a processing unit configured to, in response to receiving the sequence number generation instruction, perform the following processing steps: modifying data saved by a first data node in a data node storage server to update a data version number of the first data node, obtaining a current data version number and a child node version number of the first data node, determining whether the data version number is equal to a first preset value, further determining whether the data version number is equal to a second preset value in response to determining that the data version number is not equal to the first preset value, and determining a serial number based on the data version number and the child node version number in response to determining that the data version number is not equal to the second preset value, wherein the data node storage server stores a second data node and the first data node including child nodes in advance, the first data node and the second data node respectively store data, and the first data node includes the data version number and the child node version number, the first preset value is the minimum value of the data version number, and the second preset value is the middle value of the minimum value and the maximum value of the data version number;
a comparison value determination unit configured to determine a comparison value based on the data held by the second data node and the second preset value;
a first determination unit configured to determine whether the sequence number is less than the comparison value;
a second determining unit, configured to, in response to determining that the serial number is not less than the comparison value, further determine whether the serial number is greater than the comparison value and whether the child node version number is greater than data stored in a second data node stored in the memory in advance;
and the return unit is configured to return the sequence number in response to determining that the sequence number is not greater than the comparison value and the version number of the child node is not greater than the data stored in the second data node which is stored in the memory in advance.
7. The apparatus of claim 6, wherein the processing unit comprises:
a first processing subunit configured to add or delete a child node of the first data node to update the child node version number in response to determining that the data version number is equal to the first preset value, and to re-execute the processing step.
8. The apparatus of claim 7, wherein the processing unit comprises:
and the second processing subunit is configured to modify, in response to determining that the data version number is equal to the second preset value, data stored by a second data node that is pre-stored in the memory and data stored by the second data node in the data node storage server to the current child node version number, and determine a sequence number based on the current child node version number and the data version number.
9. The apparatus according to any one of claims 6-8, wherein the apparatus comprises:
a first processing unit configured to add or delete a child node of the first data node to update the child node version number in response to determining that the sequence number is less than the comparison value, and to re-execute the processing step.
10. The apparatus of claim 9, wherein the apparatus comprises:
and the second processing unit is configured to update the data stored in the second data node stored in the memory in response to determining that the serial number is greater than the comparison value and the version number of the child node is greater than the data stored in the second data node stored in the memory in advance, modify the data stored in the second data node in the server for storing the data node into the current version number of the child node, and return the serial number.
11. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-5.
12. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN201710287039.XA 2017-04-27 2017-04-27 Serial number generation method and device Active CN108804442B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710287039.XA CN108804442B (en) 2017-04-27 2017-04-27 Serial number generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710287039.XA CN108804442B (en) 2017-04-27 2017-04-27 Serial number generation method and device

Publications (2)

Publication Number Publication Date
CN108804442A CN108804442A (en) 2018-11-13
CN108804442B true CN108804442B (en) 2022-06-07

Family

ID=64069691

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710287039.XA Active CN108804442B (en) 2017-04-27 2017-04-27 Serial number generation method and device

Country Status (1)

Country Link
CN (1) CN108804442B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110046192B (en) * 2019-04-22 2021-08-20 广州荔支网络技术有限公司 System and method for generating serial number of request information
CN112104743B (en) * 2020-09-21 2022-08-16 北京金山云网络技术有限公司 Sequence generation method and device and electronic equipment

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102110121A (en) * 2009-12-24 2011-06-29 阿里巴巴集团控股有限公司 Method and system for processing data
CN102801736A (en) * 2011-12-29 2012-11-28 公安部第三研究所 Generation and verification control method of network identity identification code in network electronic identity card
CN102833281A (en) * 2011-06-15 2012-12-19 中兴通讯股份有限公司 Method, device and system for realizing distributed automatically-increasing counting
CN103826252A (en) * 2014-01-16 2014-05-28 京信通信系统(中国)有限公司 Method of acquiring and sending sequence numbers among main and slave devices and system
CN104092675A (en) * 2014-06-30 2014-10-08 飞天诚信科技股份有限公司 Reverse processing method and terminal based on main communication structure and auxiliary communication structure
CN104361065A (en) * 2014-11-04 2015-02-18 福建亿榕信息技术有限公司 Orderly sequence number generating method of Zookeeper-based distributed system
CN105245367A (en) * 2015-10-08 2016-01-13 北京搜狗科技发展有限公司 Serial number generation method and electronic device
CN106095927A (en) * 2016-06-12 2016-11-09 北京三快在线科技有限公司 A kind for the treatment of method and apparatus of position data

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP2452298A4 (en) * 2009-07-10 2014-08-27 Certicom Corp System and method for performing serialization of devices
US20160164748A1 (en) * 2014-12-04 2016-06-09 Belkin International, Inc. Identifying and resolving network device rule conflicts and recursive operations at a network device

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102110121A (en) * 2009-12-24 2011-06-29 阿里巴巴集团控股有限公司 Method and system for processing data
CN102833281A (en) * 2011-06-15 2012-12-19 中兴通讯股份有限公司 Method, device and system for realizing distributed automatically-increasing counting
CN102801736A (en) * 2011-12-29 2012-11-28 公安部第三研究所 Generation and verification control method of network identity identification code in network electronic identity card
CN103826252A (en) * 2014-01-16 2014-05-28 京信通信系统(中国)有限公司 Method of acquiring and sending sequence numbers among main and slave devices and system
CN104092675A (en) * 2014-06-30 2014-10-08 飞天诚信科技股份有限公司 Reverse processing method and terminal based on main communication structure and auxiliary communication structure
CN104361065A (en) * 2014-11-04 2015-02-18 福建亿榕信息技术有限公司 Orderly sequence number generating method of Zookeeper-based distributed system
CN105245367A (en) * 2015-10-08 2016-01-13 北京搜狗科技发展有限公司 Serial number generation method and electronic device
CN106095927A (en) * 2016-06-12 2016-11-09 北京三快在线科技有限公司 A kind for the treatment of method and apparatus of position data

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
"A distributed abnormal packet generation engine based on MapReduce";Zhang Qi-fei 等;《2012 19th International Conference on High Performance Computing》;20130429;1-5 *
"管理信息系统中流水号生成方法与实现";杨宝明;《计算机工程与设计》;20051228(第5期);3383-3385,3401 *

Also Published As

Publication number Publication date
CN108804442A (en) 2018-11-13

Similar Documents

Publication Publication Date Title
CN108846753B (en) Method and apparatus for processing data
CN107302597B (en) Message file pushing method and device
US20220043898A1 (en) Methods and apparatuses for acquiring information
CN108011949B (en) Method and apparatus for acquiring data
CN110007936B (en) Data processing method and device
CN107347093B (en) Configuration method and device for distributed server system
CN108733527B (en) System, method and apparatus for testing server functionality
CN111857720A (en) Method and device for generating user interface state information, electronic equipment and medium
CN108804442B (en) Serial number generation method and device
CN109828830B (en) Method and apparatus for managing containers
CN112559898B (en) Item information sending method, item information sending device, electronic equipment and computer readable medium
CN110795328A (en) Interface testing method and device
CN110708238B (en) Method and apparatus for processing information
CN109840072B (en) Information processing method and device
CN111324470A (en) Method and device for generating information
CN113722007B (en) Configuration method, device and system of VPN branch equipment
CN111124523A (en) Method and apparatus for initializing applications
CN114428925A (en) Page rendering method and device, electronic equipment and computer readable medium
CN112929453A (en) Method and device for sharing session data
CN109840073B (en) Method and device for realizing business process
CN113760487A (en) Service processing method and device
CN111414566A (en) Method and device for pushing information
CN111290761A (en) Gray scale distribution method, device, medium and electronic equipment
CN113472565B (en) Method, apparatus, device and computer readable medium for expanding server function
CN113765868B (en) Service processing method and device

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
GR01 Patent grant
GR01 Patent grant