Database serial number generation method, device, equipment and medium

By monitoring and analyzing the request peak, setting multiple request partitions and generating partitions, the problem of low serial number generation efficiency in MySQL database is solved, and the database performance and availability of high concurrent systems are improved.

CN116701395BActive Publication Date: 2025-08-22INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310671088.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-07
Publication Date
2025-08-22
Estimated Expiration
2043-06-07

AI Technical Summary

Technical Problem

In high concurrency systems, the lack of a sequence number generator in the MySQL database causes a locking operation to cause slow generation of sequence numbers and slow system response, affecting system availability.

Method used

By monitoring the serial number generation requests of the application system in real time, recording them in the log table, counting the request volume peak, determining the initial length and length increment, setting the initial value for the message queue, and setting multiple request partitions and generating partitions, using the partitions of the message queue to process the serial number generation requests, improving the generation efficiency.

Benefits of technology

High concurrent sequence number generation is realized, database performance and system availability are improved, and rapid response in high concurrency situations are ensured.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116701395B_ABST
    Figure CN116701395B_ABST
Patent Text Reader

Abstract

The present disclosure provides a method for generating a database serial number, which relates to the field of big data technology. The method first monitors multiple request volume peaks of the application system in multiple historical time periods in real time, and by analyzing the request volume peaks, determines the initial length and length increment of the serial number, as well as the initial value of the serial number of the message queue, and sets multiple request partitions and corresponding multiple generation partitions for the message queue. By sending a serial number generation request to a request partition in the message queue, the generation partition corresponding to the request partition obtains the request from the message queue and processes it to respond to the application system's request to obtain the serial number. The present disclosure also provides a database serial number generation device, an electronic device, a storage medium, and a program product.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of big data technology, and in particular to a method, device, electronic device, medium, and program product for generating a database sequence number. Background Art

[0002] To increase the request volume and response speed of high-concurrency systems, online clusters are often built. The maturity of various cluster technologies has led to an exponential increase in the number of requests that a system can handle simultaneously. Sequence numbers do not exist in the relational database MySQL. If a sequence is needed as a primary key, this can only be achieved programmatically. Maintaining sequence uniqueness in clustered, highly concurrent systems often requires locking, which can lead to wait times or deadlocks. This slows down sequence generation and can cause temporary system unavailability. Summary of the Invention

[0003] In view of the above-mentioned problems of slow serial number generation and slow system response due to locking, the present disclosure provides a database serial number generation method, device, electronic device, medium and program product that improve the efficiency of serial number generation.

[0004] According to a first aspect of the present disclosure, a method for generating a database serial number is provided, comprising: monitoring serial number generation requests sent by an application system to a message queue in real time, and recording the serial number generation requests in a log table; counting multiple request volume peaks of the serial number in multiple historical time periods based on the current log table; determining an initial length and a length increment of the serial number based on the multiple request volume peaks, and setting an initial serial number value for the message queue based on the initial length and the length increment; setting multiple request partitions and corresponding multiple generation partitions for the message queue based on the multiple request volume peaks, wherein the request partition is used to store the serial number generation requests, and the generation partition is used to generate corresponding serial numbers based on the serial number generation requests; in response to monitoring a target serial number generation request in a target request partition among the multiple request partitions of the message queue, sending the target serial number generation request to a target generation partition corresponding to the target request partition; the target generation partition generates a target serial number based on the initial serial number value, and feeds the generated target serial number back to the application system.

[0005] According to an embodiment of the present disclosure, the initial length and length increment of the serial number are determined based on multiple request volume peaks, including: determining the initial length based on the serial number length in the current log table; pre-setting the first i digits of the serial number to a time identifier in the year-month-day format, where i is a positive integer; judging whether the initial length is less than i, and if so, adding i digits before the initial length to obtain the final length of the serial number; otherwise, replacing the first i digits of the initial length with the time identifier to obtain the final length of the serial number; calculating the maximum value among multiple request volume peaks, comparing the maximum value with the final length, and determining the length increment of the serial number.

[0006] According to an embodiment of the present disclosure, the maximum value is compared with the final length to determine the length increment of the serial number, including: judging whether the final length is less than the maximum value; if so, taking the difference between the maximum value and the final length as the length increment, and supplementing the final length with the length increment; otherwise, determining that the length increment is 0.

[0007] According to an embodiment of the present disclosure, an initial serial number value is set for a message queue based on an initial length and a length increment, including: adding a predetermined number of 0s after the current time identifier as the initial serial number value, wherein the predetermined number of bits is the sum of the initial length and the length increment minus i bits.

