You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2018/06/27 23:14:40 UTC

svn commit: r1834557 - in /apr/apr-util/branches/1.7.x: ./ misc/apr_reslist.c test/testreslist.c

Author: ylavic
Date: Wed Jun 27 23:14:39 2018
New Revision: 1834557

URL: http://svn.apache.org/viewvc?rev=1834557&view=rev
Log:
Merge r1834022, r1834023, r1834024 from trunk:

apr_reslist: test for ttl = 0

The current reslist implementation handles ttl=0 as no TTL when acquiring
resources (expected and documented), but as zero TTL when releasing (immediate
expiry, so resources above smax are never recycled).

This test validates the upcoming fix (r1834023).


apr_reslist: fix release of resource with zero/no TTL.

Ignore expiry when ttl=0 in apr_reslist_maintain(), like apr_reslist_acquire().

While ttl=0 is supposed to mean no TTL/expiry, apr_reslist_maintain() hence
apr_reslist_release() were destroying all resources above smax in this case.

Corresponding test already committed in r1834022.


apr_reslist: follow up to r1834023: avoid unnecessary apr_time_now() calls.

When ttl=0 is configured, we never need to check for expiry.

Modified:
    apr/apr-util/branches/1.7.x/   (props changed)
    apr/apr-util/branches/1.7.x/misc/apr_reslist.c
    apr/apr-util/branches/1.7.x/test/testreslist.c

Propchange: apr/apr-util/branches/1.7.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun 27 23:14:39 2018
@@ -1,4 +1,4 @@
-/apr/apr/trunk:781403,781409,784519,784592,789965,794508,917837-917838,982408-982409,998533,1086937,1127053,1127648,1128838,1129433,1133587,1207704,1210524,1211987,1214516,1308087,1308131,1308318,1327636,1340286,1346865,1357761,1357772,1357780,1357966,1357968,1357979,1358295,1358480,1361811,1362241,1362248,1362252,1362255,1363076,1369681,1370626,1371811,1371817,1371919,1371923,1382174,1389154,1389169,1390461,1390477,1402870,1402897,1402903,1402907,1406088,1422413,1425356,1426442,1426448,1438960,1449308,1449314,1460185,1460243-1460244,1462219,1462224,1484271,1493715,1495887,1495889,1496407,1516261,1523479,1529554,1531009,1541054,1543399,1544846,1618843,1619438,1625247,1626561,1648830,1711657,1722547,1728958,1728963,1747941,1751567,1751806,1751898,1752008,1763665,1763667,1763669,1763672-1763673,1763842-1763843,1765378,1772414,1778153,1781391,1782042,1782045,1788335,1789947,1809394,1811470,1820080,1825311,1833359,1833366,1833382,1833421,1833425-1833426,1833440,1833449-1833451,1833456,1
 833525,1833599,1833993,1833995,1834551
+/apr/apr/trunk:781403,781409,784519,784592,789965,794508,917837-917838,982408-982409,998533,1086937,1127053,1127648,1128838,1129433,1133587,1207704,1210524,1211987,1214516,1308087,1308131,1308318,1327636,1340286,1346865,1357761,1357772,1357780,1357966,1357968,1357979,1358295,1358480,1361811,1362241,1362248,1362252,1362255,1363076,1369681,1370626,1371811,1371817,1371919,1371923,1382174,1389154,1389169,1390461,1390477,1402870,1402897,1402903,1402907,1406088,1422413,1425356,1426442,1426448,1438960,1449308,1449314,1460185,1460243-1460244,1462219,1462224,1484271,1493715,1495887,1495889,1496407,1516261,1523479,1529554,1531009,1541054,1543399,1544846,1618843,1619438,1625247,1626561,1648830,1711657,1722547,1728958,1728963,1747941,1751567,1751806,1751898,1752008,1763665,1763667,1763669,1763672-1763673,1763842-1763843,1765378,1772414,1778153,1781391,1782042,1782045,1788335,1789947,1809394,1811470,1820080,1825311,1833359,1833366,1833382,1833421,1833425-1833426,1833440,1833449-1833451,1833456,1
 833525,1833599,1833993,1833995,1834022-1834024,1834551
 /apr/apr-util/branches/1.3.x:896410,1154885
 /apr/apr-util/branches/1.4.x:1126217,1211211,1211219,1211223,1211330
 /apr/apr-util/branches/1.5.x:1757430

