A method, device and equipment for generating a time series primary key

By sending a registration request to the timing registration device in ultra-high concurrency scenarios and combining the global counter value and target application startup time to generate a timing primary key, the problem of insufficient timing primary key generation performance in the prior art is solved, and efficient and scalable Time sequence primary key generation.

CN113672621BActive Publication Date: 2025-02-18CCB FINTECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110958809.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-20
Publication Date
2025-02-18
Estimated Expiration
2041-08-20

AI Technical Summary

Technical Problem

The existing technology cannot effectively solve the problem of timing primary key generation in ultra-high concurrency scenarios, and the existing methods have poor performance or cannot meet the high concurrency requirements.

Method used

By sending a registration request to the timing registration device when the target application is started, obtaining the application instance registration number, and combining the global counter value and the target application startup time, a timing primary key is generated.

Benefits of technology

It realizes efficient generation of timing primary keys in ultra-high concurrency scenarios, meets the deployment needs of multi-region, multi-center, and multi-clusters, and improves the throughput capability of distributed clusters.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113672621B_ABST
    Figure CN113672621B_ABST
Patent Text Reader

Abstract

The embodiments of this specification provide a method, device and equipment for generating a sequential primary key, including: when a target application is started, sending a registration request to a sequential registration device; wherein the registration request includes registration metadata; the sequential registration device is used to generate an application instance registration number corresponding to the target application according to the registration metadata; receiving the application instance registration number sent by the sequential registration device; obtaining the value of a global counter as a primary key count value; obtaining the time corresponding to the start of the target application as a primary key time identifier; generating a sequential primary key for the target application according to the primary key time identifier, the primary key count value and the application instance registration number. The embodiments of this specification can effectively solve the generation problem of sequential primary keys in ultra-high concurrency scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of distributed application technology, and in particular to a method, device and equipment for generating a temporal primary key. Background Art

[0002] With the advent of the era of the Internet of Everything, the number of IoT access terminals is growing exponentially. In order to quickly judge the status, grasp the trend, and quickly analyze and make decisions, each terminal continuously transmits data to the background. In this way, the QPS (Query Per Second) at a certain moment will develop from hundreds or thousands to tens of thousands, or even tens of millions of QPS, resulting in high-concurrency application scenario characteristics such as high concurrency, high resource dependence, and high time sensitivity, which cannot meet the requirements for generating temporal primary keys in a high-concurrency environment.

[0003] In the prior art, in view of the characteristics of such high-concurrency application scenarios, the following methods are mainly used to generate sequential primary keys: (1) Using the database self-increment sequence to generate sequential primary keys. In this method, each call can automatically accumulate upward to obtain a self-increment primary key. The implementation method is relatively simple, but the performance is poor and cannot meet the requirements for sequential primary key generation in an ultra-high concurrency environment. (2) Using UUID to generate sequential primary keys. UUID is randomly generated by the application based on information such as the current time, counter, and hardware identifier. The sequential primary keys generated in this way are irregular and do not contain sequential features. They cannot reflect the global increasing trend of the sequential primary keys, and thus cannot meet the requirements for sequential primary key generation in an ultra-high concurrency environment. (3) Use middleware to generate time-series primary keys. The middleware is mainly cache middleware, such as redis, ehcache, memcache, etc. This method mainly consumes time on network requests, distributed locks, and request returns. In addition, cache middleware uses host memory to cache data. The performance depends on the writing and transactions of the middleware, which has performance bottlenecks. In addition, as the QPS increases, the hardware cost will also rise sharply, which cannot meet the requirements of time-series primary key generation in ultra-high concurrency environments. It can be seen that the existing technology cannot effectively solve the problem of time-series primary key generation in ultra-high concurrency scenarios.

[0004] Therefore, the industry is in urgent need of a technical solution that can solve the above technical problems. Summary of the invention

[0005] The embodiments of this specification provide a method, apparatus, and device for generating a sequential primary key, which can effectively solve the problem of generating a sequential primary key in an ultra-high concurrency scenario.

[0006] The method, device and equipment for generating a temporal primary key provided in this specification are implemented in the following manner.

[0007] A method for generating a sequential primary key, comprising: being applied to a sequential primary key generator, the method comprising: sending a registration request to a sequential registration device when a target application is started; wherein the registration request includes registration metadata; the sequential registration device is used to generate an application instance registration number corresponding to the target application according to the registration metadata; receiving the application instance registration number sent by the sequential registration device; obtaining a value of a global counter as a primary key count value; obtaining a time corresponding to when the target application is started as a primary key time identifier; and generating a sequential primary key for the target application according to the primary key time identifier, the primary key count value, and the application instance registration number.

