Skip to content

INTERNAL: Fix a smget handling about trimmed result without bkey #286

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions libmemcached/fetch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ merge_smget_results(memcached_coll_smget_result_st **results,
memset(result_idx, 0, 256*sizeof(size_t));

memcached_coll_sub_key_st *prev_sub_key = NULL;
memcached_coll_sub_key_st *curr_sub_key;
memcached_coll_sub_key_st *curr_sub_key = NULL;

size_t merged_count= 0;
size_t found_count= 0;
Expand Down Expand Up @@ -627,7 +627,7 @@ merge_smget_results(memcached_coll_smget_result_st **results,
for (size_t i=0; i<merged->trimmed_key_count; i++)
{
int smallest_idx= -1;
int comp_result;
int comp_result= 0;
bool should_merge= false;
for (size_t j=0; j<num_results; j++)
{
Expand Down Expand Up @@ -666,15 +666,17 @@ merge_smget_results(memcached_coll_smget_result_st **results,

if (merged->value_count < merged->count)
{
/* compare it with the bkey of the last found element */
prev_sub_key = &merged->sub_keys[merged->value_count-1];
curr_sub_key = &results[smallest_idx]->trimmed_sub_keys[result_idx[smallest_idx]];
if (byte_array_bkey) {
comp_result= memcached_compare_two_hexadecimal(&prev_sub_key->bkey_ext,
&curr_sub_key->bkey_ext);
} else {
comp_result= (prev_sub_key->bkey == curr_sub_key->bkey) ? 0
: (prev_sub_key->bkey < curr_sub_key->bkey) ? -1 : 1;
if (merged->value_count > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

์กฐ๊ฑด๋ฌธ์„ ์•„๋ž˜์™€ ๊ฐ™์ด ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‚˜์š”?
value_count๊ฐ€ 0์ด๋ฉด, trimed_keys๋ฅผ mergeํ•˜์ง€ ์•Š์•„์•ผ ํ•˜๋‚˜์š”?

if (merged->value_count == 0) {
    should_merge = true;
} else if (merged->value_count < merged->count) {
    /*
     * compare sub_keys
     */

    if (comp_result <= 0) {
        should_merge = true;
    }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

value_count๊ฐ€ 0์ด๋ฉด, trimed_keys๋ฅผ mergeํ•˜์ง€ ์•Š์•„์•ผ ํ•˜๋‚˜์š”?

์ž˜ ๋ชจ๋ฅด๊ฒ ๋„ค์š”. ์ข€ ๋” ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ƒํ™ฉ์„ ๊ณ ๋ คํ•ด์„œ ๋‹ค์‹œ ์งœ์•ผํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
๊ทธ๋Ÿฌ๋ฏ€๋กœ ์ž ์‹œ ํ•ด๋‹น PR์€ ๋ณด๋ฅ˜ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

value_count == 0 ์ธ ์ƒํ™ฉ์—์„œ should_merge๊ฐ€ ๋˜์–ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์€
Trimed key๊ฐ€ ํƒ์ƒ‰ํ•œ ํƒ์ƒ‰ํ•œ Btree ๋‚ด ๋ฒ”์œ„ ์ค‘ ์ตœ์†Œ์—ฌ์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด ๋ณด์žฅ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

โ†“       Search Range        โ†“   
----- |--Not Trimmed--| |--Trimed--|

But, all skipped by eflag!

/* compare it with the bkey of the last found element */
prev_sub_key = &merged->sub_keys[merged->value_count-1];
curr_sub_key = &results[smallest_idx]->trimmed_sub_keys[result_idx[smallest_idx]];
if (byte_array_bkey) {
comp_result= memcached_compare_two_hexadecimal(&prev_sub_key->bkey_ext,
&curr_sub_key->bkey_ext);
} else {
comp_result= (prev_sub_key->bkey == curr_sub_key->bkey) ? 0
: (prev_sub_key->bkey < curr_sub_key->bkey) ? -1 : 1;
}
}
if (comp_result <= 0) {
should_merge= true;
Expand Down Expand Up @@ -759,6 +761,8 @@ memcached_coll_smget_fetch_result(memcached_st *ptr,
*error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
break;
}

each_result->sub_key_type = result->sub_key_type;
}

char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
Expand Down
17 changes: 12 additions & 5 deletions libmemcached/response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,12 @@ static void textual_switchover_peer_check(memcached_server_write_instance_st ins
if (str_length < buf_length) {
/* OK */
memcpy(instance->switchover_peer, startptr, str_length);
instance->switchover_peer[str_length]= '\0';
instance->switchover_peer[str_length]= '\0';
instance->switchover_sidx= -1; /* undefined */
} else {
/* something is wrong */
memcpy(instance->switchover_peer, startptr, buf_length-1);
instance->switchover_peer[buf_length-1]= '\0';
instance->switchover_peer[buf_length-1]= '\0';
instance->switchover_sidx= 1; /* set first slave */
}
}
Expand Down Expand Up @@ -2002,12 +2002,17 @@ static memcached_return_t textual_coll_smget_value_fetch(memcached_server_write_
/* byte array bkey : starts with 0x */
if (to_read_string[0] == '0' && to_read_string[1] == 'x')
{
if (result->sub_key_type != MEMCACHED_COLL_QUERY_BOP_EXT &&
result->sub_key_type != MEMCACHED_COLL_QUERY_BOP_EXT_RANGE)
return MEMCACHED_PROTOCOL_ERROR;
memcached_conv_str_to_hex(ptr->root, to_read_string+2, read_length-2-1, &result->sub_keys[i].bkey_ext); // except '0x' and '\0'
result->sub_key_type = MEMCACHED_COLL_QUERY_BOP_EXT;
}
/* normal bkey */
else
{
if (result->sub_key_type != MEMCACHED_COLL_QUERY_BOP &&
result->sub_key_type != MEMCACHED_COLL_QUERY_BOP_RANGE)
return MEMCACHED_PROTOCOL_ERROR;
result->sub_keys[i].bkey = strtoull(to_read_string, &string_ptr, 10);
result->sub_key_type = MEMCACHED_COLL_QUERY_BOP;
}
Expand Down Expand Up @@ -2280,7 +2285,8 @@ static memcached_return_t textual_coll_smget_trimmed_key_fetch(memcached_server_
{
memcached_conv_str_to_hex(ptr->root, to_read_string+2, read_length-2-1,
&result->trimmed_sub_keys[i].bkey_ext); // except '0x' and '\0'
if (result->sub_key_type != MEMCACHED_COLL_QUERY_BOP_EXT)
if (result->sub_key_type != MEMCACHED_COLL_QUERY_BOP_EXT &&
result->sub_key_type != MEMCACHED_COLL_QUERY_BOP_EXT_RANGE)
{
memcached_string_free(&result->trimmed_keys[i]);
return MEMCACHED_PROTOCOL_ERROR;
Expand All @@ -2290,7 +2296,8 @@ static memcached_return_t textual_coll_smget_trimmed_key_fetch(memcached_server_
else
{
result->trimmed_sub_keys[i].bkey = strtoull(to_read_string, &string_ptr, 10);
if (result->sub_key_type != MEMCACHED_COLL_QUERY_BOP)
if (result->sub_key_type != MEMCACHED_COLL_QUERY_BOP &&
result->sub_key_type != MEMCACHED_COLL_QUERY_BOP_RANGE)
{
memcached_string_free(&result->trimmed_keys[i]);
return MEMCACHED_PROTOCOL_ERROR;
Expand Down
Loading