In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The definition, classification, application and generation tools of UUID are discussed.
What is UUID?
UUID is an acronym for Universally Unique Identifier, which is a unique machine-generated identifier within a range (from a specific namespace to the world). UUID has the following meanings:
In order to ensure the uniqueness of UUID, the specification defines elements such as network card MAC address, timestamp, namespace (Namespace), random or pseudo-random number, time series and so on, and the algorithm for generating UUID from these elements. The complexity of UUID not only ensures its uniqueness, but also means that it can only be generated by computer.
Non-manual, non-manually identified UUID cannot be manually specified unless you run the risk of repeating the UUID. The complexity of UUID determines that the "average person" cannot know which object is associated with it directly from an UUID.
The possibility of repetition within a specific range is minimal. The main purpose of the algorithm defined by the generation specification of UUID is to ensure its uniqueness. But this uniqueness is limited and can only be guaranteed within a specific scope, depending on the type of UUID (see version of UUID).
A UUID is a 16-byte, 128-bit number, usually represented as a 36-byte string, as shown in the following example:
3F2504E0-4F89-11D3-9A0C-0305E82C3301
The letters are represented in hexadecimal, regardless of case.
GUID (Globally Unique Identifier) is an alias for UUID; but in practical applications, GUID usually refers to the UUID implemented by Microsoft.
The version of UUID
There are several versions of UUID, each with different algorithms and different applications.
First of all, there is a special case-- Nil UUID--, which we don't usually use, is made up of numbers with all zeros, as follows:
00000000-0000-0000-0000-0000000000
UUID Version 1: time-based UUID
Time-based UUID is obtained by calculating the current timestamp, random number, and machine MAC address. Due to the use of MAC addresses in the algorithm, this version of UUID ensures global uniqueness. At the same time, however, the use of MAC addresses creates security issues, which is where this version of UUID is criticized. If the application is only used in the local area network, you can also use a degenerate algorithm to replace the MAC address with the IP address-- the UUID of Java is often implemented this way (of course, the difficulty of obtaining MAC is also taken into account).
UUID Version 2:DCE secure UUID
The DCE (Distributed Computing Environment) secure UUID algorithm is the same as the time-based UUID algorithm, but replaces the first four bits of the timestamp with POSIX's UID or GID. This version of UUID is rarely used in practice.
UUID Version 3: name-based UUID (MD5)
Name-based UUID is obtained by calculating the MD5 hash values of names and namespaces. This version of UUID guarantees the uniqueness of UUID generated by different names in the same namespace, the uniqueness of UUID in different namespaces, and the repeated generation of UUID with the same name in the same namespace.
UUID Version 4: random UUID
Generate UUID from random numbers, or pseudorandom numbers. The probability that this UUID produces repetition can be calculated, but something random is like buying a lottery ticket: it's impossible to expect it to get rich, but bad luck usually comes unexpectedly.
UUID Version 5: name-based UUID (SHA1)
Similar to the version 3 UUID algorithm, except that the hash value is calculated using the SHA1 (Secure Hash Algorithm 1) algorithm.
Application of UUID
As can be seen from different versions of UUID, Version 1 Version 2 is suitable for use in distributed computing environments with a high degree of uniqueness; Version 3 UUID 5 is suitable for environments where names are unique within a certain range and UUID is needed or may be generated repeatedly; as for Version 4, my personal advice is that it is best not to use it (although it is the simplest and most convenient).
In general, we recommend using UUID to identify objects or persist data, but it is best not to use UUID in the following situations:
Objects of the mapping type. For example, a code table with only codes and names. Manually maintained non-system-generated objects. For example, some of the basic data in the system. For objects with natural properties with non-repeatable names, it is best to use the UUID of Version 3 to 5. Such as the users in the system. If the user's UUID is Version 1, if you accidentally delete and then rebuild the user, you will find that the user is the same person and the user is no longer that user. (although marking as deletion state is also a solution, it brings implementation complexity. )
UUID generator
I didn't expect anyone to implement a UUID generator on their own after reading this article, so the previous content does not cover the details of the algorithm. Here are some available Java UUID generators:
Java UUID Generator (JUG): open source UUID generator, LGPL protocol, supports MAC addresses. UUID: special License, source code. The UUID generator that comes with Java 5 and above seems to only generate UUID for Version 3 and Version 4.
In addition, there is a UUID generator in Hibernate, but it is not a (specification) version of UUID that is generated and is strongly deprecated.
Extended reading
UUID specification: rfc4122
UUID in DCE 1.1
UUID, GUID
Reproduced from: http://www.blogjava.net/feelyou/archive/2008/10/14/234320.html
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.