[0008] A device for generating a timing primary key, comprising: a sending module, used to send a registration request to a timing registration device when a target application is started; wherein the registration request includes registration metadata; the timing registration device is used to generate an application instance registration number corresponding to the target application according to the registration metadata; a receiving module, used to receive the application instance registration number sent by the timing registration device; a first acquisition module, used to obtain the value of a global counter as a primary key count value; a second acquisition module, used to obtain the time corresponding to the start of the target application as a primary key time identifier; a generation module, used to generate a timing primary key for the target application according to the primary key time identifier, the primary key count value and the application instance registration number.

[0009] A device for generating a temporal primary key comprises at least one processor and a memory storing computer executable instructions, wherein when the processor executes the instructions, the steps of any method embodiment in the embodiments of the specification are implemented.

[0010] A computer-readable storage medium stores computer instructions, which, when executed, implement the steps of any method embodiment in the embodiments of this specification.

[0011] This specification provides a method, device and equipment for generating a timing primary key. In some embodiments, when the target application is started, a registration request including registration metadata can be sent to the timing registration device, so that the timing registration device generates an application instance registration number corresponding to the target application based on the registration metadata and returns it to the timing primary key generator. It is also possible to obtain the value of the global counter as the primary key count value, obtain the time corresponding to the start of the target application as the primary key time identifier, and generate a timing primary key for the target application based on the primary key time identifier, the primary key count value and the application instance registration number. Since the timing primary key is generated through application registration and a single point, it can be deployed in multiple regions, multiple centers, and multiple clusters to meet the needs of timing primary key generation under ultra-high concurrency. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The drawings described herein are used to provide a further understanding of this specification, constitute a part of this specification, and do not constitute a limitation of this specification. In the drawings:

[0013] Figure 1 It is a flowchart of an embodiment of a method for generating a temporal primary key provided in this specification;

[0014] Figure 2 It is a schematic diagram of the module structure of an embodiment of a device for generating a time sequence primary key provided in this specification;

[0015] Figure 3 This is a hardware structure block diagram of an embodiment of a server for generating a sequential primary key provided in this specification. DETAILED DESCRIPTION

[0016] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments in this specification, not all of the embodiments. Based on one or more embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the embodiments of this specification.

[0017] The following is an example of a specific application scenario to illustrate the implementation plan of this specification. Specifically, Figure 1 The flowchart of an embodiment of a method for generating a time sequence primary key provided in this specification is shown in FIG. Although this specification provides method operation steps or device structures as shown in the following embodiments or drawings, the method or device may include more or fewer operation steps or module units after partial combination based on routine or no creative labor.

[0018] An implementation scheme provided in this specification can be applied to a sequential primary key generator. The sequential primary key generator can be deployed in a target application. The target application can run in a client or a server, etc. The client can include a terminal device, such as a smart phone, a tablet computer, etc. The server can include a single computer device, or a server cluster consisting of multiple servers, or a server structure of a distributed system, etc.

[0019] It should be noted that the following embodiment description does not limit the technical solutions in other application scenarios that can be extended based on this specification. Figure 1 As shown, in an embodiment of a method for generating a temporal primary key provided in this specification, the method may include the following steps.

[0020] S0: When the target application is started, a registration request is sent to a timing registration device; wherein the registration request includes registration metadata; the timing registration device is used to generate an application instance registration number corresponding to the target application according to the registration metadata.

[0021] The target application can be a distributed application or other application. The timing registration device can be used to receive the registration metadata of the target application, and use the registration metadata to register and generate an application instance registration number corresponding to the target application. The application instance registration number corresponds to the application instance registration identifier one by one. The application instance registration identifier is globally unique in the timing registration device and can be used to identify each application instance running on a distributed host. Each time an application is opened, it can be understood as an application instance.

[0022] In some implementation scenarios, the time series primary key generator can collect distributed host and application information as registration metadata. In some implementation scenarios, the registration metadata can include the name of the distributed host deployed by the target application, the name of the target application, the physical address of the network card corresponding to the target application outbound call, the IP (Internet Protocol) address, the external service port number of the target application, etc.

[0023] In some implementation scenarios, after receiving the registration request, the timing registration device can perform hash processing on the registration metadata to obtain a first application instance registration identifier; and obtain an application instance registration number corresponding to the target application based on the first application instance registration identifier.

[0024] For example, in some implementation scenarios, the timing primary key generator can send a registration request including registration metadata to the timing registration device. After receiving the registration request, the timing registration device can calculate the hash value of the registration metadata according to a preset hash function, and then use the calculation result as the first application instance registration identifier.

[0025] In some implementation scenarios, after obtaining the application instance registration identifier, the timing registration device can obtain the application instance registration number corresponding to the target application according to the application instance registration identifier.

[0026] In some implementation scenarios, obtaining the application instance registration number corresponding to the target application based on the first application instance registration identifier may include: comparing the first application instance registration identifier with the application instance registration identifiers stored in the database; and if the first application instance registration identifier does not exist in the stored application instance registration identifiers, generating a corresponding application instance registration number for the target application based on the first application instance registration identifier.

