Distributed Short Serial Number Generation Method and Device

By dividing the serial number repetition period into multiple time intervals and generating a sequence number for each node, the problem of limited serial number generation performance in the prior art is solved, and fast response and serial number uniqueness in high concurrency are achieved.

CN113515557BActive Publication Date: 2025-06-10INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110451781.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-26
Publication Date
2025-06-10
Estimated Expiration
2041-04-26

AI Technical Summary

Technical Problem

When the number of serial numbers is not large enough in the prior art, the generation performance of serial numbers is seriously affected and cannot cope with the sudden high concurrency phenomenon.

Method used

By dividing the preset serial number repetition period into multiple time intervals, decimal numbering is performed for these time intervals in chronological order, the interval ID of each time interval is obtained, and a sequence number is generated for each node within each time interval. Receive the node's serial number request, and decide whether to send a serial number to the node based on the comparison result of the number of serial numbers in the request and the number of serial numbers that have been generated.

Benefits of technology

Effectively respond to high concurrency situations at peak transactions, improve the serial number generation performance, and avoid serial number duplication while saving the number of serial number bits.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113515557B_ABST
    Figure CN113515557B_ABST
Patent Text Reader

Abstract

The present invention provides a distributed short serial number generation method and device, which relate to the computer field and the financial field. The method includes: dividing a preset serial number repetition period into multiple time intervals according to the total number of nodes, and numbering the multiple time intervals in decimal order according to the time sequence to obtain the interval ID of each time interval; generating a serial number for each node respectively within each time interval; receiving a serial number request sent by a node, and comparing the number of serial numbers in the serial number request with the number of serial numbers of the corresponding node that has been generated; when the number of serial numbers in the serial number request is less than or equal to the number of serial numbers of the corresponding node that has been generated, sending serial numbers to the node according to the serial number request. This application saves the number of bits of the serial number while improving the generation performance of the serial number, can use up all the serial numbers generated from after the node starts to the current time, and effectively cope with the high concurrency phenomenon during the transaction peak.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of computers and finance, and particularly to a method and device for generating distributed short serial numbers. Background Art

[0002] In the design of distributed serial numbers, in order to support horizontal expansion well, serial numbers are usually not associated with the persistent layer, but are generated purely in memory based on application nodes. For example, the Snowflake algorithm divides the serial number into "millisecond timestamp | node ID | sequence bit" in binary bits. Since the node IDs are different, the serial numbers of each node are not repeated. For each node, the last generated timestamp is recorded to determine whether there are multiple requests at the same time. If so, the sequence bit is incremented by 1 for each request. If the sequence bit overflows, it is reset to 0 and waits for the next millisecond.

[0003] The implementation of the above Snowflake algorithm needs to ensure that the number of bits of the serial number is sufficient. When the number of bits is not enough, the Snowflake algorithm can be improved. For example, shorten the node ID and the sequence bit, or even cancel the sequence bit.

[0004] However, after canceling the sequence bit, in order to ensure that the serial numbers are not repeated, each node can only generate 1 serial number at each timestamp, that is, the rate of generating serial numbers for each node is only one over the total number of nodes. Since the serial numbers are generated evenly over time, and the serial number requests do not occur evenly, in the high-concurrency period of serial number requests, the existing serial number generation methods cannot respond quickly. Therefore, in the prior art, when the number of bits of the serial number is not enough, the performance of generating serial numbers will be severely affected and cannot cope with sudden high concurrency. Summary of the Invention

[0005] In order to solve the problems existing in the prior art, the present application provides a method for generating distributed short serial numbers, which relates to the fields of computers and finance. The method for generating distributed short serial numbers includes:

[0006] Dividing a preset serial number repetition period into multiple time intervals according to the total number of nodes, and numbering the multiple time intervals in decimal order according to the time sequence to obtain the interval ID of each time interval;

[0007] Generating a serial number for each node in each time interval;

[0008] Receiving a serial number request sent by a node, and comparing the number of serial numbers in the serial number request with the number of serial numbers of the corresponding node that have been generated;

[0009] Sending serial numbers to the corresponding nodes according to the comparison result and the serial number sending strategy.

[0010] In one embodiment, sending the sequence number to the corresponding node according to the comparison result and the sequence number sending policy includes:

[0011] When the number of sequence numbers in the sequence number request is less than or equal to the number of sequence numbers of the corresponding node that have been generated, send the sequence number to the node according to the sequence number request;

