Method and apparatus for generating service identifiers in a distributed system
By introducing an identification generation server in a distributed system, and determining the service identity using the identification interval and generation method, the problem of single and inefficient UUID generation method is solved, and flexible and efficient service identity generation is achieved.
Patent Information
- Application Number
- CN202110411291.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-16
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2041-04-16
AI Technical Summary
The generation method of UUID is single and the generation efficiency is low, making it difficult to meet the flexible and efficient needs of business identity generation in distributed systems.
A method for generating a service identity in a distributed system is provided. By receiving a request from a service server through the identification generation server, obtaining an identification interval, and determining the generation method (random or incremental) based on the request, thereby generating an identification of the target service. This method supports the use of pessimistic locks and optimistic locks, ensuring the uniqueness and efficiency of the logo.
It realizes the flexibility and efficiency of generating identity for services in a distributed system, and supports both random and incremental methods to ensure the uniqueness and generation efficiency of identification, avoiding the problem of low UUID generation efficiency.
Smart Images

Figure CN113076303B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to database technology, and in particular, to a method and device for generating service identifiers in a distributed system. Background Art
[0002] As an identifier of elements (such as services, services, data, etc.) in a distributed system, the Universally Unique Identifier (UUID) can uniquely identify an element, and does not need to be centrally managed and generated by a central control end. Each device can independently generate a UUID and will not conflict with the UUIDs generated by other devices. Therefore, it is widely used in distributed systems.
[0003] A UUID is a 128-bit value that can be calculated through a certain algorithm. To improve the search efficiency of the UUID, the UUID can be shortened to 32 bits or 16 bits. The UUID can be generated based on the current time, a counter, and a hardware identifier (usually the MAC address of the wireless network card of the device).
[0004] However, the generation method of the UUID is single and the generation efficiency is low. Summary of the Invention
[0005] The present invention provides a method and device for generating service identifiers in a distributed system, which can flexibly and efficiently generate identifiers for services in a distributed system.
[0006] The first aspect of the present invention provides a method for generating a service identifier in a distributed system, which is applied to an identifier generation server and includes:
[0007] Receiving a service identifier request message sent by a service server, where the service identifier request message is used to request an identifier for a target service;
[0008] Obtaining the identifier range used this time, where the identifier range is determined according to an identifier configuration rule, and the identifier configuration rule includes an identifier threshold, an identifier increment step, and an identifier version number;
[0009] Determining an identifier generation method according to the service identifier request message, where the identifier generation method is a random method or an increment method;
[0010] Determining the identifier of the target service from the identifier range according to the identifier generation method;
[0011] Returning a request response to the service server, where the request response includes the identifier of the target service.
[0012] Optionally, the obtaining the identifier range used this time includes:
[0013] Add a pessimistic lock, and the pessimistic lock is unlocked after the identifier of the target service is generated;
[0014] Determine whether the service identifier request message is the first request after the identifier generation server is started;
[0015] If the service identifier request message is the first request after the identifier generation server is started, update the identifier configuration rule and the identifier range, and the updated identifier range is the identifier range used this time;
[0016] If the service identifier request message is not the first request after the identifier generation server is started, use the identifier range read from the local cache space as the identifier range used this time.
[0017] Optionally, the identifier generation method is a random method. According to the identifier generation method, determining the identifier of the target service from the identifier range includes:
[0018] Obtain a random number from the identifier range;
[0019] When the random number has not been used, generate the identifier of the target service according to the random number;
[0020] When the random data has been used and the number of times of obtaining the random number is less than or equal to the first threshold, obtain a random number from the identifier range again;
[0021] When the random number has been used and the number of times of re-obtaining the random number is greater than the first threshold, update the identifier configuration rule and the identifier range.
[0022] Optionally, after obtaining a random number from the identifier range, it further includes:
[0023] Use a bitmap to determine whether the random number has been used, where the bitmap includes the bit positions corresponding to the random numbers that have been used in the identifier range.
[0024] Optionally, the first threshold is the product of the identifier growth step and the load factor, and the load factor is greater than 0 and less than 1.
[0025] Optionally, the identifier generation method is an incremental method. According to the identifier generation method, determining the identifier of the target service from the identifier range includes:
[0026] Use the current identifier plus 1 to obtain a candidate identifier;
[0027] When the candidate identifier is less than or equal to the upper limit value of the identifier range, generate the identifier of the target service according to the candidate identifier;
[0028] When the candidate identifier is greater than the upper limit value of the identifier range, update the identifier configuration rule and the identifier range, and return to execute the step of using the candidate identifier obtained by adding 1 to the current identifier.
[0029] Optionally, before using the candidate identifier obtained by adding 1 to the current identifier, it further includes:
[0030] Determine whether the current identifier is greater than or equal to a second threshold, where the second threshold is less than the upper limit value of the identifier range;
[0031] When the current identifier is greater than or equal to the second threshold, update the identifier configuration rule and the identifier range;
[0032] When the current identifier is less than the second threshold, or when the current identifier is greater than or equal to the second threshold, use the candidate identifier obtained by adding 1 to the current identifier.
[0033] Optionally, the second threshold is the product of the upper limit value of the identifier range and the load factor, where the load factor is greater than 0 and less than 1;
[0034] The updating the identifier configuration rule and the identifier range includes:
[0035] Use an exclusive lock in an asynchronous manner to update the identifier configuration rule and the identifier range.
[0036] Optionally, the updating the identifier configuration rule and the identifier range includes:
[0037] Use an exclusive lock to read the identifier configuration rule from the database;
[0038] When the identifier version number included in the identifier configuration rule read from the database is different from the identifier version number stored in the local cache space, and the number of times of reading the identifier configuration rule from the database is less than or equal to the preset number of times, re-use the exclusive lock to read the identifier configuration rule from the database;
[0039] When the identifier version number included in the identifier configuration rule read from the database is the same as the identifier version number stored in the local cache space, obtain a new identifier threshold according to the identifier threshold and the identifier increment step included in the identifier configuration rule, and update the identifier version number in the identifier configuration rule;
[0040] Update the identification configuration rules stored in the database and the local cache space according to the new identification threshold and the updated identification version number;
[0041] Obtain the identification range according to the new identification threshold and the identification increment step in the identification configuration rules.
[0042] Optionally, the method further includes: when the identification version number included in the identification configuration rules read from the database is different from the identification version number stored in the local cache space, and the number of reads is greater than the preset number, return a request failure message to the service server.
[0043] Optionally, before receiving the service identification request message sent by the service server, it further includes:
[0044] Start the service and update the first identification to indicate that the identification generation server has never been accessed;
[0045] Obtain multiple identification configuration rules from the database and store them in the local cache space. The identification configuration rules include the identification of the identification configuration rules, business description information, the initial value of the business identification, the identification threshold, the identification increment step, the identification version number, and the indication information of whether the business identification is incremented continuously.
[0046] Optionally, the identification configuration rules further include a business prefix code, the initial creation time and the latest modification time of the identification configuration rules.
[0047] Optionally, determining whether the service identification request message is the first request after the identification generation server is started includes:
[0048] Determine whether the service identification request message is the first request received after the identification generation server is started according to the first identification;
[0049] If the service identification request message is the first request after the identification generation server is started, after updating the identification configuration rules and the identification range using an exclusive lock, it further includes:
[0050] Update the first identification to indicate that the identification generation server has been accessed.
[0051] Optionally, the identification configuration rules include multiple fields, and each field in the identification configuration rules occupies a cache line;
[0052] The step of updating the identification configuration rules stored in the local cache space according to the new identification threshold and the updated identification version number includes:
[0053] Update the new identification threshold to the cache line corresponding to the identification threshold field;
[0054] When the bytes of the cache line corresponding to the identification threshold field are not full, pad the cache line corresponding to the identification threshold field;
[0055] Update the updated identification version number to the cache line corresponding to the version number field;
[0056] When the bytes of the cache line corresponding to the version number field are not full, pad the cache line corresponding to the version number field.
[0057] Optionally, the method further includes: counting the access frequency of the target service to the database, and when the access frequency is higher than a preset frequency, increasing the identification increment step in the identification configuration rule.
[0058] Optionally, the identification configuration rule further includes a service prefix, and generating the identifier of the target service according to the random number includes: adding the service prefix before the random number to generate the identifier of the target service.
[0059] Optionally, the identification configuration rule further includes a service prefix, and generating the identifier of the target service according to the candidate identifier includes: adding the service prefix before the candidate identifier to generate the identifier of the target service.
[0060] In a second aspect, the present invention provides an identification generation server, including:
[0061] A receiving module, configured to receive a service identification request message sent by a service server, where the service identification request message is used to request an identifier of a target service;
[0062] An obtaining module, configured to obtain the identification range used this time, where the identification range is determined according to an identification configuration rule, and the identification configuration rule includes an identification threshold, an identification increment step, and an identification version number;
[0063] A first determination module, configured to determine an identification generation method according to the service identification request message, where the identification generation method is a random method or an increment method;
[0064] A second determination module, configured to determine the identifier of the target service from the identification range according to the identification generation method;
[0065] A sending module, configured to return a request response to the service server, where the request response includes the identifier of the target service.
[0066] In a third aspect, the present invention provides an identification generation server, including: at least one processor and a memory;
[0067] The memory stores computer-executable instructions;
[0068] The at least one processor executes the computer-executable instructions stored in the memory, such that the at least one processor executes the method as described in the first aspect of the present invention.
[0069] In a fourth aspect, the present invention provides a computer-readable storage medium, in which computer-executable instructions are stored, and when the computer-executable instructions are executed by a processor, they are used to implement the method as described in the first aspect of the present invention.
[0070] In a fifth aspect, the present invention provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the method as described in the first aspect of the present invention.
[0071] The present invention provides a method and apparatus for generating a service identifier in a distributed system. The identifier generation server receives a service identifier request message sent by a service server, and this service identifier request message is used to request the identifier of a target service. Secondly, obtain the identifier range used this time, and this identifier range is determined according to an identifier configuration rule, and the identifier configuration rule includes an identifier threshold, an identifier increment step, and an identifier version number. Then, determine an identifier generation method according to the service identifier request message, and this identifier generation method is a random method or an increment method. According to the identifier generation method, determine the identifier of the target service from the identifier range and return it. This method supports flexible allocation of identifiers for services in both random and increment methods, and the identifier generation rule does not have strict requirements on the length of the identifier. Compared with UUID, it has better performance, and the generation of the identifier does not depend on the system time. Compared with the Snowflake method, it can ensure that the generated identifiers are not repeated. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] The drawings herein are incorporated into the specification and form a part of this specification, showing embodiments consistent with the present disclosure, and are used together with the specification to explain the principles of the present disclosure.
[0073] Figure 1 It is a schematic diagram of a network architecture applicable to the present invention;
[0074] Figure 2 It is a flowchart of the method for generating a service identifier in a distributed system provided in Embodiment 1 of the invention;
[0075] Figure 3 It is a flowchart of the method for updating an identifier configuration rule and an identifier range provided in Embodiment 2 of the invention;
[0076] Figure 4 It is a flowchart of the method for generating a service identifier in a random manner provided in Embodiment 3 of the invention;
[0077] Figure 5 Flowchart of the method for generating service identifiers in an increasing manner provided for the fourth invention embodiment;
[0078] Figure 6 Flowchart of the method for generating service identifiers in a distributed system provided for the fifth invention embodiment;
[0079] Figure 7 Schematic structural diagram of an identifier generation server provided for the sixth embodiment of the present invention;
[0080] Figure 8 Schematic structural diagram of an identifier generation server provided for the seventh embodiment of the present invention.
[0081] Through the above-mentioned drawings, the clear embodiments of the present disclosure have been shown, and more detailed descriptions will be given hereinafter. These drawings and textual descriptions are not intended to limit the scope of the concept of the present disclosure in any way, but to illustrate the concept of the present disclosure to those skilled in the art by referring to specific embodiments. Detailed implementation manners
[0082] Here, the exemplary embodiments will be described in detail, and their examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all the implementation manners consistent with the present disclosure. On the contrary, they are merely examples of the devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0083] Figure 1 Schematic diagram of the network architecture applicable to the present invention, as Figure 1 shown, the network architecture includes three sub-networks: service 11, identity (ID) generation server cluster 12, and database 13.
[0084] Service 11 includes multiple service servers, and among the multiple service servers, there are servers for processing different services, such as order service server 111, commodity service server 112, etc. The service servers are used to request service identifiers from the ID generation server cluster 12, and the ID generation server cluster 12 generates service identifiers according to the requests and returns the service identifiers to the service servers.
[0085] The ID generation service cluster 12 includes multiple ID generation servers, Figure 1In the shown cluster, there are a total of N ID generation servers. Each ID generation server is used to generate business identifiers according to the identifier configuration rules. Among them, one ID generation server can be used to generate identifiers corresponding to one type of business, or can also generate identifiers corresponding to multiple types of business. The ID generation service cluster 12 supports dynamic expansion to ensure the high availability of the ID service.
[0086] The database 13 is used to provide storage services, and can store the identifier configuration rules, as well as some other content related to business identifiers. The database can adopt the form of one master and multiple slaves to ensure the high availability of the storage service.
[0087] Based on the above network architecture, Figure 2 FIG. is a flowchart of a method for generating business identifiers in a distributed system provided in the first embodiment of the invention. The method of this embodiment is applied to an identifier generation server, as Figure 2 shown. The method provided in this embodiment includes the following steps:
[0088] S101. Receive a business identifier request message sent by a business server. The business identifier request message is used to request an identifier for a target business.
[0089] The business server can request to call the ID generation server to obtain the ID of the required target business through the Hyper Text Transfer Protocol (HTTP) or Remote Procedure Call (RPC) according to its own needs. Optionally, the business identifier request message may include a business type identifier, and the business type identifier is used to indicate the business type corresponding to the requested identifier.
[0090] S102. Obtain the identifier range used this time. The identifier range is determined according to the identifier configuration rules, and the identifier configuration rules include an identifier threshold, an identifier increment step, and an identifier version number.
[0091] In an exemplary manner, first add a pessimistic lock, and the pessimistic lock is unlocked after the identifier of the target business is generated. Then, it is determined whether the business identifier request message is the first request after the identifier generation server is started. If the business identifier request message is not the first request after the identifier generation server is started, the identifier range read from the local cache space is used as the identifier range used this time. If the business identifier request message is the first request after the identifier generation server is started, the identifier configuration rules and the identifier range are updated, and the updated identifier range is the identifier range used this time.
[0092] To solve the concurrency problem, pessimistic locks are introduced. As the name implies, pessimistic locks are very pessimistic. Every time data is retrieved, it is assumed that others will modify it. Therefore, a lock is set every time data is retrieved. In this way, others will be blocked from accessing the data until they obtain the lock. In this embodiment, after receiving the service identifier request message, a pessimistic lock is added, and the data used during the processing of the service identifier request message will be locked, that is, other requests cannot modify the data used during the processing of the service identifier request message. By adding a pessimistic lock, multiple service identifier request messages are processed serially, that is, serially generating service identifiers for multiple services, thereby avoiding assigning the same service identifier to two services.
[0093] After the identifier generation server is started and receives the service identifier request message for the first time, at this time, the identifier generation server has not generated an identifier range, that is, there is no available identifier range stored in the local cache space, and it is necessary to read the identifier configuration rule from the database and generate the identifier range used this time.
[0094] In one implementation, a first identifier is set, which is used to indicate whether the identifier generation server has been accessed. After the identifier generation server is started, the first identifier is updated to indicate that the identifier generation server has never been accessed. After the identifier generation server processes the first service identifier request message, the first identifier is updated to indicate that the identifier generation server has been accessed. Subsequently, when the identifier generation server receives a service identifier request message, it determines whether the identifier generation server has been accessed based on the first identifier. That the identifier generation server has been accessed indicates that the identifier generation server has generated an identifier range according to the identifier configuration rule.
[0095] If the service identifier request message is the first request after the identifier generation server is started, then update the identifier configuration rule and the identifier range. The updated identifier range is the identifier range used this time. Here, updating the identifier configuration rule includes updating the identifier configuration rule stored in the database and the identifier configuration rule stored in the local cache space. By updating, it is ensured that the identifier configuration rule stored in the database is the same as the identifier configuration rule stored in the local cache space. Updating the identifier range means updating the identifier range stored in the local cache space, and the identifier range stored in the local cache space is generated according to the identifier configuration rule stored in the local cache space.
[0096] Multiple identifier configuration rules are stored in the database, and each identifier configuration rule can be modified by multiple identifier generation servers. The identifier configuration rule includes an identifier threshold, an identifier increment step, and an identifier version number. Among them, the identifier threshold can be understood as the minimum value of the identifier range, and the maximum value of the identifier range is obtained by adding the identifier increment step to the identifier threshold.
[0097] The identification version number can also be referred to as the optimistic lock version number. Optimistic lock is relative to pessimistic lock. Optimistic lock assumes that data generally does not cause conflicts. Therefore, when data is submitted for update, the conflict of the data will be formally detected. If a conflict is found, an error message will be returned to the user to let the user decide what to do. Optimistic lock is applicable to scenarios with more read operations, which can improve the throughput of the program. In this embodiment, the optimistic lock is adopted for the maintenance of the identification configuration rules in the database.
[0098] It can be understood that the identification configuration rules also include some other information. For example, the identification of the identification configuration rules, business description information, the initial value of the business identification, the indication information of whether the business identification is continuously incremented, the initial creation time and the latest modification time of the identification configuration rules, etc. The identification of the identification configuration rules is also called the primary key, which can uniquely identify a rule. The business description information can include rule description, business type, etc. The initial value of the business identification is fixed, and the identification threshold is continuously updated.
[0099] The identification generation server requests the identification configuration rules from the database. The request message includes the identification of the requested rules or other information. For example, the request message includes the business type. After receiving the request message, the database determines the identification configuration rules requested by the identification generation server according to the business type.
[0100] After the identification generation server receives the identification configuration rules returned by the database, it updates the identification configuration rules and the identification range according to the identification configuration rules returned by the database and the identification configuration rules stored in the local cache space.
[0101] S103. Determine the identification generation method according to the business identification request message. The identification generation method is a random method or an increment method.
[0102] The identification generation server can determine the identification generation method according to the interface input parameters of the request message.
[0103] S104. Determine the identification of the target business from the identification range according to the identification generation method.
[0104] In this embodiment, the identification generation server supports both the random method and the increment method to generate business identifications, making the generation of business identifications more flexible and meeting the different needs of different businesses.
[0105] When the identifier generation method is the random method, the identifier of the target service can be determined from the identifier range in the following way: First, obtain a random number from the identifier range, then determine whether the random number has been used. When the random number has not been used, generate the identifier of the target service according to the random number. When the random number has been used and the number of times of obtaining the random number is less than or equal to the first threshold, obtain a random number from the identifier range again. When the random number has been used and the number of times of re-obtaining the random number is greater than the first threshold, update the identifier configuration rule and the identifier range.
[0106] When the random number has been used, it is necessary to obtain a random number from the identifier range again. In the actual process, it may be necessary to obtain it multiple times to get an unused random number. Among them, the fewer the unused random numbers in the identifier range (that is, the more used random numbers), the greater the number of times of obtaining an unused random number. The more unused random numbers in the identifier range, the smaller the number of times of obtaining an unused random number.
[0107] Therefore, a threshold for the number of times of obtaining, that is, the first threshold, is set. Each time an already used random number is obtained, the number of times of obtaining is incremented by 1, and it is judged whether the number of times of obtaining the random number is less than or equal to the first threshold. If the number of times of obtaining the random number is less than or equal to the first threshold, obtain a random number from the identifier range again. If the number of times of obtaining the random number is greater than the first threshold, do not obtain the random number again, indicating that the number of unused random numbers in the identifier range is small, and a new identifier range needs to be obtained, so update the identifier configuration rule and the identifier range.
[0108] Optionally, the first threshold is the product of the identifier growth step and the load factor. The value of the load factor is greater than 0 and less than 1. Exemplarily, the values of the load factor are 0.8, 0.85, 0.9, etc. The load factor can be configured in the identifier configuration rule or can be configured separately in the system of the identifier generation server.
[0109] Optionally, the identifier configuration rule also includes a service prefix, which is used to distinguish different services. When the identifier configuration rule includes a service prefix, the service prefix can be added before or after the random number to generate the identifier of the target service. When the identifier configuration rule does not include a service prefix, the random number can be directly used as the identifier of the target service.
[0110] When the identifier generation method is the incremental method, the identifier of the target service can be determined from the identifier range as follows: Use the current identifier plus 1 to obtain a candidate identifier. When the candidate identifier is less than or equal to the upper limit value of the identifier range, generate the identifier of the target service according to the candidate identifier. When the candidate identifier is greater than the upper limit value of the identifier range, update the identifier configuration rule and the identifier range, and return to execute the step of using the current identifier plus 1 to obtain a candidate identifier.
[0111] The current identifier is stored in the local storage space, specifically, it can be stored in the identifier range or the identifier configuration rule. Since the identifier is incremented according to a predetermined rule in this method, it is necessary to know the current identifier and the increment rule to determine the next identifier. The increment rule can be the next identifier obtained by adding a preset step size to the current identifier. The preset step size is usually 1, that is, the next identifier is obtained by adding 1 to the current identifier each time. The upper limit value of the identifier range, that is, the maximum value of the identifier range, is obtained by adding the identifier threshold and the identifier increment step size.
[0112] Optionally, the identifier configuration rule also includes a service prefix, which is used to distinguish different services. When the identifier configuration rule includes a service prefix, the service prefix can be added before or after the candidate identifier to generate the identifier of the target service. When the identifier configuration rule does not include a service prefix, the candidate identifier can be directly used as the identifier of the target service.
[0113] When the generated service identifier includes a service prefix, the service identifier can be ensured to have service attributes, and users can know the service type or other information according to the service identifier. Among them, the service prefix can be a number, a letter, or a combination of numbers and letters. The random number and the candidate identifier are usually numbers.
[0114] S105. Return a request response to the service server, and the request response includes the identifier of the target service.
[0115] The service server generates the identifier of the target service through the above method and returns the identifier of the target service to the service server.
[0116] Optionally, in this embodiment, the access frequency of the target service to the database can also be counted. The access frequency can be the Query Per Second (QPS). When the access frequency is higher than the preset frequency, increase the identifier increment step size in the identifier configuration rule, so that the identifier increment step size of the service is positively correlated with the QPS, thereby ensuring the stability of the database performance.
[0117] In this embodiment, the identifier generation server receives a service identifier request message sent by the service server. The service identifier request message is used to request the identifier of the target service. Secondly, obtain the identifier range used this time. The identifier range is determined according to the identifier configuration rule. The identifier configuration rule includes an identifier threshold, an identifier increment step size, and an identifier version number. Then, determine the identifier generation method according to the service identifier request message. The identifier generation method is a random method or an increment method. According to the identifier generation method, determine the identifier of the target service from the identifier range and return it. This method can flexibly allocate identifiers for services.
[0118] Based on Embodiment 1, Embodiment 2 of the present invention provides a method for updating the identification configuration rule and the identification range. Usually, the identification configuration rule and the identification range need to be updated in the following situations: when the identification generation server receives a service identification request message for the first time, and the usage amount of the service identification stored in the local cache space of the identification generation server reaches a threshold, a new identification range needs to be regenerated. Figure 3 It is a flowchart of the method for updating the identification configuration rule and the identification range provided by Embodiment 2 of the invention, as Figure 3 shown, the method provided in this embodiment includes the following steps.
[0119] S201. Read the identification configuration rule from the database using an exclusive lock.
[0120] S202. Determine whether the identification version number read from the database is the same as the identification version number stored in the local cache space.
[0121] In this embodiment, the identification configuration rule in the database is updated in an optimistic lock manner. The identification version number read from the database refers to the identification version number included in the identification configuration rule read from the database. When the identification version number read from the database is the same as the identification version number stored in the local cache space, step S203 is executed. When the identification version number read from the database is different from the identification version number stored in the local cache space, step S204 is executed.
[0122] S203. Determine whether the number of reads is greater than a preset number.
[0123] The number of reads refers to the number of times of reading the identification configuration rule from the database. After each reading of the identification configuration rule, the number of reads is incremented by 1, and the initial value of the number of reads can be 0. When the preset number is not greater than (i.e., less than or equal to) the preset number, return to execute step S201. When the preset number is greater than the preset number, execute step S207.
[0124] S204. Obtain a new identification threshold according to the identification threshold and the identification increment step included in the identification configuration rule, and update the identification version number in the identification configuration rule.
[0125] The identification generation server can obtain a new identification threshold by adding the identification increment step to the identification threshold, and add 1 to the identification version number to obtain a new identification version number (or an updated identification version number).
[0126] S205. Update the identification configuration rule stored in the database and the local cache space according to the new identification threshold and the updated identification version number.
[0127] When updating the identification configuration rules in the database, the new identification threshold and the updated identification version number can be used to replace the corresponding values in the identification configuration rules, and the updated identification configuration rules can be sent to the database. Alternatively, the new identification threshold and the updated identification version number can be carried in the database update message and sent to the database, and the database updates the identification configuration rules in the database according to this update message. If the identification configuration rules include the latest modification time, the corresponding latest modification time is updated accordingly.
[0128] The identification configuration rules include multiple fields. For example, they include the identification of the identification configuration rules, business description information, the initial value of the business identification, identification threshold, identification increment step, identification version number, indication information on whether the business identification is continuously incremented, business prefix code, initial creation time, and the latest modification time, etc. Optionally, each field in the identification configuration rules occupies one cache line.
[0129] In the cache system, storage is unitized by cache lines. A cache line is an integer power of 2 consecutive bytes, generally 32 - 256 bytes. The most common cache line size is 64 bytes. When multiple threads modify mutually independent variables, if these variables share the same cache line, it will inadvertently affect each other's performance, which is false sharing. To solve the problem of false sharing, in this embodiment, each field of the identification configuration rules is set to occupy one cache line, and the actual value of this field may only occupy some bytes in the cache line. Therefore, it is necessary to pad redundant multiple long - type fields. For example, each cache line occupies 64 bytes, and the identification threshold occupies 32 bytes, then the remaining 32 bytes need to be padded.
[0130] Specifically, the new identification threshold is updated to the cache line corresponding to the identification threshold field. When the bytes of the cache line corresponding to the identification threshold field are not fully occupied, the cache line corresponding to the identification threshold field is padded. When the bytes of the cache line corresponding to the identification threshold field are fully occupied, there is no need to pad. Similarly, the updated identification version number is updated to the cache line corresponding to the version number field. When the bytes of the cache line corresponding to the version number field are not fully occupied, the cache line corresponding to the version number field is padded. When the bytes of the cache line corresponding to the version number field are fully occupied, there is no need to pad the cache line corresponding to the version number field.
[0131] S206. Obtain an identification range according to the new identification threshold and the identification increment step in the identification configuration rules.
[0132] After the update of the identification configuration rules is completed, a new identification range is generated according to the new identification threshold and the identification increment step, and the new identification range is stored in the local cache space.
[0133] S207. Return a request failure message to the service server.
[0134] In this embodiment, an exclusive lock of the database is used to read the identification configuration rule from the database, so as to avoid multiple requests reading the same data from the database simultaneously and reduce the system performance loss. When the identification version number included in the identification configuration rule read from the database is different from the identification version number stored in the local cache space, and the number of times of reading the identification configuration rule from the database is less than or equal to the preset number of times, the exclusive lock is reused to read the identification configuration rule from the database. When the identification version number included in the identification configuration rule read from the database is the same as the identification version number stored in the local cache space, a new identification threshold is obtained according to the identification threshold and the identification increment step included in the identification configuration rule, the identification version number in the identification configuration rule is updated, and a new identification range is obtained according to the updated identification configuration rule. By adding an identification version number field, when updating the identification configuration rule, comparing the version numbers can avoid multiple requests from repeatedly updating the rule and causing waste of resources.
[0135] Based on Embodiment 1 and Embodiment 2, Embodiment 3 of the present invention provides a method for generating a service identifier in a random manner. Figure 4 FIG. is a flowchart of the method for generating a service identifier in a random manner provided in Embodiment 3 of the invention. As Figure 4 shown, the method provided in this embodiment includes the following steps.
[0136] S301. Obtain a random number from the identification range.
[0137] The identification range refers to the range composed of the identification threshold and the identification increment step.
[0138] S302. Use a bitmap to determine whether the random number has been used.
[0139] In one implementation, the bitmap (bit set) includes the bit positions corresponding to the random numbers that have been used in the identification range. Exemplarily, when the value of the bit position is 0 or 1, when the value of the bit position is 0, it indicates that the random number corresponding to the bit position has not been used, and when the value of the bit position is 1, it indicates that the random number corresponding to the bit position has been used. Or, when the value of the bit position is 1, it indicates that the random number corresponding to the bit position has not been used, and when the value of the bit position is 0, it indicates that the random number corresponding to the bit position has been used. Determine whether the random number exists in the bitmap. If the random number exists in the bitmap, it is determined that the random number has been used. If the random number does not exist in the bitmap, it is determined that the random number has not been used.
[0140] It can be understood that other methods can also be used to determine whether the random number has been used. This embodiment is only an example and does not constitute a limitation.
[0141] When the random number has been used, step S303 is executed; when the random number has not been used, step S305 is executed.
[0142] S303. Determine whether the acquisition times of the random number are greater than a first threshold.
[0143] When the random number has been used, a new random number needs to be obtained again from the identification interval. When the acquisition times of the random number are greater than the first threshold, step S304 is executed; when the acquisition times of the random number are not greater than the first threshold, return to execute step S301, and an unused random number can be obtained through multiple loops.
[0144] This first threshold can be an empirical value, or it can be the product of the identification growth step and the load factor, where the load factor is greater than 0 and less than 1. Alternatively, the integer part of the product of the identification growth step and the load factor is used as the first threshold.
[0145] S304. Update the identification configuration rule and the identification interval.
[0146] The identification generation server can update the identification configuration rule and the identification interval asynchronously. Updating asynchronously can be understood as updating the identification configuration rule and the identification interval while processing requests, that is, the update of the identification configuration rule does not affect the processing of requests, enabling the identification generation server to return the service identification to the service server in a timely manner. The update method of the identification configuration rule and the identification interval can adopt the method of Embodiment 2, which will not be elaborated here.
[0147] S305. Generate the identification of the target service according to the random number.
[0148] The random number can be used as the identification of the target service, or the service prefix plus the random number can form the identification of the target service.
[0149] Optionally, in another implementation manner, the used random number can also be deleted from the identification interval, so that the random numbers read from the identification interval are all unused, and there is no need to determine whether the random number has been used.
[0150] In this embodiment, a bitmap is used as a filter to determine whether the random number has been used, which can conveniently exclude the used random numbers and accurately generate an identification for the service.
[0151] Based on Embodiment 1 and Embodiment 2, Embodiment 4 of the present invention provides a method for generating a service identification in an incremental manner. Figure 5 For the flowchart of the method for generating a service identification in an incremental manner provided by Embodiment 4 of the invention, as Figure 5 shown, the method provided in this embodiment includes the following steps.
[0152] S401. Determine whether the current identifier is greater than or equal to a second threshold, where the second threshold is less than the upper limit of the identifier range.
[0153] The current identifier is the service identifier determined by the previous service identifier request message, and this current identifier can be recorded in the local cache space. After generating a new service identifier each time, update this current identifier.
[0154] Optionally, the second threshold is the product of the upper limit of the identifier range and the load factor, where the load factor is greater than 0 and less than 1.
[0155] When the current identifier is greater than or equal to the second threshold, execute step S403. When the current identifier is less than the second threshold or the current identifier is greater than or equal to the second threshold, execute step S402.
[0156] S402. Use the current identifier plus 1 to obtain a candidate identifier.
[0157] S403. Update the identifier configuration rule and the identifier range.
[0158] The identifier generation server can update the identifier configuration rule and the identifier range asynchronously. Updating asynchronously can be understood as updating the identifier configuration rule and the identifier range while processing the request, that is, the update of the identifier configuration rule will not affect the processing of the request, enabling the identifier generation server to return the service identifier to the service server in a timely manner. The update method of the identifier configuration rule and the identifier range can adopt the method of Embodiment 2, which will not be elaborated here.
[0159] S404. Determine whether the candidate identifier is greater than the upper limit of the identifier range.
[0160] When the candidate identifier is greater than the upper limit of the identifier range, execute step S405. When the candidate identifier is not greater than (i.e., less than or equal to) the upper limit of the identifier range, execute S406.
[0161] S405. Update the identifier configuration rule and the identifier range.
[0162] For the specific implementation of this step, refer to the description of step S403. After step S405 is executed, execute step S401. After updating the identifier configuration rule, if the second threshold is the product of the upper limit of the identifier range and the load factor, then the second threshold also changes accordingly, and it is necessary to re-determine whether the current identifier is greater than or equal to the second threshold.
[0163] S406. Generate the identifier of the target service according to the candidate identifier.
[0164] The candidate identifier can be used as the identifier of the target service, or the service prefix can be added to the candidate identifier to form the identifier of the target service.
[0165] In this embodiment, by setting the load factor, when the identifiers in the local cache space are not used up, the service identifier rule is obtained from the database and the service identifier rule in the local cache space is updated, which can prevent the identifier generation server from being unable to return the service identifier to the service server due to reading the service identifier configuration rule from the database, resulting in a large service delay or a failure of the service identifier request. If the service identifier rule is obtained from the database after the identifiers in the local cache space are used up, then there are no available identifiers for service allocation during the update of the service identifier rule, resulting in a large service delay or a failure of the service identifier request.
[0166] On the basis of the foregoing embodiment, Embodiment 5 of the present invention provides a method for generating a service identifier in a distributed system. Figure 6 The flowchart of the method for generating a service identifier in the distributed system provided in Embodiment 5 of the invention is as Figure 6 shown, and the method provided in this embodiment includes the following steps.
[0167] S501. Configure the identifier configuration rule in the data table of the database.
[0168] The identifier configuration rule may include a primary key, service description information, an initial value of the service identifier, an identifier threshold, an identifier increment step, an identifier version number, an indication information on whether the service identifier is continuously incremented, a service prefix code, a rule initial creation time, and a latest modification time, etc.
[0169] S502. The identifier generation server starts the service.
[0170] After starting the service, the identifier generation server can provide the identifier generation service to the service server. After starting the service, the first identifier is updated to indicate that the identifier generation server has never been accessed.
[0171] S503. The identifier generation server reads all the identifier configuration rules from the database into the local cache space.
[0172] S504. The service server sends a service identifier request message to the identifier generation server.
[0173] S505. The identifier generation server adds a pessimistic lock to the service identifier request message.
[0174] The pessimistic lock is used to solve the concurrency problem. When the identifier generation server receives multiple service identifier request messages, the pessimistic lock can be used to process the multiple service identifier request messages sequentially.
[0175] S506. Determine whether the service identifier request message is the first request after the service is started.
[0176] It can be determined whether this request is the first request after the service is started through the first identifier. If the first identifier indicates that the identifier generation server has never been accessed, it is determined that this request is the first request after the service is started. If the first identifier indicates that the identifier generation server has been accessed, it is determined that this request is not the first request after the service is started. Among them, after the first request, the first identifier is updated to indicate that the identifier generation server has been accessed. When this request is the first request after the service is started, step S507 is executed. When this request is not the first request after the service is started, step S509 is executed.
[0177] S507. Update the identifier configuration rule corresponding to the service identifier request message in the database.
[0178] In this step, the identifier threshold and version number in the identifier configuration rule are updated. For the specific update process, refer to the description of the foregoing embodiments and will not be elaborated here.
[0179] S508. The identifier generation server stores the updated identifier configuration rule in the local cache space.
[0180] The updated identifier configuration rule can be stored in the local cache space by padding the cache line. For the specific implementation method, refer to the description of the foregoing embodiments and will not be elaborated here.
[0181] S509. The identifier generation server determines the identifier of the target service from the local cache space.
[0182] In this embodiment, the identifier of the target service can be determined from the local cache space in a random manner and an incremental manner. For the random manner, the identifier generation server generates a random number between the identifier threshold and the identifier threshold + identifier increment step according to the identifier configuration rule stored in the local cache space. For the incremental manner, the current identifier of the identifier generation rule is saved in the local cache space, and the candidate identifier is obtained by adding 1 to the current identifier. Further, it is determined whether the candidate identifier is available and the service identifier is generated. For the specific implementation methods of the above two methods, refer to the relevant descriptions of Embodiment 3 and Embodiment 4 and will not be elaborated here.
[0183] S510. The identifier generation server releases the pessimistic lock.
[0184] S511. The identifier generation server returns the requested service identifier to the service server.
[0185] Figure 7 This is a schematic structural diagram of an identifier generation server provided by Embodiment 6 of the present invention. As Figure 7As shown in the figure, the server provided in this embodiment is 200, including:
[0186] A receiving module 21, configured to receive a service identification request message sent by a service server, where the service identification request message is used to request an identification of a target service;
[0187] An obtaining module 22, configured to obtain an identification range used this time, where the identification range is determined according to an identification configuration rule, and the identification configuration rule includes an identification threshold, an identification increment step, and an identification version number;
[0188] A first determination module 23, configured to determine an identification generation method according to the service identification request message, where the identification generation method is a random method or an increment method;
[0189] A second determination module 24, configured to determine the identification of the target service from the identification range according to the identification generation method;
[0190] A sending module 25, configured to return a request response to the service server, where the request response includes the identification of the target service.
[0191] Optionally, the obtaining module 22 is specifically configured to:
[0192] Add a pessimistic lock, and the pessimistic lock is unlocked after the identification of the target service is generated;
[0193] Determine whether the service identification request message is the first request after the identification generation server is started;
[0194] If the service identification request message is the first request after the identification generation server is started, update the identification configuration rule and the identification range, and the updated identification range is the identification range used this time;
[0195] If the service identification request message is not the first request after the identification generation server is started, use the identification range read from the local cache space as the identification range used this time.
[0196] Optionally, the identification generation method is a random method, and determining the identification of the target service from the identification range according to the identification generation method specifically includes:
[0197] Obtain a random number from the identification range;
[0198] When the random number has not been used, generate the identification of the target service according to the random number;
[0199] When the random data has been used and the number of times of obtaining the random number is less than or equal to the first threshold, obtain a random number from the identification interval again;
[0200] When the random number has been used and the number of times of re-obtaining the random number is greater than the first threshold, update the identification configuration rule and the identification interval.
[0201] Optionally, after the obtaining module 22 obtains a random number from the identification interval, it is further configured to: use a bitmap to determine whether the random number has been used, where the bitmap includes bit positions corresponding to the random numbers that have been used in the identification interval.
[0202] Optionally, the first threshold is the product of the identification growth step and the load factor, and the load factor is greater than 0 and less than 1.
[0203] Optionally, the identification generation method is an incremental method. According to the identification generation method, to determine the identification of the target service from the identification interval, specifically:
[0204] Obtain a candidate identification by adding 1 to the current identification;
[0205] When the candidate identification is less than or equal to the upper limit value of the identification interval, generate the identification of the target service according to the candidate identification;
[0206] When the candidate identification is greater than the upper limit value of the identification interval, update the identification configuration rule and the identification interval, and return to execute the step of obtaining a candidate identification by adding 1 to the current identification.
[0207] Optionally, before the obtaining module 22 obtains a candidate identification by adding 1 to the current identification, it is further configured to:
[0208] Judge whether the current identification is greater than or equal to a second threshold, and the second threshold is less than the upper limit value of the identification interval;
[0209] When the current identification is greater than or equal to the second threshold, update the identification configuration rule and the identification interval;
[0210] When the current identification is less than the second threshold, or when the current identification is greater than or equal to the second threshold, obtain a candidate identification by adding 1 to the current identification.
[0211] Optionally, the second threshold is the product of the upper limit value of the identification interval and the load factor, and the load factor is greater than 0 and less than 1;
[0212] The updating of the identification configuration rule and the identification interval includes:
[0213] Use an asynchronous method to update the identification configuration rule and the identification range using an exclusive lock.
[0214] Optionally, the update of the identification configuration rule and the identification range is specifically as follows:
[0215] Read the identification configuration rule from the database using an exclusive lock;
[0216] When the identification version number included in the identification configuration rule read from the database is different from the identification version number stored in the local cache space, and the number of times of reading the identification configuration rule from the database is less than or equal to the preset number of times, read the identification configuration rule from the database again using an exclusive lock;
[0217] When the identification version number included in the identification configuration rule read from the database is the same as the identification version number stored in the local cache space, obtain a new identification threshold according to the identification threshold and the identification increment step included in the identification configuration rule, and update the identification version number in the identification configuration rule;
[0218] Update the database and the identification configuration rule stored in the local cache space according to the new identification threshold and the updated identification version number;
[0219] Obtain the identification range according to the new identification threshold and the identification increment step in the identification configuration rule.
[0220] Optionally, when the identification version number included in the identification configuration rule read from the database is different from the identification version number stored in the local cache space, and the number of reading times is greater than the preset number of times, the sending module 25 is further configured to: return a request failure message to the service server.
[0221] Optionally, it further includes a startup module for:
[0222] Start the service and update the first identification to indicate that the identification generation server has never been accessed;
[0223] Obtain multiple identification configuration rules from the database and store them in the local cache space. The identification configuration rule includes the identification of the identification configuration rule, service description information, the initial value of the service identification, the identification threshold, the identification increment step, the identification version number, and the indication information of whether the service identification is continuously incremented.
[0224] Optionally, the identification configuration rule further includes a service prefix code, the initial creation time and the latest modification time of the identification configuration rule.
[0225] Optionally, determining whether the service identifier request message is the first request after the identifier generation server is started specifically includes:
[0226] Determining whether the service identifier request message is the first request received after the identifier generation server is started according to the first identifier;
[0227] If the service identifier request message is the first request after the identifier generation server is started, after the obtaining module 22 updates the identifier configuration rule and the identifier range using an exclusive lock, it is further configured to: update the first identifier to indicate that the identifier generation server has been accessed.
[0228] Optionally, the identifier configuration rule includes multiple fields, and each field in the identifier configuration rule occupies one cache line;
[0229] Updating the identifier configuration rule stored in the local cache space according to the new identifier threshold and the updated identifier version number specifically includes:
[0230] Updating the new identifier threshold to the cache line corresponding to the identifier threshold field;
[0231] When the bytes of the cache line corresponding to the identifier threshold field are not fully occupied, padding the cache line corresponding to the identifier threshold field;
[0232] Updating the updated identifier version number to the cache line corresponding to the version number field;
[0233] When the bytes of the cache line corresponding to the version number field are not fully occupied, padding the cache line corresponding to the version number field.
[0234] Optionally, it further includes a statistics module, configured to count the access frequency of the target service to the database, and when the access frequency is higher than a preset frequency, increasing the identifier increment step length in the identifier configuration rule.
[0235] Optionally, the identifier configuration rule further includes a service prefix, and generating the identifier of the target service according to the random number specifically includes: adding the service prefix before the random number to generate the identifier of the target service.
[0236] Optionally, the identifier configuration rule further includes a service prefix, and generating the identifier of the target service according to the candidate identifier specifically includes: adding the service prefix before the candidate identifier to generate the identifier of the target service.
[0237] The device in this embodiment can be used to execute the method described in any one of Embodiments 1 to 5 above. The specific implementation manners and technical effects are similar and will not be elaborated here.
[0238] Figure 8 A schematic structural diagram of the identification generation server provided in the seventh embodiment of the present invention is shown as Figure 8 shown. The identification generation server 300 includes: a processor 31, a memory 32, and a transceiver 33. The memory 32 is used to store instructions, the transceiver 33 is used to communicate with other devices, and the processor 31 is used to execute the instructions stored in the memory, so that the electronic device 300 executes the method described in any one of the first to fifth embodiments above. The specific implementation manners and technical effects are similar and will not be elaborated here.
[0239] The eighth embodiment of the present invention provides a computer-readable storage medium. Computer-executable instructions are stored in the computer-readable storage medium. When the computer-executable instructions are executed by a processor, they are used to implement the method described in any one of the first to fifth embodiments above. The specific implementation manners and technical effects are similar and will not be elaborated here.
[0240] The ninth embodiment of the present invention provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the method described in any one of the first to fifth embodiments above. The specific implementation manners and technical effects are similar and will not be elaborated here.
[0241] After considering the specification and practicing the invention disclosed herein, those skilled in the art will readily conceive of other embodiments of the present disclosure. The present invention is intended to cover any variations, uses, or adaptations of the present disclosure, which follow the general principles of the present disclosure and include known common knowledge or conventional technical means in the technical field not disclosed in the present disclosure. The specification and embodiments are only to be considered as exemplary, and the true scope and spirit of the present disclosure are pointed out by the following claims.
[0242] It should be understood that the present disclosure is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present disclosure is only limited by the appended claims.
Claims
1. A method for generating a service identifier in a distributed system, applied to an identifier generation server, characterized in that, Including: Receiving a service identification request message sent by a service server, where the service identification request message is used to request an identification of a target service; Obtaining an identification range used this time, where the identification range is determined according to an identification configuration rule, and the identification configuration rule includes an identification threshold, an identification increment step, and an identification version number; Determining an identification generation method according to the service identification request message, where the identification generation method is a random method or an increment method; Determining the identification of the target service from the identification range according to the identification generation method; Returning a request response to the service server, where the request response includes the identification of the target service; The obtaining the identification range used this time includes: Adding a pessimistic lock, and the pessimistic lock is unlocked after the identification of the target service is generated; Judging whether the service identification request message is the first request after the identification generation server is started; If the service identification request message is the first request after the identification generation server is started, updating the identification configuration rule and the identification range, and the updated identification range is the identification range used this time; If the service identification request message is not the first request after the identification generation server is started, using the identification range read from the local cache space as the identification range used this time.
2. The method according to claim 1, characterized in that, When the identification generation method is a random method, and determining the identification of the target service from the identification range according to the identification generation method includes: Obtaining a random number from the identification range; When the random number has not been used, generating the identification of the target service according to the random number; When the random data has been used and the number of times of obtaining the random number is less than or equal to a first threshold, obtaining a random number from the identification range again; When the random number has been used and the number of times of re-obtaining the random number is greater than the first threshold, updating the identification configuration rule and the identification range.
3. The method according to claim 2, characterized in that, After obtaining a random number from the identification range, it further includes: Using a bitmap to judge whether the random number has been used, where the bitmap includes bit positions corresponding to the random numbers that have been used in the identification range.
4. The method according to claim 2, characterized in that, The first threshold is the product of the identification increment step and the load factor, and the load factor is greater than 0 and less than 1.
5. The method according to claim 1, characterized in that, When the identification generation method is an increment method, and determining the identification of the target service from the identification range according to the identification generation method includes: Using the current identification plus 1 to obtain a candidate identification; When the candidate identification is less than or equal to the upper limit value of the identification range, generating the identification of the target service according to the candidate identification; When the candidate identification is greater than the upper limit value of the identification range, updating the identification configuration rule and the identification range, and returning to execute the step of using the current identification plus 1 to obtain a candidate identification.
6. The method according to claim 5, characterized in that, Before using the current identification plus 1 to obtain a candidate identification, it further includes: Judging whether the current identification is greater than or equal to a second threshold, and the second threshold is less than the upper limit value of the identification range; When the current identifier is greater than or equal to the second threshold, update the identifier configuration rule and the identifier range; When the current identifier is less than the second threshold, or the current identifier is greater than or equal to the second threshold, use the current identifier plus 1 to obtain a candidate identifier.
7. The method according to claim 6, characterized in that, The second threshold is the product of the upper limit value of the identifier range and the load factor, and the load factor is greater than 0 and less than 1; The updating the identifier configuration rule and the identifier range includes: Asynchronously update the identifier configuration rule and the identifier range using an exclusive lock.
8. The method according to any one of claims 1-7, characterized in that, The updating the identifier configuration rule and the identifier range includes: Use an exclusive lock to read the identifier configuration rule from the database; When the identifier version number included in the identifier configuration rule read from the database is different from the identifier version number stored in the local cache space, and the number of times of reading the identifier configuration rule from the database is less than or equal to the preset number of times, re-use the exclusive lock to read the identifier configuration rule from the database; When the identifier version number included in the identifier configuration rule read from the database is the same as the identifier version number stored in the local cache space, obtain a new identifier threshold according to the identifier threshold and the identifier increment step included in the identifier configuration rule, and update the identifier version number in the identifier configuration rule; Update the identifier configuration rule stored in the database and the local cache space according to the new identifier threshold and the updated identifier version number; Obtain the identifier range according to the new identifier threshold and the identifier increment step in the identifier configuration rule.
9. The method according to claim 8, wherein, It further includes: When the identifier version number included in the identifier configuration rule read from the database is different from the identifier version number stored in the local cache space, and the number of reading times is greater than the preset number of times, return a request failure message to the service server.
10. The method according to claim 1, wherein, Before receiving the service identifier request message sent by the service server, it further includes: Start the service and update the first identifier to indicate that the identifier generation server has never been accessed; Obtain multiple identifier configuration rules from the database and store them in the local cache space. The identifier configuration rule includes the identifier of the identifier configuration rule, service description information, the initial value of the service identifier, the identifier threshold, the identifier increment step, the identifier version number, and the indication information of whether the service identifier is incremented continuously.
11. The method according to claim 10, wherein, The identifier configuration rule further includes a service prefix code, the initial creation time and the latest modification time of the identifier configuration rule.
12. The method according to claim 10, wherein, The judging whether the service identifier request message is the first request after the identifier generation server is started includes: Judge whether the service identifier request message is the first request received after the identifier generation server is started according to the first identifier; If the service identifier request message is the first request after the identifier generation server is started, after using the exclusive lock to update the identifier configuration rule and the identifier range, it further includes: Update the first identifier to indicate that the identifier generation server has been accessed.
13. The method according to claim 8, wherein, The identification configuration rule includes multiple fields, and each field in the identification configuration rule occupies one cache line; Updating the identification configuration rule stored in the local cache space according to the new identification threshold and the updated identification version number includes: Updating the new identification threshold to the cache line corresponding to the identification threshold field; When the bytes of the cache line corresponding to the identification threshold field are not fully occupied, filling up the cache line corresponding to the identification threshold field; Updating the updated identification version number to the cache line corresponding to the version number field; When the bytes of the cache line corresponding to the version number field are not fully occupied, filling up the cache line corresponding to the version number field.
14. The method according to any one of claims 1-7, wherein, It further includes: Counting the access frequency of the target service to the database; When the access frequency is higher than the preset frequency, increasing the identification increment step in the identification configuration rule.
15. The method according to claim 2, wherein, The identification configuration rule also includes a service prefix; Generating the identification of the target service according to the random number includes: Adding the service prefix before the random number to generate the identification of the target service.
16. The method according to claim 5, wherein, The identification configuration rule also includes a service prefix; Generating the identification of the target service according to the candidate identification includes: Adding the service prefix before the candidate identification to generate the identification of the target service.
17. An identification generation server, wherein, It includes: A receiving module, configured to receive a service identification request message sent by a service server, where the service identification request message is used to request the identification of a target service; An obtaining module, configured to obtain the identification range used this time, where the identification range is determined according to an identification configuration rule, and the identification configuration rule includes an identification threshold, an identification increment step, and an identification version number; A first determination module, configured to determine an identification generation method according to the service identification request message, where the identification generation method is a random method or an increment method; A second determination module, configured to determine the identification of the target service from the identification range according to the identification generation method; A sending module, configured to return a request response to the service server, where the request response includes the identification of the target service; The obtaining module is specifically configured to add a pessimistic lock, and the pessimistic lock is unlocked after the identification of the target service is generated; determining whether the service identification request message is the first request after the identification generation server is started; if the service identification request message is the first request after the identification generation server is started, updating the identification configuration rule and the identification range, and the updated identification range is the identification range used this time; if the service identification request message is not the first request after the identification generation server is started, using the identification range read from the local cache space as the identification range used this time.
18. An identification generation server, characterized in that, It includes: At least one processor and a memory; The memory stores computer execution instructions; The at least one processor executes the computer execution instructions stored in the memory, so that the at least one processor executes the method according to any one of claims 1 to 16.
19. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method according to any one of claims 1 to 16.
20. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method according to any one of claims 1 to 16.
Citation Information
Patent Citations
Service data processing method and apparatus
CN109344162A