A method and apparatus for generating a globally unique identifier in a distributed system

By using a coordination service center to allocate fixed and temporary machine identifiers in a distributed system, the problem of cluster scalability and concurrency performance under the limitation of the number of bits of globally unique identifiers is solved, achieving efficient generation of globally unique identifiers and supporting high scalability and high concurrency.

CN115145726BActive Publication Date: 2026-07-31WEBANK (CHINA)
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
WEBANK (CHINA)
Filing Date
2022-06-29
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

In distributed systems, existing technologies struggle to improve cluster scalability and single-server concurrency performance while maintaining the same number of globally unique identifier bits, resulting in reduced cluster scalability and high-concurrency performance.

Method used

By allocating fixed and temporary machine identifiers in the coordination service center, the server uses the fixed machine identifier to generate a globally unique identifier during low concurrency and the temporary machine identifier during high concurrency, combining the local identifier to generate a globally unique identifier, thus ensuring the uniqueness and efficient allocation of the identifier.

Benefits of technology

It improves the cluster scalability of distributed systems and the concurrent performance of a single server without increasing the number of bits of the globally unique identifier, avoids the emergence of zombie machine identifiers, and supports high scalability and high concurrency requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115145726B_ABST
    Figure CN115145726B_ABST
Patent Text Reader

Abstract

This invention relates to the field of computer technology, and more particularly to a method and apparatus for generating globally unique identifiers in a distributed system. The method includes: assigning a first globally unique identifier to a first object based on a server's fixed machine identifier and a first n-bit local identifier within any given unit of time; ensuring that the first n-bit local identifiers generated by the server within the unit of time are not duplicated; obtaining a temporary machine identifier from a coordination service center when the number of assigned first globally unique identifiers meets a preset threshold; and assigning a second globally unique identifier to a second object based on the server's temporary machine identifier and a second n-bit local identifier; ensuring that the second n-bit local identifiers generated by the server within the unit of time are not duplicated. This method can meet the high scalability requirements of a distributed system and, when the workload of any server in the distributed system reaches its peak, expand the number of globally unique identifiers that the server can generate, thus satisfying the high concurrency requirements of the distributed system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, apparatus, computing device, and computer-readable storage medium for generating a globally unique identifier in a distributed system. Background Technology

[0002] With the development of computer technology, more and more technologies are being applied in the financial field. The traditional financial industry is gradually transforming into financial technology (Fintech). However, due to the security and real-time requirements of the financial industry, higher demands are being placed on technology.

[0003] In a distributed system, each server generates a distributed globally unique identifier (ID) for its multiple running threads. There are several methods for generating globally unique identifiers. One possible method is to use the Snowflake or Leaf-Segment algorithm. Specifically, each server is bound to an m-bit machine identifier, and each server generates an n-bit auto-incrementing identifier within a unit of time. Then, within a unit of time, any server combines the timestamp corresponding to that unit of time, the m-bit machine identifier, and the n-bit auto-incrementing identifier to obtain a globally unique identifier: timestamp_m-bit machine identifier_n-bit auto-incrementing identifier. Because the m-bit machine identifier is pre-designed, it ensures that different servers will not have duplicate globally unique identifiers; and because the n-bit auto-incrementing identifier is generated by the server itself, it ensures that multiple threads on the same server will not have duplicate globally unique identifiers within a unit of time.

[0004] However, the above methods have problems in some scenarios. For example, some businesses have limitations on the number of bits in the globally unique identifier, and it cannot be too long. Another example is when the Snowflake algorithm needs to replace the old globally unique identifier algorithm; to ensure that users do not perceive a change in the number of bits, the number of bits in the globally unique identifier generated by the Snowflake algorithm should be consistent with the number of bits in the old algorithm.

[0005] When business scenarios have strict limitations on the number of bits required for globally unique identifiers, since the number of bits in the timestamp field is fixed, Snowflake or leaf-segment algorithms can only shorten the number of bits in the machine identifier or the number of bits in the auto-incrementing identifier. Shortening the number of bits in the machine identifier reduces the number of servers that can be supported in the distributed system, decreasing cluster scalability; shortening the number of bits in the auto-incrementing identifier reduces the number of auto-incrementing identifiers that each server can generate per unit of time, reducing the cluster's high-concurrency performance.

[0006] Taking a globally unique identifier of 20 bits as an example, and a timestamp of fixed length of 14 bits, the sum of the machine identifier and the auto-incrementing identifier is 6 bits. If the machine identifier is 2 bits and the auto-incrementing identifier is 4 bits, then the distributed system can have a maximum of 10... 2 There are 10 servers, and each server can support the generation of 10 auto-incrementing identifiers per unit of time. 4 However, in a real-world production environment, the number of servers in a cluster is very likely to exceed 100, therefore the scalability of the above-described cluster solution is very low. If the machine identifier is 3 digits and the auto-incrementing identifier is 3 digits, then the distributed system can have a maximum of 10 3 Each server can only generate a maximum of 10 auto-incrementing identifiers per unit of time. 3 In the above solution, although the scalability of the cluster is guaranteed, each server can only support a concurrency of 1,000 threads per unit time, which is far from meeting the concurrency required during peak business periods. Therefore, the high concurrency performance of the cluster is reduced.

[0007] Therefore, there is an urgent need for a method that can ensure the high scalability of the cluster while improving the high concurrency performance of a single server. Summary of the Invention

[0008] This invention provides a method for generating globally unique identifiers in a distributed system, which can ensure the high scalability of the cluster while improving the high concurrency performance of a single server.

[0009] In a first aspect, embodiments of the present invention provide a method for generating a globally unique identifier in a distributed system, the method being applied to any server in the distributed system; the method includes:

[0010] Within any given time period, a first globally unique identifier is assigned to the first object based on the server's fixed machine identifier and the first n-bit local identifier; the first n-bit local identifiers generated by the server within each time period are not duplicated; the fixed machine identifier is assigned to the server by the coordination service center from a preset pool of fixed machine identifiers;

[0011] Once the number of allocated first globally unique identifiers is detected to meet a preset threshold, a temporary machine identifier for the server is obtained from the coordination service center. The temporary machine identifier for the server is allocated to the server by the coordination service center from a preset pool of temporary machine identifiers. The sum of the number of each fixed machine identifier and the number of each temporary machine identifier is used to characterize the cluster expansion performance of the distributed system.

[0012] A second globally unique identifier is assigned to the second object based on the server's temporary machine identifier and the second n-bit local identifier; the second n-bit local identifiers generated by the server within a unit of time are not repeated.

[0013] Within any given time period, a first globally unique identifier is assigned to a first object based on the server's fixed machine identifier and the first n-bit local identifier. Once the number of assigned first globally unique identifiers meets a preset threshold, a temporary machine identifier is obtained from the coordination service center. A second globally unique identifier is then assigned to a second object based on the server's temporary machine identifier and the second n-bit local identifier. Thus, when the concurrency of any server is low within a given time period, only the fixed machine identifier is used to generate the first globally unique identifier; when the concurrency of any server is high within a given time period, globally unique identifiers are generated not only through the fixed machine identifier but also based on the temporary machine identifier. This method allows servers to flexibly request machine identifiers without limiting the number of machine identifiers a server can request. It satisfies the high scalability requirements of distributed systems and can expand the number of globally unique identifiers a server can generate when the workload of any server in the distributed system is at its peak, thus meeting the high concurrency requirements of distributed systems.

[0014] Optionally, the coordination service center assigns machine identifiers to each server through a distributed coordination service.

[0015] The distributed coordination service comes with a built-in distributed atomic counter function, which can guarantee the atomicity of machine identifier distribution and prevent different servers from obtaining the same machine identifier.

[0016] Optionally, it also includes:

[0017] Monitor the usage duration of the server's fixed machine identifier. If the usage duration exceeds a preset duration, reapply for the server's fixed machine identifier from the coordination service center.

[0018] Based on the fixed machine identifier of the server that has been re-obtained, a first globally unique identifier is assigned to each first object.

[0019] No server can use a fixed machine identifier for more than a preset duration. If it does, a new fixed machine identifier must be applied for. After the preset duration, each fixed machine identifier will be unbound from the server and can be re-applied for by other servers. This enhances the liquidity of fixed machine identifiers and the flexibility of servers applying for them. It avoids the situation where a server becomes a "zombie machine identifier" because its fixed machine identifier cannot be applied for by other servers after it has gone offline.

