Commits

Oleksiy Pikalo  committed 1ca9ece

When large fixtures (~30000) are installed upon deployment, appengine occasionally dies with "ApplicationError: ApplicationError: 2 too much contention on these datastore entities. please try again." The solution seems to be to retry Entry.Put until the problem is solved. This patch introduces MAX_PUT_RETRIES in db_settings and tries that many times before giving up. A value of 100 did the trick.

  • Participants
  • Parent commits 605cf90

Comments (0)

Files changed (2)

File db/compiler.py

-from .db_settings import get_model_indexes
+from .db_settings import get_model_indexes, MAX_PUT_RETRIES
 
 import datetime
 import sys
 
         entity = Entity(self.query.get_meta().db_table, **kwds)
         entity.update(gae_data)
-        key = Put(entity)
+
+        key = None
+        attempt = 0
+        while key is None:
+            try:
+                key = Put(entity)
+            except:
+                attempt += 1
+                if attempt > MAX_PUT_RETRIES:
+                    raise
+
+                pass
+
         return key.id_or_name()
 
 class SQLUpdateCompiler(NonrelUpdateCompiler, SQLCompiler):

File db/db_settings.py

 
 FIELD_INDEXES = None
 
+MAX_PUT_RETRIES = 100
+
 # TODO: add support for eventual consistency setting on specific models
 
 def get_model_indexes(model):