[0012] When the number of sequence numbers in the sequence number request is greater than the number of sequence numbers of the corresponding node that have been generated, suspend receiving the sequence number request of the node until the number of sequence numbers of the corresponding node that have been generated is equal to the number of sequence numbers in the sequence number request, and then send the sequence number to the node according to the sequence number request.

[0013] In one embodiment, generating a sequence number for each node respectively in each time interval includes:

[0014] Generate a sequence number for each node respectively in the current time interval according to a preset sequence number generation function;

[0015] The sequence number generation function is:

[0016] Sequence number = interval ID of the current time interval × time interval length + node ID

[0017] wherein, the time interval length is equal to the total number of nodes, and the node ID is the decimal number corresponding to each node.

[0018] In one embodiment, the distributed short sequence number generation method further includes:

[0019] When the node restarts within the current sequence number repetition period, determine the time interval in which the restart time of the node is located;

[0020] Delete all the sequence numbers generated in the time interval in which the restart time is located and the time intervals before the time interval in which the restart time is located, and update the number of sequence numbers of the corresponding node that have been generated.

[0021] In one embodiment, before comparing the number of sequence numbers in the sequence number request with the number of sequence numbers of the corresponding node that have been generated, it further includes:

[0022] Determine the request timestamp of the node for sending the sequence number request, and the request timestamp of the previous sequence number request sent by the node;

[0023] Judge whether the request timestamp of the sequence number request is later than the request timestamp of the previous sequence number request sent by the node;

[0024] If so, compare the number of serial numbers in the serial number request with the number of serial numbers of the corresponding nodes that have been generated; if not, reject the receipt of the serial number request.

[0025] In one embodiment, determining the request timestamp at which the node sends the serial number request includes:

[0026] Determine the time interval in which the moment when the node sends the serial number request is located;

[0027] Substitute the time interval into a preset request timestamp determination function,

[0028] Request timestamp = interval ID of the time interval × length of the time interval.

[0029] In one embodiment, the request timestamp of the previous serial number request sent by the node includes:

[0030] Determine the time interval in which the request moment when the node sends the previous serial number request is located;

[0031] Substitute the time interval into a preset request timestamp determination function,

[0032] Request timestamp = interval ID of the time interval × length of the time interval.

[0033] This application also provides a distributed short serial number generation device for implementing the distributed short serial number generation method provided by this application. The device includes:

[0034] A time interval determination module, configured to divide a preset serial number repetition period into multiple time intervals according to the total number of nodes, and perform decimal numbering on the multiple time intervals in chronological order to obtain the interval ID of each time interval;

[0035] A serial number generation module, configured to generate a serial number for each node respectively within each time interval;

[0036] A serial number comparison module, configured to receive the serial number request sent by the node, and compare the number of serial numbers in the serial number request with the number of serial numbers of the corresponding nodes that have been generated;

[0037] A serial number sending module, configured to send serial numbers to the corresponding nodes according to the comparison result and the serial number sending strategy.

[0038] Among them, the serial number generation module is specifically configured to:

[0039] Generate a serial number for each node respectively within the current time interval according to a preset serial number generation function;

[0040] The serial number generation function is:

[0041] Serial number = interval ID of the current time interval × length of the time interval + node ID

[0042] Wherein, the length of the time interval is equal to the total number of nodes, and the node ID is the decimal number corresponding to each node.

[0043] In one embodiment, the serial number sending module is specifically configured to:

[0044] When the number of serial numbers in the serial number request is less than or equal to the number of serial numbers of the corresponding node that has been generated, send the serial number to the node according to the serial number request;

[0045] When the number of serial numbers in the serial number request is greater than the number of serial numbers of the corresponding node that has been generated, suspend receiving the serial number request of the node, and continuously determine whether the number of serial numbers of the corresponding node that has been generated is equal to the number of serial numbers in the serial number request; when the number of serial numbers of the corresponding node that has been generated is equal to the number of serial numbers in the serial number request, send the serial number to the node according to the serial number request.

[0046] In one embodiment, the distributed short serial number generation device further includes:

[0047] A restart time interval determination module, configured to determine the time interval in which the restart moment of the node is located when the node restarts within the current serial number repetition period;

[0048] A serial number update module, configured to delete all serial numbers generated within the time interval in which the restart moment is located and the time intervals before the time interval in which the restart moment is located, and update the number of serial numbers of the corresponding node that has been generated.

