Identifier generation method and device

The globally unique and self-increasing identifier based on the index value is generated through program control, which solves the single point of failure and low efficiency problems of identifier generation in the existing technology, realizes efficient and low-space identifier generation and transmission, and ensures Thread safety.

CN110109912BActive Publication Date: 2024-09-20BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN201810034687.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-01-15
Publication Date
2024-09-20
Estimated Expiration
2038-01-15

AI Technical Summary

Technical Problem

In the existing technology, identifiers generated using the auto-incrementing ID method have problems such as single points of failure and difficulty in expansion. The identifiers generated using the UUID method are disordered and have low query efficiency, large storage space, and large amounts of data to be transmitted.

Method used

A globally unique and self-increasing identifier is generated through program control. Based on the numerical form generated by the index value, the mapping table of the memory and database is used to obtain and update the index value, ensuring high query efficiency, small storage space, and small amount of data transmission, and through Guava and Atomic ensure thread safety.

Benefits of technology

It realizes the generation of globally unique and self-increasing identifiers, avoids single points of failure and expansion problems caused by database generation, improves query efficiency and storage space utilization, and ensures the uniqueness and thread safety of identifiers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110109912B
    Figure CN110109912B
Patent Text Reader

Abstract

The present invention discloses an identifier generation method and device, and relates to the field of computer technology. A specific implementation of the method includes: using the name in the identifier acquisition request as a key, obtaining the value corresponding to the key from the mapping in the memory; wherein the value includes a starting index value and an ending index value; if the number of indexes in the identifier acquisition request is less than or equal to the difference between the ending index value and the starting index value, then updating the starting index value according to the number of indexes; assembling the acquired starting index value and the updated starting index value to obtain an identifier. This implementation uses program control to generate a globally unique and self-incrementing identifier, which is easy to expand; the identifier generated based on the index value is in numerical form, with high query efficiency, small storage space occupation, and small amount of data transmission.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a method and device for generating an identifier. Background Art

[0002] In the Internet industry, it is sometimes necessary to concurrently obtain unique self-incrementing identifiers (IDs) between several systems to meet business needs, and it is also necessary to count the situations in which each system obtains identifiers. In the prior art, a unique identifier can be generated using a database's self-incrementing ID or a universally unique identifier (UUID). Identifiers generated using the self-incrementing ID method are self-incrementing, and identifiers generated using the UUID method are easy to expand.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] (1) Using the auto-increment ID method to generate identifiers requires additional processing during database migration because different databases have different syntaxes. Only the primary database can generate auto-increment IDs, which is prone to single point failures. It relies on database resources and is difficult to expand.

[0005] (2) The identifiers generated by using UUID are disordered and cannot maintain an increasing trend; the generated identifiers are stored in the form of strings, which has low query efficiency, occupies a large storage space, and transmits a large amount of data. Summary of the invention

[0006] In view of this, an embodiment of the present invention provides an identifier generation method and device, which uses program control to generate a globally unique and self-incrementing identifier for easy expansion; the identifier generated based on the index value is in numerical form, has high query efficiency, occupies little storage space, and transmits a small amount of data.

[0007] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for generating an identifier is provided.

[0008] An identifier generation method according to an embodiment of the present invention includes: using the name in the identifier acquisition request as a key, obtaining the value corresponding to the key from a mapping in memory; wherein the value includes a starting index value and an ending index value; if the number of indexes in the identifier acquisition request is less than or equal to the difference between the ending index value and the starting index value, updating the starting index value according to the number of indexes; assembling the acquired starting index value and the updated starting index value to obtain an identifier.

[0009] Optionally, after the step of obtaining the value corresponding to the key from the mapping in the memory and before the step of assembling the obtained starting index value and the updated starting index value, it also includes: if the number of indexes is greater than the difference, obtaining the current index value from the database; updating the starting index value according to the number of indexes, and updating the ending index value according to the memory capacity; wherein the memory capacity is the number of indexes added in the memory after obtaining the current index value.

[0010] Optionally, updating the starting index value according to the number of indexes includes: taking the sum of the starting index value and the number of indexes as the updated starting index value; updating the ending index value according to the memory capacity includes: taking the sum of the ending index value and the memory capacity as the updated ending index value.

