diff --git a/catalogue/CatalogueFactory.cpp b/catalogue/CatalogueFactory.cpp index 7f16fb1228a589c0d126a1d51bb1cc190eb77fbd..5cceb8b39eb412ede3b2429784ecac86303b03f2 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 d76d19461b68cc181f8ba81d70c9590cf9aa47e7..7c0cae56b3d15e3852be295900318deb5f8dc7de 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 69eeb195103a9fff734d880278768a63f91c97d6..03af6576982ec2b04ea022c2308ba3cb6340659d 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 6605647dcbc0cde497d75e1ff22c2a29f4a04bdc..06376bd981f3843afb3cd46ca91eebbd4533017a 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 51372829814ce52e91bce7ec0f61af8a39b3dca5..24f58e9e0ab47df8a676c100a85c64ba7d2a4156 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 de265fc19b914c9e1e913b53c42b7ce96f0bf583..2b57b7fb858d8f484c43539218401e8d965cf07d 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 e492e78fb9e7146f972d76535482cdc3e4c7d8d0..dd236e42d373c2a62657a325dd3cbe84dc2a291d 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 fe265c3932deb6fb38d00a91ba58f33e23c9b368..790f1bafd3ae0766c4b6319b84f2022af6927f8b 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 b923e49f71facba47e5d335dcf51427718d1487e..6ed110590118180bcbb7efbefccb6ff867891f3c 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 a1d8d966d7f856f39ab7fb123f1deb3026e976ee..db78c06be4dba1f88b040968caa942be48556548 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 fe45504f62be2440f6242c14cf7811fb813c5ad5..743b51e6f5a547e1ab0a6552c0ffaa9712b3e29c 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 ecfe79f902d1a9ae163009af58110aecc9183e5a..e02b2431debb129517ca06f331f48d8cbd95dace 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));