SMU-SIS / ksketch2

K-Sketch Animation Sketching System
2 stars 0 forks source link

Same sketchId may be assigned to multiple sketches #37

Closed rc-davis closed 10 years ago

rc-davis commented 10 years ago

I don't know how to reproduce this, but here's how to see the symptoms:

  1. Go to the Google App Engine console for ksketchweb
  2. Go to the Datastore viewer
  3. Search the "Sketch" table by GQL: "SELECT * FROM Sketch WHERE sketchId = 365"
  4. You will find two sketches that match the same ID (one named "Dude where's my sketch?" and one named "Old School Galactica". Both were created around the same time on the same iPad, which was not connected to the server. They were uploaded to the server at together when I logged in to the server. Several other sketches were also uploaded, and these all have unique IDs.
rc-davis commented 10 years ago

It looks like new sketches are assigned a sketchId when they are uploaded, and this is found by incrementing the "sketch_count" field of the AppVersionCount singleton table in the DataStore. Is that right?

If so, then I suspect that this is a race condition on sketch_count. Remember that we are using the High Replication Data Store. That means there could be several copies of our database on different servers, and these are only guaranteed to be EVENTUALLY consistent. Thus, if we are uploading two sketches (A and B) at the same time, and we have two copies of the data store (X and Y), we could have the following situation:

1) Upload sketch A.

If I have diagnosed this correctly, then I can think of two ways to fix this:

Option 1: When fetching sketch_count, perform an ancestor query for a single entity group, as explained here: https://developers.google.com/appengine/docs/python/datastore/structuring_for_strong_consistency. This is probably the easiest way to fix this problem, but it should slow down uploads to one sketch per second.

Option 2: We could try using the "id" field wherever we currently use the "sketchId" field. This is created automatically and is always unique. The only problem is that the id field is probably larger than the sketchID field. This is hard to do, but it would probably work better in the long run.

ramvibhakar commented 10 years ago

Issue fixed using Option 2