I am developing a node.js application on Windows Azure Websites (IISNode) and have installed the Azure SDK module for node.js my question is how to use the etag or timestamp field in table storage.
Is it a matter of “me” doing something e.g:
if (entities[0].Timestamp == newEntity.Timestamp)
// commit this update because we are dealing with the latest copy of this entity
else
// oops! one of the entities is newer than the other, better not save it
Or do I need to listen for a error returned by the tableService.updateEntity( … for an error returned or something ?
Any help or advice appreciated
As Neil mentioned good practice is to let table service handles the concurrency related stuff.
When we fetch the entity from the table service using the client library, library will store the ETag associated with the entity (which present in the response from the service for the entity) in an EntityDescriptior instance (EntityDescriptor is an object maintained by the library for each entity instance in the context)
When you submit a request to update an entity, sdk will prepare HTTP request with body as entity serialized to XML and ETag header of the request as the ETag value stored in the entity descriptor corresponding to the entity.
When the table service receives this request for updating the entity instance, it checks whether the ETag in the request matches with the ETag currently associated with entity in the table storage (the ETag associated with the entity stored in the service changes if some other update happened before receiving your update request), if it does not matches service returns pre-condition failed/conflict error by setting Http status code in the response to 412 or 409.