Node identification management method, global identification generation method and computing device

Through the automatic allocation and recycling mechanism of node IDs, combined with the global ID generation method, the problems of node ID resource waste and time callback are solved, efficient node identification management and global ID generation are realized, and dynamic expansion and capacity are supported.

CN116319678BActive Publication Date: 2025-08-15UNIONTECH SOFTWARE TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202310274135.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-17
Publication Date
2025-08-15
Estimated Expiration
2043-03-17

AI Technical Summary

Technical Problem

In the prior art, node ID resources are seriously wasted, and the global ID generation method has time callback problems, so it is impossible to efficiently manage node identifiers in the cluster.

Method used

The automatic allocation and recycling mechanism of node ID is adopted to allocate node IDs by detecting the accumulation of available IDs and maximum IDs, and combined with the global ID generation method, a 32-bit second number of timestamp and node ID are used to generate a global ID.

Benefits of technology

It realizes efficient management and resource utilization of node IDs, reduces the impact of time callbacks, supports dynamic expansion and capacity improvement, and improves system flexibility and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116319678B_ABST
    Figure CN116319678B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for managing node identifiers, a method for generating global identifiers, and a computing device, and relates to the field of computers. The method for managing node identifiers of the present invention comprises: receiving a node identifier ID application request sent by any node, and detecting whether an available node ID currently exists among the generated node IDs. If so, determining a target node ID from the available node IDs and assigning it to the node. If not, obtaining the maximum node ID among the generated node IDs, adding one to the maximum node ID, and assigning the node ID obtained by the addition as the target node ID to the node. The present invention realizes the automatic allocation and recycling of node IDs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a node identification management method, a global identification generation method, and a computing device. Background Art

[0002] With the development of information technology, the scale of internet applications (both in terms of user base and user data volume) has continued to grow. A system often consists of multiple machines forming a cluster, working together to provide external services. Each node in the cluster requires a unique identifier (i.e., ID). Currently, each node is typically assigned a node ID in advance, which wastes node ID resources. Furthermore, global identifiers (i.e., global IDs) are currently mostly generated based on Twitter's open-source Snowflake algorithm, but this approach suffers from time rollback issues.

[0003] To this end, the present invention provides a node identification management method and a global identification generation method to solve the above technical problems. Summary of the Invention

[0004] To this end, the present invention provides a node identification management method, a global identification generation method and a computing device, in an effort to solve or at least alleviate the above problems.

[0005] According to one aspect of the present invention, a method for managing node identification is provided, comprising: receiving a node identification ID application request sent by any node, detecting whether there is an available node ID currently in the generated node IDs; if so, determining a target node ID from the available node IDs and assigning it to the node; if not, obtaining the maximum node ID in the generated node IDs, adding one to the maximum node ID, and assigning the accumulated node ID to the node as the target node ID.

[0006] Optionally, in the node identification management method according to the present invention, the duration that the node possesses the target node ID is a first duration, and after possessing the target node ID, the node sends a node ID renewal request every second duration, and the second duration is less than the first duration. Accordingly, the method also includes: receiving the node ID renewal request sent by the node, and detecting whether the node meets the conditions for renewal; if so, resetting the duration that the node possesses the target node ID to the first duration; if not, sending a renewal failure message to the node.

[0007] Optionally, in the node identification management method according to the present invention, the database system stores the time of the last successful renewal of each generated node ID. Accordingly, detecting whether there is an available node ID currently among the generated node IDs includes: obtaining the time of the last successful renewal of each generated node ID from the database system, and obtaining the difference between the current time and the time of the last successful renewal of each node ID; comparing each difference with a first duration; if there is a difference greater than the first duration, determining that there is an available node ID currently among the generated node IDs; otherwise, determining that there is no available node ID currently among the generated node IDs.

[0008] Optionally, in the node identification management method according to the present invention, the database system also stores the nodes currently associated with each generated node ID, and the node ID renewal request includes the node ID to be renewed. Accordingly, detecting whether the node meets the renewal conditions includes: obtaining the node currently associated with the node ID to be renewed from the database system, and detecting whether it is the node that sends the node ID renewal request; if so, obtaining the difference between the current time and the last successful renewal time of the node ID to be renewed, and detecting whether the difference is less than a third time period, and the third time period is greater than the first time period; if it is less than, determining that the node meets the renewal conditions, otherwise, determining that the node does not meet the renewal conditions.

[0009] Optionally, the node identification management method according to the present invention further includes: if the node continuously receives renewal failure messages within a third time period, resending the node ID application request.

[0010] Optionally, in the node identifier management method according to the present invention, the first duration is greater than twice the second duration.

