annotate Framework/PostgreSQL/PostgreSQLDatabase.cpp @ 135:e26690365c25

MySQL: Added an advisory lock to avoid race conditions during database setup
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 May 2019 21:09:18 +0200
parents cc3dc759c989
children 4cd7e45b671e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
67
714c5d2bee76 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
107
5765cc5fd268 reverted fix for OS X that breaks other targets
Sebastien Jodogne <s.jodogne@orthanc-labs.com>
parents: 105
diff changeset
22 #include "PostgreSQLIncludes.h" // Must be the first
105
eefbcee7bd78 fix build on OS X
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 103
diff changeset
23 #include "PostgreSQLDatabase.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "PostgreSQLResult.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "PostgreSQLStatement.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "PostgreSQLTransaction.h"
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
28 #include "../Common/ImplicitTransaction.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <Core/Logging.h>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <Core/OrthancException.h>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <boost/lexical_cast.hpp>
134
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
34 #include <boost/thread.hpp>
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 namespace OrthancDatabases
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 void PostgreSQLDatabase::ThrowException(bool log)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 if (log)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 LOG(ERROR) << "PostgreSQL error: "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 << PQerrorMessage(reinterpret_cast<PGconn*>(pg_));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 if (PQstatus(reinterpret_cast<PGconn*>(pg_)) == CONNECTION_OK)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 void PostgreSQLDatabase::Close()
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if (pg_ != NULL)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 LOG(INFO) << "Closing connection to PostgreSQL";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 PQfinish(reinterpret_cast<PGconn*>(pg_));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 pg_ = NULL;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
46
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
68
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
69 PostgreSQLDatabase::~PostgreSQLDatabase()
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
70 {
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
71 try
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
72 {
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
73 Close();
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
74 }
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
75 catch (Orthanc::OrthancException&)
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
76 {
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
77 // Ignore possible exceptions due to connection loss
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
78 }
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
79 }
6a574d810b98 Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 29
diff changeset
80
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 void PostgreSQLDatabase::Open()
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 if (pg_ != NULL)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 // Already connected
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 return;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 std::string s;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 parameters_.Format(s);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 pg_ = PQconnectdb(s.c_str());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 if (pg_ == NULL ||
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 PQstatus(reinterpret_cast<PGconn*>(pg_)) != CONNECTION_OK)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 std::string message;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 if (pg_)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 message = PQerrorMessage(reinterpret_cast<PGconn*>(pg_));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 PQfinish(reinterpret_cast<PGconn*>(pg_));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 pg_ = NULL;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 LOG(ERROR) << "PostgreSQL error: " << message;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
12
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
110 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
134
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
113 bool PostgreSQLDatabase::RunAdvisoryLockStatement(const std::string& statement)
12
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
114 {
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
115 PostgreSQLTransaction transaction(*this);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
134
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
117 Query query(statement, false);
29
2fb9cd42af14 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
118 PostgreSQLStatement s(*this, query);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
12
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
120 PostgreSQLResult result(s);
134
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
121
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
122 bool success = (!result.IsDone() &&
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
123 result.GetBoolean(0));
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
124
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
125 transaction.Commit();
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
126
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
127 return success;
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
128 }
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
129
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
130
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
131 bool PostgreSQLDatabase::AcquireAdvisoryLock(int32_t lock)
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
132 {
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
133 return RunAdvisoryLockStatement(
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
134 "select pg_try_advisory_lock(" +
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
135 boost::lexical_cast<std::string>(lock) + ")");
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
136 }
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
137
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
138
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
139 bool PostgreSQLDatabase::ReleaseAdvisoryLock(int32_t lock)
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
140 {
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
141 return RunAdvisoryLockStatement(
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
142 "select pg_advisory_unlock(" +
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
143 boost::lexical_cast<std::string>(lock) + ")");
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
144 }
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
145
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
146
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
147 void PostgreSQLDatabase::AdvisoryLock(int32_t lock)
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
148 {
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
149 if (!AcquireAdvisoryLock(lock))
12
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
150 {
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
151 LOG(ERROR) << "The PostgreSQL database is locked by another instance of Orthanc";
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
152 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
153 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 void PostgreSQLDatabase::Execute(const std::string& sql)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 LOG(TRACE) << "PostgreSQL: " << sql;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 Open();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 PGresult* result = PQexec(reinterpret_cast<PGconn*>(pg_), sql.c_str());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 if (result == NULL)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 ThrowException(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 bool ok = (PQresultStatus(result) == PGRES_COMMAND_OK ||
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 PQresultStatus(result) == PGRES_TUPLES_OK);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 if (ok)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 PQclear(result);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 std::string message = PQresultErrorMessage(result);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 PQclear(result);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 LOG(ERROR) << "PostgreSQL error: " << message;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 ThrowException(false);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 bool PostgreSQLDatabase::DoesTableExist(const char* name)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 std::string lower(name);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 std::transform(lower.begin(), lower.end(), lower.begin(), tolower);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 // http://stackoverflow.com/a/24089729/881731
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 PostgreSQLStatement statement(*this,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 "SELECT 1 FROM pg_catalog.pg_class c "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 "JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 "WHERE n.nspname = 'public' AND c.relkind='r' "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 "AND c.relname=$1", true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 statement.DeclareInputString(0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 statement.BindString(0, lower);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 PostgreSQLResult result(statement);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 return !result.IsDone();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 void PostgreSQLDatabase::ClearAll()
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 PostgreSQLTransaction transaction(*this);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 // Remove all the large objects
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 Execute("SELECT lo_unlink(loid) FROM (SELECT DISTINCT loid FROM pg_catalog.pg_largeobject) as loids;");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 // http://stackoverflow.com/a/21247009/881731
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 Execute("DROP SCHEMA public CASCADE;");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 Execute("CREATE SCHEMA public;");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 Execute("GRANT ALL ON SCHEMA public TO postgres;");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 Execute("GRANT ALL ON SCHEMA public TO public;");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 Execute("COMMENT ON SCHEMA public IS 'standard public schema';");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 transaction.Commit();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 IPrecompiledStatement* PostgreSQLDatabase::Compile(const Query& query)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 return new PostgreSQLStatement(*this, query);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
231 namespace
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 {
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
233 class PostgreSQLImplicitTransaction : public ImplicitTransaction
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
234 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
235 private:
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
236 PostgreSQLDatabase& db_;
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
237
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
238 protected:
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
239 virtual IResult* ExecuteInternal(IPrecompiledStatement& statement,
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
240 const Dictionary& parameters)
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
241 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
242 return dynamic_cast<PostgreSQLStatement&>(statement).Execute(*this, parameters);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
243 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
244
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
245 virtual void ExecuteWithoutResultInternal(IPrecompiledStatement& statement,
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
246 const Dictionary& parameters)
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
247 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
248 dynamic_cast<PostgreSQLStatement&>(statement).ExecuteWithoutResult(*this, parameters);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
249 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
250
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
251 public:
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
252 PostgreSQLImplicitTransaction(PostgreSQLDatabase& db) :
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
253 db_(db)
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
254 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
255 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
256 };
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
257 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
258
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
259
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
260 ITransaction* PostgreSQLDatabase::CreateTransaction(bool isImplicit)
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
261 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
262 if (isImplicit)
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
263 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
264 return new PostgreSQLImplicitTransaction(*this);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
265 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
266 else
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
267 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
268 return new PostgreSQLTransaction(*this);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 12
diff changeset
269 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
134
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
271
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
272
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
273 PostgreSQLDatabase::TransientAdvisoryLock::TransientAdvisoryLock(
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
274 PostgreSQLDatabase& database,
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
275 int32_t lock) :
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
276 database_(database),
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
277 lock_(lock)
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
278 {
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
279 bool locked = true;
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
280
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
281 for (unsigned int i = 0; i < 10; i++)
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
282 {
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
283 if (database_.AcquireAdvisoryLock(lock_))
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
284 {
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
285 locked = false;
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
286 break;
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
287 }
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
288 else
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
289 {
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
290 boost::this_thread::sleep(boost::posix_time::milliseconds(500));
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
291 }
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
292 }
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
293
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
294 if (locked)
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
295 {
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
296 LOG(ERROR) << "Cannot acquire a transient advisory lock";
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
297 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin);
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
298 }
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
299 }
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
300
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
301
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
302 PostgreSQLDatabase::TransientAdvisoryLock::~TransientAdvisoryLock()
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
303 {
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
304 database_.ReleaseAdvisoryLock(lock_);
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
305 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 }