[0049] In one embodiment, the distributed short serial number generation device further includes:

[0050] A time determination module, configured to determine the request timestamp of the serial number request sent by the node, and the request timestamp of the previous serial number request sent by the node;

[0051] A validity judgment module, configured to judge whether the request timestamp of the serial number request is later than the request timestamp of the previous serial number request sent by the node; if so, compare the number of serial numbers in the serial number request with the number of serial numbers of the corresponding node that has been generated; if not, reject receiving the serial number request.

[0052] In one embodiment, the time determination module is specifically configured to:

[0053] Determine the time interval in which the moment when the node sends the serial number request is located;

[0054] Substitute the time interval into a preset request timestamp determination function,

[0055] Request timestamp = interval ID of the time interval × length of the time interval.

[0056] In one embodiment, the time determination module includes a request timestamp determination unit for:

[0057] Determine the time interval in which the request moment when the node sends the previous sequence number request is located;

[0058] Substitute the time interval into a preset request timestamp determination function,

[0059] Request timestamp = interval ID of the time interval × length of the time interval.

[0060] The distributed short sequence number generation method and device of the present application use up all the sequence numbers generated from the start of the node startup to the current time based on the Snowflake algorithm, save the redundant sequence numbers during the transaction low period, and can effectively cope with the sudden high concurrency phenomenon during the transaction peak. While saving the number of bits of the sequence number, the generation performance of the sequence number is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0062] Figure 1 It is a schematic diagram of the distributed short sequence number generation method.

[0063] Figure 2 It is another schematic diagram of the distributed short sequence number generation method.

[0064] Figure 3 It is another schematic diagram of the distributed short sequence number generation method.

[0065] Figure 4 It is another schematic diagram of the distributed short sequence number generation method.

[0066] Figure 5 It is a schematic diagram of the distributed short sequence number generation device.

[0067] Figure 6 It is another schematic diagram of the distributed short sequence number generation device.

[0068] Figure 7 It is another schematic diagram of the distributed short sequence number generation device.

[0069] Figure 8 It is a schematic diagram of an electronic device. Specific implementation mode

[0070] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0071] This application provides a distributed short serial number generation method, which relates to the computer field and the financial field. As Figure 1 shown, the distributed short serial number generation method includes:

[0072] Step S101, divide the preset serial number repetition period into multiple time intervals according to the total number of nodes, and number the multiple time intervals in decimal order according to the time sequence to obtain the interval ID of each time interval.

[0073] Specifically, assume that the total number of nodes is 32, the node IDs of each node are 0 to 31 in sequence, the serial number repetition period is 24 hours, the serial number generation frequency is 1 per millisecond, and only one serial number can be generated for the same node within each time interval. On this basis, in order to ensure that one serial number is generated for each node within the same time interval, at least 32 serial numbers need to be generated in each time interval. Therefore, the time interval length should be equal to or greater than 32 ms. In this example, taking the time interval length equal to 32 ms as an example, each 24-hour repetition period can be divided into 2,700,000 time intervals with a length of 32 ms.

[0074] According to the chronological order, number the divided time intervals in decimal order to obtain the interval IDs of each time interval as 0 to 2,699,999 in sequence.

[0075] Step S102, generate a serial number for each node in each time interval respectively.

[0076] As can be seen from the above, when the time interval length is 32 ms, each node can and only generate one serial number in each time interval. In order to ensure that the serial numbers of each node generated within the same time interval do not repeat, this application gives a serial number generation rule to generate a serial number for each node in the current time interval respectively. Specifically, according to the preset serial number generation function:

[0077] Serial number = interval ID of the current time interval × time interval length + node ID

[0078] Among them, the length of the time interval is greater than or equal to the total number of nodes (unit: ms), and the node ID is the decimal number corresponding to each node.

[0079] For example, assume that the interval ID of the current time interval is 1. Then, the sequence number generated for the node with node ID 13 in the 1st time interval is: 1×32 + 13 = 00000045, and the sequence number generated for the node with node ID 20 is: 1×32 + 20 = 00000052.

[0080] According to the sequence number generation function, the sequence number is related to both the interval ID of the time interval and the node ID. Therefore, due to the different node IDs of each node, the sequence numbers generated for each node in the same time interval are different. At the same time, since the interval IDs of each time interval are also different, the sequence numbers generated for the same node in different time intervals are also different. In fact, all the sequence numbers generated within the same sequence number repetition period are different. Therefore, generating sequence numbers according to the above sequence number generation function can avoid the situation of sequence number repetition.