[0011] Optionally, after the step of obtaining the value corresponding to the key from the mapping in the memory and before the step of obtaining the value if the number of indexes in the identifier acquisition request is less than or equal to the difference between the ending index value and the starting index value, it also includes: if the value corresponding to the key is not obtained, obtaining the current index value from the database; using the current index value as the starting index value, and the sum of the current index value and the memory capacity as the ending index value, and storing them in the mapping; obtaining the starting index value and the ending index value corresponding to the key from the mapping.

[0012] Optionally, obtaining the current index value from the database includes: obtaining the current index value from the database using Guava and Atomic.

[0013] To achieve the above objective, according to one aspect of an embodiment of the present invention, a device for generating an identifier is provided.

[0014] An identifier generation device according to an embodiment of the present invention includes: an acquisition module, which is used to use the name in the identifier acquisition request as a key to obtain the value corresponding to the key from the mapping in the memory; wherein the value includes a starting index value and an ending index value; a first update module, which is used to update the starting index value according to the number of indexes if the number of indexes in the identifier acquisition request is less than or equal to the difference between the ending index value and the starting index value; and an assembling module, which is used to assemble the acquired starting index value and the updated starting index value to obtain an identifier.

[0015] Optionally, the device also includes: a second update module, used to obtain the current index value from the database if the number of indexes is greater than the difference; and update the starting index value according to the number of indexes, and update the ending index value according to the memory capacity; wherein the memory capacity is the number of indexes added to the memory after obtaining the current index value.

[0016] Optionally, the first update module is further used to: use the sum of the starting index value and the number of indexes as the updated starting index value; the second update module is further used to: use the sum of the ending index value and the memory capacity as the updated ending index value.

[0017] Optionally, the device also includes: an index value acquisition module, which is used to obtain the current index value from the database if the value corresponding to the key is not obtained; use the current index value as the starting index value, and use the sum of the current index value and the memory capacity as the ending index value, and store them in the mapping; and obtain the starting index value and the ending index value corresponding to the key from the mapping.

[0018] Optionally, the index value acquisition module is further used to: use Guava and Atomic to obtain the current index value from the database.

[0019] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.

[0020] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement an identifier generation method according to an embodiment of the present invention.

[0021] To achieve the above objective, according to another aspect of the embodiments of the present invention, a computer readable medium is provided.

[0022] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, an identifier generation method according to an embodiment of the present invention is implemented.

[0023] An embodiment of the above invention has the following advantages or beneficial effects: a globally unique and self-incrementing identifier is generated by program control instead of by a database, which is convenient for expansion; the identifier generated based on the index value is in numerical form, with high query efficiency, small storage space occupation, and small amount of data transmission; the source of the identifier is unified as the server, and each application can concurrently request the identifier from the same server. The current index value stored in the server database can be used to obtain the identifier acquisition status of each system, which is convenient for statistical analysis; Guava (an open source JAVA library, including the core library used by Google in many projects, which facilitates coding and reduces coding errors, and provides practical methods for collections, caching, supporting primitives, concurrency, common annotations, string processing, input / output (I / O) and verification) and Atomic (atomic operation, which means that it cannot be divided into several parts. If a piece of code is considered to be Atomic, it means that this piece of code cannot be interrupted during execution) is used to obtain the current index value from the database, ensuring thread safety and the uniqueness of the generated identifier.

[0024] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0026] Figure 1 is a schematic diagram of main steps of a method for generating an identifier according to an embodiment of the present invention;

[0027] Figure 2 is a schematic diagram of the main flow of the identifier generation method according to an embodiment of the present invention;

[0028] Figure 3 is a schematic diagram of main modules of an identifier generating device according to an embodiment of the present invention;

[0029] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0030] Figure 5 It is a schematic diagram of the structure of a computer device suitable for implementing the electronic device of the embodiment of the present invention. DETAILED DESCRIPTION

[0031] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0032] Figure 1 FIG. 1 is a schematic diagram of the main steps of the identifier generation method according to an embodiment of the present invention. Figure 1 As shown, the identifier generation method of the embodiment of the present invention mainly includes the following steps:

