3
unsigned StoredIp::target(struct in_addr clientip,
4
BackendVector const &targetlist) {
5
PROFILE("StoredIP::target");
8
msg(Mstr("Starting stored-ip dispatcher\n"));
11
if ( (tb = IPStore::target(clientip)) >= 0 ) {
13
IPStore::clear(clientip);
14
if (balancer.backend(target).available()) {
15
// Historical target is up, go there!
16
msg(Mstr("Sending ") + Mstr(inet_ntoa(clientip)) + " to " +
17
balancer.backend(target).description() + "\n");
20
msg (Mstr("Historical target ") +
21
balancer.backend(target).description() + " unavailable\n");
22
if (config.dispatchmode() == Dispatchmode::m_strict_stored_ip)
23
throw Error("Stored-IP algorithm: target back end " +
24
balancer.backend(target).description() +
28
// Client is seen for the first time, or after the timout period, or
29
// their preferred back end is down (and we're in lax mode ofc).
30
// Treat as new connection.
33
if (!config.removereservations())
34
return l.target(clientip, targetlist);
36
BackendVector tlist = targetlist;
39
return l.target(clientip, tlist);
41
// We're out of back ends and need to clear up the IP store to retry.
42
// We give it a sec, remove the oldest entry, and rebuild the
43
// target list for the least-connections dispatch algorithm.
44
warnmsg("Out of back ends, releasing oldest client entry and retrying\n");
45
IPStore::clearoldest();
47
BackendVector newlist;
48
for (unsigned int i = 0; i < balancer.nbackends(); i++)
49
if (balancer.backend(i).available())