# HG changeset patch # User Alain Mazy # Date 1580765391 -3600 # Node ID 0b3e9ee53c46b8996c7152a9289890b23e0bae41 # Parent 4cd7e45b671e4f3d7153fe44132af50807f695e2 Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup diff -r 4cd7e45b671e -r 0b3e9ee53c46 Framework/Common/DatabaseManager.cpp --- a/Framework/Common/DatabaseManager.cpp Fri Jan 31 17:24:29 2020 +0100 +++ b/Framework/Common/DatabaseManager.cpp Mon Feb 03 22:29:51 2020 +0100 @@ -32,9 +32,11 @@ { IDatabase& DatabaseManager::GetDatabase() { - static const unsigned int MAX_CONNECTION_ATTEMPTS = 10; // TODO: Parameter + unsigned int maxConnectionRetries = 10; + unsigned int connectionRetryInterval = 5; + unsigned int count = 0; - unsigned int count = 0; + factory_->GetConnectionRetriesParameters(maxConnectionRetries, connectionRetryInterval); while (database_.get() == NULL) { @@ -50,10 +52,10 @@ { count ++; - if (count <= MAX_CONNECTION_ATTEMPTS) + if (count <= maxConnectionRetries) { LOG(WARNING) << "Database is currently unavailable, retrying..."; - boost::this_thread::sleep(boost::posix_time::seconds(1)); + boost::this_thread::sleep(boost::posix_time::seconds(connectionRetryInterval)); continue; } else diff -r 4cd7e45b671e -r 0b3e9ee53c46 Framework/Common/IDatabaseFactory.h --- a/Framework/Common/IDatabaseFactory.h Fri Jan 31 17:24:29 2020 +0100 +++ b/Framework/Common/IDatabaseFactory.h Mon Feb 03 22:29:51 2020 +0100 @@ -35,5 +35,7 @@ virtual Dialect GetDialect() const = 0; virtual IDatabase* Open() = 0; + + virtual void GetConnectionRetriesParameters(unsigned int& maxConnectionRetries, unsigned int& connectionRetryInterval) = 0; }; } diff -r 4cd7e45b671e -r 0b3e9ee53c46 Framework/MySQL/MySQLParameters.cpp --- a/Framework/MySQL/MySQLParameters.cpp Fri Jan 31 17:24:29 2020 +0100 +++ b/Framework/MySQL/MySQLParameters.cpp Mon Feb 03 22:29:51 2020 +0100 @@ -89,6 +89,9 @@ } lock_ = configuration.GetBooleanValue("Lock", true); // Use locking by default + + maxConnectionRetries_ = configuration.GetUnsignedIntegerValue("MaximumConnectionRetries", 10); + connectionRetryInterval_ = configuration.GetUnsignedIntegerValue("ConnectionRetryInterval", 5); } diff -r 4cd7e45b671e -r 0b3e9ee53c46 Framework/MySQL/MySQLParameters.h --- a/Framework/MySQL/MySQLParameters.h Fri Jan 31 17:24:29 2020 +0100 +++ b/Framework/MySQL/MySQLParameters.h Mon Feb 03 22:29:51 2020 +0100 @@ -39,6 +39,8 @@ uint16_t port_; std::string unixSocket_; bool lock_; + unsigned int maxConnectionRetries_; + unsigned int connectionRetryInterval_; void Reset(); @@ -99,6 +101,16 @@ return lock_; } + unsigned int GetMaxConnectionRetries() const + { + return maxConnectionRetries_; + } + + unsigned int GetConnectionRetryInterval() const + { + return connectionRetryInterval_; + } + void Format(Json::Value& target) const; }; } diff -r 4cd7e45b671e -r 0b3e9ee53c46 Framework/PostgreSQL/PostgreSQLParameters.cpp --- a/Framework/PostgreSQL/PostgreSQLParameters.cpp Fri Jan 31 17:24:29 2020 +0100 +++ b/Framework/PostgreSQL/PostgreSQLParameters.cpp Mon Feb 03 22:29:51 2020 +0100 @@ -39,6 +39,8 @@ uri_.clear(); ssl_ = false; lock_ = true; + maxConnectionRetries_ = 10; + connectionRetryInterval_ = 5; } @@ -90,6 +92,9 @@ } lock_ = configuration.GetBooleanValue("Lock", true); // Use locking by default + + maxConnectionRetries_ = configuration.GetUnsignedIntegerValue("MaximumConnectionRetries", 10); + connectionRetryInterval_ = configuration.GetUnsignedIntegerValue("ConnectionRetryInterval", 5); } diff -r 4cd7e45b671e -r 0b3e9ee53c46 Framework/PostgreSQL/PostgreSQLParameters.h --- a/Framework/PostgreSQL/PostgreSQLParameters.h Fri Jan 31 17:24:29 2020 +0100 +++ b/Framework/PostgreSQL/PostgreSQLParameters.h Mon Feb 03 22:29:51 2020 +0100 @@ -40,6 +40,8 @@ std::string uri_; bool ssl_; bool lock_; + unsigned int maxConnectionRetries_; + unsigned int connectionRetryInterval_; void Reset(); @@ -112,6 +114,16 @@ return lock_; } + unsigned int GetMaxConnectionRetries() const + { + return maxConnectionRetries_; + } + + unsigned int GetConnectionRetryInterval() const + { + return connectionRetryInterval_; + } + void Format(std::string& target) const; }; } diff -r 4cd7e45b671e -r 0b3e9ee53c46 MySQL/NEWS --- a/MySQL/NEWS Fri Jan 31 17:24:29 2020 +0100 +++ b/MySQL/NEWS Mon Feb 03 22:29:51 2020 +0100 @@ -3,6 +3,8 @@ * Implementation of new extensions: LookupResourceAndParent and GetAllMetadata * Added an advisory lock to avoid race conditions during database setup +* Added "MaximumConnectionRetries" & "ConnectionRetryInterval" to configure + the retries when connecting to the DB at startup Release 2.0 (2019-01-23) diff -r 4cd7e45b671e -r 0b3e9ee53c46 MySQL/Plugins/MySQLIndex.h --- a/MySQL/Plugins/MySQLIndex.h Fri Jan 31 17:24:29 2020 +0100 +++ b/MySQL/Plugins/MySQLIndex.h Mon Feb 03 22:29:51 2020 +0100 @@ -49,6 +49,12 @@ { return that_.OpenInternal(); } + + virtual void GetConnectionRetriesParameters(unsigned int& maxConnectionRetries, unsigned int& connectionRetryInterval) + { + maxConnectionRetries = that_.parameters_.GetMaxConnectionRetries(); + connectionRetryInterval = that_.parameters_.GetConnectionRetryInterval(); + } }; OrthancPluginContext* context_; diff -r 4cd7e45b671e -r 0b3e9ee53c46 MySQL/Plugins/MySQLStorageArea.h --- a/MySQL/Plugins/MySQLStorageArea.h Fri Jan 31 17:24:29 2020 +0100 +++ b/MySQL/Plugins/MySQLStorageArea.h Mon Feb 03 22:29:51 2020 +0100 @@ -50,6 +50,12 @@ { return that_.OpenInternal(); } + + virtual void GetConnectionRetriesParameters(unsigned int& maxConnectionRetries, unsigned int& connectionRetryInterval) + { + maxConnectionRetries = that_.parameters_.GetMaxConnectionRetries(); + connectionRetryInterval = that_.parameters_.GetConnectionRetryInterval(); + } }; OrthancPluginContext* context_; diff -r 4cd7e45b671e -r 0b3e9ee53c46 PostgreSQL/NEWS --- a/PostgreSQL/NEWS Fri Jan 31 17:24:29 2020 +0100 +++ b/PostgreSQL/NEWS Mon Feb 03 22:29:51 2020 +0100 @@ -2,6 +2,8 @@ =============================== * Added an advisory lock to avoid race conditions during database setup +* Added "MaximumConnectionRetries" & "ConnectionRetryInterval" to configure + the retries when connecting to the DB at startup Release 3.2 (2019-03-01) diff -r 4cd7e45b671e -r 0b3e9ee53c46 PostgreSQL/Plugins/PostgreSQLIndex.h --- a/PostgreSQL/Plugins/PostgreSQLIndex.h Fri Jan 31 17:24:29 2020 +0100 +++ b/PostgreSQL/Plugins/PostgreSQLIndex.h Mon Feb 03 22:29:51 2020 +0100 @@ -49,6 +49,12 @@ { return that_.OpenInternal(); } + + virtual void GetConnectionRetriesParameters(unsigned int& maxConnectionRetries, unsigned int& connectionRetryInterval) + { + maxConnectionRetries = that_.parameters_.GetMaxConnectionRetries(); + connectionRetryInterval = that_.parameters_.GetConnectionRetryInterval(); + } }; OrthancPluginContext* context_; diff -r 4cd7e45b671e -r 0b3e9ee53c46 PostgreSQL/Plugins/PostgreSQLStorageArea.h --- a/PostgreSQL/Plugins/PostgreSQLStorageArea.h Fri Jan 31 17:24:29 2020 +0100 +++ b/PostgreSQL/Plugins/PostgreSQLStorageArea.h Mon Feb 03 22:29:51 2020 +0100 @@ -49,6 +49,12 @@ { return that_.OpenInternal(); } + + virtual void GetConnectionRetriesParameters(unsigned int& maxConnectionRetries, unsigned int& connectionRetryInterval) + { + maxConnectionRetries = that_.parameters_.GetMaxConnectionRetries(); + connectionRetryInterval = that_.parameters_.GetConnectionRetryInterval(); + } }; OrthancPluginContext* context_;