[0027] In some implementation scenarios, after comparing the first application instance registration identifier with the application instance registration identifiers stored in the database, it may also include: if the first application instance registration identifier exists in the stored application instance registration identifiers, obtaining a second application instance registration identifier that is the same as the first application instance registration identifier; and using the application instance registration number corresponding to the second application instance registration identifier as the application instance registration number corresponding to the target application.

[0028] For example, in some implementation scenarios, after the timing registration device obtains the first application instance registration identifier, it can be compared with the application instance registration identifier stored in the database corresponding to the timing registration device. If it does not exist in the database, an application instance registration number can be generated based on the first application instance registration identifier; if it exists in the database, the originally generated application instance registration number can be directly returned.

[0029] It should be noted that "first" and "second" are only used to distinguish the application instance registration identifiers and have no special meaning.

[0030] In some implementation scenarios, after the application instance registration number corresponding to the second application instance registration identifier is used as the application instance registration number corresponding to the target application, the registration time of the application instance registration number corresponding to the second application instance registration identifier may also be updated.

[0031] In some implementation scenarios, after the application instance registration number corresponding to the second application instance registration identifier is used as the application instance registration number corresponding to the target application, the application instance registration number may be returned to the temporal primary key generator.

[0032] S2: Receive the application instance registration number sent by the timing registration device.

[0033] In some implementation scenarios, after the time series registration device generates the application instance registration number corresponding to the target application according to the registration metadata, the application instance registration number can be returned to the time series primary key generator.

[0034] In some implementation scenarios, after receiving the application instance registration number, the temporal primary key generator may store it as a global static variable within the scope of the application instance, for global use by the application instance and valid within the scope of the application instance.

[0035] In some implementation scenarios, the application instance registration number may be a decimal value of a first preset number of digits, wherein the first preset number of digits is at most 6.

[0036] For example, in some implementation scenarios, the minimum value of the application instance registration number can be 0, the maximum value can be 62 cubed, that is, 238328, and the maximum length is 6 digits to obtain a decimal value. In this way, the global system can accommodate 238,329 application running instances for registration. Of course, the above is only an exemplary description, and the application instance registration number is not limited to the above examples. Technicians in the relevant field may make other changes under the inspiration of the technical essence of this application, but as long as the functions and effects achieved are the same or similar to those of this application, they should be covered within the scope of protection of this application.

[0037] S4: Get the value of the global counter as the primary key count value.

[0038] In some implementation scenarios, after receiving the application instance registration number sent by the timing registration device, the timing primary key generator can obtain the value of the global counter as the primary key count value.

[0039] In some implementation scenarios, before obtaining the value of the global counter as the primary key count value, the process may include: establishing a global counter within the target application instance. The global counter may be used to accumulate the number of time-series primary keys generated within the target application instance at a preset time granularity. The preset time granularity may be set according to the actual scenario, for example, milliseconds, seconds, etc., which is not limited in this specification.

[0040] In some implementation scenarios, the primary key count value may be a decimal value of a second preset number of digits, wherein the second preset number of digits may be 10 at most.

[0041] For example, in some implementation scenarios, the time series primary key generator can establish a global counter within the scope of the running application instance to accumulate the number of time series primary keys generated within a certain time granularity within the scope of the application instance. The counter starts at 0 and accumulates by 1 for each time a time series primary key is generated. The maximum accumulated value is 2. 31 -1, that is, 2147483647. After reaching the maximum cumulative value, the counter can be reset to 0, and then start accumulating from 0 again in the next time granularity. Each accumulation can return the primary key count value of a certain time granularity within the scope of an application instance. The global counter is valid within the scope of the application running instance.

[0042] In some implementation scenarios, the global counter can support multi-threaded concurrency through a synchronous lock mechanism. In this way, each request initiated by the terminal to the application instance will generate a response thread. Before accumulation, the thread can obtain the lock of an object, and after accumulation, the lock can be released. In addition, in order to improve the response efficiency, the response thread of other terminals can adopt an unfair lock mechanism. In this way, waiting for a locked object counter to complete accumulation before competition can ensure that the accumulated value returned at a certain time granularity within the scope of the application instance is unique.

[0043] S6: Obtain the time corresponding to the start of the target application as a primary key time identifier.

[0044] In some implementation scenarios, after obtaining the value of the global counter as the primary key count value, the time corresponding to the start of the target application can be obtained as the primary key time identifier. Of course, the time corresponding to the start of the target application can be obtained when the target application is started, when the value of the global counter is obtained, or at other times. In the embodiments of this specification, obtaining the time corresponding to the start of the target application after obtaining the value of the global counter is only for exemplary explanation and does not constitute a limitation on other application scenarios of this specification.

