在重新启动节点/ VM之前,erlang引用是否唯一? [英] Are erlang refs unique between nodes/VM restarts?

查看:280
本文介绍了在重新启动节点/ VM之前,erlang引用是否唯一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档说,


make_ref() -> ref()  

返回几乎唯一的引用。

Returns an almost unique reference.

返回的引用将在大约2次 82 调用后重新出现;
因此它是独一无二的实际目的。

The returned reference will re-occur after approximately 282 calls; therefore it is unique enough for practical purposes.

但我的眼睛告诉我,在VM重新启动之间,我可以很容易地得到相同的参考:

But my eyes tell me that between VM restarts I could easily get the same ref:

[~] erl
Erlang R14B04 (erts-5.8.5)
1> make_ref().
#Ref<0.0.0.33>
2> make_ref().
#Ref<0.0.0.37>
^C

[~] erl
Erlang R14B04 (erts-5.8.5)
1> make_ref().
#Ref<0.0.0.33>

那么,Erlang的参考文献有多么独特?当标签在mq或db中持续存在并且可能由不同的VM会话生成时,它们是否适合用作唯一的标签生成器。

So, how unique Erlang’s Refs are? Are they suitable to be used as an unique "tag" generator when tags are persistent in mq or db and may be generated by different VM sessions.

我知道UUID可以是用于此。还有众所周知的是,pids()是可重复的,可重用的,绝对不是唯一的,如果序列化,然后从持久存储加载。

I know UUIDs could be used for this. It’s also well known that pids() are repeatable, reusable and by no means unique if serialized and then loaded from persistent storage.

问题是,什么是refs()更像是UUID或更像pids()?节点之间的refs()是否唯一?重启之间?有关这个主题的官方信息?

Question is, what are refs() — more like UUIDs or more like pids()? Are refs() unique between nodes? Between restarts? Is there any official info on this topic?

推荐答案

与节点名称相关的参考,并不意味着随机性,只是唯一性。
正如您已经注意到的那样,它们以循环的方式创建。
另外,你是正确的事实参考是唯一的只有一个节点的寿命。一旦重新启动VM,就可以重复引用。

References, which are related to the name of a node, do not imply randomness, just uniqueness. As you've already noticed, they're created in a cyclic way. Also, you're correct on the fact references are unique only for the life span of a node. Once, you restart the VM, references can be repeated.

与PID一样,打印引用#Ref< WXYZ& code>包含 - 作为第一个元素( W ) - 有关节点号的信息:

As in the case of PIDs, printed references #Ref<W.X.Y.Z> contain - as their first element (W) - information about the node number:

erl -sname right
Erlang R15B (erts-5.9) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9  (abort with ^G)
(right@mars)1> register(right, self()).
true
(right@mars)2> receive M -> M end.
#Ref<6793.0.0.41>
(right@mars)3> 

erl -sname left
Erlang R15B (erts-5.9) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9  (abort with ^G)
(left@mars)1> {right, 'right@mars'} ! make_ref().
#Ref<0.0.0.41>
(left@mars)2> 

请注意在这种情况下, W 在本地节点中的引用是 0 ,远程的 6793

Notice how in this case the W for the reference is 0 in the local node, 6793 in the remote one.

这篇关于在重新启动节点/ VM之前,erlang引用是否唯一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