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

FEATURE: add set offset command #813

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

Conversation

jeesup0103
Copy link

๐Ÿ”— Related Issue

โŒจ๏ธ What I did

  • Set get ์—ฐ์‚ฐ์‹œ offset์„ ๊ธฐ์ค€์œผ๋กœ get์„ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค.
sop get <key> [<offset>] <count> [delete | drop]\r\n

๊ตฌํ˜„๋ฐฉ๋ฒ•

Offset ํƒ์ƒ‰ ๋ฐฉ์‹

  • Offset ํƒ์ƒ‰์€ subtree count ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • tot_elem_cnt ๋ฅผ ์ž์‹ ๋…ธ๋“œ๊นŒ์ง€ ํฌํ•จํ•œ subtree์˜ element ๊ฐœ์ˆ˜๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค.
    • ๊ธฐ์กด์—๋Š” ํ˜„์žฌ ๋…ธ๋“œ์˜ element ๊ฐœ์ˆ˜๋งŒ ์ €์žฅํ–ˆ์Šต๋‹ˆ๋‹ค.

Offset์œผ๋กœ ํƒ์ƒ‰ ์‹œ:

  1. ๋…ธ๋“œ โ†’ ๋ฒ„ํ‚ท(์ฒด์ธ) โ†’ element ์ˆœ์„œ๋กœ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

tot_elem_cnt๋ฅผ ๋…ธ๋“œ๋ณ„๋กœ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด:

  1. ์‚ฝ์ž… ์‹œ:
    • ๋ถ€๋ชจ node pointer๋ฅผ ์ €์žฅํ•˜์—ฌ ์‚ฝ์ž…์ด ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•˜๋ฉด ๊ฐฑ์‹ ํ•ฉ๋‹ˆ๋‹ค.
  2. ์‚ญ์ œ ์‹œ:
    • DFS๋กœ ๋ถ€๋ชจ ๋…ธ๋“œ๋กœ ์˜ฌ๋ผ๊ฐ€๋ฉฐ tot_elem_cnt๋ฅผ ๊ฐฑ์‹ ํ•ฉ๋‹ˆ๋‹ค.
  3. ํ˜„์žฌ ๋…ธ๋“œ์˜ element ๊ฐœ์ˆ˜๊ฐ€ ํ•„์š”ํ•  ๋•Œ:
    • (tot_elem_cnt) - (์ž์‹ ๋…ธ๋“œ๋“ค์˜ tot_elem_cnt ํ•ฉ)์œผ๋กœ ๊ณ„์‚ฐํ•˜์—ฌ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์™ธ์ฒ˜๋ฆฌ

  • offset ๊ฐ’์ด ccnt ๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด NOT_FOUND_ELEMENT ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

์‚ฌ์šฉ ์˜ˆ์‹œ

sop get skey 0
VALUE 0 7
1 b
1 c
1 a
1 f
1 g
1 d
1 e
END

sop get skey 1 1
VALUE 0 1
1 c
END

sop get skey 1 0
VALUE 0 6
1 c
1 a
1 f
1 g
1 d
1 e
END

sop get skey 3 5
VALUE 0 4
1 f
1 g
1 d
1 e
END

sop get skey 12 0
NOT_FOUND_ELEMENT

@jeesup0103 jeesup0103 marked this pull request as ready for review December 30, 2024 07:14
@namsic namsic self-requested a review December 30, 2024 07:15
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.

์ฝ”๋“œ ํฌ๋งท ์œ„์ฃผ๋กœ 1์ฐจ ๋ฆฌ๋ทฐํ•ฉ๋‹ˆ๋‹ค.

commit message ๋ถ„๋ฅ˜(FEATURE:)๋Š” ๋Œ€๋ฌธ์ž๋กœ ์ž‘์„ฑํ•˜๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

