Inconsistency in model field with file storage on Amazon S3
Hi all,
-- I am running a fairly good scale production system in Django, where we receive requests in order of 100 to 1000 per second. We are using s3boto backend for file storage. All the files are saved in a single bucket on S3. When the request for number of files to be saved increases, database inconsistencies start coming up which are hard to explain. The file is saved in S3, but not saved in the model's FileField.
This is the related configuration in my settings file:
DEFAULT_FILE_STORAGE = 'lib.s3utils.MediaRootS3BotoStorage'
# cat lib/s3utils.py
from storages.backends.s3boto import S3BotoStorage
MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media')
Let's take an example Model.
class FileModel(models.Model):
s3_file = models.FileField(upload_to=get_file_path, max_length=512)
The s3_file is being saved in a way as following:
fileModel_instance.s3_file.save(filename, ContentFile(source), save=True)
Now, this is directly from the django documentation:
This method takes a filename and file contents and passes them to the storage class for the field, then associates the stored file with the model field.
But with fairly good number of requests, it happens sometimes that the stored file is not associated with the model field. The file is saved in S3 bucket, but the model field remains null. I suspect one the reason could be that s3boto has built-in connection pooling which defers the file save on underlying storage and hence the model field remains null. But again that should not happen.
Has anyone faced similar issue? Or I am doing something fundamentally wrong? Any suggestion and help is highly appreciated.
Thanks,
Vivek
Vivek Prakash | HackerEarth | Co-Founder | vivek@hackerearth.com | Follow us on twitter: @HackerEarth | http://engineering.hackerearth.com | http://blog.hackerearth.com
'Like us': http://www.facebook.com/HackerEarthYou received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAENtUgqwVTL-vOeYst6ZY1tXB94ks2KuQUrOs8eHpeTnwUxKTg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home