15#include "RelationalAccess/ConnectionService.h"
16#include "RelationalAccess/IConnectionServiceConfiguration.h"
17#include "RelationalAccess/IWebCacheControl.h"
18#include "RelationalAccess/IDatabaseServiceSet.h"
19#include "RelationalAccess/IDatabaseServiceDescription.h"
27 const char* chost=getenv(
"ATLAS_CONDDB");
32 const char* chost=getenv(
"HOSTNAME");
37 <<
" has no domain - try hostname --fqdn");
40 system(
"hostname --fqdn > hostnamelookup.tmp");
43 system(
"hostname > hostnamelookup.tmp");
46 infile.open(
"hostnamelookup.tmp");
56 const char* cfrontier=getenv(
"FRONTIER_SERVER");
59 <<
" will be considered for COOL data");
66 ATH_MSG_INFO (
"COOL SQLite replicas will be excluded if matching pattern "
70 ATH_MSG_INFO (
"COOL Frontier replicas will be excluded");
72 ATH_MSG_INFO (
"Geometry SQLite replicas will be excluded");
74 ATH_MSG_INFO (
"Failover to secondary replicas disabled");
80 return (StatusCode::FAILURE);
83 coral::ConnectionService conSvcH;
84 coral::IConnectionServiceConfiguration& csConfig = conSvcH.configuration();
85 csConfig.setReplicaSortingAlgorithm(*
this);
86 ATH_MSG_DEBUG(
"Successfully setup replica sorting algorithm");
91 csConfig.enablePoolAutomaticCleanUp();
94 csConfig.disablePoolAutomaticCleanUp();
95 csConfig.setConnectionTimeOut(0);
98 <<
" seconds with connection cleanup "
99 << (csConfig.isPoolAutomaticCleanUpEnabled() ?
"enabled" :
"disabled"));
101 coral::IWebCacheControl& webCache = conSvcH.webCacheControl();
103 ATH_MSG_INFO(
"Frontier compression level set to " << webCache.compressionLevel());
114 return StatusCode::FAILURE;
118 FILE* p_inp=fopen(
file.c_str(),
"r");
119 if (p_inp==
nullptr) {
121 return StatusCode::FAILURE;
124 const unsigned int bufsize=999;
126 while (!feof(p_inp)) {
127 char* p_line=fgets(p_buf,bufsize,p_inp);
128 if (p_line!=NULL && p_line[0]!=
'#') {
129 std::string buf=std::string(p_line);
130 std::string::size_type iofs1=0;
133 std::vector<std::string> domains;
134 std::vector<std::string> servers;
135 while (iofs1<buf.size()) {
136 std::string::size_type iofs2=buf.find(
' ',iofs1);
138 if (iofs2==std::string::npos) iofs2=buf.size()-1;
139 std::string token=buf.substr(iofs1,iofs2-iofs1);
141 if (token!=
"" && token!=
" ") {
144 }
else if (!sequal) {
146 domains.push_back(std::move(token));
149 if (!
m_nofailover || servers.size()==0 || token==
"atlas_dd")
150 servers.push_back(std::move(token));
158 unsigned int bestlen=0;
159 for (
const std::string& d : domains) {
160 std::string::size_type len=d.size();
161 std::string::size_type hlen=
m_hostname.size();
162 if (hlen>=len && d==
m_hostname.substr(hlen-len,len)) {
171 ATH_MSG_INFO (
"No specific match for domain found - use default fallback");
179 for (
unsigned int i=0;i<servers.size();++i) {
180 int priority=i*5-100*bestlen;
185 if (servers[i]==
"ATLF") priority-=2000;
188 " (priority " << priority <<
")");
196 " servers found for host " <<
m_hostname <<
" [";
198 msg() << name <<
" ";
201 return StatusCode::SUCCESS;
208 if (replicaSet.size()<=1)
return;
211 std::map<int,const coral::IDatabaseServiceDescription*> primap;
212 for (
const coral::IDatabaseServiceDescription* dbdescr : replicaSet) {
214 const std::string conn=dbdescr->connectionString();
216 if (conn.find(
"sqlite_file")!=std::string::npos) {
225 && conn.find(
"ALLP")!=std::string::npos)
229 && conn.find(
"geomDB")!=std::string::npos))) {
233 if (conn.find(
"sqlite_file:/")!=std::string::npos ||
234 conn.find(
"DBRelease")!=std::string::npos) {
235 primap[-999]=dbdescr;
237 primap[-9999]=dbdescr;
244 if (conn.find(
"frontier:")!=std::string::npos) {
250 (conn.find(
"()")!=std::string::npos &&
m_frontiergen==
false))
254 std::string::size_type ipos1=conn.find(
"://");
255 std::string::size_type ipos2=conn.find(
'/',ipos1+3);
258 std::string::size_type ipos3=conn.find(
'(',ipos1+3);
259 if (ipos3!=std::string::npos && ipos3<ipos2) ipos2=ipos3;
260 if (ipos1!=std::string::npos && ipos2!=std::string::npos && !
veto) {
261 const std::string server=conn.substr(ipos1+3,ipos2-ipos1-3);
266 primap[pri+spri]=dbdescr;
274 for (
const auto& [pri, db] : primap) {
275 replicaSet.push_back(db);
276 ATH_MSG_DEBUG (
"Allowed replica to try (priority " << pri <<
") : " << db->connectionString());
278 if (replicaSet.empty()) {
281 ATH_MSG_DEBUG (
"Retained total of " << replicaSet.size() <<
" replicas");
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
Gaudi::Property< int > m_retrialTimeOut
ConnectionRetrialTimeOut, the retrial time out for CORAL Connection Service: default = 300 seconds.
Gaudi::Property< bool > m_connClean
ConnectionCleanUp - whether to use CORAL connection management thread: default = false.
virtual StatusCode initialize() override
Gaudi::Property< std::string > m_testhost
Gaudi::Property< bool > m_usegeomsqlite
coral::Context * m_context
void sort(std::vector< const coral::IDatabaseServiceDescription * > &replicaSet) override
Gaudi::Property< int > m_timeOut
ConnectionTimeOut, the time out for CORAL Connection Service: default = 5 seconds.
std::pair< std::string, int > ServerPair
Gaudi::Property< int > m_frontierComp
Frontier proprties, compression level and list of schemas to be refreshed: default = 5.
Gaudi::Property< int > m_retrialPeriod
ConnectionRetrialPeriod, retry period for CORAL Connection Service: default = 30 seconds.
Gaudi::Property< bool > m_usecoolsqlite
Gaudi::Property< bool > m_nofailover
Gaudi::Property< std::string > m_coolsqlitepattern
std::vector< ServerPair > m_servermap
Gaudi::Property< std::string > m_configfile
Gaudi::Property< bool > m_usecoolfrontier
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
std::vector< std::string > veto
these patterns are anded