<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html><head><meta http-equiv="Content-Type" content="text/html;charset=us-ascii">
<style>BODY{font:10pt Tahoma,Verdana,sans-serif} .MsoNormal{line-height:120%;margin:0}</style></head><body>
<div><font face="Tahoma, Verdana, sans-serif" size="2">Hi List,</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2">My coworkers and I are working on a sharding VMOD and we got to the point</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2">it's actually working (woohoo!).</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2">Now, our implementation is pretty straightforward:</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> - get id from url</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> - do a "id mod n" to pick correct shard ( = director)</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> - set req.backend = shardN</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2">Right now we have a very long if/elsif codepath that looks like this:</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> var.set_int("shard", sharding.get_mod_n(req.url,420));</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> if (var.get_int("shard") == 0) {</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> set req.backend = shard0;</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> set req.http.X-Varnish-Backend = "shard0";</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> }</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> elsif (var.get_int("shard") == 1) {</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> set req.backend = shard1;</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> set req.http.X-Varnish-Backend = "shard1";</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> }</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> ...</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2">So my question is, is it possible to *generate* the correct backend director,</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2">so we only need one line of VCL, instead of the long if/else, like so:</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"> set req.backend = shard + sharding.get_mod_n(req.url,420);</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2">Yet, this does not work, maybe there's a workaround, or maybe someone else found a solution?</font></div><div><span style="font-family: Tahoma, Verdana, sans-serif; font-size: small;">Thanks in advance!</span></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2">Regards,</font></div><div><font face="Tahoma, Verdana, sans-serif" size="2"><br></font></div><div><font face="Tahoma, Verdana, sans-serif" size="2">Enno</font></div><div style="font-family: Tahoma, Verdana, sans-serif; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><br></div></body></html>