apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aa...@apache.org
Subject cvs commit: apr-util/test testreslist.c
Date Mon, 15 Mar 2004 08:21:26 GMT
aaron       2004/03/15 00:21:26

  Modified:    include  apr_reslist.h
               misc     apr_reslist.c
               test     testreslist.c
  Log:
  Rationale: if an module gets a resource that proves to be bad (e.g.
  a connection that's gone away), it shouldn't be returned to the
  pool to be given out again.  We should invalidate it.
  
  Submitted by:	Nick Kew <nick@webthing.com>
  Reviewed by:	Aaron Bannert
  
  Revision  Changes    Path
  1.9       +9 -0      apr-util/include/apr_reslist.h
  
  Index: apr_reslist.h
  ===================================================================
  RCS file: /home/cvs/apr-util/include/apr_reslist.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apr_reslist.h	13 Feb 2004 09:55:26 -0000	1.8
  +++ apr_reslist.h	15 Mar 2004 08:21:26 -0000	1.9
  @@ -123,6 +123,15 @@
   APU_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t *reslist,
                                             apr_interval_time_t timeout);
   
  +/**
  + * Invalidate a resource in the pool - e.g. a database connection
  + * that returns a "lost connection" error and can't be restored.
  + * Use this instead of apr_reslist_release if the resource is bad.
  + */
  +APU_DECLARE(apr_status_t) apr_reslist_invalidate(apr_reslist_t *reslist,
  +                                                 void *resource);
  +
  +
   #ifdef __cplusplus
   }
   #endif
  
  
  
  1.9       +11 -0     apr-util/misc/apr_reslist.c
  
  Index: apr_reslist.c
  ===================================================================
  RCS file: /home/cvs/apr-util/misc/apr_reslist.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apr_reslist.c	13 Feb 2004 09:55:26 -0000	1.8
  +++ apr_reslist.c	15 Mar 2004 08:21:26 -0000	1.9
  @@ -360,4 +360,15 @@
       reslist->timeout = timeout;
   }
   
  +APU_DECLARE(apr_status_t) apr_reslist_invalidate(apr_reslist_t *reslist,
  +                                                 void *resource)
  +{
  +    apr_status_t ret;
  +    apr_thread_mutex_lock(reslist->listlock);
  +    ret = reslist->destructor(resource, reslist->params, reslist->pool);
  +    reslist->ntotal--;
  +    apr_thread_mutex_unlock(reslist->listlock);
  +    return ret;
  +}
  +
   #endif  /* APR_HAS_THREADS */
  
  
  
  1.7       +22 -9     apr-util/test/testreslist.c
  
  Index: testreslist.c
  ===================================================================
  RCS file: /home/cvs/apr-util/test/testreslist.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- testreslist.c	13 Feb 2004 09:55:26 -0000	1.6
  +++ testreslist.c	15 Mar 2004 08:21:26 -0000	1.7
  @@ -59,7 +59,8 @@
       res = apr_palloc(pool, sizeof(*res));
       res->id = my_params->c_count++;
   
  -    printf("++ constructing new resource [id:%d]\n", res->id);
  +    printf("++ constructing new resource [id:%d, #%d/%d]\n", res->id,
  +       my_params->c_count, my_params->d_count);
   
       /* Sleep for awhile, to simulate construction overhead. */
       apr_sleep(my_params->sleep_upon_construct);
  @@ -75,8 +76,8 @@
       my_resource_t *res = resource;
       my_parameters_t *my_params = params;
   
  -    printf("-- destructing old resource [id:%d, #%d]\n", res->id,
  -           my_params->d_count++);
  +    printf("-- destructing old resource [id:%d, #%d/%d]\n", res->id,
  +           my_params->c_count, ++my_params->d_count);
   
       apr_sleep(my_params->sleep_upon_destruct);
   
  @@ -108,12 +109,23 @@
           printf("  [tid:%d,iter:%d] using resource id:%d\n", thread_info->tid,
                  i, res->id);
           apr_sleep(thread_info->work_delay_sleep);
  -        rv = apr_reslist_release(rl, res);
  -        if (rv != APR_SUCCESS) {
  -            fprintf(stderr, "Failed to return resource to reslist\n");
  -            apr_thread_exit(thd, rv);
  -            return NULL;
  -        }
  +/* simulate a 5% chance of the resource being bad */
  +        if ( drand48() < 0.95 ) {
  +           rv = apr_reslist_release(rl, res);
  +            if (rv != APR_SUCCESS) {
  +                fprintf(stderr, "Failed to return resource to reslist\n");
  +                apr_thread_exit(thd, rv);
  +                return NULL;
  +            }
  +       } else {
  +           printf("invalidating resource id:%d\n", res->id) ;
  +           rv = apr_reslist_invalidate(rl, res);
  +            if (rv != APR_SUCCESS) {
  +                fprintf(stderr, "Failed to invalidate resource\n");
  +                apr_thread_exit(thd, rv);
  +                return NULL;
  +            }
  +       }
       }
   
       return APR_SUCCESS;
  @@ -173,6 +185,7 @@
       int i;
       apr_thread_t *my_threads[CONSUMER_THREADS];
       my_thread_info_t my_thread_info[CONSUMER_THREADS];
  +    srand48(time(0)) ;
   
       printf("Creating child pool.......................");
       rv = apr_pool_create(&pool, parpool);
  
  
  

Mime
View raw message