Permalink
Browse files

add patch to share shdict between http and stream

  • Loading branch information...
fffonion committed Feb 12, 2018
1 parent 6c1f0c3 commit eecc96a13a4ec79ae8c5f98a0650f449d01d01ca
Showing with 82 additions and 1 deletion.
  1. +14 −1 README.md
  2. +68 −0 patches/openresty-1.13.6.1-cross_module_shdict.patch
@@ -43,7 +43,20 @@ Experimental.
Synopsis
========
Shared dictionaries defined in `http` and `stream` subsystems are not shared to each other *currently*, thus we need two sets of configurations to debug with either subsystem. Despite from this, this module provide a similar API to use in both subsystems.
Shared dictionaries defined in `http` and `stream` subsystems are not shared to each other *currently*, thus we need two sets of configurations to debug with either subsystem.
However there're [patches](patches) if you want to share shdict between `http` and `stream` subsystems. After apply the patch, you will need to use two `lua_shared_dict` directive to define shared dict twice with same name and size. e.g.:
```lua
http {
lua_shared_dict dogs 10m;
}
stream {
lua_shared_dict dogs 10m;
}
```
http
----
@@ -0,0 +1,68 @@
diff --git a/ngx_lua-0.10.11/src/ngx_http_lua_directive.c b/ngx_lua-0.10.11/src/ngx_http_lua_directive.c
index 014a472..60493b2 100644
--- a/ngx_lua-0.10.11/src/ngx_http_lua_directive.c
+++ b/ngx_lua-0.10.11/src/ngx_http_lua_directive.c
@@ -125,7 +125,7 @@ ngx_http_lua_shared_dict(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ctx->log = &cf->cycle->new_log;
zone = ngx_http_lua_shared_memory_add(cf, &name, (size_t) size,
- &ngx_http_lua_module);
+ &ngx_shared_memory_add);
if (zone == NULL) {
return NGX_CONF_ERROR;
}
@@ -133,10 +133,16 @@ ngx_http_lua_shared_dict(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (zone->data) {
ctx = zone->data;
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "lua_shared_dict \"%V\" is already defined as "
- "\"%V\"", &name, &ctx->name);
- return NGX_CONF_ERROR;
+ if((&name)->len == (&ctx->name)->len &&
+ ! ngx_strcmp((&name)->data, (&ctx->name)->data) &&
+ zone->tag == &ngx_shared_memory_add) {
+ dd("same zone in other subsystem");
+ } else {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "http lua_shared_dict \"%V\" is already defined as "
+ "\"%V\"", &name, &ctx->name);
+ return NGX_CONF_ERROR;
+ }
}
zone->init = ngx_http_lua_shdict_init_zone;
diff --git a/ngx_stream_lua-0.0.3/src/ngx_stream_lua_directive.c b/ngx_stream_lua-0.0.3/src/ngx_stream_lua_directive.c
index dbf491c..e59f019 100644
--- a/ngx_stream_lua-0.0.3/src/ngx_stream_lua_directive.c
+++ b/ngx_stream_lua-0.0.3/src/ngx_stream_lua_directive.c
@@ -115,7 +115,7 @@ ngx_stream_lua_shared_dict(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ctx->log = &cf->cycle->new_log;
zone = ngx_stream_lua_shared_memory_add(cf, &name, (size_t) size,
- &ngx_stream_lua_module);
+ &ngx_shared_memory_add);
if (zone == NULL) {
return NGX_CONF_ERROR;
}
@@ -123,10 +123,16 @@ ngx_stream_lua_shared_dict(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (zone->data) {
ctx = zone->data;
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "lua_shared_dict \"%V\" is already defined as "
- "\"%V\"", &name, &ctx->name);
- return NGX_CONF_ERROR;
+ if((&name)->len == (&ctx->name)->len &&
+ ! ngx_strcmp((&name)->data, (&ctx->name)->data) &&
+ zone->tag == &ngx_shared_memory_add) {
+ dd("same zone in other subsystem");
+ } else {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "stream lua_shared_dict \"%V\" is already defined as "
+ "\"%V\"", &name, &ctx->name);
+ return NGX_CONF_ERROR;
+ }
}
zone->init = ngx_stream_lua_shdict_init_zone;

0 comments on commit eecc96a

Please sign in to comment.