[0081] The sequence number obtained by the distributed short sequence number generation method of this application only contains 8 digits, cancels the sequence bits of the sequence numbers generated by the existing Snowflake algorithm, and can be applied to the situation where the number of sequence number digits is insufficient.

[0082] In step S102, instead of generating a sequence number after receiving a sequence number request from a node, sequence numbers are generated for each node in each time interval.

[0083] When no sequence number request from a node is received, the generated sequence numbers will be stored in the storage space corresponding to each node. When a sequence number request from a node is received, the sequence number (i.e., the available sequence number) stored in the storage space corresponding to this node can be sent to this node, which can save the sequence number generation time.

[0084] Step S103, receive the sequence number request sent by the node, and compare the number of sequence numbers in the sequence number request with the number of sequence numbers of the corresponding node that have been generated.

[0085] Generally, a single sequence number request sent by a node can request multiple sequence numbers. According to the method of this application, since multiple sequence numbers may have been generated for this node before receiving the sequence number request from the node, step S103 compares the number of sequence numbers in the sequence number request with the number of sequence numbers of the corresponding node that have been generated to determine whether the stored sequence numbers of this node meet the sequence number request of the node.

[0086] Step S104, send sequence numbers to the corresponding node according to the comparison result and the sequence number sending strategy.

[0087] In one embodiment, the sending of the serial number to the corresponding node according to the comparison result and the serial number sending policy specifically includes:

[0088] When the number of serial numbers in the serial number request is less than or equal to the number of serial numbers of the corresponding node that have been generated, send the serial number to the node according to the serial number request.

[0089] In this embodiment, when the number of serial numbers in the serial number request is less than or equal to the number of serial numbers of the corresponding node that have been generated, it means that the serial numbers stored for this node (i.e., available serial numbers) can meet the serial number request of this node. At this time, directly send the serial number to the node according to the serial number request.

[0090] For example, assume that the interval ID of the current time interval is 100, and node 13 requests to issue 90 serial numbers. And before this, node 13 has never sent a serial number request. Then it indicates that the number of serial numbers stored in the storage space corresponding to node 13 (i.e., available serial numbers) is 101, which meets the serial number request of node 13. At this time, directly issue 90 serial numbers to node 13. Among them, the 90 serial numbers issued are included in the 101 serial numbers in the storage space. As for how to select 90 serial numbers from 101 serial numbers, it can be randomly selected or selected according to the generation order of the serial numbers. This application does not limit this.

[0091] For another example, assume that the interval ID of the current time interval is 100, and node 13 requests to issue 90 serial numbers. And before this, node 13 has sent at least one serial number request and has requested to issue a total of 11 serial numbers. Then at this time, the number of serial numbers stored in the storage space corresponding to node 13 (i.e., available serial numbers) is 101 - 11 = 90, which still meets the serial number request of node 13. At this time, directly issue 90 serial numbers to node 13.

[0092] In another embodiment, as Figure 2 shown, the sending of the serial number to the corresponding node according to the comparison result and the serial number sending policy includes:

[0093] Step S105, when the number of serial numbers in the serial number request is greater than the number of serial numbers of the corresponding node that have been generated, suspend receiving the serial number request of the node;

[0094] Step S106, when the number of serial numbers of the corresponding node that have been generated is equal to the number of serial numbers in the serial number request, send the serial number to the node according to the serial number request.

[0095] When the number of serial numbers in the serial number request is greater than the number of serial numbers of the corresponding node that have been generated, it means that the serial numbers stored for this node cannot meet the serial number request of this node, let alone other serial number requests sent by this node. Therefore, the reception of the serial number request of this node is suspended. Until after waiting for a period of time, when the number of serial numbers of the corresponding node that have been generated is equal to the number of serial numbers in the serial number request, then send serial numbers to the node according to the serial number request. At the same time, the serial number requests sent by this node can be received normally.