[0020] Optionally, it also includes:

[0021] Add a fixed correspondence between the server and the fixed machine identifier of the server to the fixed correspondence stored in the coordination service center; the binding duration of the fixed correspondence is a preset duration.

[0022] A new fixed mapping relationship between servers and their fixed machine identifiers is added to the fixed mapping relationships stored in the coordination service center. This prevents the coordination service center from reassigning the fixed machine identifier to other servers. The binding duration of the fixed mapping relationship is set to a preset duration. After the preset duration, each fixed machine identifier will be unbound from the server and can be re-applied for by other servers. This enhances the mobility of fixed machine identifiers and the flexibility of servers applying for fixed machine identifiers. It avoids the situation where a server becomes offline and its corresponding fixed machine identifier cannot be applied for by other servers, thus becoming a "zombie ID." This method automates the cleanup, eliminating the need for manual operation and maintenance, and enabling the long-term automated operation of the cluster. It also allows fixed machine identifiers to be distributed as centrally as possible in the fixed machine identifier area of ​​the coordination service, increasing the probability of successful machine ID application.

[0023] Optionally, after obtaining the temporary machine identifier from the coordination service center, the method further includes:

[0024] A temporary correspondence between the server and the server's temporary machine identifier is added to each temporary correspondence stored in the coordination service center; the temporary correspondence expires when the next unit of time arrives.

[0025] Temporary mappings between servers and their temporary machine identifiers are added to the temporary mappings stored in the coordination service center. This prevents the coordination service center from reassigning a temporary machine identifier to another server. The temporary mappings are set to expire at the end of the next unit of time, allowing each temporary machine identifier to be re-applied for by other servers in the next unit of time. This enhances the liquidity of temporary machine identifiers and the flexibility of servers applying for them. It avoids situations where a server becomes offline and its corresponding temporary machine identifier cannot be applied for by other servers, thus becoming a "zombie ID." This method automates the cleanup process, eliminating the need for manual maintenance and enabling the long-term automated operation of the cluster. It also ensures that temporary machine identifiers are concentrated as much as possible in the coordination service's temporary machine identifier area, increasing the probability of successful machine ID application.

[0026] Optionally, it also includes:

[0027] Apply for lock removal from the coordination service center at preset intervals;

[0028] If a cleanup lock is obtained, then for any of the fixed correspondences, if the binding duration of the fixed correspondence meets the preset duration, the fixed correspondence is released.

[0029] This avoids the situation where a server crashes and cannot clear its corresponding relationship in the coordination service center, thus preventing the creation of "zombie IDs".

[0030] Optionally, it also includes:

[0031] After the unit time expires, the temporary correspondence between the server and the server's temporary machine identifier is terminated.

[0032] Since the temporary mapping relationship needs to be unbound after the unit time ends, using the method of applying for lock cleanup to unbind would consume too much computing resources. Therefore, it is set that after the unit time ends, the server will automatically release itself from the temporary mapping relationship with the temporary machine identifier in the coordination service.

[0033] Optionally, it also includes:

[0034] Once the number of second globally unique identifiers allocated based on the temporary machine identifier is detected to meet the preset threshold, a new temporary machine identifier for the server is requested from the coordination service center.

[0035] A second globally unique identifier is assigned to each second object based on the temporary machine identifier of the server that has been re-obtained.

[0036] If a temporary machine identifier cannot meet the concurrency requirements within a unit of time, a new temporary machine identifier will be obtained from the temporary ID area of ​​the coordination service. This can meet the high concurrency requirements of the distributed system and reduce the probability of downtime.

[0037] Secondly, embodiments of the present invention also provide a method for generating a globally unique identifier in a distributed system, the method being applied to a coordination service center; the method includes:

[0038] In response to a request to obtain a fixed machine identifier from any server, a fixed machine identifier is assigned to the server from a preset pool of fixed machine identifiers;

[0039] In response to a temporary machine identifier acquisition request from any server, a temporary machine identifier is allocated to the server from a preset pool of temporary machine identifiers; the sum of the number of fixed machine identifiers and the number of temporary machine identifiers is used to characterize the cluster scalability of the distributed system.

[0040] Optionally, the coordination service center assigns machine identifiers to each server through a distributed coordination service.

[0041] Optionally, the coordination service center stores fixed correspondences between each server and a fixed machine identifier; the validity period of the fixed correspondence is a preset duration.

[0042] Optionally, the coordination service center stores temporary correspondences between each server and a temporary machine identifier; the temporary correspondences expire when the next unit of time arrives.

[0043] Optionally, it also includes:

[0044] If any temporary correspondence is not terminated after any unit of time has elapsed, then the temporary correspondence is terminated.

[0045] Optionally, it also includes:

[0046] When the number of servers in the distributed system is detected to be greater than a first threshold, a first number of temporary machine identifiers from each temporary machine identifier are used as fixed machine identifiers; and / or,

[0047] When the number of servers in the distributed system is detected to be less than the second threshold, the second number of fixed machine identifiers among the fixed machine identifiers are used as temporary machine identifiers.

[0048] Thirdly, embodiments of the present invention also provide a device for generating a globally unique identifier in a distributed system, comprising:

[0049] Allocation unit, used for:

[0050] Within any given time period, a first globally unique identifier is assigned to the first object based on the server's fixed machine identifier and the first n-bit local identifier; the first n-bit local identifiers generated by the server within each time period are not duplicated; the fixed machine identifier is assigned to the server by the coordination service center from a preset pool of fixed machine identifiers;

[0051] A second globally unique identifier is assigned to the second object based on the server's temporary machine identifier and the second n-bit local identifier; the second n-bit local identifiers generated by the server within a unit of time are not repeated;

[0052] The generation unit is used to obtain a temporary machine identifier for the server from the coordination service center when the number of allocated first globally unique identifiers is detected to meet a preset threshold. The temporary machine identifier for the server is allocated to the server by the coordination service center from a preset set of temporary machine identifiers. The sum of the number of each fixed machine identifier and the number of each temporary machine identifier is used to characterize the cluster expansion performance of the distributed system.

[0053] Optionally, the coordination service center assigns machine identifiers to each server through a distributed coordination service.

[0054] Optionally, the generation unit is further configured to:

[0055] Monitor the usage duration of the server's fixed machine identifier. If the usage duration exceeds a preset duration, reapply for the server's fixed machine identifier from the coordination service center.

[0056] The allocation unit is further configured to: allocate a first globally unique identifier to each first object based on the fixed machine identifier of the server that has been re-obtained.

[0057] Optionally, the generation unit is further configured to:

[0058] Add a fixed correspondence between the server and the fixed machine identifier of the server to the fixed correspondence stored in the coordination service center; the binding duration of the fixed correspondence is a preset duration.

[0059] Optionally, the generation unit is further configured to:

[0060] A temporary correspondence between the server and the server's temporary machine identifier is added to each temporary correspondence stored in the coordination service center; the temporary correspondence expires when the next unit of time arrives.

[0061] Optionally, it also includes a scheduling unit, the scheduling unit being used for:

[0062] Apply for lock removal from the coordination service center at preset intervals;

[0063] If a cleanup lock is obtained, then for any of the fixed correspondences, if the binding duration of the fixed correspondence meets the preset duration, the fixed correspondence is released.

[0064] Optionally, the scheduling unit is further configured to:

[0065] After the unit time expires, the temporary correspondence between the server and the server's temporary machine identifier is terminated.

[0066] Optionally, the generation unit is further configured to:

[0067] Once the number of second globally unique identifiers allocated based on the temporary machine identifier is detected to meet the preset threshold, a new temporary machine identifier for the server is requested from the coordination service center.

[0068] The allocation unit is further configured to: allocate a second globally unique identifier to each second object based on the temporary machine identifier of the server that has been re-obtained.

[0069] Fourthly, embodiments of the present invention also provide a device for generating a globally unique identifier in a distributed system, comprising:

[0070] A fixed machine identifier allocation unit is used to allocate a fixed machine identifier to the server from a preset set of fixed machine identifiers in response to a fixed machine identifier acquisition request from any server.