[0033] Step S101: Using the name in the identifier acquisition request as a key, obtain the value corresponding to the key from the mapping in the memory; wherein the value includes a start index value and an end index value. The client sends an identifier acquisition request to the server, and the identifier acquisition request includes a name and the number of indexes. The key of the mapping is the name in the identifier acquisition request, and the value is the start index value and the end index value obtained from the database. After receiving the identifier acquisition request, the server obtains the value corresponding to the name from the mapping.

[0034] Step S102: If the number of indexes in the identifier acquisition request is less than or equal to the difference between the end index value and the start index value, the start index value is updated according to the number of indexes. The number of indexes in the identifier acquisition request is compared with the difference between the end index value and the start index value, and if the number of indexes is less than or equal to the difference, the start index value is updated to the sum of the start index value and the number of indexes.

[0035] Step S103: Assemble the obtained starting index value and the updated starting index value to obtain an identifier. According to the needs of the client, assemble the obtained starting index value and the updated starting index value to obtain an identifier, and send the identifier to the client. For example, if the obtained starting index value is 1 and the number of indexes is 10, then the updated starting index value is 11, and the assembled number is a number between [1,11).

[0036] Figure 2 FIG. 1 is a schematic diagram of the main flow of the identifier generation method according to an embodiment of the present invention. Figure 2 As shown, the identifier generation method of the embodiment of the present invention is implemented by the server, and mainly includes the following steps:

[0037] Step S201: After receiving the identifier acquisition request from the client, determine whether the number of indexes in the identifier acquisition request is greater than the preset maximum number of indexes that can be obtained. If it is less than or equal to, execute step S202; if it is greater, end this process. The client sends an identifier acquisition request to the server, and the identifier acquisition request includes a name and the number of indexes; the name is user-defined and can be English + numbers, such as an English name + date. For example, if the number of indexes in the identifier acquisition request is 15, if the maximum number of indexes that can be obtained is 20, execute step S202; if the maximum number of indexes that can be obtained is 10, end this process.

[0038] Step S202: Take out the mapping from the memory, use the name as the key, and obtain the value corresponding to the key in the mapping. The key of the mapping is the name, and the value is the starting index value and the ending index value. The mapping in the memory stores the starting index value and the ending index value obtained from the database. When the server receives the identifier acquisition request, it will first obtain the value corresponding to the key in the memory. When the number of indexes is greater than the number of indexes stored in the memory, the server will obtain it from the database again. The format of the mapping in the memory is: name:AtomicEntity; where name is the key (Key) and AtomicEntity is the Value (value). The format of AtomicEntity in the memory is: {AtomicIntegerstartIndex; AtomicIntegerendIndex;}.

[0039] Step S203: Determine whether the value corresponding to the key is obtained, if not, execute step S204; if obtained, execute step S207. Use the Get() method to obtain the value corresponding to the key, if not, it means that the client requests to obtain the identifier for the first time.

[0040] Step S204: Obtain the current index value from the database, and update the current index value in the database according to the memory capacity. The memory capacity is the number of indexes added to the memory each time the current index value is obtained, and this value is preset. The server sends a request corresponding to the Key to the database, and a new record of the Key is added to the database. For example, assuming that the client sends an identifier acquisition request to the server for the first time, the server's memory and database are not initialized, and the server initializes 10 by default. In this way, the server requests the database once when it is initialized for the first time, and the database adds a new record of the request, and the updated current index value is 10.

[0041] In a preferred embodiment, the server uses Guava cache and Atomic to obtain data from the database in batches and initialize the data to reduce interaction with the database and improve concurrency performance. Guava cache is thread-safe (i.e., multiple threads will not conflict), ensuring that data is initialized only once; Aatomic is also thread-safe, ensuring that index values ​​will not be obtained repeatedly. The combination of the two ensures the uniqueness of the identifier. The specific implementation process of initialization is as follows:

[0042]

[0043] In addition, if the server knows the name of the identifier acquisition request before receiving the identifier acquisition request, then it can use build(newCacheLoader) when the server starts.<Key,Graph> ()) to initialize the data; if you do not know the name of the identifier acquisition request, initialize it after receiving the identifier acquisition request, and use the above-mentioned CacheMap.get() method to initialize it.

[0044] Batch acquisition:

[0045] If the Key does not exist in the database,

[0046] Return new AtomicEntity(new AtomicInteger(1),new AtomicInteger(cacheStep));

