Azure 中取决于日期时间的重复行键的概率是多少
是否有机会在像这样构造的Azure表中重复RowKey?
string.Format("{0:d19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks)
这与问:
在我们获得新的 Ticks 值之前,我的网络角色会创建两条记录吗?
我想按时间倒序返回实体。该表预计不会不断添加新实体,但希望会有许多插入事务。
解决方案
好的,这是我遇到的解决方案,感谢 Mark Seeman:
string.Format("{0:d19}+{1}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks, Guid.NewGuid().ToString ("N"))
使用 Guid,我确信 rowkey 不会重复。
Is the there the chance to repeat a RowKey in an Azure table that is constructed like this?
string.Format("{0:d19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks)
This is the same to ask:
Will my webrole create two records before we get to a new value for Ticks?
I want to return the entities in reverse chronological order. This table is not expected to be constantly added new entities, but hopefully will have many insert transactions.
Solution
OK, this is the solution I came across thanks to Mark Seeman:
string.Format("{0:d19}+{1}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks, Guid.NewGuid().ToString("N"))
Using a Guid, I know for sure that the rowkey will not be repeated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当并发写入数量接近无穷大时,获得多个相同 rowkey 的概率为 1 :)
说真的,一个 Tick 是 100 纳秒。现代处理器的运行速度使得每个 Tick 有数百个 CPU 周期,因此会发生相同的 Tick。
事实上,我昨天刚刚和我的一位客户交谈。他遇到了这个确切的问题,并且不得不解决它以确保唯一性。
考虑引入一个真正独特的组件(例如 GUID)作为(可排序)组合的一部分。
The probability of getting more than one identical rowkey is 1 as the number of concurrent writes approaches infinity :)
Seriously, a Tick is 100 nanoseconds. Modern processors run at speeds where you will have hundreds of CPU cycles per Tick, so getting identical Ticks will happen.
In fact, I was just talking to one of my customers yesterday. He had that exact problem and had had to hack around it to ensure uniqueness.
Consider introducing a truly unique component (such as GUID) as part of a (sortable) composite.