[0071] A temporary machine identifier allocation unit is used to allocate a temporary machine identifier to the server from a preset pool of temporary machine identifiers in response to a temporary machine identifier acquisition request from any server; the sum of the number of fixed machine identifiers and the number of temporary machine identifiers is used to characterize the cluster expansion performance of the distributed system.

[0072] Optionally, the coordination service center assigns machine identifiers to each server through a distributed coordination service.

[0073] Optionally, the coordination service center stores fixed correspondences between each server and a fixed machine identifier; the validity period of the fixed correspondence is a preset duration.

[0074] Optionally, the coordination service center stores temporary correspondences between each server and a temporary machine identifier; the temporary correspondences expire when the next unit of time arrives.

[0075] Optionally, the temporary machine identifier allocation unit is further configured to:

[0076] If any temporary correspondence is not terminated after any unit of time has elapsed, then the temporary correspondence is terminated.

[0077] Optionally, it further includes an adjustment unit, the adjustment unit being used for:

[0078] When the number of servers in the distributed system is detected to be greater than a first threshold, a first number of temporary machine identifiers from each temporary machine identifier are used as fixed machine identifiers; and / or,

[0079] When the number of servers in the distributed system is detected to be less than the second threshold, the second number of fixed machine identifiers among the fixed machine identifiers are used as temporary machine identifiers.

[0080] Fifthly, embodiments of the present invention also provide a computing device, comprising:

[0081] Memory, used to store computer programs;

[0082] The processor is configured to invoke a computer program stored in the memory and execute, according to the obtained program, a method for generating a globally unique identifier in a distributed system as listed in any of the above methods.

[0083] In a sixth aspect, embodiments of the present invention also provide a computer-readable storage medium storing a computer-executable program, the computer-executable program being used to cause a computer to execute a method for generating a globally unique identifier in a distributed system as listed in any of the above methods. Attached Figure Description

[0084] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0085] Figure 1a A schematic diagram of a system architecture provided for an embodiment of the present invention;

[0086] Figure 1b This is a schematic diagram of machine identifiers in a fixed machine identifier area and a temporary machine identifier area of ​​a coordination service center, provided as an embodiment of the present invention.

[0087] Figure 2 A flowchart illustrating a method for generating a globally unique identifier in a distributed system, provided by an embodiment of the present invention;

[0088] Figure 3 This is a schematic flowchart illustrating a method for a server to apply for a fixed machine identifier from a coordination service center, as provided in an embodiment of the present invention.

[0089] Figure 4 A flowchart illustrating a method for generating a globally unique identifier on a server, as provided in an embodiment of the present invention;

[0090] Figure 5 A flowchart illustrating a method for allocating a globally unique identifier to a server, as provided in an embodiment of the present invention;

[0091] Figure 6 A flowchart illustrating a method for clearing fixed correspondences in a coordination service center by a server, as provided in an embodiment of the present invention;

[0092] Figure 7 A sequence diagram illustrating the overall nature of a method for generating a globally unique identifier in a distributed system, as provided in this embodiment of the invention.

[0093] Figure 8 This is a schematic diagram of the structure of a device for generating a globally unique identifier in a distributed system, provided in an embodiment of the present invention.

[0094] Figure 9This is a schematic diagram of the structure of a device for generating a globally unique identifier in a distributed system, provided in an embodiment of the present invention.

[0095] Figure 10 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Detailed Implementation

[0096] To make the objectives, implementation methods and advantages of this application clearer, the exemplary implementation methods of this application will be clearly and completely described below with reference to the accompanying drawings of the exemplary embodiments of this application. Obviously, the described exemplary embodiments are only some embodiments of this application, and not all embodiments.

[0097] Based on the exemplary embodiments described in this application, all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of the appended claims. Furthermore, although the disclosures in this application are presented by way of one or more exemplary examples, it should be understood that each aspect of these disclosures can also constitute a complete implementation on its own.

[0098] It should be noted that the brief descriptions of terms in this application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise stated, these terms should be understood in their ordinary and common meaning.

[0099] The terms "first," "second," "third," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar or related objects or entities and do not necessarily imply a specific order or sequence, unless otherwise indicated. It should be understood that such terms can be used interchangeably where appropriate, for example, to implement the application in a sequence other than those given in the embodiments illustrated or described herein.

[0100] Furthermore, the terms “comprising” and “having”, and any variations thereof, are intended to cover but not exclusively include, for example, a product or device that includes a series of components is not necessarily limited to those that are explicitly listed, but may include other components that are not explicitly listed or that are inherent to such product or device.

[0101] When business operations are subject to strict limitations on the number of bits in globally unique identifiers, it becomes impossible to achieve a balance between high scalability and high concurrency in clustering. One possible scenario is that some business operations have limitations on the number of bits in the globally unique identifier, preventing it from being too long. For example, if we need to use this globally unique identifier as an identifier for a business task for user queries, an excessively long globally unique identifier is difficult to remember; moreover, passing the globally unique identifier as input to other systems carries higher risks (for example, some systems limit the number of bits allowed in the input). Another possible scenario is when the Snowflake algorithm needs to replace the old globally unique identifier algorithm. To ensure that users do not perceive a change in the number of bits, the number of bits in the globally unique identifier generated by the Snowflake algorithm should remain consistent with the number of bits in the old algorithm.

[0102] Figure 1a An exemplary system architecture applicable to embodiments of the present invention is illustrated, comprising multiple servers (e.g., in a distributed system) Figure 1a The server shown is 100, 200 and 300, and the coordination service center is 400.

[0103] In a distributed system, multiple servers generate a large amount of data, messages, threads, processes, and other objects within a unit of time. To uniquely identify these objects and ensure the orderliness and traceability of task execution, a globally unique identifier is assigned to each object in the distributed system. For example, a globally unique identifier is assigned to a currently executing thread; a globally unique identifier is assigned to an order or a coupon; a globally unique identifier is assigned to a user or a delivery rider, and so on. These are just examples, and the embodiments of this invention do not limit the scenarios for assigning globally unique identifiers.

[0104] The server described in this embodiment of the invention can be a physical server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.

[0105] The coordination service center 400 stores multiple machine identifiers. Upon receiving a request to obtain a machine identifier from any server in the distributed system, the coordination service center assigns a machine identifier to each server. The coordination service center can be divided into two storage areas: a fixed machine identifier area and a temporary machine identifier area. The fixed machine identifier area stores preset fixed machine identifiers; the temporary machine identifier area stores preset temporary machine identifiers. If the coordination service center receives a request to obtain a fixed machine identifier from any server, it assigns a fixed machine identifier to that server from the fixed machine identifier area; if the coordination service center receives a request to obtain a temporary machine identifier from any server, it assigns a temporary machine identifier to that server from the temporary machine identifier area.

[0106] If the server's machine identifier is specified as an m-digit number, then the sum of the number of fixed machine identifiers in the fixed machine identifier area and the number of temporary machine identifiers in the temporary machine identifier area is 10. m The number of fixed machine identifiers in the fixed machine identifier area and the number of temporary machine identifiers in the temporary machine identifier area can be flexibly adjusted based on the experience of those skilled in the art and actual needs. For example, if m=3, the sum of the number of fixed machine identifiers in the fixed machine identifier area and the number of temporary machine identifiers in the temporary machine identifier area is 1000. For example, 400 numbers from 000 to 399 can be used as fixed machine identifiers in the fixed machine identifier area; and 600 numbers from 400 to 999 can be used as temporary machine identifiers in the temporary machine identifier area. For example, 500 numbers from 000 to 499 can also be used as fixed machine identifiers in the fixed machine identifier area; and 500 numbers from 500 to 999 can be used as temporary machine identifiers in the temporary machine identifier area. The above are merely examples, and the embodiments of the present invention do not limit this.

[0107] The number of fixed machine identifiers in the fixed machine identifier area can be determined based on the number of servers in the current distributed system. It can also be flexibly adjusted according to changes in the number of servers. When the number of servers in the distributed system is detected to be greater than a first threshold, a first number of temporary machine identifiers from the temporary machine identifiers are used as fixed machine identifiers; and / or, when the number of servers in the distributed system is detected to be less than a second threshold, a second number of fixed machine identifiers from the fixed machine identifiers are used as temporary machine identifiers.

