Skip to content

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.

}
}

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

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

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
}

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

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

@w4096
Copy link

w4096 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