[0096] For example, assume that the interval ID of the current time interval is 100, and node 13 requests to issue 90 serial numbers. And before this, node 13 has sent at least one serial number request, and a total of 21 serial numbers have been requested to be issued. Then at this time, the number of serial numbers (i.e., available serial numbers) stored in the storage space corresponding to node 13 is 101 - 21 = 80, which cannot meet the serial number request of node 13. At this time, the reception of other serial number requests of node 13 is suspended, and wait to enter the next time interval. Since a serial number will be generated for node 13 in each time interval, therefore, when waiting to enter the time interval with interval ID 110, the number of serial numbers of node 13 that have been generated is 80 + 10 = 90, which exactly meets the serial number request of node 13. At this time, just send 90 serial numbers to node 13 directly.

[0097] It can be understood that after each time serial numbers are sent to a node, it is necessary to update the serial numbers (i.e., available serial numbers) stored in the storage space corresponding to this node and the number of generated serial numbers. Specifically, it can be: delete the serial numbers sent to the node from the corresponding storage space, and at the same time update the number of generated serial numbers to the number of serial numbers (i.e., available serial numbers) stored in the storage space.

[0098] In this embodiment, when the generated serial numbers cannot meet the serial number request of the node, it is necessary to wait until entering a subsequent time interval until the number of generated serial numbers reaches the number of serial numbers in the serial number request. This method ensures that serial numbers generated in future time intervals will not be used in advance.

[0099] In one embodiment, as Figure 3 shown, the distributed short serial number generation method further includes:

[0100] Step S301, when the node restarts within the current serial number repetition period, determine the time interval in which the restart moment of the node is located.

[0101] Specifically, assume that node 13 restarts at 12:00, and determine that the interval ID of the time interval where 12:00 is located is 1349999.

[0102] Step S302: Delete all the serial numbers generated within the time interval where the restart moment is located and the time intervals before the time interval where the restart moment is located, and update the number of serial numbers of the corresponding node that has been generated.

[0103] Specifically, delete the serial numbers generated for node 13 within the time interval with interval ID from 0 to 1349999. It can be understood that since the serial numbers have been deleted after being issued to the node, the serial numbers deleted in step S302 are actually the serial numbers generated within the time interval with interval ID from 0 to 1349999 and not issued to node 13, that is, all the serial numbers stored in the storage space corresponding to node 13.

[0104] The above step S301 and step S302 are executed immediately when the node restarts.

[0105] In this embodiment, when the node restarts, the serial numbers in the storage space corresponding to the node are cleared, ensuring that the node will not use the serial numbers before the node restarts after restarting.

[0106] In one embodiment, as Figure 4 shown, before comparing the number of serial numbers in the serial number request with the number of serial numbers of the corresponding node that has been generated in step S103, it further includes:

[0107] Step S401: Determine the request timestamp of the node sending the serial number request and the request timestamp of the previous serial number request sent by the node.

[0108] Specifically, the request timestamp of the node sending the serial number request can be determined by a preset request timestamp determination function:

[0109] Request timestamp = interval ID of the time interval where the request moment of the node sending the serial number request is located × time interval length.

[0110] For example, assume that the time interval length is 32 ms. Node 13 sends a serial number request at the 10th ms at the start of the current repetition period, and the interval ID of the time interval where the request moment of the node sending the serial number request is located is 0, then the request timestamp is 0 ms; when node 13 sends a serial number request at the 40th ms at the start of the current repetition period, and the interval ID of the time interval where the request moment of the node sending the serial number request is located is 1, then the request timestamp is 32 ms;

[0111] Similarly, the request timestamp of the previous serial number request sent by the node can be determined by a preset request timestamp determination function:

[0112] Request timestamp = interval ID of the time interval where the request moment of the node sending the previous serial number request is located × time interval length.

[0113] It should be noted that the request timestamp in this embodiment is different from the existing time concept. For example, assume that node 13 sends a sequence number request at the 40th millisecond at the start of the current repetition period, and then sends another sequence number request at the 50th millisecond. According to the above request timestamp determination function, the request timestamp of the sequence number request sent at the 40th millisecond is determined to be 32 milliseconds, and the request timestamp of the sequence number request sent at the 50th millisecond is also 32 milliseconds. That is, the request timestamps of sequence number requests sent at any moment within the same time interval are the same, and they are all the first second of this time interval. For example, the request timestamps of requests sent within the time interval with ID 0 are all 0 milliseconds, the request timestamps of requests sent within the time interval with ID 1 are all 32 milliseconds, and the request timestamps of requests sent within the time interval with ID 2 are all 64 milliseconds.

[0114] Step S402: Determine whether the request timestamp of the sequence number request is later than the request timestamp of the previous sequence number request sent by the node; if so, execute step S403, if not, execute step S404.