[0011] According to another aspect of the present invention, a method for generating a global identifier is provided, comprising: when any node generates a global identifier ID, obtaining the difference between the current time and a preset reference time, and expressing it in 32-bit seconds, and adding one to the serial number in the last generated global ID, where the serial number is a 19-bit integer; using the difference as the first 32 bits, the node ID of the node as the middle bit, and the accumulated serial number as the last 19 bits to generate the global ID, wherein the node ID of the node is managed by the method described above, and the node ID is a 13-bit integer.

[0012] According to another aspect of the present invention, a node identification management device is provided, comprising: a detection unit, adapted to receive a node identification ID application request sent by any node, and detect whether there is an available node ID currently in the generated node IDs; an allocation unit, adapted to determine the target node ID from the available node IDs and allocate it to the node if it exists; an accumulation unit, adapted to obtain the maximum node ID in the generated node IDs and accumulate the maximum node ID by one if it does not exist, and allocate the accumulated node ID as the target node ID to the node.

[0013] According to another aspect of the present invention, a computing device is provided, comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be suitable for execution by the at least one processor, and the program instructions include instructions for executing any of the above methods.

[0014] According to another aspect of the present invention, a readable storage medium storing program instructions is provided. When the program instructions are read and executed by a computing device, the computing device executes any one of the above methods.

[0015] The node identification management method of the present invention enables the automatic allocation and recycling of node IDs. This, combined with container technology and automated operation and maintenance techniques, enables dynamic capacity expansion and contraction. Furthermore, the first 32 bits of the global ID of the present invention are in seconds, which significantly reduces the impact of time rollbacks. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] To achieve the above and related purposes, certain illustrative aspects are described herein in conjunction with the following description and accompanying drawings, which indicate various ways in which the principles disclosed herein may be practiced, and all aspects and their equivalents are intended to fall within the scope of the claimed subject matter. The above and other objects, features, and advantages of the present disclosure will become more apparent by reading the following detailed description in conjunction with the accompanying drawings. Throughout this disclosure, the same reference numerals generally refer to the same parts or elements.

[0017] Figure 1 shows a structural block diagram of a computing device 100 according to one embodiment of the present invention;

[0018] Figure 2 A flowchart of a method 200 for managing node identification according to an embodiment of the present invention is shown;

[0019] Figure 3 A schematic diagram showing a flow chart of a method for managing node identification according to yet another embodiment of the present invention;

[0020] Figure 4A flowchart of a method 400 for generating a global identifier according to an embodiment of the present invention is shown;

[0021] Figure 5 A structural diagram of a node identification management device 500 according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0022] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0023] Figure 1 A block diagram of the physical components (i.e., hardware) of a computing device 100 is shown. In a basic configuration, the computing device 100 includes at least one processing unit 102 and a system memory 104. According to one aspect, depending on the configuration and type of the computing device, the processing unit 102 can be implemented as a processor. The system memory 104 includes, but is not limited to, volatile storage (e.g., random access memory), non-volatile storage (e.g., read-only memory), flash memory, or any combination of such memories. According to one aspect, the system memory 104 includes an operating system 105 and a program module 106, the program module 106 includes a node identification management device 500, and the node identification management device 500 is configured to execute the node identification management method 200 of the present invention.

[0024] According to one aspect, operating system 105 is suitable for controlling the operation of computing device 100, for example. Furthermore, examples may be practiced in conjunction with graphics libraries, other operating systems, or any other application programs, and are not limited to any particular application or system. Figure 1 This basic configuration is illustrated in FIG by those components within dashed line 108. According to one aspect, computing device 100 has additional features or functionality. For example, according to one aspect, computing device 100 includes additional data storage devices (removable and / or non-removable), such as magnetic disks, optical disks, or tapes. Such additional storage Figure 1 1 is illustrated by a removable storage device 109 and a non-removable storage device 110.

[0025] As stated above, according to one aspect, program modules are stored in the system memory 104. According to one aspect, the program modules may include one or more application programs, and the present invention is not limited to the type of application program. For example, the application program may include an email and contact application program, a word processing application program, a spreadsheet application program, a database application program, a slide show application program, a drawing or computer-aided application program, a web browser application program, etc.

[0026] According to one aspect, examples may be practiced on a circuit comprising discrete electronic components, a packaged or integrated electronic chip containing logic gates, a circuit utilizing a microprocessor, or a single chip containing electronic components or a microprocessor. Figure 1 Each or many components shown in can be integrated into a system on a chip (SOC) on a single integrated circuit to practice examples. According to one aspect, such an SOC device may include one or more processing units, a graphics unit, a communication unit, a system virtualization unit, and various application functions, all of which are integrated (or "burned") onto a chip substrate as a single integrated circuit. When operated via SOC, the functions described in this article can be operated via dedicated logic integrated with other components of the computing device 100 on a single integrated circuit (chip). Embodiments of the present invention can also be practiced using other technologies capable of performing logical operations (such as AND, OR, and NOT), including but not limited to mechanical, optical, fluid, and quantum technologies. In addition, embodiments of the present invention can be practiced in a general-purpose computer or in any other circuit or system.

