Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 13101 invoked from network); 10 Aug 2005 23:03:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Aug 2005 23:03:42 -0000 Received: (qmail 67341 invoked by uid 500); 10 Aug 2005 23:03:41 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 67303 invoked by uid 500); 10 Aug 2005 23:03:41 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 67250 invoked by uid 99); 10 Aug 2005 23:03:40 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 10 Aug 2005 16:03:40 -0700 Received: (qmail 12908 invoked by uid 65534); 10 Aug 2005 23:03:40 -0000 Message-ID: <20050810230340.12893.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r231349 - /httpd/httpd/trunk/modules/cache/mod_disk_cache.c Date: Wed, 10 Aug 2005 23:03:39 -0000 To: cvs@httpd.apache.org From: jerenkrantz@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jerenkrantz Date: Wed Aug 10 16:03:38 2005 New Revision: 231349 URL: http://svn.apache.org/viewcvs?rev=231349&view=rev Log: mod_disk_cache: Retry file rename up to three times to ameliorate race condition with htcacheclean removing the directories underneath us. (Includes tweaks by Justin.) Suggested by: Graham Leggett Submitted by: Andreas Steinmetz Reviewed by: Justin Erenkrantz Modified: httpd/httpd/trunk/modules/cache/mod_disk_cache.c Modified: httpd/httpd/trunk/modules/cache/mod_disk_cache.c URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/modules/cache/mod_disk_cache.c?rev=231349&r1=231348&r2=231349&view=diff ============================================================================== --- httpd/httpd/trunk/modules/cache/mod_disk_cache.c (original) +++ httpd/httpd/trunk/modules/cache/mod_disk_cache.c Wed Aug 10 16:03:38 2005 @@ -184,6 +184,33 @@ } } +/* htcacheclean may remove directories underneath us. + * So, we'll try renaming three times at a cost of 0.002 seconds. + */ +static apr_status_t safe_file_rename(disk_cache_conf *conf, + const char *src, const char *dest, + apr_pool_t *pool) +{ + apr_status_t rv; + + rv = apr_file_rename(src, dest, pool); + + if (rv != APR_SUCCESS) { + int i; + + for (i = 0; i < 2 && rv != APR_SUCCESS; i++) { + /* 1000 micro-seconds aka 0.001 seconds. */ + apr_sleep(1000); + + mkdir_structure(conf, dest, pool); + + rv = apr_file_rename(src, dest, pool); + } + } + + return rv; +} + static apr_status_t file_cache_el_final(disk_cache_object_t *dobj, request_rec *r) { @@ -795,7 +822,8 @@ dobj->tfd = NULL; - rv = apr_file_rename(dobj->tempfile, dobj->hdrsfile, r->pool); + rv = safe_file_rename(conf, dobj->tempfile, dobj->hdrsfile, + r->pool); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, r->server, "disk_cache: rename tempfile to varyfile failed: %s -> %s", @@ -886,9 +914,8 @@ if (rv != APR_SUCCESS) { mkdir_structure(conf, dobj->hdrsfile, r->pool); } - - rv = apr_file_rename(dobj->tempfile, dobj->hdrsfile, r->pool); + rv = safe_file_rename(conf, dobj->tempfile, dobj->hdrsfile, r->pool); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server, "disk_cache: rename tempfile to hdrsfile failed: %s -> %s",