开发者

Amazon SimpleDB: Response messages don't agree with the request parameters

I'm making a simple high scores database for an iPhone game using Amazon's SimpleDB and am running into some strange issues where SimpleDB's response messages don't seem to line up with the requests I'm sending or even the state of the data on the server.

The expected sequence of events for submitting high scores in the app is:

  1. A PutAttributes request is created that tries to overwrite the current score with the new value but only if it is greater than the last known value of the score.

  2. If the expected value doesn't match the value on the server, SimpleDB's response message lets the app know what the actual value is and a new request is created using it as the new expected value.

  3. This process continues until either the response states that everything was OK or until the score on the server comes back as higher than the score we're trying to submit (i.e. if somebody with a higher score submitted while this back and forth was going on)

(In case it's relevant I'm using the ASIHTTPRequest class to handle the requests and I've explicitly turned off caching by setting each request's cache policy to ASIIgnoreCachePolicy when I create them.)

However, what's actually happening is a bit strange...

  1. The first response comes back with the expected result. For example, the app submits a score of 200 and expects the score on the server to be 0 but it's actually 100. SimpleDB responds that the conditional check failed and lets the app know the actual value on the server (100).

  2. The app sends a request with an updated expected value but SimpleDB responds with an identical response as the first time even though the expected value was changed (e.g. the response says the actual value is 100 and the expected value we passed in was 0 even though we had just changed it to 100).

  3. The app sends a third request with the exact same score/expected values as the second request (e.g. 100 for both) and SimpleDB reports that the condition failed again because the actual value is 200.

So it looks like the second attempt actually worked even though SimpleDB reported a failure and gave an incorrect account of the param开发者_运维百科eters I had passed in. This odd behavior is also very consistent - every time I try to update a score with an expected value that doesn't match the one on the server the exact same sequence occurs.

I've been scratching my head at this for a while now and I'm flat out of ideas so if anyone with more SimpleDB experience than me could shed some light on this I'd be mighty grateful.

Below is a sample sequence of requests and responses in case that does a better job of describing the situation than my tortured explanation above (these values taken from actual requests and responses but I've edited out the non-relevant parts of the requests).

Request 1

(The score on the server is 100 at this point)

Attribute.1.Name=Score

Attribute.1.Replace=true

Attribute.1.Value=200

Expected.1.Name=Score

Expected.1.Value=000

Consistent=true

Response 1

Conditional check failed. Attribute (Score) value is (100) but was expected (000)

Request 2

(The app updates to proper score but based on the response SimpleDB seems to ignore the changes)

Attribute.1.Name=Score

Attribute.1.Replace=true

Attribute.1.Value=200

Expected.1.Name=Score

Expected.1.Value=100

Consistent=true

Response 2

Conditional check failed. Attribute (Score) value is (100) but was expected (000)

Request 3

(This time SimpleDB gets the expected value right but also reports that the score has been updated even though all previous responses indicated otherwise)

Attribute.1.Name=Score

Attribute.1.Replace=true

Attribute.1.Value=200

Expected.1.Name=Score

Expected.1.Value=100

Consistent=true

Response 3

Conditional check failed. Attribute (Score) value is (200) but was expected (100)

Update (10/21/10)

I checked to make sure that the requestIDs that are being returned from the server are all unique and indeed they are.


Try passing ConsistentRead=true in your requests.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