[0008] According to an embodiment of the present disclosure, multiple request partitions and corresponding multiple generation partitions are set for a message queue based on multiple request volume peaks, including: calculating the maximum value among the multiple request volume peaks to determine the number of messages processed per second by the message queue; judging whether the maximum value is less than the number of messages processed per second, and if so, determining the number of request partitions to be 1; otherwise, rounding up the quotient of the maximum value divided by the number of messages processed per second as the number of request partitions; in the message queue, setting a corresponding generation partition for each request partition.

[0009] According to an embodiment of the present disclosure, in response to monitoring a target request partition among multiple request partitions of a message queue before a target sequence number generation request occurs, it also includes: starting multiple consumers to monitor multiple request partitions of the message queue in real time, wherein the number of consumers is set to be the same as the number of request partitions.

[0010] According to an embodiment of the present disclosure, a target generation partition generates a target sequence number based on an initial value of the sequence number, including: determining a partition number of the target generation partition among multiple generation partitions; counting the ordinal number of target sequence number generation requests appearing in the target generation partition; summing the initial value of the sequence number and the ordinal number, and appending the partition number after the summation result as the generated target sequence number.

[0011] According to an embodiment of the present disclosure, a message queue includes a first message queue and a second message queue; multiple request partitions and corresponding multiple generation partitions are set for the message queue, and it also includes: in the first message queue, multiple request partitions are set; in the second message queue, multiple generation partitions are set, and each generation partition corresponds to a request partition in the first message queue.

[0012] A second aspect of the present disclosure provides a database serial number generation device, comprising: a request monitoring module, configured to monitor in real time the serial number generation requests sent by an application system to a message queue, and record the serial number generation requests in a log table; a peak value statistics module, configured to count multiple request volume peaks of the serial number in multiple historical time periods based on the current log table; an initial value determination module, configured to determine the initial length and length increment of the serial number based on the multiple request volume peaks, and set the initial value of the serial number for the message queue based on the initial length and length increment; a partition determination module, configured to set multiple request partitions and corresponding multiple generation partitions for the message queue based on the multiple request volume peaks, wherein the request partition is configured to store the serial number generation requests, and the generation partition is configured to generate corresponding serial numbers based on the serial number generation requests; a partition monitoring module, configured to send the target serial number generation request to the target generation partition corresponding to the target request partition in response to detecting the occurrence of a target serial number generation request in a target request partition among the multiple request partitions of the message queue; and a sequence number generation module, configured to generate a target serial number based on the initial value of the serial number in the target generation partition, and feed the generated target serial number back to the application system.

[0013] The third aspect of the present disclosure provides an electronic device, comprising: one or more processors; a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors execute the above-mentioned database serial number generation method.

[0014] A fourth aspect of the present disclosure further provides a computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute the above-mentioned database serial number generation method.

[0015] The fifth aspect of the present disclosure further provides a computer program product, including a computer program, which implements the above-mentioned database serial number generation method when executed by a processor.

[0016] According to the database serial number generation method, device, electronic device, medium and program product provided by the embodiment of the present disclosure, first, multiple request volume peaks of the application system in multiple historical time periods are monitored in real time, and by analyzing the request volume peaks, the initial length and length increment of the serial number, as well as the initial value of the serial number of the message queue are determined, and multiple request partitions and corresponding multiple generation partitions are set for the message queue. By sending the serial number generation request to a request partition in the message queue, the generation partition corresponding to the request partition obtains the request from the message queue and processes it to respond to the application system's request to obtain the serial number. Therefore, the present disclosure utilizes multiple request partitions and corresponding generation partitions of the message queue to achieve high-concurrency serial number generation for the application system, improve the efficiency of serial number generation, ensure the database performance of the application system, and improve the availability of the application system. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The above contents and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:

[0018] Figure 1 The system architecture of the method and apparatus for generating a database sequence number according to an embodiment of the present disclosure is schematically shown;

[0019] Figure 2 The flowchart of the method for generating a database sequence number according to an embodiment of the present disclosure is schematically shown;

[0020] Figure 3 The following schematically shows a principle diagram of a message queue system according to an embodiment of the present disclosure;

[0021] Figure 4 A schematic diagram illustrating a principle of counting multiple request volume peaks based on a log table according to an embodiment of the present disclosure is shown;

[0022] Figure 5 Schematically illustrates a flow chart of a process for determining an initial length and a length increment of a sequence number according to an embodiment of the present disclosure;

[0023] Figure 6 Schematically shows the Figure 5 A flow chart of a length increment determination process;

[0024] Figure 7 The flowchart schematically shows a process of setting multiple request partitions and multiple generation partitions according to an embodiment of the present disclosure;

[0025] Figure 8 The following schematically shows a flow chart of a target sequence number generation process according to an embodiment of the present disclosure;

[0026] Figure 9Schematically illustrates a flow chart of a process for setting multiple request partitions and multiple generation partitions according to another embodiment of the present disclosure;

