Stale read when creating images
Sentry Issue: ARKINDEX-BACKEND-W0
UniqueViolation: duplicate key value violates unique constraint "images_image_server_id_hash_e1ccd087_uniq"
DETAIL: Key (server_id, hash)=(3, ae4b1f07e16065c81b7681868ba13928) already exists.
File "django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
IntegrityError: duplicate key value violates unique constraint "images_image_server_id_hash_e1ccd087_uniq"
DETAIL: Key (server_id, hash)=(3, ae4b1f07e16065c81b7681868ba13928) already exists.
(23 additional frame(s) were not displayed)
...
File "django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
This issue occurred specifically on CreateImage
, but the same scenario can occur for CreateIIIFURL
and CreateIIIFInformation
: the existing image check does not use the primary database, so a stale read can occur where running the same API request twice could cause an IntegrityError. This was noticed due to some lag of unknown origin on the replica, starting from this weekend.
Edited by Erwan Rouchet