[0045] In some implementation scenarios, obtaining the time corresponding to the start of the target application as the primary key time identifier may include: converting the obtained time into a decimal value of a third preset number of digits; and using the decimal value of the third preset number of digits as the primary key time identifier. The third preset number of digits may be 13.

[0046] For example, in some implementation scenarios, the timing primary key generator can collect the host time corresponding to the startup of the distributed application at a time granularity of microseconds, and then convert the time into a 13-digit decimal value, and use the obtained 13-digit value as the primary key time identifier.

[0047] S8: Generate a temporal primary key for the target application according to the primary key time identifier, the primary key count value and the application instance registration number.

[0048] In some implementation scenarios, after obtaining the primary key timestamp, primary key count value and application instance registration number, a temporal primary key can be generated for the target application based on the primary key timestamp, primary key count value and application instance registration number.

[0049] In some implementation scenarios, generating a temporal primary key for the target application based on the primary key timestamp, the primary key count value and the application instance registration number may include: concatenating the primary key timestamp, the primary key count value and the application instance registration number to obtain the temporal primary key corresponding to the target application.

[0050] For example, in some implementation scenarios, through the above steps, three groups of decimal values ​​can be obtained: (1) application instance registration number, a maximum of 6 decimal digits; (2) primary key count value, a maximum of 10 decimal digits; (3) primary key time identifier, a 13-digit decimal value. Furthermore, the above three groups of decimal values ​​can be concatenated in the order of primary key time identifier, primary key count value and application instance registration number to generate a sequential primary key corresponding to the target application. In this way, the generated sequential primary key can be globally unique in the distributed database.

[0051] Since the length of the temporal primary key obtained by the above method cannot be guaranteed to be consistent, in some implementation scenarios, the three groups of decimal values ​​obtained above are further processed so that the temporal primary key finally obtained can meet the requirements of the distributed database primary key. Among them, the requirements of the distributed database primary key may include: (1) the primary key is text; (2) the primary key length is consistent; (3) the primary key index is efficient and requires less storage space.

[0052] In some implementation scenarios, before concatenating the primary key time identifier, the primary key count value, and the application instance registration number, the method may also include: connecting numbers, uppercase letters, and lowercase letters in a preset order to obtain a first character string; based on the first character string, converting the primary key time identifier, the primary key count value, and the application instance registration number, respectively, to obtain a target primary key time identifier, a target primary key count value, and a target application instance registration number; and concatenating the target primary key time identifier, the target primary key count value, and the target application instance registration number to obtain a sequential primary key corresponding to the target application.

[0053] In some implementation scenarios, the preset order may be an order in the ASCII code table, such as the ordering rules of numbers, uppercase letters, and lowercase letters in the ASCII code table are shown in Table 1:

[0054] Table 1

[0055] 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z

[0056] In some implementation scenarios, 62 characters of numbers, uppercase letters, and lowercase letters can be connected in the order of the ASCII code table to form a string of 62 characters (i.e., the first string). Further, the string of 62 characters can be used to replace the decimal number to obtain the sixty-binary system.

[0057] In some implementation scenarios, integer division may be used to convert the obtained decimal values ​​of the primary key time identifier, primary key count value, and application instance registration number into sixty-digit binary text.

[0058] In some implementation scenarios, the length of the target primary key time identifier may be 7; the length of the target primary key count value may be 6; and the length of the target application instance registration number may be 3.

[0059] For example, in some implementation scenarios, the decimal value of the application instance registration number can be converted into a 3-digit sixty-binary number. If it is less than 3 digits, it can be padded on the left with 0; the decimal value of the primary key count value can be converted into a 6-digit sixty-binary number. If it is less than 6 digits, it can be padded on the left with 0; the decimal number of the primary key time identifier can be converted into a 7-digit sixty-binary number. Furthermore, the obtained 7-digit, 6-digit, and 3-digit sixty-binary fixed-length texts can be sequentially connected to obtain a 16-digit text as the target time series primary key.

[0060] Of course, the above is only an exemplary explanation, and the preset order is not limited to the above examples. Technical personnel in the relevant field may make other changes inspired by the technical essence of this application, but as long as the functions and effects achieved are the same or similar to those of this application, they should be covered within the scope of protection of this application.

[0061] In some implementation scenarios, after the timing primary key generator generates the timing primary key for the target application, it can also periodically send heartbeat information to the timing registration device, so that the timing registration device refreshes the update time of the application running instance identifier according to the heartbeat information. Wherein, the application running instance identifier corresponds to the application instance registration number.

[0062] For example, in some implementation scenarios, the time sequence primary key generator may initiate a heartbeat request to the time sequence registration device every 10 minutes, wherein the heartbeat request may indicate the working status of the time sequence primary key generator to the time sequence registration device.

[0063] In some implementation scenarios, the timing registration device may include a heartbeat information processing unit and a storage unit. The heartbeat information processing unit may be used to process the heartbeat information sent by the timing primary key generator, and each time the heartbeat information is received, the update time of the application running instance identifier in the storage unit may be refreshed. The storage unit may be used to store metadata registration data, application running instance identifier, application instance registration number, heartbeat record, etc.