[0108] For example, if there are 500 servers in the current distributed system, the fixed machine identifier area can contain 600 fixed machine identifiers, ranging from 400 to 999; the temporary machine identifier area can contain 400 temporary machine identifiers, ranging from 000 to 399. When the distributed system is expanded and the number of servers increases to 650, which is greater than the first threshold of 600, 200 temporary machine identifiers can be allocated from the temporary machine identifier area to the fixed machine identifier area as fixed machine identifiers. Then, the fixed machine identifier area will contain 800 fixed machine identifiers, ranging from 200 to 999; and the temporary machine identifier area will contain 200 temporary machine identifiers, ranging from 000 to 199. When scaling down in a distributed system, and the number of servers drops to 350, which is less than the second threshold of 400, 100 fixed machine identifiers can be allocated from the fixed machine identifier area to the temporary machine identifier area as temporary machine identifiers. Then, the fixed machine identifier area contains 500 fixed machine identifiers, ranging from 500 to 999; and the temporary machine identifier area contains 500 temporary machine identifiers, ranging from 000 to 499.

[0109] Therefore, the sum of the number of fixed machine identifiers in the fixed machine identifier area and the number of temporary machine identifiers in the temporary machine identifier area can be used to characterize the cluster scalability of the distributed system. If m=3, then the number of scalable servers in the distributed system is 1000. That is to say, although a fixed machine identifier area and a temporary machine identifier area are divided, each temporary machine identifier in the temporary machine identifier area can be transferred to the fixed machine identifier area as a fixed machine identifier due to cluster expansion.

[0110] Figure 1b The diagram shows machine identifiers in a fixed machine identifier area and a temporary machine identifier area of ​​a possible coordination service center provided by an embodiment of the present invention.

[0111] The coordination service center achieves atomicity in assigning machine identifiers to servers through various functionalities. For example, it can design a distributed atomic counter in the database to ensure the atomicity of machine identifier distribution, preventing different servers from obtaining the same machine identifier. Alternatively, the coordination service center can assign machine identifiers to servers through a distributed coordination service. This distributed coordination service can be middleware such as ZooKeeper. Because the distributed coordination service has built-in distributed atomic counting functionality, it can guarantee the atomicity of machine identifier distribution, preventing different servers from obtaining the same machine identifier.

[0112] Based on the above system architecture, embodiments of the present invention provide a method for generating globally unique identifiers in a distributed system, such as... Figure 2 As shown, it includes:

[0113] Step 201: Any server requests a fixed machine identifier from the coordination service center.

[0114] Step 202: In response to a request from any server to obtain a fixed machine identifier, the coordination service center assigns a fixed machine identifier to the server from a set of preset fixed machine identifiers.

[0115] Step 203: Any server, within any unit of time, assigns a first globally unique identifier to the first object based on the server's fixed machine identifier and the first n-bit local identifier.

[0116] Step 204: When any server detects that the number of allocated first globally unique identifiers meets a preset threshold, it applies to the coordination service center to obtain a temporary machine identifier for the server.

[0117] Step 205: In response to a temporary machine identifier acquisition request from any server, the coordination service center allocates a temporary machine identifier to the server from a set of preset temporary machine identifiers.

[0118] Step 206: Any server assigns a second globally unique identifier to the second object based on the server's temporary machine identifier and the second n-bit local identifier; the second n-bit local identifiers generated by the server within a unit of time are not repeated.

[0119] In step 201, any server requests the fixed machine identifier of the server from the coordination service center at preset intervals.

[0120] The server monitors the usage duration of the current fixed machine identifier. If the usage duration exceeds the preset duration, it reapplies for a fixed machine identifier from the coordination service center. The preset duration is set by those skilled in the art based on their needs or experience; for example, it can be 12 hours or 24 hours. The process of applying for a machine identifier from the coordination service center is computationally resource-intensive. Therefore, a longer preset duration will save computational resources and reduce the possibility of downtime. However, if the preset duration is too long, such as one month, the server will be bound to the fixed machine identifier for a full month. If the server crashes or goes offline on the second day of that month, the fixed machine identifier will remain bound to that crashed or offline server for a long time, making it unusable by other servers and thus becoming a "zombie machine identifier."

[0121] For example, a server applies for a fixed machine identifier 400 from the coordination service center at 0:00 on June 20, 2022, with a preset duration of 12 hours. If the server detects that the usage duration of the fixed machine identifier 400 exceeds 12 hours at 12:00 on June 20, 2022, it will reapply for a fixed machine identifier from the coordination service center, for example, obtaining 600. If the preset duration is 30 days, and the server goes offline the day after obtaining the fixed machine identifier 400, then the fixed machine identifier 400 will be bound to the offline server for the next 29 days and cannot be bound to other normally functioning servers, thus becoming a "zombie machine identifier".

[0122] In step 202, in response to a request from any server to obtain a fixed machine identifier, the coordination service center assigns a fixed machine identifier to the server from a set of preset fixed machine identifiers.

[0123] As mentioned above, the coordination service center is divided into a fixed machine identifier area and a temporary machine identifier area. When any server requests a fixed machine identifier from the coordination service center, the coordination service center can select an unused fixed machine identifier from the various fixed machine identifiers in the fixed machine identifier area and assign that fixed machine identifier to the server. For example, the unused fixed machine identifier 400 is assigned to this server.

[0124] In step 203, any server assigns a first globally unique identifier to the first object based on the server's fixed machine identifier and the first n-bit local identifier within any unit of time.

[0125] For example, for a server that has previously obtained a fixed machine identifier 400, a first globally unique identifier will be generated based on the fixed machine identifier 400 within any unit of time before the preset duration is reached, and this first globally unique identifier will be assigned to a first object. This object can be a process, thread, user, message, or data, etc. Those skilled in the art are not limited in this regard.

[0126] In one possible embodiment, when a request to obtain a globally unique identifier for a first object is received within any unit of time, a first n-bit local identifier is generated, a first globally unique identifier is generated based on the first n-bit local identifier, and the first globally unique identifier is assigned to the first object.

[0127] Another possible implementation involves generating multiple first n-bit local identifiers within any given unit of time, generating multiple first globally unique identifiers based on these first n-bit local identifiers, and storing these multiple first globally unique identifiers in a buffer. When a request to obtain a globally unique identifier for a first object is received, any first globally unique identifier is retrieved from the buffer and assigned to that first object. This approach avoids potential race conditions and better supports high concurrency.

[0128] The specific method for generating the first globally unique identifier is as follows: The first globally unique identifier is generated by combining the current unit time timestamp, the fixed machine identifier, and the first n-bit local identifier. The unit time can be accurate to the second, minute, hour, etc., and this embodiment of the invention does not impose any limitations on this. For example, if the current timestamp is 20220421172400 and the fixed machine identifier is 400, then a first globally unique identifier of 10 is generated. n The first nth local identifier, according to 10 n Generate 10 local identifiers from the first nth bit. n Each first globally unique identifier is stored in a buffer. For example, if n=3, 1000 first n-bit local identifiers from 000 to 999 are generated, and 1000 first globally unique identifiers are generated based on these 1000 first n-bit local identifiers and stored in the buffer. For any thread currently running on the server, a first globally unique identifier is assigned: 20220421172400_400_000; for the next thread, a first globally unique identifier is assigned: 20220421172400_400_001... until the current unit of time ends, or the number of first globally unique identifiers assigned meets a preset threshold, that is, the usage of the first n-bit local identifiers reaches the preset threshold. For example, if the current unit of time ends, the timestamp needs to be changed, and the first globally unique identifier generated afterward might be: 20220421172401_400_000, 20220421172401_400_001, 20220421172401_400_002, and so on. Alternatively, if the current unit of time has not ended, but the usage of the first n-bit local identifier has reached the preset threshold of 800, meaning 800 threads have been allocated the first globally unique identifier within the current unit of time, then step 204 will be executed.

[0129] In the above method, the timestamp setting ensures that the first globally unique identifier generated in different units of time will not be repeated; the fixed machine identifier setting ensures that the first globally unique identifier generated between different servers will not be repeated; the first n-bit local identifier will not be repeated in any unit of time, thus ensuring that different first objects running on the server will obtain the first globally unique identifier without duplication.

[0130] In step 204, when any server detects that the number of allocated first globally unique identifiers meets a preset threshold, it applies to the coordination service center to obtain a temporary machine identifier for the server.