[0115] Step S403: Compare the number of sequence numbers in the sequence number request with the number of sequence numbers of the corresponding node that have been generated. If the request timestamp of the current sequence number request is later than the request timestamp of the previous sequence number request, then the current sequence number request is valid.

[0116] Step S404: Reject the reception of the sequence number request. If the request timestamp of the current sequence number request is earlier than or equal to the request timestamp of the previous sequence number request, then the current sequence number request is invalid.

[0117] This embodiment is used to handle the situation when the same node frequently sends sequence number requests.

[0118] The distributed short sequence number generation method of this application can exhaust all the sequence numbers generated from the start of the node startup to the current time, save the redundant sequence numbers during the trading trough, and can effectively handle the sudden high concurrency phenomenon during the trading peak. While saving the number of bits of the sequence number, it improves the generation performance of the sequence number.

[0119] Based on the same inventive concept, the embodiments of the present application further provide a distributed short serial number generation device, which can be used to implement the method described in the above embodiments, as described in the following embodiments. Since the principle of the distributed short serial number generation device to solve problems is similar to that of the distributed short serial number generation method, the implementation of the distributed short serial number generation device can refer to the implementation of the distributed short serial number generation method, and the repeated parts will not be elaborated. As used hereinafter, the term "unit" or "module" can be a combination of software and / or hardware that can achieve a predetermined function. Although the systems described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware is also possible and contemplated.

[0120] The present application also provides a distributed short serial number generation device for implementing the distributed short serial number generation method provided by the present application, as Figure 5 shown. The distributed short serial number generation device 5 includes:

[0121] A time interval determination module 501, configured to divide a preset serial number repetition period into multiple time intervals according to the total number of nodes, and number the multiple time intervals in decimal order according to time to obtain the interval ID of each time interval;

[0122] A serial number generation module 502, configured to generate a serial number for each node within each time interval;

[0123] A serial number comparison module 503, configured to receive a serial number request sent by a node, and compare the number of serial numbers in the serial number request with the number of serial numbers of the corresponding node that has been generated;

[0124] A serial number sending module 504, configured to send serial numbers to the corresponding nodes according to the comparison result and the serial number sending strategy.

[0125] Wherein, the serial number generation module 502 is specifically configured to:

[0126] Generate a serial number for each node within the current time interval according to a preset serial number generation function;

[0127] The serial number generation function is:

[0128] Serial number = interval ID of the current time interval × time interval length + node ID

[0129] Wherein, the time interval length is equal to the total number of nodes, and the node ID is the decimal number corresponding to each node.

[0130] In one embodiment, the serial number sending module 503 is specifically configured to:

[0131] When the number of serial numbers in the serial number request is less than or equal to the number of serial numbers of the corresponding node that has been generated, send the serial number to the node according to the serial number request; and

[0132] When the number of serial numbers in the serial number request is greater than the number of serial numbers of the corresponding node that has been generated, suspend receiving the serial number request of the node, and determine in real time whether the number of serial numbers of the corresponding node that has been generated is equal to the number of serial numbers in the serial number request; when the number of serial numbers of the corresponding node that has been generated is equal to the number of serial numbers in the serial number request, send the serial number to the node according to the serial number request.

[0133] In one embodiment, as Figure 6 shown, the distributed short serial number generation device 5 further includes:

[0134] A restart time interval determination module 505, configured to determine the time interval in which the restart time of the node is located when the node restarts within the current serial number repetition period;

[0135] A serial number update module 506, configured to delete all serial numbers generated within the time interval in which the restart time is located and the time intervals before the time interval in which the restart time is located, and update the number of serial numbers of the corresponding node that has been generated.

[0136] In one embodiment, as Figure 7 shown, the distributed short serial number generation device 5 further includes:

[0137] A timestamp determination module 507, configured to determine the request timestamp of the serial number request sent by the node, and the request timestamp of the previous serial number request sent by the node;

[0138] A validity judgment module 508, configured to judge whether the request timestamp of the serial number request is later than the request timestamp of the previous serial number request sent by the node; if so, compare the number of serial numbers in the serial number request with the number of serial numbers of the corresponding node that has been generated; if not, reject receiving the serial number request, for example, feedback information such as "operation is too frequent" to the corresponding node.

[0139] In one embodiment, as Figure 7 shown, the timestamp determination module 507 is specifically configured to:

