Skip to content

Conversation

@6unYoung
Copy link
Contributor

@6unYoung 6unYoung commented Nov 19, 2025

๐Ÿ”— Related Issue

โŒจ๏ธ What I did

  • cmdlog filter ๋ช…๋ น์„ ์ฒ˜๋ฆฌํ•˜๋Š” process_cmdlog_filter() ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ํ•„ํ„ฐ๋ง ๊ฒ€์‚ฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” is_cmdlog_filter_match() ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • cmdlog_write()๊ฐ€ ๊ธฐ์กด๊ณผ ๋™์ผํ•œ ๋™์ž‘์„ ํ•˜๊ฒŒ๋” command์— ๋Œ€ํ•œ ๋กœ์ง์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • cmdlog_add(), cmdlog_remove(), cmdlog_list() ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • cmd_log_global์˜ ๋ฉค๋ฒ„ ๋ณ€์ˆ˜๋กœ ํ•„ํ„ฐ ๋ฆฌ์ŠคํŠธ struct cmd_log_filter filters[CMDLOG_FILTER_MAXNUM]์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

๋ช…์„ธ

  1. ํ•„ํ„ฐ ์ถ”๊ฐ€ ๋ช…๋ น์–ด
    cmdlog filter add (command <cmd> | key <key> | command <cmd> key <key>)๋กœ ํ•„ํ„ฐ๋ฅผ ๋“ฑ๋กํ•œ๋‹ค. command, key ์˜ต์…˜ ์ค‘ ํ•˜๋‚˜๋Š” ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋‹ค. ์ƒ๋žต๋œ ์˜ต์…˜์€ ํ•„ํ„ฐ๋งํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋ฌธ์ž ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋Š” ์ˆ˜ํ–‰ํ•˜์ง€๋งŒ, ๋ช…๋ น์–ด์™€ ํ‚ค์˜ ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ๊ฒ€์‚ฌํ•˜์ง„ ์•Š๋Š”๋‹ค. ํ•„ํ„ฐ ์ˆ˜์—๋Š” ์ œํ•œ์ด ์กด์žฌํ•œ๋‹ค.
์˜ˆ์‹œ
$ cmdlog start
$ cmdlog filter add command add key 01
    0. Filter: command = add, key = 01
$ add 01 0 0 2  // ๋กœ๊น…
$ add 01:02 0 5 1  // ๋กœ๊น…x(ํ‚ค ๋ถˆ์ผ์น˜)

$ cmdlog filter add command bop_insert
    1. Filter: command = bop_insert, key =
$ bop insert  // ํ•„ํ„ฐ๊ฐ€ ์ผ์น˜ํ•ด ๋ช…๋ น์˜ ๊ฒฐ๊ณผ์™€ ์ƒ๊ด€์—†์ด ๋กœ๊น…
    CLIENT_ERROR bad command line format

// ์˜ต์…˜ ๋ชจ๋‘ ์ƒ๋žต ์‹œ ์—๋Ÿฌ
$ cmdlog filter add
    CLIENT_ERROR bad command line format

// ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์œ ํšจํ•œ์ง€ ๊ฒ€์‚ฌ
$ cmdlog filter add key \t\n
    CLIENT_ERROR bad command line format
$ cmdlog filter add command add key
    CLIENT_ERROR bad command line format
$ cmdlog filter add key a:b:d!#-^
    2. Filter: command = , key = a:b:d!#-^

// ๋‹จ ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ๊ฒ€์‚ฌํ•˜์ง„ ์•Š์Œ
$ cmdlog filter add command dumm1
    2. Filter: command = dumm1, key =

// ํ•„ํ„ฐ ์ตœ๋Œ€ ๊ฐœ์ˆ˜์— ์ œํ•œ ์กด์žฌ
$ cmdlog filter add key a
    3. Filter: command = , key = a
...
$ cmdlog filter add key b
    CLIENT_ERROR filter list is full
  1. ํ•„ํ„ฐ ์‚ญ์ œ ๋ช…๋ น์–ด
    cmdlog filter remove (index)๋กœ ํ•„ํ„ฐ๋ฅผ ์‚ญ์ œํ•œ๋‹ค. ์ธ๋ฑ์Šค๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ฐพ์•„ ์‚ญ์ œํ•˜๊ณ , ์ƒ๋žต ์‹œ ๋ชจ๋“  ํ•„ํ„ฐ๋ฅผ ์‚ญ์ œํ•œ๋‹ค.