[0047] Update the current index value of the database to cacheStep+1;

[0048] If the Key exists in the database, then

[0049] Integer endIndex=startIndex+cacheStep;

[0050] Return new AtomicEntity(new AtomicInteger(startIndex), new AtomicInteger(endIndex));

[0051] Update the current index value of the database to endIndex+1.

[0052] Among them, cacheStep is the memory capacity, startIndex is the starting index value, and endIndex is the ending index value.

[0053] That is to say, if cacheStep is 10, then 10 numbers can be used to update the database once; if it is 100, then 100 numbers can be used to update the database once. The batch is the value of cacheStep, and the above method reduces the access to the database.

[0054] Step S205: The current index value obtained is used as the starting index value, and the sum of the current index value and the memory capacity is used as the ending index value, which are stored in the memory map. The starting index value and the ending index value are stored in the value corresponding to the key in the map.

[0055] Step S206: Obtain the start index value and the end index value corresponding to the name from the memory mapping.

[0056] Step S207: Determine whether the number of indexes is greater than the number of indexes stored in the memory, if so, execute step S208; otherwise, execute step S210. That is, determine whether the number of indexes is greater than the end index value minus the start index value, if so, it is necessary to re-acquire the current index value from the database.

[0057] Step S208: Obtain the current index value from the database, and update the current index value according to the memory capacity. Update the current index value in the database to the sum of the current index value and the memory capacity, and then splice the obtained current index value to the end of the memory. According to the current index value of each Key stored in the database, the situation of each system obtaining the identifier from the server can be known.

[0058] Step S209: Update the end index value according to the memory capacity, and execute step S210, and use the sum of the end index value and the memory capacity as the updated end index value.

[0059] Step S210: Update the starting index value in the memory according to the number of indexes, and execute step S211. The sum of the starting index value and the number of indexes is used as the updated starting index value.

[0060] Step S211: Assemble the obtained starting index value and the updated starting index value to obtain an identifier, and output the identifier to the client. When the number of indexes is greater than the number of indexes stored in the memory, it is necessary to re-acquire the current index value from the database, and update the ending index value and the starting index value, and assemble the obtained starting index value and the updated starting index value. When the number of indexes is less than or equal to the number of indexes stored in the memory, only the starting index value needs to be updated, and the ending index value remains unchanged, and the obtained starting index value and the updated starting index value are assembled.

[0061] Assembly means that the obtained starting index value and the updated starting index value are processed according to the needs of the client. For example, the obtained starting index value is 1, the obtained ending index value is 10, the number of indexes is 15, and the memory capacity is 10, then the updated starting index value is 16, and the updated ending index value is 20. If the client needs numbers one by one, 1-15 will be sent to the client in sequence; if the client only needs the set of 1-15, it will be directly given to the client and allocated by the client itself.

[0062] It can be seen from the identifier generation method of the embodiment of the present invention that a globally unique and self-incrementing identifier is generated by program control rather than by a database, which is convenient for expansion; the identifier generated based on the index value is in numerical form, has high query efficiency, occupies little storage space, and transmits a small amount of data; the source of the identifier is unified as the server, and each application can concurrently request an identifier from the same server. The current index value stored in the server database can be used to obtain the identifier acquisition status of each system, which is convenient for statistical analysis; Guava and Atomic are used to obtain the current index value from the database, which ensures thread safety and the uniqueness of the generated identifier.

[0063] Figure 3 Schematic diagram of the main modules of the identifier generation device according to an embodiment of the present invention. Figure 3 As shown, the identifier generation device 300 of the embodiment of the present invention mainly includes:

[0064] The acquisition module 301 is used to use the name in the identifier acquisition request as a key to obtain the value corresponding to the key from the mapping in the memory; wherein the value includes a starting index value and an ending index value. The client sends an identifier acquisition request to the server, and the identifier acquisition request includes a name and an index number. The key of the mapping is the name of the identifier acquisition request, and the value is the starting index value and the ending index value obtained from the database. After receiving the identifier acquisition request, the server obtains the value corresponding to the name from the mapping.

