diff PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 134:cc3dc759c989

Added an advisory lock to avoid race conditions during database setup
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 May 2019 20:21:13 +0200
parents e61587582cef
children 3266785d5627
line wrap: on
line diff
--- a/PostgreSQL/Plugins/PostgreSQLIndex.cpp	Fri Mar 01 12:56:13 2019 +0100
+++ b/PostgreSQL/Plugins/PostgreSQLIndex.cpp	Wed May 08 20:21:13 2019 +0200
@@ -74,6 +74,14 @@
       db->AdvisoryLock(42 /* some arbitrary constant */);
     }
 
+    /**
+     * Try and acquire a transient advisory lock to protect the setup
+     * of the database, because concurrent statements like "CREATE
+     * TABLE" are not protected by transactions.
+     * https://groups.google.com/d/msg/orthanc-users/yV3LSTh_TjI/h3PRApJFBAAJ
+     **/
+    PostgreSQLDatabase::TransientAdvisoryLock lock(*db, 44 /* some arbitrary constant */);
+
     if (clearAll_)
     {
       db->ClearAll();