[0027] Figure 10 A schematic diagram illustrating a process of setting multiple request partitions and multiple generation partitions according to another embodiment of the present disclosure is shown;

[0028] Figure 11 A block diagram of a database sequence number generating device according to an embodiment of the present disclosure is schematically shown;

[0029] Figure 12 A block diagram of an electronic device suitable for implementing a method for generating a database sequence number according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0030] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present disclosure. In the detailed description below, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.

[0031] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise," "include," etc. used herein indicate the presence of the features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.

[0032] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.

[0033] When expressions such as "at least one of A, B and C, etc." are used, they should generally be interpreted in accordance with the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).

[0034] Some block diagrams and / or flow charts are shown in the accompanying drawings. It should be understood that some blocks in the block diagrams and / or flow charts or their combinations can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that these instructions, when executed by the processor, can create a device for implementing the functions / operations described in these block diagrams and / or flow charts. The technology of the present disclosure can be implemented in the form of hardware and / or software (including firmware, microcode, etc.). In addition, the technology of the present disclosure can take the form of a computer program product on a computer-readable storage medium having instructions stored thereon, which can be used by an instruction execution system or in combination with an instruction execution system.

[0035] In the technical solution disclosed herein, the collection, storage, use, processing, transmission, provision, disclosure and application of user personal information involved comply with the provisions of relevant laws and regulations, take necessary confidentiality measures, and do not violate public order and good morals.

[0036] In the technical solution disclosed herein, the user's authorization or consent is obtained before obtaining or collecting the user's personal information.

[0037] When production application systems experience temporary or prolonged unavailability, analysis often reveals a significant link to database performance. In production environments, the large number of concurrent users accessing the system, coupled with uncertainty in access, can lead to database performance issues at certain times, resulting in slow response times or even unavailability of the entire application system. Currently, the relational database MySQL lacks a corresponding sequence number generator, requiring users to implement their own. Sequence numbers are commonly used as database primary keys to uniquely identify data. Therefore, in highly concurrent systems, when a request concurrently requests a sequence number, locking is required to ensure that the sequence number is incremented.

[0038] Based on this, in order to solve the problem of slow sequence number generation and slow system response caused by locking, the embodiments of the present disclosure provide a database sequence number generation method, device, electronic device, storage medium and program product. The method includes: real-time monitoring of sequence number generation requests sent by the application system to the message queue, recording the sequence number generation requests in a log table; according to the current log table, counting multiple request peaks of the sequence number in multiple historical time periods; according to the multiple request peaks, determining the initial length and length increment of the sequence number, and setting the initial sequence number value for the message queue according to the initial length and length increment; according to the multiple request peaks, setting multiple request partitions and corresponding multiple generation partitions for the message queue, wherein the request partition is used to store the sequence number generation request, and the generation partition is used to generate the corresponding sequence number according to the sequence number generation request; in response to the target sequence number generation request being detected in the target request partition among the multiple request partitions of the message queue, sending the target sequence number generation request to the target generation partition corresponding to the target request partition; the target generation partition generates a target sequence number according to the initial sequence number value, and feeds the generated target sequence number back to the application system.

[0039] Figure 1 The following schematically illustrates the system architecture of the method and apparatus for generating a database sequence number according to an embodiment of the present disclosure. Figure 1 The examples shown are merely examples of system architectures to which the embodiments of the present disclosure may be applied, to help those skilled in the art understand the technical content of the present disclosure, but do not mean that the embodiments of the present disclosure may not be used in other devices, systems, environments or scenarios.

[0040] like Figure 1 As shown, the system architecture 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables.

[0041] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).

[0042] The terminal devices 101 , 102 , and 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.

[0043] The server 105 may be a server that provides various services, such as a background management server (for example only) that supports websites browsed by users using the terminal devices 101, 102, and 103. The background management server may analyze and process received data such as user requests, and feed back processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.

[0044] It should be noted that the database sequence number generation method provided in the embodiments of the present disclosure can generally be executed by the server 105. Accordingly, the database sequence number generation device provided in the embodiments of the present disclosure can generally be set in the server 105. The database sequence number generation method provided in the embodiments of the present disclosure can also be executed by a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105. Accordingly, the database sequence number generation device provided in the embodiments of the present disclosure can also be set in a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105.

[0045] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.

[0046] The following will be based on Figure 1 The system architecture described by Figures 2 to 10 The database serial number generation method of the embodiment of the present disclosure is described in detail.

[0047] Figure 2 The flowchart of the method for generating a database sequence number according to an embodiment of the present disclosure is schematically shown.

[0048] like Figure 2 As shown, the database serial number generation method of this embodiment may include operations S210 to S260, and the database serial number generation method may be executed by the above-mentioned server 105.

[0049] In operation S210 , the sequence number generation request sent by the application system to the message queue is monitored in real time, and the sequence number generation request is recorded in a log table.