[0064] In some implementation scenarios, a filter interceptor can also be deployed in the distributed host to intercept front-end requests to ensure the normal operation of the service. For example, in some implementation scenarios, after the distributed application is started, the timing primary key generator can apply for registration with the timing registration device. After successful registration, the application instance registration number can be obtained, the timing primary key generator works normally, the filter interceptor is released, and the distributed application provides services to the outside normally. If the registration is unsuccessful and the application instance registration number is not obtained, the timing primary key generator cannot work normally. At this time, the filter interceptor intervenes and returns a 500 exception representing an internal server error for identification by devices such as the load balancer. The load balancer will take the application offline, so that the application cannot provide services to the outside.

[0065] In some implementation scenarios, an application startup interceptor can be used. Specifically, during the application startup process, the timing primary key generator can apply for registration with the timing registration device. After successful registration, the application instance registration number can be obtained, and the application can be started normally. If the registration is unsuccessful and the application instance registration number is not obtained, the interceptor intervenes and throws a startup exception. At this time, the application cannot be started normally.

[0066] In the embodiment of this specification, the time sequence primary key generator is used to apply for registration with the time sequence registration device, so that each time sequence primary key generator is not repeated. Since the time sequence registration device can be run on a certain host or deployed in a distributed manner, cross-regional and cross-center registration can be achieved, and a large amount of data synchronization is not required for the cache middleware.

[0067] In the embodiments of this specification, since the global counter works within the scope of a single application instance, it can ensure that the count value within a certain time granularity is not repeated. Since the global counter is based on the maximum computing power of the application server, the maximum count value cannot be calculated within the unit time granularity, and the counter cannot be reset to 0 to generate a new round of iterations. In this way, time dialback caused by host time synchronization will not cause primary key duplication, thereby achieving maximum fault tolerance.

[0068] In the embodiments of this specification, because the time series primary key is generated based on a single application instance, a single running instance can generate multiple primary keys (e.g., 10 million) per second. In this way, horizontal expansion can be achieved through distributed application deployment, and the maximum number of primary keys can reach hundreds of millions (e.g., 238.32 billion), thereby meeting the generation requirements of the time series primary key in extreme high-concurrency situations and ensuring that the time series primary key is globally unique.

[0069] The embodiments of this specification can be deployed in multiple regions, multiple centers, and multiple clusters through application registration and single-point generation, meeting the needs of generating time-series primary keys under ultra-high concurrency.

[0070] In the embodiments of this specification, the primary key time identifier, the primary key count value, and the application instance registration number are compressed in sequence through sixty-bit binary conversion and connected into a 16-bit fixed-length sequential primary key, which is ordered as a whole and globally unique, thereby solving the problems of inefficiency of traditional methods and high cost of existing mainstream solutions and improving the throughput capacity of distributed clusters.

[0071] The embodiments of this specification can not only solve the problems of data synchronization between hosts in distributed cache, but also solve the problems of cross-regional delay, high bandwidth cost, time call back, etc. as QPS increases.

[0072] Of course, the above is only an exemplary description, and the embodiments of this specification are not limited to the above examples. Technical personnel in the relevant field may make other changes based on the technical essence of this application. However, as long as the functions and effects achieved are the same or similar to those of this application, they should be included in the scope of protection of this application.

[0073] From the above description, it can be seen that the embodiment of the present application can send a registration request including registration metadata to the timing registration device when the target application is started, so that the timing registration device generates an application instance registration number corresponding to the target application based on the registration metadata and returns it to the timing primary key generator. It is also possible to obtain the value of the global counter as the primary key count value, obtain the time corresponding to the start of the target application as the primary key time identifier, and generate a timing primary key for the target application based on the primary key time identifier, the primary key count value, and the application instance registration number. Since the timing primary key is generated through application registration and a single point, it can be deployed in multiple regions, multiple centers, and multiple clusters to meet the timing primary key generation requirements under ultra-high concurrency.

[0074] In this specification, each embodiment of the above method is described in a progressive manner, and the same or similar parts between the embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments. For relevant parts, refer to the partial description of the method embodiment.

[0075] Based on the above-mentioned method for generating a time-series primary key, one or more embodiments of this specification also provide a device for generating a time-series primary key. The device may include a system (including a distributed system), software (application), module, component, server, client, etc. using the method described in the embodiment of this specification and a device combined with necessary implementation hardware. Based on the same innovative concept, the device in one or more embodiments provided in the embodiment of this specification is as described in the following embodiments. Since the implementation scheme and method of the device to solve the problem are similar, the implementation of the specific device in the embodiment of this specification can refer to the implementation of the aforementioned method, and the repetitions will not be repeated. As used below, the term "unit" or "module" can implement a combination of software and / or hardware of predetermined functions. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.