[0140] Determine the time interval in which the moment when the node sends the serial number request is located;

[0141] Substitute the time interval in which the moment of the serial number request is located into a preset request timestamp determination function:

[0142] Request timestamp = interval ID of the time interval × length of the time interval; and

[0143] Determine the time interval in which the request moment when the node sends the previous sequence number request is located;

[0144] Substitute the time interval in which the node sends the sequence number at the moment of the previous sequence number request into a preset request timestamp determination function:

[0145] Request timestamp = interval ID of the time interval × length of the time interval.

[0146] The distributed short sequence number generation device of the present application uses up all the sequence numbers generated from after the node starts to the current time on the basis of the Snowflake algorithm, saves the extra sequence numbers during the transaction trough, and can effectively cope with the sudden high concurrency phenomenon during the transaction peak. While saving the number of bits of the sequence number, the generation performance of the sequence number is improved.

[0147] The present invention also provides an electronic device including the distributed short sequence number generation device in the above embodiment. Refer to Figure 8 , the electronic device 800 specifically includes:

[0148] Central processing unit (processor) 810, memory 820, communication module (Communications) 830, input unit 840, output unit 850, and power supply 860.

[0149] Among them, the memory 820, communication module (Communications) 830, input unit 840, output unit 850, and power supply 860 are respectively connected to the central processing unit (processor) 810. A computer program is stored in the memory 820, the central processing unit 810 can call the computer program, and when the central processing unit 810 executes the computer program, all steps in the distributed short sequence number generation method in the above embodiment are implemented.

[0150] The embodiment of the present application also provides a computer storage medium for storing a computer program, and the computer program can be executed by a processor. When the computer program is executed by the processor, any distributed short sequence number generation method provided by the present invention is implemented.

[0151] Each embodiment in this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the device or system embodiments, since they are basically similar to the method embodiments, the description is relatively simple. For the relevant parts, reference can be made to the corresponding parts of the method embodiments. In the description of this specification, the description of reference terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the embodiments of this specification.

[0152] In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment or example. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples. The above are only the embodiments of the embodiments of this specification and are not used to limit the embodiments of this specification. For those skilled in the art, various changes and modifications can be made to the embodiments of this specification. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the embodiments of this specification shall be included within the scope of the claims of the embodiments of this specification.

Claims

1. A distributed short serial number generation method, characterized in that, it includes: Dividing a preset serial number repetition period into multiple time intervals according to the total number of nodes, and numbering the multiple time intervals in decimal order according to time sequence to obtain the interval ID of each time interval; Generating a serial number for each node respectively within each time interval; Receiving a serial number request sent by a node, determining the request timestamp when the node sends the serial number request, and the request timestamp of the previous serial number request sent by the node; Judging whether the request timestamp of the serial number request is later than the request timestamp of the previous serial number request sent by the node; If so, comparing the number of serial numbers in the serial number request with the number of serial numbers of the corresponding node that has been generated; if not, rejecting the receipt of the serial number request; Sending serial numbers to the corresponding node according to the comparison result and the serial number sending strategy, wherein, determining the request timestamp when the node sends the serial number request includes: Determining the time interval where the moment when the node sends the serial number request is located; Substituting the time interval where the moment when the node sends the serial number request is located into a preset request timestamp determination function, the request timestamp when the node sends the serial number request = the interval ID of the time interval where the moment when the node sends the serial number request is located × the time interval length; The request timestamp of the previous serial number request sent by the node includes: Determining the time interval where the request moment of the previous serial number request sent by the node is located; Substituting the time interval where the request moment of the previous serial number request sent by the node is located into a preset request timestamp determination function, the request timestamp of the previous serial number request sent by the node = the interval ID of the time interval where the request moment of the previous serial number request sent by the node is located × the time interval length.

2. The distributed short serial number generation method according to claim 1, characterized in that, the sending serial numbers to the corresponding node according to the comparison result and the serial number sending strategy includes: When the number of serial numbers in the serial number request is less than or equal to the number of serial numbers of the corresponding node that has been generated, sending serial numbers to the node according to the serial number request; When the number of serial numbers in the serial number request is greater than the number of serial numbers of the corresponding node that has been generated, suspending the receipt of the serial number request from the node until the number of serial numbers of the corresponding node that has been generated is equal to the number of serial numbers in the serial number request, and then sending serial numbers to the node according to the serial number request.

