سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top