From d272da768c82fa5807183069aeff1584f88fb3bb Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Wed, 31 Jan 2018 08:37:47 +0100 Subject: [PATCH] cta/CTA#186 CTA should cope with idle database connections being dropped by the database server Moved maxTriesToConnect parameter to CatalogueFactory::create(). --- catalogue/CatalogueFactory.cpp | 10 ++++++---- catalogue/CatalogueFactory.hpp | 6 +++++- catalogue/InMemoryCatalogue.cpp | 6 ++++-- catalogue/InMemoryCatalogue.hpp | 6 +++++- catalogue/InMemoryCatalogueTest.cpp | 5 +++-- catalogue/RdbmsCatalogue.hpp | 2 +- catalogue/SchemaCreatingSqliteCatalogue.cpp | 5 +++-- catalogue/SchemaCreatingSqliteCatalogue.hpp | 6 +++++- catalogue/SqliteCatalogue.cpp | 6 ++++-- catalogue/SqliteCatalogue.hpp | 6 +++++- scheduler/SchedulerTest.cpp | 4 +++- .../tape/tapeserver/daemon/DataTransferSessionTest.cpp | 4 +++- 12 files changed, 47 insertions(+), 19 deletions(-) diff --git a/catalogue/CatalogueFactory.cpp b/catalogue/CatalogueFactory.cpp index 7f16fb1228..5cceb8b39e 100644 --- a/catalogue/CatalogueFactory.cpp +++ b/catalogue/CatalogueFactory.cpp @@ -33,16 +33,18 @@ std::unique_ptr<Catalogue> CatalogueFactory::create( log::Logger &log, const rdbms::Login &login, const uint64_t nbConns, - const uint64_t nbArchiveFileListingConns) { + const uint64_t nbArchiveFileListingConns, + const uint32_t maxTriesToConnect) { try { switch(login.dbType) { case rdbms::Login::DBTYPE_IN_MEMORY: - return cta::make_unique<InMemoryCatalogue>(log, nbConns, nbArchiveFileListingConns); + return cta::make_unique<InMemoryCatalogue>(log, nbConns, nbArchiveFileListingConns, maxTriesToConnect); case rdbms::Login::DBTYPE_ORACLE: return cta::make_unique<OracleCatalogue>(log, login.username, login.password, login.database, nbConns, - nbArchiveFileListingConns); + nbArchiveFileListingConns, maxTriesToConnect); case rdbms::Login::DBTYPE_SQLITE: - return cta::make_unique<SqliteCatalogue>(log, login.database, nbConns, nbArchiveFileListingConns); + return cta::make_unique<SqliteCatalogue>(log, login.database, nbConns, nbArchiveFileListingConns, + maxTriesToConnect); case rdbms::Login::DBTYPE_NONE: throw exception::Exception("Cannot create a catalogue without a database type"); default: diff --git a/catalogue/CatalogueFactory.hpp b/catalogue/CatalogueFactory.hpp index d76d19461b..7c0cae56b3 100644 --- a/catalogue/CatalogueFactory.hpp +++ b/catalogue/CatalogueFactory.hpp @@ -51,12 +51,16 @@ public: * listing archive files. * @return The newly created CTA catalogue object. Please note that it is the * responsibility of the caller to delete the returned CTA catalogue object. + * @param maxTriesToConnext The maximum number of times a single method should + * try to connect to the database in the event of LostDatabaseConnection + * exceptions being thrown. */ static std::unique_ptr<Catalogue> create( log::Logger &log, const rdbms::Login &login, const uint64_t nbConns, - const uint64_t nbArchiveFileListingConns); + const uint64_t nbArchiveFileListingConns, + const uint32_t maxTriesToConnect = 3); }; // class CatalogueFactory diff --git a/catalogue/InMemoryCatalogue.cpp b/catalogue/InMemoryCatalogue.cpp index 69eeb19510..03af657698 100644 --- a/catalogue/InMemoryCatalogue.cpp +++ b/catalogue/InMemoryCatalogue.cpp @@ -27,8 +27,10 @@ namespace catalogue { InMemoryCatalogue::InMemoryCatalogue( log::Logger &log, const uint64_t nbConns, - const uint64_t nbArchiveFileListingConns): - SchemaCreatingSqliteCatalogue(log, "file::memory:?cache=shared", nbConns, nbArchiveFileListingConns) { + const uint64_t nbArchiveFileListingConns, + const uint32_t maxTriesToConnect): + SchemaCreatingSqliteCatalogue(log, "file::memory:?cache=shared", nbConns, nbArchiveFileListingConns, + maxTriesToConnect) { } //------------------------------------------------------------------------------ diff --git a/catalogue/InMemoryCatalogue.hpp b/catalogue/InMemoryCatalogue.hpp index 6605647dcb..06376bd981 100644 --- a/catalogue/InMemoryCatalogue.hpp +++ b/catalogue/InMemoryCatalogue.hpp @@ -41,11 +41,15 @@ public: * @param nbArchiveFileListingConns The maximum number of concurrent * connections to the underlying relational database for the sole purpose of * listing archive files. + * @param maxTriesToConnext The maximum number of times a single method should + * try to connect to the database in the event of LostDatabaseConnection + * exceptions being thrown. */ InMemoryCatalogue( log::Logger &log, const uint64_t nbConns, - const uint64_t nbArchiveFileListingConns); + const uint64_t nbArchiveFileListingConns, + const uint32_t maxTriesToConnect); /** * Destructor. diff --git a/catalogue/InMemoryCatalogueTest.cpp b/catalogue/InMemoryCatalogueTest.cpp index 5137282981..24f58e9e0a 100644 --- a/catalogue/InMemoryCatalogueTest.cpp +++ b/catalogue/InMemoryCatalogueTest.cpp @@ -39,15 +39,16 @@ TEST_F(cta_catalogue_InMemoryCatalogue, createSameSchemaInTwoSeparateInMemoryDat log::DummyLogger dummyLog("dummy"); const uint64_t nbConns = 1; const uint64_t nbArchiveFileListingConns = 0; + const uint32_t maxTriesToConnect = 1; // First in-memory database { - catalogue::InMemoryCatalogue inMemoryCatalogue(dummyLog, nbConns, nbArchiveFileListingConns); + catalogue::InMemoryCatalogue inMemoryCatalogue(dummyLog, nbConns, nbArchiveFileListingConns, maxTriesToConnect); } // Second in-memory database { - catalogue::InMemoryCatalogue inMemoryCatalogue(dummyLog, nbConns, nbArchiveFileListingConns); + catalogue::InMemoryCatalogue inMemoryCatalogue(dummyLog, nbConns, nbArchiveFileListingConns, maxTriesToConnect); } } diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index de265fc19b..2b57b7fb85 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -79,7 +79,7 @@ protected: const rdbms::Login &login, const uint64_t nbConns, const uint64_t nbArchiveFileListingConns, - const uint32_t maxTriesToConnect = 3); + const uint32_t maxTriesToConnect); public: diff --git a/catalogue/SchemaCreatingSqliteCatalogue.cpp b/catalogue/SchemaCreatingSqliteCatalogue.cpp index e492e78fb9..dd236e42d3 100644 --- a/catalogue/SchemaCreatingSqliteCatalogue.cpp +++ b/catalogue/SchemaCreatingSqliteCatalogue.cpp @@ -29,8 +29,9 @@ SchemaCreatingSqliteCatalogue::SchemaCreatingSqliteCatalogue( log::Logger &log, const std::string &filename, const uint64_t nbConns, - const uint64_t nbArchiveFileListingConns): - SqliteCatalogue(log, filename, nbConns, nbArchiveFileListingConns) { + const uint64_t nbArchiveFileListingConns, + const uint32_t maxTriesToConnect): + SqliteCatalogue(log, filename, nbConns, nbArchiveFileListingConns, maxTriesToConnect) { try { createCatalogueSchema(); } catch(exception::Exception &ex) { diff --git a/catalogue/SchemaCreatingSqliteCatalogue.hpp b/catalogue/SchemaCreatingSqliteCatalogue.hpp index fe265c3932..790f1bafd3 100644 --- a/catalogue/SchemaCreatingSqliteCatalogue.hpp +++ b/catalogue/SchemaCreatingSqliteCatalogue.hpp @@ -42,12 +42,16 @@ public: * @param nbArchiveFileListingConns The maximum number of concurrent * connections to the underlying relational database for the sole purpose of * listing archive files. + * @param maxTriesToConnext The maximum number of times a single method should + * try to connect to the database in the event of LostDatabaseConnection + * exceptions being thrown. */ SchemaCreatingSqliteCatalogue( log::Logger &log, const std::string &filename, const uint64_t nbConns, - const uint64_t nbArchiveFileListingConns); + const uint64_t nbArchiveFileListingConns, + const uint32_t maxTriesToConnect); /** * Destructor. diff --git a/catalogue/SqliteCatalogue.cpp b/catalogue/SqliteCatalogue.cpp index b923e49f71..6ed1105901 100644 --- a/catalogue/SqliteCatalogue.cpp +++ b/catalogue/SqliteCatalogue.cpp @@ -37,12 +37,14 @@ SqliteCatalogue::SqliteCatalogue( log::Logger &log, const std::string &filename, const uint64_t nbConns, - const uint64_t nbArchiveFileListingConns): + const uint64_t nbArchiveFileListingConns, + const uint32_t maxTriesToConnect): RdbmsCatalogue( log, rdbms::Login(rdbms::Login::DBTYPE_SQLITE, "", "", filename), nbConns, - nbArchiveFileListingConns) { + nbArchiveFileListingConns, + maxTriesToConnect) { } //------------------------------------------------------------------------------ diff --git a/catalogue/SqliteCatalogue.hpp b/catalogue/SqliteCatalogue.hpp index a1d8d966d7..db78c06be4 100644 --- a/catalogue/SqliteCatalogue.hpp +++ b/catalogue/SqliteCatalogue.hpp @@ -42,12 +42,16 @@ public: * @param nbArchiveFileListingConns The maximum number of concurrent * connections to the underlying relational database for the sole purpose of * listing archive files. + * @param maxTriesToConnext The maximum number of times a single method should + * try to connect to the database in the event of LostDatabaseConnection + * exceptions being thrown. */ SqliteCatalogue( log::Logger &log, const std::string &filename, const uint64_t nbConns, - const uint64_t nbArchiveFileListingConns); + const uint64_t nbArchiveFileListingConns, + const uint32_t maxTriesToConnect); public: diff --git a/scheduler/SchedulerTest.cpp b/scheduler/SchedulerTest.cpp index fe45504f62..743b51e6f5 100644 --- a/scheduler/SchedulerTest.cpp +++ b/scheduler/SchedulerTest.cpp @@ -101,8 +101,10 @@ public: m_db = param.dbFactory.create(); const uint64_t nbConns = 1; const uint64_t nbArchiveFileListingConns = 1; + const uint32_t maxTriesToConnect = 1; //m_catalogue = cta::make_unique<catalogue::SchemaCreatingSqliteCatalogue>(m_tempSqliteFile.path(), nbConns); - m_catalogue = cta::make_unique<catalogue::InMemoryCatalogue>(m_dummyLog, nbConns, nbArchiveFileListingConns); + m_catalogue = cta::make_unique<catalogue::InMemoryCatalogue>(m_dummyLog, nbConns, nbArchiveFileListingConns, + maxTriesToConnect); m_scheduler = cta::make_unique<Scheduler>(*m_catalogue, *m_db, 5, 2*1000*1000); } diff --git a/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp b/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp index ecfe79f902..e02b2431de 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/DataTransferSessionTest.cpp @@ -118,8 +118,10 @@ public: m_db = param.dbFactory.create(); const uint64_t nbConns = 1; const uint64_t nbArchiveFileListingConns = 1; + const uint32_t maxTriesToConnect = 1; //m_catalogue = cta::make_unique<catalogue::SchemaCreatingSqliteCatalogue>(m_tempSqliteFile.path(), nbConns); - m_catalogue = cta::make_unique<catalogue::InMemoryCatalogue>(m_dummyLog, nbConns, nbArchiveFileListingConns); + m_catalogue = cta::make_unique<catalogue::InMemoryCatalogue>(m_dummyLog, nbConns, nbArchiveFileListingConns, + maxTriesToConnect); m_scheduler = cta::make_unique<Scheduler>(*m_catalogue, *m_db, 5, 2*1000*1000); strncpy(m_tmpDir, "/tmp/DataTransferSessionTestXXXXXX", sizeof(m_tmpDir)); -- GitLab