3. The distributed short serial number generation method according to claim 2, characterized in that, the generating a serial number for each node respectively within each time interval includes: Generating a serial number for each node respectively within the current time interval according to a preset serial number generation function; The serial number generation function is: serial number = the interval ID of the current time interval × the time interval length + node ID wherein, the time interval length is equal to the total number of nodes, and the node ID is the decimal number corresponding to each node.

4. The distributed short serial number generation method according to claim 3, characterized in that, it further includes: When the node restarts within the current serial number repetition period, determine the time interval in which the restart moment of the node is located; Delete all serial numbers generated within the time interval in which the restart moment is located and the time intervals before the time interval in which the restart moment is located, and update the number of serial numbers of the corresponding node that has been generated.

5. A distributed short serial number generation device, characterized in that, it includes: a time interval determination module, configured to divide a preset serial number repetition period into multiple time intervals according to the total number of nodes, and perform decimal numbering on the multiple time intervals in chronological order to obtain the interval ID of each time interval; a serial number generation module, configured to generate a serial number for each node within each time interval; a serial number comparison module, configured to receive a serial number request sent by a node, determine the request timestamp of the serial number request sent by the node, and the request timestamp of the previous serial number request sent by the node, and determine whether the request timestamp of the serial number request is later than the request timestamp of the previous serial number request sent by the node; if so, compare the number of serial numbers in the serial number request with the number of serial numbers of the corresponding node that has been generated; if not, reject receiving the serial number request; a serial number sending module, configured to send a serial number to the corresponding node according to the comparison result and the serial number sending policy, wherein, determining the request timestamp of the serial number request sent by the node includes: determining the time interval in which the moment when the node sends the serial number request is located; substituting the time interval in which the moment when the node sends the serial number request is located into a preset request timestamp determination function, the request timestamp of the serial number request sent by the node = the interval ID of the time interval in which the moment when the node sends the serial number request is located × the time interval length; the request timestamp of the previous serial number request sent by the node includes: determining the time interval in which the request moment of the previous serial number request sent by the node is located; substituting the time interval in which the request moment of the previous serial number request sent by the node is located into a preset request timestamp determination function, the request timestamp of the previous serial number request sent by the node = the interval ID of the time interval in which the request moment of the previous serial number request sent by the node is located × the time interval length.

6. The distributed short serial number generation device according to claim 5, characterized in that, the serial number sending module is specifically configured to: when the number of serial numbers in the serial number request is less than or equal to the number of serial numbers of the corresponding node that has been generated, send a serial number to the node according to the serial number request; when the number of serial numbers in the serial number request is greater than the number of serial numbers of the corresponding node that has been generated, suspend receiving the serial number request of the node, and continuously determine whether the number of serial numbers of the corresponding node that has been generated is equal to the number of serial numbers in the serial number request; when the number of serial numbers of the corresponding node that has been generated is equal to the number of serial numbers in the serial number request, send a serial number to the node according to the serial number request.

7. The distributed short serial number generation device according to claim 6, It is characterized in that the serial number generation module is specifically configured to: generate a serial number for each node respectively within the current time interval according to a preset serial number generation function; the serial number generation function is: Serial number = interval ID of the current time interval × time interval length + node ID wherein, the time interval length is equal to the total number of nodes, and the node ID is the decimal number corresponding to each node.

8. The distributed short serial number generation device according to claim 7, it is characterized in that it further includes: a restart time interval determination module, configured to determine the time interval in which the restart moment of the node is located when the node restarts within the current serial number repetition period; a serial number update module, configured to delete all the serial numbers generated within the time interval in which the restart moment is located and the time intervals before the time interval in which the restart moment is located, and update the number of serial numbers of the corresponding nodes that have been generated.

9. An electronic device, it is characterized in that it includes: a central processing unit, a memory, and a communication module, wherein a computer program is stored in the memory, the central processing unit can call the computer program, and when the central processing unit executes the computer program, it implements the distributed short serial number generation method according to any one of claims 1 to 4.

10. A computer storage medium for storing a computer program, it is characterized in that when the computer program is executed by a processor, it implements the distributed short serial number generation method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Distributed global ID generation method, device and equipment, and storage medium

    CN108959386A

  • Service serial number generation method, apparatus, computer device, and storage medium

    CN109491772A

  • Generation method, device and system of globally monotonously incremental ID and equipment

    CN109639775A