1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-08 15:02:10 +03:00

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
This commit is contained in:
Daniel Gruno
2012-07-30 08:19:14 +00:00
parent e69eb628f7
commit c0cc85a065
2 changed files with 31 additions and 14 deletions

View 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) {
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, lifecycle_pool);
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;
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);

View 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);