You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rp...@apache.org on 2023/05/25 07:47:16 UTC

svn commit: r1910042 - in /apr/apr-util/branches/1.7.x: ./ include/apr_memcache.h memcache/apr_memcache.c

Author: rpluem
Date: Thu May 25 07:47:16 2023
New Revision: 1910042

URL: http://svn.apache.org/viewvc?rev=1910042&view=rev
Log:
Merge r1910012, r1910039 from trunk:

Add a configurable retry period for dead servers instead of the currently
hardcoded period of 5 seconds. The default is still 5 seconds.

* include/apr_memcache.h::struct apr_memcache_t:
    Add retry_period to struct.

* memcache/apr_memcache.c::apr_memcache_set_retry_period
    Added setter function for retry_period field

* memcache/apr_memcache.c::apr_memcache_get_retry_period
    Added getter function for retry_period field


* Whitespace fixes only. No functional change

Modified:
    apr/apr-util/branches/1.7.x/   (props changed)
    apr/apr-util/branches/1.7.x/include/apr_memcache.h
    apr/apr-util/branches/1.7.x/memcache/apr_memcache.c

Propchange: apr/apr-util/branches/1.7.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r1910012,1910039

Modified: apr/apr-util/branches/1.7.x/include/apr_memcache.h
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/include/apr_memcache.h?rev=1910042&r1=1910041&r2=1910042&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/include/apr_memcache.h (original)
+++ apr/apr-util/branches/1.7.x/include/apr_memcache.h Thu May 25 07:47:16 2023
@@ -113,6 +113,8 @@ struct apr_memcache_t
     apr_memcache_hash_func hash_func;
     void *server_baton;
     apr_memcache_server_func server_func;
+    /** Period of time before retrying a dead server */
+    apr_time_t retry_period;
 };
 
 /** Returned Data from a multiple get */
@@ -208,6 +210,26 @@ APU_DECLARE(apr_status_t) apr_memcache_e
 APU_DECLARE(apr_status_t) apr_memcache_disable_server(apr_memcache_t *mc,
                                                       apr_memcache_server_t *ms);
 
+
+/**
+ * Set the retry period for retrying a dead server
+ * @param mc The memcache client object to use
+ * @param retry_period Period that must have passed until a server that was
+ *        declared dead is retried.
+ */
+APU_DECLARE(void) apr_memcache_set_retry_period(apr_memcache_t *mc,
+                                                apr_time_t retry_period);
+
+
+/**
+ * Get the retry period for retrying a dead server
+ * @param mc The memcache client object to use
+ * @return retry_period Period that must have passed until a server that was
+ *         declared dead is retried.
+ */
+APU_DECLARE(apr_time_t) apr_memcache_get_retry_period(apr_memcache_t *mc);
+
+
 /**
  * Creates a new Server Object
  * @param p Pool to use

Modified: apr/apr-util/branches/1.7.x/memcache/apr_memcache.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/memcache/apr_memcache.c?rev=1910042&r1=1910041&r2=1910042&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/memcache/apr_memcache.c (original)
+++ apr/apr-util/branches/1.7.x/memcache/apr_memcache.c Thu May 25 07:47:16 2023
@@ -165,7 +165,7 @@ apr_memcache_find_server_hash_default(vo
     apr_uint32_t i = 0;
     apr_time_t curtime = 0;
    
-    if(mc->ntotal == 0) {
+    if (mc->ntotal == 0) {
         return NULL;
     }
 
@@ -182,7 +182,7 @@ apr_memcache_find_server_hash_default(vo
             apr_thread_mutex_lock(ms->lock);
 #endif
             /* Try the dead server, every 5 seconds */
-            if (curtime - ms->btime >  apr_time_from_sec(5)) {
+            if (curtime - ms->btime > mc->retry_period) {
                 ms->btime = curtime;
                 if (mc_version_ping(ms) == APR_SUCCESS) {
                     make_server_live(mc, ms);
@@ -511,13 +511,24 @@ APU_DECLARE(apr_status_t) apr_memcache_s
     return rv;
 }
 
+APU_DECLARE(void) apr_memcache_set_retry_period(apr_memcache_t *mc,
+                                                apr_time_t retry_period)
+{
+    mc->retry_period = retry_period;
+}
+
+APU_DECLARE(apr_time_t) apr_memcache_get_retry_period(apr_memcache_t *mc)
+{
+    return mc->retry_period;
+}
+
 APU_DECLARE(apr_status_t) apr_memcache_create(apr_pool_t *p,
                                               apr_uint16_t max_servers, apr_uint32_t flags,
-                                              apr_memcache_t **memcache) 
+                                              apr_memcache_t **memcache)
 {
     apr_status_t rv = APR_SUCCESS;
     apr_memcache_t *mc;
-    
+
     mc = apr_palloc(p, sizeof(apr_memcache_t));
     mc->p = p;
     mc->nalloc = max_servers;
@@ -527,6 +538,8 @@ APU_DECLARE(apr_status_t) apr_memcache_c
     mc->hash_baton = NULL;
     mc->server_func = NULL;
     mc->server_baton = NULL;
+    /* Init with previous default value */
+    mc->retry_period = apr_time_from_sec(5);
     *memcache = mc;
     return rv;
 }