์˜ˆ์‹œ
$ cmdlog filter remove 99
    CLIENT_ERROR  invalid parameters
$ cmdlog filter remove 2
    1 filters removed
$ cmdlog filter remove
    9 filters removed
$ cmdlog filter remove
    0 filters removed
$ cmdlog filter remove 1
    CLIENT_ERROR invalid parameters
  1. ํ•„ํ„ฐ ์ถœ๋ ฅ ๋ช…๋ น์–ด
    cmdlog filter list๋กœ ํ•„ํ„ฐ ๋ชฉ๋ก์„ ์ถœ๋ ฅํ•œ๋‹ค. ํ˜„์žฌ ํ•„ํ„ฐ ์ˆ˜์™€ ์ตœ๋Œ€ ํ•„ํ„ฐ ์ˆ˜๋ฅผ ๊ฐ™์ด ์ถœ๋ ฅํ•œ๋‹ค.
์˜ˆ์‹œ
$ cmdlog filter list
    (2/10)
    1. command=     key=01
    2. command=add  key=02:02

@6unYoung 6unYoung force-pushed the feature_cmdlog branch 3 times, most recently from 5ceae4f to d16a097 Compare November 19, 2025 09:17
@6unYoung
Copy link
Contributor Author

6unYoung commented Nov 20, 2025

์˜๊ฒฌ์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„์ด ๋ช‡ ๊ฐœ ์žˆ์–ด ํ™•์ธ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

  1. ํ•„ํ„ฐ ์ถ”๊ฐ€ ์‹œ ํ‚ค๋ฅผ ๋ฌด์‹œํ•˜๊ฑฐ๋‚˜ ํ•„์š”๋กœ ํ•˜์ง€ ์•Š๋Š” ๋ช…๋ น(mget, flush, help, ..)์— ๋Œ€ํ•ด ์ž„์˜๋กœ ํ‚ค๋ฅผ ๊ฐ™์ด ๋„ฃ์€ ๊ฒฝ์šฐ, ๋ช…๋ น์–ด๊ฐ€ ์‹ค์ œ๋กœ ์ž…๋ ฅ๋  ๋•Œ ํ‚ค๋ฅผ ํ•„์š”๋กœ ํ•˜์ง€ ์•Š๋Š” ๋ช…๋ น์— ๋Œ€ํ•ด ํ‚ค๋ฅผ nul๋กœ ์ฒ˜๋ฆฌํ•˜๋ฏ€๋กœ ํ•ด๋‹น ํ•„ํ„ฐ๋Š” ์ ˆ๋Œ€ ๋งค์นญ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๊ฒฝ์šฐ์— ๋Œ€ํ•ด ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์ง€ ๋ชปํ•˜๋„๋ก ๋ฐฉ์–ด ์ฝ”๋“œ๊ฐ€ ํ•„์š”ํ• ๊นŒ์š”?

  2. ํ•„ํ„ฐ๋ฅผ ๋™์ ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๊ธฐ๋Šฅ์€ ์—†์–ด๋„ ๋œ๋‹ค๊ณ  ํ•˜์…จ๋Š”๋ฐ, ๋™์  ๋ณ€๊ฒฝ์„ ๋ง‰์œผ๋ ค๊ณ  ํ•˜๋ฉด ์ฝ”๋“œ๊ฐ€ ๋‹ค์†Œ ์ง€์ €๋ถ„ํ•ด์งˆ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
    ๊ธฐ์กด ์ฝ”๋“œ์—์„œ๋Š” process_cmdlog_command()์—์„œ cmdlog_start()๋“ฑ์„ ํ˜ธ์ถœํ•  ๋•Œ already_check ๋ณ€์ˆ˜๋ฅผ ์ธ์ž๋กœ ๋„˜๊ฒจ cmdlog.c์— ์กด์žฌํ•˜๋Š” cmdlog_in_use์˜ true/false ์—ฌ๋ถ€์— ๋”ฐ๋ผ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ filter ๊ธฐ๋Šฅ์€ ๋ณ„๋„์˜ subcommand๋ฅผ ์š”๊ตฌํ•˜๋ฏ€๋กœ process_cmdlog_filter()๋ฅผ ๋งŒ๋“ค์–ด cmdlog_filter_add()๋“ฑ์„ ํ˜ธ์ถœํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๊ธฐ์กด ์ฝ”๋“œ์™€ ๊ฐ™์€ ๋ ˆ๋ฒจ์—์„œ ์—๋Ÿฌ ํ•ธ๋“ค๋ง๋„ ์•ˆ๋˜๊ณ , ๋ฆฌํ„ด ์ฝ”๋“œ๋กœ ๋„˜๊ธฐ๊ธฐ์—๋„ ์ข‹์ง„ ์•Š์•„ ๋ณด์ž…๋‹ˆ๋‹ค.
    ๊ทธ๋ž˜์„œ ์ผ๋‹จ ๋™์  ๋ณ€๊ฒฝ์„ ํ—ˆ์šฉํ•˜๊ฒŒ ํ–ˆ๋Š”๋ฐ, ๊ธฐ๋Šฅ์ ์œผ๋กœ ๋ฌธ์ œ๊ฐ€ ๋ ๊นŒ์š”?

