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: Limit the count of elems get from set structure #826

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

Conversation

ing-eoking
Copy link
Collaborator

๐Ÿ”— Related Issue

  • jam2in/arcus-works#571

โŒจ๏ธ What I did

sop get ์—ฐ์‚ฐ์—์„œ ์ผ๋ถ€ element ์กฐํšŒ ์‹œ ๊ฐ€๋Šฅํ•œ ๊ฐœ์ˆ˜๋ฅผ 1000๊ฐœ๋กœ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค.

์ฒ˜์Œ์—๋Š” core(memcached.c)์—์„œ 1000๊ฐœ ์ดํ•˜๋กœ ์กฐํšŒ ๊ฐœ์ˆ˜๋ฅผ ์ œํ•œํ•˜๊ณ  ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ์œผ๋‚˜,
์ด ๊ฒฝ์šฐ, count๊ฐ€ 1000์„ ์ดˆ๊ณผํ•˜๋Š” set์— ๋Œ€ํ•ด ์ „์ฒด ์กฐํšŒ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ–ˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋ž˜์„œ ํ˜„์žฌ PR์€ count ์ •๋ณด๋ฅผ ๊ฐ€์ง„ ์—”์ง„์—์„œ ์ œํ•œ์„ ์ ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

@jhpark816
Copy link
Collaborator

์ฒ˜์Œ์—๋Š” core(memcached.c)์—์„œ 1000๊ฐœ ์ดํ•˜๋กœ ์กฐํšŒ ๊ฐœ์ˆ˜๋ฅผ ์ œํ•œํ•˜๊ณ  ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ์œผ๋‚˜,
์ด ๊ฒฝ์šฐ, count๊ฐ€ 1000์„ ์ดˆ๊ณผํ•˜๋Š” set์— ๋Œ€ํ•ด ์ „์ฒด ์กฐํšŒ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ–ˆ์Šต๋‹ˆ๋‹ค.

์œ„์˜ ์‚ฌํ•ญ์— ๊ด€ํ•œ ์ฝ”๋“œ๋ฅผ ๋ณด์—ฌ์ฃผ์„ธ์š”.

@ing-eoking
Copy link
Collaborator Author

ing-eoking commented Feb 24, 2025

์œ„์˜ ์‚ฌํ•ญ์— ๊ด€ํ•œ ์ฝ”๋“œ๋ฅผ ๋ณด์—ฌ์ฃผ์„ธ์š”.

  • ๋ณ€๊ฒฝํ•˜๋ ค ํ–ˆ๋˜ ์‚ฌํ•ญ์ž…๋‹ˆ๋‹ค.
bool delete = false;
bool drop_if_empty = false;
uint32_t count = 0;

if (! safe_strtoul(tokens[SOP_KEY_TOKEN+1].value, &count)) {
    print_invalid_command(c, tokens, ntokens);
    out_string(c, "CLIENT_ERROR bad command line format");
    return;
}
+ if (count > MAX_SGET_ELM_COUNT) {
+     out_string(c, "CLIENT_ERROR bad value");
+     return;
+ }
if (ntokens == 6) {
    if (strcmp(tokens[SOP_KEY_TOKEN+2].value, "delete")==0) {
        delete = true;
    } else if (strcmp(tokens[SOP_KEY_TOKEN+2].value, "drop")==0) {
        delete = true;
        drop_if_empty = true;
    } else {
        print_invalid_command(c, tokens, ntokens);
        out_string(c, "CLIENT_ERROR bad command line format");
        return;
    }
}

process_sop_get(c, key, nkey, count, delete, drop_if_empty);

์ด ๊ฒฝ์šฐ, ์œ ๋‹›ํ…Œ์ŠคํŠธ coll_sop_unittest.t ์—์„œ ์ „์ฒด element๋ฅผ ์กฐํšŒํ•˜๋Š” ์•„๋ž˜๊ฐ™์€ ๋กœ์ง์ด ์‹คํŒจํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

assert_sop_get("skey 50000", $flags, 50000, 0, 49999); /* fail */
assert_sop_get("skey 0",     $flags, 50000, 0, 49999); /* success */

Copy link
Collaborator

@namsic namsic left a comment

Choose a reason for hiding this comment

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

sop get skey 50000๊ณผ sop get skey 0์ด ์—”์ง„ ๋‚ด๋ถ€์—์„œ๋Š” ๋™์ผํ•œ ์ „์ฒด ์กฐํšŒ ์š”์ฒญ์ด๋ผ๊ณ  ํ•˜๋”๋ผ๋„
ํด๋ผ์ด์–ธํŠธ ์ž…์žฅ์—์„œ๋Š” ์ „์ฒด elem ๊ฐœ์ˆ˜๋ฅผ ๋ช…ํ™•ํžˆ ์•Œ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‘ ์š”์ฒญ์—๋Š” ์˜๋ฏธ ์ƒ ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ sop get skey 50000์€ ์‹คํŒจํ•˜๊ณ  sop get skey 0์€ ์„ฑ๊ณตํ•˜๋Š” ๊ฒƒ์ด ํŠน๋ณ„ํžˆ ์–ด์ƒ‰ํ•ด๋ณด์ด์ง€๋Š” ์•Š๋Š”๋ฐ์š”.
ํ…Œ์ŠคํŠธ๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ํŽธ์ด ์˜คํžˆ๋ ค ์ž์—ฐ์Šค๋Ÿฌ์šด ๋ฐฉํ–ฅ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