[0027] According to one aspect, the computing device 100 may also have one or more input devices 112, such as a keyboard, a mouse, a pen, a voice input device, a touch input device, etc. It may also include an output device 114, such as a display, a speaker, a printer, etc. The aforementioned devices are examples, and other devices may also be used. The computing device 100 may include one or more communication connections 116 that allow communication with other computing devices 118. Examples of suitable communication connections 116 include, but are not limited to: RF transmitter, receiver, and / or transceiver circuitry; Universal Serial Bus (USB), parallel, and / or serial ports.

[0028] As used herein, the term computer-readable medium includes computer storage media. Computer storage media can include volatile and non-volatile, removable and non-removable media implemented with any method or technology for storing information (e.g., computer-readable instructions, data structures, or program modules). System memory 104, removable storage device 109, and non-removable storage device 110 are all examples of computer storage media (i.e., memory storage). Computer storage media can include random access memory (RAM), read-only memory (ROM), electrically erasable read-only memory (EEPROM), flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical storage, cassette tape, magnetic tape, disk storage or other magnetic storage device, or any other product that can be used to store information and can be accessed by computer device 100. According to one aspect, any such computer storage medium can be a part of computing device 100. Computer storage media does not include carrier waves or other propagated data signals.

[0029] According to one aspect, communication media is implemented by computer-readable instructions, data structures, program modules, or other data in a modulated data signal (e.g., a carrier wave or other transport mechanism), and includes any information delivery media. According to one aspect, the term "modulated data signal" describes a signal that has one or more characteristics set or changed in such a manner as to encode information in the signal. By way of example, and not limitation, communication media includes wired media such as a wired network or direct-wired connection, and wireless media such as acoustic, radio frequency (RF), infrared, and other wireless media.