[0050] In operation S220 , multiple request volume peaks of the sequence numbers in multiple historical time periods are counted according to the current log table.

[0051] In operation S230 , an initial length and a length increment of a sequence number are determined according to the plurality of request volume peaks, and an initial value of the sequence number is set for the message queue according to the initial length and the length increment.

[0052] In operation S240, multiple request partitions and corresponding multiple generation partitions are set for the message queue according to multiple request volume peaks, wherein the request partition is used to store sequence number generation requests, and the generation partition is used to generate corresponding sequence numbers according to the sequence number generation requests.

[0053] In operation S250 , in response to detecting that a target sequence number generation request occurs in a target request partition among a plurality of request partitions monitored in a message queue, the target sequence number generation request is sent to a target generation partition corresponding to the target request partition.

[0054] In operation S260 , the target generation partition generates a target sequence number according to the initial sequence number value, and feeds the generated target sequence number back to the application system.

[0055] Through the above-mentioned embodiments, the present disclosure monitors in real time the multiple request volume peaks of the application system in multiple historical time periods, and by analyzing the request volume peaks, determines the initial length and length increment of the serial number, as well as the initial value of the serial number of the message queue, and sets multiple request partitions and corresponding multiple generation partitions for the message queue. By sending the serial number generation request to a request partition in the message queue, the generation partition corresponding to the request partition pulls the request from the message queue and processes it to respond to the application system's request to obtain the serial number. Thus, the present disclosure utilizes multiple request partitions and corresponding generation partitions of the message queue to achieve high-concurrency serial number generation for the application system, improve the efficiency of serial number generation, ensure the database performance of the application system, and improve the availability of the application system.

[0056] Figure 3 The schematic diagram shows a principle diagram of a message queue system according to an embodiment of the present disclosure.

[0057] Typically, a message queue system consists of three parts: Producer, Message Queue, and Consumer. Producers, as message producers (transmitted data is a message, such as various types of data files or processing requests sent by one application to other applications), can send messages to the message queue. Consumers can pull messages from the message queue for consumption (for example, sending emails based on the pulled messages).

[0058] In the actual application of the message queue system, there can be multiple producers and multiple consumers, and the message queue can also include queues of multiple message topics. A topic can also include multiple queue groups. Consumers can subscribe to a topic and process the messages published in each queue group under the topic. Figure 3As shown, in the embodiment of the present disclosure, an application architecture of a message queue system is illustrated. Request partitions 302A and 302B can belong to the same message queue 302. Producer 301 can send messages to the message queue 302 (i.e., sequence number generation request). The corresponding messages are pulled by consumers 303A and 303B from request partitions 302A and 302B respectively for consumption.

[0059] Figure 4 The schematic diagram shows a principle diagram of counting multiple request volume peaks based on a log table according to an embodiment of the present disclosure.

[0060] like Figure 4 As shown, due to the uncertainty of the daily request volume in the production environment of the application system, the data volume of the daily serial number request is also inconsistent. The above operation S220 requires real-time monitoring of the serial number generation request sent by the application system and recording it in the corresponding log table. By analyzing the log table, multiple request volume peaks of the serial number in multiple historical time periods can be determined. The multiple historical time periods can include, for example, one month, one quarter, and one year. Thus, the request volume peak of one month, the request volume peak of one quarter, and the request volume peak of one year can be counted. Based on the calculated maximum value max of these three request volume peaks, the high concurrent request volume peak at the same time can also be determined.

[0061] Figure 5 The flowchart of the process of determining the initial length and length increment of a sequence number according to an embodiment of the present disclosure is schematically shown.

[0062] like Figure 5 As shown, in the embodiment of the present disclosure, the above-mentioned operation S230 determines the initial length and length increment of the sequence number according to multiple request volume peaks, and may further include operations S531 to S534.

[0063] In operation S531 , an initial length is determined according to the length of the sequence number in the current log table.

[0064] In operation S532, the first i digits of the serial number are preset as a time identifier in the format of year, month, and day, where i is a positive integer.

[0065] For example, if i=8, the first 8 digits of the serial number can be set as a time identifier yyyymmdd in the format of year, month, and day, where yyyy represents the year, mm represents the month, and dd represents the day.

[0066] In operation S533, it is determined whether the initial length is less than i. If so, i bits are added before the initial length to obtain the final length of the sequence number; otherwise, the first i bits of the initial length are replaced with a time identifier to obtain the final length of the sequence number.

[0067] For example, if the initial length S of the serial number is less than the number of digits i occupied by the time stamp in the year-month-day format yyyymmdd, the final length L of the serial number is obtained as S + i. If the initial length S ≥ i, the first i digits of the initial length S are replaced with the time stamp yyyymmdd to obtain the final length L of the serial number.

