From 1009c498e2827e5d1b059d8dff47f68f2bed0b21 Mon Sep 17 00:00:00 2001 From: Harrison Feng Date: Thu, 29 Jan 2015 16:38:56 +0800 Subject: [PATCH 1/2] fix registry._setup_database.lock remove issue It will try to remove non-existing registry._setup_database.lock when search_backend setting to sqlalchemy Signed-off-by: Harrison Feng --- docker_registry/toolkit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker_registry/toolkit.py b/docker_registry/toolkit.py index 5a35c88a7..78b36eaad 100644 --- a/docker_registry/toolkit.py +++ b/docker_registry/toolkit.py @@ -327,7 +327,8 @@ def wrapper(*args, **kwargs): try: result = f(*args, **kwargs) finally: - os.remove(lock_path) + if os.path.exists(lock_path): + os.remove(lock_path) return result return wrapper From 0f085f3d3f38661f8a7a9c3733baecf6ed0b4831 Mon Sep 17 00:00:00 2001 From: Harrison Feng Date: Thu, 29 Jan 2015 17:07:32 +0800 Subject: [PATCH 2/2] rollback the session after UNIQUE constraint failed exception Here is the error message: InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (IntegrityError) UNIQUE constraint failed: version.id u'INSERT INTO version (id) VALUES (?)' (1,) Signed-off-by: Harrison Feng --- docker_registry/lib/index/db.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docker_registry/lib/index/db.py b/docker_registry/lib/index/db.py index e9d4c68d2..9e1607364 100644 --- a/docker_registry/lib/index/db.py +++ b/docker_registry/lib/index/db.py @@ -113,7 +113,11 @@ def _generate_index(self, session): session.add(Version(id=self.version)) for repository in self._walk_storage(store=store): session.add(Repository(**repository)) - session.commit() + try: + session.commit() + except Exception as e: + logger.exception(str(e)) + session.rollback() @retry def _handle_repository_created(