comparison Framework/PostgreSQL/PostgreSQLDatabase.cpp @ 469:302f3c2b1c34

merge pg-transactions -> mainline
author Alain Mazy <am@osimis.io>
date Mon, 05 Feb 2024 09:48:11 +0100
parents f0976163dbe1
children 54d518dcd74a
comparison
equal deleted inserted replaced
464:042416783518 469:302f3c2b1c34
157 } 157 }
158 158
159 159
160 void PostgreSQLDatabase::ExecuteMultiLines(const std::string& sql) 160 void PostgreSQLDatabase::ExecuteMultiLines(const std::string& sql)
161 { 161 {
162 LOG(TRACE) << "PostgreSQL: " << sql; 162 if (IsVerboseEnabled())
163 {
164 LOG(INFO) << "PostgreSQL: " << sql;
165 }
163 Open(); 166 Open();
164 167
165 PGresult* result = PQexec(reinterpret_cast<PGconn*>(pg_), sql.c_str()); 168 PGresult* result = PQexec(reinterpret_cast<PGconn*>(pg_), sql.c_str());
166 if (result == NULL) 169 if (result == NULL)
167 { 170 {
316 } 319 }
317 320
318 321
319 PostgreSQLDatabase::TransientAdvisoryLock::TransientAdvisoryLock( 322 PostgreSQLDatabase::TransientAdvisoryLock::TransientAdvisoryLock(
320 PostgreSQLDatabase& database, 323 PostgreSQLDatabase& database,
321 int32_t lock) : 324 int32_t lock,
325 unsigned int retries,
326 unsigned int retryInterval) :
322 database_(database), 327 database_(database),
323 lock_(lock) 328 lock_(lock)
324 { 329 {
325 bool locked = true; 330 bool locked = true;
326 331
327 for (unsigned int i = 0; i < 10; i++) 332 for (unsigned int i = 0; i < retries; i++)
328 { 333 {
329 if (database_.AcquireAdvisoryLock(lock_)) 334 if (database_.AcquireAdvisoryLock(lock_))
330 { 335 {
331 locked = false; 336 locked = false;
332 break; 337 break;
333 } 338 }
334 else 339 else
335 { 340 {
336 boost::this_thread::sleep(boost::posix_time::milliseconds(500)); 341 boost::this_thread::sleep(boost::posix_time::milliseconds(retryInterval));
337 } 342 }
338 } 343 }
339 344
340 if (locked) 345 if (locked)
341 { 346 {