15 #include "RelationalAccess/IDatabaseServiceDescription.h"
23 std::cout <<
"ReplicaSorter constructor" << std::endl;
30 std::map<int,const coral::IDatabaseServiceDescription*> primap;
31 for (std::vector<const coral::IDatabaseServiceDescription*>::const_iterator
32 itr=replicaSet.begin();itr!=replicaSet.end();++itr) {
33 const std::string
conn=(**itr).connectionString();
35 if (
conn.find(
"sqlite_file")==std::string::npos) {
38 std::string::size_type ipos0=
conn.find(
'&');
39 std::string::size_type ipos1=
conn.find(
"://",ipos0+1);
40 std::string::size_type ipos2=
conn.find(
'/',ipos1+3);
41 if (ipos1!=std::string::npos && ipos2!=std::string::npos) {
42 const std::string
server=
conn.substr(ipos1+3,ipos2-ipos1-3);
45 for (ServerMap::const_iterator sitr=m_servermap.begin();
46 sitr!=m_servermap.end();++sitr) {
48 primap[sitr->second]=*itr;
55 for (std::map<int,const coral::IDatabaseServiceDescription*>::const_iterator
56 itr=primap.begin();itr!=primap.end();++itr) {
57 replicaSet.push_back(itr->second);
58 std::cout <<
"Allowed replica to try (priority " << itr->first
59 <<
") : " << (itr->second)->connectionString() << std::endl;
61 if (replicaSet.empty())
62 std::cout <<
"No matching replicas found" << std::endl;
69 const char* chost=
getenv(
"ATLAS_CONDDB");
70 if (chost) m_hostname=chost;
71 if (m_hostname.empty()) {
72 const char* chost=
getenv(
"HOSTNAME");
73 if (chost) m_hostname=chost;
75 if (m_hostname.find(
'.')==std::string::npos) {
77 char cstr_host[HOST_NAME_MAX];
78 if (gethostname(cstr_host,
sizeof(cstr_host))==0) {
79 m_hostname=std::string(cstr_host);
83 std::cout <<
"Using machine hostname " << m_hostname <<
" for DB replica resolution" << std::endl;
85 const char* cfrontier=
getenv(
"FRONTIER_SERVER");
86 if (cfrontier && strcmp(cfrontier,
"")!=0) {
87 std::cout <<
"Frontier server at " << cfrontier <<
" will be considered"
97 std::cout <<
"Cannot open/locate configuration file dbreplica.config"
102 unsigned int bufsize=999;
103 char* p_buf=
new char[bufsize];
104 while (!feof(p_inp)) {
105 char* p_line=fgets(p_buf,bufsize,p_inp);
106 if (p_line!=NULL && p_line[0]!=
'#') {
107 std::string buf=std::string(p_line);
108 std::string::size_type iofs1=0;
111 std::vector<std::string> domains;
112 std::vector<std::string> servers;
114 while (iofs1<buf.size()) {
115 std::string::size_type iofs2=buf.find(
' ',iofs1);
117 if (iofs2==std::string::npos) iofs2=buf.size()-1;
118 std::string token=buf.substr(iofs1,iofs2-iofs1);
120 if (token!=
"" && token!=
" ") {
123 }
else if (!sequal) {
125 domains.push_back(token);
126 if(token==
"cern.ch") atCERN =
true;
130 if(atCERN && token==
"ATONR_CONF") atCERN =
false;
131 if (token!=
"ATLF" || m_frontiergen) servers.push_back(token);
139 unsigned int bestlen=0;
140 for (std::vector<std::string>::const_iterator itr=domains.begin();
141 itr!=domains.end();++itr) {
142 std::string::size_type len=(itr->size());
143 std::string::size_type hlen=m_hostname.size();
144 if (hlen>=len && *itr==m_hostname.substr(hlen-len,len)) {
153 if (
"default"==*itr && m_servermap.empty()) {
155 "No specific match for domain found - use default fallback"
163 servers.push_back(
"ATONR_COOL");
164 servers.push_back(
"ATONR_CONF");
168 for (
unsigned int i=0;
i<servers.size();++
i) {
177 std::cout <<
"Total of " << m_servermap.size() <<
178 " servers found for host " << m_hostname << std::endl;
186 const std::string& pathvar)
189 std::string::size_type iofs1,iofs2,len;
194 while (!
fptr && iofs1<len) {
195 iofs2=pathvar.find(
':',iofs1);
196 if (iofs2==std::string::npos) iofs2=len;
201 std::cout <<
"Opening " <<
name << endl;