Azure Concurrency Table Update Problem

I am trying to update the user's credit / account information for each transaction. If we hit more than 2/4 transactions per second, the update below does not update the counts / user credit information.

Two problems basically.

  • The update does not occur with anything or with an error message.
  • Update error with error message: 412: Fail: Code: 412 Value: Condition Condition Failed (if any): UpdateConditionNotSatisfied The update condition specified in the request was not met. RequestId: 1beb3fa9-9ad2-46f7-b8ee-af3a09300db7 Time: 2013-06-09T16: 12: 17.6797130Z.

I am making a prototype for migrating from RDMBS to NoSQL using Azure for SMS API . I don’t know why this is happening.

Paste the code below

public function update_credit_to_azure_table () { // Create table REST proxy. $tableRestProxy = ServicesBuilder::getInstance() ->createTableService($this->connectionString); $result = $tableRestProxy->getEntity("tblapilogin", $this->apiusr , $this->apiusr); $entity = $result->getEntity(); $new_api_balance = $this->global_api_credit - $this->credittodeduct; $credit_used = $this->api_credit_used + $this->credittodeduct; $entity->setPropertyValue("global_api_credit", $new_api_balance); //Update Balance. $entity->setPropertyValue("api_credit_used", $credit_used); //credit used Updated . try { $tableRestProxy->updateEntity("tblapilogin", $entity); echo "<br>New Blance is: " . $new_api_balance; echo "<br>credit_used is: " . $credit_used; } catch(ServiceException $e) { $code = $e->getCode(); $error_message = $e->getMessage(); echo $code.": ".$error_message."<br />"; } } 

The refresh function with optimistic concurrency here is a big test.

+4
source share
2 answers

I am not an expert in PHP, but looking at the Github source code, I found that the updateEntity function always forces the use of ETag , i.e. the function forces a conditional update:

 public function updateEntity($table, $entity, $options = null) { return $this->_putOrMergeEntityImpl( $table, $entity, Resources::HTTP_PUT, true, $options ); } 

Based on the documentation here :

If the ETag is different from the request specified in the update, the update operation completes with status code 412 (Prerequisite Failed). This error indicates that the object has been modified to the server since it was restored. To resolve this error, the object again and reissue the request.

To force an unconditional update operation, set the If-Match header value to the wildcard character (*) in the request. Passing this value for the operation will override the default concurrency optimization and ignore any mismatch of ETag values.

If the Etag value does not match, you will get the 412 error you get.

I would suggest using the insertOrReplaceEntity operation instead of the insertOrReplaceEntity operation, since it would create an entity if it does not exist, otherwise it would update it. Also looking at the code, this one does not use ETag .

 public function insertOrReplaceEntity($table, $entity, $options = null) { return $this->_putOrMergeEntityImpl( $table, $entity, Resources::HTTP_PUT, false, $options ); } 

Pay attention to the 4th parameter in both functions. This is the one that forces the use of ETag. In updateEntity it is set to true , and in insertOrReplaceEntity set to false .

0
source

With the same problem, as Steve explained in one of his episodes.

http://channel9.msdn.com/Shows/Cloud+Cover/Cloud-Cover-Episode-43-Scalable-Counters-with-Windows-Azure

If you do 1 read, write the operation per second on one object, it will work without Etag rollback. Otherwise, you will create your own intelligent logic.

Another useful resource:

How to build a globally high counter in Azure?

0
source

Source: https://habr.com/ru/post/1485299/


All Articles