[0131] If, within the current unit of time, the usage of the first n-bit local identifier reaches a preset threshold (for example, if there are 1000 first n-bit local identifiers, representing numbers from 000 to 999), then the number of first globally unique identifiers that can be generated within the current unit of time is 1000. When the number of allocated first globally unique identifiers reaches the preset threshold, it indicates that the current unit of time is experiencing peak business activity, and 1000 concurrent requests may not be sufficient. The preset threshold is set based on experience or needs in this field and is not limited; for example, it can be any value such as 800, 900, or 950.

[0132] Once the number of the first globally unique identifiers assigned is detected to meet the preset threshold, a temporary machine identifier is requested from the coordination service center.

[0133] In step 205, after receiving the temporary machine identifier acquisition request from the server, the coordination service center will obtain a temporary machine identifier from the temporary machine identifier area and assign the temporary machine identifier to the server.

[0134] For example, the coordination service center assigns 001 to this server.

[0135] In step 206, the server assigns a second globally unique identifier to the second object based on a temporary machine identifier and a second n-bit local identifier. The second n-bit local identifiers generated by the server within a unit of time are all unique.

[0136] For example, within the current unit of time, the server generates 1000 numbers from 000 to 999 as the second n-bit local identifier. Based on the second n-bit local identifier, 1000 second globally unique identifiers are generated and placed in a buffer. When a request to obtain the second globally unique identifier of a second object is received, any second globally unique identifier is retrieved from the buffer and assigned to that second object. The second globally unique identifiers are 20220421172400_001_000, 20220421172400_001_001, 20220421172400_001_002, etc., until the current unit of time ends, or the number of assigned second globally unique identifiers meets a preset threshold, that is, the usage of the second n-bit local identifiers reaches the preset threshold. For example, when the current unit of time ends, the timestamp needs to be changed, and a first globally unique identifier will continue to be generated based on a fixed machine identifier, such as: 20220421172401_400_000, 20220421172401_400_001, 20220421172401_400_002, and so on. Alternatively, if the current unit of time has not ended, but the usage of the second n-bit local identifier has reached the preset threshold of 800, and 800 threads have been allocated a second globally unique identifier within the current unit of time, then the server will again request a temporary machine identifier from the coordination service center. Based on this newly obtained temporary machine identifier, a second globally unique identifier will be generated. For example, if the reacquired temporary machine identifier is 002, then the second globally unique identifier is 20220421172400_002_000, 20220421172400_002_001, 20220421172400_001_002, and so on.

[0137] It can be observed that in the above method, when the server is at a peak of business activity and has high concurrency at any given time, it can apply for temporary machine identifiers from the coordination service center to "emerge" and change the machine identifier for the current time, thereby improving the high concurrency of the cluster. For example, in existing technologies, when the number of bits in the machine identifier is 3 and the number of bits in the auto-incrementing identifier is also 3, the number of scalable machines in the cluster is 1000, and the concurrency is only 1000. However, in this scheme, when the number of bits in the machine identifier is 3 and the number of bits in the n-bit local identifier is also 3, since fixed machine identifiers and temporary machine identifiers are divided, the number of scalable machines in the cluster is still 1000 (because temporary machine identifiers in the temporary machine identifier area can be flexibly allocated to the fixed machine identifier area according to the expansion of the distributed system, becoming fixed machine identifiers), but the concurrency is greatly increased, not just 1000, because each temporary machine identifier in the temporary machine identifier area can be used to generate a second globally unique identifier. For example, if there are 400 temporary machine identifiers in the temporary machine identifier area, all 400 temporary machine identifiers can be used by the server in the current unit of time, resulting in a concurrency of 400 × 1000. Therefore, the above method can improve concurrency performance while ensuring the high scalability of the cluster.

[0138] After the current unit of time ends, the process will continue with steps 201-206, continuing to generate the first globally unique identifier using the fixed machine identifier.

[0139] Within any given time period, a first globally unique identifier is assigned to a first object based on the server's fixed machine identifier and the first n-bit local identifier. Once the number of assigned first globally unique identifiers meets a preset threshold, a temporary machine identifier is obtained from the coordination service center. A second globally unique identifier is then assigned to a second object based on the server's temporary machine identifier and the second n-bit local identifier. Thus, when the concurrency of any server is low within a given time period, only the fixed machine identifier is used to generate the first globally unique identifier; when the concurrency of any server is high within a given time period, globally unique identifiers are generated not only through the fixed machine identifier but also based on the temporary machine identifier. This method allows servers to flexibly request machine identifiers without limiting the number of machine identifiers a server can request. It satisfies the high scalability requirements of distributed systems and can expand the number of globally unique identifiers a server can generate when the workload of any server in the distributed system is at its peak, thus meeting the high concurrency requirements of distributed systems.

[0140] In one possible implementation, the first n-bit local identifier is not randomly generated, but rather auto-incremented. For example, the auto-increment identifier starts from 0 and increments by 1 sequentially until it reaches 999. This generated auto-increment identifier is combined with a timestamp and a fixed machine identifier to generate a first globally unique identifier, which is then placed in a buffer. When the first object requests an identifier, a first globally unique identifier is retrieved sequentially from the buffer and assigned to that first object.

[0141] The second n-bit local identifier is not randomly generated, but rather auto-incremented. When the number of allocated first globally unique identifiers meets a preset threshold, a temporary machine identifier is obtained. The auto-incrementing identifier is set to 0, and starting from 0, it is incremented by 1 sequentially until 999, thus obtaining the second n-bit local identifier…

[0142] Another existing technology for generating globally unique identifiers is to utilize a distributed coordination service like ZooKeeper. For example, ZooKeeper generates 10 unique identifiers within any given time period. k A unique k-digit number. For any server in a distributed system, for any object running on that server, a k-digit number is requested from ZooKeeper. The obtained k-digit number is combined with a timestamp to obtain a globally unique identifier: timestamp_k-digit number. In this way, the globally unique identifiers generated by each server in the distributed system within any unit of time will not be duplicated.

[0143] However, the problem with the above method is that each server requests a k-bit number from ZooKeeper for each thread it runs, and all servers can only request a maximum of 10 bits per unit of time. k After obtaining the k-digit number, each server writes a globally unique identifier derived from the k-digit number and a timestamp into ZooKeeper. These operations consume excessive CPU, memory, and other system resources for ZooKeeper. When the number of requests exceeds a certain level, ZooKeeper's response speed slows down significantly, and may even cause ZooKeeper to crash, making it unable to handle high-concurrency globally unique identifier generation scenarios. Therefore, using the above method not only leads to frequent ZooKeeper failures, but also the number of k-digit numbers that all servers can request per unit of time is far less than 10. k Furthermore, due to the inherent characteristics of ZooKeeper, this problem cannot be solved by scaling up ZooKeeper.

[0144] In this embodiment of the invention, although a distributed coordination service, such as ZooKeeper, is used, a fixed machine identifier is requested only once every preset time interval, for example, 12 hours as mentioned above. For temporary machine identifiers, a request is only made to ZooKeeper within a unit of time when concurrency is high; if concurrency is even higher, another request is made, and so on. This is far less than the scale of prior art where every thread requests an identifier from ZooKeeper. Therefore, it avoids slow ZooKeeper response times and crashes.

[0145] When using existing technologies like the Snowflake or Leaf-Segment algorithms to generate globally unique identifiers, the relationship between each server and its machine identifier is completely bound and unchanging, leading to the creation of "zombie machine identifiers." For example, server A is bound to machine identifier 400, server B to machine identifier 401, and server C to machine identifier 402. This binding relationship is stored in an external storage system. After a period of time, server A crashes, and server B goes offline, leaving machine identifiers 400 and 401 idle. Because the binding relationship between server A and machine identifier 400, and server B and machine identifier 401, still exists in the external storage system, machine identifiers 400 and 401 cannot be used by other servers, thus becoming "zombie machine identifiers." As the number of offline or crashed servers increases, the number of "zombie machine identifiers" also increases. Newly added servers will face a situation where no machine identifiers are available for allocation, ultimately rendering the entire cluster unusable.

[0146] The above-mentioned problems are solved in the embodiments of this application. The binding duration of the fixed correspondence between any server and a fixed machine identifier is a preset duration. When the preset duration is reached, the fixed correspondence is released in the coordination service. The binding duration of the temporary correspondence between any server and a temporary machine identifier is one unit of time. When the unit of time is reached, the temporary correspondence is released in the coordination service. Then, the fixed machine identifier and the temporary machine identifier, after being released, can be applied for and used by other servers.