[0076] Specifically, Figure 2 is a schematic diagram of a module structure of an embodiment of a device for generating a time sequence primary key provided in this specification, such as Figure 2 As shown, a device for generating a temporal primary key provided in this specification may include: a sending module 120 , a receiving module 122 , a first obtaining module 124 , a second obtaining module 126 , and a generating module 128 .

[0077] The sending module 120 may be used to send a registration request to a timing registration device when the target application is started; wherein the registration request includes registration metadata; the timing registration device is used to generate an application instance registration number corresponding to the target application according to the registration metadata;

[0078] The receiving module 122 may be used to receive the application instance registration number sent by the timing registration device;

[0079] A first acquisition module 124 may be used to acquire a value of a global counter as a primary key count value;

[0080] The second acquisition module 126 may be used to acquire the time corresponding to the start of the target application as a primary key time identifier;

[0081] The generating module 128 may be configured to generate a temporal primary key for the target application according to the primary key time identifier, the primary key count value, and the application instance registration number.

[0082] The registration metadata may include the name of the distributed host deployed by the target application, the name of the target application, the physical address of the network card corresponding to the outbound call of the target application, the IP address, and the external service port number of the target application.

[0083] In some implementation scenarios, after receiving the registration request, the timing registration device may include:

[0084] A processing unit may be used to perform hash processing on the registration metadata to obtain a first application instance registration identifier;

[0085] The obtaining unit may be configured to obtain the application instance registration number corresponding to the target application according to the first application instance registration identifier.

[0086] In some implementation scenarios, the obtaining unit may include:

[0087] The comparison unit may be used to compare the first application instance registration identifier with the application instance registration identifiers stored in the database;

[0088] The first generating unit may be configured to generate a corresponding application instance registration number for a target application according to the first application instance registration identifier when the first application instance registration identifier does not exist in the stored application instance registration identifiers.

[0089] In some implementation scenarios, the obtaining unit may further include:

[0090] The first acquisition unit may be configured to acquire a second application instance registration identifier that is identical to the first application instance registration identifier when the first application instance registration identifier exists in the stored application instance registration identifiers;

[0091] The second generating unit may be configured to use the application instance registration number corresponding to the second application instance registration identifier as the application instance registration number corresponding to the target application.

[0092] In some implementation scenarios, after the application instance registration number corresponding to the second application instance registration identifier is used as the application instance registration number corresponding to the target application, the following may also be included:

[0093] The updating unit may be configured to update the registration time of the application instance registration number corresponding to the second application instance registration identifier.

[0094] In some implementation scenarios, before obtaining the value of the global counter as the primary key count value, the following steps may be included:

[0095] The establishing unit can be used to establish a global counter within the scope of the target application instance; wherein the global counter is used to accumulate the number of time series primary keys generated at a preset time granularity within the scope of the target application instance.

[0096] In some implementation scenarios, the application instance registration number can be a decimal value of a first preset number of digits; the primary key count value can be a decimal value of a second preset number of digits; wherein the maximum number of the first preset number of digits can be 6, and the maximum number of the second preset number of digits can be 10.

[0097] In some implementation scenarios, the second acquisition module 126 may include:

[0098] A conversion unit, which can be used to convert the acquired time into a decimal value of a third preset digit;

[0099] The second acquisition unit may be configured to use a decimal value of a third preset number of digits as a primary key time identifier.

[0100] In some implementation scenarios, the generating module 128 may include:

[0101] The first concatenation unit may be used to concatenate the primary key time identifier, the primary key count value, and the application instance registration number to obtain a temporal primary key corresponding to a target application.

[0102] In some implementation scenarios, before concatenating the primary key time identifier, the primary key count value, and the application instance registration number, the following steps may also be performed:

[0103] A connection unit may be used to connect numbers, uppercase letters, and lowercase letters in a preset order to obtain a first character string;

[0104] A conversion unit may be used to convert the primary key time identifier, the primary key count value and the application instance registration number based on the first character string to obtain a target primary key time identifier, a target primary key count value and a target application instance registration number;

[0105] The second concatenation unit may be used to concatenate the target primary key time identifier, the target primary key count value, and the target application instance registration number to obtain a temporal primary key corresponding to the target application.

[0106] In some implementation scenarios, the length of the target primary key time identifier may be 7; the length of the target primary key count value may be 6; and the length of the target application instance registration number may be 3.

[0107] Some implementation scenarios may also include:

[0108] The sending unit can be used to periodically send heartbeat information to the timing registration device, so that the timing registration device refreshes the update time of the application running instance identifier according to the heartbeat information; wherein the application running instance identifier corresponds to the application instance registration number.

[0109] It should be noted that the above-mentioned device may also include other implementation modes according to the description of the method embodiment. The specific implementation mode may refer to the description of the relevant method embodiment, which will not be described one by one here.

