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: Refactor a memcached_fetch function #337

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ing-eoking
Copy link
Collaborator

๐Ÿ”— Related Issue

โŒจ๏ธ What I did

  • memcached_fetch ํ•จ์ˆ˜๊ฐ€ ๋ฆฌํŒฉํ† ๋ง๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
  • use_udp ๋ถ€๋ถ„์„ ํ™•์ธํ•œ ๊ฒฐ๊ณผ, ํ•„์š”ํ•˜์ง€ ์•Š์•„์„œ ์ œ๊ฑฐํ–ˆ์Šต๋‹ˆ๋‹ค.
  • if (result_buffer == NULL || memcached_failed(*error)) ์กฐ๊ฑด๋ฌธ์—์„œ memcached_failed๋ฅผ ์ œ๊ฑฐํ–ˆ์Šต๋‹ˆ๋‹ค.
    • memcached_fetch_result์—์„œ error ๊ฐ’์ด memcached_success๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ, ํ•ญ์ƒ NULL์„ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • libmemcached๋ฅผ ํ™•์ธํ•œ ๊ฒฐ๊ณผ, ๋ณ„๋‹ค๋ฅธ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์€ ์—†๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

@ing-eoking ing-eoking force-pushed the fetch branch 2 times, most recently from b7882cb to b1080f4 Compare January 14, 2025 05:41
Copy link
Contributor

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

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

๋ฆฌ๋ทฐ ์™„๋ฃŒ


if (flags)
*flags= 0;
*error= (result_buffer == NULL) ? *error : MEMCACHED_KEY_TOO_BIG;
Copy link
Contributor

Choose a reason for hiding this comment

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

์•„๋ž˜์™€ ๊ฐ™์ด ํ•ฉ์‹œ๋‹ค.

if (result_buffer != NULL) *error= MEMCACHED_KEY_TOO_BIG;

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_buffer= memcached_fetch_result(ptr, result_buffer, error);
if (result_buffer == NULL or memcached_failed(*error))
if (result_buffer == NULL || result_buffer->key_length > MEMCACHED_MAX_KEY)
Copy link
Contributor

Choose a reason for hiding this comment

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

result_buffer != NULL์ด์ง€๋งŒ, *error ๊ฐ’์ด failture์ธ ๊ฒฝ์šฐ๋Š” ์—†๋‹ค๋Š” ๊ฒƒ์ด์ฃ ?

memcached_fetch_result() ํ•จ์ˆ˜์—์„œ
result_buffer != NULL์ด๋ฉด์„œ result_buffer->key_length > MEMCACHED_MAX_KEY ๊ฒฝ์šฐ
MEMCACHED_KEY_TOO_BIG ์—๋Ÿฌ ์„ค์ •ํ•˜์—ฌ ๋ฆฌํ„ดํ•˜๋ ค๋Š” ์˜๋„๊ฐ€ ์žˆ์—ˆ๋˜ ๊ฒƒ์ด ์•„๋‹Œ์ง€ ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

์˜๋„๊นŒ์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์œผ๋‚˜ memcached_fetch_result์—์„œ MEMCACHED_MAX_KEY๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ˜•ํƒœ๊ฐ€ ๋” ์ž์—ฐ์Šค๋Ÿฌ์šด ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

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
๋…ผ๋ฆฌ์ ์œผ๋กœ ๋ด์„œ,
result_buffer->key_length > MEMCACHED_MAX_KEY ์ธ ๊ฒฝ์šฐ ์˜ค๋ฅ˜๋ฅผ ๋ฆฌํ„ดํ•  ํ•„์š”๋Š” ์—†์–ด ๋ณด์ž…๋‹ˆ๋‹ค.

ํŠนํžˆ๋‚˜, memcached_fetch()์—์„œ๋Š” key์— ๋Œ€ํ•ด ๊ด€์‹ฌ์ด ์—†๊ณ  ๋‹จ์ง€ value๋งŒ ์กฐํšŒํ•˜๋Š” ๊ฒฝ์šฐ์ž…๋‹ˆ๋‹ค.
์ด๋Ÿฌํ•œ ์กฐ๊ฑด ๊ฒ€์‚ฌ๊ฐ€ ๋“ค์–ด๊ฐ„ ์ด์œ ๋ฅผ ๊ฐ„๋‹จํžˆ ํ™•์ธํ•ด ๋ณผ ์ˆ˜ ์žˆ์„๊นŒ์š”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jhpark816

