本文介绍了顺序的GUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我希望有人能回答这个问题。I hope someone can answer this question.如何在Rpcrt4.dll中类使用UuidCreateSequential方法种子它的GUID?How does the UuidCreateSequential method in the rpcrt4.dll class use to seed it's guids?我知道这么多:微软改变了UuidCreate功能,使其不再使用本机的MAC地址作为UUID的一部分。由于CoCreateGuid呼吁UuidCreate来获得它的GUID,它的输出也发生了变化。如果你还是喜欢的GUID被按顺序产生的(有助于在系统注册表中保存的GUID的相关组合在一起),您可以使用UuidCreateSequential函数。I know this much:Microsoft changed the UuidCreate function so it no longer uses the machine's MAC address as part of the UUID. Since CoCreateGuid calls UuidCreate to get its GUID, its output also changed. If you still like the GUIDs to be generated in sequential order (helpful for keeping a related group of GUIDs together in the system registry), you can use the UuidCreateSequential function.这个问题背后的原因是。如果我用这个功能来生成一个Web集群顺序的GUID,我怎么能保证GUID是接近了一系列的GUID没有被复制的GUID的潜力?The reason behind the question is. If I use this function to generate sequential GUIDs in a web cluster, how can I ensure that the GUIDs are close to a range of GUIDs without the potential of the GUID being duplicated?推荐答案 Win32的 UuidCreateSequential 创建的 版本1 UUID 。 The Win32 UuidCreateSequential creates a Version 1 uuid. 下面是一些示例版本1 UUID的使用 UuidCreateSequential 我的计算机上创建的:Here's some sample version 1 uuid's created on my computer using UuidCreateSequential:{1BE8D85D-63D1-11E1-80DB-B8AC6FBE26E1}{1BE8D85E-63D1-11E1-80DB-B8AC6FBE26E1}{1BE8D85F-63D1-11E1-80DB-B8AC6FBE26E1}{1BE8D860-63D1-11E1-80DB-B8AC6FBE26E1}{1BE8D861-63D1-11E1-80DB-B8AC6FBE26E1}{1BE8D862-63D1-11E1-80DB-B8AC6FBE26E1}{1BE8D863-63D1-11E1-80DB-B8AC6FBE26E1}{1BE8D864-63D1-11E1-80DB-B8AC6FBE26E1}{1BE8D865-63D1-11E1-80DB-B8AC6FBE26E1}{220FB46C-63D1-11E1-80DB-B8AC6FBE26E1}这是非常重要的首先要注意的是,这些UUID包含我的机器的MAC地址( B8AC6FBE26E1 ):The first thing that's important to note that these uuid contain my machine's MAC address (B8AC6FBE26E1): Node======================= ============1BE8D85D-63D1-11E1-80DB B8AC6FBE26E11BE8D85E-63D1-11E1-80DB B8AC6FBE26E11BE8D85F-63D1-11E1-80DB B8AC6FBE26E11BE8D860-63D1-11E1-80DB B8AC6FBE26E11BE8D861-63D1-11E1-80DB B8AC6FBE26E11BE8D862-63D1-11E1-80DB B8AC6FBE26E11BE8D863-63D1-11E1-80DB B8AC6FBE26E11BE8D864-63D1-11E1-80DB B8AC6FBE26E11BE8D865-63D1-11E1-80DB B8AC6FBE26E1220FB46C-63D1-11E1-80DB B8AC6FBE26E1所以,如果你希望对不同的计算机生成GUID的是接近对方,你会失望的。So if you're hoping for different computers to generate guid's that are "close" to each other, you're going to be disappointed.让我们来看看其余值。七剩下的10个字节的半字节是一个时间戳;因为 15 00:00:00 1582年10月为100ns间隔数即可。重新排列这些时间戳字节加在一起:Seven and a half bytes of the remaining 10 bytes are a timestamp; the number of 100ns intervals since 00:00:00 15 October 1582. Rearranging those timestamp bytes together:Timestamp Node=============== ====== ============1E163D11BE8D85D 1-80DB B8AC6FBE26E11E163D11BE8D85E 1-80DB B8AC6FBE26E11E163D11BE8D85F 1-80DB B8AC6FBE26E11E163D11BE8D860 1-80DB B8AC6FBE26E11E163D11BE8D861 1-80DB B8AC6FBE26E11E163D11BE8D862 1-80DB B8AC6FBE26E11E163D11BE8D863 1-80DB B8AC6FBE26E11E163D11BE8D864 1-80DB B8AC6FBE26E11E163D11BE8D865 1-80DB B8AC6FBE26E11E163D1220FB46C 1-80DB B8AC6FBE26E1您可以看到在同一台机器上创建的GUID的由 UuidCreateSequential 会在一起,因为他们是按时间顺序排列。You can see that guid's created on the same machine by UuidCreateSequential will be together, as they are chronological.的 1 你看到的是版本号的,在这种情况下,这意味着一个的基于时间的UUID。有5个定义的版本:The 1 you see is the version number, in this case meaning a time based uuid. There are 5 defined versions: 1:基于时间的版本( UuidCreateSequential ) 2:DCE安全的版本,具有嵌入式POSIX的UID 3:使用MD5散列 基于名字的版本 4:随机或伪随机生成的版本( UuidCreate ) 5:使用SHA-1散列基于名字的版本 1: time based version (UuidCreateSequential)2: DCE Security version, with embedded POSIX UIDs3: Name-based version that uses MD5 hashing4: Randomly or pseudo-randomly generated version (UuidCreate)5: Name-based version that uses SHA-1 hashing捐赠:Timestamp Version Node=============== ======= ==== ============1E163D11BE8D85D 1 80DB B8AC6FBE26E11E163D11BE8D85E 1 80DB B8AC6FBE26E11E163D11BE8D85F 1 80DB B8AC6FBE26E11E163D11BE8D860 1 80DB B8AC6FBE26E11E163D11BE8D861 1 80DB B8AC6FBE26E11E163D11BE8D862 1 80DB B8AC6FBE26E11E163D11BE8D863 1 80DB B8AC6FBE26E11E163D11BE8D864 1 80DB B8AC6FBE26E11E163D11BE8D865 1 80DB B8AC6FBE26E11E163D1220FB46C 1 80DB B8AC6FBE26E1最后的字的包含了两件事情。 The last word contains two things. 低12位的是机器specifc的时钟序列号:The lower 12 bits is the machine-specifc Clock Sequence number:Timestamp Version Clock Sequence Node=============== ======= = ================ ============1E163D11BE8D85D 1 8 0DB B8AC6FBE26E11E163D11BE8D85E 1 8 0DB B8AC6FBE26E11E163D11BE8D85F 1 8 0DB B8AC6FBE26E11E163D11BE8D860 1 8 0DB B8AC6FBE26E11E163D11BE8D861 1 8 0DB B8AC6FBE26E11E163D11BE8D862 1 8 0DB B8AC6FBE26E11E163D11BE8D863 1 8 0DB B8AC6FBE26E11E163D11BE8D864 1 8 0DB B8AC6FBE26E11E163D11BE8D865 1 8 0DB B8AC6FBE26E11E163D1220FB46C 1 8 0DB B8AC6FBE26E1本机广泛持久的数值增加,如果:This machine-wide persistent value is incremented if: 您交换网络卡 您生成一个UUID从最后一个小于100ns(和时间戳会发生冲突) 所以,再次,任何GUID由 UuidCreateSequential 创建的意志(理想情况下)具有相同的时钟序列数量,使他们接近给对方。So, again, any guid's created by UuidCreateSequential will (ideally) have the same Clock Sequence number, making them "near" to each other.最后2位,被称为变,然后始终设置为二进制 10 :The final 2 bits, is called a Variant, and is always set to binary 10:Timestamp Version Variant Clock Sequence Node=============== ======= ======= ================ ============1E163D11BE8D85D 1 8 0DB B8AC6FBE26E11E163D11BE8D85E 1 8 0DB B8AC6FBE26E11E163D11BE8D85F 1 8 0DB B8AC6FBE26E11E163D11BE8D860 1 8 0DB B8AC6FBE26E11E163D11BE8D861 1 8 0DB B8AC6FBE26E11E163D11BE8D862 1 8 0DB B8AC6FBE26E11E163D11BE8D863 1 8 0DB B8AC6FBE26E11E163D11BE8D864 1 8 0DB B8AC6FBE26E11E163D11BE8D865 1 8 0DB B8AC6FBE26E11E163D1220FB46C 1 8 0DB B8AC6FBE26E1所以你有它。顺序的GUID是连续的;如果你的在同一台机器的他们将是近在数据库对方。So there you have it. Sequential guid's are sequential; and if you create them on the same machine they will be "near" to each other in a database.但是你想知道究竟发生了与两个连续的UUID的不同计算机上创建的。 But you want to know what actually happens with two sequential UUID's created on different computers. 使用我们的版本的新知识1的GUID,让我们构造两个GUID的从不同的机器,如相同的时间戳:Using our newfound knowledge of Version 1 guids, let's construct two guid's for the same timestamp from different machines, e.g.:{1BE8D85D-63D1-11E1-80DB-B8AC6FBE26E1}{1BE8D85D-63D1-11E1-80DB-123456789ABC}首先,让我们插入了一堆的GUID与连续时间戳。首先创建一个临时表来存储GUID在和的群集的由GUID:First let's insert a bunch of guid's with sequential timestamps. First create a temporary table to store our guid's in, and cluster by the guid:--DROP table #uuidOrderingTestCREATE TABLE #uuidOrderingTest( uuid uniqueidentifier not null)CREATE clustered index IX_uuidorderingTest_uuid ON #uuidOrderingTest ( uuid)现在插入数据:INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D866-63D1-11E1-80DB-B8AC6FBE26E1}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D862-63D1-11E1-80DB-B8AC6FBE26E1}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D861-63D1-11E1-80DB-B8AC6FBE26E1}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D85E-63D1-11E1-80DB-B8AC6FBE26E1}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D864-63D1-11E1-80DB-B8AC6FBE26E1}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D863-63D1-11E1-80DB-B8AC6FBE26E1}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D85F-63D1-11E1-80DB-B8AC6FBE26E1}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D85D-63D1-11E1-80DB-B8AC6FBE26E1}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D865-63D1-11E1-80DB-B8AC6FBE26E1}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D860-63D1-11E1-80DB-B8AC6FBE26E1}') 注意:我将它们插入随机时间戳顺序,以表明SQL Server将群集他们Note: i insert them in random timestamp order, to illustrate that SQL Server will cluster them.获取行回来看看他们是什么样的顺序在顺序(时间标记)命令:Get the rows back and see what order they're in sequential (timestamp) order:SELECT * FROM #uuidOrderingTestuuid------------------------------------1BE8D85D-63D1-11E1-80DB-B8AC6FBE26E11BE8D85E-63D1-11E1-80DB-B8AC6FBE26E11BE8D85F-63D1-11E1-80DB-B8AC6FBE26E11BE8D860-63D1-11E1-80DB-B8AC6FBE26E11BE8D861-63D1-11E1-80DB-B8AC6FBE26E11BE8D862-63D1-11E1-80DB-B8AC6FBE26E11BE8D863-63D1-11E1-80DB-B8AC6FBE26E11BE8D864-63D1-11E1-80DB-B8AC6FBE26E11BE8D865-63D1-11E1-80DB-B8AC6FBE26E11BE8D866-63D1-11E1-80DB-B8AC6FBE26E1现在可以插入GUID的搭配:Now lets insert guid's with: 相同的时间戳 但不同的节点(即MAC地址): the same timestampsbut different node (i.e. MAC address):这是一个不一样的计算机将新的GUID:Insert the new guids from a "different" computer:INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D866-63D1-11E1-80DB-123456789ABC}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D862-63D1-11E1-80DB-123456789ABC}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D861-63D1-11E1-80DB-123456789ABC}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D85E-63D1-11E1-80DB-123456789ABC}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D864-63D1-11E1-80DB-123456789ABC}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D863-63D1-11E1-80DB-123456789ABC}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D85F-63D1-11E1-80DB-123456789ABC}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D85D-63D1-11E1-80DB-123456789ABC}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D865-63D1-11E1-80DB-123456789ABC}')INSERT INTO #uuidOrderingTest (uuid) VALUES ('{1BE8D860-63D1-11E1-80DB-123456789ABC}')和得到的结果:uuid------------------------------------1BE8D85D-63D1-11E1-80DB-123456789ABC1BE8D85E-63D1-11E1-80DB-123456789ABC1BE8D85F-63D1-11E1-80DB-123456789ABC1BE8D860-63D1-11E1-80DB-123456789ABC1BE8D861-63D1-11E1-80DB-123456789ABC1BE8D862-63D1-11E1-80DB-123456789ABC1BE8D863-63D1-11E1-80DB-123456789ABC1BE8D864-63D1-11E1-80DB-123456789ABC1BE8D865-63D1-11E1-80DB-123456789ABC1BE8D866-63D1-11E1-80DB-123456789ABC1BE8D85D-63D1-11E1-80DB-B8AC6FBE26E11BE8D85E-63D1-11E1-80DB-B8AC6FBE26E11BE8D85F-63D1-11E1-80DB-B8AC6FBE26E11BE8D860-63D1-11E1-80DB-B8AC6FBE26E11BE8D861-63D1-11E1-80DB-B8AC6FBE26E11BE8D862-63D1-11E1-80DB-B8AC6FBE26E11BE8D863-63D1-11E1-80DB-B8AC6FBE26E11BE8D864-63D1-11E1-80DB-B8AC6FBE26E11BE8D865-63D1-11E1-80DB-B8AC6FBE26E11BE8D866-63D1-11E1-80DB-B8AC6FBE26E1所以你有它。 SQL Server的订单的节点之前的时间戳。从不同的机器上创建的UUID不会群集在一起。会更好,如果它没有这样做,但干麻要怎么做。So there you have it. SQL Server order's Node before Timestamp. Uuid created from different machines will not be clustered together. Would have been better if it hadn't done so, but whatcha gonna do. 这篇关于顺序的GUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-27 05:13