Skip to content
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

Use fake client flag to replace not conn check #1198

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from

Conversation

enjoy-binbin
Copy link
Member

The fake client flag was introduced in #1063,
we want this to replace all !conn fake client checks.

The fake client flag was introduced in valkey-io#1063, we want
this to replace all !conn fake client checks.

Signed-off-by: Binbin <[email protected]>
Copy link
Member

@PingXie PingXie left a comment

Choose a reason for hiding this comment

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

LGTM

src/networking.c Show resolved Hide resolved
@@ -894,7 +894,7 @@ void updateClientMemoryUsage(client *c) {
}

int clientEvictionAllowed(client *c) {
if (server.maxmemory_clients == 0 || c->flag.no_evict || !c->conn) {
if (server.maxmemory_clients == 0 || c->flag.no_evict || c->flag.fake) {
return 0;
}
int type = getClientType(c);
Copy link
Member

Choose a reason for hiding this comment

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

serverAssert on c->conn?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is good practice. But how do we ensure a new dev/reviewer ensure(s) this? Wouldn't this be better asserted while setting/unsetting the flag in one place? WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be better asserted while setting/unsetting the flag in one place?

I think we would need to create a wrapper like the below and make flag.fake a client internal state.

connection *clientGetConnection(client *c) {
    serverAssert((c->flag.fake && !c->conn) || (!c->flag.fake && c->conn));
    return c->conn;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

the wrapper changed will require a lot of code changes, there a LOT OF code are using c->conn

Copy link
Contributor

Choose a reason for hiding this comment

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

@enjoy-binbin We merge this and file a new issue with help-wanted/good-first-issue tag?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not worried about not doing it myself, i just wonder if it's worth doing (diff causes conflicts).

But looking at the code again, i guess doing this wrapper is indeed a good way to avoid fake client connection issue in the future. I will do it in a later commit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm starting to feel like we might still need to keep c->conn...

Signed-off-by: Binbin <[email protected]>
@@ -894,7 +894,7 @@ void updateClientMemoryUsage(client *c) {
}

int clientEvictionAllowed(client *c) {
if (server.maxmemory_clients == 0 || c->flag.no_evict || !c->conn) {
if (server.maxmemory_clients == 0 || c->flag.no_evict || c->flag.fake) {
return 0;
}
int type = getClientType(c);
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be better asserted while setting/unsetting the flag in one place?

I think we would need to create a wrapper like the below and make flag.fake a client internal state.

connection *clientGetConnection(client *c) {
    serverAssert((c->flag.fake && !c->conn) || (!c->flag.fake && c->conn));
    return c->conn;
}

@enjoy-binbin
Copy link
Member Author

i think the change somehow break the CI, i will take a deep look later.

@enjoy-binbin
Copy link
Member Author

ok, i see the test fail because we have a createCachedResponseClient, it is a fake client but with a connection

Signed-off-by: Binbin <[email protected]>
Copy link

codecov bot commented Oct 27, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 70.66%. Comparing base (a62d1f1) to head (8cbc7d3).
Report is 17 commits behind head on unstable.

Files with missing lines Patch % Lines
src/module.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1198      +/-   ##
============================================
+ Coverage     70.65%   70.66%   +0.01%     
============================================
  Files           114      114              
  Lines         61799    63156    +1357     
============================================
+ Hits          43664    44632     +968     
- Misses        18135    18524     +389     
Files with missing lines Coverage Δ
src/networking.c 88.49% <100.00%> (-0.01%) ⬇️
src/server.c 87.70% <100.00%> (-0.94%) ⬇️
src/server.h 100.00% <ø> (ø)
src/module.c 9.66% <0.00%> (+0.02%) ⬆️

... and 88 files with indirect coverage changes

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.

3 participants