libmemcached ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋ฅผ ํ™•์ธํ•œ ๊ฒฐ๊ณผ, ๋”ฐ๋กœ ์ด์œ ๋ฅผ ์ ์–ด ๋†“์ง€๋Š” ์•Š์•˜์Šต๋‹ˆ๋‹ค.
awesomized/libmemcached#7e592f0

We now check return key size for memcached_fetch() to make sure it is not
too big (compared to original ascii server). result_st is now initialized 
differently. This should make it a bit faster.

ํ•˜์ง€๋งŒ result_buffer->key_length > MEMCACHED_MAX_KEY ๋น„๊ต๋ฅผ memcached_fetch๋‚˜ memcached_fetch_result์—์„œ ํ•˜๋Š” ๊ฒƒ์€ ๋‹ค์†Œ ๋ถ€์ž์—ฐ์Šค๋Ÿฌ์›Œ ๋ณด์ž…๋‹ˆ๋‹ค.

result_buffer ๊ตฌ์กฐ์ฒด ๋‚ด์˜ item_key ๋ณ€์ˆ˜๊ฐ€ ์ด๋ฏธ MEMCACHED_MAX_KEY ํฌ๊ธฐ๋กœ ๊ณ ์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
ํ‚ค๋ฅผ ์ €์žฅํ•  ๋•Œ ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ ์ด๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์ด ๋” ์ ํ•ฉํ•˜์ง€ ์•Š์„๊นŒ ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค.

struct memcached_result_st {
  ...
  size_t key_length;
  ...
  char item_key[MEMCACHED_MAX_KEY];
  ...
};

@ing-eoking ing-eoking force-pushed the fetch branch 3 times, most recently from 913a854 to c8c28b1 Compare January 14, 2025 08:32
Copy link
Contributor

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

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

๋ฆฌ๋ทฐ ์™„๋ฃŒ

else if (result->key_length > MEMCACHED_MAX_KEY)
{
*error= MEMCACHED_KEY_TOO_BIG;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

result๊ฐ€ ์กด์žฌํ•  ๊ฒฝ์šฐ๋Š” ์œ„์—์„œ ์ด๋ฏธ return ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์ด ์ฝ”๋“œ๊ฐ€ ์ˆ˜ํ–‰๋  ์ˆ˜๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

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() ํ˜ธ์ถœํ•˜๋Š” ๊ฒฝ์šฐ๋Š” memcached_fetch() ์™ธ์— ๋‹ค๋ฅธ ๊ฒฝ์šฐ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

MEMCACHED_KEY_TOO_BIG ์˜ค๋ฅ˜๋ฅผ ๋ฆฌํ„ดํ•˜๊ฒŒ ๋งŒ๋“ค๋ฉด, ๋‹ค๋ฅธ ํ˜ธ์ถœ ๊ฒฝ์šฐ์—๋„ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•œ ์ƒํƒœ์ธ๊ฐ€์š”?
ํ™•์ธํ•˜๊ธฐ ์–ด๋ ต๋‹ค๋ฉด, ํ˜„์žฌ๋กœ๋Š” ์ฒ˜์Œ PR ์ฒ˜๋Ÿผ memcached_fetch()์—์„œ๋งŒ MEMCACHED_KEY_TOO_BIG ์˜ค๋ฅ˜๋ฅผ ์„ค์ •ํ•˜๊ฒŒ ํ•˜๋Š” ๊ฒƒ๋„ ๊ดœ์ฐฎ์„ ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

์šฐ์„  ์ด์ „ PR๋กœ ๋ณต๊ตฌํ–ˆ์Šต๋‹ˆ๋‹ค.

MEMCACHED_KEY_TOO_BIG ์˜ค๋ฅ˜๋ฅผ ๋ฆฌํ„ดํ•˜๊ฒŒ ๋งŒ๋“ค๋ฉด, ๋‹ค๋ฅธ ํ˜ธ์ถœ ๊ฒฝ์šฐ์—๋„ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•œ ์ƒํƒœ์ธ๊ฐ€์š”?

๋”ฐ๋กœ ํ™•์ธ์€ ํ•˜์ง„ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ, memcached_fetch_result()๊ฐ€ ๊ณต๊ฐœ๋œ API๋ผ ๋‚ด๋ถ€์—์„œ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค๊ณ  ํ•ด์„œ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๊ณ  ๋‹จ์ •ํ•  ์ˆ˜๋Š” ์—†์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

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.

2 participants