From: Daniel Gruno Date: Mon, 30 Jul 2012 08:19:14 +0000 (+0000) Subject: mod_lua: Fix up LuaCodeCache: X-Git-Tag: 2.5.0-alpha~6570 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0cc85a0659b11911726b98fae7d24d18388d8cf;p=thirdparty%2Fapache%2Fhttpd.git mod_lua: Fix up LuaCodeCache: - 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 --- diff --git a/modules/lua/lua_vmprep.c b/modules/lua/lua_vmprep.c index 21fbf207349..a5f97b80238 100644 --- a/modules/lua/lua_vmprep.c +++ b/modules/lua/lua_vmprep.c @@ -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); diff --git a/modules/lua/lua_vmprep.h b/modules/lua/lua_vmprep.h index c3b5376664d..0669df5802f 100644 --- a/modules/lua/lua_vmprep.h +++ b/modules/lua/lua_vmprep.h @@ -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);