[0147] Specifically, the method provided in this embodiment of the invention further includes: adding a fixed correspondence between the server and the fixed machine identifier of the server to each fixed correspondence stored in the coordination service center; the binding duration of the fixed correspondence is a preset duration.

[0148] Once a server obtains a fixed machine identifier from the coordination service center, it writes a fixed correspondence between itself and that identifier into the coordination service center, for example, server A-400. This prevents the coordination service center from reassigning the fixed machine identifier to other servers.

[0149] Furthermore, the binding duration of this fixed mapping relationship is a preset duration. Therefore, it is necessary to periodically clean up the fixed mapping relationships in the coordination service center. The cleanup logic is to remove fixed mapping relationships in the coordination service center whose binding duration meets the preset duration. Three cleanup methods are provided below.

[0150] Method 1

[0151] For any server, after determining that the binding duration of its fixed correspondence with a certain fixed machine identifier is a preset duration, it initiates a cleanup request to the coordination service center, only cleaning up its fixed correspondence with a certain fixed machine identifier.

[0152] For example, the coordination service center stores the following fixed mapping relationships: Server A-400, Server B-401, and Server C-402. After determining that the usage duration of the current fixed machine identifier meets the preset duration, Server A initiates a cleanup request to the coordination service center, clearing the fixed mapping relationship for Server A-400. Similarly, after determining that the usage duration of the current fixed machine identifier meets the preset duration, Server B initiates a cleanup request to the coordination service center, clearing the fixed mapping relationship for Server B-401.

[0153] A potential problem with the above method is that if the server crashes or goes offline before the preset duration of using the fixed machine identifier, it's impossible to determine whether the binding duration has been reached, and therefore, a cleanup action cannot be initiated. This would still result in the fixed machine identifier becoming a "zombie machine identifier."

[0154] Method 2

[0155] For any server, a cleanup lock is requested from the coordination service center at a preset interval. If a cleanup lock is obtained, the fixed correspondence is released when the binding duration of the fixed correspondence meets the preset duration for any of the fixed correspondences.

[0156] For example, the coordination service center stores the following fixed mappings: Server A-400, Server B-401, and Server C-402. It also records the creation time of each fixed mapping. If Server A acquires a cleanup lock at any time, it iterates through all the fixed mappings in the coordination service center, checking if the difference between the current time and the creation time of any fixed mapping meets the preset duration of 12 hours. If it does, the mapping is cleaned up. For example, the fixed mappings for Servers A-400 and B-401 are cleaned up.

[0157] The second method was used for cleanup, which avoids the situation where the corresponding relationship cannot be cleaned up in the coordination service center after any server goes down, thus avoiding the situation of "zombie IDs".

[0158] Method 3

[0159] The coordination service center monitors the fixed mapping relationships stored within itself. When the binding duration of any fixed mapping relationship reaches a preset time, the coordination service center automatically cleans up the fixed mapping relationship. However, if the coordination service center is a database, such as the distributed coordination service ZooKeeper, it cannot initiate the cleanup of fixed mapping relationships automatically and must use methods one and two for cleanup.

[0160] Setting the binding duration of fixed mappings to a preset duration ensures that each fixed machine ID is unbound from the server after the preset duration, allowing it to be re-applied for by other servers. This enhances the liquidity of fixed machine IDs and the flexibility of servers applying for them. It prevents situations where a server becomes offline and its corresponding fixed machine ID cannot be applied for by other servers, thus becoming a "zombie ID." This method automates the cleanup, eliminating the need for manual intervention and enabling the long-term automated operation of the cluster. The method of periodically unbinding fixed mappings also ensures that fixed machine IDs are distributed as centrally as possible within the fixed machine ID area of ​​the coordination service, increasing the probability of successful machine ID application.

[0161] The method provided in this embodiment of the invention further includes: adding a temporary correspondence between the server and the temporary machine identifier of the server to each temporary correspondence stored in the coordination service center; the temporary correspondence expires when the next unit of time arrives.

[0162] Once a server obtains a temporary machine identifier from the coordination service center, it writes a temporary mapping between itself and that machine identifier into the coordination service center, for example, server A-000. This prevents the coordination service center from reassigning the temporary machine identifier to other servers.

[0163] Furthermore, this temporary mapping expires when the next unit of time arrives. Therefore, it is necessary to periodically clean up the temporary mappings in the coordination service center. Three cleanup methods are provided below.

[0164] Method 1

[0165] For any server, after the unit time ends, it applies to the coordination service center for a cleanup lock. If the cleanup lock is obtained, it cleans up any temporary correspondence in the coordination service center.

[0166] For example, the coordination service center stores the following temporary mappings: server A-000, server B-001, and server C-002. If server A acquires a cleanup lock after the current unit of time expires, it will clean up all temporary mappings in the coordination service center, for example, cleaning up the three temporary mappings for servers A-000, B-001, and C-002.

[0167] The problem with the above method is that it requests lock clearing from the coordination service center every unit of time, which consumes a lot of the coordination service center's computing resources and can easily cause system crashes and other failures.

[0168] Method 2

[0169] For any given server, after the unit time ends, a cleanup request is sent to the coordination service center, which only cleans up the temporary correspondence between itself and the temporary machine identifier.

[0170] For example, the coordination service center stores the following temporary mappings: Server A-000, Server B-001, and Server C-002. At the end of each unit of time, Server A initiates a cleanup request to the coordination service center, clearing the temporary mapping for Server A-000. At the end of each unit of time, Server B initiates a cleanup request to the coordination service center, clearing the temporary mapping for Server B-001. At the end of each unit of time, Server C initiates a cleanup request to the coordination service center, clearing the temporary mapping for Server C-002.

[0171] The above method solves the problem encountered in Method 1, but the following situation may also occur: if the server crashes or goes offline before the unit time ends, the cleanup action cannot be initiated. In this case, the temporary machine identifier will become a "zombie machine identifier".

[0172] To address this issue, if the coordination service center is a distributed coordination service like ZooKeeper, ZooKeeper's ephemeral node mechanism can be used to enable the coordination service center to proactively clean up these ephemeral relationships. If the coordination service center is a distributed storage system like Redis, Redis's timeout management mechanism can be used to enable the coordination service center to proactively clean up these ephemeral relationships. Specifically, after any unit of time has elapsed, if the coordination service detects that any ephemeral relationship has not been terminated, it will terminate the ephemeral relationship.

[0173] Temporary mappings between servers and their temporary machine identifiers are added to the temporary mappings stored in the coordination service center. This prevents the coordination service center from reassigning a temporary machine identifier to another server. The temporary mappings are set to expire at the end of the next unit of time, allowing each temporary machine identifier to be re-applied for by other servers in the next unit of time. This enhances the liquidity of temporary machine identifiers and the flexibility of servers applying for them. It avoids situations where a server becomes offline and its corresponding temporary machine identifier cannot be applied for by other servers, thus becoming a "zombie ID." This method automates the cleanup process, eliminating the need for manual maintenance and enabling the long-term automated operation of the cluster. It also ensures that temporary machine identifiers are concentrated as much as possible in the coordination service's temporary machine identifier area, increasing the probability of successful machine ID application.

[0174] To better explain the embodiments of the present invention, the method for generating globally unique identifiers in the above-described distributed system will be described in detail below.

[0175] Figure 3 The flowchart illustrates a method for a server to apply for a fixed machine identifier from a coordination service center, according to an embodiment of the present invention, including:

[0176] Step 301: The server applies to the coordination service center for a fixed machine identifier.

[0177] Step 302: The server stores the obtained fixed machine identifier into the server's memory.

[0178] The new fixed machine identifier obtained will replace the previous fixed machine identifier.

[0179] Step 303: The server writes the obtained fixed machine identifier into the coordination service center.

[0180] Step 304: After waiting for a preset time, the server returns to step 301.

[0181] Figure 4 The flowchart illustrates a method for generating a globally unique identifier on a server according to an embodiment of the present invention, including:

[0182] Step 401: Obtain the current timestamp.

[0183] Step 402: Obtain the fixed machine identifier in memory.

