-
Notifications
You must be signed in to change notification settings - Fork 2k
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
New atomic functions(cas, cog) for shm #1955
base: master
Are you sure you want to change the base?
Conversation
9bd4136
to
ee71300
Compare
Hi, @Miniwoffer I was wondering what the |
cas(compare and swap) cas refers to the atomic operation(https://en.wikipedia.org/wiki/Compare-and-swap), and is also used by memcached amogst others. |
LGTM. @zhuizhuhaomeng @doujiang24 could you help with this PR ? |
I'm fine with the |
|
||
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua** | ||
|
||
Similar to the [get](#ngxshareddictget) method, but only returns if |
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.
What does the "only returns if" part mean? If the if condition is not met, this method will never return? It cannot be. Maybe you mean "will only return the value and the flags" here? And you should also be explicit about what values it returns otherwise (like two nil values?)
The cog
name is a bit confusing. How about get_if_not_eq
?
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.
Yeah the "only returns if" part is not true.
Maybe something like:
Similar to the [get](#ngxshareddictget) method, but if ``old_value`` and
``old_flags`` match value and flag in dictionary ngx.shared.DICT,
returns ``nil, true``.
I'm fine with get_if_not_eq
`old_value` or `old_flags` do not match. | ||
|
||
If `old_value` or `old_flags` is `nil` | ||
it will be ignored when comparing. |
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 semantics does not feel right to me. When old value is nil, then it means the expected value in the shdict should also be nil. It should not get ignored? So it always return nil, nil
in this case?
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 function first lookups the key, and if cant find it return nil, nil
.
And after that apply comparison logic.
The reason for the "don't compare nil
" is because of old_flags
, and i simply tried to have old_value
and old_flags
act as similar as possible.
For old_flags
i added a distinction between 0
and nil
simply because it adds more functionality compared to having nil == 0
.
Its also the fact that flags cannot exist if value is nil
. Does that make flags nil
or 0
maybe both maybe neither?
Having different logic where only old_flags
is not compared when nil
, might be best.
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.
When old value is nil, it should be ignored when comparing (so value could be anything), when old flag is nil, flag is ignored.
This way the api user could have either old_value or old_flag (or both) and whichever is not nil will be compared to the value in shm
Hi @Miniwoffer, may I ask if there is a recent update commit in this PR? |
I was waiting for a comment on my answer to @agentzh s question. For some reason my comments are hidden Il just commit my suggestions |
5287368
to
3e36f86
Compare
- Added cas(compare and swap) to shdict - Added get_if_not_eq to shdict
3e36f86
to
83b71eb
Compare
In In the case of Same goes for We could off course add
and have the same logic, if the API is too unintelligible. I could also try and rewrite the documentation, if wording similar to |
This pull request is now in conflict :( |
I would strongly prefer |
@LoganDark But then again maybe that can be an advantage, forcing the user not to make assumptions about its functionality. @xiaocang |
The best thing that can be done for documentation is to ensure the README is complete and up-to-date; this allows the creation of typings: Since the README is already incredibly detailed and useful, I feel like
I would not consider this an advantage or a disadvantage. Warnings about implementation details belong in the documentation. |
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.
See: #1954