@ing-eoking
Copy link
Collaborator Author

@namsic

์šฐ์„  ์ˆ˜์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์•„๋ž˜๋Š” ์งˆ๋ฌธ์‚ฌํ•ญ ์ž…๋‹ˆ๋‹ค.

ํด๋ผ์ด์–ธํŠธ ์ž…์žฅ์—์„œ๋Š” ์ „์ฒด elem ๊ฐœ์ˆ˜๋ฅผ ๋ช…ํ™•ํžˆ ์•Œ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‘ ์š”์ฒญ์—๋Š” ์˜๋ฏธ ์ƒ ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํด๋ผ์ด์–ธํŠธ์—์„œ getattr์„ ํ†ตํ•ด ์ „์ฒด elem ๊ฐœ์ˆ˜๋ฅผ ์•Œ ์ˆ˜ ์žˆ์ง€ ์•Š๋‚˜์š”?

ํ˜„์žฌ sop get์€ max_count๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ๊ฐ’๋„ ์„ฑ๊ณตํ•˜๊ฒŒ ๋” ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด sop get MAXIMUM_MAX_COLL_SIZE ๊ฐ™์€ ๋ช…๋ น์–ด๋Š” ์ „์ฒด ์กฐํšŒ๋กœ ๋ด๋„ ๋˜์ง€ ์•Š์„๊นŒ์š”?

@namsic
Copy link
Collaborator

namsic commented Feb 26, 2025

element๊ฐ€ ์ถ”๊ฐ€๋˜๊ฑฐ๋‚˜ ์ œ๊ฑฐ๋˜๋Š” set item์ด ์žˆ์„ ๋•Œ, ๊ฐ™์€ ๋ช…๋ น์ด ์–ด๋–จ ๋•Œ๋Š” ์„ฑ๊ณตํ•˜๊ณ  ์–ด๋–จ ๋•Œ๋Š” ์‹คํŒจํ•˜๋Š” ๊ฒƒ์ด ์ง๊ด€์ ์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

getattr ๋ช…๋ น์„ ์ˆ˜ํ–‰ํ•˜์—ฌ elem ๊ฐœ์ˆ˜๋ฅผ ํ™•์ธํ•œ ๋’ค์— ๊ทธ์— ๋งž์ถฐ ์ „์ฒด ์กฐํšŒ ์š”์ฒญ์„ ๋ณด๋‚ด์•ผ ํ•  ์ด์œ ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.
๋˜ํ•œ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ํ™•์ธํ•œ elem ๊ฐœ์ˆ˜๊ฐ€ sop get ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์‹œ์ ์˜ elem ๊ฐœ์ˆ˜์™€ ์ผ์น˜ํ•œ๋‹ค๋Š” ๋ณด์žฅ์ด ์—†์Šต๋‹ˆ๋‹ค.

0๊ฐ’์„ ์ „์ฒด ์กฐํšŒ๋กœ ์ •์˜ํ•˜๊ณ  ์žˆ๋Š” ์ƒํƒœ์—์„œ, sop get key 999999 ์™€ ๊ฐ™์€ ์š”์ฒญ์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š์•„๋„ ์›ํ•˜๋Š” ์š”๊ตฌ์‚ฌํ•ญ์„ ๋งŒ์กฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ธฐ์กด์— ์ „์ฒด ์กฐํšŒ ๋ชฉ์ ์œผ๋กœ count๋ฅผ ์ถฉ๋ถ„ํžˆ ํฐ ์ˆ˜๋กœ ์„ค์ •ํ•˜์—ฌ ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์—ˆ๋‹ค๋ฉด, ์ธ์ž๋ฅผ 0์œผ๋กœ ์ฃผ์–ด ์š”์ฒญํ•˜๋„๋ก ๊ฐ€์ด๋“œํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.


์—”์ง„ ๊ตฌํ˜„์ฒด์˜ ํŠน์„ฑ์ด๋‚˜ ์ฒ˜๋ฆฌ ๋Šฅ๋ ฅ์— ๋”ฐ๋ผ count ์ œ์•ฝ์ด ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์—”์ง„ ๋‚ด๋ถ€์—์„œ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์ž์—ฐ์Šค๋Ÿฌ์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ smget ๋“ฑ ๊ธฐ์กด ๊ตฌํ˜„์—์„œ๋„ ์ธ์ž๋ฅผ core์—์„œ ํ™•์ธํ•˜๊ณ  ์ฒ˜๋ฆฌํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