[0110] The present specification also provides an embodiment of a device for generating a timing primary key, comprising a processor and a memory for storing processor executable instructions, wherein the instructions, when executed by the processor, implement the following steps: when a target application is started, sending a registration request to a timing registration device; wherein the registration request includes registration metadata; the timing registration device is used to generate an application instance registration number corresponding to the target application according to the registration metadata; receiving the application instance registration number sent by the timing registration device; obtaining the value of a global counter as a primary key count value; obtaining the time corresponding to the start of the target application as a primary key time identifier; and generating a timing primary key for the target application according to the primary key time identifier, the primary key count value, and the application instance registration number.

[0111] It should be noted that the above-mentioned device may also include other implementations according to the description of the method or device embodiment. The specific implementation methods can refer to the description of the relevant method embodiments, which will not be described one by one here.

[0112] The method embodiments provided in this specification can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Taking running on a server as an example, Figure 31 is a hardware structure block diagram of an embodiment of a server for generating a sequential primary key provided in this specification. The server may be the apparatus for generating a sequential primary key or the device for generating a sequential primary key in the above embodiment. Figure 3 As shown, the server 10 may include one or more (only one is shown in the figure) processors 100 (the processor 100 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 200 for storing data, and a transmission module 300 for communication functions. A person skilled in the art can understand that Figure 3 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 3 More or fewer components shown in the figure may also include other processing hardware, such as a database or multi-level cache, GPU, or other hardware with Figure 3 Different configurations are shown.

[0113] The memory 200 can be used to store software programs and modules of application software, such as the program instructions / modules corresponding to the method for generating a timing master key in the embodiment of this specification. The processor 100 executes various functional applications and data processing by running the software programs and modules stored in the memory 200. The memory 200 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 200 may further include a memory remotely arranged relative to the processor 100, and these remote memories may be connected to a computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0114] The transmission module 300 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of a computer terminal. In one example, the transmission module 300 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission module 300 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0115] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0116] The methods or devices described in the above embodiments provided in this specification can implement business logic through computer programs and record them on storage media, and the storage media can be read and executed by computers to achieve the effects of the solutions described in the embodiments of this specification. The storage medium may include a physical device for storing information, which is usually to digitize the information and then store it in a medium using electrical, magnetic or optical methods. The storage medium may include: devices that use electrical energy to store information, such as various types of memories, such as RAM, ROM, etc.; devices that use magnetic energy to store information, such as hard disks, floppy disks, magnetic tapes, magnetic core memories, bubble memories, and U disks; devices that use optical methods to store information, such as CDs or DVDs. Of course, there are other types of readable storage media, such as quantum memories, graphene memories, and so on.

[0117] The above-mentioned method or device embodiment for generating a timing master key provided in this specification can be implemented by a processor in a computer executing corresponding program instructions, such as using the C++ language of the Windows operating system to implement it on a PC, on a Linux system, or other implementations such as using the Android or iOS system programming language to implement it on a smart terminal, as well as based on the processing logic of a quantum computer.

[0118] It should be noted that the devices, equipment, and systems described in the specification may also include other implementation methods according to the description of the relevant method embodiments. The specific implementation methods can refer to the description of the corresponding method embodiments, which will not be described one by one here.

[0119] Each embodiment in this application is described in a progressive manner, and the same or similar parts between the embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the hardware + program embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0120] For the convenience of description, the above devices are described in various modules according to their functions. Of course, when implementing one or more of the present specification, the functions of some modules can be implemented in the same or more software and / or hardware, and the modules that implement the same function can also be implemented by a combination of multiple sub-modules or sub-units.

[0121] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices, equipment, and systems according to the embodiments of the present invention. It should be understood that it can be implemented by computer program instructions, and these computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the specified function. These computer program instructions can also be stored in a computer-readable memory that can guide the computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, and the instruction device is implemented in the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0122] Those skilled in the art will appreciate that one or more embodiments of the present specification may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present specification may be provided in the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware.

[0123] The above is only an example of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. For those skilled in the art, one or more embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this application should be included in the scope of the claims.

Claims

1. A method for generating a temporal primary key, characterized in that: Applied to a time series primary key generator, the method includes: When the target application is started, a registration request is sent to a timing registration device; wherein the registration request includes registration metadata; the timing registration device is used to generate an application instance registration number corresponding to the target application according to the registration metadata, wherein the application instance registration number corresponds to the application instance registration identifier one by one, and the application instance registration identifier is globally unique in the timing registration device and is used to identify each application instance running on the distributed host, wherein each time the application is opened is understood as an application instance; Receiving the application instance registration number sent by the timing registration device; Get the value of the global counter as the primary key count value; Obtaining the time corresponding to when the target application is started as a primary key time identifier; Generate a temporal primary key for the target application according to the primary key time identifier, the primary key count value and the application instance registration number; The registration metadata includes the name of the distributed host deployed by the target application, the name of the target application, the physical address of the network card corresponding to the outbound call of the target application, the IP address, and the external service port number of the target application.

