Method for generating serial numbers and method for managing service numbers
By introducing a registry center to uniformly manage service numbers in a distributed system, the problem of serial number generation methods being unable to balance uniqueness and efficiency is solved, thus improving both the uniqueness and generation efficiency of serial numbers.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 中国邮政储蓄银行股份有限公司
- Filing Date
- 2023-09-28
- Publication Date
- 2026-06-19
AI Technical Summary
Existing serial number generation methods cannot balance uniqueness and efficiency, and suffer from high complexity and low efficiency.
By introducing a registry center to uniformly manage service numbers in a distributed system, a target service instance obtains a unique service number when registering with the registry center, and uses this number when generating a serial number, thus avoiding communication with additional devices.
It improves the uniqueness and generation efficiency of serial numbers, reduces system complexity, and increases the efficiency of serial number generation.
Smart Images

Figure CN117235152B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and more specifically, to a method for generating serial numbers, a method for managing service numbers, a device for generating serial numbers, and a device for managing service numbers. Background Technology
[0002] The existing methods for generating serial numbers are as follows:
[0003] Method 1: Use shared memory to generate serial numbers. In a distributed system, it is necessary to establish a shared memory system for multiple servers. Each service instance on each server needs to request the memory system to obtain a serial number. The memory system increments the serial number to ensure the uniqueness of the serial number in the distributed system.
[0004] Method 1 can guarantee the uniqueness of the serial number, but it requires the establishment of a shared memory system for multiple servers in the distributed system, which increases the complexity of the distributed system. Furthermore, since each service instance on the server needs to request the memory system to obtain the serial number, the serial number generation efficiency is low.
[0005] Method 2: Static allocation assigns a fixed code to each service instance, which generates the serial number itself without requesting other devices. This method is highly efficient, and the service instance adds the fixed code to the serial number.
[0006] Method 2 has a higher efficiency in generating serial numbers, but it cannot uniformly maintain the serial numbers of each service instance. Duplicates may occur if not handled carefully, and the uniqueness of the serial numbers cannot be guaranteed.
[0007] Method 3: Pre-allocation method. A separate service instance is set up in the system to store the serial number, so as to ensure the uniqueness of the serial number in the distributed system. Each service requests a group or multiple serial numbers at a time.
[0008] Method 3 requires a separate service instance to allocate serial numbers, which increases the complexity of the distributed system. Furthermore, since each service instance needs to request this service instance to obtain a serial number, the serial number generation efficiency is low.
[0009] As can be seen from the above, the existing methods for generating serial numbers cannot simultaneously achieve both uniqueness and efficiency. Summary of the Invention
[0010] The main objective of this application is to provide a method for generating serial numbers, a method for managing service numbers, a device for generating serial numbers, and a device for managing service numbers, so as to at least solve the problem that the existing serial number generation methods cannot simultaneously achieve uniqueness and efficiency.
[0011] To achieve the above objectives, according to one aspect of this application, a method for generating serial numbers is provided. The distributed system includes multiple first servers, second servers, and third servers. Each first server is configured with multiple service instances. The second server is configured with a registration center and a database. Each service instance is communicatively connected to the registration center. The registration center is communicatively connected to the database. The database stores multiple service numbers, and any two service numbers in the database are different. Each service number is a string of characters. The method is applied to a target service instance, which is any one of the multiple service instances of a target server. The target server is any one of the multiple first servers. The method includes: sending target registration information to the registration center, where the target registration information is the registration information of the target service instance. The service instance has registration information, which includes the IP address of the first server to which the service instance belongs and the port number of the service instance. Any two service instances have different port numbers. It receives a target service number sent from the registration center. The target service number is a service number in the database that is not bound to the service instance. One service number is bound to at most one service instance. The registration center retrieves the target service number from the database, binds the target service number to the target service instance, and sends the target service number to the target service instance. Upon receiving target information sent by the third server, it generates a target serial number based at least on the target service number. The target information indicates a request to invoke the target service instance, and the target serial number includes the target service number.
[0012] Optionally, upon receiving target information sent by the third server, generating a target serial number based at least on the target service number includes: if there are multiple target information items, obtaining multiple target timestamps, each target timestamp corresponding to a target information item, wherein the target timestamp is the time node at which the target service instance receives the target information; generating multiple target serial numbers based at least on the target service number and the multiple target timestamps, each target serial number corresponding to a target timestamp, wherein the target serial number also includes the corresponding target timestamp.
[0013] Optionally, the process of generating multiple target serial numbers based at least on the target service number and multiple target timestamps includes: when multiple target timestamps are the same, obtaining a first target quantity, wherein the first target quantity is the number of target information with corresponding target serial numbers; obtaining a second target quantity, wherein the second target quantity is the sum of the first target quantity and 1; generating the target serial number based on the target service number, the target timestamp and the second target quantity, wherein the target serial number further includes the second target quantity.
[0014] Optionally, after receiving the target information sent by the third server and generating a target serial number based at least on the target service number, the method further includes: sending a heartbeat to the registration center once in each heartbeat cycle, so that the registration center extends the target binding period by a preset time, wherein the heartbeat cycle is the period during which the target service instance communicates with the registration center periodically, and the target binding period is the duration for which the target service instance is bound to the target service number.
[0015] Optionally, within each heartbeat cycle, a heartbeat is sent to the registry center so that the registry center extends the target binding period by a preset time. The method further includes: sending offline information to the registry center so that the registry center unbinds the target service number from the target service instance, wherein the offline information indicates that the target service instance is offline.
[0016] According to another aspect of this application, a method for managing service numbers is provided. A distributed system includes multiple first servers and second servers. Each first server is configured with multiple service instances. The second server is configured with a registration center and a database. Each service instance is communicatively connected to the registration center, and the registration center is communicatively connected to the database. The database stores multiple service numbers, and any two service numbers in the database are different. Each service number is a string of characters. The method is applied to the registration center. The method includes: detecting whether target registration information is received from a target service instance, where the target service instance is any one of the service instances on the target server. The service instance is defined as follows: the target server is any one of the multiple first servers; the target registration information is the registration information corresponding to the target service instance; each service instance has one registration information, which includes the IP address of the first server to which the service instance belongs and the port number of the service instance; any two service instances have different port numbers; upon receiving the target registration information, a target service number is obtained from the database, the target service number is bound to the target service instance, and the target service number is sent to the target service instance; the target service number is a service number in the database that is not bound to the service instance.
[0017] Optionally, upon receiving the target registration information, the method further includes: obtaining the target service number from the database, binding the target service number to the target service instance, and sending the target service number to the target service instance; detecting whether offline information is received from the target service instance, the offline information indicating that the target service instance is offline; and unbinding the target service number from the target service instance upon receiving the offline information from the target service instance.
[0018] Optionally, upon receiving the target registration information, after obtaining the target service number from the database, binding the target service number to the target service instance, and sending the target service number to the target service instance, the method further includes: detecting whether a heartbeat sent by the target service instance is received within N consecutive heartbeat cycles, where the heartbeat cycle is the period during which the target service instance communicates with the registration center periodically, N is a positive integer, and N > 1; if no heartbeat is received from the target service instance within the N consecutive heartbeat cycles, unbinding the target service number from the target service instance.
[0019] Optionally, upon receiving the target registration information, the method further includes: obtaining the target service number from the database, binding the target service number to the target service instance, and sending the target service number to the target service instance. The method also includes: if a heartbeat is received from the target service within a heartbeat cycle, extending the target binding time by a preset time. The heartbeat cycle is the period during which the target service instance communicates periodically with the registration center, and the target binding time is the time during which the target service instance is bound to the target service number.
[0020] According to another aspect of this application, a serial number generation device is provided. The distributed system includes multiple first servers, second servers, and third servers. Each first server is configured with multiple service instances. The second server is configured with a registration center and a database. Each service instance is communicatively connected to the registration center. The registration center is communicatively connected to the database. The database stores multiple service numbers, and any two service numbers in the database are different. Each service number is a string of characters. The device is applied to a target service instance, which is any one of the multiple service instances of the target server. The target server is any one of the multiple first servers. The device includes: a first sending unit, used to send target registration information to the registration center. The target registration information is the registration information of the target service instance. Each service instance has one set of registration information. The system includes the IP address of the first server to which the service instance belongs and the port number of the service instance, wherein any two service instances have different port numbers; a receiving unit is used to receive a target service number sent from the registration center, wherein the target service number is a service number in the database that is not bound to the service instance, and one service number is bound to at most one service instance; the registration center is used to bind the target service instance to the target service number, and the registration center is used to obtain the target service number from the database, bind the target service number to the target service instance, and send the target service number to the target service instance; a generating unit is used to generate a target serial number, at least based on the target service number, upon receiving target information sent by the third server, wherein the target information indicates a request to call the target service instance, and the target serial number includes the target service number.
[0021] According to another aspect of this application, a service ID management device is provided. The distributed system includes multiple first servers and second servers. Each first server is configured with multiple service instances. The second server is configured with a registration center and a database. Each service instance is communicatively connected to the registration center, and the registration center is communicatively connected to the database. The database stores multiple service IDs, and any two service IDs in the database are different. Each service ID is a string of characters. The device is applied to the registration center. The device includes: a first detection unit, used to detect whether target registration information is received from a target service instance, where the target service instance is any one of the service instances on the target server. The service instance is defined as follows: the target server is any one of the multiple first servers; the target registration information is the registration information corresponding to the target service instance; each service instance has one registration information, which includes the IP address of the first server to which the service instance belongs and the port number of the service instance; any two service instances have different port numbers; the second sending unit is configured to, upon receiving the target registration information, retrieve a target service number from the database, bind the target service number to the target service instance, and send the target service number to the target service instance; the target service number is a service number in the database that is not bound to the service instance.
[0022] By applying the technical solution of this application, service numbers are uniformly maintained through the registration center. When a target service instance registers with the registration center, it obtains a unique service number that is not bound to other service instances. A serial number is generated using this service number to ensure the uniqueness of the serial number. Since the service number is managed by the registration center of the distributed system itself, the service instance does not need to communicate with additional devices, which improves the efficiency of serial number generation. This solves the problem that the serial number generation method in the prior art cannot balance uniqueness and efficiency. Attached Figure Description
[0023] Figure 1 A flowchart illustrating a serial number generation method according to an embodiment of this application is shown.
[0024] Figure 2 A flowchart illustrating a service number management method according to an embodiment of this application is shown.
[0025] Figure 3 A structural block diagram of a serial number generation apparatus according to an embodiment of this application is shown;
[0026] Figure 4A structural block diagram of a service number management device provided according to an embodiment of this application is shown. Detailed Implementation
[0027] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0028] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0029] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0030] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:
[0031] Serial number: In computer application systems, most requests need to generate a unique serial number for global tracking and idempotency guarantee.
[0032] Characters: Characters refer to alphanumeric words and symbols used in computers, including numbers, symbols and alphanumeric operators, punctuation marks and other symbols, as well as some functional symbols 1 2 3.
[0033] As described in the background section, existing serial number generation methods cannot simultaneously achieve uniqueness and efficiency. To address this issue, embodiments of this application provide a serial number generation method, a service number management method, a serial number generation apparatus, and a service number management apparatus.
[0034] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0035] This embodiment provides a method for generating serial numbers. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Also, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0036] The distributed system includes multiple first servers, second servers, and third servers. Each of the first servers is configured with multiple service instances. Each of the second servers is configured with a registry center and a database. Each of the service instances is communicatively connected to the registry center. The registry center is communicatively connected to the database. The database is used to store multiple service IDs. Any two service IDs in the database are different. Each service ID is a string of characters. The serial number generation method is applied to a target service instance. The target service instance is any one of the multiple service instances of the target server. The target server is any one of the multiple first servers.
[0037] Figure 1 This is a flowchart of a serial number generation method according to an embodiment of this application. For example... Figure 1 As shown, the method includes the following steps:
[0038] Step S101: Send the target registration information to the aforementioned registration center;
[0039] The aforementioned target registration information refers to the aforementioned registration information of the aforementioned target service instance. Each of the aforementioned service instances has one set of registration information, which includes the IP address of the aforementioned first server to which the aforementioned service instance belongs and the port number of the aforementioned service instance. Any two of the aforementioned service instances have different port numbers.
[0040] Step S102: Receive the target service number sent from the above-mentioned registration center;
[0041] Wherein, the target service number is a service number in the database that is not bound to the service instance. One service number is bound to at most one service instance. The registration center is used to obtain the target service number from the database, bind the target service number to the target service instance, and send the target service number to the target service instance.
[0042] Step S103: Upon receiving the target information sent by the third server, generate a target serial number based at least on the target service number.
[0043] The aforementioned target information indicates a request to invoke the aforementioned target service instance, and the aforementioned target serial number includes the aforementioned target service number.
[0044] Through the above embodiments, the service number is uniformly maintained by the registration center. When the target service instance registers with the registration center, it obtains a unique service number that is not bound to other service instances. A serial number is generated using this service number to ensure the uniqueness of the serial number. Since the service number is managed by the registration center of the distributed system itself, the service instance does not need to communicate with additional devices, which improves the efficiency of serial number generation. This solves the problem that the serial number generation method in the prior art cannot balance uniqueness and efficiency.
[0045] To further ensure the uniqueness of the generated serial number, step S103 above can be implemented as follows:
[0046] Step S1031: When there are multiple target information, obtain multiple target timestamps. Each target timestamp corresponds to one of the target information. The target timestamp is the time node when the target service instance receives the target information.
[0047] Step S1032: Based at least on the target service number and the multiple target timestamps, generate multiple target serial numbers, each of which corresponds one-to-one with the target timestamps. Each target serial number also includes the corresponding target timestamp.
[0048] Specifically, since the third server may call the target service instance multiple times, the time node when the target service instance receives the call request, i.e., the target timestamp, is added to the target serial number to ensure the uniqueness of the generated serial number.
[0049] To further ensure the uniqueness of the generated serial number, step S1032 above can be implemented as follows:
[0050] In the case of multiple identical target timestamps, the first target quantity is obtained, which is the quantity of target information with the corresponding target serial number.
[0051] Obtain the second target quantity, which is the sum of the first target quantity and 1;
[0052] Based on the aforementioned target service number, the aforementioned target timestamp, and the aforementioned second target quantity, the aforementioned target serial number is generated, and the aforementioned target serial number also includes the aforementioned second target quantity.
[0053] Specifically, since the third server may have multiple requests to call the target service instance at the same time, the target serial number is generated by incrementing by 1 to ensure the uniqueness of the generated serial number.
[0054] Following step S103, the method further includes:
[0055] Step S201: In each heartbeat cycle, send a heartbeat to the above-mentioned registration center so that the above-mentioned registration center extends the target binding period by a preset time. The above-mentioned heartbeat cycle is the period during which the above-mentioned target service instance communicates with the above-mentioned registration center at regular intervals. The above-mentioned target binding period is the duration for which the above-mentioned target service instance is bound to the above-mentioned target service number.
[0056] Specifically, when the target service instance sends a heartbeat to the registry center, the registry center will extend the binding time between the target service instance and the target service number by a preset time, that is, renew the lease of the target service number.
[0057] Following step S201, the method further includes:
[0058] Sending offline information to the aforementioned registry center causes the registry center to unbind the aforementioned target service ID from the aforementioned target service instance. The offline information indicates that the aforementioned target service instance is offline.
[0059] Specifically, during the operation of the target service instance, there is a possibility that the target service instance will go offline normally. The target service instance sends offline information to the registry center to indicate that the target service instance is offline. At this time, the registry center will unbind the target service number from the target service instance, that is, reclaim and release the service number, effectively avoiding the endless increase of service numbers, thereby achieving efficient utilization of service numbers.
[0060] This embodiment provides a method for managing service numbers. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Also, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0061] The distributed system includes multiple first servers and second servers. Each first server is configured with multiple service instances. Each second server is configured with a registry center and a database. Each service instance is connected to the registry center, and the registry center is connected to the database. The database is used to store multiple service IDs. Any two service IDs in the database are different. Each service ID is a string of characters. The method described above is applied to the registry center.
[0062] Figure 2 This is a flowchart of a service number management method according to an embodiment of this application. Figure 2 As shown, the method includes the following steps:
[0063] Step S301: Detect whether target registration information has been received from the target service instance;
[0064] Wherein, the aforementioned target service instance is any one of the aforementioned service instances on the target server, the aforementioned target server is any one of the aforementioned first servers, the aforementioned target registration information is the aforementioned registration information corresponding to the aforementioned target service instance, one of the aforementioned service instances has one registration information, the aforementioned registration information includes the IP address of the aforementioned first server to which the aforementioned service instance belongs and the port number of the aforementioned service instance, and the port numbers of any two of the aforementioned service instances are different.
[0065] Step S302: Upon receiving the target registration information, retrieve the target service number from the database, bind the target service number to the target service instance, and send the target service number to the target service instance.
[0066] The target service number mentioned above is a service number in the database that is not bound to the service instance mentioned above.
[0067] Through the above embodiments, the service number is uniformly maintained by the registration center. When the target service instance registers with the registration center, it obtains a unique service number that is not bound to other service instances. A serial number is generated using this service number to ensure the uniqueness of the serial number. Since the service number is managed by the registration center of the distributed system itself, the service instance does not need to communicate with additional devices, which improves the efficiency of serial number generation. This solves the problem that the serial number generation method in the prior art cannot balance uniqueness and efficiency.
[0068] To achieve efficient utilization of service numbers, after step S302, the above method further includes:
[0069] Check whether the offline information sent by the above target service instance has been received. The offline information indicates that the above target service instance is offline.
[0070] Upon receiving the aforementioned offline information from the target service instance, the target service ID will be unbound from the target service instance.
[0071] Specifically, during the operation of the target service instance, there is a possibility that the target service instance will go offline normally. The target service instance sends offline information to the registry center to indicate that the target service instance is offline. At this time, the registry center will unbind the target service number from the target service instance, that is, reclaim and release the service number, effectively avoiding the endless increase of service numbers, thereby achieving efficient utilization of service numbers.
[0072] To achieve efficient utilization of service numbers, after step S302, the above method further includes:
[0073] The system detects whether a heartbeat is received from the target service instance within N consecutive heartbeat cycles. The heartbeat cycle is the period during which the target service instance communicates with the registration center periodically. N is a positive integer and N > 1.
[0074] If no heartbeat is received from the target service instance within N consecutive heartbeat cycles, the target service ID will be unbound from the target service instance.
[0075] Specifically, during the operation of the target service instance, there is a possibility that the target service instance will go offline abnormally. The registry center checks whether it receives a heartbeat from the target service instance within N consecutive heartbeat cycles. If no heartbeat is received, it is determined that the target service instance has gone offline abnormally. At this time, the registry center unbinds the target service number from the target service instance, that is, it reclaims and releases the service number, effectively avoiding the endless increase of service numbers, thereby achieving efficient utilization of service numbers.
[0076] To achieve efficient utilization of service numbers, after step S302, the above method further includes:
[0077] If a heartbeat is received from the target service within the heartbeat period, the target binding time is extended by a preset time. The heartbeat period is the period during which the target service instance communicates with the registration center at regular intervals, and the target binding time is the time during which the target service instance is bound to the target service number.
[0078] Specifically, when the target service instance sends a heartbeat to the registry center, the registry center will extend the binding time between the target service instance and the target service number by a preset time, that is, renew the lease of the target service number.
[0079] This application also provides a serial number generation apparatus. It should be noted that the serial number generation apparatus of this application can be used to execute the serial number generation method provided in this application. This apparatus is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0080] The distributed system includes multiple first servers, second servers, and third servers. Each of the first servers is configured with multiple service instances. Each of the second servers is configured with a registry center and a database. Each of the service instances is communicatively connected to the registry center. The registry center is communicatively connected to the database. The database is used to store multiple service IDs. Any two service IDs in the database are different. Each service ID is a string of characters. The method is applied to a target service instance. The target service instance is any one of the multiple service instances of the target server. The target server is any one of the multiple first servers.
[0081] The serial number generation apparatus provided in the embodiments of this application is described below.
[0082] Figure 3 This is a structural block diagram of a serial number generation apparatus according to an embodiment of this application. Figure 3 As shown, the device includes:
[0083] The first sending unit 10 is used to send target registration information to the registration center. The target registration information is the registration information of the target service instance. Each service instance has one registration information. The registration information includes the IP address of the first server to which the service instance belongs and the port number of the service instance. Any two service instances have different port numbers.
[0084] The receiving unit 20 is used to receive a target service number sent from the registration center. The target service number is a service number in the database that is not bound to the service instance. One service number is bound to at most one service instance. The registration center is used to obtain the target service number from the database, bind the target service number to the target service instance, and send the target service number to the target service instance.
[0085] The generation unit 30 is configured to generate a target serial number based at least on the target service number when receiving the target information sent by the third server. The target information indicates a request to call the target service instance, and the target serial number includes the target service number.
[0086] Through the above embodiments, the service number is uniformly maintained by the registration center. When the target service instance registers with the registration center, it obtains a unique service number that is not bound to other service instances. A serial number is generated using this service number to ensure the uniqueness of the serial number. Since the service number is managed by the registration center of the distributed system itself, the service instance does not need to communicate with additional devices, which improves the efficiency of serial number generation. This solves the problem that the serial number generation method in the prior art cannot balance uniqueness and efficiency.
[0087] To further ensure the uniqueness of the generated serial number, the first generation unit mentioned above includes:
[0088] The acquisition module is used to acquire multiple target timestamps when there are multiple target information. Each target timestamp corresponds to one of the target information. The target timestamp is the time node when the target service instance receives the target information.
[0089] The generation module is used to generate multiple target serial numbers based on at least the target service number and multiple target timestamps, wherein each target serial number corresponds one-to-one with the target timestamp, and each target serial number also includes the corresponding target timestamp.
[0090] Specifically, since the third server may call the target service instance multiple times, the time node when the target service instance receives the call request, i.e., the target timestamp, is added to the target serial number to ensure the uniqueness of the generated serial number.
[0091] To further ensure the uniqueness of the generated serial numbers, the above generation module includes:
[0092] The first acquisition submodule is used to acquire the first target quantity when multiple target timestamps are the same, wherein the first target quantity is the number of target information with the corresponding target serial number;
[0093] The second acquisition submodule is used to acquire the second target quantity, which is the sum of the first target quantity and 1.
[0094] The generation submodule is used to generate the target serial number based on the target service number, the target timestamp, and the second target quantity. The target serial number also includes the second target quantity.
[0095] Specifically, since the third server may have multiple requests to call the target service instance at the same time, the target serial number is generated by incrementing by 1 to ensure the uniqueness of the generated serial number.
[0096] The aforementioned serial number generation device also includes:
[0097] The registration unit is used to send a heartbeat to the registration center once in each heartbeat cycle, so that the registration center extends the target binding period by a preset time. The heartbeat cycle is the period during which the target service instance communicates with the registration center at regular intervals, and the target binding period is the duration for which the target service instance is bound to the target service number.
[0098] Specifically, when the target service instance sends a heartbeat to the registry center, the registry center will extend the binding time between the target service instance and the target service number by a preset time, that is, renew the lease of the target service number.
[0099] The aforementioned serial number generation device also includes:
[0100] The third sending unit is used to send offline information to the above-mentioned registration center, so that the above-mentioned registration center unbinds the above-mentioned target service number from the above-mentioned target service instance. The offline information indicates that the above-mentioned target service instance is offline.
[0101] Specifically, during the operation of the target service instance, there is a possibility that the target service instance will go offline normally. The target service instance sends offline information to the registry center to indicate that the target service instance is offline. At this time, the registry center will unbind the target service number from the target service instance, that is, reclaim and release the service number, effectively avoiding the endless increase of service numbers, thereby achieving efficient utilization of service numbers.
[0102] The aforementioned serial number generation device includes a processor and a memory. The first sending unit, receiving unit, and generating unit are all stored as program units in the memory, and the processor executes the program units stored in the memory to achieve the corresponding functions. All of the above modules are located in the same processor; alternatively, the modules may be located in different processors in any combination.
[0103] The processor contains a kernel, which retrieves the corresponding program unit from memory. One or more kernels can be configured, and adjusting kernel parameters can address the issue that existing serial number generation methods cannot simultaneously achieve uniqueness and efficiency.
[0104] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0105] This application also provides a service number management device. It should be noted that the service number management device of this application can be used to execute the service number management method provided in this application. This device is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0106] The distributed system includes multiple first servers and second servers. Each first server is configured with multiple service instances. Each second server is configured with a registry center and a database. Each service instance is connected to the registry center. The registry center is connected to the database. The database is used to store multiple service numbers. Any two service numbers in the database are different. Each service number is a string of characters. The management device for the service numbers is applied to the registry center.
[0107] The following describes the service number management device provided in the embodiments of this application.
[0108] Figure 4 This is a structural block diagram of a service number management device according to an embodiment of this application. For example... Figure 4 As shown, the device includes:
[0109] The first detection unit 40 is used to detect whether target registration information is received from the target service instance. The target service instance is any one of the service instances on the target server. The target server is any one of the multiple first servers. The target registration information is the registration information corresponding to the target service instance. Each service instance has one registration information. The registration information includes the IP address of the first server to which the service instance belongs and the port number of the service instance. The port numbers of any two service instances are different.
[0110] The second sending unit 50 is configured to, upon receiving the target registration information, obtain a target service number from the database, bind the target service number to the target service instance, and send the target service number to the target service instance, wherein the target service number is a service number in the database that is not bound to the service instance.
[0111] Through the above embodiments, the service number is uniformly maintained by the registration center. When the target service instance registers with the registration center, it obtains a unique service number that is not bound to other service instances. A serial number is generated using this service number to ensure the uniqueness of the serial number. Since the service number is managed by the registration center of the distributed system itself, the service instance does not need to communicate with additional devices, which improves the efficiency of serial number generation. This solves the problem that the serial number generation method in the prior art cannot balance uniqueness and efficiency.
[0112] To achieve efficient utilization of service numbers, the aforementioned service number management device also includes:
[0113] The second detection unit is used to detect whether it receives the offline information sent by the target service instance, which indicates that the target service instance is offline.
[0114] The first unbinding unit is used to unbind the target service number from the target service instance upon receiving the offline information sent by the target service instance.
[0115] Specifically, during the operation of the target service instance, there is a possibility that the target service instance will go offline normally. The target service instance sends offline information to the registry center to indicate that the target service instance is offline. At this time, the registry center will unbind the target service number from the target service instance, that is, reclaim and release the service number, effectively avoiding the endless increase of service numbers, thereby achieving efficient utilization of service numbers.
[0116] To achieve efficient utilization of service numbers, the aforementioned service number management device also includes:
[0117] The third detection unit is used to detect whether a heartbeat sent by the target service instance is received within N consecutive heartbeat cycles. The heartbeat cycle is the period during which the target service instance communicates with the registration center at regular intervals. N is a positive integer and N>1.
[0118] The second unbinding unit is used to unbind the target service number from the target service instance if no heartbeat is received from the target service instance within N consecutive heartbeat cycles.
[0119] Specifically, during the operation of the target service instance, there is a possibility that the target service instance will go offline abnormally. The registry center checks whether it receives a heartbeat from the target service instance within N consecutive heartbeat cycles. If no heartbeat is received, it is determined that the target service instance has gone offline abnormally. At this time, the registry center unbinds the target service number from the target service instance, that is, it reclaims and releases the service number, effectively avoiding the endless increase of service numbers, thereby achieving efficient utilization of service numbers.
[0120] To achieve efficient utilization of service numbers, the aforementioned service number management device also includes:
[0121] The processing unit is configured to extend the target binding time by a preset time when it receives a heartbeat sent by the target service within the heartbeat period. The heartbeat period is the period during which the target service instance communicates with the registration center at regular intervals, and the target binding time is the time during which the target service instance is bound to the target service number.
[0122] Specifically, when the target service instance sends a heartbeat to the registry center, the registry center will extend the binding time between the target service instance and the target service number by a preset time, that is, renew the lease of the target service number.
[0123] The aforementioned service number management device includes a processor and a memory. The first detection unit and the second transmission unit, etc., are all stored as program units in the memory, and the processor executes the program units stored in the memory to achieve the corresponding functions. All of the above modules are located in the same processor; alternatively, the above modules may be located in different processors in any combination.
[0124] The processor contains a kernel, which retrieves the corresponding program unit from memory. One or more kernels can be configured, and adjusting kernel parameters can address the issue that existing serial number generation methods cannot simultaneously achieve uniqueness and efficiency.
[0125] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0126] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0127] 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.
[0128] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will 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, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0129] 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, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0130] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0131] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0132] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0133] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0134] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0135] As can be seen from the above description, the embodiments of this application achieve the following technical effects:
[0136] 1) In the serial number generation method of this application, the service number is uniformly maintained by the registration center. When the target service instance registers with the registration center, it obtains a unique service number that is not bound to other service instances. The serial number is generated using this service number to ensure the uniqueness of the serial number. Since the service number is managed by the registration center of the distributed system itself, the service instance does not need to communicate with additional devices, which improves the efficiency of serial number generation and solves the problem that the serial number generation method in the prior art cannot take into account both uniqueness and efficiency.
[0137] 2) In the service number management method of this application, the service number is uniformly maintained by the registration center. When the target service instance registers with the registration center, it obtains a unique service number that is not bound to other service instances. A serial number is generated using this service number to ensure the uniqueness of the serial number. Since the service number is managed by the registration center of the distributed system itself, the service instance does not need to communicate with additional devices, which improves the efficiency of serial number generation and solves the problem that the serial number generation method in the prior art cannot take into account both uniqueness and efficiency.
[0138] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method of generating a flow number, characterized by, The distributed system includes multiple first servers, second servers, and third servers. Each first server is configured with multiple service instances. The second server is configured with a registry center and a database. Each service instance is communicatively connected to the registry center, and the registry center is communicatively connected to the database. The database stores multiple service IDs, and any two service IDs in the database are different. Each service ID is a string of characters. The method is applied to a target service instance, which is any one of the multiple service instances on the target server. The target server is any one of the multiple first servers. The method includes: Send target registration information to the registration center. The target registration information is the registration information of the target service instance. Each service instance has one registration information. The registration information includes the IP address of the first server to which the service instance belongs and the port number of the service instance. The port numbers of any two service instances are different. The system receives a target service number sent from the registry center. The target service number is a service number in the database that is not bound to the service instance. One service number is bound to at most one service instance. The registry center is used to retrieve the target service number from the database, bind the target service number to the target service instance, and send the target service number to the target service instance. Upon receiving the target information sent by the third server, a target serial number is generated based at least on the target service number. The target information indicates a request to invoke the target service instance, and the target serial number includes the target service number. Upon receiving target information sent by the third server, generating a target serial number based at least on the target service number includes: if there are multiple target information items, obtaining multiple target timestamps, each target timestamp corresponding to a target information item, wherein the target timestamp is the time node at which the target service instance receives the target information; generating multiple target serial numbers based at least on the target service number and the multiple target timestamps, each target serial number corresponding to a target timestamp, wherein the target serial number also includes the corresponding target timestamp; The process of generating multiple target serial numbers based at least on the target service number and multiple target timestamps includes: when multiple target timestamps are the same, obtaining a first target quantity, the first target quantity being the number of target information with corresponding target serial numbers; obtaining a second target quantity, the second target quantity being the sum of the first target quantity and 1; generating the target serial number based on the target service number, the target timestamps and the second target quantity, the target serial number further including the second target quantity.
2. The method according to claim 1, characterized in that, Upon receiving the target information sent by the third server, after generating a target serial number based at least on the target service number, the method further includes: Within each heartbeat cycle, a heartbeat is sent to the registry center to extend the target binding period by a preset time. The heartbeat cycle is the period during which the target service instance communicates with the registry center periodically, and the target binding period is the duration for which the target service instance is bound to the target service number.
3. The method of claim 2, wherein, Within each heartbeat cycle, a heartbeat is sent to the registry center so that the registry center extends the target binding period by a preset time. The method further includes: Send offline information to the registry center, so that the registry center unbinds the target service ID from the target service instance. The offline information indicates that the target service instance is offline.
4. A method for managing service numbers, characterized in that, The distributed system includes multiple first servers, second servers, and third servers. Each first server is configured with multiple service instances. The second servers are configured with a registry center and a database. Each service instance is communicatively connected to the registry center, and the registry center is communicatively connected to the database. The database stores multiple service IDs, and any two service IDs in the database are different. Each service ID is a string of characters. The method is applied to the registry center, and the method includes: Detect whether target registration information is received from the target service instance. The target service instance is any one of the service instances on the target server. The target server is any one of the multiple first servers. The target registration information is the registration information corresponding to the target service instance. Each service instance has one registration information. The registration information includes the IP address of the first server to which the service instance belongs and the port number of the service instance. The port numbers of any two service instances are different. Upon receiving the target registration information, the target service number is retrieved from the database, the target service number is bound to the target service instance, and the target service number is sent to the target service instance. The target service number is a service number in the database that is not bound to the service instance. The target service number is used by the target service instance to generate a target serial number when the target service instance receives target information sent by the third server. The target information represents a request to invoke the target service instance, and the target serial number includes the target service number. The process of generating the target serial number by the target service instance is as follows: if there are multiple target information entries, multiple target timestamps are obtained, each corresponding to a specific target information entry. The target timestamp is the time node when the target service instance receives the target information. At least based on the target service number and the multiple target timestamps, multiple target serial numbers are generated, with each target serial number corresponding to a specific target timestamp. The target serial number also includes the corresponding target timestamp. The process of generating multiple target serial numbers based at least on the target service number and multiple target timestamps includes: when multiple target timestamps are the same, obtaining a first target quantity by the target service instance, the first target quantity being the number of target information items with corresponding target serial numbers; obtaining a second target quantity, the second target quantity being the sum of the first target quantity and 1; and generating the target serial number by the target service instance based on the target service number, the target timestamps, and the second target quantity, wherein the target serial number further includes the second target quantity.
5. The method according to claim 4, characterized in that, Upon receiving the target registration information, the method further includes retrieving the target service ID from the database, binding the target service ID to the target service instance, and sending the target service ID to the target service instance. Detect whether a shutdown message is received from the target service instance, the shutdown message indicating that the target service instance is offline; Upon receiving the offline information sent by the target service instance, the target service ID is unbound from the target service instance.
6. The method of claim 4, wherein, Upon receiving the target registration information, the method further includes retrieving the target service ID from the database, binding the target service ID to the target service instance, and sending the target service ID to the target service instance. The system detects whether a heartbeat is received from the target service instance within N consecutive heartbeat cycles. The heartbeat cycle is the period during which the target service instance communicates with the registration center periodically. N is a positive integer and N > 1. If no heartbeat is received from the target service instance within N consecutive heartbeat cycles, the target service ID is unbound from the target service instance.
7. The method of claim 4, wherein, Upon receiving the target registration information, the method further includes retrieving the target service ID from the database, binding the target service ID to the target service instance, and sending the target service ID to the target service instance. If a heartbeat is received from the target service within the heartbeat period, the target binding time is extended by a preset time. The heartbeat period is the period during which the target service instance communicates with the registration center periodically, and the target binding time is the time during which the target service instance is bound to the target service number.
8. An apparatus for generating a flow number, characterized by The distributed system includes multiple first servers, second servers, and third servers. Each first server is configured with multiple service instances. The second server is configured with a registry center and a database. Each service instance is communicatively connected to the registry center, and the registry center is communicatively connected to the database. The database stores multiple service IDs, and any two service IDs in the database are different. Each service ID is a string of characters. The device is applied to a target service instance, which is any one of the multiple service instances of the target server. The target server is any one of the multiple first servers. The device includes: The first sending unit is used to send target registration information to the registration center. The target registration information is the registration information of the target service instance. Each service instance has one registration information. The registration information includes the IP address of the first server to which the service instance belongs and the port number of the service instance. Any two service instances have different port numbers. A receiving unit is configured to receive a target service number sent from the registration center, wherein the target service number is a service number in the database that is not bound to the service instance, and one service number is bound to at most one service instance. The registration center is configured to bind the target service instance to the target service number, and the registration center is configured to retrieve the target service number from the database, bind the target service number to the target service instance, and send the target service number to the target service instance. The generation unit is configured to generate a target serial number based at least on the target service number when receiving target information sent by the third server, wherein the target information indicates a request to invoke the target service instance, and the target serial number includes the target service number; The generation unit includes: an acquisition module, configured to acquire multiple target timestamps when there are multiple target information, wherein each target timestamp corresponds one-to-one with the target information, and the target timestamp is the time node when the target service instance receives the target information; and a generation module, configured to generate multiple target serial numbers based at least on the target service number and the multiple target timestamps, wherein each target serial number corresponds one-to-one with the target timestamps, and the target serial number also includes the corresponding target timestamp. The generation module includes: a first acquisition submodule, configured to acquire a first target quantity when multiple target timestamps are identical, wherein the first target quantity is the number of target information with corresponding target serial numbers; a second acquisition submodule, configured to acquire a second target quantity, wherein the second target quantity is the sum of the first target quantity and 1; and a generation submodule, configured to generate the target serial number based on the target service number, the target timestamp, and the second target quantity, wherein the target serial number further includes the second target quantity.
9. A service number management apparatus characterized by comprising: The distributed system includes multiple first servers, second servers, and third servers. Each first server is configured with multiple service instances. The second servers are configured with a registry center and a database. Each service instance is communicatively connected to the registry center. The registry center is communicatively connected to the database. The database stores multiple service IDs, and any two service IDs in the database are different. Each service ID is a string of characters. The device is applied to the registry center and includes: The first detection unit is used to detect whether target registration information is received from the target service instance. The target service instance is any one of the service instances on the target server. The target server is any one of the multiple first servers. The target registration information is the registration information corresponding to the target service instance. Each service instance has one registration information. The registration information includes the IP address of the first server to which the service instance belongs and the port number of the service instance. The port numbers of any two service instances are different. The second sending unit is configured to, upon receiving the target registration information, obtain a target service number from the database, bind the target service number to the target service instance, and send the target service number to the target service instance, wherein the target service number is a service number in the database that is not bound to the service instance; The target service number is used to generate a target serial number by the target service instance when the target service instance receives target information sent by the third server. The target information represents a request to invoke the target service instance, and the target serial number includes the target service number. The process of generating the target serial number by the target service instance is as follows: when there are multiple target information items, multiple target timestamps are obtained, each target timestamp corresponding to a specific target information item, and the target timestamp is the time node when the target service instance receives the target information; multiple target serial numbers are generated based at least on the target service number and the multiple target timestamps, and each target serial number corresponds one-to-one with a target timestamp, with the target serial number also including the corresponding target timestamp. The process of generating multiple target serial numbers based at least on the target service number and multiple target timestamps includes: when multiple target timestamps are the same, obtaining a first target quantity by the target service instance, the first target quantity being the number of target information items with corresponding target serial numbers; obtaining a second target quantity, the second target quantity being the sum of the first target quantity and 1; and generating the target serial number by the target service instance based on the target service number, the target timestamps, and the second target quantity, wherein the target serial number further includes the second target quantity.