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

redis scan command support #678

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

lukemakeit
Copy link

Problem

redis scan command not support.

Solution

image

Note:
server_idx is saved by the lowest 12 bits of cursor, so the number of servers of the twemproxy must be less than 4096.

Result

1.1.1.1:60100> scan 0
1) "1"
2) 1) "d"
   2) "b"
   3) "c"
   4) "a"
1.1.1.1:60100> scan 1
1) "0"
2) 1) "a"
   2) "b"

r->max_server_idx=(pool->server).nelem;
}else{
idx = server_pool_idx(pool, key, keylen);
}
Copy link

Choose a reason for hiding this comment

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

Change the cursor of request in req_filter and save the server_index on msg in the mean time.

@@ -3053,6 +3069,46 @@ redis_post_coalesce_mget(struct msg *request)
}
}

void redis_post_coalesce_scan(struct msg *request) {
Copy link

Choose a reason for hiding this comment

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

move those code in rsp_filter

@@ -2963,6 +2976,9 @@ redis_fragment(struct msg *r, uint32_t nserver, struct msg_tqh *frag_msgq)
case MSG_REQ_REDIS_MSET:
return redis_fragment_argx(r, nserver, frag_msgq, 2);

case MSG_REQ_REDIS_SCAN:
return redis_fragment_scan(r,frag_msgq);
Copy link

Choose a reason for hiding this comment

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

The scan command doesn't need fragment, the thing you want do is change the cursor, you can do this in req_filter.
When response received you need change the cursor again, you can do this in rsp_filter.

src/nc_server.h Outdated
@@ -137,7 +137,7 @@ void server_connected(struct context *ctx, struct conn *conn);
void server_ok(struct context *ctx, struct conn *conn);

uint32_t server_pool_idx(const struct server_pool *pool, const uint8_t *key, uint32_t keylen);
struct conn *server_pool_conn(struct context *ctx, struct server_pool *pool, const uint8_t *key, uint32_t keylen);
struct conn *server_pool_conn(struct context *ctx, struct server_pool *pool, const uint8_t *key, uint32_t keylen, struct msg *msg);
Copy link

Choose a reason for hiding this comment

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

I think put msg in front of key and keylen is better.

src/nc_server.c Outdated
nc_memcpy(key,arr,keylen);
}
r->scan_server_idx=idx;
r->max_server_idx=(pool->server).nelem;
Copy link

Choose a reason for hiding this comment

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

I think max_server_idx is unnecessary, since you can always known the number of server by array_n(&pool->server) .

@lukemakeit
Copy link
Author

Hi @wy-ei , I have re-committed according to your suggestion, thanks.

src/nc_request.c Outdated
@@ -511,6 +520,31 @@ req_filter(struct conn *conn, struct msg *msg)
msg->noforward = 1;
}

if (msg->type == MSG_REQ_REDIS_SCAN) {
ASSERT(array_n(msg->keys) > 0);
Copy link

Choose a reason for hiding this comment

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

move this into a function and call the function here like what you did in rsp_filter.

Copy link
Author

Choose a reason for hiding this comment

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

Good advice

@@ -300,6 +301,8 @@ struct msg {
unsigned fdone:1; /* all fragments are done? */
unsigned swallow:1; /* swallow response? */
unsigned redis:1; /* redis? */

uint32_t server_index; /* used for store the redis server index in server pool */
};
Copy link

Choose a reason for hiding this comment

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

this comment is not clear enough. how about this one:

the server index which the requstion should be forwarded.

Copy link
Author

Choose a reason for hiding this comment

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

this comment is not clear enough. how about this one:

the server index which the requstion should be forwarded.

ok

@wy-ei
Copy link

wy-ei commented Jan 13, 2023

@lukexwang

I have see the change you made. it's better. And I think the code can be optimized again. I have leave some more suggestions.

@lukemakeit
Copy link
Author

Hi @wy-ei , thank you for your suggestion. I have re-committed.

@lukemakeit
Copy link
Author

Hello @wy-ei , 空了辛苦看下哈 ^_^

@yuerugou54
Copy link

yuerugou54 commented Feb 7, 2023 via email

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