[0030] Figure 2 A flowchart of a node identification management method 200 according to an embodiment of the present invention is shown. The method 200 is suitable for managing a node identification in a computing device (eg Figure 1 The method 200 is executed in the computing device 100 shown in the figure. Furthermore, the method 200 is suitable for being executed in the node identification management service of the computing device (ie the node identification management device mentioned above).

[0031] Let's first explain what a node is. A node primarily refers to a program process that provides external services. For example, in Kubernetes or virtualization, this typically refers to a pod node or a container. A single physical machine or virtual operating system terminal can host multiple service programs, pod nodes, or Docker containers.

[0032] After understanding the concept of node, the node identification management method 200 of the present invention will be described. Figure 2As shown, the method 200 begins at 210. At 210, a node identification ID application request is received from any node, and a check is performed to determine whether any node ID is currently available among the generated node IDs. An available node ID is an assignable node ID. Specifically, it does not currently belong to any node and can be assigned to any node.

[0033] In this embodiment, after any node applies for a node ID, the duration for which it possesses the node ID is a limited duration, such as a first duration. The node can extend the duration for which it possesses this node ID by renewing the contract. For example, each time a node successfully renews its contract, the duration for which it possesses this node ID is updated to the first duration (the renewal of the node ID will be described in detail later). In addition, the database system stores the time when each generated node ID was last successfully renewed (i.e., the time of the most recent successful renewal). Therefore, in this embodiment, it is possible to determine whether there is an available node ID among the generated node IDs by detecting whether the time of the most recent successful renewal of each generated node ID exceeds the first duration from the current time, as follows.

[0034] When a node ID application request is received from any node, the time when each generated node ID was last successfully renewed is obtained from the database system, and the difference between the current time and the time when each generated node ID was last successfully renewed is obtained, that is, the current time is subtracted from the time when each node ID was last successfully renewed. Then, the obtained differences are compared with the first duration. If there is a difference greater than the first duration, it indicates that at least one node ID among the generated node IDs is no longer used by any node (that is, at least one node ID among the generated node IDs no longer belongs to any node), and it is determined that there is currently an available node ID among the generated node IDs. If there is no difference greater than the first duration, it indicates that all the generated node IDs are currently in use, and it is determined that there is currently no available node ID among the generated node IDs.

[0035] If there is an available node ID among the generated node IDs, then proceed to 220 to determine the target node ID from the available node IDs and assign it to the above-mentioned node (i.e., the node that sent the node ID application request). In some embodiments, when the target node ID is assigned to the above-mentioned node, the time of the last successful renewal of the target node ID is also correspondingly modified to the current time. In addition, it should be noted that when determining the target node ID from the available node IDs, any node ID among the available node IDs can be determined as the target node. For example, the node ID among the available node IDs whose last successful renewal time is the longest (i.e., the largest difference) from the current time can be determined as the target node ID, and the present invention does not limit this.

[0036] If there is no available node ID among the generated node IDs, proceed to 230 to obtain the maximum node ID among the currently generated node IDs, add one to the maximum node ID, and assign the accumulated node ID as the target node ID to the above-mentioned node. Specifically, first obtain the maximum node ID currently stored in the database system, then add one to it, and then assign the obtained value to the node that sent the node ID application request as its node ID. Furthermore, in some embodiments, after the newly generated node ID is assigned to the above-mentioned node as the target node ID, the target node ID (i.e., the newly generated node ID) and the time when the target node ID was generated are also associated and stored in the database system. It should be noted that in this embodiment, the time when the target node ID was generated is stored in the database system as the time when the target node ID was last successfully renewed.

[0037] Whether a target node ID is assigned from available node IDs to the node that sent the node ID application request, or a newly generated node ID is assigned as the target node ID, the node's possession of the target node ID is limited to the first duration. If the node wishes to extend its possession of the target node ID, it must renew the contract. Specifically, after possessing the target node ID, the node can extend its possession of the target node ID by sending a node ID renewal request every second duration.

[0038] For the node identification management service, after receiving a node ID renewal request including the node ID to be renewed from a node, it is detected whether the node meets the renewal conditions. Specifically, it is possible to detect whether the node meets the renewal conditions based on the associated information of the node ID stored in the database system. In some embodiments, in addition to storing the time when each generated node ID was last successfully renewed, the database system also stores the node to which each generated node ID is currently associated (i.e., the node to which it belongs). Therefore, in this step, it is possible to detect whether the node meets the renewal conditions based on the time when each generated node ID was last successfully renewed and the node to which it is currently associated, as follows.

[0039] After receiving the node ID renewal request sent by the node, the node currently associated with the node ID to be renewed is obtained from the database system, and it is detected whether it is the node that sent the node ID renewal request. If not, it is determined that the node does not meet the conditions for renewal. If so, the time when the node ID to be renewed was last successfully renewed is obtained from the database system, and then the difference between the current time and the time when the node ID to be renewed was last successfully renewed is obtained, that is, the current time is subtracted from the time when the node ID to be renewed was last successfully renewed. Finally, it is detected whether the obtained difference is less than the third time length. If it is less than, it is determined that the node meets the conditions for renewal. If not, it is determined that the node does not meet the conditions for renewal.

[0040] Next, if the node meets the renewal conditions, the duration that the node has held the target node ID is reset to the first duration. That is, the duration that the node has held the target node ID is updated to the first duration based on the current time. In some embodiments, after resetting the duration that the node has held the target node ID to the first duration, the time when the target node ID was last successfully renewed is also correspondingly modified to the current time.

[0041] If the node does not meet the conditions for renewal, a renewal failure message is sent to the node. If the node receives renewal failure messages continuously within the third time period, it resends the node ID application request.

[0042] Here, the first duration, the second duration and the third duration are explained. The third duration is greater than the first duration, the first duration is greater than the second duration, and further, the first duration may be greater than twice the second duration.

[0043] Specifically, in some embodiments, the first duration can be set to 2T+m, the second duration to T, and the third duration to 3T, where m is less than T and T can be set according to actual conditions, for example, several minutes. Regarding m, adding m is mainly used to address the time overhead of the request during network transmission and interface response, to ensure the validity of the time period on the time boundary, and to resolve critical state issues. Generally, the value of m can be set to around 1s (if no response is received within 1s, the request is deemed to have failed). Furthermore, by setting the first duration to 2T+m, the second duration to T, and the third duration to 3T, each node can have two renewal opportunities. Thus, when the system is in high service availability and the availability rate is N, the failure rate of the two attempts can be guaranteed to be below (1-N)^2. For example, taking N>99.9% as an example, the failure rate of the two attempts can be guaranteed to be below 0.000001. Therefore, setting the first duration to 2T+m, the second duration to T, and the third duration to 3T can take into account both efficiency and reduction of the recovery time of invalid IDs.

[0044] It should be noted that the above is merely an example and does not limit the present invention. In specific embodiments, those skilled in the art can set the first, second, and third durations according to actual needs. Furthermore, regarding the node ID, its specific number of digits can be 13, and its initial value can be set to 0. Of course, this is merely an example and does not limit the present invention.

[0045] It can be seen that the present invention manages node IDs by applying for and renewing the node IDs, thereby realizing automatic allocation and recycling of node IDs.

[0046] In order to better understand the present invention, the following Figure 3 The node ID management method of the present invention is illustrated using a specific example. In this example, a table is used in the database system to record the associated information of each generated node ID. Each row in the table records the associated information of a node ID, specifically including the node ID, the time of the node ID's last successful renewal, and the node currently owning the node ID. Furthermore, in this example, the first duration is 2T+m, the second duration is T, and the third duration is 3T. Specifically:

[0047] Node N sends a node ID application request to the management service S, that is, applies for a node ID.

[0048] After receiving the node ID application request, the management service S detects whether there is an available node ID among the generated node IDs based on the last successful renewal time of each node ID recorded in the table.

[0049] If it exists, one of the available node IDs is sent to node N, and the effective duration of node N's possession of the available node ID is set to 2T+m, and the associated information of the available node ID recorded in the table is updated. Specifically, the time when the available node ID was last successfully renewed is changed to the current time, and the node that currently owns the available node ID is changed to node N.

[0050] If it does not exist, obtain the largest node ID recorded in the current table, add one to the value, and then send the obtained ID to node N. At the same time, set the effective duration of node N's possession of the node ID to 2T+m, and add the obtained ID and its associated information to the above table. Specifically, add the time when the node ID is generated to the time when the node ID was last successfully renewed, and add node N to the node that currently owns the node ID.

[0051] At this point, node N has its node ID. Next, node N regularly renews its node ID to the management service S. Specifically, it sends a node ID renewal request to the management service S every time interval T.

[0052] After receiving the node ID renewal request, the management service S determines whether the node N meets the renewal conditions.

[0053] If so, the valid duration of node N's node ID is reset to 2T+m (i.e., the time period during which node N holds its node ID is from the current time t1 to t1+2T+m), and the time of the last successful renewal of the node ID is changed to the current time. If not, a renewal failure message is sent to node N.

[0054] If node N continuously receives renewal failure messages within the 3T period, it will resend a node ID application request to the management service S, that is, reapply for a node ID.

[0055] For details on the node ID management method of this embodiment, please refer to the above-mentioned Figure 1 and Figure 2 The description is not repeated here.

[0056] Based on the node ID management method of the above embodiment, the present invention also provides a method for generating a global identifier. Figure 4 A flowchart of a method 400 for generating a global ID according to one embodiment of the present invention is shown. In this embodiment, the global ID is represented using a 64-bit unsigned long. Specifically, the first 32 bits are the timestamp difference expressed in seconds, the middle 13 bits are the node ID of the node generating the global ID, and the last 19 bits are the sequence number (or serial number) of the global ID generated by the node.

[0057] like Figure 4 As shown, the global identifier generation method 400 of the present invention begins at 410. Specifically, when any node wants to generate a global identifier ID, it proceeds to 410 to obtain the difference between the current time (the node's local time) and the preset reference time, and express it in 32-bit seconds, and increment the sequence number in the last generated global ID by one.

[0058] According to one embodiment of the present invention, the serial number is a 19-digit integer, specifically the last 19 digits of the global ID. Therefore, adding one to the serial number in the last generated global ID is equivalent to adding one to the last 19 digits of the last generated global ID.

[0059] In addition, in some embodiments, the preset reference time may be the system online time, and the initial value of the sequence number may be 0. Of course, this is only an example and the present invention is not limited thereto. In specific embodiments, those skilled in the art may set it according to actual needs.

[0060] Then, the process proceeds to step 420, where the resulting difference is used as the first 32 bits, the node ID of the node is used as the middle bits, and the accumulated sequence number is used as the last 19 bits to generate a global ID, where the node ID is a 13-digit integer. Specifically, this step involves sequentially concatenating the 32-bit difference expressed in seconds, the 13-bit node ID of the node, and the accumulated sequence number to form a global ID. The 13-bit node ID of the node can be managed using the node ID management method described in the above embodiment.

[0061] It can be seen from this that the method for a node to generate a global ID of the present invention is, in summary, to express the difference between the current time and the preset reference time in 32-bit seconds, and use it as the first 32 bits, accumulate the serial number of the global ID generated last time by one, and use it as the last 19 bits, and the middle 13 bits use the node ID currently owned by the node.

[0062] For details on the method for generating the global ID of this embodiment, please refer to the above-mentioned method based on Figures 1 to 3 The description is not repeated here.

[0063] According to one embodiment of the present invention, the exemplary code of the node ID management part is as follows:

[0064] type ServiceNode struct{

[0065] ID int

[0066] SyncTime time.Time

[0067] }

[0068] func(nm*nodeManager)NodeID()(int32,error){

[0069] tm:=time.Now().Add(-nm.alivetime)

[0070] nodeid:=0

[0071] return int32(nodeid),nm.db.Transaction(func(tx*gorm.DB)error{

[0072] sn:=ServiceNode{}

[0073] if err:=tx.Set("gorm:query_option","FOR UPDATE").Where("`sync_time`<?",

[0074] tm).First(sn).Error;err!=nil&&err!=gorm.ErrRecordNotFound{

[0075] return err

[0076] }else if err==gorm.ErrRecordNotFound{

[0077] var v int

[0078] var err error

[0079] for i:=0;i<3;i++{

[0080] if v,err=nm.nodeID(tx);err==nil{

[0081] nodeid=v

[0082] return nil

[0083] }

[0084] }

[0085] return err

[0086] }else{

[0087] nodeid=sn.ID

[0088] return tx.Model(ServiceNode{}).Where("`id`=?",sn.ID).Update("sync_time",

[0089] time.Now()).Error

[0090] }

[0091] })

[0092] }

[0093] func(nm*nodeManager)nodeID(tx*gorm.DB)(int,error){

[0094] var maxs[]sql.NullInt32

[0095] if err:=tx.Model(&ServiceNode{}).Raw("SELECT MAX(`id`)AS`max`FROMservice_nodes").Pluck("max",&maxs).Error; err! =nil&&err! =

[0096] gorm.ErrRecordNotFound{

[0097] return 0,err

[0098] }

[0099] var max=0

[0100] if len(maxs)>0{

[0101] max=int(maxs[0].Int32)

[0102] }

[0103] sn:=&model.ServiceNode{ID:max+1,SyncTime:time.Now()}

[0104] return sn.ID,tx.Create(sn).Error

[0105] }

[0106] func(nm*nodeManager)NodeIDSync(id int32)error{

[0107] return nm.db.Model(&ServiceNode{ID:int(id)}).Update("sync_time",time.Now()).Error}

[0108] The sample code for the global ID generation part is as follows:

[0109] type msgID struct{

[0110] once sync.Once

[0111] lock sync.Mutex / / lock

[0112] epoch time.Time / / Timestamp start time

[0113] now uint32 / / current time

[0114] seq uint32 / / current time serial number

[0115] seqMask uint32 / / serial number mask

[0116] nodeid uint16 / / node ID

[0117] timeShift uint8 / / time bit

[0118] nodeidShift uint8 / / node bit

[0119] manager ManagerService / / Node ID registration and renewal

[0120] live time.Duration / / lease

[0121] count uint8 / / Number of times it has failed

[0122] maxFail uint8 / / Maximum number of failures

[0123] timer*time.Timer / / lease

[0124] exit chan struct{} / /

[0125] }

[0126] func(mid*msgID)ID()(uint64,error){

[0127] mid.lock.Lock()

[0128] if mid.count>=mid.maxFail{

[0129] mid.lock.Unlock()

[0130] return 0,errors.New("Node ID application failed")

[0131] }

[0132] now:=time.Since(mid.epoch).Nanoseconds() / int64(time.Second) / / seconds

[0133] if now==int64(mid.now){

[0134] mid.seq=(mid.seq+1)&mid.seqMask

[0135] if mid.seq==0{

[0136] for now<=int64(mid.now){

[0137] now=time.Since(mid.epoch).Nanoseconds() / int64(time.Second)

[0138] }

[0139] }

[0140] }else{

[0141] mid.seq=0

[0142] }

[0143] mid.now=uint32(now)

[0144] seq:=uint64(now)<<uint64(mid.timeShift)|

[0145] uint64(mid.nodeid)<<uint64(mid.nodeidShift)|uint64(mid.seq)

[0146] mid.lock.Unlock()

[0147] return seq,nil

[0148] }

[0149] func(mid*msgID)apply()(int,error){

[0150] resp,err:=mid.manager.NodeID(context.Background(),&NodeIDReq{})

[0151] if err!=nil{

[0152] return 0,err

[0153] }

[0154] if resp.ID>(1<<(mid.timeShift-mid.nodeidShift))-1{

[0155] return 0,errors.New("err id")

[0156] }

[0157] mid.lock.Lock()

[0158] mid.nodeid=uint16(resp.ID)

[0159] mid.count=0

[0160] mid.lock.Unlock()

[0161] mid.once.Do(func(){

[0162] mid.timer=time.NewTimer(mid.live)

[0163] go mid.start()

[0164] })

[0165] return int(resp.ID),nil

[0166] }

[0167] func(mid*msgID)start(){

[0168] for{

[0169] select{

[0170] case<-mid.timer.C:

[0171] _,err:=mid.manager.NodeIDSync(context.Background(),&proto.NodeIDSyncReq{ID:int32(mid.nodeid)})

[0172] mid.lock.Lock()

[0173] count:=mid.count

[0174] if err!=nil{

[0175] count++

[0176] }else{

[0177] count=0

[0178] }

[0179] mid.count=count

[0180] mid.lock.Unlock()

[0181] if count>=mid.maxFail{

[0182] go mid.ApplyID()

[0183] }

[0184] mid.timer.Reset(mid.live)

[0185] case<-mid.exit:

[0186] return

[0187] }

[0188] }

[0189] }

[0190] The present invention also provides a node identification management device. Figure 5 FIG. 5 shows a structural block diagram of a node identification management device 500 according to an embodiment of the present invention. Figure 5 As shown, the node identification management device 500 includes a detection unit 510 , an allocation unit 520 and an accumulation unit 530 .

[0191] The detection unit 510 is adapted to receive a node identification ID application request sent by any node, and detect whether there is an available node ID among the generated node IDs.

[0192] The allocating unit 520 is adapted to determine the target node ID from the available node IDs, if any, and allocate it to the above-mentioned node.

[0193] The accumulation unit 530 is adapted to obtain the maximum node ID among the generated node IDs if it does not exist, accumulate the maximum node ID by one, and allocate the accumulated node ID as the target node ID to the above node.

[0194] The node identification management device 500 according to the present invention has been described in detail in the Figures 1 to 4 The details are disclosed in the description and will not be repeated here.

[0195] This invention manages node IDs through an application and renewal process, enabling automatic allocation and recycling of node IDs. This, combined with container technology and automated operations and maintenance, enables dynamic scaling. Furthermore, the first 32 bits of the global ID are expressed in seconds, significantly reducing the impact of time rollbacks during time calibration.

[0196] The various techniques described herein may be implemented in conjunction with hardware or software, or a combination thereof. Thus, the methods and apparatus of the present invention, or certain aspects or portions of the methods and apparatus of the present invention, may be implemented in the form of program codes (i.e., instructions) embedded in a tangible medium, such as a removable hard disk, a USB flash drive, a floppy disk, a CD-ROM, or any other machine-readable storage medium, wherein when the program is loaded into a machine such as a computer and executed by the machine, the machine becomes an apparatus for practicing the present invention.

[0197] When the program code is executed on a programmable computer, the computing device generally includes a processor, a storage medium readable by the processor (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device. The memory is configured to store the program code; the processor is configured to execute the node identifier management method or global identifier generation method of the present invention according to the instructions in the program code stored in the memory.

[0198] By way of example and not limitation, readable media include readable storage media and communication media. Readable storage media store information such as computer-readable instructions, data structures, program modules, or other data. Communication media typically embody computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and include any information delivery medium. Combinations of any of the above are also included within the scope of readable media.

[0199] In the description provided herein, the algorithms and displays are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems may also be used in conjunction with the examples of the present invention. Based on the above description, it is apparent that the structure required for constructing such systems is well understood. In addition, the present invention is not directed to any specific programming language. It should be understood that various programming languages may be utilized to implement the present invention described herein, and the description of specific languages above is provided for the purpose of disclosing the preferred embodiment of the present invention.

[0200] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures, and techniques are not shown in detail so as not to obscure the understanding of this description.

[0201] It should be understood that in order to streamline the present disclosure and aid understanding of one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together in a single embodiment, figure, or description thereof. However, this method of disclosure should not be interpreted as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim.

[0202] Those skilled in the art will appreciate that the modules, units, or components of the devices in the examples disclosed herein may be arranged in the device described in the embodiment, or alternatively may be located in one or more devices different from the devices in the examples. The modules in the foregoing examples may be combined into one module or further divided into multiple submodules.

[0203] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition may be divided into multiple submodules or subunits or subcomponents. All features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed herein may be combined in any combination, except that at least some of such features and / or processes or units are mutually exclusive. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.

[0204] Furthermore, those skilled in the art will appreciate that although some embodiments described herein include certain features and not other features included in other embodiments, the combination of features from different embodiments is intended to be within the scope of the invention and to form different embodiments.

[0205] In addition, some of the embodiments are described herein as methods or combinations of method elements that can be implemented by a processor of a computer system or by other devices that perform the functions described. Thus, a processor having the necessary instructions for implementing the method or method element forms a device for implementing the method or method element. Furthermore, the elements described herein of the device embodiments are examples of devices for implementing the functions performed by the elements for the purpose of implementing the invention.

[0206] As used herein, unless otherwise specified, the use of ordinal numbers "first," "second," "third," etc. to describe common objects merely indicates that different instances of similar objects are involved and are not intended to imply that the objects so described must have a given order in time, space, ranking, or in any other manner.

[0207] Although the present invention has been described with respect to a limited number of embodiments, it will be apparent to those skilled in the art, having benefit of the foregoing description, that other embodiments are contemplated within the scope of the invention thus described. Furthermore, it should be noted that the language used in this specification has been selected primarily for readability and didactic purposes, rather than for the purpose of explaining or limiting the subject matter of the present invention. Consequently, many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the appended claims. The disclosure of the present invention is intended to be illustrative rather than restrictive of the scope of the invention, which is defined by the appended claims.

Claims

1. A method for managing node identification, comprising: Receive a node ID application request from any node and check whether there is an available node ID among the generated node IDs; If so, determine the target node ID from the available node IDs and assign it to the node; If it does not exist, obtaining the maximum node ID among the generated node IDs, adding one to the maximum node ID, and assigning the accumulated node ID as the target node ID to the node; The duration during which the node possesses the target node ID is a first duration. After possessing the target node ID, the node sends a node ID renewal request every second duration. The first duration is 2T+m, the second duration is T, and m is less than T. The method further includes: receiving the node ID renewal request sent by the node, and detecting whether the node meets the conditions for renewal; if so, resetting the duration during which the node possesses the target node ID to the first duration; if not, sending a renewal failure message to the node; The node ID renewal request includes the node ID to be renewed, the time of the last successful renewal of each generated node ID stored in the database system, and the node to which each generated node ID is currently associated. Detecting whether the node meets the renewal conditions includes: obtaining the node to which the node ID to be renewed is currently associated from the database system, and detecting whether it is the node that sends the node ID renewal request; if so, obtaining the difference between the current time and the time of the last successful renewal of the node ID to be renewed, and detecting whether the difference is less than a third time period, which is 3T; if it is less than, determining that the node meets the renewal conditions, otherwise, determining that the node does not meet the renewal conditions.

2. The method according to claim 1, wherein Check whether there is an available node ID among the generated node IDs, including: Obtaining from the database system the time when each generated node ID was last successfully renewed, and obtaining the difference between the current time and the time when each node ID was last successfully renewed; comparing each of the difference values with the first duration; If there is a difference greater than the first time length, determining that there is an available node ID among the generated node IDs; Otherwise, it is determined that no available node ID currently exists among the generated node IDs.

3. The method according to claim 1 or 2, further comprising: If the node continuously receives renewal failure messages within the third time period, it resends the node ID application request.

4. A method for generating a global identifier, the method comprising: When any node generates a global identification ID, it obtains the difference between the current time and the preset reference time and expresses it as a 32-bit number of seconds, and increments the sequence number in the last generated global ID by one. The sequence number is a 19-bit integer. The difference is used as the first 32 bits, the node ID of the node is used as the middle bit, and the accumulated serial number is used as the last 19 bits to generate a global ID, wherein the node ID of the node is managed by the method described in any one of claims 1-3, and the node ID is a 13-bit integer.

5. A node identification management device, comprising: a detection unit adapted to receive a node identification ID application request sent by any node and detect whether there is an available node ID among the generated node IDs; an allocating unit adapted to determine a target node ID from the available node IDs, if present, and to allocate it to said node; an accumulation unit adapted to obtain a maximum node ID from the generated node IDs if it does not exist, accumulate the maximum node ID by one, and assign the accumulated node ID as the target node ID to the node; The duration during which the node possesses the target node ID is a first duration. After possessing the target node ID, the node sends a node ID renewal request every second duration. The first duration is 2T+m, the second duration is T, and m is less than T. The device is further adapted to: receive the node ID renewal request sent by the node, and detect whether the node meets the conditions for renewal; if so, reset the duration during which the node possesses the target node ID to the first duration; if not, send a renewal failure message to the node; The node ID renewal request includes the node ID to be renewed, the time of the last successful renewal of each generated node ID stored in the database system, and the node to which each generated node ID is currently associated. Detecting whether the node meets the renewal conditions includes: obtaining the node to which the node ID to be renewed is currently associated from the database system, and detecting whether it is the node that sends the node ID renewal request; if so, obtaining the difference between the current time and the time of the last successful renewal of the node ID to be renewed, and detecting whether the difference is less than a third time period, which is 3T; if it is less than, determining that the node meets the renewal conditions, otherwise, determining that the node does not meet the renewal conditions.

6. A computing device comprising: at least one processor; as well as A memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, and the program instructions include instructions for executing the method according to any one of claims 1 to 3.

7. A readable storage medium storing program instructions, wherein when the program instructions are read and executed by a computing device, the computing device executes the method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Dynamic host configuration protocol server,ip address assignment system and method of assigning an ip address

    CN102811262A

  • Data identifier generation method and device, computer equipment and storage medium

    CN114116848A

  • Identifier distribution method and device

    CN115374151A