[0068] In operation S534 , a maximum value among a plurality of request amount peak values ​​is calculated, the maximum value is compared with the final length, and a length increment of the sequence number is determined.

[0069] For example, the maximum value max of the three request amount peaks is calculated, and the maximum value max is compared with the final length L to determine the length increment of the sequence number.

[0070] Figure 6 Schematically shows the Figure 5 Flowchart of the length increment determination process.

[0071] like Figure 6 As shown, in the embodiment of the present disclosure, the above operation S534 compares the maximum value with the final length to determine the length increment of the sequence number, and may also include the following operation S601.

[0072] In operation S601, it is determined whether the final length is less than the maximum value. If so, the difference between the maximum value and the final length is used as a length increment, and the final length is supplemented with the length increment; otherwise, the length increment is determined to be 0.

[0073] For example, if the final length L is less than the maximum value max, the length increment K=max-L, and K bits are added to the final length L. If the final length L is greater than or equal to the maximum value max, the final length L does not need to be changed, and K=0.

[0074] In an embodiment of the present disclosure, the above operation S230 sets the initial value of the serial number for the message queue based on the initial length and the length increment, including: adding a predetermined number of 0s after the current time identifier as the initial value of the serial number, wherein the predetermined number of bits is the sum of the initial length and the length increment minus i bits.

[0075] For example, based on the final length L and length increment K obtained above, the initial value of the sequence number of the message queue can be determined to be the current timestamp yyyymmdd plus a predetermined number of zeros, where the predetermined number of zeros = L + K - 8. In other words, the initial value of the sequence number is yyyymmdd plus (L + K - 8) zeros, where dd is the current date.

[0076] Figure 7 The flowchart schematically shows a process of setting multiple request partitions and multiple generation partitions according to an embodiment of the present disclosure.

[0077] like Figure 7 As shown, in the embodiment of the present disclosure, the above operation S240 sets multiple request partitions and corresponding multiple generation partitions for the message queue according to multiple request volume peaks, and may further include operations S741 to S743.

[0078] In operation S741 , a maximum value among a plurality of request volume peaks is calculated to determine the number of messages processed per second by the message queue.

[0079] In operation S742, it is determined whether the maximum value is less than the number of messages processed per second. If so, the number of requested partitions is determined to be 1; otherwise, the quotient of the maximum value divided by the number of messages processed per second is rounded up as the number of requested partitions.

[0080] In operation S743 , a corresponding generation partition is set for each request partition in the message queue.

[0081] By analyzing the peak number of concurrent requests at the same time, also known as the maximum value (max), and comparing it with the number of messages processed per second by the message queue, if the maximum value (max) is less than the number of messages processed per second (n), the number of request partitions (NUM) is determined to be 1. If the maximum value (max) is greater than or equal to the number of messages processed per second (n), the number of request partitions (NUM) is determined to be "max / n", where "" represents rounding up to ensure that the number of partitions multiplied by the number of messages processed per second is greater than or equal to the maximum value (max). This determines the number of request partitions, with each generated partition corresponding to a request partition, resulting in multiple corresponding generated partitions.

[0082] Through the above embodiments, the present disclosure sets multiple request partitions and corresponding multiple generation partitions for the message queue. The number of partitions of the message queue can effectively improve the data reading and writing capabilities, and the reasonable number of partitions can effectively improve the concurrent sequence number generation capability.

[0083] Please continue reading Figure 3 Based on the above, it can be seen that the message queue system includes producers and consumers. In the embodiment of the present disclosure, in response to monitoring the occurrence of a target sequence number generation request in a target request partition among the multiple request partitions of the message queue, operation S250 further includes: starting multiple consumers to monitor the multiple request partitions of the message queue in real time, wherein the number of consumers is set to be the same as the number of request partitions.

[0084] Through the above embodiments, the present disclosure starts multiple consumers to monitor the message occurrence of each request partition in real time. In order to improve the request processing capability, the number of consumers to be started is the same as the number of request partitions.

[0085] Figure 8The flowchart schematically shows a process of generating a target sequence number according to an embodiment of the present disclosure.

[0086] like Figure 8 As shown, in the embodiment of the present disclosure, the above-mentioned operation S260 of generating a target partition to generate a target sequence number according to the initial value of the sequence number may further include operations S861 to S863.

[0087] In operation S861 , a partition number of a target generation partition among a plurality of generation partitions is determined.

[0088] In operation S862 , the sequence number of the target sequence number generation request appearing in the target generation partition is counted.

[0089] In operation S863, the initial value of the sequence number and the ordinal number are summed, and the partition number is appended to the sum result to generate a target sequence number.