[0184] Step 403: Use the fixed machine identifier as the machine identifier.

[0185] Step 404: Generate a globally unique identifier using a timestamp, machine identifier, and auto-incrementing identifier.

[0186] Step 405: Write the globally unique identifier into the buffer.

[0187] Step 406: Determine whether the number of globally unique identifiers assigned to the ID buffer meets the preset threshold. If yes, proceed to step 407. If no, proceed to step 408.

[0188] Step 407: Obtain a temporary machine identifier from the Coordination Service Center.

[0189] Step 408: Determine if the current unit of time has ended. If yes, return to step 401; otherwise, return to step 406.

[0190] Step 409: Use the temporary machine identifier as the machine identifier.

[0191] Step 410: Set the auto-incrementing flag to 0. Return to step 404.

[0192] Figure 5 The flowchart illustrates a method for allocating globally unique identifiers on a server according to an embodiment of the present invention, including:

[0193] Step 501: Obtain a globally unique identifier request for any object.

[0194] Step 502: Access the buffer that stores the globally unique identifier request and obtain the globally unique identifier.

[0195] Step 503: Determine whether the globally unique identifier was successfully obtained. If yes, proceed to step 504; otherwise, return to step 502.

[0196] Step 504: Assign the obtained globally unique identifier to the object.

[0197] Figure 6 The flowchart illustrates a method for cleaning up fixed correspondences in a coordination service center by a server, according to an embodiment of the present invention, including:

[0198] Step 601: Apply to the coordination service center to clear the lock according to the preset interval.

[0199] If the coordination service center is a distributed coordination service, then a distributed cleanup lock will be requested from the distributed coordination service at preset intervals.

[0200] Step 602: Determine whether the lock clearing application was successful. If yes, proceed to step 603; otherwise, return to step 601.

[0201] Step 603: Delete all fixed correspondences in the coordination service center that have reached the preset duration.

[0202] For example, if a fixed mapping exists in the distributed coordination service ZooKeeper as ZooKeeper nodes, then all ZooKeeper nodes in the distributed coordination service that have reached the preset creation time will be deleted.

[0203] Figure 7 This diagram illustrates the overall timing of a method for generating globally unique identifiers in a distributed system, as provided in an embodiment of the present invention. The execution of this method involves a scheduling unit, a generation unit, an allocation unit, a buffer, and a fixed machine identifier area and a temporary machine identifier area for a distributed coordination service.

[0204] Based on the same technological concept Figure 8 An exemplary embodiment of the present invention illustrates the structure of a device for generating globally unique identifiers in a distributed system, which can execute the process of generating globally unique identifiers in a distributed system.

[0205] like Figure 8 As shown, the device specifically includes:

[0206] Allocation unit 801 is used for:

[0207] Within any given time period, a first globally unique identifier is assigned to the first object based on the server's fixed machine identifier and the first n-bit local identifier; the first n-bit local identifiers generated by the server within each time period are not duplicated; the fixed machine identifier is assigned to the server by the coordination service center from a preset pool of fixed machine identifiers;

[0208] A second globally unique identifier is assigned to the second object based on the server's temporary machine identifier and the second n-bit local identifier; the second n-bit local identifiers generated by the server within a unit of time are not repeated;

[0209] The generation unit 802 is used to obtain the temporary machine identifier of the server from the coordination service center after detecting that the number of allocated first globally unique identifiers meets a preset threshold; the temporary machine identifier of the server is allocated to the server by the coordination service center from a preset number of temporary machine identifiers; the sum of the number of each fixed machine identifier and the number of each temporary machine identifier is used to characterize the cluster expansion performance of the distributed system.

[0210] Optionally, the coordination service center assigns machine identifiers to each server through a distributed coordination service.

[0211] Optionally, the generation unit 802 is further configured to:

[0212] Monitor the usage duration of the server's fixed machine identifier. If the usage duration exceeds a preset duration, reapply for the server's fixed machine identifier from the coordination service center.

[0213] The allocation unit 801 is further configured to: allocate a first globally unique identifier to each first object based on the fixed machine identifier of the server that has been re-obtained.

[0214] Optionally, the generation unit 802 is further configured to:

[0215] Add a fixed correspondence between the server and the fixed machine identifier of the server to the fixed correspondence stored in the coordination service center; the binding duration of the fixed correspondence is a preset duration.

[0216] Optionally, the generation unit 802 is further configured to:

[0217] A temporary correspondence between the server and the server's temporary machine identifier is added to each temporary correspondence stored in the coordination service center; the temporary correspondence expires when the next unit of time arrives.

[0218] Optionally, it also includes a scheduling unit 803, the scheduling unit 803 being used for:

[0219] Apply for lock removal from the coordination service center at preset intervals;

[0220] If a cleanup lock is obtained, then for any of the fixed correspondences, if the binding duration of the fixed correspondence meets the preset duration, the fixed correspondence is released.

[0221] Optionally, the scheduling unit 803 is further configured to:

[0222] After the unit time expires, the temporary correspondence between the server and the server's temporary machine identifier is terminated.

[0223] Optionally, the generation unit 802 is further configured to:

[0224] Once the number of second globally unique identifiers allocated based on the temporary machine identifier is detected to meet the preset threshold, a new temporary machine identifier for the server is requested from the coordination service center.

[0225] The allocation unit 801 is further configured to: allocate a second globally unique identifier to each second object based on the temporary machine identifier of the server that has been re-obtained.

[0226] Based on the same technological concept Figure 9An exemplary embodiment of the present invention illustrates the structure of a device for generating globally unique identifiers in a distributed system, which can execute the process of generating globally unique identifiers in a distributed system.

[0227] like Figure 9 As shown, it includes:

[0228] The fixed machine identifier allocation unit 901 is used to allocate a fixed machine identifier to the server from a preset set of fixed machine identifiers in response to a fixed machine identifier acquisition request from any server.

[0229] The temporary machine identifier allocation unit 902 is used to allocate a temporary machine identifier to the server from a preset set of temporary machine identifiers in response to a temporary machine identifier acquisition request from any server; the number of each fixed machine identifier and the sum of the number of each temporary machine identifier are used to characterize the cluster expansion performance of the distributed system.

[0230] Optionally, the coordination service center assigns machine identifiers to each server through a distributed coordination service.

[0231] Optionally, the coordination service center stores fixed correspondences between each server and a fixed machine identifier; the validity period of the fixed correspondence is a preset duration.

[0232] Optionally, the coordination service center stores temporary correspondences between each server and a temporary machine identifier; the temporary correspondences expire when the next unit of time arrives.

[0233] Optionally, the temporary machine identifier allocation unit 902 is further configured to:

[0234] If any temporary correspondence is not terminated after any unit of time has elapsed, then the temporary correspondence is terminated.

[0235] Optionally, it also includes an adjustment unit 903, the adjustment unit 903 being used for:

[0236] When the number of servers in the distributed system is detected to be greater than a first threshold, a first number of temporary machine identifiers from each temporary machine identifier are used as fixed machine identifiers; and / or,

[0237] When the number of servers in the distributed system is detected to be less than the second threshold, the second number of fixed machine identifiers among the fixed machine identifiers are used as temporary machine identifiers.

[0238] Based on the same technical concept, embodiments of this application provide a computer device, such as... Figure 10As shown, it includes at least one processor 1001 and a memory 1002 connected to at least one processor. In this embodiment, the specific connection medium between the processor 1001 and the memory 1002 is not limited. Figure 10 Taking the connection between processor 1001 and memory 1002 via a bus as an example. The bus can be divided into address bus, data bus, control bus, etc.

[0239] In this embodiment of the application, the memory 1002 stores instructions that can be executed by at least one processor 1001. By executing the instructions stored in the memory 1002, at least one processor 1001 can perform the steps of the above-described method for generating a globally unique identifier in a distributed system.

[0240] The processor 1001 is the control center of the computer device, capable of connecting various parts of the computer device via various interfaces and lines. It generates globally unique identifiers in the distributed system by running or executing instructions stored in the memory 1002 and accessing data stored in the memory 1002. Optionally, the processor 1001 may include one or more processing units. The processor 1001 may integrate an application processor and a modem processor. The application processor primarily handles the operating system, user interface, and applications, while the modem processor primarily handles wireless communication. It is understood that the modem processor may not be integrated into the processor 1001. In some embodiments, the processor 1001 and the memory 1002 may be implemented on the same chip; in other embodiments, they may be implemented on separate chips.

