Azure 中取决于日期时间的重复行键的概率是多少

发布于 2024-10-13 08:38:47 字数 441 浏览 5 评论 0原文

是否有机会在像这样构造的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

双马尾 2024-10-20 08:38:47

当并发写入数量接近无穷大时,获得多个相同 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文