[0065] The first updating module 302 is configured to update the starting index value according to the index number if the index number in the identifier acquisition request is less than or equal to the difference between the ending index value and the starting index value. The first updating module 302 is configured to compare the index number in the identifier acquisition request with the difference between the ending index value and the starting index value, and if the index number is less than or equal to the difference, update the starting index value to the sum of the starting index value and the index number.

[0066] The assembling module 303 is used to assemble the obtained starting index value and the updated starting index value to obtain an identifier. According to the requirements of the client, the obtained starting index value and the updated starting index value are assembled to obtain an identifier, and the identifier is sent to the client.

[0067] In addition, the identifier generation device 300 of the embodiment of the present invention may also include: a second updating module and an index value acquisition module ( Figure 3 ). The second update module is used to obtain the current index value from the database if the number of indexes is greater than the difference; and to update the starting index value according to the number of indexes, and to update the ending index value according to the memory capacity. The index value acquisition module is used to obtain the current index value from the database if the value corresponding to the key is not obtained; use the current index value as the starting index value, and use the sum of the current index value and the memory capacity as the ending index value, and store them in the mapping; and obtain the starting index value and the ending index value corresponding to the key from the mapping.

[0068] From the above description, it can be seen that a globally unique and self-incrementing identifier is generated by program control instead of by a database, which is convenient for expansion; the identifier generated based on the index value is in numerical form, with high query efficiency, small storage space occupation, and small amount of data transmission; the source of the identifier is unified as the server, and each application can concurrently request an identifier from the same server. The current index value stored in the server database can be used to obtain the identifier acquisition status of each system, which is convenient for statistical analysis; Guava and Atomic are used to obtain the current index value from the database, which ensures thread safety and the uniqueness of the generated identifier.

[0069] Figure 4 An exemplary system architecture 400 is shown to which the method for processing real-time messages or the system for processing real-time messages according to the embodiments of the present invention can be applied.

[0070] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0071] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).

[0072] The terminal devices 401 , 402 , and 403 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.

[0073] The server 405 may be a server that provides various services, such as a background management server (only an example) that provides support for click events generated by users using the terminal devices 401, 402, and 403. The background management server may analyze and process the received click data, text content, and other data, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.

[0074] It should be noted that the identifier generation method provided in the embodiment of the present application is generally executed by the server 405 , and accordingly, the identifier generation device is generally set in the server 405 .

[0075] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0076] According to an embodiment of the present invention, the present invention also provides an electronic device and a computer-readable medium.

[0077] The electronic device of the present invention comprises: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement an identifier generation method of an embodiment of the present invention.

[0078] The computer-readable medium of the present invention stores a computer program, and when the program is executed by a processor, an identifier generation method according to an embodiment of the present invention is implemented.

[0079] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 suitable for implementing an electronic device of an embodiment of the present invention. Figure 5 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0080] like Figure 5As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the computer system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0081] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.

[0082] In particular, according to the embodiments disclosed in the present invention, the process described in the main step diagram above can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the main step diagram. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.

[0083] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, 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), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, 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, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0084] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order 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 flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0085] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, they may be described as: a processor includes an acquisition module, a first update module, and an assembly module. The names of these modules do not constitute a limitation on the modules themselves in certain cases. For example, the acquisition module may also be described as "a module that uses the name in the identifier acquisition request as a key to obtain the value corresponding to the key from the memory mapping".

[0086] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by a device, the device includes: using the name in the identifier acquisition request as a key, obtaining the value corresponding to the key from the mapping in the memory; wherein the value includes a starting index value and an ending index value; if the number of indexes in the identifier acquisition request is less than or equal to the difference between the ending index value and the starting index value, then updating the starting index value according to the number of indexes; assembling the acquired starting index value and the updated starting index value to obtain an identifier.

[0087] From the above description, it can be seen that a globally unique and self-incrementing identifier is generated by program control instead of by a database, which is convenient for expansion; the identifier generated based on the index value is in numerical form, with high query efficiency, small storage space occupation, and small amount of data transmission; the source of the identifier is unified as the server, and each application can concurrently request an identifier from the same server. The current index value stored in the server database can be used to obtain the identifier acquisition status of each system, which is convenient for statistical analysis; Guava and Atomic are used to obtain the current index value from the database, which ensures thread safety and the uniqueness of the generated identifier.

[0088] The above product can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided by the embodiment of the present invention.

