]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_lua: Fix up LuaCodeCache:
authorDaniel Gruno <humbedooh@apache.org>
Mon, 30 Jul 2012 08:19:14 +0000 (08:19 +0000)
committerDaniel Gruno <humbedooh@apache.org>
Mon, 30 Jul 2012 08:19:14 +0000 (08:19 +0000)
- Check both mtime and size of a file when comparing with cache, in case the file is being written to while read
- If LuaCodeCache is 'never', only reload it if it has been run once or more.
- Never use cache if LuaScope is 'once'.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1367025 13f79535-47bb-0310-9956-ffa450edef68

modules/lua/lua_vmprep.c
modules/lua/lua_vmprep.h

index 21fbf2073497e64c5e230656918108c69f169d03..a5f97b8023823e8aa9711174b26d8780ab816663 100644 (file)
@@ -344,7 +344,7 @@ AP_LUA_DECLARE(lua_State*)ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
     int tryCache = 0;
     if (apr_pool_userdata_get((void **)&L, spec->file,
                               lifecycle_pool) == APR_SUCCESS) {
-      
+        
       if(L==NULL) {
         ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool, APLOGNO(01483)
                       "creating lua_State with file %s", spec->file);
@@ -363,26 +363,37 @@ AP_LUA_DECLARE(lua_State*)ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
     if (spec->codecache == AP_LUA_CACHE_FOREVER || (spec->bytecode && spec->bytecode_len > 0)) {
         tryCache = 1;
     }
-    else if (spec->codecache == AP_LUA_CACHE_STAT) {
-        apr_time_t modified;
-        char* mkey = apr_psprintf(lifecycle_pool, "ap_lua_modified:%s", spec->file);
-        if (apr_pool_userdata_get((void **)&modified, mkey,
+    else {
+        ap_lua_finfo *cache_info;
+        char* mkey = apr_psprintf(lifecycle_pool, "ap_lua_modified:%s", spec->file); /* XXX: Change to a different pool? */
+        if (apr_pool_userdata_get((void **)&cache_info, mkey,
                               lifecycle_pool) == APR_SUCCESS) {
-            apr_finfo_t lua_finfo;
-            apr_stat(&lua_finfo, spec->file, APR_FINFO_MTIME, lifecycle_pool);
+            if (cache_info == NULL) {
+                cache_info = apr_pcalloc(lifecycle_pool, sizeof(ap_lua_finfo));
+            }
+            if (spec->codecache == AP_LUA_CACHE_STAT) {
+                apr_finfo_t lua_finfo;
+                apr_stat(&lua_finfo, spec->file, APR_FINFO_MTIME|APR_FINFO_SIZE, lifecycle_pool);
             
-            /* On first visit, modified will be zero, but that's fine - The file is 
-             loaded in the vm_construct function.
-             */
-            if (modified == lua_finfo.mtime || modified == 0) tryCache = 1;
-            modified = lua_finfo.mtime;
+                /* On first visit, modified will be zero, but that's fine - The file is 
+                loaded in the vm_construct function.
+                */
+                if ((cache_info->modified == lua_finfo.mtime && cache_info->size == lua_finfo.size) \
+                        || cache_info->modified == 0) tryCache = 1;
+                cache_info->modified = lua_finfo.mtime;
+                cache_info->size = lua_finfo.size;
+            }
+            else if (spec->codecache == AP_LUA_CACHE_NEVER) {
+                if (cache_info->runs == 0) tryCache = 1;
+            }
+            cache_info->runs++;
         }
         else {
             tryCache = 1;
         }
-        apr_pool_userdata_set((void*) modified, mkey, NULL, lifecycle_pool);
+        apr_pool_userdata_set((void*) cache_info, mkey, NULL, lifecycle_pool);
     }
-    if (tryCache == 0) {
+    if (tryCache == 0 && spec->scope != AP_LUA_SCOPE_ONCE) {
         int rc;
         ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool, APLOGNO(01481)
             "(re)loading lua file %s", spec->file);
index c3b5376664d497ba34d7de68705fc0ea9f52453a..0669df5802fc445bc7e4207630ceecc224dd6acb 100644 (file)
@@ -91,6 +91,12 @@ typedef struct
     int codecache;
 } ap_lua_mapped_handler_spec;
 
+typedef struct {
+    apr_size_t runs;
+    apr_time_t modified;
+    apr_size_t size;
+} ap_lua_finfo;
+
 /* remove and make static once out of mod_wombat.c */
 AP_LUA_DECLARE(void) ap_lua_openlibs(lua_State *L);