-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cross modules stream/http shared dict #36
base: master
Are you sure you want to change the base?
Conversation
a15851e
to
60df5b2
Compare
60df5b2
to
a440866
Compare
src/ngx_stream_lua_shdict.c
Outdated
@@ -13,6 +13,7 @@ | |||
#include "ngx_stream_lua_shdict.h" | |||
#include "ngx_stream_lua_util.h" | |||
|
|||
extern ngx_module_t ngx_http_lua_module; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't quite like the fact that the ngx_stream_lua_module always requires ngx_http_lua_module, which is not acceptable when the user does not need the http subsystem at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should try to detect the presence of ngx_http_lua_module automatically in the build system (i.e., the config
file) and fork the logic with C macros.
src/ngx_stream_lua_shdict.c
Outdated
} | ||
|
||
if (&ngx_http_lua_module == shm_zone->tag || | ||
&ngx_stream_lua_module == shm_zone->tag ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: ||
should be at the beginning of the continued line. See other similar places for examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we should make constant value on the RHS of the ==
.
if (&ngx_http_lua_module == shm_zone->tag || | ||
&ngx_stream_lua_module == shm_zone->tag ) | ||
{ | ||
zone = ngx_array_push(&all_zones); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is risky since the shdict implementation of ngx_http_lua_module might be different than ngx_stream_lua_module (due to different versions of these modules, for example). It will lead to hard-to-debug issues when these two modules' implementations are incompatible in terms of the shm zone storage layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The safest way, IMHO, is to abstract the shm dict implementation out and make both these ngx_xxx_lua modules share it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agentzh You mean share the a common header file ? Where would this file reside ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alonbg I mean creating a ngx_meta_lua_module and make both ngx_http_lua_module and ngx_stream_lua_module depend on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agentzh Yes this was your original idea :) but to avoid collision [and allow coexistence of old and new] meta's shared dict directive will need to have a different name or stay with the name lua_shared_dict
but restricted to the configuration main part (outside both http and stream contexts). Which option do you prefer ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The risk is still there I believe since the ngx_meta_lua_shdict_ctx_t
which would be defined in all three modules might be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this. But this PR still needs quite some work I'm afraid :) Thanks!
src/ngx_stream_lua_socket_tcp.c
Outdated
ngx_stream_lua_inject_socket_option_consts(lua_State *L) | ||
{ | ||
/* {{{ socket option constants */ | ||
#if (NGX_HAVE_TRANSPARENT_PROXY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, do not include unrelated changes in the PR. Thank you.
@alonbg BTW, the Travis CI testing is broken on this PR, as evidenced below. |
@agentzh thanks for taking the time to comment. |
4c78f78
to
0d4dda7
Compare
2 or more share dict, when reload nginx, some dict lost . 17 http { telnet localhost 9999 |
We need a separate ngx_meta_lua_module for this. It's wrong to do such things in either ngx_stream_lua_module or ngx_http_lua_module. Either way is wrong and fragile. |
@agentzh, I'm convinced btw. I'll start working on ngx_meta_lua_module when I find the time. |
What is the status on the ngx_meta_lua_module? |
Here is my alternative proposal to this feature: openresty/meta-lua-nginx-module#76 |
This addresses issue #25 - cross modules shared dict.
Tested (including adding/removing dicts and reload) but tests still need to be added.
I'v covered different ways to do this. Most were either over complicated or/and risky.
This one is quite simple - a module references the other module zones only during post-configuration phase. It works as it relies on the fact (to my best knowledge) that across all pushed dict functions,
zone->data
isngx_stream_lua_shdict_ctx_t
orngx_http_lua_shdict_ctx_t
which are cast-interchangeable (they are aligned in the attributes that they are referenced to).The single non compatible attribute is
ctx->main_conf
but it's only accessed during configuration phase where each module takes care of it's own.Another big advantage is that it works without any changes to
lua_ngx_module
. Until http module adopts the change, a dict should be configured in http context for this to work.This is of course not ideal but it's by far the simplest way.
If possible, it would be best to make these structs fully aligned or even better including a common header file for this. Another TODO is "selectively sharing dicts".
test configuration attached
nginx.txt