[0089] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for generating an identifier, characterized in that: include: Using the name in the identifier acquisition request as the key, obtain the value corresponding to the key from the mapping in the memory; wherein the value includes a starting index value and an ending index value; obtain the current index value from the database, update the current index value according to the memory capacity, and concatenate the updated current index value to the last storage in the memory, wherein the memory capacity is the number of indexes added in the memory after obtaining the current index value, so as to use the current index value as the starting index value and the sum of the current index value and the memory capacity as the ending index value; If the number of indexes in the identifier acquisition request is less than or equal to the difference between the end index value and the start index value, updating the start index value according to the number of indexes; The acquired starting index value and the updated starting index value are assembled to obtain an identifier.

2. The method according to claim 1, characterized in that: After the step of obtaining the value corresponding to the key from the memory mapping and before the step of assembling the obtained starting index value and the updated starting index value, the method further includes: If the number of indexes is greater than the difference, obtaining the current index value from the database; The starting index value is updated according to the number of indexes, and the ending index value is updated according to the memory capacity; wherein the memory capacity is the number of indexes added to the memory after the current index value is obtained.

3. The method according to claim 2, characterized in that The updating of the starting index value according to the number of indexes includes: taking the sum of the starting index value and the number of indexes as the updated starting index value; The updating of the end index value according to the memory capacity includes: taking the sum of the end index value and the memory capacity as the updated end index value.

4. The method according to claim 2, characterized in that: After the step of obtaining the value corresponding to the key from the mapping in the memory and before the step of if the number of indexes in the identifier acquisition request is less than or equal to the difference between the end index value and the start index value, the method further includes: If the value corresponding to the key is not obtained, the current index value is obtained from the database; Using the current index value as the starting index value, and using the sum of the current index value and the memory capacity as the ending index value, and storing them in the mapping; The starting index value and the ending index value corresponding to the key are obtained from the mapping.

5. The method according to claim 4, characterized in that The obtaining the current index value from the database includes: obtaining the current index value from the database using Guava and Atomic.

6. An identifier generating device, characterized in that: include: An acquisition module is used to obtain the value corresponding to the key from the mapping in the memory using the name in the identifier acquisition request as a key; wherein the value includes a starting index value and an ending index value; obtain the current index value from the database, update the current index value according to the memory capacity, and concatenate the updated current index value to the last storage in the memory, wherein the memory capacity is the number of indexes added in the memory after the current index value is obtained, so as to use the current index value as the starting index value and the sum of the current index value and the memory capacity as the ending index value; A first updating module, configured to update the starting index value according to the number of indexes if the number of indexes in the identifier acquisition request is less than or equal to the difference between the ending index value and the starting index value; An assembling module is used to assemble the acquired starting index value and the updated starting index value to obtain an identifier.

7. The device according to claim 6, characterized in that The apparatus further includes: a second updating module, configured to obtain a current index value from a database if the number of indexes is greater than the difference; and The starting index value is updated according to the number of indexes, and the ending index value is updated according to the memory capacity; wherein the memory capacity is the number of indexes added to the memory after the current index value is obtained.

8. The device according to claim 7, characterized in that The first updating module is further used to: use the sum of the starting index value and the number of indexes as the updated starting index value; The second updating module is further used to: use the sum of the end index value and the memory capacity as the updated end index value.

9. The device according to claim 7, characterized in that The device further comprises: an index value acquisition module, configured to acquire a current index value from the database if the value corresponding to the key is not acquired; Using the current index value as the starting index value, and using the sum of the current index value and the memory capacity as the ending index value, and storing them in the mapping; and The starting index value and the ending index value corresponding to the key are obtained from the mapping.

10. The device according to claim 9, characterized in that The index value acquisition module is further used to: use Guava and Atomic to obtain the current index value from the database.

11. An electronic device, characterized in that: include: 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 implement the method according to any one of claims 1 to 5.

12. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Database primary key generating device and database primary key generating method

    CN102880705A

  • E-commerce platform communication queuing method and system

    CN104835063A

  • Service identifier generation method and apparatus

    CN105447023A

  • Service ID generating method, device and system

    CN106911780A

  • Identifier management methods and identifier server for cluster and corresponding systems

    CN106993022A