You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by pq...@apache.org on 2005/06/11 02:26:20 UTC
svn commit: r190043 - in /httpd/httpd/trunk: CHANGES
modules/cache/mod_disk_cache.c
Author: pquerna
Date: Fri Jun 10 17:26:19 2005
New Revision: 190043
URL: http://svn.apache.org/viewcvs?rev=190043&view=rev
Log:
- Use apr_file_mktemp() and rename the header data file to its final location, instead of opening it and then writing it out as we go. Should prevent race conditions on busy servers.
Modified:
httpd/httpd/trunk/CHANGES
httpd/httpd/trunk/modules/cache/mod_disk_cache.c
Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/CHANGES?rev=190043&r1=190042&r2=190043&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES (original)
+++ httpd/httpd/trunk/CHANGES Fri Jun 10 17:26:19 2005
@@ -2,6 +2,8 @@
[Remove entries to the current 2.0 section below, when backported]
+ *) mod_disk_cache: Atomically create the header data file. [Paul Querna]
+
*) mod_cache: Fix 'Vary: *' behavior to be RFC compliant. PR 16125.
[Paul Querna]
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=190043&r1=190042&r2=190043&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_disk_cache.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_disk_cache.c Fri Jun 10 17:26:19 2005
@@ -535,21 +535,14 @@
/* This is flaky... we need to manage the cache_info differently */
h->cache_obj->info = *info;
- /* Remove old file with the same name. If remove fails, then
- * perhaps we need to create the directory tree where we are
- * about to write the new headers file.
- */
- rv = apr_file_remove(dobj->hdrsfile, r->pool);
- if (rv != APR_SUCCESS) {
- mkdir_structure(conf, dobj->hdrsfile, r->pool);
- }
+ rv = apr_file_mktemp(&dobj->hfd, dobj->tempfile,
+ APR_CREATE | APR_WRITE | APR_BINARY |
+ APR_BUFFERED | APR_EXCL, r->pool);
- rv = apr_file_open(&dobj->hfd, dobj->hdrsfile,
- APR_WRITE | APR_CREATE | APR_EXCL,
- APR_OS_DEFAULT, r->pool);
if (rv != APR_SUCCESS) {
return rv;
}
+
dobj->name = h->cache_obj->key;
disk_info.format = DISK_FORMAT_VERSION;
@@ -606,6 +599,26 @@
}
apr_file_close(dobj->hfd); /* flush and close */
+
+ /* Remove old file with the same name. If remove fails, then
+ * perhaps we need to create the directory tree where we are
+ * about to write the new headers file.
+ */
+ rv = apr_file_remove(dobj->hdrsfile, r->pool);
+ if (rv != APR_SUCCESS) {
+ mkdir_structure(conf, dobj->hdrsfile, r->pool);
+ }
+
+ rv = apr_file_rename(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",
+ dobj->tempfile, dobj->hdrsfile);
+ return rv;
+ }
+
+ dobj->tempfile = apr_pstrcat(r->pool, conf->cache_root, AP_TEMPFILE, NULL);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"disk_cache: Stored headers for URL %s", dobj->name);