projects
/
metaproxy-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix ref to freed memory in log filter 1line - MP-556
[metaproxy-moved-to-github.git]
/
src
/
filter_load_balance.cpp
diff --git
a/src/filter_load_balance.cpp
b/src/filter_load_balance.cpp
index
57e1eb8
..
dafe8f3
100644
(file)
--- a/
src/filter_load_balance.cpp
+++ b/
src/filter_load_balance.cpp
@@
-1,5
+1,5
@@
/* This file is part of Metaproxy.
/* This file is part of Metaproxy.
- Copyright (C) 2005-2009 Index Data
+ Copyright (C) Index Data
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
@@
-17,11
+17,10
@@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.hpp"
*/
#include "config.hpp"
-#include "session.hpp"
-#include "package.hpp"
-#include "filter.hpp"
+#include <metaproxy/package.hpp>
+#include <metaproxy/filter.hpp>
#include "filter_load_balance.hpp"
#include "filter_load_balance.hpp"
-#include "util.hpp"
+#include <metaproxy/util.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/mutex.hpp>
@@
-35,7
+34,6
@@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#undef max
#endif
#undef max
#endif
-//#include <iostream>
#include <list>
#include <map>
#include <limits>
#include <list>
#include <map>
#include <limits>
@@
-55,7
+53,7
@@
namespace metaproxy_1
void process(metaproxy_1::Package & package);
void configure(const xmlNode * ptr);
private:
void process(metaproxy_1::Package & package);
void configure(const xmlNode * ptr);
private:
- // statistic manipulating functions,
+ // statistic manipulating functions,
void add_dead(unsigned long session_id);
//void clear_dead(unsigned long session_id);
void add_package(unsigned long session_id);
void add_dead(unsigned long session_id);
//void clear_dead(unsigned long session_id);
void add_package(unsigned long session_id);
@@
-76,11
+74,6
@@
namespace metaproxy_1
unsigned int deads;
unsigned int cost() {
unsigned int c = sessions + packages + deads;
unsigned int deads;
unsigned int cost() {
unsigned int c = sessions + packages + deads;
- //std::cout << "stats c:" << c
- // << " s:" << sessions
- // << " p:" << packages
- // << " d:" << deads
- // <<"\n";
return c;
}
};
return c;
}
};
@@
-94,7
+87,7
@@
namespace metaproxy_1
}
// define Pimpl wrapper forwarding to Impl
}
// define Pimpl wrapper forwarding to Impl
-
+
yf::LoadBalance::LoadBalance() : m_p(new Impl)
{
}
yf::LoadBalance::LoadBalance() : m_p(new Impl)
{
}
@@
-103,7
+96,8
@@
yf::LoadBalance::~LoadBalance()
{ // must have a destructor because of boost::scoped_ptr
}
{ // must have a destructor because of boost::scoped_ptr
}
-void yf::LoadBalance::configure(const xmlNode *xmlnode, bool test_only)
+void yf::LoadBalance::configure(const xmlNode *xmlnode, bool test_only,
+ const char *path)
{
m_p->configure(xmlnode);
}
{
m_p->configure(xmlnode);
}
@@
-119,7
+113,7
@@
yf::LoadBalance::Impl::Impl()
}
yf::LoadBalance::Impl::~Impl()
}
yf::LoadBalance::Impl::~Impl()
-{
+{
}
void yf::LoadBalance::Impl::configure(const xmlNode *xmlnode)
}
void yf::LoadBalance::Impl::configure(const xmlNode *xmlnode)
@@
-129,12
+123,12
@@
void yf::LoadBalance::Impl::configure(const xmlNode *xmlnode)
void yf::LoadBalance::Impl::process(mp::Package &package)
{
bool is_closed_front = false;
void yf::LoadBalance::Impl::process(mp::Package &package)
{
bool is_closed_front = false;
-
+
// checking for closed front end packages
if (package.session().is_closed())
{
is_closed_front = true;
// checking for closed front end packages
if (package.session().is_closed())
{
is_closed_front = true;
- }
+ }
Z_GDU *gdu_req = package.request().get();
Z_GDU *gdu_req = package.request().get();
@@
-158,15
+152,19
@@
void yf::LoadBalance::Impl::process(mp::Package &package)
{
std::string target;
std::list<std::string>::iterator ivh = vhosts.begin();
{
std::string target;
std::list<std::string>::iterator ivh = vhosts.begin();
+
+ Package init_pkg(package.session(), package.origin());
+ init_pkg.copy_filter(package);
+
unsigned int cost = std::numeric_limits<unsigned int>::max();
unsigned int cost = std::numeric_limits<unsigned int>::max();
- {
+ {
boost::mutex::scoped_lock scoped_lock(m_mutex);
boost::mutex::scoped_lock scoped_lock(m_mutex);
-
+
for (; ivh != vhosts.end(); )
{
if ((*ivh).size() != 0)
{
for (; ivh != vhosts.end(); )
{
if ((*ivh).size() != 0)
{
- unsigned int vhcost
+ unsigned int vhcost
= yf::LoadBalance::Impl::cost(*ivh);
yaz_log(YLOG_LOG, "Consider %s cost=%u vhcost=%u",
(*ivh).c_str(), cost, vhcost);
= yf::LoadBalance::Impl::cost(*ivh);
yaz_log(YLOG_LOG, "Consider %s cost=%u vhcost=%u",
(*ivh).c_str(), cost, vhcost);
@@
-189,22
+187,23
@@
void yf::LoadBalance::Impl::process(mp::Package &package)
yazpp_1::GDU init_gdu(base_req);
Z_InitRequest *init_req = init_gdu.get()->u.z3950->u.initRequest;
yazpp_1::GDU init_gdu(base_req);
Z_InitRequest *init_req = init_gdu.get()->u.z3950->u.initRequest;
-
- mp::util::set_vhost_otherinfo(&(init_req->otherInfo),
+
+ mp::util::set_vhost_otherinfo(&(init_req->otherInfo),
odr_en, target, 1);
odr_en, target, 1);
-
- package.request() = init_gdu;
-
- // moving all package types
- package.move();
-
+
+ init_pkg.request() = init_gdu;
+
+ // moving all package types
+ init_pkg.move();
+
// checking for closed back end packages
// checking for closed back end packages
- if (!package.session().is_closed())
+ if (!init_pkg.session().is_closed())
{
add_session(package.session().id(), target);
{
add_session(package.session().id(), target);
+
+ package.response() = init_pkg.response();
return;
}
return;
}
- yaz_log(YLOG_LOG, "Other round..");
}
mp::odr odr;
package.response() = odr.create_initResponse(
}
mp::odr odr;
package.response() = odr.create_initResponse(
@@
-217,18
+216,18
@@
void yf::LoadBalance::Impl::process(mp::Package &package)
else if (gdu_req->u.z3950->which == Z_APDU_close)
{
is_closed_front = true;
else if (gdu_req->u.z3950->which == Z_APDU_close)
{
is_closed_front = true;
- boost::mutex::scoped_lock scoped_lock(m_mutex);
+ boost::mutex::scoped_lock scoped_lock(m_mutex);
add_package(package.session().id());
add_package(package.session().id());
- }
+ }
// any other Z39.50 package is added to statistics
else
{
// any other Z39.50 package is added to statistics
else
{
- boost::mutex::scoped_lock scoped_lock(m_mutex);
+ boost::mutex::scoped_lock scoped_lock(m_mutex);
add_package(package.session().id());
}
}
add_package(package.session().id());
}
}
- // moving all package types
+ // moving all package types
package.move();
bool is_closed_back = false;
package.move();
bool is_closed_back = false;
@@
-248,7
+247,7
@@
void yf::LoadBalance::Impl::process(mp::Package &package)
is_closed_back = true;
boost::mutex::scoped_lock scoped_lock(m_mutex);
remove_package(package.session().id());
is_closed_back = true;
boost::mutex::scoped_lock scoped_lock(m_mutex);
remove_package(package.session().id());
- }
+ }
// any other Z39.50 package is removed from statistics
else
{
// any other Z39.50 package is removed from statistics
else
{
@@
-262,7
+261,7
@@
void yf::LoadBalance::Impl::process(mp::Package &package)
{
boost::mutex::scoped_lock scoped_lock(m_mutex);
{
boost::mutex::scoped_lock scoped_lock(m_mutex);
- // marking backend dead if backend closed without fronted close
+ // marking backend dead if backend closed without fronted close
if (is_closed_front == false)
add_dead(package.session().id());
if (is_closed_front == false)
add_dead(package.session().id());
@@
-272,40
+271,36
@@
void yf::LoadBalance::Impl::process(mp::Package &package)
package.session().close();
}
}
package.session().close();
}
}
-
-// statistic manipulating functions,
+
+// statistic manipulating functions,
void yf::LoadBalance::Impl::add_dead(unsigned long session_id)
{
std::string target = find_session_target(session_id);
if (target.size() != 0)
{
void yf::LoadBalance::Impl::add_dead(unsigned long session_id)
{
std::string target = find_session_target(session_id);
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end()
&& itarg->second.deads < std::numeric_limits<unsigned int>::max())
{
itarg->second.deads += 1;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end()
&& itarg->second.deads < std::numeric_limits<unsigned int>::max())
{
itarg->second.deads += 1;
- // std:.cout << "add_dead " << session_id << " " << target
+ // std:.cout << "add_dead " << session_id << " " << target
// << " d:" << itarg->second.deads << "\n";
}
}
}
// << " d:" << itarg->second.deads << "\n";
}
}
}
-//void yf::LoadBalance::Impl::clear_dead(unsigned long session_id){
-// std::cout << "clear_dead " << session_id << "\n";
-//};
-
void yf::LoadBalance::Impl::add_package(unsigned long session_id)
{
std::string target = find_session_target(session_id);
if (target.size() != 0)
{
void yf::LoadBalance::Impl::add_package(unsigned long session_id)
{
std::string target = find_session_target(session_id);
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end()
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end()
- && itarg->second.packages
+ && itarg->second.packages
< std::numeric_limits<unsigned int>::max())
{
itarg->second.packages += 1;
< std::numeric_limits<unsigned int>::max())
{
itarg->second.packages += 1;
@@
-319,7
+314,7
@@
void yf::LoadBalance::Impl::remove_package(unsigned long session_id)
if (target.size() != 0)
{
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end()
&& itarg->second.packages > 0)
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end()
&& itarg->second.packages > 0)
@@
-329,7
+324,7
@@
void yf::LoadBalance::Impl::remove_package(unsigned long session_id)
}
}
}
}
-void yf::LoadBalance::Impl::add_session(unsigned long session_id,
+void yf::LoadBalance::Impl::add_session(unsigned long session_id,
std::string target)
{
// finding and adding session
std::string target)
{
// finding and adding session
@@
-350,7
+345,7
@@
void yf::LoadBalance::Impl::add_session(unsigned long session_id,
stat.packages = 0;
stat.deads = 0;
m_target_stat.insert(std::make_pair(target, stat));
stat.packages = 0;
stat.deads = 0;
m_target_stat.insert(std::make_pair(target, stat));
- }
+ }
else if (itarg->second.sessions < std::numeric_limits<unsigned int>::max())
{
itarg->second.sessions += 1;
else if (itarg->second.sessions < std::numeric_limits<unsigned int>::max())
{
itarg->second.sessions += 1;
@@
-377,15
+372,11
@@
void yf::LoadBalance::Impl::remove_session(unsigned long session_id)
m_session_target.erase(isess);
return;
}
m_session_target.erase(isess);
return;
}
-
+
// counting session down
if (itarg->second.sessions > 0)
itarg->second.sessions -= 1;
// counting session down
if (itarg->second.sessions > 0)
itarg->second.sessions -= 1;
- // std:.cout << "remove_session " << session_id << " " << target
- // << " s:" << itarg->second.sessions << "\n";
-
- // clearing empty sessions and targets
if (itarg->second.sessions == 0 && itarg->second.deads == 0)
{
m_target_stat.erase(itarg);
if (itarg->second.sessions == 0 && itarg->second.deads == 0)
{
m_target_stat.erase(itarg);
@@
-411,13
+402,11
@@
unsigned int yf::LoadBalance::Impl::cost(std::string target)
if (target.size() != 0)
{
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end())
cost = itarg->second.cost();
}
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end())
cost = itarg->second.cost();
}
-
- //std::cout << "cost " << target << " c:" << cost << "\n";
return cost;
}
return cost;
}
@@
-427,13
+416,11
@@
unsigned int yf::LoadBalance::Impl::dead(std::string target)
if (target.size() != 0)
{
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end())
dead = itarg->second.deads;
}
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end())
dead = itarg->second.deads;
}
-
- //std::cout << "dead " << target << " d:" << dead << "\n";
return dead;
}
return dead;
}