lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

New atomic functions(cas, cog) for shm

Open Miniwoffer opened this issue 4 years ago • 11 comments

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

See: https://github.com/openresty/lua-nginx-module/issues/1954

Miniwoffer avatar Oct 28 '21 11:10 Miniwoffer

Hi, @Miniwoffer I was wondering what the cas and cog abbreviations refer to? seems not very common

xiaocang avatar Nov 01 '21 14:11 xiaocang

cas(compare and swap) cog(compare or get)

cas refers to the atomic operation(https://en.wikipedia.org/wiki/Compare-and-swap), and is also used by memcached amogst others. cog is not a common abbreviations, just something derived from cas.

Miniwoffer avatar Nov 01 '21 14:11 Miniwoffer

LGTM.

@zhuizhuhaomeng @doujiang24 could you help with this PR ?

xiaocang avatar Nov 02 '21 15:11 xiaocang

I'm fine with the cas API. We'd better wait for @agentzh 's comment for the cos API.

doujiang24 avatar Nov 04 '21 03:11 doujiang24

Hi @Miniwoffer, may I ask if there is a recent update commit in this PR?

xiaocang avatar Jan 20 '22 15:01 xiaocang

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 Screenshot from 2022-01-21 15-58-55

Il just commit my suggestions

Miniwoffer avatar Jan 21 '22 15:01 Miniwoffer

@agentzh

In get_if_not_eq, nil for old_value or old_flag is equal to any value. Why? It adds more functionality.

In the case of get_if_not_eq(key, nil, flag) if we where to interpret nil as literal nil it would simply just be a get(key). But if we interpret nil as any it will act as a get_if_flag_not_eq(key, flag).

Same goes for get_if_not_eq(key, value, nil) this would be the same as get_if_not_eq(key, value, 0) since 0==nil in shm. But if we interpret nil as any it would act as a get_if_value_not_eq(key, value)

We could off course add

get_if_value_not_eq(key, value)
get_if_flag_not_eq(key, flag)

and have the same logic, if the API is too unintelligible.

I could also try and rewrite the documentation, if wording similar to nil==any would help.

Miniwoffer avatar Jan 31 '22 09:01 Miniwoffer

This pull request is now in conflict :(

mergify[bot] avatar Mar 15 '22 14:03 mergify[bot]

I would strongly prefer compare_swap over cas, and for the other, compare_get, fetch or something. get_if_not_eq is such a horrible sore to type, I really hope a name like that never makes it into the main release.

LoganDark avatar Apr 10 '22 17:04 LoganDark

@LoganDark I agree that compare_swap and compare_get are cleaner. The only disadvantage is that it's less self-documenting.

But then again maybe that can be an advantage, forcing the user not to make assumptions about its functionality.

@xiaocang Also, this pull request has been idle for a while, and I'm unsure of what to do; is there anything I can do to get the process going?

Miniwoffer avatar Apr 19 '22 08:04 Miniwoffer

it's less self-documenting

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:

image

Since the README is already incredibly detailed and useful, I feel like compare_swap is more than good enough. But keep in mind that's just a suggestion. Even I think compare_get is a little weird, and possibly misleading...

But then again maybe that can be an advantage, forcing the user not to make assumptions about its functionality.

I would not consider this an advantage or a disadvantage. Warnings about implementation details belong in the documentation.

LoganDark avatar Apr 19 '22 09:04 LoganDark