[0090] For example, if a request occurs in one of the multiple request partitions (i.e., the target request partition), and this request is the first to appear in the production partition, the current sequence number is calculated by adding 1 to the initial sequence number of the message queue. For subsequent requests, the sequence number of each request is added to the current sequence number. To distinguish between production partitions, the partition number is appended to the current sequence number to obtain the final target sequence number.

[0091] It can be understood that since the first i digits of the target serial number of the production are the current time identifier yyyymmdd, if it is 00:00 of the next day, the initial value of the serial number of each production partition will be reset to yyyymmdd plus (L+K-8) zeros, and dd is the date of the day.

[0092] Figure 9 The flowchart schematically shows a process of setting multiple request partitions and multiple generation partitions according to another embodiment of the present disclosure. Figure 10 The following schematically shows a principle diagram of a process for setting multiple request partitions and multiple generation partitions according to another embodiment of the present disclosure.

[0093] like Figure 9 and Figure 10 As shown, in the embodiment of the present disclosure, the message queue includes a first message queue and a second message queue; the above operation S240 sets multiple request partitions and corresponding multiple generation partitions for the message queue, and may also include operations S941 to S942.

[0094] In operation S941 , a plurality of request partitions are set in a first message queue.

[0095] In operation S942 , a plurality of generation partitions are set in the second message queue, and each generation partition corresponds to a request partition in the first message queue.

[0096] like Figure 10 As shown, the application system sends a serial number generation request to a request partition of the first message queue, and obtains the serial number by obtaining the serial number generation module. Specifically, the serial number generation module is provided with a second message queue corresponding to the first message queue. In the second message queue, the generation partition corresponding to the request partition pulls the request from the first message queue and processes it to generate the target serial number in response to the application system's request to obtain the serial number. The serial number generation module obtains the target serial number by real-time monitoring of the serial number generation partition. In order to increase the concurrency speed, multiple consumers will be started to pull requests (the number of consumers is equal to the number of request partitions). When the serial number generation module receives the request, it will generate a target serial number from the serial number generation partition and feed the target serial number back to the corresponding request.

[0097] Based on the above database serial number generation method, the present disclosure also provides a database serial number generation device. Figure 11 The device is described in detail.

[0098] Figure 11 The block diagram of the database sequence number generating device according to the embodiment of the present disclosure is schematically shown.

[0099] like Figure 11 As shown, the database sequence number generating device 1100 of this embodiment includes a request monitoring module 1110 , a peak value statistics module 1120 , an initial value determination module 1130 , a partition determination module 1140 , a partition monitoring module 1150 and a sequence number generating module 1160 .

[0100] The request monitoring module 1110 is used to monitor the sequence number generation request sent by the application system to the message queue in real time and record the sequence number generation request in the log table. In one embodiment, the request monitoring module 1110 can be used to perform the operation S210 described above, which will not be repeated here.

[0101] The peak statistics module 1120 is used to count multiple request volume peaks of the sequence number in multiple historical time periods according to the current log table. In one embodiment, the peak statistics module 1120 can be used to perform the operation S220 described above, which will not be repeated here.

[0102] Initial value determination module 1130 is configured to determine an initial length and length increment of a sequence number based on the multiple request volume peaks, and to set an initial sequence number value for the message queue based on the initial length and length increment. In one embodiment, initial value determination module 1130 may be configured to perform operation S230 described above, which will not be further described herein.

[0103] Partition determination module 1140 is configured to set multiple request partitions and corresponding multiple generation partitions for the message queue based on the multiple request volume peaks, wherein the request partitions are configured to store sequence number generation requests, and the generation partitions are configured to generate corresponding sequence numbers based on the sequence number generation requests. In one embodiment, partition determination module 1140 may be configured to perform operation S240 described above, which will not be further described here.

[0104] Partition monitoring module 1150 is configured to, in response to detecting a target sequence number generation request from a target request partition among the multiple request partitions in the message queue, send the target sequence number generation request to a target generation partition corresponding to the target request partition. In one embodiment, partition monitoring module 1150 may be configured to perform operation S250 described above, which will not be further described herein.

[0105] The sequence number generating module 1160 is used for the target generation partition to generate a target sequence number according to the sequence number initial value and to feed the generated target sequence number back to the application system. In one embodiment, the sequence number generating module 1160 can be used to perform the operation S260 described above, which will not be repeated here.

