From 0034c40674899ed144f73ad6b880ea61a32b6187 Mon Sep 17 00:00:00 2001 From: Odin Hultgren Van Der Horst Date: Wed, 22 Sep 2021 13:23:57 +0200 Subject: [PATCH 1/2] Add flags argument to shm:get(_stale)? Add optional flags argument to shmdict_get(_stale)? that only returns value if flags do not match. And a 3rd (4th for _stale) return value to indicate if it is a flag match. Fixed match_flags stream --- lib/resty/core/shdict.lua | 51 ++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/resty/core/shdict.lua b/lib/resty/core/shdict.lua index dedf12c44..72505e973 100644 --- a/lib/resty/core/shdict.lua +++ b/lib/resty/core/shdict.lua @@ -47,7 +47,7 @@ if subsystem == 'http' then int ngx_http_lua_ffi_shdict_get(void *zone, const unsigned char *key, size_t key_len, int *value_type, unsigned char **str_value_buf, size_t *str_value_len, double *num_value, int *user_flags, - int get_stale, int *is_stale, char **errmsg); + int *user_flags_neq, int get_stale, int *is_stale, char **errmsg); int ngx_http_lua_ffi_shdict_incr(void *zone, const unsigned char *key, size_t key_len, double *value, char **err, int has_init, @@ -101,7 +101,7 @@ elseif subsystem == 'stream' then int ngx_stream_lua_ffi_shdict_get(void *zone, const unsigned char *key, size_t key_len, int *value_type, unsigned char **str_value_buf, size_t *str_value_len, double *num_value, int *user_flags, - int get_stale, int *is_stale, char **errmsg); + int *user_flags_neq, int get_stale, int *is_stale, char **errmsg); int ngx_stream_lua_ffi_shdict_incr(void *zone, const unsigned char *key, size_t key_len, double *value, char **err, int has_init, @@ -162,6 +162,7 @@ end local value_type = ffi_new("int[1]") local user_flags = ffi_new("int[1]") +local user_flags_neq = ffi_new("int[1]") local num_value = ffi_new("double[1]") local is_stale = ffi_new("int[1]") local forcible = ffi_new("int[1]") @@ -292,13 +293,20 @@ local function shdict_delete(zone, key) end -local function shdict_get(zone, key) +local function shdict_get(zone, key, flags) zone = check_zone(zone) if key == nil then return nil, "nil key" end + if flags ~= nil then + user_flags_neq[0] = 1 + user_flags[0] = flags + else + user_flags_neq[0] = 0 + end + if type(key) ~= "string" then key = tostring(key) end @@ -319,8 +327,9 @@ local function shdict_get(zone, key) local rc = ngx_lua_ffi_shdict_get(zone, key, key_len, value_type, str_value_buf, value_len, - num_value, user_flags, 0, - is_stale, errmsg) + num_value, user_flags, + user_flags_neq, 0, is_stale, + errmsg) if rc ~= 0 then if errmsg[0] ~= nil then return nil, ffi_str(errmsg[0]) @@ -332,10 +341,13 @@ local function shdict_get(zone, key) local typ = value_type[0] if typ == 0 then -- LUA_TNIL + if flags ~= nil and user_flags_neq[0] == 0 then -- user_flegs are equal + return nil, nil, true + end return nil end - local flags = tonumber(user_flags[0]) + local flags_ret = tonumber(user_flags[0]) local val @@ -359,21 +371,28 @@ local function shdict_get(zone, key) error("unknown value type: " .. typ) end - if flags ~= 0 then - return val, flags + if flags_ret ~= 0 then + return val, flags_ret end return val end -local function shdict_get_stale(zone, key) +local function shdict_get_stale(zone, key, flags) zone = check_zone(zone) if key == nil then return nil, "nil key" end + if flags ~= nil then + user_flags_neq[0] = 1 + user_flags[0] = flags + else + user_flags_neq[0] = 0 + end + if type(key) ~= "string" then key = tostring(key) end @@ -394,8 +413,9 @@ local function shdict_get_stale(zone, key) local rc = ngx_lua_ffi_shdict_get(zone, key, key_len, value_type, str_value_buf, value_len, - num_value, user_flags, 1, - is_stale, errmsg) + num_value, user_flags, + user_flags_neq, 1, is_stale, + errmsg) if rc ~= 0 then if errmsg[0] ~= nil then return nil, ffi_str(errmsg[0]) @@ -407,10 +427,13 @@ local function shdict_get_stale(zone, key) local typ = value_type[0] if typ == 0 then -- LUA_TNIL + if flags ~= nil and user_flags_neq[0] == 0 then -- user_flegs are equal + return nil, nil, is_stale[0] == 1, true + end return nil end - local flags = tonumber(user_flags[0]) + local flags_ret = tonumber(user_flags[0]) local val if typ == 4 then -- LUA_TSTRING @@ -433,8 +456,8 @@ local function shdict_get_stale(zone, key) error("unknown value type: " .. typ) end - if flags ~= 0 then - return val, flags, is_stale[0] == 1 + if flags_ret ~= 0 then + return val, flags_ret, is_stale[0] == 1 end return val, nil, is_stale[0] == 1 From 358f7708d3ec11e7023436b9336c62927115368f Mon Sep 17 00:00:00 2001 From: Odin Hultgren Van Der Horst Date: Mon, 4 Oct 2021 13:11:16 +0200 Subject: [PATCH 2/2] Changed lua-nginx-module in .travis.yml Change stream in travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c47d6e719..960edb3c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,7 @@ install: - git clone https://github.com/openresty/openresty.git ../openresty - git clone https://github.com/openresty/openresty-devel-utils.git - git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module - - git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module + - git clone https://github.com/webcore-no/lua-nginx-module.git ../lua-nginx-module - git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx - git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module - git clone https://github.com/openresty/lua-resty-lrucache.git @@ -72,7 +72,7 @@ install: - git clone https://github.com/openresty/set-misc-nginx-module.git ../set-misc-nginx-module - git clone https://github.com/openresty/mockeagain.git - git clone https://github.com/openresty/test-nginx.git - - git clone https://github.com/openresty/stream-lua-nginx-module.git ../stream-lua-nginx-module + - git clone https://github.com/webcore-no/stream-lua-nginx-module.git ../stream-lua-nginx-module script: - cd luajit2/