@ing-eoking
Copy link
Collaborator

๊ฐœ์ธ ์˜๊ฒฌ์ž…๋‹ˆ๋‹ค.

ํ•„ํ„ฐ ์ถ”๊ฐ€ ์‹œ ํ‚ค๋ฅผ ๋ฌด์‹œํ•˜๊ฑฐ๋‚˜ ํ•„์š”๋กœ ํ•˜์ง€ ์•Š๋Š” ๋ช…๋ น(mget, flush, help, ..)์— ๋Œ€ํ•ด ์ž„์˜๋กœ ํ‚ค๋ฅผ ๊ฐ™์ด ๋„ฃ์€ ๊ฒฝ์šฐ, ๋ช…๋ น์–ด๊ฐ€ ์‹ค์ œ๋กœ ์ž…๋ ฅ๋  ๋•Œ ํ‚ค๋ฅผ ํ•„์š”๋กœ ํ•˜์ง€ ์•Š๋Š” ๋ช…๋ น์— ๋Œ€ํ•ด ํ‚ค๋ฅผ nul๋กœ ์ฒ˜๋ฆฌํ•˜๋ฏ€๋กœ ํ•ด๋‹น ํ•„ํ„ฐ๋Š” ์ ˆ๋Œ€ ๋งค์นญ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๊ฒฝ์šฐ์— ๋Œ€ํ•ด ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜์ง€ ๋ชปํ•˜๋„๋ก ๋ฐฉ์–ด ์ฝ”๋“œ๊ฐ€ ํ•„์š”ํ• ๊นŒ์š”?

์ด ๊ฒฝ์šฐ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป ๋„ฃ์€ ๊ฒฝ์šฐ์— ํ•ด๋‹นํ•˜๋ฏ€๋กœ ๋ณ„๋‹ค๋ฅธ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ํ•„์š”๊ฐ€ ์—†์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
ํ•„ํ„ฐ ์กฐ๊ฑด์— ๋ช…๋ น์–ด๋ฅผ ์—†๋Š” ๋ช…๋ น์–ด๋ฅผ ๋„ฃ๋Š” ๊ฒฝ์šฐ์™€ ์œ ์‚ฌํ•˜์ง€ ์•Š์„๊นŒ ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค. (ex. cmd=abcdef)

ํ•„ํ„ฐ๋ฅผ ๋™์ ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๊ธฐ๋Šฅ์€ ์—†์–ด๋„ ๋œ๋‹ค๊ณ  ํ•˜์…จ๋Š”๋ฐ, ๋™์  ๋ณ€๊ฒฝ์„ ๋ง‰์œผ๋ ค๊ณ  ํ•˜๋ฉด ์ฝ”๋“œ๊ฐ€ ๋‹ค์†Œ ์ง€์ €๋ถ„ํ•ด์งˆ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
๊ธฐ์กด ์ฝ”๋“œ์—์„œ๋Š” process_cmdlog_command()์—์„œ cmdlog_start()๋“ฑ์„ ํ˜ธ์ถœํ•  ๋•Œ already_check ๋ณ€์ˆ˜๋ฅผ ์ธ์ž๋กœ ๋„˜๊ฒจ cmdlog.c์— ์กด์žฌํ•˜๋Š” cmdlog_in_use์˜ true/false ์—ฌ๋ถ€์— ๋”ฐ๋ผ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ filter ๊ธฐ๋Šฅ์€ ๋ณ„๋„์˜ subcommand๋ฅผ ์š”๊ตฌํ•˜๋ฏ€๋กœ process_cmdlog_filter()๋ฅผ ๋งŒ๋“ค์–ด cmdlog_filter_add()๋“ฑ์„ ํ˜ธ์ถœํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๊ธฐ์กด ์ฝ”๋“œ์™€ ๊ฐ™์€ ๋ ˆ๋ฒจ์—์„œ ์—๋Ÿฌ ํ•ธ๋“ค๋ง๋„ ์•ˆ๋˜๊ณ , ๋ฆฌํ„ด ์ฝ”๋“œ๋กœ ๋„˜๊ธฐ๊ธฐ์—๋„ ์ข‹์ง„ ์•Š์•„ ๋ณด์ž…๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ผ๋‹จ ๋™์  ๋ณ€๊ฒฝ์„ ํ—ˆ์šฉํ•˜๊ฒŒ ํ–ˆ๋Š”๋ฐ, ๊ธฐ๋Šฅ์ ์œผ๋กœ ๋ฌธ์ œ๊ฐ€ ๋ ๊นŒ์š”?