2. The method according to claim 1, characterized in that After receiving the registration request, the timing registration device includes: Performing hash processing on the registration metadata to obtain a first application instance registration identifier; According to the first application instance registration identifier, an application instance registration number corresponding to the target application is obtained.

3. The method according to claim 2, characterized in that The obtaining, according to the first application instance registration identifier, an application instance registration number corresponding to the target application includes: Compare the first application instance registration identifier with the application instance registration identifiers stored in the database; When the first application instance registration identifier does not exist in the stored application instance registration identifiers, a corresponding application instance registration number is generated for the target application according to the first application instance registration identifier.

4. The method according to claim 3, characterized in that Also includes: When the first application instance registration identifier exists in the stored application instance registration identifiers, obtaining a second application instance registration identifier that is the same as the first application instance registration identifier; The application instance registration number corresponding to the second application instance registration identifier is used as the application instance registration number corresponding to the target application.

5. The method according to claim 4, characterized in that After the application instance registration number corresponding to the second application instance registration identifier is used as the application instance registration number corresponding to the target application, the method further includes: The registration time of the application instance registration number corresponding to the second application instance registration identifier is updated.

6. The method according to claim 1, characterized in that Before obtaining the value of the global counter as the primary key count value, the method includes: A global counter is established within the scope of the target application instance; wherein the global counter is used to accumulate the number of time series primary keys generated at a preset time granularity within the scope of the target application instance.

7. The method according to claim 1, characterized in that The application instance registration number is a decimal value of a first preset number of digits; the primary key count value is a decimal value of a second preset number of digits; wherein the maximum number of the first preset number of digits is 6, and the maximum number of the second preset number of digits is 10.

8. The method according to claim 1, characterized in that The step of obtaining the time corresponding to the start of the target application as a primary key time identifier includes: Convert the acquired time into a decimal value of a third preset digit; The decimal value of the third preset digit is used as the primary key time identifier.

9. The method according to claim 1, characterized in that: The generating a temporal primary key for the target application according to the primary key time identifier, the primary key count value and the application instance registration number includes: The primary key time identifier, the primary key count value and the application instance registration number are concatenated to obtain a temporal primary key corresponding to the target application.

10. The method according to claim 9, characterized in that Before the primary key time identifier, the primary key count value and the application instance registration number are concatenated, the method further includes: Connect numbers, uppercase letters, and lowercase letters in a preset order to obtain a first string; Based on the first character string, the primary key time identifier, the primary key count value and the application instance registration number are respectively converted to obtain a target primary key time identifier, a target primary key count value and a target application instance registration number; The target primary key time identifier, the target primary key count value and the target application instance registration number are concatenated to obtain a temporal primary key corresponding to the target application.

11. The method according to claim 10, characterized in that The length of the target primary key time identifier is 7; the length of the target primary key count value is 6; and the length of the target application instance registration number is 3.

12. The method according to claim 1, characterized in that Also includes: Heartbeat information is periodically sent to the timing registration device, so that the timing registration device refreshes the update time of the application running instance identifier according to the heartbeat information; wherein the application running instance identifier corresponds to the application instance registration number.

13. A device for generating a temporal primary key, characterized in that: include: A sending module, used for sending a registration request to a timing registration device when a target application is started; wherein the registration request includes registration metadata; the timing registration device is used for generating an application instance registration number corresponding to the target application according to the registration metadata, wherein the application instance registration number corresponds to the application instance registration identifier one by one, and the application instance registration identifier is globally unique in the timing registration device and is used to identify each application instance running on a distributed host, wherein each time an application is opened is understood as an application instance; A receiving module, used for receiving the application instance registration number sent by the timing registration device; A first acquisition module is used to obtain a value of a global counter as a primary key count value; A second acquisition module is used to obtain the time corresponding to the start of the target application as a primary key time identifier; A generating module, configured to generate a temporal primary key for the target application according to the primary key time identifier, the primary key count value and the application instance registration number; The registration metadata includes the name of the distributed host deployed by the target application, the name of the target application, the physical address of the network card corresponding to the outbound call of the target application, the IP address, and the external service port number of the target application.

14. A device for generating a temporal primary key, characterized in that: The method comprises at least one processor and a memory storing computer executable instructions, wherein the processor implements the steps of the method according to any one of claims 1 to 12 when executing the instructions.

15. A computer-readable storage medium, characterized in that: Computer instructions are stored thereon, and when the instructions are executed, the steps of the method according to any one of claims 1 to 12 are implemented.

Citation Information

Patent Citations

  • Distributed database main key generation method and apparatus

    CN108241715A

  • Database primary key id generation method, device and equipment, and storage medium

    CN112632071A