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

INTERNAL: Remove dummy fetch in the get API #334

Merged
merged 1 commit into from
Feb 20, 2025
Merged
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
53 changes: 29 additions & 24 deletions libmemcached/get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ char *memcached_get_by_key(memcached_st *ptr,
{
arcus_server_check_for_update(ptr);

if (value_length)
*value_length= 0;

if (flags)
*flags= 0;

memcached_return_t unused;
if (error == NULL)
error= &unused;
Expand All @@ -503,11 +509,6 @@ char *memcached_get_by_key(memcached_st *ptr,
*error= memcached_last_error(ptr);
}

if (value_length)
{
*value_length= 0;
}

return NULL;
}

Expand Down Expand Up @@ -540,20 +541,36 @@ char *memcached_get_by_key(memcached_st *ptr,
*error= memcached_last_error(ptr);
}

if (value_length)
*value_length= 0;

return NULL;
}

char *value= memcached_fetch(ptr, NULL, NULL,
value_length, flags, error);
char *value= NULL;
bool is_value_fetched= false;
memcached_result_st *result= &ptr->result;

while (memcached_fetch_result(ptr, result, error) != NULL)
{
is_value_fetched= true;
if (value != NULL)
libmemcached_free(ptr, value);
value= memcached_string_take_value(&result->value);
if (value_length)
*value_length= memcached_string_length(&result->value);
if (flags)
*flags= result->item_flags;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

memcached_fetch_result() != NULL ๊ฒฝ์šฐ๊ฐ€ 2ํšŒ ์ด์ƒ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ๋„ ๊ณ ๋ คํ•˜์‹œ์ฃ .

This comment was marked as off-topic.

Copy link
Contributor

Choose a reason for hiding this comment

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

memcached_fetch_result() != NULL ๊ฒฝ์šฐ๊ฐ€ 2ํšŒ ์ด์ƒ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ๋„ ๊ณ ๋ คํ•˜์‹œ์ฃ .

์˜ˆ์ „์— ์ด๋ ‡๊ฒŒ ์ฝ”๋ฉ˜ํŠธ ํ–ˆ์ง€๋งŒ, ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ๋ณด๋Š” ๊ฒƒ์ด ๋งž๊ฒ ์ฃ ?
๋งŒ์•ฝ์˜ SW ๋ฒ„๊ทธ๋ฅผ ๊ณ ๋ คํ•˜๋”๋ผ๋„ END ์ด์ „์˜ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  *error = ENGINE_SUCCESS;
  while (memcached_fetch_result(ptr, result, error) != NULL)
  {
    value= memcached_string_take_value(&result->value);
    if (value_length)
      *value_length= memcached_string_length(&result->value);
    if (flags)
      *flags= result->item_flags;
  }

Copy link
Contributor

Choose a reason for hiding this comment

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

while loop ์•ˆ์— ์•„๋ž˜ ์ฝ”๋“œ๊ฐ€ ์žˆ์–ด์•ผ ํ•˜์ฃ ?

if (value) 
  memcached_free(value);


assert_msg(ptr->query_id >= query_id +1, "Programmer error, the query_id was not incremented.");
//assert_msg(ptr->query_id == query_id +1, "Programmer error, the query_id was not incremented.");

/* This is for historical reasons */
if (*error == MEMCACHED_END)
if (is_value_fetched)
Copy link
Contributor

Choose a reason for hiding this comment

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

is_value_fetched ๋ผ๋Š” ๋ณ€์ˆ˜๊ฐ€ ํ•„์š”ํ•œ๊ฐ€์š”?

์•„๋ž˜์™€ ๊ฐ™์ด ๊ฒ€์‚ฌํ•˜๋ฉด ๋˜์ง€ ์•Š๋‚˜์š”?

if (value) 

{
*error= MEMCACHED_SUCCESS;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

success_occurred ๊ฒฝ์šฐ๋Š” value != NULL ์ƒํƒœ์ž…๋‹ˆ๋‹ค.
success_occurred ๋ณ€์ˆ˜๊ฐ€ ํ•„์š” ์—†์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ , ์ด๋Ÿฌํ•œ ์ฝ”๋“œ๋Š” value == NULL ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ ์ฝ”๋“œ ๋‹ค์Œ์— ์œ„์น˜ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

Copy link
Collaborator Author

@ing-eoking ing-eoking Jan 17, 2025

Choose a reason for hiding this comment

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

value์— ๋นˆ ๋ฌธ์ž์—ด์„ ์ €์žฅํ–ˆ์„ ๊ฒฝ์šฐ, value == NULL์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์šฉ์–ด๋ฅผ success_occurred์—์„œ is_value_fetched๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ing-eoking
์งˆ๋ฌธ์ž…๋‹ˆ๋‹ค.

  • value == ""(๋นˆ ๋ฌธ์ž์—ด)์„ ์ €์žฅํ•˜๊ณ  ๋‚˜์„œ, ์ด๋ฅผ ์กฐํšŒํ•˜๋ฉด ๋นˆ ๋ฌธ์ž์—ด์ด ๋ฆฌํ„ด๋˜์–ด์•ผ ํ•˜์ง€ ์•Š๋‚˜์š”?
  • value == NULL๋กœ ํ•ด์„œ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‚˜์š”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

result->value์—๋Š” ๋นˆ ๋ฌธ์ž์—ด์ด ๋“ค์–ด๊ฐ€๋Š”๋ฐ, ์ด๋ฅผ ๋‹ค์‹œ value์— copyํ•˜์—ฌ ๋„ฃ๋Š” ๊ณผ์ •์—์„œ NULL๋กœ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค.
memcached_string_take_value ํ•จ์ˆ˜ ๋‚ด๋ถ€ ๋™์ž‘์—์„œ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๊ฐ€ 0์ด๋ฉด NULL์„ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค

if (not memcached_string_length(string))
    return NULL;

Copy link
Contributor

Choose a reason for hiding this comment

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

value == NULL๋กœ ํ•ด์„œ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‚˜์š”?

Copy link
Collaborator Author

@ing-eoking ing-eoking Feb 19, 2025

Choose a reason for hiding this comment

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

value == NULL๋กœ ํ•ด์„œ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‚˜์š”?

๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์„œ๋ฒ„ ์ธก์—์„œ๋Š” value์— NULL ๊ฐ’์„ ์ €์žฅํ•  ์ˆ˜ ์—†์œผ๋ฉฐ,
ํด๋ผ์ด์–ธํŠธ ์ธก์—๋„ NULL Value๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ธฐ๋Šฅ์ด ์—†์Šต๋‹ˆ๋‹ค.

Copy link
Contributor

Choose a reason for hiding this comment

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

value = NULL, value_length = 0์œผ๋กœ ํ•˜์—ฌ set ํ•˜๋ฉด ์–ด๋–ค ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋‚˜์š”?

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_length๊ฐ€ 0์ด๋ฏ€๋กœ ๋นˆ๋ฌธ์ž์—ด์ด ๋“ค์–ด๊ฐ€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

memcached_set(memc, "i", 1, NULL, 0, 0, 0);
/* telnet */
get i
VALUE i 0 0

END

else if (*error == MEMCACHED_END)
{
*error= MEMCACHED_NOTFOUND;
}

if (value == NULL)
{
Expand Down Expand Up @@ -607,18 +624,6 @@ char *memcached_get_by_key(memcached_st *ptr,
return NULL;
}

size_t dummy_length;
uint32_t dummy_flags;
memcached_return_t dummy_error;

char *dummy_value= memcached_fetch(ptr, NULL, NULL,
&dummy_length, &dummy_flags,
&dummy_error);
assert_msg(dummy_value == 0, "memcached_fetch() returned additional values beyond the single get it expected");
assert_msg(dummy_length == 0, "memcached_fetch() returned additional values beyond the single get it expected");
assert_msg(ptr->query_id >= query_id +1, "Programmer error, the query_id was not incremented.");
//assert_msg(ptr->query_id == query_id +1, "Programmer error, the query_id was not incremented.");

return value;
}

Expand Down
Loading