memcached.h Outdated
@@ -84,6 +84,7 @@
#define BIN_PKT_HDR_WORDS (MIN_BIN_PKT_LENGTH/sizeof(uint32_t))

#define MAX_MGET_KEY_COUNT 10000
#define MAX_SGET_ELM_COUNT 1000
Copy link
Collaborator

Choose a reason for hiding this comment

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

ํŠน๋ณ„ํžˆ ๋ณ€๊ฒฝ ์•„์ด๋””์–ด๊ฐ€ ์žˆ๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๊ณ , ์ฐธ๊ณ  ์‚ฌํ•ญ์œผ๋กœ ๊ฐœ์ธ ์˜๊ฒฌ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค.

โ€ฆMGET_โ€ฆ๊ณผ โ€ฆSGET_์ด ๋ถ™์–ด์žˆ๋‹ค๋ณด๋‹ˆ ์Šค์น˜๋“ฏ ๋ณด์•˜์„ ๋•Œ
SGET => single get ๋˜๋Š” MGET => mop get๊ณผ ๊ฐ™์ด ์ฐฉ๊ฐํ•  ์ˆ˜ ์žˆ์–ด ๋ณด์ž…๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ MAX_BMGET_ELM_COUNT๊ณผ ๊ฐ™์€ ๊ธฐ์กด ์ƒ์ˆ˜ ์ด๋ฆ„์„ ๋ณผ ๋•Œ,
ํ˜„์žฌ PR์˜ ์ƒ์ˆ˜๋ช…์ด ์ผ๊ด€์„ฑ์„ ํ•ด์น˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์ ์—์„œ๋Š” ์ ์ ˆํ•˜๊ณ ,
๊ด€๋ จ ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•  ๋•Œ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธธ ์ •๋„๋Š” ์•„๋‹ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Copy link
Collaborator

Choose a reason for hiding this comment

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

์šฉ์–ด ๋ณ€๊ฒฝํ•ฉ์‹œ๋‹ค.

  • MAX_SGET_ELM_COUNT => MAX_SOP_GET_COUNT

Copy link
Collaborator

@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.

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

memcached.h Outdated
@@ -84,6 +84,7 @@
#define BIN_PKT_HDR_WORDS (MIN_BIN_PKT_LENGTH/sizeof(uint32_t))

#define MAX_MGET_KEY_COUNT 10000
#define MAX_SGET_ELM_COUNT 1000
Copy link
Collaborator

Choose a reason for hiding this comment

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

์šฉ์–ด ๋ณ€๊ฒฝํ•ฉ์‹œ๋‹ค.

  • MAX_SGET_ELM_COUNT => MAX_SOP_GET_COUNT

@@ -10950,6 +10950,10 @@ static void process_sop_command(conn *c, token_t *tokens, const size_t ntokens)
out_string(c, "CLIENT_ERROR bad command line format");
return;
}
if (count > MAX_SGET_ELM_COUNT) {
out_string(c, "CLIENT_ERROR bad value");
Copy link
Collaborator

Choose a reason for hiding this comment

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

CLIENT_ERROR๊ฐ€ ์—†๋Š” ๋‹ค๋ฅธ ์‘๋‹ต ๋ฌธ์ž์—ด์€ ์–ด๋–ค ๊ฒƒ์ด ์žˆ๋‚˜์š”?

Copy link
Collaborator Author

@ing-eoking ing-eoking Feb 27, 2025

Choose a reason for hiding this comment

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

Sop get์˜ ๊ฒฝ์šฐ ์•„๋ž˜์˜ ์—๋Ÿฌ๊ฐ€ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค.

Response String ์„ค๋ช…
"NOT_FOUND" key miss
"NOT_FOUND_ELEMENT" element miss (element๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ƒํƒœ์ž„)
"TYPE_MISMATCH" ํ•ด๋‹น item์ด set collection์ด ์•„๋‹˜
"UNREADABLE" ํ•ด๋‹น item์ด unreadable item์ž„
"NOT_SUPPORTED" ์ง€์›ํ•˜์ง€ ์•Š์Œ
"CLIENT_ERROR bad command line format" protocol syntax ํ‹€๋ฆผ
"SERVER_ERROR out of memory [writing get response]" ๋ฉ”๋ชจ๋ฆฌ ๋ถ€์กฑ

@@ -1,7 +1,7 @@
#!/usr/bin/perl

use strict;
use Test::More tests => 83007;
use Test::More tests => 83005;
Copy link
Collaborator

Choose a reason for hiding this comment

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

ํ…Œ์ŠคํŠธ๋„ ๋ณ€๊ฒฝํ•ด์•ผ ๊ฒ ์ง€๋งŒ, docs๋„ ํ•จ๊ป˜ ๋ณ€๊ฒฝํ•ฉ์‹œ๋‹ค.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

์ˆ˜์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

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