Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UUID race conditions #2818

Merged

Conversation

jamalex
Copy link
Member

@jamalex jamalex commented Dec 19, 2014

Previously, the default get_uuid method calculated the uuid as a function of the device ID and the counter position, but as the function for incrementing/retrieving the counter wasn't properly atomic, this led in some cases to duplicate model ids (and hence likely a couple instances of data loss 😿).

This PR does two things:

  • Makes the default uuid generation get_uuid method be random (uuid4), rather than being based on the counter.
  • Makes the counter incrementing more atomic, to avoid race conditions (seems quite robust, from testing, especially compared to the old one).

@jamalex jamalex added the has PR label Dec 19, 2014
return self.devicemetadata
except DeviceMetadata.DoesNotExist:
return DeviceMetadata(device=self)
return DeviceMetadata.objects.get_or_create(device=self)[0]

This comment was marked as spam.

@jamalex jamalex added this to the 0.12.x milestone Dec 19, 2014
@@ -388,16 +388,24 @@ def save(self, imported=False, increment_counters=True, sign=True, *args, **kwar
def set_id(self):
self.id = self.id or self.get_uuid()

# def get_uuid(self):

This comment was marked as spam.

This comment was marked as spam.

@aronasorman
Copy link
Collaborator

Just one cleanup, then wait for the tests to pass.

@aronasorman
Copy link
Collaborator

Will fix assertion error on the 0.12 branch.

aronasorman added a commit that referenced this pull request Dec 20, 2014
@aronasorman aronasorman merged commit 9efbf1a into learningequality:release-0.12.0 Dec 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants