dynamic determination of backend?

Jeremy Hinegardner jeremy at hinegardner.org
Wed May 20 18:35:43 CEST 2009


Hi all,

I'm working on a consistent hashing based system for our asset storage
and am considering putting varnish in front of it.   We have the
library, that given the url can determine the backend server:port, and
are wondering the best way to integrate this into VCL.  

My initial thought is something along the lines of:

    sub vcl_miss {
        C{  
            char *be_name = calloc( 32, sizeof( char )); 
            char done = 0;
            int n;
            int i;

            /* is this the right way to get the url ? */
            n = backend_name_for_url( VRT_r_req_url( sp ), be_name );

            for(i = 0 ; !done && (i < VCL_conf.ndirector) ; i++ ) { 
                /* what can be compared to be_name to find the right director? */
                if ( strncmp( be_name, VCL_conf.director[i]->vcl_name, n  )  == 0 ) { 
                    VRT_l_req_backend(sp, VCL_conf.director[i]);
                    done = 1;
                }   
            }   
            free(be_name);
        }C  
        fetch; 
    }

Unfortunately, the compiler doesn't like acessing the director pointer 
dereference to access 'vcl_name'.  I cobbled this together after digging 
through the source, so I'm sure that there is a better way to do this.
I think I'm close with this idea, just having a problem getting the
names of the the various backends at runtime.

Essentially I'd like to be able to dynamically lookup a backend by name
and then directly assign it as that requests backend.  

Any thoughts?  Or am I completely off base here?

enjoy,

-jeremy

-- 
========================================================================
Jeremy Hinegardner                              jeremy at hinegardner.org 




More information about the varnish-misc mailing list