Comment on lines +10868 to +10869
if (strcmp(tokens[read_ntokens+rest_ntokens-1].value, "delete")==0 ||
strcmp(tokens[read_ntokens+rest_ntokens-1].value, "drop")==0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

์ˆ˜์ •ํ•˜๋Š” ๊น€์— ์ฝ”๋“œ ์Šคํƒ€์ผ๋„ ํ•จ๊ป˜ ์ •๋ฆฌํ•ด๋‘๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

Suggested change
if (strcmp(tokens[read_ntokens+rest_ntokens-1].value, "delete")==0 ||
strcmp(tokens[read_ntokens+rest_ntokens-1].value, "drop")==0) {
if (strcmp(tokens[read_ntokens+rest_ntokens-1].value, "delete") == 0 ||
strcmp(tokens[read_ntokens+rest_ntokens-1].value, "drop") == 0) {

@@ -288,11 +287,14 @@ static ENGINE_ERROR_CODE do_set_elem_link(set_meta_info *info, set_elem_item *el
set_hash_node *node = info->root;
set_elem_item *find;
int hidx = -1;
set_hash_node *parents[100];
Copy link
Collaborator

Choose a reason for hiding this comment

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

100์€ ๋ฌด์—‡์„ ๊ธฐ์ค€์œผ๋กœ ํ•œ ํฌ๊ธฐ์ธ๊ฐ€์š”?

Copy link
Author

@jeesup0103 jeesup0103 Dec 30, 2024

Choose a reason for hiding this comment

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

์ฝ”๋“œ์—์„œ ํ•ด์‹œ ํŠธ๋ฆฌ์˜ ์ตœ๋Œ€ ๊นŠ์ด์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์—†์–ด์„œ ์ ๋‹นํžˆ ๋„‰๋„‰ํ•œ ๊ฐ’์œผ๋กœ 100์„ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
Collection ํ•˜๋‚˜์˜ ์ตœ๋Œ€ ํฌ๊ธฐ๊ฐ€ 1,000,000์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ๊ณ ๋ฅด๊ฒŒ ๋ถ„ํฌ ๋œ๋‹ค๋Š” ๊ฐ€์ •ํ•˜์— ํ•œ ๋…ธ๋“œ์— 1024๊ฐœ์˜ element ๊ฐ€ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค. ์ด๋•Œ, ํ•œ ๋…ธ๋“œ์—๋Š” 16๊ฐœ์˜ bucket์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํŠธ๋ฆฌ์˜ ๊นŠ์ด๊ฐ€ 10์ด๋ผ๊ณ  ํ•  ๋•Œ 1024*(16^10) ์ •๋„ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” 1,000,000๋ณด๋‹ค ํ›จ์”ฌ ํฌ๊ธฐ๋„ ํ•˜๊ณ  worst case๋ฅผ ๊ณ ๋ คํ•ด์„œ ์ ๋‹นํžˆ ํฐ ์ˆ˜์ธ depth ๋ฅผ 100์œผ๋กœ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
๋‹ค๋ฅธ ์ฝ”๋“œ์—์„œ ํ•ด์‹œ ํŠธ๋ฆฌ์˜ ๊นŠ์ด์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์žˆ์œผ๋ฉด ์กฐ์ • ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@@ -517,8 +548,17 @@ static int do_set_elem_traverse_dfs(set_meta_info *info, set_hash_node *node,

for (hidx = 0; hidx < SET_HASHTAB_SIZE; hidx++) {
if (node->hcnt[hidx] > 0) {
if (offset && ((*skip_cnt + node->hcnt[hidx]) <= offset)) {
(*skip_cnt) += node->hcnt[hidx];
Copy link
Collaborator

Choose a reason for hiding this comment

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

์•„๋ž˜์—์„œ *skip_cnt += 1; ํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ์—ฌ๊ธฐ์„œ๋„ ๊ด„ํ˜ธ ์—†์–ด๋„ ๋˜์ฃ ?

Copy link
Author

Choose a reason for hiding this comment

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

๋„ค. ์—†์–ด๋„ ๋˜๋Š”๋ฐ ๊ฐ€๋…์„ฑ๊ณผ ํ†ต์ผ์„ฑ์„ ์œ„ํ•ด์„œ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

if (info->root->tot_hash_cnt == 0 && info->root->tot_elem_cnt == 0) {
do_set_node_unlink(info, NULL, 0);
}
}
return fcnt;
}

static uint32_t do_set_elem_get(set_meta_info *info,
static uint32_t do_set_elem_get(set_meta_info *info, const uint32_t offset,
Copy link
Collaborator

Choose a reason for hiding this comment

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

offset๊ณผ count๋Š” ๊ฐ™์€ line์— ์œ„์น˜ํ•˜๋„๋ก ํ•˜๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.
btree ์ฐธ๊ณ  ๋ฐ”๋ž๋‹ˆ๋‹ค.

static uint32_t do_btree_elem_get(btree_meta_info *info,
                                  const int bkrtype, const bkey_range *bkrange,
                                  const eflag_filter *efilter,
                                  const uint32_t offset, const uint32_t count, const bool delete,
                                  btree_elem_item **elem_array,
                                  uint32_t *opcost, bool *potentialbkeytrim)

@jeesup0103 jeesup0103 changed the title Feature: add set offset command FEATURE: add set offset command Dec 30, 2024
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.

tot_elem_cnt๋ฅผ ์ž์‹ ๋…ธ๋“œ๊นŒ์ง€ ํฌํ•จํ•œ subtree์˜ element ๊ฐœ์ˆ˜๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค.
๊ธฐ์กด์—๋Š” ํ˜„์žฌ ๋…ธ๋“œ์˜ element ๊ฐœ์ˆ˜๋งŒ ์ €์žฅํ–ˆ์Šต๋‹ˆ๋‹ค.

tot_elem_cnt๋Š” map collection์—์„œ๋„ ๋™์ผํ•œ ์ด๋ฆ„/๋ชฉ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ํ•„๋“œ์ธ๋ฐ,
set collection์—์„œ๋งŒ ๊ทธ ์˜๋ฏธ๊ฐ€ ๋‹ฌ๋ผ์ง€๋ฉด ํ˜ผ๋™์ด ์ƒ๊ธธ ์ˆ˜ ์žˆ์–ด ๋ณด์ž…๋‹ˆ๋‹ค.

map collection์—๋„ ๋™์ผํ•œ ๋ณ€๊ฒฝ์„ ์ ์šฉํ•˜๊ฑฐ๋‚˜, tot_elem_cnt ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š” ๊ตฌํ˜„ ๋ฐฉ์•ˆ์ด๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

Comment on lines +529 to +536
int sum_of_children = 0;
for (int i = 0; i < SET_HASHTAB_SIZE; i++) {
if (node->hcnt[i] == -1) {
set_hash_node *child = (set_hash_node *)node->htab[i];
sum_of_children += (int)child->tot_elem_cnt;
}
}
int local_elem_cnt = node->tot_elem_cnt - sum_of_children;
Copy link
Collaborator

Choose a reason for hiding this comment

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

tot_elem_cnt์˜ ์˜๋ฏธ๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด์„œ ์ด์ „์— ์—†๋˜ loop๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

offset ์ธ์ž๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ฒฝ์šฐ๋ณด๋‹ค default ๊ฐ’(0)์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋” ๋งŽ์„ ๊ฒƒ์ด๋ฏ€๋กœ,
offset ๊ธฐ๋Šฅ์„ ์ตœ์ ํ™”ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ ๊ตฌํ˜„์—์„œ ์ถ”๊ฐ€ ๋น„์šฉ์„ ์ง€๋ถˆํ•˜๋Š” ํ˜•ํƒœ๋Š” ํ”ผํ–ˆ์œผ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

ํ˜„์žฌ PR๊ณผ ๊ฐ™์€ ๊ตฌํ˜„์ด ์•„๋‹ˆ๋ฉด offset ๊ธฐ๋Šฅ์ด ํฌ๊ฒŒ ๋น„ํšจ์œจ์ ์œผ๋กœ ๋™์ž‘ํ•˜๊ฒŒ ๋˜๋‚˜์š”?

Copy link
Author

Choose a reason for hiding this comment

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

ํ˜„์žฌ ๊ตฌํ˜„์€ ๋…ธ๋“œ(์„œ๋ธŒํŠธ๋ฆฌ) ๋‹จ์œ„์—์„œ๋„ ์Šคํ‚ตํ•  ์ˆ˜ ์žˆ๋„๋ก tot_elem_cnt์˜ ์˜๋ฏธ๋ฅผ โ€œ์„œ๋ธŒํŠธ๋ฆฌ element ์ „์ฒด ๊ฐœ์ˆ˜โ€๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค.
๊ทธ๋Ÿฌ๋‹ค๋ณด๋‹ˆ ์œ„์™€ ๊ฐ™์ด ํ˜„์žฌ ๋…ธ๋“œ์˜ element ๊ฐœ์ˆ˜๋ฅผ ์•Œ์•„์•ผ ํ•˜๋Š” ์ฝ”๋“œ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ด ๋•Œ๋ฌธ์— ์ถ”๊ฐ€ ๋ฃจํ”„ ๋น„์šฉ์ด ์ƒ๊ธฐ๋Š”๋ฐ, ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

  1. tot_elem_cnt๋ฅผ ์›๋ž˜๋Œ€๋กœ ๋‘๊ณ , ์ƒˆ ๋ณ€์ˆ˜ tree_elem_cnt๋ฅผ ๋งŒ๋“ค์–ด ์„œ๋ธŒํŠธ๋ฆฌ element ๊ฐœ์ˆ˜๋ฅผ ๊ด€๋ฆฌ
    • ์žฅ์ : ๋…ธ๋“œ(์„œ๋ธŒํŠธ๋ฆฌ) ๋‹จ์œ„ ์Šคํ‚ต ๊ฐ€๋Šฅ
    • ๋‹จ์ : ์ƒˆ๋กœ์šด ๋ณ€์ˆ˜ ๊ด€๋ฆฌ
  2. ๋…ธ๋“œ ๋‹จ์œ„ ์Šคํ‚ต์„ ํ•˜์ง€ ์•Š๊ณ  ํ•ด์‹œ ๋ฒ„ํ‚ท(์ฒด์ธ) ๋‹จ์œ„์—์„œ๋งŒ ์Šคํ‚ต (tot_elem_cnt๋ฅผ ๊ทธ๋Œ€๋กœ ์œ ์ง€)
    • ์žฅ์ : ์ถ”๊ฐ€ ๋ณ€์ˆ˜ ์—†์Œ
    • ๋‹จ์ : offset ํƒ์ƒ‰์ด ๋Š๋ ค์ง

Copy link
Collaborator

Choose a reason for hiding this comment

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

์ œ ์ƒ๊ฐ์—๋Š” 2๋ฒˆ๊ณผ ๊ฐ™์ด ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ถฉ๋ถ„ํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๋ฌผ๋ก  ๋ถ€๋ชจ hash_node ์ˆ˜์ค€์—์„œ ๊ฑด๋„ˆ๋›ฐ๋Š” ๊ฒƒ๋ณด๋‹ค๋Š” ๋Š๋ฆฌ๊ฒ ์ง€๋งŒ,
์ตœ์†Œํ•œ ๊ธฐ์กด์— ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ํƒ์ƒ‰ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค๋Š” ํšจ์œจ์ ์œผ๋กœ ๋™์ž‘ํ•  ๊ฒƒ์ด๊ณ ,
์•„๋งˆ 2๋ฒˆ ๋ฐฉ์‹์—์„œ๋Š” ๊ธฐ์กด ๋กœ์ง์„ ๊ฑฐ์˜ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์ตœ์†Œํ•œ์˜ ์ˆ˜์ •์œผ๋กœ offset ๊ธฐ๋Šฅ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

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