RyanFishman
RyanFishman

Reputation: 695

Get Timestamp after Insert/Update

In azure table storage. Is there a way to get the new timestamp value after an update or insert. I am writing a 3-phase commit protocol to get table storage to support distributed transactions , and it involes multiple writes to the same entity. So the operation order goes like this, Read Entity, Write Entity (Lock Item), Write Entity (Commit new values). I would like to get the new timestamp after the lock item operation so I don't have to unecessarily read the item again before doing the commit new value operation. So does any one know how to efficiently get the new timestamp value after a savechanges operation?

Upvotes: 0

Views: 663

Answers (4)

Gabe Rainbow
Gabe Rainbow

Reputation: 3748

You may need to hack your Azure table. drivers

In the Azure python lib (TableStorage) for example, the Timestamp is simply skipped over.

    # exclude the Timestamp since it is auto added by azure when
    # inserting entity. We don't want this to mix with real properties
    if name in ['Timestamp']:
        continue

Upvotes: 0

Cellfish
Cellfish

Reputation: 2192

I don't think you need to do anything special/extra. When you read your entity you will get an Etag for it. When you save that entity (setting someLock=true) that save will only succeed if nobody else have updated the entity since your read. Hence you know you have the lock. And then you can do your second write as you please.

Upvotes: 1

knightpfhor
knightpfhor

Reputation: 9409

If you're willing to go back to the Update REST API call, it does return the time that the response was generated. It probably won't be exactly the same as the time stamp on the record, but it will be close I'm sure.

Upvotes: 0

Igorek
Igorek

Reputation: 15860

I don't believe it is possible. I would use your own timestamp and/or guid to mark entries.

Upvotes: 0

Related Questions