Modified: apr/apr-util/branches/1.7.x/misc/apr_reslist.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/misc/apr_reslist.c?rev=1834557&r1=1834556&r2=1834557&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/misc/apr_reslist.c (original)
+++ apr/apr-util/branches/1.7.x/misc/apr_reslist.c Wed Jun 27 23:14:39 2018
@@ -81,7 +81,9 @@ static apr_res_t *pop_resource(apr_resli
 static void push_resource(apr_reslist_t *reslist, apr_res_t *resource)
 {
     APR_RING_INSERT_HEAD(&reslist->avail_list, resource, apr_res_t, link);
-    resource->freed = apr_time_now();
+    if (reslist->ttl) {
+        resource->freed = apr_time_now();
+    }
     reslist->nidle++;
 }
 
@@ -210,8 +212,10 @@ APU_DECLARE(apr_status_t) apr_reslist_ma
         created_one++;
     }
 
-    /* We don't need to see if we're over the max if we were under it before */
-    if (created_one) {
+    /* We don't need to see if we're over the max if we were under it before,
+     * nor need we check for expiry if no ttl is configure.
+     */
+    if (created_one || !reslist->ttl) {
 #if APR_HAS_THREADS
         apr_thread_mutex_unlock(reslist->listlock);
 #endif
@@ -328,14 +332,16 @@ APU_DECLARE(apr_status_t) apr_reslist_ac
 {
     apr_status_t rv;
     apr_res_t *res;
-    apr_time_t now;
+    apr_time_t now = 0;
 
 #if APR_HAS_THREADS
     apr_thread_mutex_lock(reslist->listlock);
 #endif
     /* If there are idle resources on the available list, use
      * them right away. */
-    now = apr_time_now();
+    if (reslist->ttl) {
+        now = apr_time_now();
+    }
     while (reslist->nidle > 0) {
         /* Pop off the first resource */
         res = pop_resource(reslist);

Modified: apr/apr-util/branches/1.7.x/test/testreslist.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/test/testreslist.c?rev=1834557&r1=1834556&r2=1834557&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/test/testreslist.c (original)
+++ apr/apr-util/branches/1.7.x/test/testreslist.c Wed Jun 27 23:14:39 2018
@@ -258,6 +258,44 @@ static void test_reslist(abts_case *tc,
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 }
 
+static void test_reslist_no_ttl(abts_case *tc, void *data)
+{
+    apr_status_t rv;
+    apr_reslist_t *rl;
+    my_parameters_t *params;
+    my_resource_t *res;
+
+    /* Parameters (sleep not used) */
+    params = apr_pcalloc(p, sizeof(*params));
+
+    rv = apr_reslist_create(&rl,
+                            /*no min*/0, /*no smax*/0, /*max*/1, /*no ttl*/0,
+                            my_constructor, my_destructor, params, p);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    /* Acquire/contruct one resource */
+    rv = apr_reslist_acquire(rl, (void **)&res);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+    ABTS_INT_EQUAL(tc, 0, res->id);
+
+    /* Release it before next check */
+    rv = apr_reslist_release(rl, res);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    /* Re-acquire/release: the resource should be the same */
+    rv = apr_reslist_acquire(rl, (void **)&res);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+    ABTS_INT_EQUAL(tc, 0, res->id);
+
+    /* Release it before cleanup */
+    rv = apr_reslist_release(rl, res);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    rv = apr_reslist_destroy(rl);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+    ABTS_INT_EQUAL(tc, params->d_count, 1);
+}
+
 #endif /* APR_HAS_THREADS */
 
 abts_suite *testreslist(abts_suite *suite)
@@ -266,6 +304,7 @@ abts_suite *testreslist(abts_suite *suit
 
 #if APR_HAS_THREADS
     abts_run_test(suite, test_reslist, NULL);
+    abts_run_test(suite, test_reslist_no_ttl, NULL);
 #endif
 
     return suite;