You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by hu...@apache.org on 2012/07/30 10:19:14 UTC
svn commit: r1367025 - in /httpd/httpd/trunk/modules/lua: lua_vmprep.c
lua_vmprep.h
Author: humbedooh
Date: Mon Jul 30 08:19:14 2012
New Revision: 1367025
URL: http://svn.apache.org/viewvc?rev=1367025&view=rev
Log:
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'.
Modified:
httpd/httpd/trunk/modules/lua/lua_vmprep.c
httpd/httpd/trunk/modules/lua/lua_vmprep.h
Modified: httpd/httpd/trunk/modules/lua/lua_vmprep.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_vmprep.c?rev=1367025&r1=1367024&r2=1367025&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_vmprep.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_vmprep.c Mon Jul 30 08:19:14 2012
@@ -344,7 +344,7 @@ AP_LUA_DECLARE(lua_State*)ap_lua_get_lua
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
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);
Modified: httpd/httpd/trunk/modules/lua/lua_vmprep.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_vmprep.h?rev=1367025&r1=1367024&r2=1367025&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_vmprep.h (original)
+++ httpd/httpd/trunk/modules/lua/lua_vmprep.h Mon Jul 30 08:19:14 2012
@@ -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);