๋™์ ์œผ๋กœ ๋ณ€๊ฒฝ๋˜์–ด๋„ ์ƒ๊ด€์—†์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@ing-eoking ing-eoking self-requested a review November 20, 2025 09:23
cmdlog.c Outdated
Comment on lines 498 to 506
} else if ((command[0] == 'l' ||
command[0] == 's' ||
command[0] == 'm' ||
command[0] == 'b') &&
strcmp(command + 1, "op") == 0) {
return 2;
}

return 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

์ด ํ•จ์ˆ˜ ํ˜ธ์ถœ๋˜๋Š” ์‹œ์ ์ด ntokens ๊ฒ€์ฆํ•˜๊ธฐ ์ „์ธ๋ฐ,
tokens[key_idx]๊ฐ€ ํ•ญ์ƒ ์กด์žฌํ•˜๋Š” ๊ฒƒ์ด ๋ณด์žฅ๋˜๋‚˜์š”?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

๋ฐฉ์–ด ์ฝ”๋“œ๊ฐ€ ๋น ์ ธ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. key_idx ๋ณ„ ntokens ๊ฒ€์‚ฌ ๋กœ์ง์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ํ˜„์žฌ -1 -> 2 -> ๋‚˜๋จธ์ง€ 1 ์ˆœ์„œ๋กœ ๋น„๊ตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

key๊ฐ€ ์žˆ๋Š” ๋ช…๋ น์„ ๋จผ์ € ํ™•์ธํ•˜์—ฌ 1 ๋˜๋Š” 2 ๋ฐ˜ํ™˜ํ•˜๊ณ ,
๊ทธ ์™ธ(์•Œ ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ ํฌํ•จ) ๋ช…๋ น์— ๋Œ€ํ•ด -1 ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์ด์–ด์•ผ ์ž์—ฐ์Šค๋Ÿฌ์šด ํ˜•ํƒœ์ด์ง€ ์•Š๋‚˜ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

๋˜๋Š”, command๊ฐ€ ์•„๋‹Œ tokens ์ธ์ž๋กœ ๋ฐ›์œผ๋ฉด key ๋ฌธ์ž์—ด์„ ๋ฐ”๋กœ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์–ด ๋ณด์ž…๋‹ˆ๋‹ค.
ntokens ๋น„๊ต ๋กœ์ง ๋“ฑ๋„ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•จ์ˆ˜ ์•ˆ์ชฝ์œผ๋กœ ์ด๋™๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

