Distributed serial number generation method and device, electronic equipment and storage medium
By obtaining and generating unique node instance numbers in a distributed system, the problem of duplicate node instance numbers is solved, ensuring the global uniqueness of distributed serial numbers and the reliability of the system.
Patent Information
- Application Number
- CN202510659665.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-21
- Publication Date
- 2025-09-23
AI Technical Summary
In distributed systems, node instance numbers are prone to duplication, leading to business process execution errors and distributed system operation failures, which existing technologies have failed to effectively solve.
By responding to application startup in a distributed system, obtaining the instance number of the node from a local configuration file or a preset database, and using a preset algorithm to generate a distributed serial number, it is ensured that different nodes have unique instance numbers.
The global uniqueness of distributed serial numbers is achieved, duplication of node instance numbers is avoided, and the reliability and traceability of the system are improved.
Smart Images

Figure CN120687524A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed systems and microservice technologies, and in particular to a method, device, electronic device and storage medium for generating distributed serial numbers. Background Art
[0002] With the development of emerging technologies such as cloud computing, big data, artificial intelligence, and blockchain, distributed architectures offer high availability, reliability, and scalability for business applications, becoming the mainstream technology supporting large-scale business applications. In distributed architectures supporting large-scale business applications, unique identification of deployed application systems is necessary to ensure determinism, traceability, and auditability of application systems.
[0003] In traditional distributed systems, unique identifiers are typically generated in memory. When a distributed system has a large number of nodes, duplicate unique identifiers are prone to occur, causing errors or even failures in business process execution. Furthermore, during application maintenance and deployment, unique identifiers are often assigned manually, which can easily lead to duplicate node instance numbers. This can cause data conflicts, logical errors, and even distributed system failures.
[0004] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention
[0005] The embodiments of the present invention provide a method, device, electronic device and storage medium for generating a distributed serial number, so as to at least solve the technical problem in the related art that node instance numbers in a distributed system are prone to duplication.
[0006] According to one aspect of an embodiment of the present invention, a method for generating a distributed serial number is provided, which is applied to a distributed system, comprising: in response to detecting the startup of an application in the distributed system, obtaining the instance number of at least one node in the distributed system from a local configuration file or a preset database of the distributed system, wherein the instance numbers of different nodes are different; and generating a distributed serial number based on the instance number of at least one node through a preset algorithm.
[0007] Optionally, obtaining the instance number of at least one node in the distributed system from a local configuration file or a preset database of the distributed system includes: obtaining the instance number of at least one node from the local configuration file, wherein the local configuration file is used to store configuration information of at least one node in the distributed system; in response to not obtaining the instance number of at least one node from the local configuration file, obtaining the instance number of at least one node from the preset database.
[0008] Optionally, obtaining the instance number of at least one node from a preset database includes: obtaining the program identifier of the application, the identifier of any node and a preset check number; matching the program identifier, identifier and preset check number with the preset instance number in the preset database; in response to a successful match between the program identifier, identifier and preset check number and the preset instance number, determining the preset instance number as the instance number of the node.
[0009] Optionally, before matching the program identifier, the identifier and the preset check digit with the preset instance number in the preset database, the method further includes: generating a preset instance number of at least one node; and storing the preset instance number of at least one node in the preset database.
[0010] Optionally, generating a preset instance number of at least one node includes: combining the program identifier of the application, the identifier of any node and a preset check digit based on a preset information combination order to obtain the preset instance number of the node.
[0011] Optionally, in response to not obtaining the instance number of the at least one node from the local configuration file, the method further includes: storing the instance number of the at least one node obtained from the preset database in the local configuration file.
[0012] Optionally, a distributed serial number is generated based on the instance number of at least one node through a preset algorithm, including: generating a serial number corresponding to the instance number of any node, and obtaining a timestamp of the serial number, wherein the serial numbers corresponding to the instance numbers of different nodes are different, and the timestamp is used to represent the moment when the serial number is generated; combining the instance number of the node with the corresponding serial number and timestamp to obtain the serial number corresponding to the node; and summarizing the serial numbers corresponding to at least one node to obtain a distributed serial number.
[0013] Optionally, the above method further includes: in response to detecting that the application is released in the distributed system, deleting the local configuration file and deleting the instance number stored in the preset database.
[0014] According to another aspect of an embodiment of the present invention, a device for generating a distributed serial number is also provided, including: an acquisition module for obtaining, in response to detecting the startup of an application in the distributed system, the instance number of at least one node in the distributed system from a local configuration file or a preset database of the distributed system, wherein the instance numbers of different nodes are different; a generation module for generating a distributed serial number based on the instance number of at least one node through a preset algorithm.
[0015] According to another aspect of an embodiment of the present invention, an electronic device is provided, including: a memory storing an executable program; and a processor for running the program, wherein the program executes the methods of various embodiments of the present invention when running.
[0016] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium includes a stored executable program, wherein when the executable program is running, the device where the computer-readable storage medium is located is controlled to execute the methods in various embodiments of the present invention.
[0017] According to another aspect of an embodiment of the present invention, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the method in each embodiment of the present invention is implemented.
[0018] According to another aspect of an embodiment of the present invention, a computer program product is provided, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method in each embodiment of the present invention is implemented.
[0019] According to another aspect of an embodiment of the present invention, a computer program is provided. When the computer program is executed by a processor, the method in each embodiment of the present invention is implemented.
[0020] In an embodiment of the present invention, applied to a distributed system, in response to detecting the startup of an application in the distributed system, the instance number of at least one node in the distributed system is obtained from a local configuration file or a preset database of the distributed system, wherein the instance numbers of different nodes are different; and a distributed serial number is generated based on the instance number of at least one node through a preset algorithm. It is easy to notice that the method of automatically obtaining the instance number is used, and through unified allocation, different nodes have different instance numbers, thereby ensuring that the distributed serial number generated by the instance number is globally unique, achieving the purpose of non-repetitive instance numbers, thereby achieving the technical effect of ensuring the uniqueness of the distributed serial number, and thus solving the technical problem of easy duplication of node instance numbers in distributed systems in related technologies. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0022] Figure 1 is a flow chart of a method for generating a distributed serial number according to an embodiment of the present invention;
[0023] Figure 2 is a schematic diagram of a method for obtaining an instance number according to an embodiment of the present invention;
[0024] Figure 3 is a schematic diagram of a method for releasing an instance number according to an embodiment of the present invention;
[0025] Figure 4 2 is a schematic diagram of a distributed serial number generation device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] The following describes an application scenario of the distributed serial number generation method provided by the present invention. The above method can be applied to a distributed system, which includes: a plurality of distributed nodes.
[0029] Optionally, the distributed nodes can be configured as computers, production equipment, storage devices, physical servers, virtual servers, or cloud servers, etc.
[0030] The electronic device of each distributed node includes a business application system and a local configuration file. The local configuration file stores the instance number corresponding to the distributed node, wherein the instance numbers of different distributed nodes are different.
[0031] When the business application system reads the instance number of a distributed node, a different distributed serial number corresponding to the distributed node can be generated based on the instance number of the distributed node; if the business application system does not read the instance number of the distributed node, the instance number of the distributed node can be obtained from the preset database, and a distributed serial number can be generated based on the instance number of the distributed node.
[0032] According to an embodiment of the present invention, a method for generating a distributed serial number is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0033] Figure 1 Flowchart of a method for generating a distributed serial number according to an embodiment of the present invention. Figure 1 As shown, the method includes the following steps:
[0034] Step S102 : in response to detecting that an application in the distributed system is started, obtaining an instance number of at least one node in the distributed system from a local configuration file or a preset database of the distributed system.
[0035] Different nodes have different instance numbers.
[0036] A distributed system, as described above, can be composed of one or more computers interconnected via a network, working together to complete a task. These computer nodes can communicate and coordinate with each other, forming a system that provides external services. In a distributed system, there is no single central control point; each node can operate independently while interacting with other nodes via the network to achieve functions such as data sharing and task sharing. Common distributed system applications include large-scale data processing, cloud computing, and the Internet of Things. During deployment, distributed systems sequentially number each computer, or node, to distinguish between different computer instances and facilitate task traceability and management.
[0037] The aforementioned applications can run on one or more computers. Leveraging the advantages of distributed computing, applications can distribute tasks across different computing nodes and collaborate to achieve higher performance, reliability, and scalability. A distributed system allows applications to better utilize resources, improve system resilience and fault tolerance, and better meet user needs. In a distributed system, applications running the same service on different nodes can operate independently while collaborating with other instances to complete system tasks. For example, in a distributed database system, applications on each node may be responsible for storing and processing a portion of data, synchronizing data and processing transactions with applications on other nodes over the network.
[0038] The aforementioned local configuration file can be used to store node configuration information. This configuration information may include, but is not limited to, instance numbers and node device information. This information is not limited here and can be determined as needed. When the application starts, the node instance number is preferentially read from the local configuration file. If the instance number already exists in the local configuration file, it is directly used to generate the distributed serial number. The use of local configuration files can reduce frequent access to centralized storage resources and improve the efficiency of distributed system startup and data processing.
[0039] The aforementioned preset database can be a database used in a distributed system to centrally store system-related information. When an application starts and the local configuration file does not contain an instance number, it can request an instance number from the preset database. The instance number in the database is visible and unique to all nodes, ensuring that even when multiple nodes start simultaneously, each node can obtain a unique instance number, thereby generating a globally unique distributed serial number. The preset database can be a relational or non-relational database. Alternatively, it can be a distributed or centralized database. The database type can be selected based on the application's requirements and database performance. The preset database is not limited here and can be determined as needed. Preferably, the preset database can be a Remote Dictionary Server (Redis) database. Redis databases can be used not only for key-value storage but also for storing data structures such as strings, hashes, lists, and bitmaps. Furthermore, the preset database can store and manage instance numbers for application system nodes, facilitating subsequent query, update, or release operations, ensuring the uniqueness and accuracy of instance numbers throughout the lifecycle of the distributed system.
[0040] The instance number of the node mentioned above can be the unique identifier of the node. And the instance numbers of different nodes are different to ensure the uniqueness of the encoding of each node in the distributed system. In a distributed system, multiple computers may provide services to users at the same time. In order to ensure that each operation or event has a globally unique instance number, the instance number can be generated by combining the timestamp, serial number and machine instance number, or by using a snowflake algorithm. The role of the instance number is to distinguish different server instances. Numbering the instance numbers in sequence also helps in the orderly management of application instances. Because in a large-scale distributed system, ordered instance numbers make it easier for operation and maintenance personnel to track and manage each application instance. For example, when performing troubleshooting, resource allocation, load balancing and other operations, the ordered instance numbers can be used as indexes to quickly locate nodes.
[0041] Optionally, the instance number can be at least one of the computer room number of the computer room where the distributed node is located, the server number of the server corresponding to the distributed node, the business number of the business application system in the distributed node, the IP address (Internet Protocol Address) of the distributed node, the machine number of the distributed node, etc., or it can be composed of at least two of the computer room number, server number, business number, IP address and machine number, etc.
[0042] When the instance number consists of a computer room number and a machine number, for example, if the computer room number is 24 and the machine number is 13, the instance number may be 2413.
[0043] In an optional embodiment, the application startup status can be detected using a heartbeat mechanism. Alternatively, a startup file can be created in the application's running directory to indicate that the application has started. This startup file can contain information such as the application's startup time and process identifier. The content of the startup file is not limited and can be determined as needed. Alternatively, a cloud platform or container management system can be used to detect the application's startup status.
[0044] Furthermore, in an optional embodiment, upon detecting the startup of an application in the distributed system, the instance number of at least one node in the distributed system is obtained. Alternatively, the instance number can be obtained from a local configuration file or a preset database. Specifically, the instance number can be obtained by reading a properties file in the application's root directory. Alternatively, the configuration file can be read using the application programming interface (API) of a file reading library, and the read file contents can be parsed into an in-memory data structure, such as a dictionary or object. The instance number key is then searched, and the instance number is extracted from the parsed data structure. The parsed instance number is then confirmed to be correctly formatted and within a valid range. Alternatively, the instance number can be obtained from a preset database via a query request. The application can send a query request to the preset database. The query request can include the node's address, name, and random number. Upon receiving the query request, the preset database searches the preset database for the instance number corresponding to the node. Alternatively, the instance number corresponding to the node can be queried from the preset database using a preset key-value pair.
[0045] Step S104: Generate a distributed serial number based on the instance number of at least one node using a preset algorithm.
[0046] The above-mentioned preset algorithm can be an algorithm for generating unique and ordered serial numbers. This preset algorithm can not only adapt to high-concurrency scenarios, but also realize serial number management in a distributed environment through node identification, thereby avoiding the problem of serial number duplication, while ensuring the order and traceability of the serial number. The preset algorithm can be one of the following: snowflake algorithm, hash algorithm, etc. The preset algorithm is not limited here and can be determined as needed. Optionally, the preset algorithm can be a snowflake algorithm, which uses a timestamp and a computer identifier to combine and generate distributed serial numbers to ensure that the distributed serial numbers are not repeated.
[0047] The snowflake algorithm works by generating a unique identifier (i.e., a distributed serial number) whose length can be configured, for example, 64 or 32 bits. The snowflake algorithm typically combines a timestamp and a machine ID to generate unique identifiers, ensuring unique identifiers even in a distributed environment.
[0048] The distributed serial number described above can be an ordered and unique sequence of numbers or characters in a distributed computing environment. This distributed serial number generation mechanism not only ensures data uniqueness and order, but also provides a foundation for the scalability and high availability of distributed systems. In practical applications, the distributed serial number generation method should be determined based on the specific application requirements, performance goals, and operation and maintenance strategies. For example, a financial transaction system may prioritize the orderliness of serial numbers, while a high-concurrency e-commerce system may prioritize the efficiency of serial number generation and high-concurrency processing capabilities.
[0049] In an optional embodiment, the serial number can be generated using a random distribution strategy based on a preset algorithm. Alternatively, a distributed serial number can be generated using an adaptive bit allocation strategy. Alternatively, a distributed serial number can be generated using an optimistic locking and pessimistic locking mechanism.
[0050] In an embodiment of the present invention, applied to a distributed system, in response to detecting the startup of an application in the distributed system, the instance number of at least one node in the distributed system is obtained from a local configuration file or a preset database of the distributed system, wherein the instance numbers of different nodes are different; and a distributed serial number is generated based on the instance number of at least one node through a preset algorithm. It is easy to notice that the method of automatically obtaining the instance number is used, and through unified allocation, different nodes have different instance numbers, thereby ensuring that the distributed serial number generated by the instance number is globally unique, achieving the purpose of non-repetitive instance numbers, thereby achieving the technical effect of ensuring the uniqueness of the distributed serial number, and thus solving the technical problem of easy duplication of node instance numbers in distributed systems in related technologies.
[0051] Optionally, obtaining the instance number of at least one node in the distributed system from a local configuration file or a preset database of the distributed system includes: obtaining the instance number of at least one node from the local configuration file, wherein the local configuration file is used to store configuration information of at least one node in the distributed system; in response to not obtaining the instance number of at least one node from the local configuration file, obtaining the instance number of at least one node from the preset database.
[0052] In an optional embodiment, the instance number of at least one node can be obtained from a local configuration file. The local configuration file is configured with configuration information for storing at least one node in the distributed system. The configuration information can be obtained by parsing the local configuration file, for example, using a text parser, a parsing function, or an API. The parsing method is not limited here and can be determined as needed. The instance number of the node can be further identified from the configuration information by a recognition model or manual query. Alternatively, the instance number of at least one node can be obtained from the local configuration file using text recognition technology. By preferentially obtaining the instance number from the local configuration file, computing resources are saved and acquisition efficiency is improved.
[0053] In the case where the instance number of at least one node is not obtained from the local configuration file, the instance number of at least one node can be obtained through the preset database. Optionally, the instance number can be obtained from the preset database through a query request. Specifically, a query request can be sent to the preset database through an application. The query request can include the address, name and random number of the node. After the preset database receives the query request, it searches for the instance number corresponding to the node in the preset database. Alternatively, the instance number corresponding to the node can be queried from the preset database through a preset key-value pair. This dual acquisition mechanism improves the robustness of the distributed system. Even if the local configuration file is lost or damaged, the instance number can be restored from the preset database to ensure the continuity and stability of subsequent distributed serial number generation.
[0054] Optionally, obtaining the instance number of at least one node from a preset database includes: obtaining the program identifier of the application, the identifier of any node and a preset check number; matching the program identifier, identifier and preset check number with the preset instance number in the preset database; in response to a successful match between the program identifier, identifier and preset check number and the preset instance number, determining the preset instance number as the instance number of the node.
[0055] In an optional embodiment, to obtain the instance number of at least one node from a preset database, the application's program identifier, the identifier of any node, and a preset check digit may first be obtained. Alternatively, the application's program identifier, the identifier of any node, and the preset check digit may be obtained from the cloud, or alternatively, from the distributed system's log files. Alternatively, the application's program identifier, the identifier of any node, and the preset check digit may be obtained according to preset rules. The program identifier, the identifier, and the preset check digit are then matched against the preset instance numbers in the preset database. Alternatively, the matching may be performed using a similarity algorithm, a matching algorithm, or a manual matching of the preset instance numbers. If the program identifier, the identifier, and the preset check digit successfully match the preset instance number, the preset instance number is determined to be the node's instance number, thereby obtaining the instance number of at least one node from the preset database. This matching mechanism ensures the accuracy and security of instance numbers, particularly in a multi-node environment, effectively preventing confusion between serial numbers of different applications or nodes, thereby improving the security of the distributed system.
[0056] Optionally, before matching the program identifier, the identifier and the preset check digit with the preset instance number in the preset database, the method further includes: generating a preset instance number of at least one node; and storing the preset instance number of at least one node in the preset database.
[0057] In an optional embodiment, a centralized service can be used to generate and assign a preset instance number, and the preset instance number can be stored in a preset database. Specifically, when the application is started, a generation request is sent to the centralized service. The generation request may include but is not limited to: program identification, node identifier, preset check digit, etc. The content of the generation request is not limited here and can be determined as needed. After receiving the generation request, the centralized service checks whether an instance number has been assigned to the node. If not, a preset instance number is generated and associated with the node's attribute information. The node's attribute information may include but is not limited to: the node's Internet Protocol address, program identification, and preset check digit, etc. The node's attribute information is not limited here and can be determined as needed. The preset instance number and the association relationship are then stored in the preset database.
[0058] In another optional embodiment, a preset instance number can be generated based on a hash algorithm and then stored in a preset database. Specifically, a hash algorithm can be used to perform a hash operation based on a timestamp, a program identifier, an identifier of a node, etc. to obtain a hash value of the node. Then, a bit operation is performed on the hash value to extract a subset as the instance number of the node and store it in a preset database. In order to ensure the global uniqueness of the preset instance number, a synchronization mechanism such as a distributed lock can be used to control the generation process. Through this step, it can be ensured that the nodes in the distributed system have a unique instance number when they are started, laying the foundation for the subsequent generation of distributed serial numbers.
[0059] Optionally, generating a preset instance number of at least one node includes: combining the program identifier of the application, the identifier of any node and a preset check digit based on a preset information combination order to obtain the preset instance number of the node.
[0060] The above-mentioned preset information combination order can be used to ensure uniqueness across nodes in a distributed system, thereby preventing duplication of preset instance numbers. The preset information combination order can also enhance the security of the preset instance number assignment, preventing it from being cracked. The preset information combination order can be a program identifier, a node identifier, and a preset check digit, or a node identifier, a program identifier, and a preset check digit, etc. The preset information combination order is not limited here and can be determined as needed.
[0061] In an optional embodiment, the program identifier of the application, the identifier of any node and the preset check number can be spliced together according to the preset information combination order to obtain the preset instance number of the node. Alternatively, the program identifier of the application, the identifier of any node and the preset check number can be hashed by hashing, and then adjusted and intercepted according to the preset information combination order to obtain the preset instance number of the node. Alternatively, the program identifier of the application, the identifier of any node and the preset check number can be encoded first, and then spliced together to obtain the preset instance number of the node. The preset instance number generated by this combination method can not only ensure the uniqueness of the preset instance number, but also trace the generation source of the distributed serial number by parsing the preset instance number, thereby facilitating subsequent troubleshooting and maintenance.
[0062] Optionally, in response to not obtaining the instance number of the at least one node from the local configuration file, the method further includes: storing the instance number of the at least one node obtained from the preset database in the local configuration file.
[0063] In an optional embodiment, the local configuration file can be read through an extensible markup language (XML) parser to find the location of the instance number and store the instance number in the local configuration file. Alternatively, the instance number of the node can be updated in the local configuration file by finding the key-value pair of the instance number in the local configuration file. Alternatively, the instance number of the node can be stored in an environment variable, and the instance number can be stored in the local configuration file by updating the environment variable. This mechanism can reduce the frequent access to the preset database, improve the efficiency of distributed serial number generation, and also provide a quick recovery method for the instance number when the node is restarted.
[0064] Figure 2 FIG. 1 is a schematic diagram of a method for obtaining an instance number according to an embodiment of the present invention. Figure 2 As shown, the method includes:
[0065] If the local configuration file is read successfully, the instance number is obtained. If the local configuration file fails to obtain the instance number, the instance number is obtained from the preset database. If the number is successfully obtained, the instance number is saved to the local configuration file. If the number is obtained from the preset database and fails, the number is obtained again until it is successfully obtained from the preset database.
[0066] Optionally, a distributed serial number is generated based on the instance number of at least one node through a preset algorithm, including: generating a serial number corresponding to the instance number of any node, and obtaining a timestamp of the serial number, wherein the serial numbers corresponding to the instance numbers of different nodes are different, and the timestamp is used to represent the moment when the serial number is generated; combining the instance number of the node with the corresponding serial number and timestamp to obtain the serial number corresponding to the node; and summarizing the serial numbers corresponding to at least one node to obtain a distributed serial number.
[0067] In an optional embodiment, a serial number corresponding to the instance number can be generated through a self-incrementing sequence or a distributed coordination service, and the timestamp of the serial number can be obtained through a clock, a centralized time service, or a network time protocol. The instance number of the node can then be concatenated with the corresponding serial number and timestamp to obtain the serial number corresponding to the node. Alternatively, a hash algorithm can be used to perform a hash operation on the instance number, the corresponding serial number, and the timestamp, and then a subset of the hash value can be intercepted according to a preset interception rule, and the subset can be regarded as the serial number of the node. After obtaining the serial number corresponding to the node, the serial numbers of the nodes can be aggregated through a distributed coordination service or a message queue to obtain a distributed serial number. This combination based on timestamps and serial numbers not only ensures the global uniqueness of the serial number, but also reflects the generation order and time of the serial number, which is helpful for transaction tracking and log analysis in distributed systems.
[0068] Optionally, the above method further includes: in response to detecting that the application is released in the distributed system, deleting the local configuration file and deleting the instance number stored in the preset database.
[0069] In an optional embodiment, when it is detected that an application is released in a distributed system, the local configuration file of the application can be located through the program identifier of the application, so that the local configuration file corresponding to the application can be deleted through a delete command or API call, and then the database transaction processing mechanism or the database delete statement can be used to delete the instance number in the preset database.
[0070] In another alternative embodiment, a middleware service can be integrated to monitor the application lifecycle. Upon detecting that an application has been released from the distributed system, the middleware service can notify the instance management service to delete the application. This release mechanism ensures that at the end of an application's lifecycle, the configuration and data associated with the application are promptly cleared, avoiding resource waste and data redundancy, and helping to maintain a clean and efficient distributed system.
[0071] Figure 3 is a schematic diagram of a method for releasing an instance number according to an embodiment of the present invention, such as Figure 3 As shown, the method includes: deleting from a preset database, and releasing the instance number if the deletion is successful.
[0072] According to another aspect of an embodiment of the present invention, an embodiment of a distributed serial number generation device is also provided. The device can execute the distributed serial number generation method provided in the above embodiment. The specific implementation method and preferred application scenario are the same as the above embodiment and will not be repeated here.
[0073] Figure 4 Schematic diagram of a distributed serial number generating device according to an embodiment of the present invention. Figure 4 As shown, the device includes:
[0074] An acquisition module 40 is used to obtain the instance number of at least one node in the distributed system from a local configuration file or a preset database of the distributed system in response to detecting the startup of an application in the distributed system, wherein the instance numbers of different nodes are different; a generation module 42 is used to generate a distributed serial number based on the instance number of at least one node through a preset algorithm.
[0075] Optionally, the acquisition module is also used to obtain the instance number of at least one node from a local configuration file, wherein the local configuration file is used to store configuration information of at least one node in a distributed system; in response to not obtaining the instance number of at least one node from the local configuration file, obtaining the instance number of at least one node from a preset database.
[0076] Optionally, the acquisition module is also used to obtain the program identifier of the application, the identifier of any node and a preset check number; match the program identifier, identifier and preset check number with the preset instance number in the preset database; in response to the program identifier, identifier and preset check number successfully matching the preset instance number, determine the preset instance number as the instance number of the node.
[0077] Optionally, the acquisition module is further configured to generate a preset instance number of at least one node; and store the preset instance number of at least one node in a preset database.
[0078] Optionally, the acquisition module is further configured to combine the program identifier of the application, the identifier of any node and a preset check digit based on a preset information combination order to obtain a preset instance number of the node.
[0079] Optionally, the acquisition module is further configured to store the instance number of at least one node acquired from a preset database in a local configuration file.
[0080] Optionally, the generation module is also used to generate a serial number corresponding to the instance number of any node and obtain the timestamp of the serial number, where the serial numbers corresponding to the instance numbers of different nodes are different, and the timestamp is used to represent the moment when the serial number is generated; the instance number of the node is combined with the corresponding serial number and timestamp to obtain the serial number corresponding to the node; the serial numbers corresponding to at least one node are aggregated to obtain a distributed serial number.
[0081] Optionally, the apparatus further comprises: a deletion module configured to delete the local configuration file and the instance number stored in the preset database in response to detecting that the application is released in the distributed system.
[0082] An embodiment of the present application further provides an electronic device, comprising: a memory storing an executable program; and a processor for running the program, wherein the program executes the methods of various embodiments of the present invention when running.
[0083] An embodiment of the present application further provides a computer-readable storage medium, which includes a stored executable program, wherein when the executable program is running, the device where the computer-readable storage medium is located is controlled to execute the methods in various embodiments of the present invention.
[0084] An embodiment of the present application further provides a computer program product, including a computer program, which implements the methods in various embodiments of the present invention when executed by a processor.
[0085] An embodiment of the present application further provides a computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the method in each embodiment of the present invention is implemented.
[0086] The embodiments of the present application further provide a computer program, which implements the methods in the above-mentioned embodiments of the present invention when executed by a processor.
[0087] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0088] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0089] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0090] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0091] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0092] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes various media that can store program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), a mobile hard drive, a magnetic disk, or an optical disk.
[0093] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.
Claims
1. A method for generating a distributed serial number, characterized in that: Applied to distributed systems, including: In response to detecting that an application is started in the distributed system, obtaining an instance number of at least one node in the distributed system from a local configuration file or a preset database of the distributed system, wherein the instance numbers of different nodes are different; A distributed serial number is generated based on the instance number of the at least one node using a preset algorithm.
2. The method according to claim 1, characterized in that Obtaining an instance number of at least one node in the distributed system from a local configuration file or a preset database of the distributed system includes: Obtaining an instance number of the at least one node from the local configuration file, wherein the local configuration file is used to store configuration information of the at least one node in the distributed system; In response to not obtaining the instance number of the at least one node from the local configuration file, obtaining the instance number of the at least one node from the preset database.
3. The method according to claim 2, characterized in that Acquiring the instance number of the at least one node from the preset database includes: Obtaining a program identifier of the application, an identifier of any node, and a preset checksum; matching the program identifier, the identifier, and the preset check digit with a preset instance number in the preset database; In response to a successful match between the program identifier, the identifier, and the preset check digit and the preset instance number, the preset instance number is determined to be the instance number of the node.
4. The method according to claim 3, characterized in that Before matching the program identifier, the identifier, and the preset check digit with a preset instance number in the preset database, the method further includes: generating a preset instance number of the at least one node; The preset instance number of the at least one node is stored in the preset database.
5. The method according to claim 4, characterized in that Generating a preset instance number of the at least one node includes: Based on a preset information combination sequence, the program identifier of the application, the identifier of any node and a preset check digit are combined to obtain a preset instance number of the node.
6. The method according to any one of claims 2 to 5, characterized in that In response to not obtaining the instance number of the at least one node from the local configuration file, the method further includes: The instance number of the at least one node obtained from the preset database is stored in the local configuration file.
7. The method according to claim 1, characterized in that Generating a distributed serial number based on the instance number of the at least one node by using a preset algorithm includes: Generate a serial number corresponding to the instance number of any node, and obtain a timestamp of the serial number, wherein the serial numbers corresponding to the instance numbers of different nodes are different, and the timestamp is used to indicate the time when the serial number was generated; Combining the instance number of the node with the corresponding serial number and timestamp to obtain the serial number corresponding to the node; The serial numbers corresponding to the at least one node are aggregated to obtain the distributed serial number.
8. The method according to claim 1, characterized in that The method further comprises: In response to detecting that the application is released in the distributed system, the local configuration file is deleted, and the instance number stored in the preset database is deleted.
9. A distributed serial number generation device, characterized in that: include: an acquisition module, configured to, in response to detecting that an application is started in the distributed system, acquire an instance number of at least one node in the distributed system from a local configuration file or a preset database of the distributed system, wherein the instance numbers of different nodes are different; A generating module is used to generate a distributed serial number based on the instance number of the at least one node through a preset algorithm.
10. An electronic device, characterized in that: include: a memory storing an executable program; A processor, configured to run the program, wherein the program executes the method according to any one of claims 1 to 8 when running.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored executable program, wherein when the executable program is run, the device where the storage medium is located is controlled to execute the method according to any one of claims 1 to 8.
12. A computer program product, characterized in that The invention comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Distributed system-based serial number generation method and apparatus, and electronic device
CN108509433A
Distributed serial number generation method and device based on transaction link and storage medium
CN115936608A
Service number generation method and device and computer equipment
CN117076722A