[0106] According to an embodiment of the present disclosure, any multiple modules among the request monitoring module 1110, the peak statistics module 1120, the initial value determination module 1130, the partition determination module 1140, the partition monitoring module 1150, and the serial number generation module 1160 can be combined into a single module, or any one of them can be split into multiple modules. Alternatively, at least part of the functionality of one or more of these modules can be combined with at least part of the functionality of other modules and implemented in a single module. According to an embodiment of the present disclosure, at least one of the request monitoring module 1110, the peak statistics module 1120, the initial value determination module 1130, the partition determination module 1140, the partition monitoring module 1150, and the serial number generation module 1160 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application-specific integrated circuit (ASIC), or can be implemented in hardware or firmware by any other reasonable means of integrating or packaging circuits, or can be implemented in any one of the three implementation methods of software, hardware, and firmware, or in any appropriate combination of any of them. Alternatively, at least one of the request monitoring module 1110, the peak statistics module 1120, the initial value determination module 1130, the partition determination module 1140, the partition monitoring module 1150 and the serial number generation module 1160 can be at least partially implemented as a computer program module, which can perform the corresponding function when it is executed.

[0107] Figure 12 A block diagram of an electronic device suitable for implementing a method for generating a database sequence number according to an embodiment of the present disclosure is schematically shown.

[0108] like Figure 12 As shown, the electronic device 1200 according to an embodiment of the present disclosure includes a processor 1201, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1202 or a program loaded from a storage part 1208 into a random access memory (RAM) 1203. The processor 1201 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a dedicated microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 1201 may also include an onboard memory for caching purposes. The processor 1201 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.

[0109] Various programs and data required for the operation of the electronic device 1200 are stored in the RAM 1203. The processor 1201, the ROM 1202, and the RAM 1203 are connected to each other via a bus 1204. The processor 1201 performs various operations of the method flow according to the embodiment of the present disclosure by executing the programs in the ROM 1202 and / or the RAM 1203. It should be noted that the programs may also be stored in one or more memories other than the ROM 1202 and the RAM 1203. The processor 1201 may also perform various operations of the method flow according to the embodiment of the present disclosure by executing the programs stored in the one or more memories.

[0110] According to an embodiment of the present disclosure, electronic device 1200 may further include an input / output (I / O) interface 1205, which is also connected to bus 1204. Electronic device 1200 may further include one or more of the following components connected to I / O interface 1205: an input section 1206 including a keyboard, mouse, etc.; an output section 1207 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and speakers; a storage section 1208 including a hard disk; and a communication section 1209 including a network interface card such as a LAN card or a modem. Communication section 1209 performs communication processing via a network such as the Internet. A drive 1210 is also connected to I / O interface 1205 as needed. Removable media 1211, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in drive 1210 as needed, so that computer programs read from the removable media can be installed into storage section 1208 as needed.

[0111] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments, or may exist independently and not be incorporated into the device / apparatus / system. The computer-readable storage medium carries one or more programs, which, when executed, implement the database sequence number generation method according to the embodiments of the present disclosure.

[0112] According to an embodiment of the present disclosure, a computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, it may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, apparatus, or device. For example, according to an embodiment of the present disclosure, a computer-readable storage medium may include the ROM 1202 and / or RAM 1203 described above and / or one or more memories other than ROM 1202 and RAM 1203.

[0113] The embodiments of the present disclosure also include a computer program product, which includes a computer program containing program code for executing the method shown in the flowchart. When the computer program product is executed in a computer system, the program code is used to enable the computer system to implement the database sequence number generation method provided by the embodiments of the present disclosure.

[0114] The computer program executes the above functions defined in the system / device of the embodiment of the present disclosure when the processor 1201 executes the computer program. According to the embodiment of the present disclosure, the system, device, module, unit, etc. described above can be implemented by a computer program module.

[0115] In one embodiment, the computer program may be stored on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may be transmitted and distributed in the form of a signal on a network medium, downloaded and installed via the communication portion 1209, and / or installed from the removable medium 1211. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to wireless, wired, or any suitable combination thereof.

[0116] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1209 and / or installed from the removable medium 1211. When the computer program is executed by the processor 1201, the above-described functions defined in the system of the embodiment of the present disclosure are performed. According to the embodiment of the present disclosure, the systems, devices, means, modules, units, etc. described above can be implemented by computer program modules.

[0117] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computer programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, languages ​​such as Java, C++, python, "C" or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect via the Internet).

[0118] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0119] Those skilled in the art will appreciate that the features described in the various embodiments and / or claims of this disclosure may be combined and / or coupled in various ways, even if such combinations and / or couplings are not explicitly described in this disclosure. In particular, the features described in the various embodiments and / or claims of this disclosure may be combined and / or coupled in various ways without departing from the spirit and teachings of this disclosure. All such combinations and / or couplings are intended to fall within the scope of this disclosure.

[0120] The embodiments of the present disclosure are described above. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although each embodiment has been described separately above, this does not mean that the measures in each embodiment cannot be used in combination to advantage. The scope of the present disclosure is defined by the appended claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present disclosure.

Claims