cmdlog.c Outdated
Comment on lines 527 to 529
if (key_idx > 0) {
snprintf(key, CMDLOG_FILTER_KEY_MAXLEN + 1, "%s", tokens[key_idx].value);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

key์— ๋ฌธ์ž์—ด ๋ณต์‚ฌํ•˜์ง€ ์•Š๊ณ  tokens[key_idx].value ๊ฐ’ ๋ฐ”๋กœ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ ๋ฌธ์ œ๊ฐ€ ๋˜๋Š” ๋ถ€๋ถ„์ด ์žˆ๋‚˜์š”?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

๋ฐ”๋กœ ์‚ฌ์šฉํ•ด๋„ ๋ฌธ์ œ๋Š” ์—†์Šต๋‹ˆ๋‹ค. key ์ง€์—ญ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•œ ์ด์œ ๋Š” key๋ฅผ ์š”๊ตฌํ•˜์ง€ ์•Š๋Š” command์˜ ๊ฒฝ์šฐ key_idx๊ฐ€ -1์ด ๋˜๋ฏ€๋กœ ์ธ๋ฑ์Šค ์ ‘๊ทผ์„ ๋ฐฐ์ œํ•ด์•ผ ํ•˜๋Š”๋ฐ, ๋น„๊ต ์ค‘ -1์„ ์ฒดํฌํ•˜๊ธฐ๋ณด๋‹จ ์‚ฌ์ „์— ํ™•์ธํ•˜๊ณ  ํ•„ํ„ฐ ์ˆœํšŒ ์ค‘์—๋Š” ๋น„๊ต๋งŒ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒŒ ๊ฐ€๋…์„ฑ์ด ๋” ์ข‹์•„๋ณด์—ฌ ์„ ํƒํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Copy link
Collaborator

Choose a reason for hiding this comment

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

๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ์ง€์—ญ๋ณ€์ˆ˜ ๋‘๋Š” ๊ฒƒ์—๋Š” ํฌ๊ฒŒ ์ด๊ฒฌ ์—†์ง€๋งŒ,
๋ฐฐ์—ด์— ๋ฌธ์ž์—ด์„ ๋‹ค์‹œ ์“ฐ์ง€ ์•Š๊ณ  ๋‹จ์ˆœํžˆ tokens ๋˜๋Š” empty string์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐ๋กœ ๊ด€๋ฆฌํ•ด๋„
๊ฐ€๋…์„ฑ ์ธก๋ฉด์—์„œ ํ˜„์žฌ PR ๊ตฌํ˜„๊ณผ ํฌ๊ฒŒ ์ฐจ์ด๊ฐ€ ์—†์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

memcached.c Outdated
Comment on lines 10600 to 10618
int len = command_len + key_len + 26;
char *buf = (char *)malloc(len);
if (buf) {
snprintf(buf, len, "\tFilter: command = %s, key = %s", command, key);
out_string(c, buf);
free(buf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

์•„๋ž˜์™€ ๊ฐ™์ด ์‘๋‹ต ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์ด ์ž˜๋ ค ๋ณด์ž…๋‹ˆ๋‹ค.

$ telnet devbox.gcp.namsic.dev 11211
Trying 35.216.32.213...
Connected to devbox.gcp.namsic.dev.
Escape character is '^]'.
cmdlog filter add command add key 01
        Filter: command = add, key =
cmdlog filter add command replace
        Filter: command = replace, key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

์ถœ๋ ฅ ๋ฒ„ํผ ํฌ๊ธฐ๋ฅผ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

@6unYoung 6unYoung force-pushed the feature_cmdlog branch 2 times, most recently from 82661ae to bb79672 Compare December 4, 2025 04:28
cmdlog.c Outdated
Comment on lines 498 to 506
} else if ((command[0] == 'l' ||
command[0] == 's' ||
command[0] == 'm' ||
command[0] == 'b') &&
strcmp(command + 1, "op") == 0) {
return 2;
}

return 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

ํ˜„์žฌ -1 -> 2 -> ๋‚˜๋จธ์ง€ 1 ์ˆœ์„œ๋กœ ๋น„๊ตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

key๊ฐ€ ์žˆ๋Š” ๋ช…๋ น์„ ๋จผ์ € ํ™•์ธํ•˜์—ฌ 1 ๋˜๋Š” 2 ๋ฐ˜ํ™˜ํ•˜๊ณ ,
๊ทธ ์™ธ(์•Œ ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ ํฌํ•จ) ๋ช…๋ น์— ๋Œ€ํ•ด -1 ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์ด์–ด์•ผ ์ž์—ฐ์Šค๋Ÿฌ์šด ํ˜•ํƒœ์ด์ง€ ์•Š๋‚˜ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

๋˜๋Š”, command๊ฐ€ ์•„๋‹Œ tokens ์ธ์ž๋กœ ๋ฐ›์œผ๋ฉด key ๋ฌธ์ž์—ด์„ ๋ฐ”๋กœ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์–ด ๋ณด์ž…๋‹ˆ๋‹ค.
ntokens ๋น„๊ต ๋กœ์ง ๋“ฑ๋„ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•จ์ˆ˜ ์•ˆ์ชฝ์œผ๋กœ ์ด๋™๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

cmdlog.c Outdated
Comment on lines 527 to 529
if (key_idx > 0) {
snprintf(key, CMDLOG_FILTER_KEY_MAXLEN + 1, "%s", tokens[key_idx].value);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ์ง€์—ญ๋ณ€์ˆ˜ ๋‘๋Š” ๊ฒƒ์—๋Š” ํฌ๊ฒŒ ์ด๊ฒฌ ์—†์ง€๋งŒ,
๋ฐฐ์—ด์— ๋ฌธ์ž์—ด์„ ๋‹ค์‹œ ์“ฐ์ง€ ์•Š๊ณ  ๋‹จ์ˆœํžˆ tokens ๋˜๋Š” empty string์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐ๋กœ ๊ด€๋ฆฌํ•ด๋„
๊ฐ€๋…์„ฑ ์ธก๋ฉด์—์„œ ํ˜„์žฌ PR ๊ตฌํ˜„๊ณผ ํฌ๊ฒŒ ์ฐจ์ด๊ฐ€ ์—†์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

cmdlog.c Outdated
static int get_key_idx_by_command(const char *command)
{
assert(command);
if (strstr(command, "mget") ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

strcmp()๊ฐ€ ์•„๋‹Œ strstr() ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

*mget* ํ˜•ํƒœ์˜ ๋ช…๋ น์ด ๋ชจ๋‘ ๋งค์นญ๋  ๊ฒƒ์ธ๋ฐ,
๋‹ค๋ฅธ ๋ช…๋ น๋“ค์ด ์ •ํ™•ํ•œ ์ผ์น˜ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๋Š” ๊ฒƒ์— ๋น„ํ•˜์—ฌ ๋ชจํ˜ธํ•œ ๋กœ์ง์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mget, bop_mget, bop_smget ๋ช…๋ น๋“ค์€ ๋ชจ๋‘ key ๊ฒ€์‚ฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š๊ธฐ๋กœ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‚˜์—ดํ•˜์ง€ ์•Š๊ณ  strstr()๋กœ ๋ฌธ์ž์—ด ๋งค์นญ์„ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

cmdlog.c Outdated
Comment on lines 547 to 561
if (cmdlog.nfilters >= CMDLOG_FILTER_MAXNUM) {
return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

lock ์žก์€ ์ƒํƒœ๋กœ ํ™•์ธํ•ด์•ผ ํ•˜์ง€ ์•Š๋Š”์ง€?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is_cmdlog_filter_match(), cmdlog_filter_add(), cmdlog_filter_list() lock ๊ด€๋ จ ์ฝ”๋“œ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

@6unYoung 6unYoung force-pushed the feature_cmdlog branch 2 times, most recently from 1fcd0b9 to 5924b63 Compare December 5, 2025 02:29
@6unYoung 6unYoung requested a review from namsic December 5, 2025 03:00
@6unYoung 6unYoung marked this pull request as draft December 8, 2025 06:22
@6unYoung 6unYoung force-pushed the feature_cmdlog branch 2 times, most recently from d384f48 to b0db1d8 Compare December 8, 2025 07:11
@6unYoung 6unYoung marked this pull request as ready for review December 8, 2025 07:12
@6unYoung
Copy link
Contributor Author

6unYoung commented Dec 8, 2025

@jhpark816
๋ฆฌ๋ทฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

@jhpark816
Copy link
Collaborator

@6unYoung
cmdlog filter add [command <cmd>] [key <key>] ํ˜•์‹์€
์ธ์ž๊ฐ€ ์—†๋Š” cmdlog filter add ๋ช…๋ น๋„ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ, ์˜๋ฏธ์— ๋งž๊ฒŒ ์ˆ˜์ •ํ•ด ์ฃผ์„ธ์š”.

@6unYoung
Copy link
Contributor Author

6unYoung commented Dec 8, 2025

cmdlog filter add [command <cmd>] [key <key>] ํ˜•์‹์€ ์ธ์ž๊ฐ€ ์—†๋Š” cmdlog filter add ๋ช…๋ น๋„ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, ์˜๋ฏธ์— ๋งž๊ฒŒ ์ˆ˜์ •ํ•ด ์ฃผ์„ธ์š”.

์˜๋ฏธ์— ๋งž๋Š” EBNF ํ˜•์‹์œผ๋กœ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

inputstr[nwritten++] = ' ';
ptr++;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@6unYoung
์—ฌ๊ธฐ ์ฝ”๋“œ ์ˆ˜์ •์€ ๋ฒ„๊ทธ๋ฅผ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•œ ๊ฒƒ์ธ๊ฐ€์š”?
๊ธฐ์กด ์ฝ”๋“œ๋ฅผ ์กฐ๊ธˆ ์ˆ˜์ •ํ•ด์„œ๋„ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์€ ๋ฐ์š”. ์–ด๋–ค๊ฐ€์š”?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ํ•ด๋‹น ์ฝ”๋“œ๋Š” cmdlog_write() ํ˜ธ์ถœ ์ „์— tokenize_command()๋ฅผ ๋จผ์ € ํ˜ธ์ถœํ•˜๊ฒŒ ์ˆ˜์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค. command๊ฐ€ tokenized๋œ ์ƒํƒœ์ด๋ฏ€๋กœ ๋„ ๋ฌธ์ž๋ฅผ ๊ฑด๋„ˆ๋›ฐ๋ฉด์„œ ์ปค๋งจ๋“œ ๋ผ์ธ ์ „์ฒด๋ฅผ ์ž…๋ ฅ๋ฐ›๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค.

@6unYoung 6unYoung force-pushed the feature_cmdlog branch 2 times, most recently from d8ae576 to 7fa8720 Compare December 8, 2025 08:50
return;
}

ntokens = tokenize_command(command, cmdlen, tokens, MAX_TOKENS);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@6unYoung
tokenize_command() ์ˆ˜ํ–‰ํ•˜๊ณ  ๋‚˜๋ฉด, command ๋ฌธ์ž์—ด์ด ํ›ผ์†๋ฉ๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ, command ๋ฌธ์ž์—ด์„ ๊ทธ๋Œ€๋กœ ๋กœ๊น…ํ•˜๋Š” ๊ฒƒ์ด ์–ด๋ ค์šธ ๊ฒƒ ๊ฐ™์€ ๋ฐ์š”.
ํ™•์ธํ•ด ๋ณด์•˜๋‚˜์š”?

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.

์ผ๋ถ€ ๋ฆฌ๋ทฐ

}
} else {
out_string(c, "ERROR unknown command");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

DOCS๋„ ๋ฐ˜์˜ํ•ด ์ฃผ์‹œ์ฃ .
์ •ํ™•ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ™•์ธํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

if (!safe_strtol(tokens[3].value, &idx)) {
idx = -1;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

๋‹ค์‹œ ์‚ดํŽด๋ณด๋‹ˆ, ์•„๋ž˜ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์ง๊ด€์ ์ด๊ณ  ๋ช…ํ™•ํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

remove <index>
remove all

memcached.c Outdated
if (buf) {
snprintf(buf, buf_size, "\tFilter: command = %s, key = %s", command, key);
out_string(c, buf);
free(buf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

OK\r\n ์‘๋‹ตํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์–ด๋–ค๊ฐ€์š”?

command = tokens[4].value;
command_len = tokens[4].length;
key = tokens[6].value;
key_len = tokens[6].length;
Copy link
Collaborator

Choose a reason for hiding this comment

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

key ๋‹ค์Œ์— command ๋ช…์‹œํ•˜๋Š” ๊ฒƒ์€ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋„ค์š”.

Copy link
Contributor Author

@6unYoung 6unYoung Dec 8, 2025

Choose a reason for hiding this comment

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

์œ„์—์„œ ์ œ์‹œํ•œ ์ธํ„ฐํŽ˜์ด์Šค์—๋Š” ํ•ด๋‹น ํ˜•์‹์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
-cmd ๊ฐ™์ด ์ˆœ์„œ ์ƒ๊ด€ ์—†๋Š” ์˜ต์…˜ ํ˜•์‹์ด ์•„๋‹ˆ๊ณ , ์œ„์น˜๊ฐ€ ์ •ํ•ด์ง€๊ณ  ์„ ํƒ ๊ฐ€๋Šฅํ•œ ์ธ์ž ๋ฐฉ์‹์œผ๋กœ ํ‘œ๊ธฐํ–ˆ๊ธฐ์— ์ˆœ์„œ ๋ฐ”๊ฟˆ์€ ํ—ˆ์šฉํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

memcached.c Outdated
out_string(c, "SERVER_ERROR out of memory");
}
} else if (ret == 0) {
out_string(c, "CLIENT_ERROR filter list is full");
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 ๋ณด๋‹ค๋Š” SERVER_ERROR๊ฐ€ ๋‚˜์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

memcached.c Outdated
int buf_size = 32;
char buf[buf_size];
snprintf(buf, buf_size, "\t%d filters removed", ret);
out_string(c, buf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

์—ฌ๊ธฐ๋„ ์•„๋ž˜์™€ ๊ฐ™์ด ๊ตฌ๋ถ„๋˜์–ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • OK
  • SERVER_ERROR filter list is empty

strcmp(command + 1, "op") == 0) {
if ((cmdlen == 8 && memcmp(command, "bop_mget", 8) == 0) ||
(cmdlen == 9 && memcmp(command, "bop_smget", 9) == 0)) {
return -1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

-1 ๋ฆฌํ„ดํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mget๋ฅ˜ ๋ช…๋ น์˜ ๊ฒฝ์šฐ์— key๋ฅผ ๋ณ„๋„์˜ ๋ผ์ธ์œผ๋กœ ์ž…๋ ฅ๋ฐ›๊ธฐ์— ํ‚ค๋ฅผ ํ•„ํ„ฐ๋งํ•˜๊ธฐ์— ๋ฒˆ๊ฑฐ๋กญ๊ณ , ๊ธฐ์กด cmdlog ๋™์ž‘์—์„œ๋„ ํ‚ค ๋ผ์ธ์„ ๋กœ๊น…ํ•˜์ง€ ์•Š๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ mget๋ฅ˜ ๋ช…๋ น์€ key๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ -1์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

(cmdlen == 6 && memcmp(command, "delete", 6) == 0) ||
(cmdlen == 7 && memcmp(command, "getattr", 7) == 0) ||
(cmdlen == 7 && memcmp(command, "setattr", 7) == 0) ||
(cmdlen == 5 && memcmp(command, "touch", 5) == 0)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

๊ธฐ์กด์—๋Š” ๋ชจ๋“  ๋ช…๋ น์„ ๋กœ๊น…ํ•  ์ˆ˜ ์žˆ์—ˆ์ง€๋งŒ,
ํ˜„์žฌ๋Š” config, zkensemble ๋“ฑ์˜ ๋ช…๋ น์„ ๋กœ๊น…ํ•˜์ง€ ์•Š๋„ค์š”.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

๋กœ๊น… ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

pthread_mutex_lock(&cmdlog.lock);
for (int i = 0; i < cmdlog.nfilters; ++i) {
if (cmdlog.filters[i].command[0] == '\0' || strcmp(command, cmdlog.filters[i].command) == 0) {
if (cmdlog.filters[i].key[0] == '\0' || strcmp(key, cmdlog.filters[i].key) == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

exact match๋งŒ ํ—ˆ์šฉ๋˜๋‚˜์š”?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

๋„ค ๋งž์Šต๋‹ˆ๋‹ค


pthread_mutex_lock(&cmdlog.lock);
for (int i = 0; i < cmdlog.nfilters; ++i) {
if (cmdlog.filters[i].command[0] == '\0' || strcmp(command, cmdlog.filters[i].command) == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

lop ๋ช…๋ น ์ „์ฒด๋ฅผ ๋กœ๊น…ํ•˜๋Š” ๊ฒƒ์€ ์•ˆ ๋˜๋‚˜์š”?

Copy link
Contributor Author

@6unYoung 6unYoung Dec 9, 2025

Choose a reason for hiding this comment

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

collection type์— ๋Œ€ํ•ด ๋ถ€๋ถ„ ๋งค์นญ์„ ํ—ˆ์šฉํ•˜๋ฉด ๋‹ค๋ฅธ ๋ช…๋ น์–ด์— ๋Œ€ํ•ด์„œ๋„ ๋™์ผํ•œ ๋™์ž‘์„ ๊ธฐ๋Œ€ํ•  ๊ฒƒ ๊ฐ™์€๋ฐ, ํ•ด๋‹น ๋ถ€๋ถ„์„ ๊ณ ๋ คํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@6unYoung 6unYoung force-pushed the feature_cmdlog branch 2 times, most recently from 0e94dd1 to 9ae5839 Compare December 9, 2025 01:06
if (ntokens < 3 || ntokens > 4) {
out_string(c, "\t* Usage: cmdlog [start [path] | stop | stats]\n");
if (ntokens < 3) {
out_string(c, "\t* Usage: cmdlog [start [path] | stop | stats | filter [add|remove|list]]\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

์•„๋ž˜ notation์œผ๋กœ ๋ณ€๊ฒฝํ•˜์‹œ์ฃ .

cmdlog { start [path] | stop | stats | filter { add | remove | list } }

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.

4 participants