iRule to retry with modulus operator
We have 4 pools and we are redirecting the request to each pool by calculating modulus of crc32 value of an http header id. I have written the following iRule for that :
In http header we will get objectId and we will do crc32 and get a value and after we do a modulus to redirect to appropriate pool (and further redirection to appropriate pool via HTTP::uri). So that all same objectId remain in all same subsystem pools. From starting we know we have 3 nodes in each pool.
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 % 3]
log "mod value is $key"
if { $key == 0 }
{
log "Redirecting to Pool 0"
switch -glob [string tolower $uri] {
"/api/channel*" { pool channel-pool member 192.168.159.133 8088 }
"/api/space*" { pool space-pool member 192.168.159.133 8089 }
"/api/gateway*" { pool gateway-pool member 192.168.159.133 8087 }
default{ pool default_pool member 192.168.159.133 80 }
}
} elseif { $key == 1 }
{
log "Redirecting Pool 1"
switch -glob [string tolower $uri] {
"/api/channel*" { pool channel-pool member 192.168.159.134 8088 }
"/api/space*" { pool space-pool member 192.168.159.134 8089 }
"/api/gateway*" { pool gateway-pool member 192.168.159.134 8087 }
default { pool default_pool member 192.168.159.134 80 }
}
} elseif { $key == 2 }
{
log "Redirecting to Pool 2"
switch -glob [string tolower $uri] {
"/api/channel*" { pool channel-pool member 192.168.159.135 8088 }
"/api/space*" { pool space-pool member 192.168.159.135 8089 }
"/api/gateway*" { pool gateway-pool member 192.168.159.135 8087 }
default { pool default_pool member 192.168.159.135 80 }
}
}
}
}
Now we have a functionality that if one member in any pool went down it will not send request to the same node across all pools. But how can we can decrease the no. from 3 to 2 or some other value if it finds any member in any pool as down.
If anybody can help me on this.
Thanks.