1. A method for generating a database sequence number, comprising: Real-time monitoring of the serial number generation request sent by the application system to the message queue, and recording the serial number generation request in a log table; Based on the current log table, count the peak request volumes of the sequence number in multiple historical periods. determining an initial length and a length increment of a sequence number according to the multiple request volume peaks, and setting an initial value of the sequence number for the message queue according to the initial length and the length increment; According to the multiple request volume peaks, multiple request partitions and corresponding multiple generation partitions are set for the message queue, wherein the request partition is used to store sequence number generation requests, and the generation partition is used to generate corresponding sequence numbers according to the sequence number generation requests; In response to monitoring a target sequence number generation request in a target request partition among the multiple request partitions of the message queue, sending the target sequence number generation request to a target generation partition corresponding to the target request partition; The target generation partition generates a target sequence number according to the initial sequence number value, and feeds the generated target sequence number back to the application system.

2. The method according to claim 1, wherein The determining, based on the multiple request volume peaks, an initial length and a length increment of a sequence number includes: Determine the initial length according to the sequence number length in the current log table; The first i digits of the serial number are preset as a time identifier in the format of year, month, and day, where i is a positive integer; Determine whether the initial length is less than i. If so, add i bits before the initial length to obtain the final length of the sequence number; otherwise, replace the first i bits of the initial length with the time identifier to obtain the final length of the sequence number; The maximum value among the multiple request amount peak values ​​is calculated, the maximum value is compared with the final length, and the length increment of the sequence number is determined.

3. The method according to claim 2, wherein: Comparing the maximum value with the final length to determine the length increment of the sequence number includes: Determine whether the final length is less than the maximum value. If so, use the difference between the maximum value and the final length as the length increment, and supplement the final length with the length increment; otherwise, determine that the length increment is 0.

4. The method according to claim 2, wherein: The step of setting an initial sequence number value for the message queue according to the initial length and the length increment includes: A predetermined number of 0s is added after the current time identifier to serve as the initial value of the sequence number, wherein the predetermined number of 0s is the sum of the initial length and the length increment minus i bits.

5. The method according to claim 1, wherein The step of setting a plurality of request partitions and corresponding plurality of generation partitions for the message queue according to the plurality of request volume peaks includes: Calculate the maximum value of the multiple request volume peaks to determine the number of messages processed per second by the message queue; Determine whether the maximum value is less than the number of messages processed per second. If so, determine the number of requested partitions to be 1; otherwise, round up the quotient of the maximum value divided by the number of messages processed per second to obtain the requested number of partitions. In the message queue, a corresponding generation partition is set for each request partition.

6. The method according to claim 1, wherein Before the target sequence number generation request occurs in response to monitoring a target request partition among the multiple request partitions of the message queue, the method further includes: A plurality of consumers are started to monitor the plurality of request partitions of the message queue in real time, wherein the number of the consumers is set to be the same as the number of the request partitions.

7. The method according to claim 1, wherein The target generation partition generates a target sequence number according to the initial sequence number value, including: Determine a partition number of the target generation partition among the multiple generation partitions; Counting the ordinal number of the target sequence number generation request appearing in the target generation partition; The initial value of the sequence number and the ordinal number are summed, and the partition number is appended to the sum result to generate a target sequence number.

8. The method according to claim 1, wherein The message queue includes a first message queue and a second message queue; The step of setting a plurality of request partitions and a corresponding plurality of generation partitions for the message queue further includes: In the first message queue, multiple request partitions are set; In the second message queue, a plurality of generation partitions are set, and each of the generation partitions corresponds to a request partition in the first message queue.

9. A database sequence number generating device, comprising: A request monitoring module is used to monitor in real time the sequence number generation request sent by the application system to the message queue, and record the sequence number generation request in a log table; The peak statistics module is used to count the peak requests of the serial number in multiple historical periods according to the current log table; an initial value determination module, configured to determine an initial length and a length increment of a sequence number according to the plurality of request volume peaks, and set an initial value of the sequence number for the message queue according to the initial length and the length increment; a partition determination module, configured to set a plurality of request partitions and corresponding plurality of generation partitions for the message queue according to the plurality of request volume peaks, wherein the request partitions are used to store sequence number generation requests, and the generation partitions are used to generate corresponding sequence numbers according to the sequence number generation requests; a partition monitoring module configured to, in response to detecting a target sequence number generation request in a target request partition among the plurality of request partitions of the message queue, send the target sequence number generation request to a target generation partition corresponding to the target request partition; The sequence number generating module is used for the target generation partition to generate a target sequence number according to the sequence number initial value, and feed the generated target sequence number back to the application system.

10. An electronic device comprising: one or more processors; a storage device 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 enabled to perform the method according to any one of claims 1 to 8.

11. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to perform the method according to any one of claims 1 to 8.

12. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • Distributed non-repeated random sequence generation method and system

    CN113467753A

  • Methods, systems, and computer program products for efficiently accessing an ordered sequence in a clustered database environment

    US20230115573A1