Auto-increment on Azure Table Storage?

I haven't implemented this yet but am working on it You could seed a queue with your next ids to use, then just pick them off the queue when you need them You need to keep a table to contain the value of the biggest number added to the queue. If you know you won't be using a ton of the integers, you could have a worker every so often wake up and make sure the queue still has integers in it. You could also have a used int queue the worker could check to keep an eye on usage You could also hook that worker up so if the queue was empty when your code needed an id (by chance) it could interupt the worker's nap to create more keys asap If that call failed you would need a way to (tell the worker you are going to do the work for them (lock), then do the workers work of getting the next id and unlock) lock get the last key created from the table increment and save unlock then use the new value.

I haven't implemented this yet but am working on it ... You could seed a queue with your next ids to use, then just pick them off the queue when you need them. You need to keep a table to contain the value of the biggest number added to the queue. If you know you won't be using a ton of the integers, you could have a worker every so often wake up and make sure the queue still has integers in it.

You could also have a used int queue the worker could check to keep an eye on usage. You could also hook that worker up so if the queue was empty when your code needed an id (by chance) it could interupt the worker's nap to create more keys asap. If that call failed you would need a way to (tell the worker you are going to do the work for them (lock), then do the workers work of getting the next id and unlock) lock get the last key created from the table increment and save unlock then use the new value.

What I can understand from download.microsoft. Com/download/5/2/D/… is that a message is added to the queue again if a worker process fails while processing the queue message. You therefore need to make the job on the worker role idempotent.

If the same message (i.e. The same ID) is used by two different worker roles I don't see how you can make that idempotent. – Yrlec Dec 9 '09 at 14:20 If you have only 1 woker creating the id's then dups would be put in the queue.

When pulling the ids out of the queue, get the message, then delete the message before using the message's contents (id). That should ensure no id's are used more than once. Seems like the worse case scenario then would be you may loose a key, but your uniqueness should still be good.

– Jason Haley Dec 9 '09 at 17:44 The second sentence above should be: "If you have only 1 woker creating the id's then dups wouldn't be put in the queue ..." – Jason Haley Dec 9 '09 at 17:45.

The solution I found that prevents duplicate ids and lets you autoincrement it is to lock (lease) a blob and let that act as a logical gate. Then read the value. Write the incremented value Release the lease Use the value in your app/table Then if your worker role were to crash during that process, then you would only have a missing ID in your store.

IMHO that is better than duplicates. Here is a code sample and more information on this approach from Steve Marx.

If you really need to avoid guids, have you considered using something based on date/time and then leveraging partition keys to minimize the concurrency risk. Your partition key could be by user, year, month, day, hour, etc and the row key could be the rest of the datetime at a small enough timespan to control concurrency. Of course you have to ask yourself, at the price of date in Azure, if avoiding a Guid is really worth all of this extra effort (assuming a Guid will just work).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions