Forum Discussion
Narendra_26827
Jul 22, 2011Nimbostratus
I have the following iRule logic which calculates crc32 of objectID present in http header and does the mod of it by the no. of members present in the pool. Now with the below logic if one server goes down the request are retried to another server via LB_FAILED event but if the previous server becomes up again then again (second time) all connections are reestablished from the new member to old member which was down. Can this be avoided by some kind of persistence?
when HTTP_REQUEST {
set uri [HTTP::uri]
if { [string tolower $uri] contains "/api/gateway" or [string tolower $uri] contains "/api/channel" or [string tolower $uri] contains "/api/space" }
{
set orgid [crc32 [HTTP::header objectId]]
set key [expr $orgid % [llength [members -list default_pool]]]
set default_member [lsort [members -list default_pool]]
set channel_member [lsort [members -list channel-pool]]
set gateway_member [lsort [members -list gateway-pool]]
set space_member [lsort [members -list space-pool]]
log "CRC32 value $orgid"
log "[llength [members -list default_pool]]"
log "Mod value $key"
switch -glob [string tolower $uri] {
"/api/channel*" {
log "[lindex [lindex $channel_member $key] 0] [lindex [lindex $channel_member $key] 1]"
pool channel-pool member [lindex [lindex $channel_member $key] 0] [lindex [lindex $channel_member $key] 1]
unset channel_member
}
"/api/space*" {
log "[lindex [lindex $space_member $key] 0] [lindex [lindex $space_member $key] 1]"
pool space-pool member [lindex [lindex $space_member $key] 0] [lindex [lindex $space_member $key] 1]
unset space_member
}
"/api/gateway*" {
log "[lindex [lindex $gateway_member $key] 0] [lindex [lindex $gateway_member $key] 1]"
pool gateway-pool member [lindex [lindex $gateway_member $key] 0] [lindex [lindex $gateway_member $key] 1]
unset gateway_member
}
default {
log "[lindex [lindex $channel_member $key] 0] [lindex [lindex $channel_member $key] 1]"
pool default_pool member [lindex [lindex $default_member $key] 0] [lindex [lindex $default_member $key] 1]
unset default_member
}
}
}
}
when LB_FAILED {
set uri [HTTP::uri]
if { [HTTP::header exists "objectId"] }
{
set orgid_new [crc32 [HTTP::header objectId]]
set newkey [expr $orgid_new % [active_members default_pool]]
set default_member_new [lsort [active_members -list default_pool]]
set channel_member_new [lsort [active_members -list channel-pool]]
set gateway_member_new [lsort [active_members -list gateway-pool]]
set space_member_new [lsort [active_members -list space-pool]]
switch -glob [string tolower $uri] {
"/api/channel*" {
log "[lindex [lindex $channel_member_new $newkey] 0] [lindex [lindex $channel_member_new $newkey] 1]"
LB::reselect pool channel-pool member [lindex [lindex $channel_member_new $newkey] 0] [lindex [lindex $channel_member_new $newkey] 1]
unset channel_member_new
}
"/api/space*" {
log "[lindex [lindex $space_member_new $newkey] 0] [lindex [lindex $space_member_new $newkey] 1]"
LB::reselect pool space-pool member [lindex [lindex $space_member_new $newkey] 0] [lindex [lindex $space_member_new $newkey] 1]
unset space_member_new
}
"/api/gateway*" {
log "[lindex [lindex $gateway_member_new $newkey] 0] [lindex [lindex $gateway_member_new $newkey] 1]"
LB::reselect pool gateway-pool member [lindex [lindex $gateway_member_new $newkey] 0] [lindex [lindex $gateway_member_new $newkey] 1]
unset gateway_member_new
}
default {
log "[lindex [lindex $default_member_new $newkey] 0] [lindex [lindex $default_member_new $newkey] 1]"
LB::reselect pool default_pool member [lindex [lindex $default_member_new $newkey] 0] [lindex [lindex $default_member_new $newkey] 1]
unset default_member_new
}
}
}
}
Thanks.