From 00741cab3d8879398b0f72a55dd4314c47c284e0 Mon Sep 17 00:00:00 2001 From: Frank Winklmeier Date: Fri, 18 Oct 2019 14:07:46 +0200 Subject: [PATCH 1/2] RDBAccessSvc: Change name of friend class Change the name of the trigger-specific friend class from psc::Psc to TrigRDBManager. --- Database/RDBAccessSvc/RDBAccessSvc/IRDBAccessSvc.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Database/RDBAccessSvc/RDBAccessSvc/IRDBAccessSvc.h b/Database/RDBAccessSvc/RDBAccessSvc/IRDBAccessSvc.h index 548d3df2ba2..6683cb7c39f 100755 --- a/Database/RDBAccessSvc/RDBAccessSvc/IRDBAccessSvc.h +++ b/Database/RDBAccessSvc/RDBAccessSvc/IRDBAccessSvc.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /** @@ -9,7 +9,6 @@ * * @author Vakho Tsulaia * - * $Id: IRDBAccessSvc.h,v 1.8 2006-11-28 22:39:26 tsulaia Exp $ */ #ifndef RDBACCESSSVC_IRDBACCESSSVC_H @@ -24,9 +23,6 @@ class IRDBRecordset; class IRDBQuery; -namespace psc { - class Psc; -} typedef std::shared_ptr IRDBRecordset_ptr; @@ -50,7 +46,7 @@ class IRDBAccessSvc : virtual public IInterface // Special friends who need to call connect()/disconnect() methods friend class GeoModelSvc; friend class SourceCompAlg; - friend class psc::Psc; // HLT/Trigger/TrigControl/TrigPSC + friend class TrigRDBManager; public: -- GitLab From 978ebbc21f3ea85af170360144f7b4ef92a6e995 Mon Sep 17 00:00:00 2001 From: Frank Winklmeier Date: Fri, 18 Oct 2019 14:23:36 +0200 Subject: [PATCH 2/2] Move DB connection mgmt form Psc to HltEventLoopMgr Move the management of DB connections before forking from the Psc to HltEventLoopMgr (ATR-8907). This allows the sleep time to be configured via the new `dbConnIdleWaitSec` property. Moved the actual code to the `TrigRDBManager` helper class so we don't have to change the friend relationship in `IRDBAccessSvc` in case we need to move this code somewhere else again. --- .../TrigControl/TrigPSC/CMakeLists.txt | 5 +- HLT/Trigger/TrigControl/TrigPSC/src/Psc.cxx | 29 --------- .../TrigControl/TrigServices/CMakeLists.txt | 3 +- .../python/TriggerUnixStandardSetup.py | 3 + .../TrigServices/src/HltEventLoopMgr.cxx | 4 ++ .../TrigServices/src/HltEventLoopMgr.h | 3 + .../TrigServices/src/TrigRDBManager.h | 64 +++++++++++++++++++ 7 files changed, 78 insertions(+), 33 deletions(-) create mode 100644 HLT/Trigger/TrigControl/TrigServices/src/TrigRDBManager.h diff --git a/HLT/Trigger/TrigControl/TrigPSC/CMakeLists.txt b/HLT/Trigger/TrigControl/TrigPSC/CMakeLists.txt index 1b31e3ecd88..fa76bd32066 100644 --- a/HLT/Trigger/TrigControl/TrigPSC/CMakeLists.txt +++ b/HLT/Trigger/TrigControl/TrigPSC/CMakeLists.txt @@ -16,7 +16,6 @@ atlas_depends_on_subdirs( PUBLIC # External dependencies: find_package( Boost COMPONENTS filesystem thread system ) -find_package( CORAL COMPONENTS CoralBase CoralKernel RelationalAccess ) find_package( PythonLibs ) find_package( tdaq-common COMPONENTS ers eformat eformat_write hltinterface ) @@ -25,9 +24,9 @@ atlas_add_library( TrigPSC src/*.cxx PUBLIC_HEADERS TrigPSC INCLUDE_DIRS ${TDAQ-COMMON_INCLUDE_DIRS} - PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} + PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} LINK_LIBRARIES ${TDAQ-COMMON_LIBRARIES} GaudiKernel - PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${PYTHON_LIBRARIES} TrigKernel PathResolver TrigConfBase ) + PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} TrigKernel PathResolver TrigConfBase ) # Install files from the package: atlas_install_python_modules( python/*.py ) diff --git a/HLT/Trigger/TrigControl/TrigPSC/src/Psc.cxx b/HLT/Trigger/TrigControl/TrigPSC/src/Psc.cxx index b0ae48ad143..52a2a6ae26a 100644 --- a/HLT/Trigger/TrigControl/TrigPSC/src/Psc.cxx +++ b/HLT/Trigger/TrigControl/TrigPSC/src/Psc.cxx @@ -36,13 +36,6 @@ #include "GaudiKernel/Property.h" #include "GaudiKernel/System.h" -// Athena includes -#include "RDBAccessSvc/IRDBAccessSvc.h" - -// CORAL includes -#include "CoralKernel/Context.h" -#include "RelationalAccess/IConnectionService.h" - #include #include #include @@ -493,28 +486,6 @@ bool psc::Psc::prepareForRun (const ptree& args) return false; } - // Cleanup of dangling database connections from RDBAccessSvc - ServiceHandle p_rdbAccessSvc("RDBAccessSvc","psc::Psc"); - if(p_rdbAccessSvc->shutdown("*Everything*")) { - ERS_LOG("Cleaning up RDBAccessSvc connections"); - } else { - ERS_PSC_ERROR("Cleaning up RDBAccessSvc connections failed"); - return false; - } - - // sleep some time to allow the closing of DB connections; - // actual timeout depends on connection parameters, we seem to have 5 seconds - // timeouts in some places. - sleep(6); - // Instantiate connection service - coral::Context& context = coral::Context::instance(); - // Load CORAL connection service - coral::IHandle connSvcH = context.query(); - if (connSvcH.isValid()) { - ERS_LOG("Cleaning up idle CORAL connections"); - connSvcH->purgeConnectionPool(); - } - return true; } diff --git a/HLT/Trigger/TrigControl/TrigServices/CMakeLists.txt b/HLT/Trigger/TrigControl/TrigServices/CMakeLists.txt index 2ccec88ac4a..a82a70e900d 100644 --- a/HLT/Trigger/TrigControl/TrigServices/CMakeLists.txt +++ b/HLT/Trigger/TrigControl/TrigServices/CMakeLists.txt @@ -41,7 +41,8 @@ atlas_add_library( TrigServicesLib src/*.cxx INCLUDE_DIRS ${TDAQ-COMMON_INCLUDE_DIRS} ${TDAQ_INCLUDE_DIRS} PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} - LINK_LIBRARIES ${TDAQ-COMMON_LIBRARIES} ${TDAQ_LIBRARIES} AthenaBaseComps AthenaKernel AthenaPoolUtilities ByteStreamCnvSvcLib ByteStreamData EventInfoUtils xAODEventInfo GaudiKernel TrigKernel TrigSteeringEvent StoreGateLib ByteStreamCnvSvcBaseLib ByteStreamData_test TrigDataAccessMonitoringLib TrigROBDataProviderSvcLib TrigOutputHandlingLib ) + LINK_LIBRARIES ${TDAQ-COMMON_LIBRARIES} ${TDAQ_LIBRARIES} AthenaBaseComps AthenaKernel AthenaPoolUtilities ByteStreamCnvSvcLib ByteStreamData EventInfoUtils xAODEventInfo GaudiKernel TrigKernel TrigSteeringEvent StoreGateLib ByteStreamCnvSvcBaseLib ByteStreamData_test TrigDataAccessMonitoringLib TrigROBDataProviderSvcLib TrigOutputHandlingLib + PRIVATE_LINK_LIBRARIES ${CORAL_LIBRARIES} ) atlas_add_component( TrigServices src/components/*.cxx diff --git a/HLT/Trigger/TrigControl/TrigServices/python/TriggerUnixStandardSetup.py b/HLT/Trigger/TrigControl/TrigServices/python/TriggerUnixStandardSetup.py index ced755920b9..b51128cbf8d 100644 --- a/HLT/Trigger/TrigControl/TrigServices/python/TriggerUnixStandardSetup.py +++ b/HLT/Trigger/TrigControl/TrigServices/python/TriggerUnixStandardSetup.py @@ -121,6 +121,9 @@ def setupCommonServices(): svcMgr.HltEventLoopMgr.EvtSel = svcMgr.EventSelector svcMgr.HltEventLoopMgr.OutputCnvSvc = svcMgr.ByteStreamCnvSvc + # Time to wait before closing DB connections (see ATR-8907) + svcMgr.HltEventLoopMgr.dbConnIdleWaitSec = 6 + from TrigOutputHandling.TrigOutputHandlingConfig import HLTResultMTMakerCfg svcMgr.HltEventLoopMgr.ResultMaker = HLTResultMTMakerCfg() diff --git a/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.cxx b/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.cxx index 02e5828f4f1..bae745704ce 100644 --- a/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.cxx +++ b/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.cxx @@ -7,6 +7,7 @@ #include "TrigCOOLUpdateHelper.h" #include "TrigKernel/HltExceptions.h" #include "TrigSORFromPtreeHelper.h" +#include "TrigRDBManager.h" #include "TrigSteeringEvent/HLTResultMT.h" // Athena includes @@ -416,6 +417,9 @@ StatusCode HltEventLoopMgr::prepareForRun(const ptree& pt) // close any open files (e.g. THistSvc) ATH_CHECK(m_ioCompMgr->io_finalize()); + // close open DB connections + ATH_CHECK(TrigRDBManager::closeDBConnections(m_dbIdleWait, msg())); + // Assert that scheduler has not been initialised before forking SmartIF svc = serviceLocator()->service(m_schedulerName, /*createIf=*/ false); if (svc.isValid()) { diff --git a/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.h b/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.h index 4b2d0ce3d0e..4e16791ce03 100644 --- a/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.h +++ b/HLT/Trigger/TrigControl/TrigServices/src/HltEventLoopMgr.h @@ -247,6 +247,9 @@ private: Gaudi::Property m_forceSOR_ns{ this, "forceStartOfRunTime", 0, "Override SOR time during prepareForRun (epoch in nano-seconds)"}; + Gaudi::Property m_dbIdleWait{ + this, "dbConnIdleWaitSec", 0, "Seconds to wait before cleaning idle DB connections"}; + SG::WriteHandleKey m_eventContextWHKey{ this, "EventContextWHKey", "EventContext", "StoreGate key for recording EventContext"}; diff --git a/HLT/Trigger/TrigControl/TrigServices/src/TrigRDBManager.h b/HLT/Trigger/TrigControl/TrigServices/src/TrigRDBManager.h new file mode 100644 index 00000000000..98fe9ca31c9 --- /dev/null +++ b/HLT/Trigger/TrigControl/TrigServices/src/TrigRDBManager.h @@ -0,0 +1,64 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ +#ifndef TRIGSERVICES_TRIGRDBMANAGER_H +#define TRIGSERVICES_TRIGRDBMANAGER_H + +// Athena/Gaudi includes +#include "GaudiKernel/ServiceHandle.h" +#include "RDBAccessSvc/IRDBAccessSvc.h" + +// CORAL includes +#include "CoralKernel/Context.h" +#include "RelationalAccess/IConnectionService.h" + +// System includes +#include + +/** + * Helper to manage database connections + * + * This class is a "friend" of IRDBAccessSvc and allowed to manage + * database connections. + */ +class TrigRDBManager { +public: + /** + * Close database connections + * + * @param idleWaitSec seconds to wait before cleaning idle connections + * @param msg reference to MsgStream + */ + static StatusCode closeDBConnections(unsigned int idleWaitSec, MsgStream& msg) + { + // Cleanup of dangling database connections from RDBAccessSvc + ServiceHandle rdbAccessSvc("RDBAccessSvc", "TrigRDBManager"); + if (rdbAccessSvc->shutdown("*Everything*")) { + msg << MSG::INFO << "Cleaning up RDBAccessSvc connections" << endmsg; + } + else { + msg << MSG::ERROR << "Cleaning up RDBAccessSvc connections failed" << endmsg; + return StatusCode::FAILURE; + } + + // sleep some time to allow the closing of DB connections; + // actual timeout depends on connection parameters, we seem to have 5 seconds + // timeouts in some places: https://its.cern.ch/jira/browse/ATR-8907 + if (idleWaitSec > 0) { + msg << MSG::INFO << "Waiting " << idleWaitSec << " seconds..." << endmsg; + sleep(idleWaitSec); + } + + // Instantiate connection service + coral::Context& context = coral::Context::instance(); + // Load CORAL connection service + coral::IHandle connSvcH = context.query(); + if (connSvcH.isValid()) { + msg << MSG::INFO << "Cleaning up idle CORAL connections" << endmsg; + connSvcH->purgeConnectionPool(); + } + return StatusCode::SUCCESS; + } +}; + +#endif -- GitLab