{"issue":{"state":"closed","pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"user":{"avatar_url":"https://secure.gravatar.com/avatar/69ab66ba5d78eb9055a09e6cb5a06f57?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"69ab66ba5d78eb9055a09e6cb5a06f57","url":"https://api.github.com/users/halfer","login":"halfer","id":480975},"milestone":{"state":"open","open_issues":1,"url":"https://api.github.com/repos/halfer/Meshing/milestones/1","due_on":"2011-11-14T08:00:00Z","creator":{"avatar_url":"https://secure.gravatar.com/avatar/69ab66ba5d78eb9055a09e6cb5a06f57?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"69ab66ba5d78eb9055a09e6cb5a06f57","url":"https://api.github.com/users/halfer","login":"halfer","id":480975},"title":"Storage","description":"A basic implementation of how a Meshing database is stored locally.","number":1,"closed_issues":5,"created_at":"2011-10-01T20:19:23Z"},"assignee":null,"updated_at":"2011-11-07T23:51:01Z","labels":[],"comments":2,"closed_at":"2011-11-07T23:51:01Z","url":"https://api.github.com/repos/halfer/Meshing/issues/31","body":"Since we generate a version number separately from row insertion, the delay may be enough to permit a race condition. We do a SELECT in `MeshingBaseObject->createVersionableRow()` to get the MAX() version, and then save it some while later. In that time, that version number may have been taken by another process, and the save in our own process will fail due to non-uniqueness.\r\n\r\nOne solution is to do this:\r\n\r\n```\r\nINSERT INTO\r\n    test_model_test_organiser_versionable\r\n(id, creator_node_id, version)\r\nVALUES (\r\n    3,\r\n    1, \r\n    (\r\n        SELECT COALESCE(MAX(version), 1)\r\n        FROM test_model_test_organiser_versionable\r\n        WHERE id = 3\r\n        AND creator_node_id = 1\r\n    )\r\n);\r\n```\r\n\r\nWe can then do an update of ordinary columns at our leisure, since the race condition has been averted. However we need to address this new row - how to do that when the MAX() value is not returned to the user? We could add another column, set it to auto-increment, and then read that from Propel.\r\n\r\nThe subselect is not possible with Propel, so we'd have to do this manually.","html_url":"https://github.com/halfer/Meshing/issues/31","title":"Potential race condition when generating version numbers","number":31,"id":2139000,"created_at":"2011-11-03T23:31:15Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/69ab66ba5d78eb9055a09e6cb5a06f57?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"69ab66ba5d78eb9055a09e6cb5a06f57","url":"https://api.github.com/users/halfer","login":"halfer","id":480975},"updated_at":"2011-11-07T23:51:01Z","url":"https://api.github.com/repos/halfer/Meshing/issues/comments/2661803","body":"Fixed in 633a6329b7238073d8e5234840cd365786e5c553 and previous commits.","id":2661803,"created_at":"2011-11-07T23:51:01Z"}}