httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Kew <n...@webthing.com>
Subject Re: svn commit: r454683 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_rewrite.xml modules/mappers/mod_rewrite.c
Date Tue, 10 Oct 2006 12:27:37 GMT
On Tuesday 10 October 2006 13:00, Ruediger Pluem wrote:
> On 10/10/2006 12:33 PM,  wrote:
> > Author: niq
> > Date: Tue Oct 10 03:33:06 2006
> > New Revision: 454683
> >
> > URL: http://svn.apache.org/viewvc?view=rev&rev=454683
> > Log:
> > Add SQL Query capability to RewriteMap
> >
> >
> > Modified: httpd/httpd/trunk/modules/mappers/mod_rewrite.c
> > URL:
> > http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_rewrit
> >e.c?view=diff&rev=454683&r1=454682&r2=454683
> > =========================================================================
> >===== --- httpd/httpd/trunk/modules/mappers/mod_rewrite.c (original)
> > +++ httpd/httpd/trunk/modules/mappers/mod_rewrite.c Tue Oct 10 03:33:06
> > 2006
> >
> > +static char *lookup_map_dbd(request_rec *r, char *key, const char
> > *label) +{
> > +    apr_status_t rv;
> > +    apr_dbd_prepared_t *stmt;
> > +    apr_dbd_results_t *res = NULL;
> > +    apr_dbd_row_t *row = NULL;
> > +    const char *ret = NULL;
> > +    int n = 0;
> > +    ap_dbd_t *db = dbd_acquire(r);
> > +
> > +    stmt = apr_hash_get(db->prepared, label, APR_HASH_KEY_STRING);
> > +
> > +    rv = apr_dbd_pvselect(db->driver, r->pool, db->handle, &res,
> > +                          stmt, 0, key, NULL);
> > +    if (rv != 0) {
> > +        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
> > +                      "rewritemap: error querying for %s", key);
> > +    }
> > +    while (rv = apr_dbd_get_row(db->driver, r->pool, res, &row, -1),
rv
> > == 0) {
>
> Guess that brings us back to the code style discussion :-)
>
> > +        ++n;
> > +        if (ret == NULL) {
> > +            ret = apr_dbd_get_entry(db->driver, row, 0);
> > +        }
> > +        else {
> > +            /* randomise crudely amongst multiple results */
> > +            if ((double)rand() < (double)RAND_MAX/(double)n) {
>
> Is rand portable? Are there APR alternatives that could be used?

rand is documented as conforming to all the usual suspect standards.
And it's already used elsewhere in mod_rewrite.

>
> > +     */
> > +    case MAPTYPE_DBD_CACHE:
> > +        value = get_cache_value(s->cachename, st.mtime, key, r->pool);
>
> I think that st is not initialized here. Other maps do an apr_stat before
> using it. So it is possible that its value is different each time you call
> lookup_map.

Good catch!

> > +        if (!value) {
> > +            rewritelog((r, 6, NULL,
> > +                        "cache lookup FAILED, forcing new map lookup"));
> > +
> > +            value = lookup_map_dbd(r, key, s->dbdq);
> > +            if (!value) {
> > +                rewritelog((r, 5, NULL, "SQL map lookup FAILED: map %s
> > key=%s", +                            name, key));
>
> I noticed that the other rewritemaps also cache negative results by setting
> the cache to "". Any specfic reason why this is not done here?

Yes, it's a case of "may change".  But since we have the two separate cases
of "dbd" and "fastdbd", I guess it would make sense for the latter to cache.

-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.prenhallprofessional.com/title/0132409674

Mime
View raw message