An identity generation method, device and electronic equipment
By registering a new, unregistered copy identifier during system time rollback, the problem of duplicate identity identifiers caused by system time rollback of electronic devices is solved, thus achieving the uniqueness of identity identifiers.
Patent Information
- Application Number
- CN202211724017.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2042-12-30
AI Technical Summary
System time rollback in electronic devices can lead to duplicate generated identities, and current technologies cannot effectively avoid this problem.
By determining the current system time and the pre-registered replica identifier, an identity identifier is generated. This ensures that in the event of system time rollback, the newly registered replica identifier will be an unregistered identifier, thus avoiding the generation of duplicate identity identifiers.
In the event of system time rollback, duplicate generation of identity identifiers is avoided, ensuring that the generated identity identifiers are unique.
Smart Images

Figure CN116155860B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, and in particular to an identity generation method and device and electronic equipment. BACKGROUND
[0002] In order to enable an electronic device to identify different objects such as orders, devices, etc., different identity identifiers can be assigned to different objects. Since the identity identifier is one-to-one corresponding to the object and is used to identify the object, such an identity identifier can also be referred to as a UUID (Universally Unique Identifier).
[0003] In related technologies, when an identity identifier needs to be generated, a timestamp representing the current system time can be obtained, and an identity identifier containing the timestamp can be generated. Since the system time is often advancing, the timestamp in the generated identity identifier is usually not repeated.
[0004] However, the system time of an electronic device can be rewound, such as rewinding the system time of one or more electronic devices in a distributed system to align the system times of the electronic devices. This can cause the same timestamp to exist in a previously generated identity identifier and a subsequently generated identity identifier, thereby causing a duplicate identity identifier to be generated. SUMMARY
[0005] Embodiments of the present application aim to provide an identity generation method, device and electronic equipment to avoid the possibility of generating duplicate identity identifiers due to rewinding of the system time. The specific technical solutions are as follows:
[0006] In a first aspect, the embodiments of the present application provide an identity generation method. In the embodiments, the identity generation method comprises:
[0007] In response to an identity identifier request generated by a target instance for a target object, determining a current system time, the target instance having pre-registered a replica identifier;
[0008] If the current system time is not later than a previous system time, registering a first replica identifier as the replica identifier of the target instance, wherein the previous system time is the system time when the last identity identifier was generated, and the first replica identifier is a replica identifier that has not been registered as the replica identifier of the target instance;
[0009] Generating an identity identifier of the target object based on the current system time and the latest registered replica identifier of the target instance.
[0010] In combination with the first aspect, in a second possible embodiment, the method further comprises:
[0011] If the current system time is later than the previous system time, the step of generating the identity of the target object based on the current system time and the copy identification newly registered for the target instance is performed.
[0012] With reference to the first aspect, in a third possible implementation, the registering the first copy identification as the copy identification of the target instance comprises:
[0013] If the clock identification is a preset target value, the unregistered first copy identification is registered as the copy identification of the target instance.
[0014] The generating the identity of the target object based on the current system time and the copy identification newly registered for the target instance comprises:
[0015] The generating the identity of the target object based on the current system time, the copy identification newly registered for the target instance and the clock identification.
[0016] The method further comprises:
[0017] If the current system time is not later than the previous system time and the clock is not the preset target value, the clock identification is modified to the preset target value, and the step of generating the identity of the target object based on the current system time, the copy identification newly registered for the target instance and the clock identification is performed.
[0018] In a second aspect, an identity generation method is provided, which comprises:
[0019] In response to an identity request generated by a target instance for a target object, a current system time is determined, and the target instance has pre-registered a copy identification;
[0020] The latest time in the system times based on which the generated identity is generated is determined as a latest system time.
[0021] If the current system time is later than the latest system time, a second copy identification that has been registered is registered as the copy identification newly registered for the target instance.
[0022] The identity of the target object is generated based on the current system time and the copy identification newly registered for the target instance.
[0023] With reference to the second aspect, in a second possible implementation, the method further comprises:
[0024] determine a second replica identity from replica identities that have been registered as the same instance as the target instance, wherein the same instance is an instance that has the same instance identity as the target instance;
[0025] or,
[0026] determine a replica identity whose update time satisfies a preset long-term non-update condition as the second replica identity, wherein the update time is a time of generating an identity based on a replica identity last time.
[0027] With reference to the second possible implementation manner of the second aspect, in a third possible implementation manner, the determining of the second replica identity from the replica identities that have been registered as the same instance as the target instance comprises:
[0028] if there is the same instance, determining the second replica identity from the replica identities that have been registered as the same instance;
[0029] the determining of the replica identity whose update time satisfies the preset long-term non-update condition as the second replica identity comprises:
[0030] if there is no same instance, determining a replica identity whose update time is the earliest or earlier than a preset time threshold as the second replica identity.
[0031] With reference to the second possible implementation manner of the second aspect, in a fourth possible implementation manner, the method further comprises:
[0032] each time a new replica identity is registered for the target instance, updating, in a preset replica node table, an instance corresponding to the replica identity to the target instance and updating an update time corresponding to the replica identity to a current system time;
[0033] the determining of the second replica identity from the replica identities that have been registered as the same instance as the target instance comprises:
[0034] determining, according to a correspondence between the replica identities and the instances recorded in the replica node table, a replica identity corresponding to the target instance;
[0035] determining the second replica identity from the determined replica identity;
[0036] the determining of the replica identity whose update time satisfies the preset long-term non-update condition as the second replica identity comprises:
[0037] determining, according to a correspondence between the replica identities and the update times recorded in the replica node table, a replica identity whose corresponding update time satisfies the preset long-term non-update condition as the second replica identity.
[0038] With reference to the second aspect, in a fifth possible implementation, the generating the identity of the target object based on the current system time and the copy identification newly registered for the target instance comprises:
[0039] concatenating the first field for representing the current system time before the second field for representing the copy identification to obtain the identity of the target object;
[0040] the determining the latest system time in the system times based on which the generated identities are generated as the latest system time comprises:
[0041] determining the system time based on which the largest generated identity is generated as the latest system time.
[0042] In a third aspect, an identity generation apparatus is provided in embodiments of the present application, and the apparatus comprises:
[0043] a first determining module configured to determine a current system time in response to an identity request generated by a target instance for a target object, the target instance having a copy identification pre-registered;
[0044] a first registering module configured to register a first copy identification as the copy identification of the target instance if the current system time is not later than a previous system time, wherein the previous system time is a system time at which an identity was last generated, and the first copy identification is a copy identification that has not been registered as the copy identification of the target instance;
[0045] a first identity generation module configured to generate the identity of the target object based on the current system time and the copy identification newly registered for the target instance.
[0046] With reference to the third aspect, in a second possible implementation, the apparatus further comprises:
[0047] a first executing module configured to execute the step of generating the identity of the target object based on the current system time and the copy identification newly registered for the target instance if the current system time is later than the previous system time.
[0048] With reference to the third aspect, in a third possible implementation, the first registering module registers the first copy identification as the copy identification of the target instance by:
[0049] if the clock identification is a preset target value, registering the first copy identification that has not been registered as the copy identification of the target instance;
[0050] The first identity generation module generates the identity of the target object based on the current system time and the latest registered copy identity of the target instance, and the identity generation module comprises:
[0051] The first identity generation module generates the identity of the target object based on the current system time, the latest registered copy identity of the target instance, and the clock identity.
[0052] The apparatus further comprises:
[0053] The second execution module is configured to, if the current system time is not later than the previous system time and the clock is not the preset target value, modify the clock identity to the preset target value, and execute the step of generating the identity of the target object based on the current system time, the latest registered copy identity of the target instance, and the clock identity.
[0054] In a fourth aspect, an identity generation apparatus is provided, and the apparatus comprises:
[0055] The second determination module is configured to, in response to an identity request generated by a target instance for a target object, determine a current system time, and the target instance has pre-registered a copy identity.
[0056] The third determination module is configured to determine the latest time in the system time based on which the generated identity is generated as the latest system time.
[0057] The second registration module is configured to, if the current system time is later than the latest system time, register the second copy identity that has been registered as the latest registered copy identity of the target instance.
[0058] The second identity generation module is configured to generate the identity of the target object based on the current system time and the latest registered copy identity of the target instance.
[0059] In combination with the fourth aspect, in a second possible implementation, the apparatus further comprises:
[0060] The fourth determination module is configured to determine a second copy identity from the copy identities that have been registered as the same instance, wherein the same instance is an instance having the same instance identity as the target instance.
[0061] Or,
[0062] The copy identity for which the update time meets the preset long-term non-update condition is determined as the second copy identity, wherein the update time is the time of the last time the identity is generated based on the copy identity.
[0063] With reference to the second possible implementation of the fourth aspect, in a third possible implementation, the fourth determining module is configured to determine the second replica identifier from replica identifiers that have been registered as the same instance, specifically including:
[0064] if the same instance exists, determining the second replica identifier from replica identifiers that have been registered as the same instance;
[0065] the fourth determining module is configured to determine a replica identifier whose update time satisfies a preset long-term non-update condition as the second replica identifier, specifically including:
[0066] if the same instance does not exist, determining a replica identifier whose update time is the earliest or earlier than a preset time threshold as the second replica identifier.
[0067] With reference to the second possible implementation of the fourth aspect, in a fourth possible implementation, the apparatus further includes:
[0068] an updating module configured to, whenever a new replica identifier is registered for the target instance, update an instance corresponding to the replica identifier to the target instance and update an update time corresponding to the replica identifier to a current system time in a preset replica node table;
[0069] the fourth determining module is configured to determine the second replica identifier from replica identifiers that have been registered as the same instance, specifically including:
[0070] determining a replica identifier corresponding to the target instance according to a correspondence between replica identifiers and instances recorded in the replica node table;
[0071] determining the second replica identifier from the determined replica identifier;
[0072] the fourth determining module is configured to determine a replica identifier whose update time satisfies a preset long-term non-update condition as the second replica identifier, specifically including:
[0073] determining a replica identifier whose corresponding update time satisfies a preset long-term non-update condition as the second replica identifier according to a correspondence between replica identifiers and update times recorded in the replica node table.
[0074] With reference to the fourth aspect, in a fifth possible implementation, the second identity identifier generating module generates the identity identifier of the target object based on the current system time and a replica identifier that is newly registered for the target instance, including:
[0075] concatenating a first field used to represent the current system time before a second field used to represent the replica identifier to obtain the identity identifier of the target object;
[0076] The third determining module determines the latest system time in the system time based on which the generated identity is generated as the latest system time, comprising:
[0077] The system time based on which the generated maximum identity is generated is determined as the latest system time.
[0078] In a fifth aspect, an electronic device is provided, comprising a memory for storing a computer program;
[0079] A processor is configured to execute the program stored in the memory, and implement the identity generation method in the first aspect or the second aspect.
[0080] In a sixth aspect, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program. The computer program is executed by a processor to implement the identity generation method in the first aspect or the second aspect.
[0081] The embodiments of the present application have the following beneficial effects:
[0082] The identity generation method, device and electronic device provided by the embodiments of the present application can register a new copy identity for a target instance in the case that the system time is rewound, because the current system time is not later than the previous system time. In addition, the first copy identity registered newly is a copy identity that has not been registered before, and the identity is generated based on the copy identity that has been registered. Therefore, the identity generated based on the copy identity registered newly is not duplicated with the identity generated before. It can be seen that the present application can avoid generating duplicated identities in the case that the system time is rewound. BRIEF DESCRIPTION OF DRAWINGS
[0083] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are only some embodiments of the present application, and other embodiments can also be obtained by those skilled in the art based on these drawings.
[0084] Figure 1 A possible flowchart of the identity generation method provided by the embodiments of the present application is shown in the figure.
[0085] Figure 2a An identity diagram provided by the embodiments of the present application is shown in the figure.
[0086] Figure 2b Another identity diagram provided by the embodiments of the present application is shown in the figure.
[0087] Figure 2c Another identity identification schematic diagram provided for an embodiment of the present application;
[0088] Figure 3 Another possible flow schematic diagram of an identity identification generation method provided for an embodiment of the present application;
[0089] Figure 4 Another possible flow schematic diagram of an identity identification generation method provided for an embodiment of the present application;
[0090] Figure 5 Another possible flow schematic diagram of an identity identification generation method provided for an embodiment of the present application;
[0091] Figure 6a Another possible flow schematic diagram of an identity identification generation method provided for an embodiment of the present application;
[0092] Figure 6b Another possible flow schematic diagram of an identity identification generation method provided for an embodiment of the present application;
[0093] Figure 6c Another possible flow schematic diagram of an identity identification generation method provided for an embodiment of the present application;
[0094] Figure 7a A possible logical structure schematic diagram of an identity identification generation apparatus provided for an embodiment of the present application;
[0095] Figure 7b Another possible logical structure schematic diagram of an identity identification generation apparatus provided for an embodiment of the present application;
[0096] Figure 8 A possible logical structure schematic diagram of an electronic device provided for an embodiment of the present application. DETAILED DESCRIPTION
[0097] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art based on the present application belong to the scope of protection of the present application.
[0098] To more clearly illustrate the identity generation method provided in the present application, a possible application scenario of the identity generation method provided in the present application will be exemplarily described below. It can be understood that the following example is only one possible application scenario of the identity generation method provided in the present application, and in other possible embodiments, the identity generation method provided in the present application can also be applied to other possible application scenarios, and the following example does not limit the identity generation method provided in the present application in any way.
[0099] In a distributed system, there are multiple electronic devices, and the electronic devices are collectively used to sort data generated by a user's online shopping, thereby obtaining data related to each online shopping order (hereinafter referred to as an order). In order to distinguish different orders, the electronic devices need to generate different order serial numbers for different orders, and the order serial number is the identity of the order.
[0100] In one possible embodiment, when an identity needs to be generated, a timestamp representing the current system time is determined, and the timestamp is used as the identity. The timestamp in this document can refer to any data format that can represent time. For example, in one possible embodiment, the timestamp is represented in the form of year-month-day-hour-minute-second-millisecond, such as the timestamp "2022010100000000" representing January 1, 2022, 0:00:00:000. In another possible embodiment, the timestamp is represented as the number of milliseconds elapsed from a preset time. For example, taking the preset time of January 1, 1970, 8:00:00:000 as an example, the timestamp "1640966400000" represents the time of January 1, 2022, 0:00:00:000, which is 1640966400000 milliseconds away from January 1, 1970, 8:00:00:000.
[0101] For the sake of convenience, the following will only be described by taking the case where the timestamp is represented as the number of milliseconds elapsed from January 1, 1970, 8:00:00:000 as an example. The principle is the same for other cases, so it will not be described again here.
[0102] It can be understood that in the case where the system time of the electronic device is not rolled back, the system time is always advancing, so the timestamp determined each time the identity is generated will be different, i.e., the identity generated each time is different. However, for a distributed system, the system times of the electronic devices need to be aligned, so if the system time of an electronic device is faster than the system times of other electronic devices, the system time of the electronic device needs to be rolled back, i.e., the current system time of the electronic device is set to a time earlier than the current system time.
[0103] Suppose the current system time is t1, and an identity representing the system time t2 (t2 is earlier than t1) has been generated before, denoted as identity 1, if the system time is rolled back from t1 to t3 (t3 is earlier than t2), the system time of the electronic device will be advanced from t3 to t1, which is referred to as clock chasing period in the present disclosure. In the clock chasing period, if a new identity 2 needs to be generated at the system time t2, the generated identity 2 will be the same as the aforementioned identity 1.
[0104] It can be seen that a repeated identity can be generated in the clock chasing period. In another possible embodiment, a clock mark bit can be added to the identity, for the identity generated in the clock chasing period, the clock mark bit is set to 1, and for the identity generated in the non-clock chasing period, the clock mark bit is set to 0, so as to avoid the identity generated in the clock chasing period from being repeated with the identity generated in the non-clock chasing period. For example, suppose the identity includes N+1 bits in total, the first N bits are used to represent the system time when the identity is generated, and the N+1 bit is the clock mark bit, N is any positive integer. Still taking the aforementioned identity 1 and identity 2 as an example, since the identity 1 and the identity 2 are both generated at the system time t2, the first N bits of the identity 1 and the identity 2 are the same, but when the identity 1 is generated, it is not in the clock chasing period, so the N+1 bit of the identity 1 is 0, and for the same reason, the N+1 bit of the identity 2 is 1, so the identity 1 and the identity 2 are different.
[0105] However, in some application scenarios, the electronic device can also have the system time rolled back in the clock chasing period, thereby causing the identities generated in the clock chasing period to be repeated, and the clock mark bit cannot avoid the identities generated in the clock chasing period from being repeated.
[0106] Therefore, the present disclosure provides an identity generation method, which is applied to any electronic device with identity generation function, such as the electronic device in the aforementioned distributed system. The identity generation method provided by the present disclosure includes the following steps. Figure 1 As shown in the figure, the identity generation method provided by the present disclosure includes the following steps.
[0107] S101, determining the current system time in response to an identity request generated by a target instance for a target object.
[0108] The target instance is pre-registered with a copy identity.
[0109] S102, if the current system time is not later than the previous system time, registering a first copy identity which has not been registered as the copy identity of the target instance.
[0110] Wherein, the previous system time is the system time when the identity is generated last time, and the first replica identity is a replica identity which is not registered as a replica identity of the target instance.
[0111] S103, generating the identity of the target object based on the current system time and the latest registered replica identity of the target instance.
[0112] In this embodiment, since the current system time is not later than the previous system time, it indicates that the system time is rolled back after the identity is generated last time. Therefore, the application can register a new replica identity for the target instance in the case that the system time is rolled back. Since the first replica identity registered newly is a replica identity which is not registered before, and the identity is generated based on the registered replica identity in the application, it can be seen that the identity is not generated based on the latest registered replica identity before. Therefore, the identity generated based on the latest registered replica identity is not duplicated with the identity generated before. It can be seen that the application can avoid generating duplicated identity in the case that the system time is rolled back.
[0113] The following will be illustrated respectively in the case that the rollback occurs only once and the rollback occurs again in the clock chasing period:
[0114] For the case that the rollback occurs only once:
[0115] For the convenience of description, it is assumed that the rollback occurs at the system time t1, and the system time is rolled back from t1 to t2, and the latest generated identity before the rollback is identity 1, and the identity 1 is generated based on the system time t3 and the replica identity 1, i.e. the replica identity 1 is registered as the replica identity of the target instance in advance.
[0116] The system time when the identity is generated for the first time in the clock chasing period is recorded as t4. It can be understood that the identity generated after the rollback is generated based on t4 and the system time later than t4, and the identity generated before the rollback is generated based on t3 and the system time earlier than t3.
[0117] Therefore, if t4 is later than t3, the identity generated after the rollback and the identity generated before the rollback are obviously generated based on different system times, and therefore the identity generated after the rollback is not duplicated with the identity generated before the rollback.
[0118] If t4 is not later than t3, a new replica identifier will be registered for the target instance, and since the newly registered replica identifier is not registered as a replica identifier of the target instance, the newly registered replica identifier is obviously different from replica identifier 1. The identity after the rollback is generated based on the newly registered replica identifier, while the identity before the rollback is generated based on replica identifier 1, so the identity generated after the rollback is not repeated with the identity generated before the rollback.
[0119] It can be seen that in the case of only one rollback, the identity generated after the rollback is not repeated with the identity generated before the rollback.
[0120] For the case of a rollback again during the clock chasing period:
[0121] For convenience of description, it is assumed that the first rollback occurs at system time t1, and the system time is rolled back from t1 to t2, the second rollback occurs at system time t3, and the system time is rolled back from t3 to t4, wherein t3 is later than t2, and t4 is earlier than t2.
[0122] The identity generated latest before the second rollback is identity 2, and identity 2 is generated based on system time t5 and replica identifier 2. And the system time when the first identity needs to be generated after the second rollback is recorded as t6.
[0123] It can be understood that the identity generated after the second rollback can be regarded as the identity generated after the rollback, and for the same reason as the case of only one rollback, the identity generated after the second rollback is obviously not repeated with the identity generated before the first rollback.
[0124] And the identity generated after the first rollback and before the second rollback is obviously generated based on t5 and system time earlier than t5. And the identity generated after the second rollback is generated based on t6 and system time later than t6.
[0125] Therefore, if t6 is later than t5, the identity generated after the second rollback and the identity generated after the first rollback and before the second rollback are obviously generated based on different system times, so they are not repeated.
[0126] If t6 is not later than t5, a new replica identifier will be registered for the target instance, and since the newly registered replica identifier is not registered as a replica identifier of the target instance, the newly registered replica identifier is obviously different from replica identifier 2. The identity after the second rollback is generated based on the newly registered replica identifier, while the identity after the first rollback and before the second rollback is generated based on replica identifier 2, so they are not repeated.
[0127] It can be seen that the identity generated in the clock chasing period will not be repeated in the case of backtracking again in the clock chasing period.
[0128] As can be seen from the above, the identity generation method provided by the present application can not only avoid the repetition of the identity generated in the clock chasing period and the identity generated in the non-clock chasing period, but also avoid the repetition of the identity generated in the clock chasing period in the case of backtracking again in the clock chasing period.
[0129] The foregoing S101-S103 will be described below:
[0130] In the foregoing S101, the target instance can be different types of instances according to different application scenarios, such as a service, an application, a process, etc. The target instance can run on the execution subject (hereinafter referred to as the execution subject) of the identity generation method provided by the present application, or on other electronic devices other than the execution subject. The target object can also be different types of objects according to different application scenarios, such as orders, devices, etc.
[0131] For example, in the first application scenario, multiple applications are running on the execution subject, and each application generates multiple threads. In order to distinguish different threads, the application needs to request the execution subject to generate an identity for the thread. In this application scenario, the target instance is the application, and the target object is the thread.
[0132] In the second application scenario, the server provides multiple services, each service is used to organize order-related data, and in order to distinguish different orders, the service needs to request the execution subject to generate an identity for the order. In this application scenario, the target instance is the service, and the target object is the order.
[0133] In the foregoing S102, it can be understood that according to the actual needs of the user, in some application scenarios, the identity between any two objects needs to be non-repetitive, and in some other application scenarios, only the identity between part of the objects needs to be non-repetitive. For example, in the foregoing second application scenario, the user may require the identity of any two orders to be non-repetitive, or the user may require the identity of any two orders of the same type of goods to be non-repetitive, while the identity of two orders of different types of goods can be repeated.
[0134] For the foregoing case where the identity between any two objects needs to be non-repetitive, unregistered means not registered as a copy of any instance. For the foregoing case where only the identity between part of the objects needs to be non-repetitive, unregistered means not registered as a copy of the specified instance, wherein the specified instance at least includes the target instance.
[0135] For example, taking the second application scenario mentioned above, suppose that services 1 and 2 are used to organize orders of product type 1, and services 3 and 4 are used to organize orders of product type 2. The target instance is service 1, and the identity identifiers of any two orders with the same product type are not duplicated, while the identity identifiers of two orders with different product types can be duplicated. Then, "not registered" means that it is not registered as a copy identifier of services 1 and 2. That is, in this example, the specified instance is services 1 and 2.
[0136] The first copy identifier can be any unregistered copy identifier, such as randomly selecting one copy identifier from all unregistered copy identifiers. In another possible embodiment, in order to ensure that the generated identity identifiers are ordered, i.e., the identity identifier generated later is greater than the identity identifier generated earlier, the minimum value among the unregistered copy identifiers is determined as the first copy identifier. This makes the copy identifier on which the identity identifier generated earlier is based as small as possible, and the copy identifier on which the identity identifier generated later is based as large as possible, so as to achieve the order of the generated identity identifiers.
[0137] Since the identity identifier is generated based on the most recently registered replica identifier for the target instance, the most recently registered replica identifier for the target instance can be cached to generate the identity identifier. When an identity identifier needs to be generated, it can be quickly generated based on the cached replica identifier. In S102, the first replica identifier is registered as the replica identifier of the target instance. Therefore, the most recently registered replica identifier for the target instance becomes the first replica identifier. Subsequent identity identifiers will be generated based on the first replica identifier, so the previously cached replica identifier can be released and the first replica identifier can be cached instead. Therefore, S102 can be regarded as re-applying for a replica identifier and releasing the original replica identifier.
[0138] In S103, if the method of generating the target object is regarded as a mapping relationship, then the mapping relationship is the mapping relationship between the latest registered copy identifier and the identity identifier of the target instance at the current system time, and is therefore expressed as formula (1):
[0139] UUID = f(time) now workid new (1)
[0140] Wherein, UUID is the identity identifier of the generated target object, and time... now Workid is the current system time. new The identifier of the most recently registered copy of the target instance. f(·) is a function used to represent this mapping relationship. This function can be any function, but it should satisfy the condition that the output of the function is different when the input of the function is different.
[0141] Exemplarily, in a possible embodiment, a first field for representing time now may be concatenated with a second field for representing workid new to obtain a UUID. The concatenation manner may be different according to different application scenarios, exemplarily, in a possible embodiment, the first field may be concatenated before the second field, in another possible embodiment, the second field may be concatenated before the first field, and the UUID may further include other fields in addition to the first field and the second field.
[0142] For example, the concatenated UUID may be as shown in Figure 2a , which includes the first field, the second field, a machine room identifier and a serial number. The first field is a 41-bit binary value for representing the part before the millisecond in the time stamp of time now , the second field is a 5-bit binary value for representing workid new . The machine room identifier is a 5-bit binary value for representing the machine room to which the execution subject belongs, so that the UUIDs generated by the devices belonging to different machine rooms are different, and the UUIDs generated by the devices of different machine rooms can be distinguished, and it can be understood that the devices of different machine rooms are often used for processing different services, and by distinguishing the UUIDs generated by different devices through the machine room identifier, the UUIDs generated for different services are different, that is, the conflict between the UUIDs of different services is effectively avoided. The serial number is an 11-bit binary value for representing the part after the millisecond in the time stamp of time now .
[0143] It can be understood that the total number of copy identifiers is limited due to the length of the identity identifier, for example, the identity identifier shown in Figure 2a , since the bit length of the second field is 5 bits, a maximum of 32 copy identifiers can be set. The prerequisite for being able to perform the foregoing S102 is that there is an unregistered copy identifier, and as the number of times of performing S102 increases, the number of remaining unregistered copy identifiers will gradually decrease, resulting in that in the case of multiple callbacks, the foregoing S102 may not be performed due to the absence of an unregistered copy identifier, and thus the identity identifier generation method provided by the present application cannot avoid the repetition of the generated identity identifier.
[0144] Based on this, in a possible embodiment, as shown in Figure 3 , the identity identifier generation method provided by the present application comprises:
[0145] S301, in response to an identity identifier request generated by a target instance for a target object, determining a current system time.
[0146] The target instance has pre-registered a copy identifier.
[0147] S302, determine the latest system time in the system time based on which the generated identity is generated, as the latest system time.
[0148] The generated identity refers to an identity generated based on a registered copy identity. For the case that the identity of any two objects needs not to be duplicated, the registered refers to the copy identity registered as any instance. For the case that the identity of only part of the objects needs not to be duplicated, the registered refers to the copy identity registered as a specified instance, wherein the specified instance at least includes the target instance. The description of the specified instance can be referred to S102, and will not be repeated here.
[0149] The system time based on which the identity is generated can be obtained from the identity. For example, as shown in Figure 2a , the first field in the identity can be read to obtain the timestamp represented by the first field, and the system time represented by the timestamp is the system time based on which the identity is generated.
[0150] In a possible embodiment, the system time based on which each generated identity is generated can be obtained from the identity, and the latest system time can be determined by comparing the obtained system times. For example, assuming that three identities are generated, denoted as identity 1-3, the system times are obtained from the identities 1-3, respectively, and the obtained system times are denoted as system time 1-3, respectively. By comparison, it is determined that system time 1 is earlier than system time 2, and system time 2 is earlier than system time 3, and the latest system time is system time 3.
[0151] In another possible embodiment, the identity is obtained by splicing the first field before the second field. For example, as shown in Figure 2a , the first field for representing the system time in the spliced identity is located at the high bit, and the identity value of the identity with the latest system time represented by the first field is the largest. Therefore, the system time based on which the largest identity is generated is the latest system time. In this embodiment, the system time based on which the largest generated identity is generated can be determined as the latest system time. By using this embodiment, the system time based on which each identity is generated does not need to be obtained, and the efficiency of obtaining the latest system time and the efficiency of generating the identity can be improved.
[0152] S303, if the current system time is later than the latest system time, the registered second copy identity is registered as the copy identity of the target instance registered most recently.
[0153] In the foregoing S302, the registered second copy identifier can be any registered copy identifier, and in an exemplary embodiment, it can be randomly selected from all registered copy identifiers.
[0154] Therefore, the copy identifier of the target instance can be re-registered based on the registered copy identifier, so as to generate the identity identifier based on the originally registered copy identifier.
[0155] In the foregoing S304, the second copy identifier can be any registered copy identifier, and in an exemplary embodiment, it can be randomly selected from all registered copy identifiers.
[0156] In this embodiment, the registered copy identifier can be re-registered as the copy identifier of the target instance, so that the registered copy identifier can be fully utilized, the use of unregistered copy identifiers can be reduced, and the possibility that the identity identifier cannot be generated due to the absence of unregistered copy identifiers can be reduced, i.e., the reliability of the identity identifier generation method provided by the present application is improved.
[0157] In the foregoing S303, the registered second copy identifier is registered as the copy identifier of the target instance, which is a re-registration of the registered copy identifier, and hereinafter referred to as a re-recovered copy identifier. In the foregoing S102, the unregistered first copy identifier is registered as the copy identifier of the target instance, which is a registration of the unregistered copy identifier, and hereinafter referred to as a newly registered copy identifier.
[0158] It can be understood that each time a new copy identifier is registered, the unregistered copy identifier will be reduced, and the re-recovered copy identifier will not reduce the unregistered copy identifier, so in one possible embodiment, as shown in the embodiment of FIG. 2, the re-recovered copy identifier is preferred, and only in the case where the re-recovered copy identifier cannot be recovered, such as in the case where the current system time is not later than the latest system time, the latest system time is not successfully acquired, etc., the new copy identifier is registered. In another possible embodiment, if the number of copy identifiers is sufficient, the new copy identifier can also be registered preferentially, and the present application does not make any limitation in this regard. Figure 3
[0159] In the foregoing S304, the second copy identifier can be any registered copy identifier, and in an exemplary embodiment, it can be randomly selected from all registered copy identifiers.
[0160] It can be understood that, in order to avoid the generated identity being duplicated, the different identity should be generated based on different copy identifiers as far as possible. Therefore, the selected second copy identifier needs to meet the following condition as far as possible: the possibility that the instance to which the second copy identifier belongs needs to generate an identity in the future is as low as possible. For example, assuming that the second copy identifier is registered in advance as a copy identifier of instance 1, the following condition needs to be met: the possibility that instance 1 needs to generate a new identity in the future is as low as possible.
[0161] Based on this, in a possible embodiment, the second copy identifier can be selected in the following way or way two:
[0162] Way one: determining the second copy identifier from the copy identifiers that have been registered as the copy identifiers of the same instance.
[0163] It can be understood that the same instance has the same instance identifier as the target instance, so the same instance and the target instance should be the same instance, and the reason why the same instance and the target instance are different instances is often that the same instance is offline due to various reasons, and when the same instance is online again, it is regarded as the target instance. Therefore, it is considered that the same instance has been offline, so the same instance is unlikely (or almost unlikely) to need to generate a new identity. Therefore, the second copy identifier can be determined from the copy identifiers that have been registered as the copy identifiers of the same instance.
[0164] For example, assuming that instance 1 originally runs, the instance identifier of instance 1 is instance identifier A, and copy identifier 1 is registered for instance 1, instance 1 is offline due to various reasons, and when instance 1 is online again, it is regarded as a newly online instance 2. Since instance 2 and instance 1 are essentially the same instance, the instance identifier of instance 2 is still instance identifier A, and instance 2 will replace instance 1 to provide subsequent services. In theory, instance 1 will no longer need to generate a new identity in the future. Therefore, even if copy identifier 1 is registered as the copy identifier of instance 2, since the system time is different, the identity generated for instance 2 in the future will not be duplicated with the identity generated for instance 1 in the past.
[0165] Way two: determining a copy identifier whose update time meets a preset long-term non-update condition as the second copy identifier.
[0166] The update time is the time when the identity is generated based on the copy identifier last time. For example, for copy identifier 1, assuming that the identity is generated based on copy identifier 1 last time at system time 1, the update time of copy identifier 1 is system time 1.
[0167] The preset long-term non-updating condition can be different according to different application scenarios, but should meet the condition that the earlier the updating time is, the easier the long-term non-updating condition is met. For example, there are updating time 1 and updating time 2, and updating time 1 is earlier than updating time 2. If updating time 2 meets the long-term non-updating condition, then updating time 1 should also meet the long-term non-updating condition. In other words, if an updating time meets the preset long-term non-updating condition, all other updating times earlier than the updating time also meet the preset long-term non-updating condition. For example, the preset long-term non-updating condition can be that the updating time is the earliest, or that the updating time is earlier than a preset time threshold.
[0168] It can be understood that if the updating time of the copy identifier meets the preset long-term non-updating condition, it is considered that a new identity identifier has not been generated based on the copy identifier in a relatively long period of time in the past, and therefore the possibility of subsequently generating a new identity identifier based on the copy identifier is also relatively low. Therefore, the copy identifier whose updating condition meets the preset long-term non-updating condition can be selected as the second copy identifier.
[0169] As previously analyzed, selecting the second copy identifier in the aforementioned manner one or manner two can make different identity identifiers generated based on different copy identifiers as much as possible, thereby further reducing the possibility of generating duplicate identity identifiers.
[0170] In one possible application scenario, the second copy identifier can be selected in the aforementioned manner one. In another possible embodiment, the second copy identifier can also be selected in manner two. In yet another possible embodiment, the second copy identifier can be preferentially selected in manner two, and only in the case where the second copy identifier cannot be selected in manner two, such as failing to successfully obtain the updating time, the second copy identifier is selected in manner one.
[0171] In yet another possible embodiment, the second copy identifier can also be preferentially selected in manner one, and only in the case where the second copy identifier cannot be selected in manner one, i.e., there is no same instance, the second copy identifier is selected in manner two. It can be understood that, as previously analyzed with respect to manner one and manner two, the second copy identifier selected in manner one more meets the aforementioned condition that the instance to which the second copy identifier belongs has the possibility of subsequently generating an identity identifier as low as possible. Therefore, preferentially selecting the second copy identifier in manner one can further reduce the possibility of generating duplicate identity identifiers.
[0172] Referring to Figure 1 , the aforementioned S102 is executed when the current system time is not later than the previous system time, and for the case where the current system time is later than the previous system time, in one possible embodiment, the first copy identifier that has not been registered can also be registered as the copy identifier of the target instance. In another possible embodiment, the first copy identifier that has not been registered can also be registered as the copy identifier of the target instance when the current system time is later than the previous system time.Figure 4 Directly execute S103.
[0173] Directly execute S103, that is, generate the identity identifier using the copy identifier previously registered for the target instance without registering a new copy identifier for the target instance. With this embodiment, S103 can be directly executed when the current system time is later than the previous system time, reducing the use of the unregistered copy identifier, thereby reducing the possibility that the identity identifier cannot be generated due to the absence of the unregistered copy identifier, i.e., improving the reliability of the identity identifier provided by the present application.
[0174] Similarly, referring to Figure 3 , the aforementioned S303 is executed when the current system time is later than the latest system time, and since the previous system time is necessarily no later than the latest system time, for the case where the current system time is no later than the latest system time, it can be divided into two sub-cases:
[0175] Sub-case one: the current system time is no later than the last previous system time.
[0176] Sub-case two: the current system time is later than the previous system time, but no later than the latest system time.
[0177] Sub-case one is the same as the aforementioned S102, and the relevant description of the aforementioned S102-S103 can be referred to, which will not be repeated here. For sub-case two, S304 can be directly executed, or the unregistered first copy identifier can be registered as the copy identifier of the target instance, and then S304 is executed.
[0178] It can be understood that the identity identifier provided by the present application can not only include Figure 2a , but also include other fields. For example, in one possible embodiment, as Figure 2b indicated, the identity identifier further includes a clock identifier.
[0179] In this example, the identity generation method provided by the present application includes Figure 5 , as indicated.
[0180] S501, in response to an identity identifier request generated by a target instance for a target object, determining a current system time.
[0181] S502, determining whether the current system time is later than the previous system time, if not, executing S503, if yes, executing S506.
[0182] S503, determining whether the clock identifier is a preset target value, if yes, executing S504, if not, executing S505.
[0183] The clock mark is initially preset as an initial value. The preset initial value and the preset target value can be different according to different application scenarios. Figure 2b For example, the preset initial value is one of 0 and 1, and the preset target value is the other of 0 and 1.
[0184] S504, register a new copy mark or recycle a copy mark.
[0185] For the registration of the new copy mark and the recycled copy mark, refer to the foregoing related description of the registration of the new copy mark and the recycled copy mark, which will not be repeated here. Figure 1 、 Figure 3 The foregoing related description of the registration of the new copy mark and the recycled copy mark, which will not be repeated here.
[0186] S505, modify the clock mark to the preset target value.
[0187] S506, generate an identity mark of the target object based on the current system time, the latest registered copy mark of the target instance, and the clock mark.
[0188] The generated identity mark can be as shown in Figure 2b , can also be as shown in Figure 2c , or can be in other formats, which are not limited in the present application. Among them, Figure 2c The identity mark shown in Figure 2b has an additional 1-bit sign bit in the highest bit based on , and the value of the sign bit is fixed, such as fixed as 0 or fixed as 1.
[0189] By additionally increasing the clock mark to represent whether the rollback occurs in the clock chasing period, if the clock mark is the preset initial value, the rollback occurs in the non-clock chasing period, and if the clock mark is the preset target value, the rollback occurs in the clock chasing period. Thus, the clock mark can be used to distinguish the identity mark generated in the clock chasing period and the identity mark generated in the non-clock chasing period, without using the copy mark to distinguish the identity mark generated in the clock chasing period and the identity mark generated in the non-clock chasing period, effectively reducing the use of the copy mark, thereby reducing the possibility that the identity mark cannot be generated due to the absence of an unregistered copy mark, and improving the reliability of the identity mark generation method provided by the present application.
[0190] For example, it is assumed that the preset initial value is 0, the preset target value is 1, the clock mark at t1 is 0, the latest copy mark 1 registered for the target instance at t1 is copy mark 1, and it is assumed that the identity mark 1 is generated at t1. The identity mark 1 is generated based on the copy mark 1 and the clock mark 0.
[0191] If the first rollback occurs at t2 after t1, the system time is rolled back to before t1, and identity 2 is generated when the system time reaches t1 for the second time. Since the current system time (i.e., t1) is not later than the previous system time (t2), S503 is performed. Since the clock identifier is not the preset target value at this time, S505 is performed, the clock identifier is modified to 1, and a new copy identifier is not registered. Therefore, identity 2 is generated based on copy identifier 1 and clock identifier 1.
[0192] If the second rollback occurs before the system time reaches t2, the system time is rolled back to before t1 again, and identity 3 is generated when the system time reaches t1 for the third time. Since the current system time (i.e., t1) is not later than the previous system time (t2), S503 is performed. Since the clock identifier is the preset target value at this time, S504 is performed, a new copy identifier is registered or a copy identifier is recycled. Whether a new copy identifier is registered or a copy identifier is recycled, the latest registered copy identifier changes. Assuming that the change is copy identifier 2, identity 3 is generated based on copy identifier 2 and clock identifier 1.
[0193] As can be seen, the identities 1, 2, and 3 generated when the system time reaches t1 for the third time are different from each other, and identities 1 and 2 are generated based on the same copy identifier. Therefore, the clock identifier can effectively avoid identity duplication and reduce the use of copy identifiers.
[0194] The selection between registering a new copy identifier and recycling a copy identifier in S504 will be described below. Referring to FIG. 6, S504 includes the following steps. Figure 6a
[0195] S601, determining whether there is a same instance. If there is, S602 is performed. If there is not, S603 is performed.
[0196] S602, recycling a copy identifier by way one.
[0197] S603, obtaining the update time of each copy identifier.
[0198] S604, determining whether there is a copy identifier whose update time satisfies a preset long-term non-update condition. If there is not, S605 is performed. If there is, S606 is performed.
[0199] S605, registering a new copy identifier.
[0200] S606, recycling a copy identifier by way two.
[0201] The embodiment can preferentially recycle the copy identity, and preferentially recycle the copy identity by the first recycling method. Thus, the possibility of generating a duplicate identity can be reduced.
[0202] As described above, in the identity generation method provided in the present application, a plurality of information needs to be acquired, such as the unregistered copy identity, the registered copy identity, the instance identity, the latest system time, the update time, and the like. In order to facilitate the acquisition of the information, in a possible embodiment, whenever a new copy identity is registered for a target instance, the instance corresponding to the copy identity in a preset WORK_NODE table is updated to the target instance, and the update time corresponding to the copy identity is updated to the current system time.
[0203] The WORK_NODE table is used to record the copy identity, the target instance, and the update time. The WORK_NODE table can be a structure of any structure, and the WORK_NODE table can also record other information in addition to the copy identity, the target instance, and the update time. For example, in a possible embodiment, the WORK_NODE table can be as shown in the following table:
[0204] Field value Type Node identification bigint(20) unsigned Service identification varchar(64) Instance identification varchar(64) Replica identification int Creation time bigint(20) Update time bigint(20)
[0205] The node identity is 20-bit unsigned bigint (a type of integer data) data, which is used to identify the WORK_NODE. The copy identity is integer data. The instance identity is 64-bit varchar (variable length string) data, which is used to identify the instance to which the copy identity belongs. The service identity is 64-bit varchar data, which is used to identify the service to which the instance and the copy identity belong. The creation time is 20-bit unsigned bigint data, which is used to indicate the creation time of the WORK_NODE. The update time is 20-bit unsigned bigint data, which is used to indicate the update time corresponding to the copy identity.
[0206] The above table is taken as an example to illustrate the newly registered copy identity and the recycled copy identity. Initially, the WORK_NODE table as shown in the above table is created for each copy identity. Since the copy identities have not been registered initially, the service identity, the instance identity, and the update time in the WORK_NODE table are empty (or are default values).
[0207] When it is needed to newly register a replica identifier for a certain instance, the replica node tables are traversed in ascending order of the replica identifiers, to determine whether the service identifier, the instance identifier and the update time in the replica node table are empty (or default values), until a replica node table with empty (or default values) is found, the replica identifier recorded in the replica node table is registered as the replica identifier of the instance, and the instance identifier in the replica node table is updated as the instance identifier of the instance, the service identifier in the replica node table is updated as the service identifier of the service to which the instance belongs, and the update time in the replica node table is updated as the current system time.
[0208] When it is needed to recycle a replica identifier for a certain instance, if the replica identifier is recycled by the foregoing method one, the instance identifier of the instance (denoted as a target instance identifier) is determined, and a replica node table with the same instance identifier as the target instance is found, the replica identifier recorded in the replica node table is registered as the replica identifier of the instance, and the instance identifier in the replica node table is updated as the instance identifier of the instance, the service identifier in the replica node table is updated as the service identifier of the service to which the instance belongs, and the update time in the replica node table is updated as the current system time.
[0209] If the replica identifier is recycled by the foregoing method two, the update time recorded in each replica node table is read to determine a replica node table with an update time satisfying a preset long-term non-update condition, the replica identifier recorded in the replica node table is registered as the replica identifier of the instance, and the instance identifier in the replica node table is updated as the instance identifier of the instance, the service identifier in the replica node table is updated as the service identifier of the service to which the instance belongs, and the update time in the replica node table is updated as the current system time.
[0210] In a possible embodiment, the identity generation method provided by the present application comprises the following steps: Figure 6b , comprising the following steps:
[0211] S611, receiving an identity generation request for a target object generated by a target instance;
[0212] S612, determining a current system time;
[0213] S613, determining whether the current system time is not later than a previous system time? If yes, S615 is executed, and if not, S614 is executed;
[0214] S614, determining whether the current system time is later than a latest system time? If yes, S617 is executed, and if not, S616 is executed;
[0215] S615, registering a first replica identifier as a replica identifier of the target instance;
[0216] S616, generating the identity of the target object based on the current system time and the latest registered copy identifier of the target instance;
[0217] S617, registering the second registered copy identifier as the latest registered copy identifier of the target instance.
[0218] The specific description of S611 and S612 receiving the identity request of the target object generated by the target instance and determining the current system time can refer to the related description in the foregoing step S101, and will not be described here again. The specific description of S613 determining whether the current system time is not later than the previous system time and S615 registering the first copy identifier as the copy identifier of the target instance can refer to the related description in the foregoing step S102, and will not be described here again. The specific description of S616 based on the current system time and the latest registered copy identifier of the target instance can refer to the related description in the foregoing step S103, and will not be described here again. The specific description of S614 determining whether the current system time is later than the latest system time can refer to the related description in the foregoing step S303, and will not be described here again. The specific description of S617 registering the second registered copy identifier as the latest registered copy identifier of the target instance can refer to the related description in the foregoing step S303, and will not be described here again.
[0219] In the embodiment of the present application, as shown in the figure, Figure 6b S613 is performed first, and then S614 is performed. In another possible embodiment, as shown in the figure, Figure 6c S614 is performed first, and then S613 is performed. The specific execution order can be flexibly selected according to actual needs, and the present application does not make specific limitations.
[0220] By selecting the embodiment of the present application, the identity request of the target object generated by the target instance is received, the relationship between the current system time, the previous system time and the latest system time is determined, and the corresponding copy identifier is further selected and registered as the copy identifier of the target instance. In this way, it can not only ensure that the generated identity of the target object will not be repeated, but also effectively save the resources of the copy identifier and avoid the waste of the limited copy identifier.
[0221] In a third aspect, the embodiment of the present application also provides an identity generation device, as shown in the figure, Figure 7a The identity generation device provided by the present application comprises:
[0222] A first determination module 701 is configured to determine the current system time in response to the identity request of the target object generated by the target instance, and the target instance has pre-registered a copy identifier.
[0223] The first registration module 702 is configured to register the first copy identity as a copy identity of the target instance if the current system time is not later than the previous system time, wherein the previous system time is a system time when the last identity is generated, and the first copy identity is a copy identity that is not registered as a copy identity of the target instance.
[0224] The first identity generation module 703 is configured to generate the identity of the target object based on the current system time and the latest registered copy identity of the target instance.
[0225] In a possible embodiment, the identity generation apparatus provided in the present application further includes:
[0226] The first execution module is configured to perform the step of generating the identity of the target object based on the current system time and the latest registered copy identity of the target instance if the current system time is later than the previous system time.
[0227] In a possible embodiment, the first registration module 702 registers the first copy identity as a copy identity of the target instance, including:
[0228] If the clock identity is a preset target value, the first copy identity that is not registered is registered as a copy identity of the target instance.
[0229] The first identity generation module 703 generates the identity of the target object based on the current system time and the latest registered copy identity of the target instance, including:
[0230] Generating the identity of the target object based on the current system time, the latest registered copy identity of the target instance and the clock identity.
[0231] The identity generation apparatus provided in the present application further includes:
[0232] The second execution module is configured to modify the clock identity to a preset target value and perform the step of generating the identity of the target object based on the current system time, the latest registered copy identity of the target instance and the clock identity if the current system time is not later than the previous system time and the clock is not the preset target value.
[0233] In a fourth aspect, the embodiments of the present application further provide an identity generation apparatus, as shown in Figure 7b The identity generation apparatus provided in the present application includes:
[0234] The second determination module 711 is configured to determine the current system time in response to an identity request of the target object generated by the target instance, and the target instance has a copy identity registered in advance.
[0235] The third determining module 712 is used to determine the latest time in the system time on which the generated identity is based, and to use it as the latest system time.
[0236] The second registration module 713 is used to register the already registered second replica identifier as the latest registered replica identifier of the target instance if the current system time is later than the latest system time;
[0237] The second identity generation module 714 is used to generate the identity of the target object based on the current system time and the latest registered copy identity for the target instance.
[0238] In one possible embodiment, the identity generation apparatus provided in this application further includes:
[0239] The fourth determining module is used to determine the second replica identifier from the replica identifiers that have been registered as the same instance, wherein the same instance is an instance that has the same instance identifier as the target instance;
[0240] Alternatively, a replica identifier that meets the preset long-term no-update condition at the update time can be identified as the second replica identifier, where the update time is the time when the identity identifier was last generated based on the replica identifier.
[0241] In one possible embodiment, the fourth determining module is configured to determine a second replica identifier from replica identifiers that have been registered as the same instance, specifically including:
[0242] If the same instance exists, the second replica identifier is determined from the replica identifiers that have already been registered as the same instance;
[0243] The fourth determination module is used to determine the replica identifier that meets the preset long-term no-update condition at the update time, and serves as the second replica identifier. Specifically, it includes:
[0244] If no identical instance exists, the replica identifier that was updated earliest or earlier than a preset time threshold is identified and used as the second replica identifier.
[0245] In one possible embodiment, the identity generation apparatus provided in this application further includes:
[0246] The update module is used to update the instance corresponding to the replica identifier to the target instance in the preset replica node table whenever a new replica identifier is registered for the target instance, and to update the update time corresponding to the replica identifier to the current system time.
[0247] The fourth determination module is used to determine the second replica identifier from replica identifiers that have been registered as the same instance, specifically including:
[0248] Based on the correspondence between replica identifiers and instances recorded in the replica node table, determine the replica identifier corresponding to the target instance;
[0249] determine the second copy identifier from the determined copy identifier;
[0250] The fourth determining module is configured to determine a copy identifier whose update time satisfies the preset long-term non-update condition as the second copy identifier, and specifically includes:
[0251] According to the correspondence between the copy identifier and the update time recorded in the copy node table, determine the copy identifier whose corresponding update time satisfies the preset long-term non-update condition as the second copy identifier.
[0252] In a possible embodiment, the second identity identifier generating module generates the identity identifier of the target object based on the current system time and the copy identifier newly registered for the target instance, and includes:
[0253] Splice the first field used to represent the current system time before the second field used to represent the copy identifier to obtain the identity identifier of the target object.
[0254] The third determining module determines the latest time in the system time based on which the generated identity identifier is generated as the latest system time, and includes:
[0255] Determine the system time based on which the generated maximum identity identifier is generated as the latest system time.
[0256] In a fifth aspect, the embodiments of the present application further provide an electronic device, as shown in the accompanying drawings, which includes: Figure 8
[0257] The memory 801 is configured to store computer programs.
[0258] The processor 802 is configured to execute the programs stored in the memory 801 to implement the following steps:
[0259] In response to an identity identifier request generated by the target instance for the target object, determine the current system time.
[0260] If the current system time is not later than the previous system time when the identity identifier is generated last time, register the unregistered first copy identifier as the copy identifier of the target instance.
[0261] Generate the identity identifier of the target object based on the current system time and the copy identifier newly registered for the target instance.
[0262] The electronic device can further include a communication bus and / or a communication interface, and the processor 802, the communication interface, and the memory 801 can communicate with each other through the communication bus.
[0263] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or only one type of bus.
[0264] The communication interface is used for communication between the above electronic device and other devices.
[0265] The memory can include a Random Access Memory (RAM) and can also include a Non-Volatile Memory (NVM), for example, at least one disk memory. Optionally, the memory can also be at least one storage device located away from the aforementioned processor.
[0266] The processor mentioned above can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.
[0267] In another embodiment provided in the present application, a computer readable storage medium is also provided, and the computer readable storage medium stores a computer program. When the computer program is executed by a processor, the steps of any of the above identity generation methods are implemented.
[0268] In another embodiment provided in the present application, a computer program product containing instructions is also provided, and when the computer program product is run on a computer, the computer is caused to execute any of the identity generation methods in the above embodiments.
[0269] In the embodiments described above, all or some of the steps can be implemented by using software, hardware, firmware or any combination thereof. When implemented with software, all or some of the steps can be implemented in the form of one or more computer programs which are stored in a computer readable storage medium and executed by one or more computers. The computer readable storage medium can include any storage medium that is readable by a computer processing module and stores computer program. The computer readable storage medium can be a computer storage medium or a computer communication medium. The computer storage medium includes any tangible storage medium, including floppy disks, hard disks, optical discs (e.g., CD-ROM, DVD, etc.), memory (e.g., ROM, RAM, etc.), and the like. The computer communication medium includes any medium that facilitates transfer of computer program from one place to another, such as the Internet and wireless media. The computer program can be downloaded from an Internet website, a computer network, or a data center. Alternatively, the computer program can be stored in a computer readable storage medium and then be installed by using various means. The computer readable storage medium above includes any tangible storage medium that is readable by a computer processing module. The computer readable storage medium can be a computer storage medium or a computer communication medium.
[0270] It should be noted that the terms such as first and second, etc., are merely used to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. In addition, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of additional identical elements in the process, method, article or device including the element.
[0271] Each of the embodiments in the specification is described in a related manner, and the same or similar parts between each of the embodiments can be referred to each other. Each of the embodiments focuses on the difference from other embodiments. In particular, for the system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the related parts can be referred to the part of the description of the method embodiments.
[0272] The above only describes the preferred embodiments of the present application, and is not used to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. An identity label generation method characterized by, The method comprises: in response to an identity request generated by a target instance for a target object, determining a current system time, the target instance having pre-registered a copy identity; determining the latest time in system times based on which an identity has been generated as the latest system time; if the current system time is not later than the previous system time, registering a first copy identity as the copy identity of the target instance, wherein the previous system time is the system time when the last identity was generated, and the first copy identity is a copy identity that has not been registered as the copy identity of the target instance; if the current system time is later than the latest system time and there is a same instance, determining a second copy identity from the copy identities that have been registered as the copy identities of the same instance; if the current system time is later than the latest system time and there is no same instance, determining a copy identity whose update time satisfies a preset long-term non-update condition as the second copy identity; registering the registered second copy identity as the latest registered copy identity of the target instance; wherein the same instance is an instance having the same instance identity as the target instance, the update time is the time when the last identity was generated based on the copy identity, and the long-term non-update condition is that the update time is the earliest or earlier than a preset time threshold; generating the identity of the target object based on the current system time and the latest registered copy identity of the target instance.
2. The method of claim 1, wherein, The method further comprises: if the current system time is later than the previous system time, performing the step of generating the identity of the target object based on the current system time and the latest registered copy identity of the target instance.
3. The method of claim 1, wherein, The registration of the first copy identity as the copy identity of the target instance comprises: if the clock identity is a preset target value, registering the unregistered first copy identity as the copy identity of the target instance; The generation of the identity of the target object based on the current system time and the latest registered copy identity of the target instance comprises: generating the identity of the target object based on the current system time, the latest registered copy identity of the target instance, and the clock identity; The method further comprises: if the current system time is not later than the previous system time and the clock is not the preset target value, modifying the clock identity to the preset target value, and performing the step of generating the identity of the target object based on the current system time, the latest registered copy identity of the target instance, and the clock identity.
4. An identity generation method, characterized by, The method comprises: in response to an identity request generated by a target instance for a target object, determining a current system time, the target instance having pre-registered a copy identity; determining the latest time in system times based on which an identity has been generated as the latest system time; if the current system time is later than the latest system time and there is a same instance, determining a second copy identity from the copy identities that have been registered as the copy identities of the same instance; wherein the same instance is an instance having the same instance identity as the target instance. If the current system time is later than the latest system time and there is no same instance, a copy identifier satisfying a preset long-term non-updating condition is determined as the second copy identifier, where the updating time is a time when the last identity identifier is generated based on the copy identifier, and the long-term non-updating condition is that the updating time is the earliest or earlier than a preset time threshold; The second copy identifier that has been registered is registered as the copy identifier that is newly registered for the target instance; An identity identifier of the target object is generated based on the current system time and the copy identifier that is newly registered for the target instance.
5. The method of claim 4, wherein, The method further includes: Whenever a new copy identifier is registered for the target instance, an instance corresponding to the copy identifier is updated to the target instance in a preset copy node table, and an updating time corresponding to the copy identifier is updated to the current system time; The second copy identifier is determined from the copy identifiers that have been registered as the same instance, including: A copy identifier corresponding to the target instance is determined according to a correspondence between the copy identifiers and the instances recorded in the copy node table; The second copy identifier is determined from the determined copy identifier; The copy identifier satisfying the preset long-term non-updating condition is determined as the second copy identifier, including: The copy identifier satisfying the preset long-term non-updating condition is determined as the second copy identifier according to a correspondence between the copy identifiers and the updating times recorded in the copy node table.
6. The method of claim 4, wherein, The identity identifier of the target object is generated based on the current system time and the copy identifier that is newly registered for the target instance, including: A first field used to represent the current system time is spliced before a second field used to represent the copy identifier to obtain the identity identifier of the target object; The latest time in the system times based on which the generated identity identifier is generated is determined as the latest system time, including: The system time based on which the largest identity identifier is generated is determined as the latest system time.
7. An identity tag generating apparatus characterized by comprising: The apparatus includes: A first determining module configured to determine a current system time in response to a request for generating an identity identifier for a target object by a target instance, the target instance having registered a copy identifier in advance; A third determining module configured to determine the latest time in the system times based on which the generated identity identifier is generated as the latest system time; A first registering module configured to register a first copy identifier as the copy identifier of the target instance if the current system time is not later than a previous system time, where the previous system time is a system time when the last identity identifier is generated, and the first copy identifier is a copy identifier that has not been registered as the copy identifier of the target instance. The fourth determining module is configured to determine a second copy identifier from copy identifiers that have been registered as the same instance if the same instance exists; and determine a copy identifier that meets a preset long-term non-updating condition in terms of an updating time as the second copy identifier if the same instance does not exist, wherein the same instance is an instance that has the same instance identifier as the target instance, the updating time is a time of generating the identity identifier based on the copy identifier last time, and the long-term non-updating condition is that the updating time is the earliest or earlier than a preset time threshold. The second registering module is configured to register the second copy identifier that has been registered as the copy identifier of the target instance that is registered most recently if the current system time is later than the latest system time. The first identity identifier generating module is configured to generate the identity identifier of the target object based on the current system time and the copy identifier that is registered most recently for the target instance.
8. The apparatus of claim 7, wherein, The apparatus further includes: The first executing module is configured to execute the step of generating the identity identifier of the target object based on the current system time and the copy identifier that is registered most recently for the target instance if the current system time is later than the previous system time. The first registering module registers the first copy identifier as the copy identifier of the target instance, including: If the clock identifier is a preset target value, the first copy identifier that has not been registered is registered as the copy identifier of the target instance. The first identity identifier generating module generates the identity identifier of the target object based on the current system time and the copy identifier that is registered most recently for the target instance, including: The identity identifier of the target object is generated based on the current system time, the copy identifier that is registered most recently for the target instance, and the clock identifier. The apparatus further includes: The second executing module is configured to modify the clock identifier to the preset target value and execute the step of generating the identity identifier of the target object based on the current system time, the copy identifier that is registered most recently for the target instance, and the clock identifier if the current system time is not later than the previous system time and the clock is not the preset target value.
9. An identity label generating apparatus characterized by comprising: The apparatus includes: The second determining module is configured to determine a current system time in response to a request of generating an identity identifier for a target object by a target instance, wherein the target instance has a copy identifier registered in advance; The third determining module is configured to determine a latest time in system times based on which the identity identifier has been generated as a latest system time; The second registering module is configured to register a second copy identifier that has been registered as a copy identifier of the target instance that is registered most recently if the current system time is later than the latest system time. The second identity identifier generating module is configured to generate the identity identifier of the target object based on the current system time and the copy identifier that is registered most recently for the target instance. The fourth determining module is configured to determine a second copy identifier from the copy identifiers that have been registered as the same instance if the same instance exists, and determine a copy identifier whose update time meets a preset long-term non-update condition as the second copy identifier if the same instance does not exist, wherein the same instance is an instance having the same instance identifier as the target instance, the update time is a time of generating the identity identifier based on the copy identifier last time, and the long-term non-update condition is that the update time is the earliest or earlier than a preset time threshold.
10. The apparatus of claim 9, wherein, The apparatus further includes: The updating module is configured to update an instance corresponding to the copy identifier as the target instance and update an update time corresponding to the copy identifier as a current system time in a preset copy node table whenever a new copy identifier is registered for the target instance; The fourth determining module is further configured to determine the second copy identifier from the copy identifiers that have been registered as the same instance, and specifically includes: determining the copy identifier corresponding to the target instance according to a correspondence between the copy identifiers and the instances recorded in the copy node table; determining the second copy identifier from the determined copy identifier; The fourth determining module is configured to determine the copy identifier whose update time meets the preset long-term non-update condition as the second copy identifier, and specifically includes: determining the copy identifier whose corresponding update time meets the preset long-term non-update condition as the second copy identifier according to the correspondence between the copy identifiers and the update times recorded in the copy node table; The second identity identifier generating module generates the identity identifier of the target object based on the current system time and the copy identifier newly registered for the target instance, and includes: splicing a first field used to represent the current system time before a second field used to represent the copy identifier to obtain the identity identifier of the target object; The third determining module determines the latest time in the system times based on which the generated identity identifiers are generated as the latest system time, and includes: determining the system time based on which the largest identity identifier is generated as the latest system time.
11. An electronic device, comprising: include: a memory for storing a computer program; a processor for executing the program stored in the memory to implement the method in any one of claims 1-3 or 4-6.
Citation Information
Patent Citations
Identity label generation method and device and computer readable storage medium
CN110457335A
Identification number generation method and device, electronic equipment and storage medium
CN110554732A
Method and device for generating identity identification number
CN111680052A
Identifier generation method and device, equipment and storage medium
CN111917897A
Method and device for solving clock callback problem
CN113589881A