[0241] The processor 1001 can be a general-purpose processor, such as a central processing unit (CPU), digital signal processor, application-specific integrated circuit (ASIC), field-programmable gate array (FPGA), or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.

[0242] Memory 1002, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. Memory 1002 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic memory, magnetic disk, optical disk, etc. Memory 1002 can be any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. In the embodiments of this application, memory 1002 can also be a circuit or any other device capable of implementing storage functions for storing program instructions and / or data.

[0243] Based on the same technical concept, embodiments of the present invention also provide a computer-readable storage medium storing a computer-executable program, which is used to cause a computer to perform a method for generating a globally unique identifier in a distributed system as listed in any of the above methods.

[0244] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0245] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more blocks of the flowchart illustrations and / or one or more blocks of the block diagrams.

[0246] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.

[0247] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.

[0248] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

Claims

1. A method for generating a globally unique identifier in a distributed system, characterized in that, The method is applied to any server in the distributed system; the method includes: Within any given unit of time, a first globally unique identifier is assigned to the first object based on the server's fixed machine identifier, the first n-bit local identifier, and the timestamp of the current unit of time; the first n-bit local identifiers generated by the server within each unit of time are not duplicated; the fixed machine identifier is assigned to the server by the coordination service center from a preset pool of fixed machine identifiers; Add a fixed correspondence between the server and the server's fixed machine identifier to the fixed correspondence stored in the coordination service center; the binding duration of the fixed correspondence is a preset duration. Once the number of allocated first globally unique identifiers is detected to meet a preset threshold, a temporary machine identifier for the server is obtained from the coordination service center. The temporary machine identifier for the server is allocated to the server by the coordination service center from a preset pool of temporary machine identifiers. The sum of the number of each fixed machine identifier and the number of each temporary machine identifier is used to characterize the cluster expansion performance of the distributed system. A temporary correspondence between the server and the server's temporary machine identifier is added to the temporary correspondence stored in the coordination service center; the temporary correspondence expires when the next unit of time arrives. Within the current unit time, a second globally unique identifier is assigned to the second object based on the server's temporary machine identifier, the second n-bit local identifier, and the timestamp of the current unit time; the second n-bit local identifiers generated by the server within the unit time are not repeated.

2. The method of claim 1, wherein, The coordination service center assigns machine identifiers to each server through a distributed coordination service.

3. The method of claim 1, wherein, Also includes: Monitor the usage duration of the server's fixed machine identifier. If the usage duration exceeds a preset duration, reapply for the server's fixed machine identifier from the coordination service center. Based on the fixed machine identifier of the server that has been re-obtained, a first globally unique identifier is assigned to each first object.

4. The method of claim 1, wherein, Also includes: Apply for lock removal from the coordination service center at preset intervals; If a cleanup lock is obtained, then for any of the fixed correspondences, if the binding duration of the fixed correspondence meets the preset duration, the fixed correspondence is released.

5. The method as described in claim 1, characterized in that, Also includes: After the unit time expires, the temporary correspondence between the server and the server's temporary machine identifier is terminated.

6. The method according to any one of claims 1-5, characterized in that, Also includes: Once the number of second globally unique identifiers allocated based on the temporary machine identifier is detected to meet the preset threshold, a new temporary machine identifier for the server is requested from the coordination service center. A second globally unique identifier is assigned to each second object based on the temporary machine identifier of the server that has been re-obtained.

7. A method for generating a globally unique identifier in a distributed system, characterized in that, The method is applied to a coordination service center; the coordination service center stores fixed correspondences between each server and a fixed machine identifier; the validity period of the fixed correspondences is a preset duration; the coordination service center stores temporary correspondences between each server and a temporary machine identifier. The temporary correspondence expires when the next unit of time arrives; the method includes: When the number of servers in the distributed system is detected to be greater than the first threshold, the first number of temporary machine identifiers among the temporary machine identifiers are used as fixed machine identifiers. And / or, When it is detected that the number of servers in the distributed system is less than the second threshold, the second number of fixed machine identifiers among the fixed machine identifiers are used as temporary machine identifiers. In response to a request to obtain a fixed machine identifier from any server, a fixed machine identifier is allocated to the server from a preset pool of fixed machine identifiers; the fixed machine identifier is used to generate a first globally unique identifier, which is generated based on the server's fixed machine identifier, a first n-bit local identifier, and a timestamp of the current unit time. In response to a request to obtain a temporary machine identifier from any server, a temporary machine identifier is allocated to the server from a set of preset temporary machine identifiers; the number of each fixed machine identifier and the sum of the number of each temporary machine identifier are used to characterize the cluster expansion performance of the distributed system; the temporary machine identifier is used to generate a second globally unique identifier, which is generated based on the server's temporary machine identifier, a second n-bit local identifier, and the timestamp of the current unit time.

8. The method as described in claim 7, characterized in that, The coordination service center assigns machine identifiers to each server through a distributed coordination service.

9. The method as described in claim 7, characterized in that, Also includes: If any temporary correspondence is not terminated after any unit of time has elapsed, then the temporary correspondence is terminated.

10. A device for generating a globally unique identifier in a distributed system, characterized in that, include: Allocation unit, used for: Within any given unit of time, a first globally unique identifier is assigned to the first object based on the server's fixed machine identifier, the first n-bit local identifier, and the timestamp of the current unit of time; the first n-bit local identifiers generated by the server within each unit of time are not repeated; the fixed machine identifier is assigned to the server by the coordination service center from a preset pool of fixed machine identifiers; Add a fixed correspondence between the server and the server's fixed machine identifier to the fixed correspondence stored in the coordination service center; the binding duration of the fixed correspondence is a preset duration. Add a temporary correspondence between the server and the temporary machine identifier of the server to the temporary correspondence stored in the coordination service center; The temporary correspondence expires when the next unit of time arrives; Within the current unit of time, a second globally unique identifier is assigned to the second object based on the server's temporary machine identifier, the second n-bit local identifier, and the timestamp of the current unit of time; The second n-bit local identifiers generated by the server within a unit of time are not repeated; The generation unit is used to obtain a temporary machine identifier for the server from the coordination service center when the number of allocated first globally unique identifiers is detected to meet a preset threshold. The temporary machine identifier for the server is allocated to the server by the coordination service center from a preset set of temporary machine identifiers. The sum of the number of each fixed machine identifier and the number of each temporary machine identifier is used to characterize the cluster expansion performance of the distributed system.

11. A device for generating a globally unique identifier in a distributed system, characterized in that, It is applied to a coordination service center; the coordination service center stores fixed correspondences between each server and a fixed machine identifier; the validity period of the fixed correspondence is a preset period; the coordination service center stores temporary correspondences between each server and a temporary machine identifier; The temporary correspondence expires when the next unit of time arrives; including: An adjustment unit is configured to, when the number of servers in the distributed system is detected to be greater than a first threshold, use a first number of temporary machine identifiers as fixed machine identifiers; and / or, When it is detected that the number of servers in the distributed system is less than the second threshold, the second number of fixed machine identifiers among the fixed machine identifiers are used as temporary machine identifiers. A fixed machine identifier allocation unit is used to allocate a fixed machine identifier to the server from a preset set of fixed machine identifiers in response to a fixed machine identifier acquisition request from any server; the fixed machine identifier is used to generate a first globally unique identifier, which is generated based on the server's fixed machine identifier, a first n-bit local identifier, and a timestamp of the current unit time. A temporary machine identifier allocation unit is used to allocate a temporary machine identifier to a server from a preset pool of temporary machine identifiers in response to a temporary machine identifier acquisition request from any server; the number of each fixed machine identifier and the sum of the number of each temporary machine identifier are used to characterize the cluster expansion performance of the distributed system; the temporary machine identifier is used to generate a second globally unique identifier, which is generated based on the server's temporary machine identifier, a second n-bit local identifier, and the timestamp of the current unit time.

12. A computing device, characterized in that, include: Memory, used to store computer programs; A processor is configured to invoke a computer program stored in the memory and execute the method according to any one of claims 1 to 9 in accordance with the obtained program.

13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer-executable program for causing a computer to perform the method according to any one of claims 1 to 9.