Skip to content

ngx.shared.DICT.incr optional expire argument #942

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

Closed
wants to merge 6 commits into from

Conversation

splitice
Copy link

Rebased #358

I'll do a future commit changing all the shdict tests to _block.

I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.

@splitice
Copy link
Author

Let me know if its good and I'll do stream & resty-core.

if (n != 3 && n != 4) {
return luaL_error(L, "expecting 3 or 4 arguments, but only seen %d", n);
if (n < 3) {
return luaL_error(L, "expecting at least 3 arguments, but only seen %d", n);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line exceeds 80 columns. Please use the ngx-releng tool to check such things.

@splitice
Copy link
Author

done

lua_shared_dict dogs 1m;
--- config
location = /test {
content_by_lua '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newly added test cases should use the *_by_lua_block form instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do a future PR changing all the shdict tests to _block, not just these ones. It's an easy regex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@splitice I prefer keeping the old tests intact. Just the newly added ones should use *_by_lua_block.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to make adjustments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@splitice You want me to make adjustments in your branch? Sorry, no, I can't, obviously :)

Copy link
Member

@agentzh agentzh Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@splitice We can only help with the review process since we have many other items with much higher priorities. Thanks for your understanding.

sd->expires = (uint64_t) tp->sec * 1000 + tp->msec
+ (uint64_t) (exptime * 1000);

} else if (exptime == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better make exptime < 0 turn into exptime == 0 as well. So better replace this else if with else directly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are different code paths. Not adjusting the exptime (<0 aka -1 the default for null) vs setting it to not expire (0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@splitice Okay, got it.

if (init < 0) {
return luaL_error(L, "bad \"init\" argument");
}
has_init = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: need a blank line after the } line.

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@splitice Have you created the corresponding PR for lua-resty-core's FFI-based API?

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@splitice Thank you for your contribution! Will you please look at my comments and questions above? Thanks!

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

I think we also need updates in the documentation :)

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

Hmm, seems like we should permanently switch over to the FFI-based implementations to lua-resty-core. I'm already sick of maintaining two parallel implementations of the same Lua API :) I bet you can feel the pain as well :)

@doujiang24 @membphis @moonbingbing @thibaultcha @yangshuxin Shall we? ;)

@thibaultcha
Copy link
Member

thibaultcha commented Jan 9, 2017

mm, seems like we should permanently switch over to the FFI-based implementations to lua-resty-core.

I think so too. Having to provide two implementations for each new feature can also discourage a lot of contributors (I think it has been the case a few times already) and we may be missing a few opportunities to add relevant features.

However, this does raise a few concerns on the long term:

  • if more and more new features of the API are only provided in lua-resty-core, is it still user-friendly to ask of our users to manually require resty.core or the specific modules they need in every project they maintain?
  • the same way, library authors might use some future functions that are only implemented in the lua-resty-core module, and thus, using such libraries would load lua-resty-core without the user being aware of it. A cleaner way is probably for the library to require that users load resty.core in their init phase. This relates to the first point in that it is not as user-friendly.

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@thibaultcha To answer your concerns:

  1. We automatically require resty.core before running init_by_lua* unless lua_use_resty_core off is configured in the user nginx.conf (which is on by default).
  2. It's not a problem IMHO, since ngx_lua will require lua-resty-core and lua-resty-lrucache unless lua_use_resty_core is explicitly turned off :)

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

Another upside of this is that the ngx_lua core will also be smaller :) The downside is that we now require lua-resty-core and lua-resty-lrucache for ngx_lua. The latter is not a problem if the user uses OpenResty, of course.

@thibaultcha
Copy link
Member

thibaultcha commented Jan 9, 2017

We automatically require resty.core before running init_by_lua* unless lua_use_resty_core off

Is this an existing feature or a suggestion to solve those concerns? If so, I was about to suggest the same behavior as well (and disable it by default when not using LuaJIT).

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@thibaultcha It's a suggestion. I think I'd also drop the support for the standard Lua 5.1 interpreter in ngx_lua and openresty. LuaJIT is already diverged a lot from it and it's becoming a big burden for us due to the lack of FFI in the standard Lua 5.1 interpreter, for example.

In addition, the user can selectively choose which resty.core.* submodules to load to reduce memory footprint and GC overhead even further, as in

lua_use_resty_core regex shdict;  # only load the modules resty.core.regex and resty.core.shdict

By default, it could be lua_use_resty_core all. And the user can configure lua_use_resty_core none to disable everything :)

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@thibaultcha Alas. We should have created a separate ticket for it.

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@thibaultcha Let's move our discussion over to #949 to avoid off-topic :) Thanks!

@splitice
Copy link
Author

splitice commented Jan 9, 2017

Like this feature there has been a PR for lua-resty-core for 2 years. It needs a rebase & for the argument order to be re-ordered.

There is also a PR for the stream module that needs upgrading for the argument order same as this one.

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@splitice For your pull requests to be merged, they have to pass the review process. Thank you for your understanding :)

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@splitice So please do not blame us for not merging your old PRs for years. They just never passed the review process like the lack of test cases and etc in your old PRs.

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@splitice I do appreciate your contributions a lot and I also hope that you can respect our review process and PR merging policies. Thank you!

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@splitice We're already trying our best to collaborate and cooperate with our contributors. I hope that you can see that from our active review feedback and etc.

@agentzh
Copy link
Member

agentzh commented Jan 9, 2017

@splitice Consider that these are all volunteering work.

@splitice
Copy link
Author

splitice commented Jan 9, 2017

And I too am volunteering my time to merge upstream suitable features developed on projects I am involved with. We are all volunteers here. It's fine to do a review but the constant back and forth over small style fixes that would have taken you less time to fix than to comment on is just wasteful. Due to the time wasted by this not even being looked at that I am now investing time in rebasing & re-ordering the parameters (the new order is only required due to the time-lag, and IMHO less consistent ordering considering set/add).

At the end of the day its your project and you can accept changes however you please. But just take a look at the ancient PRs, plenty of good features abandoned there. Plenty that even look complete.

As this was submitted 2-3 years ago and never processed, none of our other patches have been even considered for pushing upstream. To give you an idea of the PRs that you have missed out on from this project alone:

  • ngx.redirect is missing support for HTTP See Other
  • user_flags in incr's return value consistent with get (quite useful for setting targets and some atomic structures)

Now back to this PR, you can quite easily make any minor style changes you so desire. You should know how, merge it into a feature branch, add a commit and then merge to master. Done and dusted. Going back and forth with minor style changes over years is only wasting both of our times. I'm sure it takes you longer to write your comment than to add a newline.

Now I could go change all the newly added tests, I could also upgrade the existing with the same regex as a separate PR but realistically it's a waste of time as it looks like this code will be replaced with resty-core soon so not worth the time investment. It will either require a re-base, or removed depending on how the code ends up structured. Either way.

Continuing to consider this a fork is fine for us at this point as the path of least resistance.

@thibaultcha
Copy link
Member

This function does not exist anymore since we removed the CFunction implementation (as originally discussed in this PR!) in 947fa00. The FFI implementation of this API has support for the init_ttl argument. Therefore, I will be closing this PR. Thanks for the patch!

@thibaultcha thibaultcha closed this Aug 8, 2019
@splitice
Copy link
Author

splitice commented Aug 8, 2019

FYI init_ttl != expire for anyone using my fork (which I continue to maintain). init_ttl does what it name says while expire continues to bump the TTL (i.e for LRU pattern)

@thibaultcha
Copy link
Member

@splitice Good to know (and important distinction), thanks for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants